vault/ui/app/models/ssh/ca-config.js
Angel Garbarino 2b3f517076
Add Azure configuration details view (#29071)
* configuration details only changes

* azure configuration acceptance test

* clean up

* change attrs to display attrs and reuse formFields

* missed some

* clean up

* Update ui/app/helpers/mountable-secret-engines.js

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>

* remove extra conditional

* fix test for oss runs

* clean up the logic for checking if the model has been configured

* remove formatTtl

* fix broken conditional

* address pr comments

* clean up clean up everybody lets clean up

---------

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
2024-12-10 16:21:55 -07:00

54 lines
1.9 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Model, { attr } from '@ember-data/model';
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
import { withModelValidations } from 'vault/decorators/model-validations';
const validations = {
generateSigningKey: [
{
validator(model) {
const { publicKey, privateKey, generateSigningKey } = model;
// if generateSigningKey is false, both public and private keys are required
if (!generateSigningKey && (!publicKey || !privateKey)) {
return false;
}
return true;
},
message: 'Provide a Public and Private key or set "Generate Signing Key" to true.',
},
],
publicKey: [
{
validator(model) {
const { publicKey, privateKey } = model;
// regardless of generateSigningKey, if one key is set they both need to be set.
return publicKey || privateKey ? publicKey && privateKey : true;
},
message: 'You must provide a Public and Private keys or leave both unset.',
},
],
};
// there are more options available on the API, but the UI does not support them yet.
@withModelValidations(validations)
export default class SshCaConfig extends Model {
@attr('string') backend; // dynamic path of secret -- set on response from value passed to queryRecord
@attr('string', { sensitive: true }) privateKey; // obfuscated, never returned by API
@attr('string') publicKey;
@attr('boolean', { defaultValue: true })
generateSigningKey;
// do not return private key for configuration.index view
get displayAttrs() {
return this.formFields.filter((attr) => attr.name !== 'privateKey');
}
// return private key for edit/create view
get formFields() {
const keys = ['privateKey', 'publicKey', 'generateSigningKey'];
return expandAttributeMeta(this, keys);
}
}