From 4660a46a7ea0922a968e41d9864bf8fb2393d400 Mon Sep 17 00:00:00 2001 From: Jacky Date: Wed, 24 Jul 2024 22:53:22 +0800 Subject: [PATCH] refactor: auto certificate options 1. Add OCSP Must Staple options #292 2. Add LEGO_DISABLE_CNAME_SUPPORT options #407 --- api/certificate/issue.go | 18 +++-- app/src/api/auto_cert.ts | 24 +++--- .../views/certificate/ACMEUserSelector.vue | 20 ++--- .../views/certificate/CertificateEditor.vue | 16 ++-- .../CertificateList/Certificate.vue | 7 -- app/src/views/certificate/RenewCert.vue | 14 ++-- .../views/certificate/WildcardCertificate.vue | 33 ++++---- app/src/views/domain/cert/IssueCert.vue | 16 ++-- .../cert/components/AutoCertStepOne.vue | 78 ++++++++++++------- .../domain/cert/components/DNSChallenge.vue | 18 ++--- .../domain/cert/components/ObtainCert.vue | 26 ++++--- .../domain/cert/components/ObtainCertLive.vue | 35 ++------- internal/cert/auto_cert.go | 14 ++-- internal/cert/cert.go | 13 +++- internal/cert/obtain.go | 5 +- internal/cert/payload.go | 24 +++--- internal/cert/renew.go | 53 ++++++------- model/cert.go | 32 ++++---- 18 files changed, 234 insertions(+), 212 deletions(-) diff --git a/api/certificate/issue.go b/api/certificate/issue.go index 36724832..f5a7e78d 100644 --- a/api/certificate/issue.go +++ b/api/certificate/issue.go @@ -117,14 +117,16 @@ func IssueCert(c *gin.Context) { } err = certModel.Updates(&model.Cert{ - Domains: payload.ServerName, - SSLCertificatePath: payload.GetCertificatePath(), - SSLCertificateKeyPath: payload.GetCertificateKeyPath(), - AutoCert: model.AutoCertEnabled, - KeyType: payload.KeyType, - ChallengeMethod: payload.ChallengeMethod, - DnsCredentialID: payload.DNSCredentialID, - Resource: payload.Resource, + Domains: payload.ServerName, + SSLCertificatePath: payload.GetCertificatePath(), + SSLCertificateKeyPath: payload.GetCertificateKeyPath(), + AutoCert: model.AutoCertEnabled, + KeyType: payload.KeyType, + ChallengeMethod: payload.ChallengeMethod, + DnsCredentialID: payload.DNSCredentialID, + Resource: payload.Resource, + MustStaple: payload.MustStaple, + LegoDisableCNAMESupport: payload.LegoDisableCNAMESupport, }) if err != nil { diff --git a/app/src/api/auto_cert.ts b/app/src/api/auto_cert.ts index 3fa99e88..cd776153 100644 --- a/app/src/api/auto_cert.ts +++ b/app/src/api/auto_cert.ts @@ -5,21 +5,27 @@ export interface DNSProvider { code?: string provider?: string configuration: { - credentials: { - [key: string]: string - } - additional: { - [key: string]: string - } + credentials: Record + additional: Record } links?: { api: string go_client: string } } -export interface DnsChallenge extends DNSProvider { - dns_credential_id: number | null - challenge_method: string + +export interface AutoCertOptions { + name?: string + domains: string[] + code?: string + dns_credential_id?: number | null + challenge_method?: string + configuration?: DNSProvider['configuration'] + key_type: string + acme_user_id?: number + provider?: string + must_staple?: boolean + lego_disable_cname_support?: boolean } const auto_cert = { diff --git a/app/src/views/certificate/ACMEUserSelector.vue b/app/src/views/certificate/ACMEUserSelector.vue index 0e7b4df6..3bc91497 100644 --- a/app/src/views/certificate/ACMEUserSelector.vue +++ b/app/src/views/certificate/ACMEUserSelector.vue @@ -3,18 +3,19 @@ import type { SelectProps } from 'ant-design-vue' import type { Ref } from 'vue' import type { AcmeUser } from '@/api/acme_user' import acme_user from '@/api/acme_user' -import type { Cert } from '@/api/cert' +import type { AutoCertOptions } from '@/api/auto_cert' const users = ref([]) as Ref -// This data is provided by the Top StdCurd component, -// is the object that you are trying to modify it -// we externalize the dns_credential_id to the parent component, -// this is used to tell the backend which dns_credential to use -const data = inject('data') as Ref +const data = defineModel('options', { + default: () => { + return {} + }, + required: true, +}) const id = computed(() => { - return data.value.acme_user_id + return data.value?.acme_user_id }) const user_idx = ref() @@ -35,7 +36,7 @@ watch(id, init) watch(current, () => { if (mounted.value) - data.value.acme_user_id = current.value.id + data.value!.acme_user_id = current.value.id }) onMounted(async () => { @@ -84,8 +85,9 @@ const filterOption = (input: string, option: { label: string }) => { diff --git a/app/src/views/certificate/CertificateEditor.vue b/app/src/views/certificate/CertificateEditor.vue index 0135b849..09fdd2ec 100644 --- a/app/src/views/certificate/CertificateEditor.vue +++ b/app/src/views/certificate/CertificateEditor.vue @@ -52,12 +52,6 @@ function save() { }) } -provide('data', data) - -provide('no_server_name', computed(() => { - return false -})) - const log = computed(() => { const logs = data.value.log?.split('\n') @@ -134,9 +128,17 @@ const isManaged = computed(() => { diff --git a/app/src/views/domain/cert/components/DNSChallenge.vue b/app/src/views/domain/cert/components/DNSChallenge.vue index 21c40a08..354827e1 100644 --- a/app/src/views/domain/cert/components/DNSChallenge.vue +++ b/app/src/views/domain/cert/components/DNSChallenge.vue @@ -1,19 +1,19 @@