mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 19:17:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
89 lines
2.8 KiB
JavaScript
89 lines
2.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Model, { attr } from '@ember-data/model';
|
|
import { inject as service } from '@ember/service';
|
|
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
|
|
import { withFormFields } from 'vault/decorators/model-form-fields';
|
|
import { withModelValidations } from 'vault/decorators/model-validations';
|
|
|
|
const validations = {
|
|
type: [{ type: 'presence', message: 'Type is required.' }],
|
|
keyType: [{ type: 'presence', message: 'Please select a key type.' }],
|
|
keyName: [
|
|
{
|
|
validator(model) {
|
|
if (model.keyName === 'default') return false;
|
|
return true;
|
|
},
|
|
message: `Key name cannot be the reserved value 'default'`,
|
|
},
|
|
],
|
|
};
|
|
const displayFields = ['keyId', 'keyName', 'keyType', 'keyBits'];
|
|
const formFieldGroups = [{ default: ['keyName', 'type'] }, { 'Key parameters': ['keyType', 'keyBits'] }];
|
|
@withModelValidations(validations)
|
|
@withFormFields(displayFields, formFieldGroups)
|
|
export default class PkiKeyModel extends Model {
|
|
@service secretMountPath;
|
|
|
|
@attr('string', { detailsLabel: 'Key ID' }) keyId;
|
|
@attr('string', {
|
|
subText: `Optional, human-readable name for this key. The name must be unique across all keys and cannot be 'default'.`,
|
|
})
|
|
keyName;
|
|
@attr('string', {
|
|
noDefault: true,
|
|
possibleValues: ['internal', 'exported'],
|
|
subText:
|
|
'The type of operation. If exported, the private key will be returned in the response; if internal the private key will not be returned and cannot be retrieved later.',
|
|
})
|
|
type;
|
|
@attr('string', {
|
|
noDefault: true,
|
|
possibleValues: ['rsa', 'ec', 'ed25519'],
|
|
subText: 'The type of key that will be generated. Must be rsa, ed25519, or ec. ',
|
|
})
|
|
keyType;
|
|
@attr('string', {
|
|
label: 'Key bits',
|
|
noDefault: true,
|
|
subText: 'Bit length of the key to generate.',
|
|
})
|
|
keyBits; // no possibleValues because dependent on selected key type
|
|
|
|
@attr('string') pemBundle;
|
|
@attr('string') privateKey;
|
|
|
|
get backend() {
|
|
return this.secretMountPath.currentPath;
|
|
}
|
|
|
|
/* CAPABILITIES
|
|
* Default to show UI elements unless we know they can't access the given path
|
|
*/
|
|
|
|
@lazyCapabilities(apiPath`${'backend'}/key/${'keyId'}`, 'backend', 'keyId') keyPath;
|
|
get canRead() {
|
|
return this.keyPath.get('canRead') !== false;
|
|
}
|
|
get canEdit() {
|
|
return this.keyPath.get('canUpdate') !== false;
|
|
}
|
|
get canDelete() {
|
|
return this.keyPath.get('canDelete') !== false;
|
|
}
|
|
|
|
@lazyCapabilities(apiPath`${'backend'}/keys/generate`, 'backend') generatePath;
|
|
get canGenerateKey() {
|
|
return this.generatePath.get('canUpdate') !== false;
|
|
}
|
|
|
|
@lazyCapabilities(apiPath`${'backend'}/keys/import`, 'backend') importPath;
|
|
get canImportKey() {
|
|
return this.importPath.get('canUpdate') !== false;
|
|
}
|
|
}
|