Fix `TokenSecretID`-handling

This commit is contained in:
Michael Klein 2022-10-18 16:07:48 +02:00
parent 12a923c658
commit 955949998f
1 changed files with 20 additions and 17 deletions

View File

@ -16,23 +16,26 @@ export default class ApplicationRoute extends Route.extend(WithBlockingActions)
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));
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));
}
}
}
}