ui: Detect token in a cookie and passthrough (#14495)
This commit is contained in:
parent
39439d07bd
commit
efb2ecbb2e
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:feature
|
||||||
|
ui: Detect a TokenSecretID cookie and passthrough to localStorage
|
||||||
|
```
|
|
@ -1,14 +1,44 @@
|
||||||
import Route from 'consul-ui/routing/route';
|
import Route from 'consul-ui/routing/route';
|
||||||
import { action } from '@ember/object';
|
import { action } from '@ember/object';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { runInDebug } from '@ember/debug';
|
||||||
|
|
||||||
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
|
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
|
||||||
|
|
||||||
export default class ApplicationRoute extends Route.extend(WithBlockingActions) {
|
export default class ApplicationRoute extends Route.extend(WithBlockingActions) {
|
||||||
@service('client/http') client;
|
@service('client/http') client;
|
||||||
|
@service('env') env;
|
||||||
|
@service('repository/token') tokenRepo;
|
||||||
|
@service('settings') settings;
|
||||||
|
|
||||||
data;
|
data;
|
||||||
|
|
||||||
|
async model() {
|
||||||
|
if(this.env.var('CONSUL_ACLS_ENABLED')) {
|
||||||
|
const secret = this.env.var('CONSUL_HTTP_TOKEN');
|
||||||
|
const existing = await this.settings.findBySlug('token');
|
||||||
|
if(!existing.AccessorID && secret) {
|
||||||
|
try {
|
||||||
|
const token = await this.tokenRepo.self({
|
||||||
|
secret: secret,
|
||||||
|
dc: this.env.var('CONSUL_DATACENTER_LOCAL')
|
||||||
|
});
|
||||||
|
await this.settings.persist({
|
||||||
|
token: {
|
||||||
|
AccessorID: token.AccessorID,
|
||||||
|
SecretID: token.SecretID,
|
||||||
|
Namespace: token.Namespace,
|
||||||
|
Partition: token.Partition,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
runInDebug(_ => console.error(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onClientChanged(e) {
|
onClientChanged(e) {
|
||||||
let data = e.data;
|
let data = e.data;
|
||||||
|
|
|
@ -192,7 +192,7 @@ export default function(config = {}, win = window, doc = document) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const ui = function(key) {
|
const ui = function(key) {
|
||||||
let $;
|
let $ = {};
|
||||||
switch (config.environment) {
|
switch (config.environment) {
|
||||||
case 'development':
|
case 'development':
|
||||||
case 'staging':
|
case 'staging':
|
||||||
|
@ -227,15 +227,28 @@ export default function(config = {}, win = window, doc = document) {
|
||||||
case 'CONSUL_UI_CONFIG':
|
case 'CONSUL_UI_CONFIG':
|
||||||
prev['CONSUL_UI_CONFIG'] = JSON.parse(value);
|
prev['CONSUL_UI_CONFIG'] = JSON.parse(value);
|
||||||
break;
|
break;
|
||||||
|
case 'TokenSecretID':
|
||||||
|
prev['CONSUL_HTTP_TOKEN'] = value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
prev[key] = value;
|
prev[key] = value;
|
||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
}, {});
|
}, {});
|
||||||
if (typeof $[key] !== 'undefined') {
|
|
||||||
return $[key];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
case 'production':
|
||||||
|
$ = dev().reduce(function(prev, [key, value]) {
|
||||||
|
switch (key) {
|
||||||
|
case 'TokenSecretID':
|
||||||
|
prev['CONSUL_HTTP_TOKEN'] = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
}, {});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (typeof $[key] !== 'undefined') {
|
||||||
|
return $[key];
|
||||||
}
|
}
|
||||||
return config[key];
|
return config[key];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue