2022-09-14 22:05:21 +00:00
|
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
|
|
|
import "@goauthentik/elements/CodeMirror";
|
|
|
|
import "@goauthentik/elements/forms/HorizontalFormElement";
|
|
|
|
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { CertificateKeyPair, CertificateKeyPairRequest, CryptoApi } from "@goauthentik/api";
|
|
|
|
|
2021-03-29 15:34:24 +00:00
|
|
|
@customElement("ak-crypto-certificate-form")
|
2021-05-11 09:55:25 +00:00
|
|
|
export class CertificateKeyPairForm extends ModelForm<CertificateKeyPair, string> {
|
|
|
|
loadInstance(pk: string): Promise<CertificateKeyPair> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsRetrieve({
|
2021-05-11 09:55:25 +00:00
|
|
|
kpUuid: pk,
|
|
|
|
});
|
|
|
|
}
|
2021-03-29 15:34:24 +00:00
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 09:55:25 +00:00
|
|
|
if (this.instance) {
|
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> => {
|
2021-05-11 09:55:25 +00:00
|
|
|
if (this.instance) {
|
2021-03-29 15:34:24 +00:00
|
|
|
return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsPartialUpdate({
|
2021-05-11 09:55:25 +00:00
|
|
|
kpUuid: this.instance.pk || "",
|
2021-08-03 15:52:21 +00:00
|
|
|
patchedCertificateKeyPairRequest: data,
|
2021-03-29 15:34:24 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new CryptoApi(DEFAULT_CONFIG).cryptoCertificatekeypairsCreate({
|
2021-08-03 15:52:21 +00:00
|
|
|
certificateKeyPairRequest: data as unknown as CertificateKeyPairRequest,
|
2021-03-29 15:34:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Name`} name="name" ?required=${true}>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.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-05-11 09:55:25 +00:00
|
|
|
?writeOnly=${this.instance !== undefined}
|
2021-08-03 15:52:21 +00:00
|
|
|
?required=${true}
|
|
|
|
>
|
2021-05-16 16:24:15 +00:00
|
|
|
<textarea class="pf-c-form-control" required></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-05-11 09:55:25 +00:00
|
|
|
?writeOnly=${this.instance !== undefined}
|
2021-08-03 15:52:21 +00:00
|
|
|
label=${t`Private Key`}
|
|
|
|
>
|
|
|
|
<textarea class="pf-c-form-control"></textarea>
|
|
|
|
<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>`;
|
|
|
|
}
|
|
|
|
}
|