diff --git a/CHANGELOG.md b/CHANGELOG.md index ee493a372b6079ac88a9a32441275f2be137fa76..3f43ee1560b112836d9a876a01b37f7d195573f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v1.0.0] - 2025-03-11 + +### Fixed + +- Wait for authentication to complete for fast polling rates + +### Changed + +- Add hyphen to regex for schema version to enable issue branches + ## [v0.1.0] - 2023-03-24 ### Added @@ -26,5 +36,6 @@ Create a soar protocol instance - implement retreive schema version by tag/branch/commitref - override methods to handle soar message structure +[unreleased]: https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-javascript/compare/v1.0.0...dev +[v1.0.0]: https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-javascript/compare/v0.1.0...v1.0.0 [v0.1.0]: https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-javascript/compare/a8eef21a...v0.1.0 -[unreleased]: https://git.noc.ac.uk/communications-backbone-system/backbone-adapter-javascript/compare/v0.1.0...dev diff --git a/dist/adapter.esm.js b/dist/adapter.esm.js index 862552155c8e296fb791c512cac2c438de251a06..22e9c0a2d1551c9d5a2cb53676a059c634123b3d 100644 --- a/dist/adapter.esm.js +++ b/dist/adapter.esm.js @@ -8,6 +8,7 @@ class Adapter { this.protocol = protocol; this.config = config; this.axios = axios; + this.authenticating = false; } /** @@ -44,6 +45,10 @@ class Adapter { * @returns {object} */ getAuthorizationHeader() { + if (this.authenticating) { + // return an pseudo response with an ignored status + return Promise.reject({ response: { status: 405 } }); + } if (!this.tokenValid()) return this.auth().then((response) => { return { @@ -62,6 +67,7 @@ class Adapter { * @returns {object} */ auth() { + this.authenticating = true; let adapterConfig = this.config; return this.axios .get(`${adapterConfig.api}/token`, { @@ -72,9 +78,11 @@ class Adapter { }) .then((response) => { this.credentials = response.data; + this.authenticating = false; return response; }) .catch((error) => { + this.authenticating = false; return Promise.reject(error); }); } @@ -116,6 +124,7 @@ class Adapter { retry = true; } break; + // ignore 405 from auth in progress case 503: { retry = true; } diff --git a/dist/adapter.js b/dist/adapter.js index c1f0e28e2fa62fdf78acd646cc8f3f4a54c08c85..868a47cf41591f29c0ced47e26788559d1d1d6c3 100644 --- a/dist/adapter.js +++ b/dist/adapter.js @@ -10,6 +10,7 @@ class Adapter { this.protocol = protocol; this.config = config; this.axios = axios; + this.authenticating = false; } /** @@ -46,6 +47,10 @@ class Adapter { * @returns {object} */ getAuthorizationHeader() { + if (this.authenticating) { + // return an pseudo response with an ignored status + return Promise.reject({ response: { status: 405 } }); + } if (!this.tokenValid()) return this.auth().then((response) => { return { @@ -64,6 +69,7 @@ class Adapter { * @returns {object} */ auth() { + this.authenticating = true; let adapterConfig = this.config; return this.axios .get(`${adapterConfig.api}/token`, { @@ -74,9 +80,11 @@ class Adapter { }) .then((response) => { this.credentials = response.data; + this.authenticating = false; return response; }) .catch((error) => { + this.authenticating = false; return Promise.reject(error); }); } @@ -118,6 +126,7 @@ class Adapter { retry = true; } break; + // ignore 405 from auth in progress case 503: { retry = true; } diff --git a/dist/protocol.esm.js b/dist/protocol.esm.js index 71a3d8207ba98ca435045d6e697b14d62d9d14c4..848a523837beb9c960d0f2a0593dab9f671d7a0c 100644 --- a/dist/protocol.esm.js +++ b/dist/protocol.esm.js @@ -125,7 +125,7 @@ class GenericSoarProtocol extends GenericProtocol { * @returns {object} */ createValidator(schema) { - if (typeof schema === 'string' && schema.match(/^[\w.]+$/)) { + if (typeof schema === 'string' && schema.match(/^[\w.-]+$/)) { this.loadSchema(schema).then((schema) => { this.validator = new Validator(schema); }); diff --git a/dist/protocol.js b/dist/protocol.js index e2c74bd15eb889140af9fa6fd70ff7241679e7f3..b8fd616adf1d601fdbabcbbb0545c6623d00afbf 100644 --- a/dist/protocol.js +++ b/dist/protocol.js @@ -127,7 +127,7 @@ class GenericSoarProtocol extends GenericProtocol { * @returns {object} */ createValidator(schema) { - if (typeof schema === 'string' && schema.match(/^[\w.]+$/)) { + if (typeof schema === 'string' && schema.match(/^[\w.-]+$/)) { this.loadSchema(schema).then((schema) => { this.validator = new Validator(schema); }); diff --git a/package.json b/package.json index 1795dd64b50996bc2a32fc0ed3a387fd586081d5..6583da0d3dd7d4c937289f66982e66fbd2ed9c1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noc-comms-backbone/backbone-adapter-javascript", - "version": "0.1.0", + "version": "1.0.0", "private": true, "contributors": [ { diff --git a/src/adapter/index.js b/src/adapter/index.js index ef71cc39fbd2d8adfb931f29db5a08adfe2f45c7..fba52314a4b40f2633f5d6909cc1384417d747c8 100644 --- a/src/adapter/index.js +++ b/src/adapter/index.js @@ -8,6 +8,7 @@ export class Adapter { this.protocol = protocol; this.config = config; this.axios = axios; + this.authenticating = false; } /** @@ -44,6 +45,10 @@ export class Adapter { * @returns {object} */ getAuthorizationHeader() { + if (this.authenticating) { + // return an pseudo response with an ignored status + return Promise.reject({ response: { status: 405 } }); + } if (!this.tokenValid()) return this.auth().then((response) => { return { @@ -62,6 +67,7 @@ export class Adapter { * @returns {object} */ auth() { + this.authenticating = true; let adapterConfig = this.config; return this.axios .get(`${adapterConfig.api}/token`, { @@ -72,9 +78,11 @@ export class Adapter { }) .then((response) => { this.credentials = response.data; + this.authenticating = false; return response; }) .catch((error) => { + this.authenticating = false; return Promise.reject(error); }); } @@ -116,6 +124,7 @@ export class Adapter { retry = true; } break; + // ignore 405 from auth in progress case 503: { retry = true; } diff --git a/src/protocol/index.js b/src/protocol/index.js index e1f35d334f0a3b3b42c42e23f09c87d7cd991f48..0dc039b5c96b90b4d5e919be4ea1e44cd541f232 100644 --- a/src/protocol/index.js +++ b/src/protocol/index.js @@ -125,7 +125,7 @@ export class GenericSoarProtocol extends GenericProtocol { * @returns {object} */ createValidator(schema) { - if (typeof schema === 'string' && schema.match(/^[\w.]+$/)) { + if (typeof schema === 'string' && schema.match(/^[\w.-]+$/)) { this.loadSchema(schema).then((schema) => { this.validator = new Validator(schema); });