mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
* Gallery allows picking stuff * Small fixes * added sentinel templates * Can set enforcement level on policies * Working on the interactive sentinel dev mode * Very rough development flow on FE * Changed position in gutter menu * More sentinel stuff * PR cleanup: removed testmode, removed unneeded mixins and deps * Heliosification * Index-level sentinel policy deletion and page title fixes * Makes the Canaries sentinel policy real and then comments out the unfinished ones * rename Access Control to Administration in prep for moving Sentinel Policies and Node Pool admin there * Sentinel policies moved within the Administration section * Mirage fixture for sentinel policy endpoints * Description length check and 500 prevention * Sync review PR feedback addressed, implied butons on radio cards * Cull un-used sentinel policies --------- Co-authored-by: Mike Nomitch <mail@mikenomitch.com>
109 lines
2.7 KiB
JavaScript
109 lines
2.7 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
// @ts-check
|
|
import Controller from '@ember/controller';
|
|
import { inject as service } from '@ember/service';
|
|
import { alias } from '@ember/object/computed';
|
|
import { task } from 'ember-concurrency';
|
|
|
|
export default class AccessControlRolesRoleController extends Controller {
|
|
@service notifications;
|
|
@service router;
|
|
@service store;
|
|
|
|
@alias('model.role') role;
|
|
@alias('model.tokens') tokens;
|
|
@alias('model.policies') policies;
|
|
|
|
get newTokenString() {
|
|
return `nomad acl token create -name="<TOKEN_NAME>" -role-name="${this.role.name}" -type=client -ttl=8h`;
|
|
}
|
|
|
|
@task(function* () {
|
|
try {
|
|
yield this.role.deleteRecord();
|
|
yield this.role.save();
|
|
this.notifications.add({
|
|
title: 'Role Deleted',
|
|
color: 'success',
|
|
type: `success`,
|
|
destroyOnClick: false,
|
|
});
|
|
this.router.transitionTo('administration.roles');
|
|
} catch (err) {
|
|
this.notifications.add({
|
|
title: `Error deleting Role ${this.role.name}`,
|
|
message: err,
|
|
color: 'critical',
|
|
sticky: true,
|
|
});
|
|
}
|
|
})
|
|
deleteRole;
|
|
|
|
async refreshTokens() {
|
|
this.tokens = this.store.peekAll('token').filter((token) =>
|
|
token.roles.any((role) => {
|
|
return role.id === decodeURIComponent(this.role.id);
|
|
})
|
|
);
|
|
}
|
|
|
|
@task(function* () {
|
|
try {
|
|
const newToken = this.store.createRecord('token', {
|
|
name: `Example Token for ${this.role.name}`,
|
|
roles: [this.role],
|
|
// New date 10 minutes into the future
|
|
expirationTime: new Date(Date.now() + 10 * 60 * 1000),
|
|
type: 'client',
|
|
});
|
|
yield newToken.save();
|
|
yield this.refreshTokens();
|
|
this.notifications.add({
|
|
title: 'Example Token Created',
|
|
message: `${newToken.secret}`,
|
|
color: 'success',
|
|
timeout: 30000,
|
|
customAction: {
|
|
label: 'Copy to Clipboard',
|
|
action: () => {
|
|
navigator.clipboard.writeText(newToken.secret);
|
|
},
|
|
},
|
|
});
|
|
} catch (err) {
|
|
this.notifications.add({
|
|
title: 'Error creating test token',
|
|
message: err,
|
|
color: 'critical',
|
|
sticky: true,
|
|
});
|
|
}
|
|
})
|
|
createTestToken;
|
|
|
|
@task(function* (token) {
|
|
try {
|
|
yield token.deleteRecord();
|
|
yield token.save();
|
|
yield this.refreshTokens();
|
|
this.notifications.add({
|
|
title: 'Token successfully deleted',
|
|
color: 'success',
|
|
});
|
|
} catch (err) {
|
|
this.notifications.add({
|
|
title: 'Error deleting token',
|
|
message: err,
|
|
color: 'critical',
|
|
sticky: true,
|
|
});
|
|
}
|
|
})
|
|
deleteToken;
|
|
}
|