Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REMOVE ngsiv1 ops aligned with CB 4.0.0 #536

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Upgrade express dep from 4.18.1 to 4.19.2 due to a vulnerability
- Remove: operations no longer supported in CB API (aligned with Orion 4.0.0)
- Remove: RPM stuff
67 changes: 0 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,73 +610,6 @@ This is the list of actions available for the Context Broker. For every action,
| discover | Dis |
| N/A | - |

### Standard operations
* `create`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `APPEND` or `APPEND_STRICT`.
* `update`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `UPDATE` or `REPLACE`.
* `delete`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `DELETE`.
* `read`: URL contains `/v1/queryContext` or `/v1/contextTypes`.
* `subscribe`: URL contains `/v1/subscribeContext`, `/v1/updateContextSubscription` o `/v1/unsubscribeContext`.
* `register`: URL contains `/v1/registry/registerContext`.
* `discover`: URL contains `/v1/registry/discoverContextAvailability`.

### Convenience operations
The following tables show the rules for detemining the action based on Method and path of the request.

An up-to-date list of the convenience operations can be found [here](https://docs.google.com/spreadsheet/ccc?key=0Aj_S9VF3rt5DdEhqZHlBaGVURmhZRDY3aDRBdlpHS3c#gid=0).

#### NGSI9 (context information availability)
| Method | Path | Action |
| ------ |:--------------------------------------------------------------------------------------- | ---:|
| GET | /v1/registry/contextEntities/{EntityId} | Dis |
| POST | /v1/registry/contextEntities/{EntityId} | Reg |
| GET | /v1/registry/contextEntities/{EntityId}/attributes | - |
| POST | /v1/registry/contextEntities/{EntityId}/attributes | - |
| GET | /v1/registry/contextEntities/{EntityId}/attributes/{attributeName} | Dis |
| POST | /v1/registry/contextEntities/{EntityId}/attributes/{attributeName} | Reg |
| GET | /v1/registry/contextEntities/{EntityId}/attributeDomains/{attributeDomainName} | Dis |
| POST | /v1/registry/contextEntities/{EntityId}/attributeDomains/{attributeDomainName} | Reg |
| GET | /v1/registry/contextEntityTypes/{typeName} | Dis |
| POST | /v1/registry/contextEntityTypes/{typeName} | Reg |
| GET | /v1/registry/contextEntityTypes/{typeName}/attributes | - |
| POST | /v1/registry/contextEntityTypes/{typeName}/attributes | - |
| GET | /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} | Dis |
| POST | /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} | Reg |
| GET | /v1/registry/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | Dis |
| POST | /v1/registry/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | Reg |

#### NGS10 (context information availability)
| Method | Path | Action |
| ------ |:--------------------------------------------------------------------------------------- | ---:|
| GET | /v1/contextEntities | R |
| POST | /v1/contextEntities | C |
| GET | /v1/contextEntities/{EntityID} | R |
| PUT | /v1/contextEntities/{EntityID} | U |
| POST | /v1/contextEntities/{EntityID} | C |
| DELETE | /v1/contextEntities/{EntityID} | D |
| GET | /v1/contextEntities/{EntityID}/attributes | - |
| PUT | /v1/contextEntities/{EntityID}/attributes | - |
| POST | /v1/contextEntities/{EntityID}/attributes | - |
| DELETE | /v1/contextEntities/{EntityID}/attributes | - |
| GET | /v1/contextEntities/{EntityID}/attributes/{attributeName} | R |
| POST | /v1/contextEntities/{EntityID}/attributes/{attributeName} | C |
| PUT | /v1/contextEntities/{EntityID}/attributes/{attributeName} | U |
| DELETE | /v1/contextEntities/{EntityID}/attributes/{attributeName} | D |
| GET | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | R |
| PUT | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | U |
| DELETE | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | D |
| GET | /v1/contextEntities/{EntityID}/attributeDomains/{attributeDomainName} | R |
| GET | /v1/contextEntityTypes/{typeName} | R |
| GET | /v1/contextEntityTypes/{typeName}/attributes | - |
| GET | /v1/contextEntityTypes/{typeName}/attributes/{attributeName} | R |
| GET | /v1/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | R |
| POST | /v1/contextSubscriptions | S |
| GET | /v1/contextSubscriptions | R |
| GET | /v1/contextSubscriptions/{subscriptionID} | R |
| PUT | /v1/contextSubscriptions/{subscriptionID} | S |
| DELETE | /v1/contextSubscriptions/{subscriptionID} | S |
| GET | /v1/contextTypes | R |
| GET | /v1/contextTypes{typename} | R |

#### NGSIv2
| Method | Path | Action |
| ------ |:--------------------------------------------------------------------------------------- | ---:|
Expand Down
115 changes: 6 additions & 109 deletions lib/plugins/orionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

'use strict';

var sax = require('sax'),
errors = require('../errors'),
var errors = require('../errors'),
identificationTable = require('./orionUrls');


Expand All @@ -42,12 +41,8 @@ function translateAction(logger, originalAction) {
case 'append':
action = 'create';
break;

case 'append_strict': // NGSIv1
action = 'create';
break;

case 'appendstrict': // NGSIv2
case 'appendstrict':
action = 'create';
break;

Expand All @@ -72,75 +67,6 @@ function translateAction(logger, originalAction) {
return action;
}

/**
* Extract the action from an XML body.
*
* @param {Object} logger Instance of logops.Logger
* @param {String} body Raw string payload.
*/
function inspectBodyXML(logger, body, callback) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML in Orion was removed in version 1.0.0 (more than 8 years ago. It's a bit surprising this has survived so long in PEP code :)

NTC (informative)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keypass still uses XML, but not usually is exposed and then no needs a pep.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I was referring to XML in the NGSI API. The rests of XML support in PEP (Keypass, etc.) has been preserved.

var parser = sax.parser(true),
readingAction = false,
errorRaised = false,
action;

parser.onerror = function(e) {
var error = new errors.WrongXmlPayload();

logger.error('[ORION-PLUGIN-006] Wrong XML Payload. Parsing error: %s', e.message);

if (!errorRaised) {
errorRaised = true;
error.moreInfo = e;
callback(error);
}
};

parser.ontext = function(t) {
if (readingAction) {
if (!action) {
action = t;
} else {
action = action + t;
}
}
};

parser.onopentag = function(node) {
if (node.name === 'updateAction') {
readingAction = true;
} else {
readingAction = false;
}
};

parser.onend = function() {
if (action) {
var translatedAction = translateAction(logger, action.trim());

if (translatedAction) {
callback(null, translatedAction);
} else {
callback(new errors.WrongXmlPayload());
}

} else {
logger.error('[ORION-PLUGIN-001] Wrong XML Payload. Action not found');

callback(new errors.WrongXmlPayload());
}
};

try {
parser.write(body).close();
} catch (e) {
var error = new errors.WrongXmlPayload();

logger.error('[ORION-PLUGIN-002] Wrong XML Payload. Parsing error: %s', e.message);
callback(error);
}
}

/**
* Extract the action from a JSON body.
*
Expand All @@ -158,39 +84,12 @@ function inspectBodyJSON(logger, body, field, callback) {
callback(new errors.WrongJsonPayload());
}
} else {
logger.error('[ORION-PLUGIN-003] Wrong JSON Payload: updateAction element not found');
logger.error('[ORION-PLUGIN-001] Wrong JSON Payload: updateAction element not found');

callback(new errors.WrongJsonPayload());
}
}

/**
* Determines what kind of body to parse to calculate the action, and invoke the appropriate function.
*
* @param {Object} req Incoming request.
* @param {Object} res Outgoing response.
*/
function inspectBodyV1(req, res, callback) {
const logger = req.logger;
var actionHandler = function actionHandler(error, action) {
req.action = action;
callback(error, req, res);
};

if (req.is('*/json')) {
logger.debug('Inspecting JSON body to discover action: \n%j\n\n', req.body);
inspectBodyJSON(logger, req.body, 'updateAction', actionHandler);
} else if (req.is('*/xml')) {
logger.debug('Inspecting XML body to discover action: \n%s\n\n', req.rawBody);
inspectBodyXML(logger, req.rawBody, actionHandler);
} else {
// TODO: raise error if the type is not recognized.
logger.error('[ORION-PLUGIN-004] Unknown content type: %s', req.headers['content-type']);

actionHandler(new errors.UnexpectedContentType(req.headers['content-type']));
}
}

function inspectBodyV2(req, res, callback) {
const logger = req.logger;
var actionHandler = function actionHandler(error, action) {
Expand All @@ -204,7 +103,7 @@ function inspectBodyV2(req, res, callback) {

} else {
// TODO: raise error if the type is not recognized.
logger.error('[ORION-PLUGIN-004] Unknown content type: %s', req.headers['content-type']);
logger.error('[ORION-PLUGIN-002] Unknown content type: %s', req.headers['content-type']);

actionHandler(new errors.UnexpectedContentType(req.headers['content-type']));
}
Expand Down Expand Up @@ -248,7 +147,7 @@ function inspectUrl(req, res, callback) {
}
}

logger.error('[ORION-PLUGIN-005] Action not found');
logger.error('[ORION-PLUGIN-003] Action not found');
callback(new errors.ActionNotFound(), req, res);
}

Expand All @@ -259,9 +158,7 @@ function inspectUrl(req, res, callback) {
* @param {Object} res Outgoing response.
*/
function extractCBAction(req, res, callback) {
if (req.path.toLowerCase().match(/\/(ngsi10|v1)\/updatecontext$/)) {
inspectBodyV1(req, res, callback);
} else if (req.path.toLowerCase().match(/\/v2\/op\/update$/)) {
if (req.path.toLowerCase().match(/\/v2\/op\/update$/)) {
inspectBodyV2(req, res, callback);
} else {
inspectUrl(req, res, callback);
Expand Down
8 changes: 0 additions & 8 deletions lib/plugins/orionUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@
* this table will fail).
*/
module.exports = [
/* Legacy NGSI operations (to be removed soon) */
/* Note POST /(v1|ngsi10)/updateContext is not included here,
/* as it is processed in an special way in orionPlugin.js */
['POST', /\/(v1|ngsi10)\/querycontext$/, 'read'],
['GET', /^\/v1\/contextentities\/.+\/attributes\/.+/, 'read'],
['PUT', /^\/v1\/contextentities\/.+/, 'update'],
['DELETE', /^\/v1\/contextentities\/.+/, 'delete'],

/* V2 Operations */
['POST', /^\/v2\/op\/query$/, 'read'],
['GET', /^\/v2$/, 'read'],
Expand Down
12 changes: 3 additions & 9 deletions operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,12 @@ it is critical: human supervision is highly advisable. Check the Keystone instan
the Keystone Operations Manual.

### Orion errors
#### ORION-PLUGIN-001: Wrong XML Payload. Action not found
#### ORION-PLUGIN-001: Wrong JSON Payload: updateAction element not found
Indicates that a received request didn't have the appropriate information to determine which action it's going to execute, so the validation process can't proceed. This is a client error and should not require human intervention. Warn the user if the error repeats.
#### ORION-PLUGIN-002: Wrong XML Payload. Parsing error: %s
An XML payload with syntactic errors has been received. This should be a client error, and it shouldn't require human intervention. Warn the user if the error repeats.
#### ORION-PLUGIN-003: Wrong JSON Payload: updateAction element not found
Indicates that a received request didn't have the appropriate information to determine which action it's going to execute, so the validation process can't proceed. This is a client error and should not require human intervention. Warn the user if the error repeats.
#### ORION-PLUGIN-004: Unknown content type: %s
#### ORION-PLUGIN-002: Unknown content type: %s
The proxy received a request with a content type that is not supported. Currently only JSON ('application/json') and XML ('application/xml' and 'text/xml') are supported. This is a client error and should not require human intervention. This may be a problem with the content headers; if repeated, advice the client to check what headers are being sent and the API for the content payload.
#### ORION-PLUGIN-005: Action not found
#### ORION-PLUGIN-003: Action not found
This error is raised when a request action should be identifiable with the information in the URL but the proxy was unavailable to do so. It might happen when the request is trying to access a URL that is not known by the Orion plugin (maybe because the client is trying to access version of the Orion Context Broker different of the one supported by the proxy). This is a client error. The client should check the API he is trying to use is the appropriate one for this version of the proxy and the Context Broker.
#### ORION-PLUGIN-006: Wrong XML Payload. Parsing error: %s
An XML payload with syntactic errors has been received. This should be a client error, and it shouldn't require human intervention. Warn the user if the error repeats.

## <a name="problems"/> Expected problems and known solutions
| Symptoms | Causes | Procedure
Expand Down
22 changes: 0 additions & 22 deletions test/orionRequests/entityCreation.json

This file was deleted.

23 changes: 0 additions & 23 deletions test/orionRequests/entityCreation.xml

This file was deleted.

10 changes: 0 additions & 10 deletions test/orionRequests/entityDelete.json

This file was deleted.

12 changes: 0 additions & 12 deletions test/orionRequests/entityDelete.xml

This file was deleted.

22 changes: 0 additions & 22 deletions test/orionRequests/entityUpdate.json

This file was deleted.

Loading
Loading