Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Monkeychip committed Jan 9, 2025
1 parent 2a454cd commit b8718fd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
18 changes: 11 additions & 7 deletions ui/app/components/secret-engine/configure-create-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import type FlashMessageService from 'vault/services/flash-messages';
* @param {string} type - The type of the engine, ex: 'azure'
* @param {object} model - The config model for the engine.
* @param {object} [secondModel] - For engines with two config models. Currently, only used by aws (lease and root config).
* @param {object} [issuerConfigModel] - the identity/oidc/config model. relevant only to wif engines.
* @param {object} [issuerConfig] - The identity/oidc/config model. Will be passed in if user has an enterprise license.
* @param {string} [displayTitle="Additional Configuration"] - Specific title to display above the second modal.
*/

Expand Down Expand Up @@ -133,11 +133,15 @@ export default class ConfigureCreateEdit extends Component<Args> {

const modelSaved = modelAttrChanged ? await this.saveModel() : false;
const issuerSaved = issuerAttrChanged ? await this.updateIssuer() : false;
const leaseSaved = secondModelAttrChanged ? await this.saveSecondModel() : false;

if (modelSaved || (!modelAttrChanged && issuerSaved) || leaseSaved) {
// transition if either of the models were saved successfully
// we only prevent a transition if the model(s) are edited and fail when saving
const secondModel = secondModelAttrChanged ? await this.saveSecondModel() : false;

if (modelSaved || (!modelAttrChanged && issuerSaved)) {
// if there is a secondModel, attempt to save it. If it fails, we should still transition and the failure will surface as a sticky flash message.
if (secondModelAttrChanged) {
await this.saveSecondModel();
}
// transition if first model or issuer are saved successfully
// we only prevent a transition if the first model or issuer are edited and fail when saving
this.transition();
} else {
// otherwise there was a failure and we should not transition and exit the function
Expand Down Expand Up @@ -180,7 +184,7 @@ export default class ConfigureCreateEdit extends Component<Args> {
return true;
} catch (error) {
this.errorMessage = errorMessage(error);
// show a flash message and no invalidForm alert. Only if the first modal fails will we prevent transition so display error via flash message as it's likely they'll transition.
// We will transition even if the second model fails. Surface a sticky flash message to the user that they can see on the next view.
this.flashMessages.danger(`Lease configuration was not saved: ${this.errorMessage}`, {
sticky: true,
});
Expand Down
2 changes: 1 addition & 1 deletion ui/app/helpers/string-to-camel-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { helper as buildHelper } from '@ember/component/helper';

// This helper turns strings with spaces into camelCase strings, example: 'hello world' -> 'helloWorld'
// If an array of strings is passed, this helper returns an array of camelCase strings.
// Taken from slackOverflow, doesn't handle accented characters. https://stackoverflow.com/questions/2970525/converting-a-string-with-spaces-into-camel-case?page=1&tab=scoredesc#tab-top
// Does not handle accented characters
export function stringToCamelCase(str) {
if (Array.isArray(str)) {
return str.map((s) => {
Expand Down
1 change: 0 additions & 1 deletion ui/app/models/azure/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default class AzureConfig extends Model {

get isConfigured() {
// if every value is falsy, this engine has not been configured yet
// doing this here because the API does not return the clientSecret
return !this.configurableParams.every((param) => !this[param]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export default class SecretsBackendConfigurationEdit extends Route {
@service declare readonly version: VersionService;

standardizedModelName(type: string, adapterPath: string) {
// we return first-model if there is only one model or the adapterPath is the first model listed
// otherwise we return second-model
if (
CONFIG_ADAPTERS_PATHS[type] &&
CONFIG_ADAPTERS_PATHS[type].length > 1 &&
Expand All @@ -48,6 +46,7 @@ export default class SecretsBackendConfigurationEdit extends Route {
const secretEngineRecord = this.modelFor('vault.cluster.secrets.backend') as SecretEngineModel;
const type = secretEngineRecord.type;
const displayName = allEngines().find((engine) => engine.type === type)?.displayName;
const isWifEngine = WIF_ENGINES.includes(type);

// if the engine type is not configurable, return a 404.
if (!secretEngineRecord || !CONFIGURABLE_SECRET_ENGINES.includes(type)) {
Expand Down Expand Up @@ -97,7 +96,7 @@ export default class SecretsBackendConfigurationEdit extends Route {
}
// if the type is a WIF engine and it's enterprise, we also fetch the issuer
// from a global endpoint which has no associated model/adapter
if (WIF_ENGINES.includes(type) && this.version.isEnterprise) {
if (isWifEngine && this.version.isEnterprise) {
try {
const response = await this.store.queryRecord('identity/oidc/config', {});
model['identity-oidc-config'] = response;
Expand All @@ -106,8 +105,8 @@ export default class SecretsBackendConfigurationEdit extends Route {
model['identity-oidc-config'] = { queryIssuerError: true };
}
}
// add displayName to the model
model['displayName'] = displayName;
model['isWifEngine'] = isWifEngine;
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
</ToolbarLink>
</ToolbarActions>
</Toolbar>
{{! Currently all WIF configurable engines are covered under one component. SSH is not a WIF engine and has a different workflow deserving of its own component }}

{{#if (eq this.model.type "ssh")}}
<SecretEngine::ConfigureSsh @model={{this.model.first-model}} @id={{this.model.id}} />
{{else}}
{{! This check is preventive. As of writing all other engines using this route——but ssh——are wif engines }}
{{else if this.model.isWifEngine}}
<SecretEngine::ConfigureCreateEdit
@backendPath={{this.model.id}}
@displayName={{this.model.displayName}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module('Acceptance | aws | configuration', function (hooks) {
assert.strictEqual(
this.flashSuccessSpy.args[1][0],
`Successfully saved ${path}'s configuration.`,
'first flash message about the aws root config.'
'first flash message about the root config.'
);
assert.strictEqual(
this.flashSuccessSpy.args[2][0],
Expand Down Expand Up @@ -159,7 +159,7 @@ module('Acceptance | aws | configuration', function (hooks) {
await fillInAwsConfig('withAccess');
await click(GENERAL.saveButton);
assert.true(
this.flashSuccessSpy.calledWith(`Successfully saved ${path}'s configuration.`),
this.flashSuccessSpy.calledWith(`Successfully saved ${path}'s root configuration.`),
'Success flash message is rendered showing the root configuration was saved.'
);
assert.dom(GENERAL.infoRowValue('Access key')).hasText('foo', 'Access Key has been set.');
Expand Down

0 comments on commit b8718fd

Please sign in to comment.