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>
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import withForbiddenState from 'nomad-ui/mixins/with-forbidden-state';
|
|
import WithModelErrorHandling from 'nomad-ui/mixins/with-model-error-handling';
|
|
import { inject as service } from '@ember/service';
|
|
import RSVP from 'rsvp';
|
|
|
|
export default class AdministrationRoute extends Route.extend(
|
|
withForbiddenState,
|
|
WithModelErrorHandling
|
|
) {
|
|
@service can;
|
|
@service store;
|
|
@service router;
|
|
|
|
beforeModel() {
|
|
if (
|
|
this.can.cannot('list policies') ||
|
|
this.can.cannot('list roles') ||
|
|
this.can.cannot('list tokens') ||
|
|
this.can.cannot('list namespaces')
|
|
) {
|
|
this.router.transitionTo('/jobs');
|
|
}
|
|
}
|
|
|
|
// Load our tokens, roles, and policies
|
|
model() {
|
|
return RSVP.hash({
|
|
policies: this.store.findAll('policy', { reload: true }),
|
|
roles: this.store.findAll('role', { reload: true }),
|
|
tokens: this.store.findAll('token', { reload: true }),
|
|
namespaces: this.store.findAll('namespace', { reload: true }),
|
|
sentinelPolicies: this.can.can('list sentinel-policy')
|
|
? this.store.findAll('sentinel-policy', { reload: true })
|
|
: [],
|
|
});
|
|
}
|
|
|
|
// After model: check for all tokens[].policies and roles[].policies to see if any of them are listed
|
|
// that aren't also in the policies list.
|
|
// If any of them are, unload them from the store — they are orphans.
|
|
afterModel(model) {
|
|
let policies = model.policies;
|
|
let roles = model.roles;
|
|
let tokens = model.tokens;
|
|
|
|
roles.forEach((role) => {
|
|
let orphanedPolicies = [];
|
|
role.policies.forEach((policy) => {
|
|
if (policy && !policies.includes(policy)) {
|
|
orphanedPolicies.push(policy);
|
|
}
|
|
});
|
|
orphanedPolicies.forEach((policy) => {
|
|
role.policies.removeObject(policy);
|
|
if (this.store.peekRecord('policy', policy.id)) {
|
|
this.store.unloadRecord(policy);
|
|
}
|
|
});
|
|
});
|
|
|
|
tokens.forEach((token) => {
|
|
let orphanedPolicies = [];
|
|
token.policies.forEach((policy) => {
|
|
if (policy && !policies.includes(policy)) {
|
|
orphanedPolicies.push(policy);
|
|
}
|
|
});
|
|
orphanedPolicies.forEach((policy) => {
|
|
token.policies.removeObject(policy);
|
|
if (this.store.peekRecord('policy', policy.id)) {
|
|
this.store.unloadRecord(policy);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|