Files

101 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
2021-07-08 11:38:41 -04:00
import GeneratedCredentialLibraryModel from '../generated/models/credential-library';
2025-06-17 11:24:19 -07:00
import {
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
TYPE_CREDENTIAL_USERNAME_PASSWORD,
TYPE_CREDENTIAL_PASSWORD,
2025-06-17 11:24:19 -07:00
} from 'api/models/credential';
2021-07-18 14:31:45 -04:00
/**
* Enum options for credential library.
*/
export const options = {
http_method: ['GET', 'POST'],
2023-02-01 13:46:23 -05:00
key_type: ['ed25519', 'ecdsa', 'rsa'],
2025-06-17 11:24:19 -07:00
credential_types: [
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
TYPE_CREDENTIAL_USERNAME_PASSWORD,
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
TYPE_CREDENTIAL_PASSWORD,
2025-06-17 11:24:19 -07:00
],
mapping_overrides: {
2024-06-03 13:38:42 -07:00
username_password: ['username_attribute', 'password_attribute'],
ssh_private_key: [
'private_key_attribute',
'private_key_passphrase_attribute',
'username_attribute',
],
2025-06-17 11:24:19 -07:00
username_password_domain: [
'username_attribute',
'password_attribute',
'domain_attribute',
],
password: ['password_attribute'],
},
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';
2025-07-25 10:57:56 -05:00
export const TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP = 'vault-ldap';
2023-02-01 13:46:23 -05:00
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,
2025-07-25 10:57:56 -05:00
TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
2023-02-01 13:46:23 -05:00
]);
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 ||
2025-07-25 10:57:56 -05:00
this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE ||
this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP
2023-02-01 13:46:23 -05:00
);
}
/**
* 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
}
2025-07-25 10:57:56 -05:00
/**
* True if credential is a vault ldap type.
* @type {boolean}
*/
get isVaultLDAP() {
return this.type === TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP;
}
2022-09-20 17:31:16 -07:00
}