2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-08 11:38:41 -04:00
|
|
|
import GeneratedCredentialLibraryModel from '../generated/models/credential-library';
|
|
|
|
|
|
2021-07-18 14:31:45 -04:00
|
|
|
/**
|
|
|
|
|
* Enum options for credential library.
|
|
|
|
|
*/
|
|
|
|
|
export const options = {
|
2021-07-22 17:42:37 -04:00
|
|
|
http_method: ['GET', 'POST'],
|
2023-02-01 13:46:23 -05:00
|
|
|
key_type: ['ed25519', 'ecdsa', 'rsa'],
|
2024-02-16 15:57:14 -08:00
|
|
|
credential_types: ['ssh_private_key', 'username_password'],
|
2024-02-23 10:07:52 -08:00
|
|
|
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',
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-07-18 14:31:45 -04:00
|
|
|
};
|
|
|
|
|
|
2023-02-01 13:46:23 -05:00
|
|
|
export const TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC = 'vault-generic';
|
|
|
|
|
export const TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE =
|
|
|
|
|
'vault-ssh-certificate';
|
|
|
|
|
|
2022-09-20 17:31:16 -07:00
|
|
|
/**
|
|
|
|
|
* Supported Credential Library types.
|
|
|
|
|
*/
|
2023-02-01 13:46:23 -05:00
|
|
|
export const TYPES_CREDENTIAL_LIBRARY = Object.freeze([
|
|
|
|
|
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
|
|
|
|
|
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
|
|
|
|
|
]);
|
2022-09-20 17:31:16 -07:00
|
|
|
|
|
|
|
|
export default class CredentialLibraryModel extends GeneratedCredentialLibraryModel {
|
|
|
|
|
// =attributes
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if credential is an unknown type.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isUnknown() {
|
2023-02-01 13:46:23 -05:00
|
|
|
return !TYPES_CREDENTIAL_LIBRARY.includes(this.type);
|
2022-09-20 17:31:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if credential is a vault type.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isVault() {
|
2023-02-01 13:46:23 -05:00
|
|
|
return (
|
|
|
|
|
this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC ||
|
|
|
|
|
this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if credential is a generic vault type.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isVaultGeneric() {
|
|
|
|
|
return this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* True if credential is a vault ssh cert type.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isVaultSSHCertificate() {
|
|
|
|
|
return this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE;
|
2022-09-20 17:31:16 -07:00
|
|
|
}
|
|
|
|
|
}
|