Icu 12567 add new field credential mapping overrides (#2156)
* chore: 🤖 add credential type select list
This commit is contained in:
1 parent
956f6fd04d
commit
93c8d481fd
14 files changed
+517
-36
No files matched your search
@@ -81,6 +81,12 @@ export default class GeneratedCredentialLibraryModel extends BaseModel {
|
||||
})
|
||||
credential_type;
|
||||
|
||||
@attr('object', {
|
||||
for: 'vault-generic',
|
||||
description: 'It indicates the credential mapping overrides.',
|
||||
})
|
||||
credential_mapping_overrides;
|
||||
|
||||
@attr('string', {
|
||||
for: 'vault-ssh-certificate',
|
||||
isNestedAttribute: true,
|
||||
|
||||
@@ -12,6 +12,17 @@ export const options = {
|
||||
http_method: ['GET', 'POST'],
|
||||
key_type: ['ed25519', 'ecdsa', 'rsa'],
|
||||
credential_types: ['ssh_private_key', 'username_password'],
|
||||
mapping_overrides: {
|
||||
username_password: {
|
||||
username_attribute: 'Username',
|
||||
password_attribute: 'Password',
|
||||
},
|
||||
ssh_private_key: {
|
||||
private_key_attribute: 'Private Key',
|
||||
private_key_passphrase_attribute: 'Private Key Passphrase',
|
||||
username_attribute: 'Username',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC = 'vault-generic';
|
||||
|
||||
@@ -7,6 +7,7 @@ import ApplicationSerializer from './application';
|
||||
import {
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
options,
|
||||
} from '../models/credential-library';
|
||||
|
||||
export default class CredentialLibrarySerializer extends ApplicationSerializer {
|
||||
@@ -31,9 +32,34 @@ export default class CredentialLibrarySerializer extends ApplicationSerializer {
|
||||
return super.serialize(...arguments);
|
||||
}
|
||||
}
|
||||
serializeAttribute(snapshot, json) {
|
||||
const value = super.serializeAttribute(...arguments);
|
||||
const { credential_type, type, credential_mapping_overrides, isNew } =
|
||||
snapshot.record;
|
||||
if (
|
||||
type === TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC &&
|
||||
credential_mapping_overrides &&
|
||||
credential_type &&
|
||||
!isNew
|
||||
) {
|
||||
// API expects to send null to fields if it is undefined or deleted
|
||||
json.credential_mapping_overrides = Object.keys(
|
||||
options.mapping_overrides[credential_type],
|
||||
).reduce((obj, key) => {
|
||||
if (credential_mapping_overrides[key]) {
|
||||
obj[key] = credential_mapping_overrides[key];
|
||||
} else {
|
||||
obj[key] = null;
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
serializeVaultGeneric() {
|
||||
const serialized = super.serialize(...arguments);
|
||||
|
||||
if (serialized.attributes) {
|
||||
// Set `http_request_body` only if `http_method` is POST
|
||||
// otherwise set to null to have the field removed
|
||||
|
||||
@@ -11,12 +11,18 @@ import {
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
TYPES_CREDENTIAL_LIBRARY,
|
||||
options,
|
||||
} from 'api/models/credential-library';
|
||||
|
||||
export default factory.extend({
|
||||
id: () => generateId('cl_'),
|
||||
type: (i) => TYPES_CREDENTIAL_LIBRARY[i % TYPES_CREDENTIAL_LIBRARY.length],
|
||||
|
||||
credential_type(i) {
|
||||
if (this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC) {
|
||||
return options.credential_types[i % options.credential_types.length];
|
||||
}
|
||||
},
|
||||
authorized_actions: () =>
|
||||
permissions.authorizedActionsFor('credential-library') || [
|
||||
'no-op',
|
||||
|
||||
@@ -24,6 +24,7 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
http_method: 'GET',
|
||||
version: 1,
|
||||
credential_type: 'ssh_private_key',
|
||||
credential_mapping_overrides: { username_attribute: 'user' },
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
@@ -34,6 +35,9 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
credential_type: 'ssh_private_key',
|
||||
credential_mapping_overrides: {
|
||||
username_attribute: 'user',
|
||||
},
|
||||
attributes: {
|
||||
path: '/vault/path',
|
||||
http_method: 'GET',
|
||||
@@ -57,6 +61,7 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
http_method: 'GET',
|
||||
version: 1,
|
||||
credential_type: 'ssh_private_key',
|
||||
credential_mapping_overrides: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -69,6 +74,11 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
credential_type: 'ssh_private_key',
|
||||
credential_mapping_overrides: {
|
||||
private_key_attribute: null,
|
||||
private_key_passphrase_attribute: null,
|
||||
username_attribute: null,
|
||||
},
|
||||
attributes: {
|
||||
path: '/vault/path',
|
||||
http_method: 'GET',
|
||||
@@ -85,6 +95,7 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
http_method: '',
|
||||
path: null,
|
||||
credential_type: null,
|
||||
credential_mapping_overrides: {},
|
||||
});
|
||||
const vaultSSHCertificateRecord = store.createRecord('credential-library', {
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
||||
@@ -105,6 +116,7 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
name: null,
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
credential_type: null,
|
||||
credential_mapping_overrides: {},
|
||||
});
|
||||
assert.deepEqual(serializedVaultSSHCertificateRecord, {
|
||||
attributes: {
|
||||
@@ -145,6 +157,7 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
name: null,
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
credential_type: null,
|
||||
credential_mapping_overrides: {},
|
||||
},
|
||||
'http_request_body attribute is not expected',
|
||||
);
|
||||
@@ -164,6 +177,7 @@ module('Unit | Serializer | credential library', function (hooks) {
|
||||
name: null,
|
||||
type: TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
||||
credential_type: null,
|
||||
credential_mapping_overrides: {},
|
||||
},
|
||||
'http_request_body attribute is expected',
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user