Cleanup app boot by using hcp service

This commit is contained in:
Michael Klein 2022-10-18 16:16:42 +02:00
parent 163f8b9057
commit e856a2c5c5
1 changed files with 2 additions and 26 deletions

View File

@ -1,43 +1,19 @@
import Route from 'consul-ui/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { runInDebug } from '@ember/debug';
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
export default class ApplicationRoute extends Route.extend(WithBlockingActions) {
@service('client/http') client;
@service('env') env;
@service('repository/token') tokenRepo;
@service('settings') settings;
@service() hcp;
data;
async model() {
if (this.env.var('CONSUL_ACLS_ENABLED')) {
const secret = this.env.var('CONSUL_HTTP_TOKEN');
if (secret) {
const existing = await this.settings.findBySlug('token');
if (secret && secret !== existing.SecretID) {
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));
}
}
}
await this.hcp.updateTokenIfNecessary(this.env.var('CONSUL_HTTP_TOKEN'));
}
return {};
}