2021-03-29 16:22:15 +00:00
|
|
|
import { CertificateKeyPair, CryptoApi } from "authentik-api";
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-03-29 15:34:24 +00:00
|
|
|
import { customElement, property } from "lit-element";
|
|
|
|
import { html, TemplateResult } from "lit-html";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
|
|
import { Form } from "../../elements/forms/Form";
|
|
|
|
import { ifDefined } from "lit-html/directives/if-defined";
|
|
|
|
import "../../elements/forms/HorizontalFormElement";
|
|
|
|
import "../../elements/CodeMirror";
|
|
|
|
|
|
|
|
@customElement("ak-crypto-certificate-form")
|
|
|
|
export class CertificateKeyPairForm extends Form<CertificateKeyPair> {
|
|
|
|
|
|
|
|
@property({attribute: false})
|
|
|
|
keyPair?: CertificateKeyPair;
|
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
|
|
|
if (this.keyPair) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated certificate-key pair.`;
|
2021-03-29 15:34:24 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created certificate-key pair.`;
|
2021-03-29 15:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: CertificateKeyPair): Promise<CertificateKeyPair> => {
|
|
|
|
if (this.keyPair) {
|
|
|
|
return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsPartialUpdate({
|
|
|
|
kpUuid: this.keyPair.pk || "",
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsCreate({
|
|
|
|
data: data
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-03-29 16:22:15 +00:00
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Name`}
|
2021-03-29 16:22:15 +00:00
|
|
|
name="name"
|
|
|
|
?required=${true}>
|
|
|
|
<input type="text" value="${ifDefined(this.keyPair?.name)}" class="pf-c-form-control" required>
|
2021-03-29 15:34:24 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-03-29 16:22:15 +00:00
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Certificate`}
|
2021-03-29 16:22:15 +00:00
|
|
|
name="certificateData"
|
2021-04-04 18:11:57 +00:00
|
|
|
?writeOnly=${this.keyPair !== undefined}
|
2021-03-29 16:22:15 +00:00
|
|
|
?required=${true}>
|
|
|
|
<textarea class="pf-c-form-control" required>${ifDefined(this.keyPair?.certificateData)}</textarea>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`PEM-encoded Certificate data.`}</p>
|
2021-03-29 15:34:24 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-03-29 16:22:15 +00:00
|
|
|
<ak-form-element-horizontal
|
|
|
|
name="keyData"
|
2021-04-04 18:11:57 +00:00
|
|
|
?writeOnly=${this.keyPair !== undefined}
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Private Key`}>
|
2021-03-29 16:22:15 +00:00
|
|
|
<textarea class="pf-c-form-control" >${ifDefined(this.keyPair?.keyData)}</textarea>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Optional Private Key. If this is set, you can use this keypair for encryption.`}</p>
|
2021-03-29 15:34:24 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|