2023-03-01 09:39:41 -06:00
|
|
|
/**
|
2026-01-28 17:09:06 -08:00
|
|
|
* Copyright IBM Corp. 2021, 2026
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2022-07-19 13:02:04 -07:00
|
|
|
import GeneratedCredentialModel from '../generated/models/credential';
|
|
|
|
|
|
2022-09-20 17:31:16 -07:00
|
|
|
/**
|
|
|
|
|
* Supported Credential types.
|
|
|
|
|
*/
|
2024-12-11 15:08:51 -08:00
|
|
|
|
|
|
|
|
export const TYPE_CREDENTIAL_USERNAME_PASSWORD = 'username_password';
|
|
|
|
|
export const TYPE_CREDENTIAL_SSH_PRIVATE_KEY = 'ssh_private_key';
|
|
|
|
|
export const TYPE_CREDENTIAL_JSON = 'json';
|
2025-11-03 14:28:25 -08:00
|
|
|
export const TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN =
|
|
|
|
|
'username_password_domain';
|
|
|
|
|
export const TYPE_CREDENTIAL_PASSWORD = 'password';
|
2024-12-11 15:08:51 -08:00
|
|
|
|
|
|
|
|
export const TYPES_CREDENTIAL = Object.freeze([
|
|
|
|
|
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
|
|
|
|
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
|
2025-06-17 11:24:19 -07:00
|
|
|
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
2024-12-11 15:08:51 -08:00
|
|
|
TYPE_CREDENTIAL_JSON,
|
2025-11-03 14:28:25 -08:00
|
|
|
TYPE_CREDENTIAL_PASSWORD,
|
2024-12-11 15:08:51 -08:00
|
|
|
]);
|
2022-09-20 17:31:16 -07:00
|
|
|
|
2022-09-02 12:29:39 -07:00
|
|
|
export default class CredentialModel extends GeneratedCredentialModel {
|
|
|
|
|
// =attributes
|
|
|
|
|
/**
|
2022-09-21 15:10:28 -05:00
|
|
|
* All Credentials are prefixed with "cred" and are considered
|
|
|
|
|
* static due to their relation with Static Credential Stores.
|
2022-10-06 11:41:12 -04:00
|
|
|
*
|
2022-09-21 15:10:28 -05:00
|
|
|
* True if credential starts with the "cred" prefix.
|
2022-09-02 12:29:39 -07:00
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
2022-09-21 15:10:28 -05:00
|
|
|
get isStatic() {
|
|
|
|
|
return this.id.startsWith('cred');
|
|
|
|
|
}
|
2022-09-20 17:31:16 -07:00
|
|
|
|
2022-12-16 15:06:19 -05:00
|
|
|
/**
|
|
|
|
|
* True if type is `json`.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isJSON() {
|
2024-12-11 15:08:51 -08:00
|
|
|
return this.type === TYPE_CREDENTIAL_JSON;
|
2022-12-16 15:06:19 -05:00
|
|
|
}
|
|
|
|
|
|
2022-09-20 17:31:16 -07:00
|
|
|
/**
|
|
|
|
|
* True if credential is an unknown type.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isUnknown() {
|
2024-12-11 15:08:51 -08:00
|
|
|
return !TYPES_CREDENTIAL.includes(this.type);
|
2022-09-20 17:31:16 -07:00
|
|
|
}
|
2022-09-02 12:29:39 -07:00
|
|
|
}
|