mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-31 18:48:08 +00:00
UI: Show error when connection roles fail to update on role create (#10980)
* Show error when connection roles fail to update on role create * Clean up errors for role, remove bad state setting after transition * Add changelog
This commit is contained in:
3
changelog/10980.txt
Normal file
3
changelog/10980.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:improvement
|
||||||
|
ui: better errors on Database secrets engine role create
|
||||||
|
```
|
||||||
@@ -127,11 +127,15 @@ export default ApplicationAdapter.extend({
|
|||||||
const backend = snapshot.attr('backend');
|
const backend = snapshot.attr('backend');
|
||||||
const id = snapshot.attr('name');
|
const id = snapshot.attr('name');
|
||||||
const db = snapshot.attr('database');
|
const db = snapshot.attr('database');
|
||||||
await this._updateAllowedRoles(store, {
|
try {
|
||||||
role: id,
|
await this._updateAllowedRoles(store, {
|
||||||
backend,
|
role: id,
|
||||||
db: db[0],
|
backend,
|
||||||
});
|
db: db[0],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error('Could not update allowed roles for selected database. Check Vault logs for details');
|
||||||
|
}
|
||||||
|
|
||||||
return this.ajax(this.urlFor(backend, id, roleType), 'POST', { data }).then(() => {
|
return this.ajax(this.urlFor(backend, id, roleType), 'POST', { data }).then(() => {
|
||||||
// ember data doesn't like 204s if it's not a DELETE
|
// ember data doesn't like 204s if it's not a DELETE
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
|
|||||||
|
|
||||||
const getErrorMessage = errors => {
|
const getErrorMessage = errors => {
|
||||||
let errorMessage = errors?.join('. ') || 'Something went wrong. Check the Vault logs for more information.';
|
let errorMessage = errors?.join('. ') || 'Something went wrong. Check the Vault logs for more information.';
|
||||||
if (errors?.join(' ').indexOf('failed to verify')) {
|
if (errorMessage.indexOf('failed to verify') >= 0) {
|
||||||
errorMessage =
|
errorMessage =
|
||||||
'There was a verification error for this connection. Check the Vault logs for more information.';
|
'There was a verification error for this connection. Check the Vault logs for more information.';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import Component from '@glimmer/component';
|
import Component from '@glimmer/component';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { action } from '@ember/object';
|
import { action } from '@ember/object';
|
||||||
|
import { tracked } from '@glimmer/tracking';
|
||||||
|
|
||||||
const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root';
|
const LIST_ROOT_ROUTE = 'vault.cluster.secrets.backend.list-root';
|
||||||
const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
|
const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';
|
||||||
@@ -9,6 +10,8 @@ export default class DatabaseRoleEdit extends Component {
|
|||||||
@service router;
|
@service router;
|
||||||
@service flashMessages;
|
@service flashMessages;
|
||||||
|
|
||||||
|
@tracked loading = false;
|
||||||
|
|
||||||
get warningMessages() {
|
get warningMessages() {
|
||||||
let warnings = {};
|
let warnings = {};
|
||||||
if (this.args.model.canUpdateDb === false) {
|
if (this.args.model.canUpdateDb === false) {
|
||||||
@@ -54,26 +57,11 @@ export default class DatabaseRoleEdit extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
handleCreateRole(evt) {
|
|
||||||
evt.preventDefault();
|
|
||||||
let roleSecret = this.args.model;
|
|
||||||
let secretId = roleSecret.name;
|
|
||||||
roleSecret.set('id', secretId);
|
|
||||||
let path = roleSecret.type === 'static' ? 'static-roles' : 'roles';
|
|
||||||
roleSecret.set('path', path);
|
|
||||||
roleSecret.save().then(() => {
|
|
||||||
try {
|
|
||||||
this.router.transitionTo(SHOW_ROUTE, `role/${secretId}`);
|
|
||||||
} catch (e) {
|
|
||||||
console.debug(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
handleCreateEditRole(evt) {
|
handleCreateEditRole(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
const mode = this.args.mode;
|
const mode = this.args.mode;
|
||||||
let roleSecret = this.args.model;
|
let roleSecret = this.args.model;
|
||||||
let secretId = roleSecret.name;
|
let secretId = roleSecret.name;
|
||||||
@@ -82,12 +70,21 @@ export default class DatabaseRoleEdit extends Component {
|
|||||||
let path = roleSecret.type === 'static' ? 'static-roles' : 'roles';
|
let path = roleSecret.type === 'static' ? 'static-roles' : 'roles';
|
||||||
roleSecret.set('path', path);
|
roleSecret.set('path', path);
|
||||||
}
|
}
|
||||||
roleSecret.save().then(() => {
|
roleSecret
|
||||||
try {
|
.save()
|
||||||
this.router.transitionTo(SHOW_ROUTE, `role/${secretId}`);
|
.then(() => {
|
||||||
} catch (e) {
|
try {
|
||||||
console.debug(e);
|
this.router.transitionTo(SHOW_ROUTE, `role/${secretId}`);
|
||||||
}
|
} catch (e) {
|
||||||
});
|
console.debug(e);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,8 +105,8 @@
|
|||||||
<button
|
<button
|
||||||
data-test-secret-save
|
data-test-secret-save
|
||||||
type="submit"
|
type="submit"
|
||||||
{{!-- disabled={{this.missingFields}} // TODO validation --}}
|
disabled={{this.loading}}
|
||||||
class="button is-primary"
|
class="button is-primary {{if this.loading 'is-loading'}}"
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user