Files
threshold-ui/addons/api/addon/models/auth-method.js
T
Lisbet AlvarezandDharini Jeeva 3b284fac66 refactor: 💡 update to allow state change & update edit action (#1797)
* refactor: 💡 update to allow state change & update edit action

✅ Closes: ICU-10078

* test: 💍 add more update and delete test cases

* refactor: 💡 auth-method serializer

* refactor: 💡 add secret input fields

* refactor: 💡 remove changes to ldap auth method serializer

---------

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
2023-07-27 14:25:40 -07:00

134 lines
2.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import GeneratedAuthMethodModel from '../generated/models/auth-method';
import { equal } from '@ember/object/computed';
export const TYPE_AUTH_METHOD_PASSWORD = 'password';
export const TYPE_AUTH_METHOD_OIDC = 'oidc';
export const TYPE_AUTH_METHOD_LDAP = 'ldap';
export const TYPES_AUTH_METHOD = Object.freeze([
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
]);
/**
* Enum options per auth method type and field.
*/
export const options = {
state: ['inactive', 'active-private', 'active-public'],
oidc: {
signing_algorithms: [
'RS256',
'RS384',
'RS512',
'ES256',
'ES384',
'ES512',
'PS256',
'PS384',
'PS512',
'EdDSA',
],
account_claim_maps: {
to: ['sub', 'name', 'email'],
},
},
ldap: {
account_attribute_maps: {
to: ['fullName', 'email'],
},
},
};
export default class AuthMethodModel extends GeneratedAuthMethodModel {
// =attributes
/**
* @type {boolean}
*/
@equal('is_primary', true) isPrimary;
options = options;
/**
* @type {boolean}
*/
get isPassword() {
return this.type === TYPE_AUTH_METHOD_PASSWORD;
}
/**
* @type {boolean}
*/
get isOIDC() {
return this.type === TYPE_AUTH_METHOD_OIDC;
}
/**
* @type {boolean}
*/
get isLDAP() {
return this.type === TYPE_AUTH_METHOD_LDAP;
}
/**
* @type {boolean}
*/
get isUnknown() {
return !TYPES_AUTH_METHOD.includes(this.type);
}
/**
* @type {boolean}
*/
get isInactive() {
return this.state === 'inactive';
}
/**
* @type {boolean}
*/
get isPrivate() {
return this.state === 'active-private';
}
/**
* @type {boolean}
*/
get isPublic() {
return this.state === 'active-public';
}
// =methods
/**
* Change the active and visibility state of an OIDC and LDAP auth method
* given its ID.
* For OIDC and LDAP auth methods only.
* @param {[string]} state
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
changeState(state, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
state,
};
if (this.isOIDC) {
defaultAdapterOptions.method = 'change-state';
}
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions,
},
});
}
}