diff --git a/ui/app/adapters/pki/urls.js b/ui/app/adapters/pki/urls.js new file mode 100644 index 000000000..c75f3212c --- /dev/null +++ b/ui/app/adapters/pki/urls.js @@ -0,0 +1,20 @@ +import { encodePath } from 'vault/utils/path-encoding-helpers'; +import ApplicationAdapter from '../application'; + +export default class PkiUrlsAdapter extends ApplicationAdapter { + namespace = 'v1'; + + _url(backend) { + return `${this.buildURL()}/${encodePath(backend)}/config/urls`; + } + + urlForCreateRecord(modelName, snapshot) { + return this._url(snapshot.record.id); + } + urlForFindRecord(id) { + return this._url(id); + } + urlForUpdateRecord(store, type, snapshot) { + return this._url(snapshot.record.id); + } +} diff --git a/ui/app/models/pki/action.js b/ui/app/models/pki/action.js index 499db2f76..07160545e 100644 --- a/ui/app/models/pki/action.js +++ b/ui/app/models/pki/action.js @@ -151,6 +151,8 @@ export default class PkiActionModel extends Model { @attr('string') ttl; @attr('date') notAfter; + @attr('string', { readOnly: true }) issuerId; // returned from generate-root action + get backend() { return this.secretMountPath.currentPath; } diff --git a/ui/app/models/pki/urls.js b/ui/app/models/pki/urls.js new file mode 100644 index 000000000..61c25bf9c --- /dev/null +++ b/ui/app/models/pki/urls.js @@ -0,0 +1,42 @@ +import Model, { attr } from '@ember-data/model'; +import { withFormFields } from 'vault/decorators/model-form-fields'; +import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities'; + +@withFormFields() +export default class PkiUrlsModel extends Model { + // This model uses the backend value as the model ID + get useOpenAPI() { + return true; + } + getHelpUrl(backendPath) { + return `/v1/${backendPath}/config/urls?help=1`; + } + + @attr({ + label: 'Issuing certificates', + subText: + 'The URL values for the Issuing Certificate field. These are different URLs for the same resource, and should be added individually, not in a comma-separated list.', + showHelpText: false, + }) + issuingCertificates; + + @attr({ + label: 'CRL distribution points', + subText: 'Specifies the URL values for the CRL Distribution Points field.', + showHelpText: false, + }) + crlDistributionPoints; + + @attr({ + label: 'OSCP Servers', + subText: 'Specifies the URL values for the OCSP Servers field.', + showHelpText: false, + }) + ocspServers; + + @lazyCapabilities(apiPath`${'id'}/config/urls`, 'id') urlsPath; + + get canSet() { + return this.urlsPath.get('canCreate') !== false; + } +} diff --git a/ui/app/serializers/pki/action.js b/ui/app/serializers/pki/action.js index 1575a3ce1..b4852fe9b 100644 --- a/ui/app/serializers/pki/action.js +++ b/ui/app/serializers/pki/action.js @@ -1,3 +1,5 @@ +import { underscore } from '@ember/string'; +import { keyParamsByType } from 'pki/utils/action-params'; import ApplicationSerializer from '../application'; export default class PkiActionSerializer extends ApplicationSerializer { @@ -9,7 +11,7 @@ export default class PkiActionSerializer extends ApplicationSerializer { serialize(snapshot, requestType) { const data = super.serialize(snapshot); // requestType is a custom value specified from the pki/action adapter - const allowedPayloadAttributes = this._allowedParamsByType(requestType); + const allowedPayloadAttributes = this._allowedParamsByType(requestType, snapshot.record.type); if (!allowedPayloadAttributes) return data; const payload = {}; @@ -21,7 +23,8 @@ export default class PkiActionSerializer extends ApplicationSerializer { return payload; } - _allowedParamsByType(actionType) { + _allowedParamsByType(actionType, type) { + const keyFields = keyParamsByType(type).map((attrName) => underscore(attrName).toLowerCase()); switch (actionType) { case 'import': return ['pem_bundle']; @@ -34,13 +37,7 @@ export default class PkiActionSerializer extends ApplicationSerializer { 'format', 'ip_sans', 'issuer_name', - 'key_bits', - 'key_name', - 'key_ref', - 'key_type', 'locality', - 'managed_key_id', - 'managed_key_name', 'max_path_length', 'not_after', 'not_before_duration', @@ -53,7 +50,9 @@ export default class PkiActionSerializer extends ApplicationSerializer { 'province', 'serial_number', 'street_address', + 'ttl', 'type', + ...keyFields, ]; default: // if type doesn't match, serialize all diff --git a/ui/lib/pki/addon/components/pki-configure-form.hbs b/ui/lib/pki/addon/components/pki-configure-form.hbs index bbe7ae043..2ddfc8360 100644 --- a/ui/lib/pki/addon/components/pki-configure-form.hbs +++ b/ui/lib/pki/addon/components/pki-configure-form.hbs @@ -31,20 +31,24 @@ {{else if (eq this.actionType "generate-root")}} {{else if (eq this.actionType "generate-csr")}} POST /intermediate/generate/:type ~or~ /issuers/generate/intermediate/:type {{else}} - +