Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0466a02

Browse files
committed
Review
Update to reduce function signature changes
1 parent 902ea03 commit 0466a02

6 files changed

Lines changed: 37 additions & 22 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ boulder_setup:
6363

6464
# runs an instance of boulder
6565
boulder_start:
66-
docker-compose -f $(BOULDER_PATH)/docker-compose.yml -f $(BOULDER_PATH)/docker-compose.next.yml -f docker-compose.boulder-temp.yml up -d
66+
docker-compose -f $(BOULDER_PATH)/docker-compose.yml -f docker-compose.boulder-temp.yml up -d
6767

6868
# waits until boulder responds
6969
boulder_wait:

examples/certbot/certbot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func main() {
105105

106106
// create a new order with the acme service given the provided identifiers
107107
log.Printf("Creating new order for domains: %s", domainList)
108-
order, err := client.NewOrder(account, ids, "")
108+
order, err := client.NewOrder(account, ids)
109109
if err != nil {
110110
log.Fatalf("Error creating new order: %v", err)
111111
}

order.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@ import (
99
"time"
1010
)
1111

12+
type OrderExtension struct {
13+
Profile string
14+
}
15+
1216
// NewOrder initiates a new order for a new certificate. This method does not use ACME Renewal Info.
13-
func (c Client) NewOrder(account Account, identifiers []Identifier, profile string) (Order, error) {
14-
return c.ReplacementOrder(account, nil, identifiers, profile)
17+
func (c Client) NewOrder(account Account, identifiers []Identifier) (Order, error) {
18+
return c.ReplacementOrder(account, nil, identifiers)
1519
}
1620

1721
// NewOrderDomains takes a list of domain dns identifiers for a new certificate. Essentially a helper function.
18-
func (c Client) NewOrderDomains(account Account, profile string, domains ...string) (Order, error) {
22+
func (c Client) NewOrderDomains(account Account, domains ...string) (Order, error) {
1923
var identifiers []Identifier
2024
for _, d := range domains {
2125
identifiers = append(identifiers, Identifier{Type: "dns", Value: d})
2226
}
23-
return c.ReplacementOrder(account, nil, identifiers, profile)
27+
return c.ReplacementOrder(account, nil, identifiers)
28+
}
29+
30+
// NewOrderExtension takes a struct providing any extensions onto the order
31+
func (c Client) NewOrderExtension(account Account, identifiers []Identifier, ext OrderExtension) (Order, error) {
32+
return c.ReplacementOrderExtension(account, nil, identifiers, ext)
2433
}
2534

2635
// ReplacementOrder takes an existing *x509.Certificate and initiates a new
@@ -31,7 +40,12 @@ func (c Client) NewOrderDomains(account Account, profile string, domains ...stri
3140
// must match the list of identifiers from the parent order to be considered as
3241
// a valid replacement order.
3342
// See https://datatracker.ietf.org/doc/html/draft-ietf-acme-ari-03#section-5
34-
func (c Client) ReplacementOrder(account Account, oldCert *x509.Certificate, identifiers []Identifier, profile string) (Order, error) {
43+
func (c Client) ReplacementOrder(account Account, oldCert *x509.Certificate, identifiers []Identifier) (Order, error) {
44+
return c.ReplacementOrderExtension(account, oldCert, identifiers, OrderExtension{})
45+
}
46+
47+
// ReplacementOrderExtension takes a struct providing any extensions onto the order
48+
func (c Client) ReplacementOrderExtension(account Account, oldCert *x509.Certificate, identifiers []Identifier, ext OrderExtension) (Order, error) {
3549
// If an old cert being replaced is present and the acme directory doesn't list a RenewalInfo endpoint,
3650
// throw an error. This endpoint being present indicates support for ARI.
3751
if oldCert != nil && c.dir.RenewalInfo == "" {
@@ -43,19 +57,19 @@ func (c Client) ReplacementOrder(account Account, oldCert *x509.Certificate, ide
4357
newOrderReq := struct {
4458
Identifiers []Identifier `json:"identifiers"`
4559
Replaces string `json:"replaces,omitempty"`
46-
Profile string `json:"profile,omitempty"`
60+
Profile string `json:"Profile,omitempty"`
4761
}{
4862
Identifiers: identifiers,
4963
}
5064

5165
newOrderResp := Order{}
5266

53-
if profile != "" {
54-
_, ok := c.Directory().Meta.Profiles[profile]
67+
if ext.Profile != "" {
68+
_, ok := c.Directory().Meta.Profiles[ext.Profile]
5569
if !ok {
56-
return Order{}, fmt.Errorf("requested profile %q not advertised by directory", profile)
70+
return Order{}, fmt.Errorf("requested Profile not advertised by directory: %v", ext.Profile)
5771
}
58-
newOrderReq.Profile = profile
72+
newOrderReq.Profile = ext.Profile
5973
}
6074

6175
// If present, add the ari cert ID from the original/old certificate

order_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestClient_NewOrder(t *testing.T) {
1515
}
1616

1717
identifiers := []Identifier{{"dns", randString() + ".com"}}
18-
order, err := testClient.NewOrder(account, identifiers, "")
18+
order, err := testClient.NewOrder(account, identifiers)
1919
if err != nil {
2020
t.Fatalf("unexpected error making order: %v", err)
2121
}
@@ -24,7 +24,7 @@ func TestClient_NewOrder(t *testing.T) {
2424
}
2525

2626
badIdentifiers := []Identifier{{"bad", randString() + ".com"}}
27-
_, err = testClient.NewOrder(account, badIdentifiers, "")
27+
_, err = testClient.NewOrder(account, badIdentifiers)
2828
if err == nil {
2929
t.Fatal("expected error, got none")
3030
}
@@ -148,17 +148,17 @@ func TestClient_ReplacementOrder(t *testing.T) {
148148
t.Fatalf("unexpected error fetching certificates: %v", err)
149149
}
150150

151-
if _, err := tc2.ReplacementOrder(account, certs[0], order.Identifiers, ""); err == nil {
151+
if _, err := tc2.ReplacementOrder(account, certs[0], order.Identifiers); err == nil {
152152
t.Fatalf("expected error, got none")
153153
} else if err != ErrRenewalInfoNotSupported {
154154
t.Fatalf("unexpected error replacing order: %v", err)
155155
}
156156

157-
if _, err := testClient.ReplacementOrder(account, &x509.Certificate{Raw: []byte{1}}, order.Identifiers, ""); err == nil {
157+
if _, err := testClient.ReplacementOrder(account, &x509.Certificate{Raw: []byte{1}}, order.Identifiers); err == nil {
158158
t.Fatalf("expected error, got none")
159159
}
160160

161-
newOrder, err := testClient.ReplacementOrder(account, certs[0], order.Identifiers, "")
161+
newOrder, err := testClient.ReplacementOrder(account, certs[0], order.Identifiers)
162162
if err != nil {
163163
t.Fatalf("unexpected error replacing certificates: %v", err)
164164
}
@@ -183,12 +183,13 @@ func TestClient_NewOrderWithProfile(t *testing.T) {
183183
}
184184

185185
for profile := range testClient.dir.Meta.Profiles {
186-
order, err := testClient.NewOrder(account, []Identifier{{"dns", randString() + ".com"}}, profile)
186+
ext := OrderExtension{Profile: profile}
187+
order, err := testClient.NewOrderExtension(account, []Identifier{{"dns", randString() + ".com"}}, ext)
187188
if err != nil {
188189
t.Fatalf("unexpected error making order: %v", err)
189190
}
190191
if !reflect.DeepEqual(order.Profile, profile) {
191-
t.Fatalf("order profile mismatch, profile: %+v, order profile: %+v", profile, order.Profile)
192+
t.Fatalf("order Profile mismatch, Profile: %+v, order Profile: %+v", profile, order.Profile)
192193
}
193194
}
194195
}

types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type Order struct {
151151
Status string `json:"status"`
152152
Expires time.Time `json:"expires"`
153153
Identifiers []Identifier `json:"identifiers"`
154-
Profile string `json:"profile,omitempty"`
154+
Profile string `json:"Profile,omitempty"`
155155
NotBefore time.Time `json:"notBefore"`
156156
NotAfter time.Time `json:"notAfter"`
157157
Error Problem `json:"error"`

utility_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func makeOrder(t *testing.T, identifiers ...Identifier) (Account, Order) {
129129
}
130130
account := makeAccount(t)
131131

132-
order, err := testClient.NewOrder(account, identifiers, "")
132+
order, err := testClient.NewOrder(account, identifiers)
133133
if err != nil {
134134
t.Fatalf("error making order: %v", err)
135135
}
@@ -194,7 +194,7 @@ func makeReplacementOrderFinalized(t *testing.T, order Order, account Account, s
194194
return Order{}, fmt.Errorf("no certs")
195195
}
196196

197-
replacementOrder, err := testClient.ReplacementOrder(account, certs[0], order.Identifiers, "")
197+
replacementOrder, err := testClient.ReplacementOrder(account, certs[0], order.Identifiers)
198198
if err != nil {
199199
return Order{}, fmt.Errorf("expected no error, got: %v", err)
200200
}

0 commit comments

Comments
 (0)