Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Show error when connection roles fail to update on role create #10980

Merged
merged 3 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/10980.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: better errors on Database secrets engine role create
```
14 changes: 9 additions & 5 deletions ui/app/adapters/database/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ export default ApplicationAdapter.extend({
const backend = snapshot.attr('backend');
const id = snapshot.attr('name');
const db = snapshot.attr('database');
await this._updateAllowedRoles(store, {
role: id,
backend,
db: db[0],
});
try {
await this._updateAllowedRoles(store, {
role: id,
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(() => {
// ember data doesn't like 204s if it's not a DELETE
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/database-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SHOW_ROUTE = 'vault.cluster.secrets.backend.show';

const getErrorMessage = errors => {
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 =
'There was a verification error for this connection. Check the Vault logs for more information.';
}
Expand Down
45 changes: 21 additions & 24 deletions ui/app/components/database-role-edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
Expand All @@ -9,6 +10,8 @@ export default class DatabaseRoleEdit extends Component {
@service router;
@service flashMessages;

@tracked loading = false;

get warningMessages() {
let warnings = {};
if (this.args.model.canUpdateDb === false) {
Expand Down Expand Up @@ -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
handleCreateEditRole(evt) {
evt.preventDefault();
this.loading = true;

const mode = this.args.mode;
let roleSecret = this.args.model;
let secretId = roleSecret.name;
Expand All @@ -82,12 +70,21 @@ export default class DatabaseRoleEdit extends Component {
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);
}
});
roleSecret
.save()
.then(() => {
try {
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;
});
}
}
4 changes: 2 additions & 2 deletions ui/app/templates/components/database-role-edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
<button
data-test-secret-save
type="submit"
{{!-- disabled={{this.missingFields}} // TODO validation --}}
class="button is-primary"
disabled={{this.loading}}
class="button is-primary {{if this.loading 'is-loading'}}"
>
Save
</button>
Expand Down