Files
threshold-ui/addons/api/addon/models/credential.js
T

55 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
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.
*/
export const TYPE_CREDENTIAL_USERNAME_PASSWORD = 'username_password';
export const TYPE_CREDENTIAL_SSH_PRIVATE_KEY = 'ssh_private_key';
export const TYPE_CREDENTIAL_JSON = 'json';
export const TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN =
'username_password_domain';
export const TYPE_CREDENTIAL_PASSWORD = 'password';
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,
TYPE_CREDENTIAL_JSON,
TYPE_CREDENTIAL_PASSWORD,
]);
2022-09-20 17:31:16 -07:00
2022-09-02 12:29:39 -07:00
export default class CredentialModel extends GeneratedCredentialModel {
// =attributes
/**
* 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
*
* True if credential starts with the "cred" prefix.
2022-09-02 12:29:39 -07:00
* @type {boolean}
*/
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() {
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() {
return !TYPES_CREDENTIAL.includes(this.type);
2022-09-20 17:31:16 -07:00
}
2022-09-02 12:29:39 -07:00
}