chore: 🤖 add credential type select list (#2144)

* chore: 🤖 add credential type select list
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-02-16 15:57:14 -08:00
1 parent f002e14673
commit 592bb15022
8 files changed
+71 -1

No files matched your search

@@ -75,6 +75,12 @@ export default class GeneratedCredentialLibraryModel extends BaseModel {
})
path;
@attr('string', {
for: 'vault-generic',
description: 'It indicates the type of credential the library returns.',
})
credential_type;
@attr('string', {
for: 'vault-ssh-certificate',
isNestedAttribute: true,
@@ -11,6 +11,7 @@ import GeneratedCredentialLibraryModel from '../generated/models/credential-libr
export const options = {
http_method: ['GET', 'POST'],
key_type: ['ed25519', 'ecdsa', 'rsa'],
credential_types: ['ssh_private_key', 'username_password'],
};
export const TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC = 'vault-generic';
@@ -23,6 +23,7 @@ module('Unit | Serializer | credential library', function (hooks) {
path: '/vault/path',
http_method: 'GET',
version: 1,
credential_type: 'ssh_private_key',
});
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
@@ -32,6 +33,7 @@ module('Unit | Serializer | credential library', function (hooks) {
name: 'Name',
description: 'Description',
version: 1,
credential_type: 'ssh_private_key',
attributes: {
path: '/vault/path',
http_method: 'GET',
@@ -54,6 +56,7 @@ module('Unit | Serializer | credential library', function (hooks) {
path: '/vault/path',
http_method: 'GET',
version: 1,
credential_type: 'ssh_private_key',
},
},
});
@@ -65,6 +68,7 @@ module('Unit | Serializer | credential library', function (hooks) {
credential_store_id: null,
name: 'Name',
description: 'Description',
credential_type: 'ssh_private_key',
attributes: {
path: '/vault/path',
http_method: 'GET',
@@ -80,6 +84,7 @@ module('Unit | Serializer | credential library', function (hooks) {
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
http_method: '',
path: null,
credential_type: null,
});
const vaultSSHCertificateRecord = store.createRecord('credential-library', {
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
@@ -99,6 +104,7 @@ module('Unit | Serializer | credential library', function (hooks) {
description: null,
name: null,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
credential_type: null,
});
assert.deepEqual(serializedVaultSSHCertificateRecord, {
attributes: {
@@ -138,6 +144,7 @@ module('Unit | Serializer | credential library', function (hooks) {
description: null,
name: null,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
credential_type: null,
},
'http_request_body attribute is not expected',
);
@@ -156,6 +163,7 @@ module('Unit | Serializer | credential library', function (hooks) {
description: null,
name: null,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
credential_type: null,
},
'http_request_body attribute is expected',
);
@@ -763,6 +763,8 @@ credential-library:
description: A credential library is a resource that provides credentials.
titles:
new: New Credential Library
ssh_private_key: SSH Private Key
username_password: Username & Password
actions:
create: New Credential Library
delete: Delete Credential Library
@@ -774,6 +776,9 @@ credential-library:
vault_path:
label: Vault Path
help: The path the library uses when requesting credentials from Vault.
credential_type:
label: Credential Type
help: Specify the type of credential this library will issue. This must be set to use credential injection. After this data is saved, it cannot be changed later.
http_method:
label: HTTP Method
help: The HTTP method the library uses when requesting credentials from Vault.
@@ -108,6 +108,38 @@
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::Select::Field
@isOptional={{true}}
@width='100%'
name='credential_type'
disabled={{or form.disabled (not @model.isNew)}}
{{on 'input' (set-from-event @model 'credential_type')}}
as |F|
>
<F.Label>
{{t 'resources.credential-library.form.credential_type.label'}}
</F.Label>
<F.HelperText>
{{t 'resources.credential-library.form.credential_type.help'}}
</F.HelperText>
<F.Options>
<option value='' />
{{#each this.credentialTypes as |type|}}
<option value={{type}} selected={{eq type @model.credential_type}}>
{{t (concat 'resources.credential-library.titles.' type)}}
</option>
{{/each}}
</F.Options>
{{#if @model.errors.credential_type}}
<F.Error as |E|>
{{#each @model.errors.credential_type as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::Select::Field>
<Hds::Form::Radio::Group
disabled={{form.disabled}}
{{on 'input' (set-from-event @model 'http_method')}}
@@ -16,6 +16,7 @@ export default class FormCredentialLibraryVaultGenericComponent extends Componen
*/
httpMethodOptions = options.http_method;
credentialTypes = options.credential_types;
/**
*
* @type {Array.<string>}
@@ -88,12 +88,22 @@ module('Acceptance | credential-libraries | create', function (hooks) {
assert.strictEqual(currentURL(), urls.credentialLibrary);
});
test('can create a credential library', async function (assert) {
test('can create a new credential library of type vault generic', async function (assert) {
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await select('[name="credential_type"]', 'ssh_private_key');
await click('[type="submit"]');
assert.strictEqual(getCredentialLibraryCount(), count + 1);
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
name: 'random string',
});
assert.strictEqual(credentialLibrary.name, 'random string');
assert.strictEqual(credentialLibrary.credentialType, 'ssh_private_key');
});
test('can create a new credential library of type vault ssh cert', async function (assert) {
@@ -191,6 +191,12 @@ module('Acceptance | credential-libraries | update', function (hooks) {
}
});
test('cannot update credential type in a vault generic credential library', async function (assert) {
await visit(urls.credentialLibrary);
await click('form [type="button"]', 'Activate edit mode');
assert.dom('[name=credential_type]').isDisabled();
});
test('can update a vault ssh cert credential library and save changes', async function (assert) {
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
@@ -226,6 +232,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
'[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({