-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
LDAP Configure Page Component #21384
Merged
zofskeez
merged 2 commits into
ui/VAULT-12945/ldap-secrets-engine
from
ui/VAULT-17265/ldap-config-form
Jun 21, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<PageHeader as |p|> | ||
<p.top> | ||
<Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} /> | ||
</p.top> | ||
<p.levelLeft> | ||
<h1 class="title is-3">Configure LDAP</h1> | ||
</p.levelLeft> | ||
</PageHeader> | ||
|
||
<hr class="is-marginless has-background-gray-200" /> | ||
|
||
<form class="has-top-margin-l" {{on "submit" (perform this.save)}}> | ||
<Hds::Form::RadioCard::Group @name="schema options" as |RadioGroup|> | ||
{{#each this.schemaOptions as |option|}} | ||
<RadioGroup.RadioCard | ||
@checked={{eq option.value @model.schema}} | ||
{{on "change" (fn (mut @model.schema) option.value)}} | ||
data-test-radio-card={{option.title}} | ||
as |Card| | ||
> | ||
<Card.Icon @name={{option.icon}} /> | ||
<Card.Label>{{option.title}}</Card.Label> | ||
<Card.Description>{{option.description}}</Card.Description> | ||
</RadioGroup.RadioCard> | ||
{{/each}} | ||
</Hds::Form::RadioCard::Group> | ||
|
||
<div class="has-top-margin-xl"> | ||
<MessageError @errorMessage={{this.error}} /> | ||
|
||
<h2 class="title is-4">Schema Options</h2> | ||
<hr class="has-background-gray-200" /> | ||
|
||
{{#if @model.schema}} | ||
<div class="has-top-margin-l"> | ||
<FormFieldGroups @model={{@model}} @groupName="formFieldGroups" @modelValidations={{this.modelValidations}} /> | ||
</div> | ||
{{else}} | ||
<EmptyState | ||
class="is-shadowless has-top-margin-l" | ||
@title="Choose an option" | ||
@message="Pick an option above to see available configuration options" | ||
/> | ||
{{/if}} | ||
</div> | ||
|
||
<hr class="has-background-gray-200 has-top-margin-l" /> | ||
|
||
<div class="has-top-margin-l has-bottom-margin-l is-flex"> | ||
<button | ||
data-test-config-save | ||
class="button is-primary" | ||
type="submit" | ||
disabled={{or this.save.isRunning (not @model.schema)}} | ||
{{on "click" (perform this.save)}} | ||
> | ||
Save | ||
</button> | ||
<button | ||
data-test-config-cancel | ||
class="button has-left-margin-xs" | ||
type="button" | ||
disabled={{or this.save.isRunning this.fetchInferred.isRunning}} | ||
{{on "click" this.cancel}} | ||
> | ||
Back | ||
</button> | ||
{{#if this.invalidFormMessage}} | ||
<AlertInline | ||
@type="danger" | ||
@paddingTop={{true}} | ||
@message={{this.invalidFormMessage}} | ||
@mimicRefresh={{true}} | ||
data-test-invalid-form-message | ||
/> | ||
{{/if}} | ||
</div> | ||
</form> | ||
|
||
{{#if this.showRotatePrompt}} | ||
<Modal | ||
@title="Rotate your root password?" | ||
@type="info" | ||
@isActive={{this.showRotatePrompt}} | ||
@showCloseButton={{true}} | ||
@onClose={{fn (mut this.showRotatePrompt) false}} | ||
> | ||
<section class="modal-card-body"> | ||
<p> | ||
It’s best practice to rotate the administrator (root) password immediately after the initial configuration of the | ||
LDAP engine. The rotation will update the password both in Vault and your directory server. Once rotated, | ||
<span class="has-text-weight-semibold">only Vault knows the new root password.</span> | ||
</p> | ||
<br /> | ||
<p> | ||
Would you like to rotate your new credentials? You can also do this later. | ||
</p> | ||
</section> | ||
<footer class="modal-card-foot modal-card-foot-outlined"> | ||
<button | ||
data-test-save-with-rotate | ||
type="button" | ||
class="button is-primary" | ||
{{on "click" (fn (perform this.save) null true)}} | ||
> | ||
Save and rotate | ||
</button> | ||
<button data-test-save-without-rotate type="button" class="button" {{on "click" (fn (perform this.save) null false)}}> | ||
Save without rotating | ||
</button> | ||
</footer> | ||
</Modal> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import { task } from 'ember-concurrency'; | ||
import { waitFor } from '@ember/test-waiters'; | ||
import errorMessage from 'vault/utils/error-message'; | ||
|
||
import type LdapConfigModel from 'vault/models/ldap/config'; | ||
import { Breadcrumb, ValidationMap } from 'vault/vault/app-types'; | ||
import type FlashMessageService from 'vault/services/flash-messages'; | ||
import type RouterService from '@ember/routing/router-service'; | ||
|
||
interface Args { | ||
model: LdapConfigModel; | ||
breadcrumbs: Array<Breadcrumb>; | ||
} | ||
interface SchemaOption { | ||
title: string; | ||
icon: string; | ||
description: string; | ||
value: string; | ||
} | ||
|
||
export default class LdapConfigurePageComponent extends Component<Args> { | ||
@service declare readonly flashMessages: FlashMessageService; | ||
@service declare readonly router: RouterService; | ||
|
||
@tracked showRotatePrompt = false; | ||
@tracked modelValidations: ValidationMap | null = null; | ||
@tracked invalidFormMessage = ''; | ||
@tracked error = ''; | ||
|
||
get schemaOptions(): Array<SchemaOption> { | ||
return [ | ||
{ | ||
title: 'OpenLDAP', | ||
icon: 'folder', | ||
description: | ||
'OpenLDAP is one of the most popular open source directory service developed by the OpenLDAP Project.', | ||
value: 'openldap', | ||
}, | ||
{ | ||
title: 'AD', | ||
icon: 'microsoft', | ||
description: | ||
'Active Directory is a directory service developed by Microsoft for Windows domain networks.', | ||
value: 'ad', | ||
}, | ||
{ | ||
title: 'RACF', | ||
icon: 'users', | ||
description: | ||
"For managing IBM's Resource Access Control Facility (RACF) security system, the generated passwords must be 8 characters or less.", | ||
value: 'racf', | ||
}, | ||
]; | ||
} | ||
|
||
leave(route: string) { | ||
this.router.transitionTo(`vault.cluster.secrets.backend.ldap.${route}`); | ||
} | ||
|
||
validate() { | ||
const { isValid, state, invalidFormMessage } = this.args.model.validate(); | ||
this.modelValidations = isValid ? null : state; | ||
this.invalidFormMessage = isValid ? '' : invalidFormMessage; | ||
return isValid; | ||
} | ||
|
||
async rotateRoot() { | ||
try { | ||
await this.args.model.rotateRoot(); | ||
} catch (error) { | ||
// since config save was successful at this point we only want to show the error in a flash message | ||
this.flashMessages.danger(`Error rotating root password \n ${errorMessage(error)}`); | ||
} | ||
} | ||
|
||
@task | ||
@waitFor | ||
*save(event: Event | null, rotate: boolean) { | ||
if (event) { | ||
event.preventDefault(); | ||
} | ||
const isValid = this.validate(); | ||
// show rotate creds prompt for new models when form state is valid | ||
this.showRotatePrompt = isValid && this.args.model.isNew && !this.showRotatePrompt; | ||
|
||
if (isValid && !this.showRotatePrompt) { | ||
try { | ||
yield this.args.model.save(); | ||
// if save was triggered from confirm action in rotate password prompt we need to make an additional request | ||
if (rotate) { | ||
yield this.rotateRoot(); | ||
} | ||
this.flashMessages.success('Successfully configured LDAP engine'); | ||
this.leave('configuration'); | ||
} catch (error) { | ||
this.error = errorMessage(error, 'Error saving configuration. Please try again or contact support'); | ||
} | ||
} | ||
} | ||
|
||
@action | ||
cancel() { | ||
const { model } = this.args; | ||
const transitionRoute = model.isNew ? 'overview' : 'configuration'; | ||
const cleanupMethod = model.isNew ? 'unloadRecord' : 'rollbackAttributes'; | ||
model[cleanupMethod](); | ||
this.leave(transitionRoute); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<Page::Configure @model={{this.model}} @breadcrumbs={{this.breadcrumbs}} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just out of curiosity why does the event need to be
null
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I'm using the
fn
helper to pass in therotate
arg it then pushes theevent
to the second argument. The same method is also triggered on submit where theevent
is the first arg which is needed topreventDefault
so I had to null it out here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 that makes sense! learned something new today :)