From 350586816520e534e3d7f80f21e578d9a2db954a Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:18:57 -0400 Subject: [PATCH] backport of UI: handle control group error on SSH (#23034) Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> --- changelog/23025.txt | 3 +++ ui/app/components/generate-credentials.js | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 changelog/23025.txt diff --git a/changelog/23025.txt b/changelog/23025.txt new file mode 100644 index 000000000..5392c75f7 --- /dev/null +++ b/changelog/23025.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui (enterprise): Fix error message when generating SSH credential with control group +``` \ No newline at end of file diff --git a/ui/app/components/generate-credentials.js b/ui/app/components/generate-credentials.js index 055d67878..a44a806d0 100644 --- a/ui/app/components/generate-credentials.js +++ b/ui/app/components/generate-credentials.js @@ -31,6 +31,7 @@ const MODEL_TYPES = { }; export default Component.extend({ + controlGroup: service(), store: service(), router: service(), // set on the component @@ -95,10 +96,23 @@ export default Component.extend({ create() { const model = this.model; this.set('loading', true); - this.model.save().finally(() => { - model.set('hasGenerated', true); - this.set('loading', false); - }); + this.model + .save() + .then(() => { + model.set('hasGenerated', true); + }) + .catch((error) => { + // Handle control group AdapterError + if (error.message === 'Control Group encountered') { + this.controlGroup.saveTokenFromError(error); + const err = this.controlGroup.logFromError(error); + error.errors = [err.content]; + } + throw error; + }) + .finally(() => { + this.set('loading', false); + }); }, codemirrorUpdated(attr, val, codemirror) {