Verified Commit 71be5f45 authored by Dan Jones's avatar Dan Jones
Browse files

fix: wait for authentication for fast polling rates

2 merge requests!21Release v1.0.0,!20Resolve "Fix fast polling race condition"
Pipeline #262741 passed with stages
in 1 minute and 37 seconds
...@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ...@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased] ## [Unreleased]
### Fixed
- Wait for authentication to complete for fast polling rates
### Changed ### Changed
- Add hyphen to regex for schema version to enable issue branches - Add hyphen to regex for schema version to enable issue branches
......
...@@ -8,6 +8,7 @@ class Adapter { ...@@ -8,6 +8,7 @@ class Adapter {
this.protocol = protocol; this.protocol = protocol;
this.config = config; this.config = config;
this.axios = axios; this.axios = axios;
this.authenticating = false;
} }
/** /**
...@@ -44,6 +45,10 @@ class Adapter { ...@@ -44,6 +45,10 @@ class Adapter {
* @returns {object} * @returns {object}
*/ */
getAuthorizationHeader() { getAuthorizationHeader() {
if (this.authenticating) {
// return an pseudo response with an ignored status
return Promise.reject({ response: { status: 405 } });
}
if (!this.tokenValid()) if (!this.tokenValid())
return this.auth().then((response) => { return this.auth().then((response) => {
return { return {
...@@ -62,6 +67,7 @@ class Adapter { ...@@ -62,6 +67,7 @@ class Adapter {
* @returns {object} * @returns {object}
*/ */
auth() { auth() {
this.authenticating = true;
let adapterConfig = this.config; let adapterConfig = this.config;
return this.axios return this.axios
.get(`${adapterConfig.api}/token`, { .get(`${adapterConfig.api}/token`, {
...@@ -72,9 +78,11 @@ class Adapter { ...@@ -72,9 +78,11 @@ class Adapter {
}) })
.then((response) => { .then((response) => {
this.credentials = response.data; this.credentials = response.data;
this.authenticating = false;
return response; return response;
}) })
.catch((error) => { .catch((error) => {
this.authenticating = false;
return Promise.reject(error); return Promise.reject(error);
}); });
} }
...@@ -116,6 +124,7 @@ class Adapter { ...@@ -116,6 +124,7 @@ class Adapter {
retry = true; retry = true;
} }
break; break;
// ignore 405 from auth in progress
case 503: { case 503: {
retry = true; retry = true;
} }
......
...@@ -10,6 +10,7 @@ class Adapter { ...@@ -10,6 +10,7 @@ class Adapter {
this.protocol = protocol; this.protocol = protocol;
this.config = config; this.config = config;
this.axios = axios; this.axios = axios;
this.authenticating = false;
} }
/** /**
...@@ -46,6 +47,10 @@ class Adapter { ...@@ -46,6 +47,10 @@ class Adapter {
* @returns {object} * @returns {object}
*/ */
getAuthorizationHeader() { getAuthorizationHeader() {
if (this.authenticating) {
// return an pseudo response with an ignored status
return Promise.reject({ response: { status: 405 } });
}
if (!this.tokenValid()) if (!this.tokenValid())
return this.auth().then((response) => { return this.auth().then((response) => {
return { return {
...@@ -64,6 +69,7 @@ class Adapter { ...@@ -64,6 +69,7 @@ class Adapter {
* @returns {object} * @returns {object}
*/ */
auth() { auth() {
this.authenticating = true;
let adapterConfig = this.config; let adapterConfig = this.config;
return this.axios return this.axios
.get(`${adapterConfig.api}/token`, { .get(`${adapterConfig.api}/token`, {
...@@ -74,9 +80,11 @@ class Adapter { ...@@ -74,9 +80,11 @@ class Adapter {
}) })
.then((response) => { .then((response) => {
this.credentials = response.data; this.credentials = response.data;
this.authenticating = false;
return response; return response;
}) })
.catch((error) => { .catch((error) => {
this.authenticating = false;
return Promise.reject(error); return Promise.reject(error);
}); });
} }
...@@ -118,6 +126,7 @@ class Adapter { ...@@ -118,6 +126,7 @@ class Adapter {
retry = true; retry = true;
} }
break; break;
// ignore 405 from auth in progress
case 503: { case 503: {
retry = true; retry = true;
} }
......
...@@ -8,6 +8,7 @@ export class Adapter { ...@@ -8,6 +8,7 @@ export class Adapter {
this.protocol = protocol; this.protocol = protocol;
this.config = config; this.config = config;
this.axios = axios; this.axios = axios;
this.authenticating = false;
} }
/** /**
...@@ -44,6 +45,10 @@ export class Adapter { ...@@ -44,6 +45,10 @@ export class Adapter {
* @returns {object} * @returns {object}
*/ */
getAuthorizationHeader() { getAuthorizationHeader() {
if (this.authenticating) {
// return an pseudo response with an ignored status
return Promise.reject({ response: { status: 405 } });
}
if (!this.tokenValid()) if (!this.tokenValid())
return this.auth().then((response) => { return this.auth().then((response) => {
return { return {
...@@ -62,6 +67,7 @@ export class Adapter { ...@@ -62,6 +67,7 @@ export class Adapter {
* @returns {object} * @returns {object}
*/ */
auth() { auth() {
this.authenticating = true;
let adapterConfig = this.config; let adapterConfig = this.config;
return this.axios return this.axios
.get(`${adapterConfig.api}/token`, { .get(`${adapterConfig.api}/token`, {
...@@ -72,9 +78,11 @@ export class Adapter { ...@@ -72,9 +78,11 @@ export class Adapter {
}) })
.then((response) => { .then((response) => {
this.credentials = response.data; this.credentials = response.data;
this.authenticating = false;
return response; return response;
}) })
.catch((error) => { .catch((error) => {
this.authenticating = false;
return Promise.reject(error); return Promise.reject(error);
}); });
} }
...@@ -116,6 +124,7 @@ export class Adapter { ...@@ -116,6 +124,7 @@ export class Adapter {
retry = true; retry = true;
} }
break; break;
// ignore 405 from auth in progress
case 503: { case 503: {
retry = true; retry = true;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment