Skip to content

Commit

Permalink
Merge 8598bb3 into f464847
Browse files Browse the repository at this point in the history
  • Loading branch information
fisuda committed Apr 29, 2022
2 parents f464847 + 8598bb3 commit 00a6ce3
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## node-red-contrib-letsfiware-NGSI v0.1.0-next

- FIX error while obtaining OAuth token (#7)
- UPDATE documentation (#6)

## node-red-contrib-letsfiware-NGSI v0.1.0 - 24 April, 2022
Expand Down
52 changes: 47 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"homepage": "https://node-red-contrib-letsfiware-ngsi.letsfiware.jp/",
"dependencies": {
"axios": "^0.26.1",
"axios": "^0.27.2",
"gtfs-realtime-bindings": "0.0.6"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/NGSI/batch-update/batch-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = function (RED) {
const param = {
host: openAPIsConfig.brokerEndpoint,
pathname: '/v2/op/update',
getToken: openAPIsConfig.getToken,
getToken: openAPIsConfig.getToken === null ? null : openAPIsConfig.getToken.bind(openAPIsConfig),
contentType: 'json',
config: defaultConfig,
};
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/NGSI/entity/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = function (RED) {
const param = {
host: openAPIsConfig.brokerEndpoint,
pathname: '/v2/entities',
getToken: openAPIsConfig.getToken,
getToken: openAPIsConfig.getToken === null ? null : openAPIsConfig.getToken.bind(openAPIsConfig),
config: Object.assign(defaultConfig, msg.payload),
};

Expand Down
3 changes: 2 additions & 1 deletion src/nodes/NGSI/open-apis/open-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const getToken = async function () {
if (this.idmType === 'tokenproxy') {
if (!this.idmEndpoint.endsWith('/token')) {
options.url = '/token';
options.data = `username=${this.credentials.username}&password=${this.credentials.password}`;
}
} else {
const authBearer = Buffer.from(`${this.credentials.clientid}:${this.credentials.clientsecret}`).toString(
Expand Down Expand Up @@ -111,7 +112,7 @@ module.exports = function (RED) {
node.getToken =
node.idmType === 'none'
? null
: getToken.call(node);
: getToken;
}

RED.nodes.registerType('Open APIs', OpenAPIsNode, {
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/NGSI/source/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module.exports = function (RED) {
host: openAPIsConfig.brokerEndpoint,
pathname: '/v2/entities',
buffer: config.buffering === 'off' ? nobuffering.open(node):buffering.open(node),
getToken: openAPIsConfig.getToken,
getToken: openAPIsConfig.getToken === null ? null : openAPIsConfig.getToken.bind(openAPIsConfig),
config: Object.assign(defaultConfig, msg.payload),
};

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/NGSI/subscription/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ module.exports = function (RED) {
const param = {
host: openAPIsConfig.brokerEndpoint,
pathname: '/v2/subscriptions',
getToken: openAPIsConfig.getToken,
getToken: openAPIsConfig.getToken === null ? null : openAPIsConfig.getToken.bind(openAPIsConfig),
contentType: 'json',
config: defaultConfig,
};
Expand Down
3 changes: 1 addition & 2 deletions test/unit/batch-update_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('batch-update.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand All @@ -66,7 +66,6 @@ describe('batch-update.js', () => {

assert.equal(actual.host, 'http://orion:1026');
assert.equal(actual.pathname, '/v2/op/update');
assert.equal(actual.getToken, null);
assert.equal(actual.contentType, 'json');
assert.equal(actual.config.service, 'openiot');
assert.equal(actual.config.servicepath, '/');
Expand Down
10 changes: 5 additions & 5 deletions test/unit/entity_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('entity.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand Down Expand Up @@ -195,7 +195,7 @@ describe('entity.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand Down Expand Up @@ -225,7 +225,7 @@ describe('entity.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand All @@ -244,7 +244,7 @@ describe('entity.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand All @@ -263,7 +263,7 @@ describe('entity.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});
entityNode.__set__('getEntity', () => {return null;});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('lib.js', () => {
assert.deepEqual(actual, expected);
});
it('Has Authorization header', async () => {
const param = { getToken: async () => '3b7c02f9e8a0b8fb1ca0df27052b6dfc00f32df4'};
const param = { getToken: async () => { return '3b7c02f9e8a0b8fb1ca0df27052b6dfc00f32df4';}};
const actual = await lib.buildHTTPHeader(param);

const expected = { 'Authorization': 'Bearer 3b7c02f9e8a0b8fb1ca0df27052b6dfc00f32df4' };
Expand Down
2 changes: 1 addition & 1 deletion test/unit/source_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('source.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand Down
3 changes: 1 addition & 2 deletions test/unit/subscription_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ describe('subscription.js', () => {
openapis: {
brokerEndpoint: 'http://orion:1026',
service: 'openiot',
getToken: null,
getToken: () => {},
}
});

Expand All @@ -466,7 +466,6 @@ describe('subscription.js', () => {
servicepath: '/',
}});
assert.equal(actual.contentType, 'json');
assert.equal(actual.getToken, null);
assert.equal(actual.host, 'http://orion:1026');
assert.equal(actual.pathname, '/v2/subscriptions');
assert.equal(actual.config.service, 'openiot');
Expand Down

0 comments on commit 00a6ce3

Please sign in to comment.