Skip to content

Commit 4660a46

Browse files
committed
refactor: auto certificate options
1. Add OCSP Must Staple options #292 2. Add LEGO_DISABLE_CNAME_SUPPORT options #407
1 parent 532d6e8 commit 4660a46

File tree

18 files changed

+234
-212
lines changed

18 files changed

+234
-212
lines changed

api/certificate/issue.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,16 @@ func IssueCert(c *gin.Context) {
117117
}
118118

119119
err = certModel.Updates(&model.Cert{
120-
Domains: payload.ServerName,
121-
SSLCertificatePath: payload.GetCertificatePath(),
122-
SSLCertificateKeyPath: payload.GetCertificateKeyPath(),
123-
AutoCert: model.AutoCertEnabled,
124-
KeyType: payload.KeyType,
125-
ChallengeMethod: payload.ChallengeMethod,
126-
DnsCredentialID: payload.DNSCredentialID,
127-
Resource: payload.Resource,
120+
Domains: payload.ServerName,
121+
SSLCertificatePath: payload.GetCertificatePath(),
122+
SSLCertificateKeyPath: payload.GetCertificateKeyPath(),
123+
AutoCert: model.AutoCertEnabled,
124+
KeyType: payload.KeyType,
125+
ChallengeMethod: payload.ChallengeMethod,
126+
DnsCredentialID: payload.DNSCredentialID,
127+
Resource: payload.Resource,
128+
MustStaple: payload.MustStaple,
129+
LegoDisableCNAMESupport: payload.LegoDisableCNAMESupport,
128130
})
129131

130132
if err != nil {

app/src/api/auto_cert.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ export interface DNSProvider {
55
code?: string
66
provider?: string
77
configuration: {
8-
credentials: {
9-
[key: string]: string
10-
}
11-
additional: {
12-
[key: string]: string
13-
}
8+
credentials: Record<string, string>
9+
additional: Record<string, string>
1410
}
1511
links?: {
1612
api: string
1713
go_client: string
1814
}
1915
}
20-
export interface DnsChallenge extends DNSProvider {
21-
dns_credential_id: number | null
22-
challenge_method: string
16+
17+
export interface AutoCertOptions {
18+
name?: string
19+
domains: string[]
20+
code?: string
21+
dns_credential_id?: number | null
22+
challenge_method?: string
23+
configuration?: DNSProvider['configuration']
24+
key_type: string
25+
acme_user_id?: number
26+
provider?: string
27+
must_staple?: boolean
28+
lego_disable_cname_support?: boolean
2329
}
2430

2531
const auto_cert = {

app/src/views/certificate/ACMEUserSelector.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import type { SelectProps } from 'ant-design-vue'
33
import type { Ref } from 'vue'
44
import type { AcmeUser } from '@/api/acme_user'
55
import acme_user from '@/api/acme_user'
6-
import type { Cert } from '@/api/cert'
6+
import type { AutoCertOptions } from '@/api/auto_cert'
77
88
const users = ref([]) as Ref<AcmeUser[]>
99
10-
// This data is provided by the Top StdCurd component,
11-
// is the object that you are trying to modify it
12-
// we externalize the dns_credential_id to the parent component,
13-
// this is used to tell the backend which dns_credential to use
14-
const data = inject('data') as Ref<Cert>
10+
const data = defineModel<AutoCertOptions>('options', {
11+
default: () => {
12+
return {}
13+
},
14+
required: true,
15+
})
1516
1617
const id = computed(() => {
17-
return data.value.acme_user_id
18+
return data.value?.acme_user_id
1819
})
1920
2021
const user_idx = ref()
@@ -35,7 +36,7 @@ watch(id, init)
3536
3637
watch(current, () => {
3738
if (mounted.value)
38-
data.value.acme_user_id = current.value.id
39+
data.value!.acme_user_id = current.value.id
3940
})
4041
4142
onMounted(async () => {
@@ -84,8 +85,9 @@ const filterOption = (input: string, option: { label: string }) => {
8485
<AFormItem :label="$gettext('ACME User')">
8586
<ASelect
8687
v-model:value="user_idx"
88+
:placeholder="$gettext('System Initial User')"
8789
show-search
88-
:options="options"
90+
:options
8991
:filter-option="filterOption"
9092
/>
9193
</AFormItem>

app/src/views/certificate/CertificateEditor.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ function save() {
5252
})
5353
}
5454
55-
provide('data', data)
56-
57-
provide('no_server_name', computed(() => {
58-
return false
59-
}))
60-
6155
const log = computed(() => {
6256
const logs = data.value.log?.split('\n')
6357
@@ -134,9 +128,17 @@ const isManaged = computed(() => {
134128
</AForm>
135129

136130
<template v-if="isManaged">
137-
<RenewCert @renewed="init" />
131+
<RenewCert
132+
:options="{
133+
name: data.name,
134+
domains: data.domains,
135+
key_type: data.key_type,
136+
}"
137+
@renewed="init"
138+
/>
138139

139140
<AutoCertStepOne
141+
v-model:options="data"
140142
style="max-width: 600px"
141143
hide-note
142144
/>

app/src/views/certificate/CertificateList/Certificate.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ import StdTable from '@/components/StdDesign/StdDataDisplay/StdTable.vue'
55
import cert from '@/api/cert'
66
import WildcardCertificate from '@/views/certificate/WildcardCertificate.vue'
77
8-
// DO NOT REMOVE THESE LINES
9-
const no_server_name = computed(() => {
10-
return false
11-
})
12-
13-
provide('no_server_name', no_server_name)
14-
158
const refWildcard = ref()
169
const refTable = ref()
1710
</script>

app/src/views/certificate/RenewCert.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<script setup lang="ts">
2-
import type { Ref } from 'vue'
32
import { message } from 'ant-design-vue'
43
import ObtainCertLive from '@/views/domain/cert/components/ObtainCertLive.vue'
5-
import type { Cert } from '@/api/cert'
4+
import type { AutoCertOptions } from '@/api/auto_cert'
5+
6+
const props = defineProps<{
7+
options: AutoCertOptions
8+
}>()
69
710
const emit = defineEmits<{
811
renewed: [void]
@@ -13,12 +16,12 @@ const modalClosable = ref(true)
1316
1417
const refObtainCertLive = ref()
1518
16-
const data = inject('data') as Ref<Cert>
17-
1819
const issueCert = () => {
1920
modalVisible.value = true
2021
21-
refObtainCertLive.value.issue_cert(data.value.name, data.value.domains, data.value.key_type).then(() => {
22+
const { name, domains, key_type } = props.options
23+
24+
refObtainCertLive.value.issue_cert(name, domains, key_type).then(() => {
2225
message.success($gettext('Renew successfully'))
2326
emit('renewed')
2427
})
@@ -52,6 +55,7 @@ provide('issuing_cert', issuing_cert)
5255
ref="refObtainCertLive"
5356
v-model:modal-closable="modalClosable"
5457
v-model:modal-visible="modalVisible"
58+
:options
5559
/>
5660
</AModal>
5761
</div>

app/src/views/certificate/WildcardCertificate.vue

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
<script setup lang="ts">
22
import type { Ref } from 'vue'
33
import { message } from 'ant-design-vue'
4-
import type { Cert } from '@/api/cert'
54
import ObtainCertLive from '@/views/domain/cert/components/ObtainCertLive.vue'
6-
import DNSChallenge from '@/views/domain/cert/components/DNSChallenge.vue'
7-
import { PrivateKeyTypeList } from '@/constants'
5+
import type { AutoCertOptions } from '@/api/auto_cert'
6+
import AutoCertStepOne from '@/views/domain/cert/components/AutoCertStepOne.vue'
87
98
const emit = defineEmits<{
109
issued: [void]
1110
}>()
1211
1312
const step = ref(0)
1413
const visible = ref(false)
15-
const data = ref({}) as Ref<Cert>
14+
const data = ref({}) as Ref<AutoCertOptions>
1615
const issuing_cert = ref(false)
1716
18-
provide('data', data)
1917
provide('issuing_cert', issuing_cert)
2018
function open() {
2119
visible.value = true
2220
step.value = 0
2321
data.value = {
2422
challenge_method: 'dns01',
2523
key_type: '2048',
26-
} as Cert
24+
} as AutoCertOptions
2725
}
2826
2927
defineExpose({
@@ -66,28 +64,22 @@ const issueCert = () => {
6664
force-render
6765
>
6866
<template v-if="step === 0">
69-
<DNSChallenge />
70-
7167
<AForm layout="vertical">
7268
<AFormItem :label="$gettext('Domain')">
7369
<AInput
7470
v-model:value="domain"
7571
addon-before="*."
7672
/>
7773
</AFormItem>
78-
79-
<AFormItem :label="$gettext('Key Type')">
80-
<ASelect v-model:value="data.key_type">
81-
<ASelectOption
82-
v-for="t in PrivateKeyTypeList"
83-
:key="t.key"
84-
:value="t.key"
85-
>
86-
{{ t.name }}
87-
</ASelectOption>
88-
</ASelect>
89-
</AFormItem>
9074
</AForm>
75+
76+
<AutoCertStepOne
77+
v-model:options="data"
78+
style="max-width: 600px"
79+
hide-note
80+
force-dns-challenge
81+
/>
82+
9183
<div
9284
v-if="step === 0"
9385
class="flex justify-end"
@@ -106,6 +98,7 @@ const issueCert = () => {
10698
ref="refObtainCertLive"
10799
v-model:modal-closable="modalClosable"
108100
v-model:modal-visible="modalVisible"
101+
:options="data"
109102
/>
110103
</AModal>
111104
</div>

app/src/views/domain/cert/IssueCert.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import ObtainCert from '@/views/domain/cert/components/ObtainCert.vue'
33
import type { NgxDirective } from '@/api/ngx'
44
5-
export interface Props {
5+
defineProps<{
66
configName: string
7-
}
8-
9-
const props = defineProps<Props>()
7+
}>()
108
119
const issuing_cert = ref(false)
1210
const obtain_cert = ref()
@@ -16,18 +14,16 @@ const enabled = defineModel<boolean>('enabled', {
1614
default: () => false,
1715
})
1816
19-
const no_server_name = computed(() => {
17+
const noServerName = computed(() => {
2018
if (!directivesMap.value.server_name)
2119
return true
2220
2321
return directivesMap.value.server_name.length === 0
2422
})
2523
26-
provide('no_server_name', no_server_name)
27-
provide('props', props)
2824
provide('issuing_cert', issuing_cert)
2925
30-
watch(no_server_name, () => {
26+
watch(noServerName, () => {
3127
enabled.value = false
3228
})
3329
@@ -45,14 +41,16 @@ async function onchange() {
4541
<ObtainCert
4642
ref="obtain_cert"
4743
:key="update"
44+
:no-server-name="noServerName"
45+
:config-name="configName"
4846
@update:auto_cert="r => enabled = r"
4947
/>
5048
<div class="issue-cert">
5149
<AFormItem :label="$gettext('Encrypt website with Let\'s Encrypt')">
5250
<ASwitch
5351
:loading="issuing_cert"
5452
:checked="enabled"
55-
:disabled="no_server_name"
53+
:disabled="noServerName"
5654
@change="onchange"
5755
/>
5856
</AFormItem>

0 commit comments

Comments
 (0)