Vault SSH Cert Feature (#1596)
* feat: 🎸 Update models for vault ssh cert feature (#1591) ✅ Closes: ICU-7546 * feat: 🎸 Setup types in cred library forms and use HDS component (#1597) * feat: 🎸 Setup types in cred library forms and use HDS component ✅ Closes: ICU-7673 * feat: 🎸 Add vault ssh cert type for credential library (#1608) * feat: 🎸 Add vault ssh cert type for credential library ✅ Closes: ICU-7678 * feat: 🎸 Enable feature flag for vault ssh cert work (#1614) * fix: 🐛 Change fields to optional as they get default by backend (#1615) * Chore/cleanup vault ssh cert (#1616)
This commit is contained in:
1 parent
e3772352ea
commit
f0530e1f8f
34 files changed
+1421
-182
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import CredentialLibraryAbility from 'api/abilities/credential-library';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class OverrideCredentialLibraryAbility extends CredentialLibraryAbility {
|
||||
// =service
|
||||
@service features;
|
||||
|
||||
/**
|
||||
* This override ensures that vault ssh cert may be read only if the
|
||||
* credential-library-vault-ssh-certificate feature flag is enabled.
|
||||
* All other types are subject to the standard logic found in the api addon.
|
||||
*/
|
||||
get canRead() {
|
||||
return this.features.isEnabled(
|
||||
'credential-library-vault-ssh-certificate'
|
||||
) || !this.model.isVaultSSHCertificate
|
||||
? super.canRead
|
||||
: false;
|
||||
}
|
||||
}
|
||||
@@ -1,129 +1,10 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@showEditToggle={{if @model.isNew false true}}
|
||||
as |form|
|
||||
>
|
||||
|
||||
<form.input
|
||||
@value={{@model.type}}
|
||||
@label={{t 'form.type.label'}}
|
||||
readonly={{true}}
|
||||
@disabled={{true}}
|
||||
/>
|
||||
|
||||
<form.input
|
||||
@name='name'
|
||||
@type='name'
|
||||
@value={{@model.name}}
|
||||
@label={{t 'form.name.label'}}
|
||||
@error={{@model.errors.name}}
|
||||
@helperText={{t 'form.name.help'}}
|
||||
disabled={{@model.isSaving}}
|
||||
readonly={{false}}
|
||||
as |field|
|
||||
>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.textarea
|
||||
@name='description'
|
||||
@type='description'
|
||||
@value={{@model.description}}
|
||||
@label={{t 'form.description.label'}}
|
||||
@error={{@model.errors.description}}
|
||||
@helperText={{t 'form.description.help'}}
|
||||
disabled={{@model.isSaving}}
|
||||
readonly={{false}}
|
||||
as |field|
|
||||
>
|
||||
{{#if @model.errors.description}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.description as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.textarea>
|
||||
|
||||
<form.input
|
||||
@name='vault_path'
|
||||
@type='text'
|
||||
@value={{@model.path}}
|
||||
@label={{t 'resources.credential-library.form.vault_path.label'}}
|
||||
@error={{@model.errors.path}}
|
||||
@helperText={{t 'resources.credential-library.form.vault_path.help'}}
|
||||
disabled={{@model.isSaving}}
|
||||
readonly={{false}}
|
||||
as |field|
|
||||
>
|
||||
{{#if @model.errors.path}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.path as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.fieldset>
|
||||
<:title>{{t 'resources.credential-library.form.http_method.label'}}</:title>
|
||||
<:description>
|
||||
{{t 'resources.credential-library.form.http_method.help'}}
|
||||
</:description>
|
||||
<:body>
|
||||
<form.radioGroup
|
||||
@name='http_method'
|
||||
@selectedValue={{@model.http_method}}
|
||||
@changed={{fn (mut @model.http_method)}}
|
||||
@inline={{true}}
|
||||
disabled={{@model.isSaving}}
|
||||
as |radioGroup|
|
||||
>
|
||||
{{#each this.httpMethodOptions as |httpMethod|}}
|
||||
<radioGroup.radio @label={{httpMethod}} @value={{httpMethod}} />
|
||||
{{/each}}
|
||||
</form.radioGroup>
|
||||
</:body>
|
||||
</form.fieldset>
|
||||
|
||||
{{#if this.isHttpRequestBodyAllowed}}
|
||||
<form.textarea
|
||||
@name='http_request_body'
|
||||
@type='text'
|
||||
@value={{@model.http_request_body}}
|
||||
@label={{t 'resources.credential-library.form.http_request_body.label'}}
|
||||
@error={{@model.errors.http_request_body}}
|
||||
@helperText={{t
|
||||
'resources.credential-library.form.http_request_body.help'
|
||||
}}
|
||||
@disabled={{this.cannotSaveHttpRequestBody}}
|
||||
readonly={{false}}
|
||||
as |field|
|
||||
>
|
||||
{{#if @model.errors.http_request_body}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.http_request_body as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.textarea>
|
||||
{{/if}}
|
||||
|
||||
{{#if (can 'save model' @model)}}
|
||||
<form.actions
|
||||
@enableEditText={{t 'actions.edit-form'}}
|
||||
@submitText={{t 'actions.save'}}
|
||||
@cancelText={{t 'actions.cancel'}}
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
</Rose::Form>
|
||||
{{#if @model.type}}
|
||||
{{component
|
||||
(concat 'form/credential-library/' @model.type)
|
||||
model=@model
|
||||
submit=@submit
|
||||
cancel=@cancel
|
||||
changeType=@changeType
|
||||
edit=@edit
|
||||
}}
|
||||
{{/if}}
|
||||
@@ -0,0 +1,169 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@showEditToggle={{if @model.isNew false true}}
|
||||
as |form|
|
||||
>
|
||||
<Hds::Form::TextInput::Field
|
||||
@isRequired={{false}}
|
||||
@isOptional={{true}}
|
||||
@value={{@model.name}}
|
||||
@isInvalid={{@model.errors.name}}
|
||||
@type='text'
|
||||
name='name'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'name')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'form.name.label'}}</F.Label>
|
||||
<F.HelperText>{{t 'form.name.help'}}</F.HelperText>
|
||||
{{#if @model.errors.name}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Hds::Form::Textarea::Field
|
||||
@isRequired={{false}}
|
||||
@isOptional={{true}}
|
||||
@value={{@model.description}}
|
||||
@isInvalid={{@model.errors.description}}
|
||||
name='description'
|
||||
disabled={{form.disabled}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'form.description.label'}}</F.Label>
|
||||
<F.HelperText>{{t 'form.description.help'}}</F.HelperText>
|
||||
{{#if @model.errors.description}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.description as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::Textarea::Field>
|
||||
|
||||
{{#if
|
||||
(and @model.isNew (feature-flag 'credential-library-vault-ssh-certificate'))
|
||||
}}
|
||||
<Hds::Form::RadioCard::Group @name='type' @alignment='center' as |G|>
|
||||
<G.Legend>{{t 'form.type.label'}}</G.Legend>
|
||||
{{#each this.types as |type|}}
|
||||
<G.RadioCard
|
||||
@value={{type}}
|
||||
@maxWidth='20rem'
|
||||
@checked={{eq type @model.type}}
|
||||
{{on 'input' (fn @changeType type)}}
|
||||
as |R|
|
||||
>
|
||||
<R.Label>{{t
|
||||
(concat 'resources.credential-library.types.' type)
|
||||
}}</R.Label>
|
||||
<R.Description>{{t
|
||||
(concat 'resources.credential-library.help.' type)
|
||||
}}</R.Description>
|
||||
</G.RadioCard>
|
||||
{{/each}}
|
||||
</Hds::Form::RadioCard::Group>
|
||||
{{else}}
|
||||
<InfoField
|
||||
@value={{t (concat 'resources.credential-library.types.' @model.type)}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'form.type.label'}}</F.Label>
|
||||
<F.HelperText>
|
||||
{{t (concat 'resources.credential-library.help.' @model.type)}}
|
||||
</F.HelperText>
|
||||
</InfoField>
|
||||
{{/if}}
|
||||
|
||||
<Hds::Form::TextInput::Field
|
||||
@isRequired={{true}}
|
||||
@isOptional={{false}}
|
||||
@value={{@model.path}}
|
||||
@isInvalid={{@model.errors.path}}
|
||||
@type='text'
|
||||
name='vault_path'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'path')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t
|
||||
'resources.credential-library.form.vault_path.label'
|
||||
}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.vault_path.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.path}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.path as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Hds::Form::Radio::Group
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'http_method')}}
|
||||
@isRequired={{true}}
|
||||
@layout='horizontal'
|
||||
@name='http_method'
|
||||
as |G|
|
||||
>
|
||||
<G.Legend>
|
||||
{{t 'resources.credential-library.form.http_method.label'}}
|
||||
</G.Legend>
|
||||
<G.HelperText>
|
||||
{{t 'resources.credential-library.form.http_method.help'}}
|
||||
</G.HelperText>
|
||||
{{#each this.httpMethodOptions as |httpMethod|}}
|
||||
<G.Radio::Field
|
||||
checked={{eq @model.http_method httpMethod}}
|
||||
@value={{httpMethod}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{httpMethod}}</F.Label>
|
||||
</G.Radio::Field>
|
||||
{{/each}}
|
||||
</Hds::Form::Radio::Group>
|
||||
|
||||
{{#if this.isHttpRequestBodyAllowed}}
|
||||
<Hds::Form::Textarea::Field
|
||||
@isRequired={{true}}
|
||||
@isOptional={{false}}
|
||||
@value={{@model.http_request_body}}
|
||||
@isInvalid={{@model.errors.http_request_body}}
|
||||
name='http_request_body'
|
||||
disabled={{form.disabled}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t
|
||||
'resources.credential-library.form.http_request_body.label'
|
||||
}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.http_request_body.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.http_request_body}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.http_request_body as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::Textarea::Field>
|
||||
{{/if}}
|
||||
|
||||
{{#if (can 'save model' @model)}}
|
||||
<form.actions
|
||||
@enableEditText={{t 'actions.edit-form'}}
|
||||
@submitText={{t 'actions.save'}}
|
||||
@cancelText={{t 'actions.cancel'}}
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
</Rose::Form>
|
||||
+11
-4
@@ -1,19 +1,26 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { options } from 'api/models/credential-library';
|
||||
import { computed } from '@ember/object';
|
||||
import {
|
||||
options,
|
||||
TYPES_CREDENTIAL_LIBRARY,
|
||||
} from 'api/models/credential-library';
|
||||
|
||||
export default class FormCredentialLibraryIndexComponent extends Component {
|
||||
export default class FormCredentialLibraryVaultGenericComponent extends Component {
|
||||
// =properties
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
httpMethodOptions = options.http_method;
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
types = TYPES_CREDENTIAL_LIBRARY;
|
||||
|
||||
/**
|
||||
* Only allow HTTP request body field if http_method is set to POST.
|
||||
* @type {boolean}
|
||||
*/
|
||||
@computed('args.model.http_method')
|
||||
get isHttpRequestBodyAllowed() {
|
||||
return this.args.model.http_method?.match(/post/i);
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
<Rose::Form
|
||||
@edit={{@edit}}
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@showEditToggle={{if @model.isNew false true}}
|
||||
as |form|
|
||||
>
|
||||
<Hds::Form::TextInput::Field
|
||||
@isOptional={{true}}
|
||||
@value={{@model.name}}
|
||||
@isInvalid={{@model.errors.name}}
|
||||
@type='text'
|
||||
name='name'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'name')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'form.name.label'}}</F.Label>
|
||||
<F.HelperText>{{t 'form.name.help'}}</F.HelperText>
|
||||
{{#if @model.errors.name}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Hds::Form::Textarea::Field
|
||||
@isOptional={{true}}
|
||||
@value={{@model.description}}
|
||||
@isInvalid={{@model.errors.description}}
|
||||
name='description'
|
||||
disabled={{form.disabled}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'form.description.label'}}</F.Label>
|
||||
<F.HelperText>{{t 'form.description.help'}}</F.HelperText>
|
||||
{{#if @model.errors.description}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.description as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::Textarea::Field>
|
||||
|
||||
{{#if @model.isNew}}
|
||||
<Hds::Form::RadioCard::Group @name='type' @alignment='center' as |G|>
|
||||
<G.Legend>{{t 'form.type.label'}}</G.Legend>
|
||||
{{#each this.types as |type|}}
|
||||
<G.RadioCard
|
||||
@value={{type}}
|
||||
@maxWidth='20rem'
|
||||
@checked={{eq type @model.type}}
|
||||
{{on 'input' (fn @changeType type)}}
|
||||
as |R|
|
||||
>
|
||||
<R.Label>{{t
|
||||
(concat 'resources.credential-library.types.' type)
|
||||
}}</R.Label>
|
||||
<R.Description>{{t
|
||||
(concat 'resources.credential-library.help.' type)
|
||||
}}</R.Description>
|
||||
</G.RadioCard>
|
||||
{{/each}}
|
||||
</Hds::Form::RadioCard::Group>
|
||||
{{else}}
|
||||
<InfoField
|
||||
@value={{t (concat 'resources.credential-library.types.' @model.type)}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'form.type.label'}}</F.Label>
|
||||
<F.HelperText>
|
||||
{{t (concat 'resources.credential-library.help.' @model.type)}}
|
||||
</F.HelperText>
|
||||
</InfoField>
|
||||
{{/if}}
|
||||
|
||||
<Hds::Form::TextInput::Field
|
||||
@isRequired={{true}}
|
||||
@value={{@model.path}}
|
||||
@isInvalid={{@model.errors.path}}
|
||||
@type='text'
|
||||
name='vault_path'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'path')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t
|
||||
'resources.credential-library.form.vault_path.label'
|
||||
}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.vault_path.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.path}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.path as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Hds::Form::TextInput::Field
|
||||
@isRequired={{true}}
|
||||
@value={{@model.username}}
|
||||
@isInvalid={{@model.errors.username}}
|
||||
@type='text'
|
||||
name='username'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'username')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.credential-library.form.username.label'}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.username.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.username}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.username as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Hds::Form::Select::Field
|
||||
@isOptional={{true}}
|
||||
@width='100%'
|
||||
name='key_type'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'key_type')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.credential-library.form.key_type.label'}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.key_type.help'
|
||||
}}</F.HelperText>
|
||||
<F.Options>
|
||||
<option disabled hidden selected value=''>{{t
|
||||
'titles.choose-an-option'
|
||||
}}</option>
|
||||
{{#each this.keyTypes as |keyType|}}
|
||||
<option
|
||||
value={{keyType}}
|
||||
selected={{eq keyType @model.key_type}}
|
||||
>{{keyType}}</option>
|
||||
{{/each}}
|
||||
</F.Options>
|
||||
{{#if @model.errors.key_type}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.key_type as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::Select::Field>
|
||||
|
||||
{{#if this.showKeyBits}}
|
||||
<Hds::Form::TextInput::Field
|
||||
@isOptional={{true}}
|
||||
@value={{@model.key_bits}}
|
||||
@isInvalid={{@model.errors.key_bits}}
|
||||
@type='text'
|
||||
name='key_bits'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'key_bits')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t
|
||||
'resources.credential-library.form.key_bits.label'
|
||||
}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.key_bits.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.key_bits}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.key_bits as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
{{/if}}
|
||||
|
||||
<Hds::Form::TextInput::Field
|
||||
@isOptional={{true}}
|
||||
@value={{@model.ttl}}
|
||||
@isInvalid={{@model.errors.ttl}}
|
||||
@type='text'
|
||||
name='ttl'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'ttl')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.credential-library.form.ttl.label'}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.ttl.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.ttl}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.ttl as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Hds::Form::TextInput::Field
|
||||
@isOptional={{true}}
|
||||
@value={{@model.key_id}}
|
||||
@isInvalid={{@model.errors.key_id}}
|
||||
@type='text'
|
||||
name='key_id'
|
||||
disabled={{form.disabled}}
|
||||
{{on 'input' (set-from-event @model 'key_id')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.credential-library.form.key_id.label'}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.credential-library.form.key_id.help'
|
||||
}}</F.HelperText>
|
||||
{{#if @model.errors.key_id}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.key_id as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::TextInput::Field>
|
||||
|
||||
<Form::Field::KeyValueList
|
||||
@layout='horizontal'
|
||||
@isOptional={{true}}
|
||||
@name='critical_options'
|
||||
@options={{@model.critical_options}}
|
||||
@addOption={{fn this.addOption 'critical_options'}}
|
||||
@removeOptionByIndex={{fn this.removeOptionByIndex 'critical_options'}}
|
||||
@disabled={{form.disabled}}
|
||||
as |M|
|
||||
>
|
||||
<M.Legend>
|
||||
{{t 'resources.credential-library.form.critical_options.label'}}
|
||||
</M.Legend>
|
||||
<M.HelperText>
|
||||
{{t 'resources.credential-library.form.critical_options.help'}}
|
||||
</M.HelperText>
|
||||
{{#if @model.errors.critical_options}}
|
||||
<M.Error as |E|>
|
||||
{{#each @model.errors.critical_options as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</M.Error>
|
||||
{{/if}}
|
||||
</Form::Field::KeyValueList>
|
||||
|
||||
<Form::Field::KeyValueList
|
||||
@layout='horizontal'
|
||||
@isOptional={{true}}
|
||||
@name='extensions'
|
||||
@options={{@model.extensions}}
|
||||
@addOption={{fn this.addOption 'extensions'}}
|
||||
@removeOptionByIndex={{fn this.removeOptionByIndex 'extensions'}}
|
||||
@disabled={{form.disabled}}
|
||||
as |M|
|
||||
>
|
||||
<M.Legend>
|
||||
{{t 'resources.credential-library.form.extensions.label'}}
|
||||
</M.Legend>
|
||||
<M.HelperText>
|
||||
{{t 'resources.credential-library.form.extensions.help'}}
|
||||
</M.HelperText>
|
||||
{{#if @model.errors.extensions}}
|
||||
<M.Error as |E|>
|
||||
{{#each @model.errors.extensions as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</M.Error>
|
||||
{{/if}}
|
||||
</Form::Field::KeyValueList>
|
||||
|
||||
{{#if (can 'save model' @model)}}
|
||||
<form.actions
|
||||
@enableEditText={{t 'actions.edit-form'}}
|
||||
@submitText={{t 'actions.save'}}
|
||||
@cancelText={{t 'actions.cancel'}}
|
||||
/>
|
||||
{{/if}}
|
||||
|
||||
</Rose::Form>
|
||||
@@ -0,0 +1,55 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action, set } from '@ember/object';
|
||||
import {
|
||||
options,
|
||||
TYPES_CREDENTIAL_LIBRARY,
|
||||
} from 'api/models/credential-library';
|
||||
|
||||
export default class FormCredentialLibraryVaultSshCertComponent extends Component {
|
||||
// =properties
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
keyTypes = options.key_type;
|
||||
|
||||
/**
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
types = TYPES_CREDENTIAL_LIBRARY;
|
||||
|
||||
/**
|
||||
* Boolean to determine if the key bits field should be displayed on the form
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get showKeyBits() {
|
||||
const keyType = this.args.model.key_type;
|
||||
return keyType === 'rsa' || keyType === 'ecdsa';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a key/value option object. We recreate a new array after adding
|
||||
* so that ember is aware that the array has been modified.
|
||||
* @param field {string}
|
||||
* @param key {string}
|
||||
* @param value {string}
|
||||
*/
|
||||
@action
|
||||
addOption(field, { key, value }) {
|
||||
const existingArray = this.args.model[field] ?? [];
|
||||
const newArray = [...existingArray, { key, value }];
|
||||
set(this.args.model, field, newArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an option by index. We recreate a new array after
|
||||
* splicing out the item so that ember is aware that the array has been modified.
|
||||
* @param field {string}
|
||||
* @param index {number}
|
||||
*/
|
||||
@action
|
||||
removeOptionByIndex(field, index) {
|
||||
const newArray = this.args.model[field].filter((_, i) => i !== index);
|
||||
set(this.args.model, field, newArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<Hds::Form::Fieldset
|
||||
@layout={{@layout}}
|
||||
@isRequired={{@isRequired}}
|
||||
@isOptional={{@isOptional}}
|
||||
as |F|
|
||||
>
|
||||
{{yield F}}
|
||||
<F.Control>
|
||||
<Hds::Table class='key-value-list' name={{@name}}>
|
||||
<:head as |H|>
|
||||
<H.Tr>
|
||||
<H.Th>{{t 'form.key.label'}}</H.Th>
|
||||
<H.Th>{{t 'form.value.label'}}</H.Th>
|
||||
<H.Th>
|
||||
{{#if @removeOptionByIndex}}
|
||||
{{t 'titles.actions'}}
|
||||
{{/if}}
|
||||
</H.Th>
|
||||
</H.Tr>
|
||||
</:head>
|
||||
<:body as |B|>
|
||||
|
||||
{{#each @options as |option index|}}
|
||||
<B.Tr>
|
||||
<B.Td>
|
||||
<Hds::Form::TextInput::Field
|
||||
@value={{option.key}}
|
||||
@type='text'
|
||||
disabled={{@disabled}}
|
||||
{{on 'input' (set-from-event option 'key')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label class='sr-only'>{{t 'form.key.label'}}</F.Label>
|
||||
</Hds::Form::TextInput::Field>
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
<Hds::Form::TextInput::Field
|
||||
@value={{option.value}}
|
||||
@type='text'
|
||||
disabled={{@disabled}}
|
||||
{{on 'input' (set-from-event option 'value')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label class='sr-only'>{{t 'form.value.label'}}</F.Label>
|
||||
</Hds::Form::TextInput::Field>
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
{{#if @removeOptionByIndex}}
|
||||
<Hds::Button
|
||||
@text={{t 'actions.remove'}}
|
||||
@color='critical'
|
||||
@icon='trash'
|
||||
@isIconOnly={{true}}
|
||||
disabled={{@disabled}}
|
||||
{{on 'click' (fn @removeOptionByIndex index)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
{{/each}}
|
||||
|
||||
<B.Tr>
|
||||
<B.Td>
|
||||
<Hds::Form::TextInput::Field
|
||||
@value={{this.newOptionKey}}
|
||||
@type='text'
|
||||
disabled={{@disabled}}
|
||||
{{on 'input' (set-from-event this 'newOptionKey')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label class='sr-only'>{{t 'form.key.label'}}</F.Label>
|
||||
</Hds::Form::TextInput::Field></B.Td>
|
||||
<B.Td>
|
||||
<Hds::Form::TextInput::Field
|
||||
@value={{this.newOptionValue}}
|
||||
@type='text'
|
||||
disabled={{@disabled}}
|
||||
{{on 'input' (set-from-event this 'newOptionValue')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label class='sr-only'>{{t 'form.value.label'}}</F.Label>
|
||||
</Hds::Form::TextInput::Field>
|
||||
</B.Td>
|
||||
<B.Td>
|
||||
<Hds::Button
|
||||
@text={{t 'actions.add'}}
|
||||
@color='secondary'
|
||||
type='button'
|
||||
disabled={{or @disabled (not this.newOptionKey)}}
|
||||
{{on 'click' this.addOption}}
|
||||
/>
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
|
||||
</:body>
|
||||
</Hds::Table>
|
||||
</F.Control>
|
||||
</Hds::Form::Fieldset>
|
||||
@@ -0,0 +1,42 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { assert } from '@ember/debug';
|
||||
|
||||
export default class MappingListComponent extends Component {
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@tracked newOptionKey = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@tracked newOptionValue = '';
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* If a new key value is entered and an addOption method was specified,
|
||||
* calls addOption with the new key and value. Resets key and value.
|
||||
*/
|
||||
@action
|
||||
addOption() {
|
||||
assert(
|
||||
'[boundary-admin-key-value-list-field] `@addOption` is required.',
|
||||
this.args.addOption
|
||||
);
|
||||
|
||||
if (this.newOptionKey) {
|
||||
this.args.addOption({
|
||||
key: this.newOptionKey,
|
||||
value: this.newOptionValue,
|
||||
});
|
||||
}
|
||||
|
||||
this.newOptionKey = '';
|
||||
this.newOptionValue = '';
|
||||
}
|
||||
}
|
||||
+1
@@ -7,6 +7,7 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
|
||||
@service intl;
|
||||
|
||||
// =attributes
|
||||
queryParams = ['type'];
|
||||
|
||||
/**
|
||||
* Translated new credential libraries breadcrumb
|
||||
|
||||
+18
@@ -1,5 +1,6 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesCredentialLibraryRoute extends Route {
|
||||
// =services
|
||||
@@ -19,4 +20,21 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
|
||||
reload: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the contents of array fields in order to force the instance
|
||||
* into a dirty state. This ensures that `model.rollbackAttributes()` reverts
|
||||
* to the original expected array.
|
||||
*
|
||||
* The deep copy implemented here is required to ensure that both the
|
||||
* array itself and its members are all new.
|
||||
*
|
||||
* @param {credentialLibraryModel} credentialLibrary
|
||||
*/
|
||||
@action
|
||||
edit(credentialLibrary) {
|
||||
const { critical_options, extensions } = credentialLibrary;
|
||||
credentialLibrary.critical_options = structuredClone(critical_options);
|
||||
credentialLibrary.extensions = structuredClone(extensions);
|
||||
}
|
||||
}
|
||||
+30
-2
@@ -1,10 +1,22 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC } from 'api/models/credential-library';
|
||||
|
||||
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesNewRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service store;
|
||||
@service router;
|
||||
@service features;
|
||||
|
||||
// =attributes
|
||||
|
||||
queryParams = {
|
||||
type: {
|
||||
refreshModel: true,
|
||||
},
|
||||
};
|
||||
|
||||
// =methods
|
||||
|
||||
@@ -12,13 +24,29 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
|
||||
* Creates a new unsaved credential library in current credential store.
|
||||
* @return {CredentialLibraryModel}
|
||||
*/
|
||||
model() {
|
||||
const { id: credential_store_id, type } = this.modelFor(
|
||||
model({ type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC }) {
|
||||
const { id: credential_store_id } = this.modelFor(
|
||||
'scopes.scope.credential-stores.credential-store'
|
||||
);
|
||||
|
||||
// Set the type to generic vault if feature flag isn't enabled in cases where
|
||||
// user sets the query parameter manually
|
||||
if (!this.features.isEnabled('credential-library-vault-ssh-certificate')) {
|
||||
type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
||||
}
|
||||
|
||||
return this.store.createRecord('credential-library', {
|
||||
type,
|
||||
credential_store_id,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update type of credential library
|
||||
* @param {string} type
|
||||
*/
|
||||
@action
|
||||
changeType(type) {
|
||||
this.router.replaceWith({ queryParams: { type } });
|
||||
}
|
||||
}
|
||||
@@ -637,3 +637,47 @@
|
||||
margin-top: sizing.rems(xs) - sizing.rems(xxxxs); // 10
|
||||
}
|
||||
}
|
||||
|
||||
.key-value-list {
|
||||
border: 0;
|
||||
|
||||
/* stylelint-disable selector-class-pattern */
|
||||
.hds-table__thead {
|
||||
.hds-table__th {
|
||||
height: auto;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.hds-table__thead,
|
||||
.hds-table__tbody {
|
||||
.hds-table__tr {
|
||||
// Remove background color on all cells (especially header cells)
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.hds-table__th,
|
||||
.hds-table__td {
|
||||
padding: 0.75rem 1rem;
|
||||
|
||||
// Rely on right padding for cell spacing...
|
||||
padding-left: 0;
|
||||
|
||||
&:last-child {
|
||||
// ...except in the last cell, which doesn't need right padding
|
||||
padding-right: 0;
|
||||
|
||||
// Shrink last cell to minimum possible width
|
||||
width: 1%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
// Reset field margins to rely instead on cell paddings
|
||||
.hds-form-field--layout-vertical,
|
||||
.hds-form-text-input {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* stylelint-enable selector-class-pattern */
|
||||
}
|
||||
+1
@@ -50,6 +50,7 @@
|
||||
<page.body>
|
||||
<Form::CredentialLibrary
|
||||
@model={{@model}}
|
||||
@edit={{route-action 'edit' @model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
/>
|
||||
|
||||
+1
@@ -19,6 +19,7 @@
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@changeType={{route-action 'changeType'}}
|
||||
/>
|
||||
</page.body>
|
||||
</Rose::Layout::Page>
|
||||
@@ -15,7 +15,7 @@ const featureEditions = {
|
||||
'vault-worker-filter': false,
|
||||
'target-worker-filters-v2': true,
|
||||
'target-network-address': true,
|
||||
'credential-library-vault-ssh-cert': false,
|
||||
'credential-library-vault-ssh-certificate': false,
|
||||
},
|
||||
};
|
||||
featureEditions.enterprise = {
|
||||
@@ -23,6 +23,7 @@ featureEditions.enterprise = {
|
||||
'ssh-target': true,
|
||||
'vault-worker-filter': true,
|
||||
'target-worker-filters-v2-ingress': true,
|
||||
'credential-library-vault-ssh-certificate': true,
|
||||
};
|
||||
featureEditions.hcp = {
|
||||
...featureEditions.enterprise,
|
||||
@@ -152,7 +153,7 @@ module.exports = function (environment) {
|
||||
ENV.featureFlags['target-worker-filters-v2-ingress'] = true;
|
||||
ENV.featureFlags['target-worker-filters-v2-hcp'] = true;
|
||||
ENV.featureFlags['target-network-address'] = true;
|
||||
ENV.featureFlags['credential-library-vault-ssh-cert'] = true;
|
||||
ENV.featureFlags['credential-library-vault-ssh-certificate'] = true;
|
||||
}
|
||||
|
||||
if (environment === 'test') {
|
||||
@@ -178,7 +179,7 @@ module.exports = function (environment) {
|
||||
ENV.featureFlags['vault-worker-filter'] = true;
|
||||
ENV.featureFlags['target-worker-filters-v2'] = true;
|
||||
ENV.featureFlags['target-network-address'] = true;
|
||||
ENV.featureFlags['credential-library-vault-ssh-cert'] = true;
|
||||
ENV.featureFlags['credential-library-vault-ssh-certificate'] = true;
|
||||
}
|
||||
|
||||
if (environment === 'production') {
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
|
||||
import {
|
||||
visit,
|
||||
click,
|
||||
fillIn,
|
||||
currentURL,
|
||||
find,
|
||||
select,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
|
||||
|
||||
module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -83,6 +91,76 @@ module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
assert.strictEqual(getCredentialLibraryCount(), count + 1);
|
||||
});
|
||||
|
||||
test('can create a new credential library of type vault ssh cert', async function (assert) {
|
||||
assert.expect(12);
|
||||
const count = getCredentialLibraryCount();
|
||||
await visit(urls.newCredentialLibrary);
|
||||
await click('[value="vault-ssh-certificate"]');
|
||||
await fillIn('[name="name"]', 'name');
|
||||
await fillIn('[name="description"]', 'description');
|
||||
await fillIn('[name="vault_path"]', 'path');
|
||||
await fillIn('[name="username"]', 'username');
|
||||
await select('[name="key_type"]', 'rsa');
|
||||
await fillIn('[name="key_bits"]', 100);
|
||||
await fillIn('[name="ttl"]', 'ttl');
|
||||
await fillIn('[name="key_id"]', 'key_id');
|
||||
await fillIn(
|
||||
'[name="critical_options"] tbody td:nth-of-type(1) input',
|
||||
'co_key'
|
||||
);
|
||||
await fillIn(
|
||||
'[name="critical_options"] tbody td:nth-of-type(2) input',
|
||||
'co_value'
|
||||
);
|
||||
await click('[name="critical_options"] button');
|
||||
await fillIn(
|
||||
'[name="extensions"] tbody td:nth-of-type(1) input',
|
||||
'ext_key'
|
||||
);
|
||||
await fillIn(
|
||||
'[name="extensions"] tbody td:nth-of-type(2) input',
|
||||
'ext_value'
|
||||
);
|
||||
await click('[name="extensions"] button');
|
||||
await click('[type="submit"]');
|
||||
assert.strictEqual(getCredentialLibraryCount(), count + 1);
|
||||
assert.strictEqual(
|
||||
this.server.schema.credentialLibraries.where({
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
}).length,
|
||||
1
|
||||
);
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
assert.strictEqual(credentialLibrary.name, 'name');
|
||||
assert.strictEqual(credentialLibrary.description, 'description');
|
||||
assert.strictEqual(credentialLibrary.attributes.path, 'path');
|
||||
assert.strictEqual(credentialLibrary.attributes.username, 'username');
|
||||
assert.strictEqual(credentialLibrary.attributes.key_type, 'rsa');
|
||||
assert.strictEqual(credentialLibrary.attributes.key_bits, 100);
|
||||
assert.strictEqual(credentialLibrary.attributes.ttl, 'ttl');
|
||||
assert.strictEqual(credentialLibrary.attributes.key_id, 'key_id');
|
||||
assert.deepEqual(credentialLibrary.attributes.critical_options, {
|
||||
co_key: 'co_value',
|
||||
});
|
||||
assert.deepEqual(credentialLibrary.attributes.extensions, {
|
||||
ext_key: 'ext_value',
|
||||
});
|
||||
});
|
||||
|
||||
test('ecdsa and rsa key types bring up a key bits field', async function (assert) {
|
||||
assert.expect(3);
|
||||
await visit(urls.newCredentialLibrary);
|
||||
await click('[value="vault-ssh-certificate"]');
|
||||
await select('[name="key_type"]', 'ed25519');
|
||||
assert.dom('[name="key_bits"]').doesNotExist();
|
||||
await select('[name="key_type"]', 'ecdsa');
|
||||
assert.dom('[name="key_bits"]').isVisible();
|
||||
await select('[name="key_type"]', 'rsa');
|
||||
assert.dom('[name="key_bits"]').isVisible();
|
||||
});
|
||||
|
||||
test('Users cannot navigate to new credential library route without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.credentialStore.authorized_collection_actions[
|
||||
@@ -107,7 +185,7 @@ module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
assert.strictEqual(getCredentialLibraryCount(), count);
|
||||
});
|
||||
|
||||
test('saving a new credential library with invalid fields displays error messasges', async function (assert) {
|
||||
test('saving a new credential library with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/credential-libraries', () => {
|
||||
return new Response(
|
||||
@@ -135,8 +213,17 @@ module('Acceptance | credential-libraries | create', function (hooks) {
|
||||
'The request was invalid.'
|
||||
);
|
||||
assert.ok(
|
||||
find('.rose-form-error-message').textContent.trim(),
|
||||
find('.hds-form-error__message').textContent.trim(),
|
||||
'Name is required.'
|
||||
);
|
||||
});
|
||||
|
||||
test('cannot select vault ssh cert when feature is disabled', async function (assert) {
|
||||
const featuresService = this.owner.lookup('service:features');
|
||||
featuresService.disable('credential-library-vault-ssh-certificate');
|
||||
assert.expect(1);
|
||||
await visit(urls.newCredentialLibrary);
|
||||
|
||||
assert.dom('[value="vault-ssh-certificate"]').doesNotExist();
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
|
||||
|
||||
module('Acceptance | credential-libraries | read', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -78,6 +79,23 @@ module('Acceptance | credential-libraries | read', function (hooks) {
|
||||
assert.notOk(find('main tbody .rose-table-header-cell a'));
|
||||
});
|
||||
|
||||
test('cannot navigate to vault ssh cert form when feature is not enabled', async function (assert) {
|
||||
assert.expect(1);
|
||||
instances.credentialLibrary = this.server.create('credential-library', {
|
||||
scope: instances.scopes.project,
|
||||
credentialStore: instances.credentialStore,
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
await visit(
|
||||
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`
|
||||
);
|
||||
const featuresService = this.owner.lookup('service:features');
|
||||
featuresService.disable('credential-library-vault-ssh-certificate');
|
||||
await visit(urls.credentialLibraries);
|
||||
|
||||
assert.dom('.rose-table-body tr:nth-of-type(2) a').doesNotExist();
|
||||
});
|
||||
|
||||
test('visiting an unknown credential library displays 404 message', async function (assert) {
|
||||
assert.expect(1);
|
||||
await visit(urls.unknownCredentialLibrary);
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
|
||||
import {
|
||||
visit,
|
||||
click,
|
||||
fillIn,
|
||||
currentURL,
|
||||
find,
|
||||
select,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import { Response } from 'miragejs';
|
||||
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
|
||||
|
||||
module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -130,7 +138,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
'The request was invalid.'
|
||||
);
|
||||
assert.ok(
|
||||
find('.rose-form-error-message').textContent.trim(),
|
||||
find('.hds-form-error__message').textContent.trim(),
|
||||
'Name is required.'
|
||||
);
|
||||
});
|
||||
@@ -181,4 +189,61 @@ module('Acceptance | credential-libraries | update', function (hooks) {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('can update a vault ssh cert credential library and save changes', async function (assert) {
|
||||
assert.expect(10);
|
||||
instances.credentialLibrary = this.server.create('credential-library', {
|
||||
scope: instances.scopes.project,
|
||||
credentialStore: instances.credentialStore,
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
await visit(
|
||||
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`
|
||||
);
|
||||
await click('form [type="button"]:not(:disabled)', 'Activate edit mode');
|
||||
await fillIn('[name="name"]', 'name');
|
||||
await fillIn('[name="description"]', 'description');
|
||||
await fillIn('[name="vault_path"]', 'path');
|
||||
await fillIn('[name="username"]', 'username');
|
||||
await select('[name="key_type"]', 'rsa');
|
||||
await fillIn('[name="key_bits"]', 100);
|
||||
await fillIn('[name="ttl"]', 'ttl');
|
||||
await fillIn('[name="key_id"]', 'key_id');
|
||||
await fillIn(
|
||||
'[name="critical_options"] tbody td:nth-of-type(1) input',
|
||||
'co_key'
|
||||
);
|
||||
await fillIn(
|
||||
'[name="critical_options"] tbody td:nth-of-type(2) input',
|
||||
'co_value'
|
||||
);
|
||||
await click('[name="critical_options"] button');
|
||||
await fillIn(
|
||||
'[name="extensions"] tbody td:nth-of-type(1) input',
|
||||
'ext_key'
|
||||
);
|
||||
await fillIn(
|
||||
'[name="extensions"] tbody td:nth-of-type(2) input',
|
||||
'ext_value'
|
||||
);
|
||||
await click('[name="extensions"] button');
|
||||
await click('[type="submit"]');
|
||||
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
assert.strictEqual(credentialLibrary.name, 'name');
|
||||
assert.strictEqual(credentialLibrary.description, 'description');
|
||||
assert.strictEqual(credentialLibrary.attributes.path, 'path');
|
||||
assert.strictEqual(credentialLibrary.attributes.username, 'username');
|
||||
assert.strictEqual(credentialLibrary.attributes.key_type, 'rsa');
|
||||
assert.strictEqual(credentialLibrary.attributes.key_bits, 100);
|
||||
assert.strictEqual(credentialLibrary.attributes.ttl, 'ttl');
|
||||
assert.strictEqual(credentialLibrary.attributes.key_id, 'key_id');
|
||||
assert.deepEqual(credentialLibrary.attributes.critical_options, {
|
||||
co_key: 'co_value',
|
||||
});
|
||||
assert.deepEqual(credentialLibrary.attributes.extensions, {
|
||||
ext_key: 'ext_value',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
import { setupIntl } from 'ember-intl/test-support';
|
||||
|
||||
module('Integration | Component | key-value-list', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
setupIntl(hooks);
|
||||
|
||||
test('it renders fields', async function (assert) {
|
||||
await render(hbs`
|
||||
<Form::Field::KeyValueList as |M|>
|
||||
<M.Legend>Label</M.Legend>
|
||||
<M.HelperText>Help</M.HelperText>
|
||||
<M.Error as |E|>
|
||||
<E.Message>Error!</E.Message>
|
||||
</M.Error>
|
||||
</Form::Field::KeyValueList>
|
||||
`);
|
||||
|
||||
assert.dom('tbody tr').exists({ count: 1 });
|
||||
assert.dom('legend').exists().hasText('Label');
|
||||
assert.dom('.hds-form-helper-text').exists().hasText('Help');
|
||||
assert.dom('.hds-form-error__message').exists().hasText('Error!');
|
||||
assert.dom('button').exists().hasText('Add');
|
||||
});
|
||||
|
||||
test('it renders multiple options', async function (assert) {
|
||||
this.options = [
|
||||
{ key: 'one', value: 'two' },
|
||||
{ key: 'three', value: 'four' },
|
||||
];
|
||||
|
||||
// Template block usage:
|
||||
await render(hbs`
|
||||
<Form::Field::KeyValueList
|
||||
@options={{this.options}}
|
||||
/>
|
||||
`);
|
||||
|
||||
assert.dom('tbody tr').exists({ count: 3 });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import {
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
} from 'api/models/credential-library';
|
||||
|
||||
module('Unit | Abilities | credential-library', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let features;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
features = this.owner.lookup('service:features');
|
||||
features.enable('credential-library-vault-ssh-certificate');
|
||||
});
|
||||
|
||||
test('can read credential library type when authorized and feature is enabled', function (assert) {
|
||||
assert.expect(2);
|
||||
const canService = this.owner.lookup('service:can');
|
||||
const store = this.owner.lookup('service:store');
|
||||
const credentialLibrary = store.createRecord('credential-library', {
|
||||
authorized_actions: ['read'],
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
assert.true(canService.can('read credential-library', credentialLibrary));
|
||||
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
||||
assert.true(canService.can('read credential-library', credentialLibrary));
|
||||
});
|
||||
|
||||
test('cannot read credential library type when unauthorized and feature is enabled', function (assert) {
|
||||
assert.expect(2);
|
||||
const canService = this.owner.lookup('service:can');
|
||||
const store = this.owner.lookup('service:store');
|
||||
const credentialLibrary = store.createRecord('credential-library', {
|
||||
authorized_actions: [],
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
assert.false(canService.can('read credential-library', credentialLibrary));
|
||||
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
||||
assert.false(canService.can('read credential-library', credentialLibrary));
|
||||
});
|
||||
|
||||
test('cannot read credential library type when unauthorized and feature is disabled', function (assert) {
|
||||
assert.expect(2);
|
||||
const canService = this.owner.lookup('service:can');
|
||||
const store = this.owner.lookup('service:store');
|
||||
const featuresService = this.owner.lookup('service:features');
|
||||
featuresService.disable('credential-library-vault-ssh-certificate');
|
||||
const credentialLibrary = store.createRecord('credential-library', {
|
||||
authorized_actions: [],
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
assert.false(canService.can('read credential-library', credentialLibrary));
|
||||
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
||||
assert.false(canService.can('read credential-library', credentialLibrary));
|
||||
});
|
||||
|
||||
test('can read vault-generic but not vault-ssh-certificate when authorized and feature is disabled', function (assert) {
|
||||
assert.expect(2);
|
||||
const canService = this.owner.lookup('service:can');
|
||||
const store = this.owner.lookup('service:store');
|
||||
const featuresService = this.owner.lookup('service:features');
|
||||
featuresService.disable('credential-library-vault-ssh-certificate');
|
||||
const credentialLibrary = store.createRecord('credential-library', {
|
||||
authorized_actions: ['read'],
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
});
|
||||
assert.false(canService.can('read credential-library', credentialLibrary));
|
||||
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
||||
assert.true(canService.can('read credential-library', credentialLibrary));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user