Skip to content

Commit 555a3bc

Browse files
committed
MINOR: add support for acme keyword reuse-key
1 parent ef1fa7e commit 555a3bc

File tree

11 files changed

+93
-4
lines changed

11 files changed

+93
-4
lines changed

config-parser/section-parsers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,5 +1044,6 @@ func (p *configParser) getAcmeParser() *Parsers {
10441044
addParser(parser, &sequence, &simple.Word{Name: "directory"})
10451045
addParser(parser, &sequence, &simple.Word{Name: "keytype"})
10461046
addParser(parser, &sequence, &simple.Word{Name: "map"})
1047+
addParser(parser, &sequence, &simple.OnOff{Name: "reuse-key"})
10471048
return p.createParsers(parser, sequence)
10481049
}

configuration/acme_provider.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func ParseAcmeProvider(p parser.Parser, name string) (*models.AcmeProvider, erro
172172
"directory": &acme.Directory,
173173
"keytype": &acme.Keytype,
174174
"map": &acme.Map,
175+
"reuse-key": &acme.ReuseKey,
175176
}
176177

177178
for kw, dest := range stringAttr {
@@ -189,6 +190,8 @@ func ParseAcmeProvider(p parser.Parser, name string) (*models.AcmeProvider, erro
189190
*dest = str.Value
190191
}
191192

193+
acme.ReuseKey = onOff(acme.ReuseKey)
194+
192195
// bits
193196
val, err := p.Get(parser.Acme, name, "bits")
194197
if err != nil {
@@ -239,6 +242,7 @@ func SerializeAcmeProvider(p parser.Parser, acme *models.AcmeProvider) error {
239242
"directory": acme.Directory,
240243
"keytype": acme.Keytype,
241244
"map": acme.Map,
245+
"reuse-key": onOff(acme.ReuseKey),
242246
}
243247

244248
for kw, val := range stringAttr {
@@ -358,3 +362,18 @@ func acmeValidKey(key string) bool {
358362
}
359363
return true
360364
}
365+
366+
func onOff(s string) string {
367+
switch len(s) {
368+
case 2: // on
369+
return "enabled"
370+
case 3: // off
371+
return "disabled"
372+
case 7: // enabled
373+
return "on"
374+
case 8: // disabled
375+
return "off"
376+
default:
377+
return s
378+
}
379+
}

models/acme_provider.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/acme_provider_compare_test.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/acmeprovider_diff_generated.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/acmeprovider_equal_generated.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/build/haproxy_spec.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11939,6 +11939,12 @@ definitions:
1193911939
description: ACME provider's name
1194011940
type: string
1194111941
x-nullable: false
11942+
reuse_key:
11943+
description: Try to reuse the private key instead of generating a new one.
11944+
enum:
11945+
- enabled
11946+
- disabled
11947+
type: string
1194211948
required:
1194311949
- name
1194411950
- directory

specification/models/configuration/acme.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ acme:
5151
map:
5252
type: string
5353
description: The map which will be used to store the ACME token (key) and thumbprint
54+
reuse_key:
55+
type: string
56+
enum: [enabled, disabled]
57+
description: Try to reuse the private key instead of generating a new one.
5458
metadata:
5559
additionalProperties:
5660
type: object

test/acme_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func TestCreateEditDeleteAcmeProvider(t *testing.T) {
108108
Directory: "https://acme.ninja.com/directory",
109109
Keytype: "ECDSA",
110110
Map: "acme@virt",
111+
ReuseKey: models.AcmeProviderReuseKeyEnabled,
111112
}
112113

113114
err := clientTest.CreateAcmeProvider(a, "", version)
@@ -132,6 +133,7 @@ func TestCreateEditDeleteAcmeProvider(t *testing.T) {
132133
// Edit
133134
a.Contact = "[email protected]"
134135
a.Bits = misc.Int64P(4096)
136+
a.ReuseKey = ""
135137
err = clientTest.EditAcmeProvider(a.Name, a, "", version)
136138
require.NoError(err)
137139
version++

test/configuration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ acme test
10191019
directory https://acme.example.com/directory
10201020
keytype ECDSA
10211021
map acme@t
1022+
reuse-key on
10221023
10231024
crt-store cert-bunker1
10241025
crt-base /secure/certs

0 commit comments

Comments
 (0)