ui: Remove settings.findHeaders now we can use promises in our adapters (#7375)

Previously the API around setting headers wasn't within a Promised like
code path, so we needed a little 'cheat' function to get a token from
localStorage syncronously.

Since we refactored our adapter layer, we now have a Promised codepath
where we need to access this localStorage value and set our headers.
This means we can remove our little 'cheat' function.
This commit is contained in:
John Cowen 2020-03-03 14:55:49 +00:00 committed by John Cowen
parent a9898fcf58
commit b2f84299ca
2 changed files with 85 additions and 93 deletions

View File

@ -126,13 +126,16 @@ export default Service.extend({
// with whats left after the line, use for the headers
const [url, ...headerParts] = urlParts.join(' ').split('\n');
return client.settings.findBySlug('token').then(function(token) {
const headers = {
// default to application/json
...{
'Content-Type': 'application/json; charset=utf-8',
},
// add any application level headers
...get(client, 'settings').findHeaders(),
...{
'X-Consul-Token': typeof token.SecretID === 'undefined' ? '' : token.SecretID,
},
// but overwrite or add to those from anything in the specific request
...createHeaders(headerParts),
};
@ -212,6 +215,7 @@ export default Service.extend({
return $.ajax(options);
});
});
});
},
abort: function(id = null) {
this.connections.purge();

View File

@ -4,18 +4,6 @@ const SCHEME = 'consul';
const storage = getStorage(SCHEME);
export default Service.extend({
storage: storage,
findHeaders: function() {
// TODO: if possible this should be a promise
// TODO: Actually this has nothing to do with settings it should be in the adapter,
// which probably can't work with a promise based interface :(
const token = this.storage.getValue('token');
// TODO: The old UI always sent ?token=
// replicate the old functionality here
// but remove this to be cleaner if its not necessary
return {
'X-Consul-Token': typeof token.SecretID === 'undefined' ? '' : token.SecretID,
};
},
findAll: function(key) {
return Promise.resolve(this.storage.all());
},