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: Enable KV create secret with Control Group #22471

Merged
merged 6 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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/22471.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: enables create and update KV secret workflow when control group present
```
9 changes: 8 additions & 1 deletion ui/app/components/secret-create-or-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class SecretCreateOrUpdate extends Component {
@tracked validationMessages = null;

@service controlGroup;
@service flashMessages;
@service router;
@service store;

Expand Down Expand Up @@ -163,6 +164,7 @@ export default class SecretCreateOrUpdate extends Component {
if (error instanceof ControlGroupError) {
const errorMessage = this.controlGroup.logFromError(error);
this.error = errorMessage.content;
this.controlGroup.saveTokenFromError(error);
}
throw error;
});
Expand Down Expand Up @@ -233,8 +235,13 @@ export default class SecretCreateOrUpdate extends Component {
return;
}

const secretPath = type === 'create' ? this.args.modelForData.path : this.args.model.id;
this.persistKey(() => {
this.transitionToRoute(SHOW_ROUTE, this.args.model.path || this.args.model.id);
// Show flash message in case there's a control group on read
this.flashMessages.success(
`Secret ${secretPath} ${type === 'create' ? 'created' : 'updated'} successfully.`
);
this.transitionToRoute(SHOW_ROUTE, secretPath);
});
}
@action
Expand Down
12 changes: 12 additions & 0 deletions ui/app/services/control-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export default Service.extend({
return this.router.transitionTo('vault.cluster.access.control-group-accessor', accessor);
},

// Handle error from non-read request (eg. POST or UPDATE) so it can be retried
saveTokenFromError(error) {
const { accessor, token, creation_path, creation_time, ttl } = error;
const data = { accessor, token, creation_path, creation_time, ttl };
// data.uiParams = { url: this.router.currentURL };
hashishaw marked this conversation as resolved.
Show resolved Hide resolved
hashishaw marked this conversation as resolved.
Show resolved Hide resolved
this.storeControlGroupToken(data);
// In the read flow the accessor is marked once the user clicks "Visit" from the control group page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for these comments!

// On a POST/UPDATE flow we don't redirect, so we need to mark automatically so that on the next try
// the request will attempt unwrap.
this.markTokenForUnwrap(accessor);
},

logFromError(error) {
const { accessor, token, creation_path, creation_time, ttl } = error;
const data = { accessor, token, creation_path, creation_time, ttl };
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/secret-create-or-update.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<div class="control">
<button
type="submit"
disabled={{or @buttonDisabled this.validationErrorCount this.error}}
disabled={{or @buttonDisabled this.validationErrorCount}}
hashishaw marked this conversation as resolved.
Show resolved Hide resolved
class="button is-primary"
data-test-secret-save={{true}}
>
Expand Down