mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 11:37:04 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
123 lines
3.4 KiB
JavaScript
123 lines
3.4 KiB
JavaScript
/**
|
||
* Copyright (c) HashiCorp, Inc.
|
||
* SPDX-License-Identifier: BUSL-1.1
|
||
*/
|
||
|
||
import Component from '@glimmer/component';
|
||
import { inject as service } from '@ember/service';
|
||
import { action } from '@ember/object';
|
||
import { tracked } from '@glimmer/tracking';
|
||
|
||
const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root';
|
||
const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
|
||
|
||
export default class DatabaseRoleEdit extends Component {
|
||
@service router;
|
||
@service flashMessages;
|
||
@service store;
|
||
|
||
constructor() {
|
||
super(...arguments);
|
||
if (this.args.initialKey) {
|
||
this.args.model.database = [this.args.initialKey];
|
||
}
|
||
}
|
||
|
||
@tracked loading = false;
|
||
|
||
get warningMessages() {
|
||
const warnings = {};
|
||
if (this.args.model.canUpdateDb === false) {
|
||
warnings.database = `You don’t have permissions to update this database connection, so this role cannot be created.`;
|
||
}
|
||
if (
|
||
(this.args.model.type === 'dynamic' && this.args.model.canCreateDynamic === false) ||
|
||
(this.args.model.type === 'static' && this.args.model.canCreateStatic === false)
|
||
) {
|
||
warnings.type = `You don't have permissions to create this type of role.`;
|
||
}
|
||
return warnings;
|
||
}
|
||
|
||
get databaseType() {
|
||
const backend = this.args.model?.backend;
|
||
const dbs = this.args.model?.database || [];
|
||
if (!backend || dbs.length === 0) {
|
||
return null;
|
||
}
|
||
return this.store
|
||
.queryRecord('database/connection', { id: dbs[0], backend })
|
||
.then((record) => record.plugin_name)
|
||
.catch(() => null);
|
||
}
|
||
|
||
@action
|
||
generateCreds(roleId, roleType = '') {
|
||
this.router.transitionTo('vault.cluster.secrets.backend.credentials', roleId, {
|
||
queryParams: { roleType },
|
||
});
|
||
}
|
||
|
||
@action
|
||
delete() {
|
||
const secret = this.args.model;
|
||
const backend = secret.backend;
|
||
return secret
|
||
.destroyRecord()
|
||
.then(() => {
|
||
try {
|
||
this.router.transitionTo(LIST_ROOT_ROUTE, backend, { queryParams: { tab: 'role' } });
|
||
} catch (e) {
|
||
console.debug(e); // eslint-disable-line
|
||
}
|
||
})
|
||
.catch((e) => {
|
||
this.flashMessages.danger(e.errors?.join('. '));
|
||
});
|
||
}
|
||
|
||
@action
|
||
handleCreateEditRole(evt) {
|
||
evt.preventDefault();
|
||
this.loading = true;
|
||
|
||
const mode = this.args.mode;
|
||
const roleSecret = this.args.model;
|
||
const secretId = roleSecret.name;
|
||
if (mode === 'create') {
|
||
roleSecret.set('id', secretId);
|
||
const path = roleSecret.type === 'static' ? 'static-roles' : 'roles';
|
||
roleSecret.set('path', path);
|
||
}
|
||
return roleSecret
|
||
.save()
|
||
.then(() => {
|
||
try {
|
||
this.router.transitionTo(SHOW_ROUTE, `role/${secretId}`);
|
||
} catch (e) {
|
||
console.debug(e); // eslint-disable-line
|
||
}
|
||
})
|
||
.catch((e) => {
|
||
const errorMessage = e.errors?.join('. ') || e.message;
|
||
this.flashMessages.danger(
|
||
errorMessage || 'Could not save the role. Please check Vault logs for more information.'
|
||
);
|
||
this.loading = false;
|
||
});
|
||
}
|
||
@action
|
||
rotateRoleCred(id) {
|
||
const backend = this.args.model?.backend;
|
||
const adapter = this.store.adapterFor('database/credential');
|
||
return adapter
|
||
.rotateRoleCredentials(backend, id)
|
||
.then(() => {
|
||
this.flashMessages.success(`Success: Credentials for ${id} role were rotated`);
|
||
})
|
||
.catch((e) => {
|
||
this.flashMessages.danger(e.errors);
|
||
});
|
||
}
|
||
}
|