-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
288 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { encodePath } from 'vault/utils/path-encoding-helpers'; | ||
import ApplicationAdapter from '../../application'; | ||
|
||
export default class PkiCertificateBaseAdapter extends ApplicationAdapter { | ||
namespace = 'v1'; | ||
|
||
deleteRecord(store, type, snapshot) { | ||
const { backend, serialNumber, certificate } = snapshot.record; | ||
// Revoke certificate requires either serial_number or certificate | ||
const data = serialNumber ? { serial_number: serialNumber } : { certificate }; | ||
return this.ajax(`${this.buildURL()}/${encodePath(backend)}/revoke`, 'POST', { data }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import { encodePath } from 'vault/utils/path-encoding-helpers'; | ||
import ApplicationAdapter from '../../application'; | ||
|
||
export default class PkiCertificateGenerateAdapter extends ApplicationAdapter { | ||
namespace = 'v1'; | ||
|
||
deleteRecord(store, type, snapshot) { | ||
const { backend, serialNumber, certificate } = snapshot.record; | ||
// Revoke certificate requires either serial_number or certificate | ||
const data = serialNumber ? { serial_number: serialNumber } : { certificate }; | ||
return this.ajax(`${this.buildURL()}/${encodePath(backend)}/revoke`, 'POST', { data }); | ||
} | ||
import PkiCertificateBaseAdapter from './base'; | ||
|
||
export default class PkiCertificateGenerateAdapter extends PkiCertificateBaseAdapter { | ||
urlForCreateRecord(modelName, snapshot) { | ||
const { name, backend } = snapshot.record; | ||
if (!name || !backend) { | ||
const { role, backend } = snapshot.record; | ||
if (!role || !backend) { | ||
throw new Error('URL for create record is missing required attributes'); | ||
} | ||
return `${this.buildURL()}/${encodePath(backend)}/issue/${encodePath(name)}`; | ||
return `${this.buildURL()}/${encodePath(backend)}/issue/${encodePath(role)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { encodePath } from 'vault/utils/path-encoding-helpers'; | ||
import PkiCertificateBaseAdapter from './base'; | ||
|
||
export default class PkiCertificateSignAdapter extends PkiCertificateBaseAdapter { | ||
urlForCreateRecord(modelName, snapshot) { | ||
const { role, backend } = snapshot.record; | ||
if (!role || !backend) { | ||
throw new Error('URL for create record is missing required attributes'); | ||
} | ||
return `${this.buildURL()}/${encodePath(backend)}/sign/${encodePath(role)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { attr } from '@ember-data/model'; | ||
import { withFormFields } from 'vault/decorators/model-form-fields'; | ||
import PkiCertificateBaseModel from './base'; | ||
|
||
const generateFromRole = [ | ||
{ | ||
default: ['csr', 'commonName', 'customTtl', 'format', 'removeRootsFromChain'], | ||
}, | ||
{ | ||
'Subject Alternative Name (SAN) Options': [ | ||
'excludeCnFromSans', | ||
'altNames', | ||
'ipSans', | ||
'uriSans', | ||
'otherSans', | ||
], | ||
}, | ||
]; | ||
@withFormFields(null, generateFromRole) | ||
export default class PkiCertificateSignModel extends PkiCertificateBaseModel { | ||
getHelpUrl(backend) { | ||
return `/v1/${backend}/sign/example?help=1`; | ||
} | ||
@attr('string') role; | ||
|
||
@attr('string', { | ||
label: 'CSR', | ||
editType: 'textarea', | ||
}) | ||
csr; | ||
|
||
@attr({ | ||
label: 'Not valid after', | ||
detailsLabel: 'Issued certificates expire after', | ||
subText: | ||
'The time after which this certificate will no longer be valid. This can be a TTL (a range of time from now) or a specific date.', | ||
editType: 'yield', | ||
}) | ||
customTtl; | ||
|
||
@attr('boolean', { | ||
subText: 'When checked, the CA chain will not include self-signed CA certificates', | ||
}) | ||
removeRootsFromChain; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { parseCertificate } from 'vault/helpers/parse-pki-cert'; | ||
import ApplicationSerializer from '../../application'; | ||
|
||
export default class PkiCertificateSignSerializer extends ApplicationSerializer { | ||
primaryKey = 'serial_number'; | ||
attrs = { | ||
type: { serialize: false }, | ||
}; | ||
|
||
normalizeResponse(store, primaryModelClass, payload, id, requestType) { | ||
if (requestType === 'createRecord' && payload.data.certificate) { | ||
// Parse certificate back from the API and add to payload | ||
const parsedCert = parseCertificate(payload.data.certificate); | ||
const json = super.normalizeResponse( | ||
store, | ||
primaryModelClass, | ||
{ ...payload, ...parsedCert }, | ||
id, | ||
requestType | ||
); | ||
return json; | ||
} | ||
return super.normalizeResponse(...arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export default class PkiRolesSignController extends Controller { | ||
@tracked hasSubmitted = false; | ||
|
||
@action | ||
toggleTitle() { | ||
this.hasSubmitted = !this.hasSubmitted; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
import Route from '@ember/routing/route'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class PkiRoleSignRoute extends Route {} | ||
export default class PkiRoleSignRoute extends Route { | ||
@service store; | ||
@service secretMountPath; | ||
@service pathHelp; | ||
|
||
beforeModel() { | ||
// Must call this promise before the model hook otherwise | ||
// the model doesn't hydrate from OpenAPI correctly. | ||
return this.pathHelp.getNewModel('pki/certificate/sign', this.secretMountPath.currentPath); | ||
} | ||
|
||
model() { | ||
const { role } = this.paramsFor('roles/role'); | ||
return this.store.createRecord('pki/certificate/sign', { | ||
role, | ||
}); | ||
} | ||
|
||
setupController(controller, resolvedModel) { | ||
super.setupController(controller, resolvedModel); | ||
const { role } = this.paramsFor('roles/role'); | ||
const backend = this.secretMountPath.currentPath || 'pki'; | ||
controller.breadcrumbs = [ | ||
{ label: 'secrets', route: 'secrets', linkExternal: true }, | ||
{ label: backend, route: 'overview' }, | ||
{ label: 'roles', route: 'roles.index' }, | ||
{ label: role, route: 'roles.role.details' }, | ||
{ label: 'sign certificate' }, | ||
]; | ||
// This is updated on successful generate in the controller | ||
controller.hasSubmitted = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
route: roles.role.sign | ||
<PageHeader as |p|> | ||
<p.top> | ||
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} /> | ||
</p.top> | ||
<p.levelLeft> | ||
<h1 class="title is-3" data-test-pki-role-page-title> | ||
<Icon @name="certificate" @size="24" class="has-text-grey-light" /> | ||
{{if this.hasSubmitted "View signed certificate" "Sign certificate"}} | ||
</h1> | ||
</p.levelLeft> | ||
</PageHeader> | ||
|
||
<PkiRoleGenerate @model={{this.model}} @type="sign" @onSuccess={{this.toggleTitle}} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.