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:
Chelsea Shaw
2021-02-23 10:47:02 -06:00
committed by GitHub
parent 76584d2749
commit 5b68724e31
5 changed files with 36 additions and 32 deletions

3
changelog/10980.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
ui: better errors on Database secrets engine role create
```

View File

@@ -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');
try {
await this._updateAllowedRoles(store, { await this._updateAllowedRoles(store, {
role: id, role: id,
backend, backend,
db: db[0], 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

View File

@@ -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.';
} }

View File

@@ -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
.save()
.then(() => {
try { try {
this.router.transitionTo(SHOW_ROUTE, `role/${secretId}`); this.router.transitionTo(SHOW_ROUTE, `role/${secretId}`);
} catch (e) { } catch (e) {
console.debug(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;
}); });
} }
} }

View File

@@ -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>