Skip to content

Commit 02cd3b6

Browse files
committed
Fix PR comments
1 parent 66464ae commit 02cd3b6

File tree

5 files changed

+160
-99
lines changed

5 files changed

+160
-99
lines changed

acme/account.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ func KeyToID(jwk *jose.JSONWebKey) (string, error) {
4444
}
4545

4646
type ExternalAccountKey struct {
47-
ID string `json:"id"`
48-
ProvisionerName string `json:"provisionerName"`
49-
Name string `json:"name"`
50-
AccountID string `json:"-"`
51-
KeyBytes []byte `json:"-"`
52-
CreatedAt time.Time `json:"createdAt"`
53-
BoundAt time.Time `json:"boundAt,omitempty"`
47+
ID string `json:"id"`
48+
Provisioner string `json:"provisioner"`
49+
Reference string `json:"reference"`
50+
AccountID string `json:"-"`
51+
KeyBytes []byte `json:"-"`
52+
CreatedAt time.Time `json:"createdAt"`
53+
BoundAt time.Time `json:"boundAt,omitempty"`
5454
}
5555

5656
func (eak *ExternalAccountKey) AlreadyBound() bool {

acme/api/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (h *Handler) validateExternalAccountBinding(ctx context.Context, nar *NewAc
257257
// about the handler and thus about its dependencies.
258258
eabJSONBytes, err := json.Marshal(nar.ExternalAccountBinding)
259259
if err != nil {
260-
return nil, acme.WrapErrorISE(err, "error marshaling externalAccountBinding into JSON")
260+
return nil, acme.WrapErrorISE(err, "error marshaling externalAccountBinding into bytes")
261261
}
262262

263263
eabJWS, err := squarejose.ParseSigned(string(eabJSONBytes))

acme/api/account_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,11 @@ func TestHandler_NewAccount(t *testing.T) {
686686
},
687687
MockGetExternalAccountKey: func(ctx context.Context, provisionerName string, keyID string) (*acme.ExternalAccountKey, error) {
688688
return &acme.ExternalAccountKey{
689-
ID: "eakID",
690-
ProvisionerName: escProvName,
691-
Name: "testeak",
692-
KeyBytes: []byte{1, 3, 3, 7},
693-
CreatedAt: time.Now(),
689+
ID: "eakID",
690+
Provisioner: escProvName,
691+
Reference: "testeak",
692+
KeyBytes: []byte{1, 3, 3, 7},
693+
CreatedAt: time.Now(),
694694
}, nil
695695
},
696696
MockUpdateExternalAccountKey: func(ctx context.Context, provisionerName string, eak *acme.ExternalAccountKey) error {
@@ -1059,11 +1059,11 @@ func TestHandler_validateExternalAccountBinding(t *testing.T) {
10591059
db: &acme.MockDB{
10601060
MockGetExternalAccountKey: func(ctx context.Context, provisionerName string, keyID string) (*acme.ExternalAccountKey, error) {
10611061
return &acme.ExternalAccountKey{
1062-
ID: "eakID",
1063-
ProvisionerName: escProvName,
1064-
Name: "testeak",
1065-
KeyBytes: []byte{1, 3, 3, 7},
1066-
CreatedAt: time.Now(),
1062+
ID: "eakID",
1063+
Provisioner: escProvName,
1064+
Reference: "testeak",
1065+
KeyBytes: []byte{1, 3, 3, 7},
1066+
CreatedAt: time.Now(),
10671067
}, nil
10681068
},
10691069
},
@@ -1200,12 +1200,12 @@ func TestHandler_validateExternalAccountBinding(t *testing.T) {
12001200
db: &acme.MockDB{
12011201
MockGetExternalAccountKey: func(ctx context.Context, provisionerName string, keyID string) (*acme.ExternalAccountKey, error) {
12021202
return &acme.ExternalAccountKey{
1203-
ID: "eakID",
1204-
ProvisionerName: escProvName,
1205-
Name: "testeak",
1206-
CreatedAt: createdAt,
1207-
AccountID: "some-account-id",
1208-
BoundAt: boundAt,
1203+
ID: "eakID",
1204+
Provisioner: escProvName,
1205+
Reference: "testeak",
1206+
CreatedAt: createdAt,
1207+
AccountID: "some-account-id",
1208+
BoundAt: boundAt,
12091209
}, nil
12101210
},
12111211
},
@@ -1235,11 +1235,11 @@ func TestHandler_validateExternalAccountBinding(t *testing.T) {
12351235
db: &acme.MockDB{
12361236
MockGetExternalAccountKey: func(ctx context.Context, provisionerName string, keyID string) (*acme.ExternalAccountKey, error) {
12371237
return &acme.ExternalAccountKey{
1238-
ID: "eakID",
1239-
ProvisionerName: escProvName,
1240-
Name: "testeak",
1241-
KeyBytes: []byte{1, 2, 3, 4},
1242-
CreatedAt: time.Now(),
1238+
ID: "eakID",
1239+
Provisioner: escProvName,
1240+
Reference: "testeak",
1241+
KeyBytes: []byte{1, 2, 3, 4},
1242+
CreatedAt: time.Now(),
12431243
}, nil
12441244
},
12451245
},
@@ -1271,11 +1271,11 @@ func TestHandler_validateExternalAccountBinding(t *testing.T) {
12711271
db: &acme.MockDB{
12721272
MockGetExternalAccountKey: func(ctx context.Context, provisionerName string, keyID string) (*acme.ExternalAccountKey, error) {
12731273
return &acme.ExternalAccountKey{
1274-
ID: "eakID",
1275-
ProvisionerName: escProvName,
1276-
Name: "testeak",
1277-
KeyBytes: []byte{1, 3, 3, 7},
1278-
CreatedAt: time.Now(),
1274+
ID: "eakID",
1275+
Provisioner: escProvName,
1276+
Reference: "testeak",
1277+
KeyBytes: []byte{1, 3, 3, 7},
1278+
CreatedAt: time.Now(),
12791279
}, nil
12801280
},
12811281
},

acme/db/nosql/account.go

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ func (dba *dbAccount) clone() *dbAccount {
2828
}
2929

3030
type dbExternalAccountKey struct {
31-
ID string `json:"id"`
32-
ProvisionerName string `json:"provisioner_name"`
33-
Name string `json:"name"`
34-
AccountID string `json:"accountID,omitempty"`
35-
KeyBytes []byte `json:"key"`
36-
CreatedAt time.Time `json:"createdAt"`
37-
BoundAt time.Time `json:"boundAt"`
31+
ID string `json:"id"`
32+
Provisioner string `json:"provisioner"`
33+
Reference string `json:"reference"`
34+
AccountID string `json:"accountID,omitempty"`
35+
KeyBytes []byte `json:"key"`
36+
CreatedAt time.Time `json:"createdAt"`
37+
BoundAt time.Time `json:"boundAt"`
3838
}
3939

4040
func (db *DB) getAccountIDByKeyID(ctx context.Context, kid string) (string, error) {
@@ -165,7 +165,7 @@ func (db *DB) UpdateAccount(ctx context.Context, acc *acme.Account) error {
165165
}
166166

167167
// CreateExternalAccountKey creates a new External Account Binding key with a name
168-
func (db *DB) CreateExternalAccountKey(ctx context.Context, provisionerName string, name string) (*acme.ExternalAccountKey, error) {
168+
func (db *DB) CreateExternalAccountKey(ctx context.Context, provisionerName string, reference string) (*acme.ExternalAccountKey, error) {
169169
keyID, err := randID()
170170
if err != nil {
171171
return nil, err
@@ -178,24 +178,24 @@ func (db *DB) CreateExternalAccountKey(ctx context.Context, provisionerName stri
178178
}
179179

180180
dbeak := &dbExternalAccountKey{
181-
ID: keyID,
182-
ProvisionerName: provisionerName,
183-
Name: name,
184-
KeyBytes: random,
185-
CreatedAt: clock.Now(),
181+
ID: keyID,
182+
Provisioner: provisionerName,
183+
Reference: reference,
184+
KeyBytes: random,
185+
CreatedAt: clock.Now(),
186186
}
187187

188188
if err = db.save(ctx, keyID, dbeak, nil, "external_account_key", externalAccountKeyTable); err != nil {
189189
return nil, err
190190
}
191191
return &acme.ExternalAccountKey{
192-
ID: dbeak.ID,
193-
ProvisionerName: dbeak.ProvisionerName,
194-
Name: dbeak.Name,
195-
AccountID: dbeak.AccountID,
196-
KeyBytes: dbeak.KeyBytes,
197-
CreatedAt: dbeak.CreatedAt,
198-
BoundAt: dbeak.BoundAt,
192+
ID: dbeak.ID,
193+
Provisioner: dbeak.Provisioner,
194+
Reference: dbeak.Reference,
195+
AccountID: dbeak.AccountID,
196+
KeyBytes: dbeak.KeyBytes,
197+
CreatedAt: dbeak.CreatedAt,
198+
BoundAt: dbeak.BoundAt,
199199
}, nil
200200
}
201201

@@ -206,18 +206,18 @@ func (db *DB) GetExternalAccountKey(ctx context.Context, provisionerName string,
206206
return nil, err
207207
}
208208

209-
if dbeak.ProvisionerName != provisionerName {
209+
if dbeak.Provisioner != provisionerName {
210210
return nil, acme.NewError(acme.ErrorUnauthorizedType, "name of provisioner does not match provisioner for which the EAB key was created")
211211
}
212212

213213
return &acme.ExternalAccountKey{
214-
ID: dbeak.ID,
215-
ProvisionerName: dbeak.ProvisionerName,
216-
Name: dbeak.Name,
217-
AccountID: dbeak.AccountID,
218-
KeyBytes: dbeak.KeyBytes,
219-
CreatedAt: dbeak.CreatedAt,
220-
BoundAt: dbeak.BoundAt,
214+
ID: dbeak.ID,
215+
Provisioner: dbeak.Provisioner,
216+
Reference: dbeak.Reference,
217+
AccountID: dbeak.AccountID,
218+
KeyBytes: dbeak.KeyBytes,
219+
CreatedAt: dbeak.CreatedAt,
220+
BoundAt: dbeak.BoundAt,
221221
}, nil
222222
}
223223

@@ -240,21 +240,24 @@ func (db *DB) GetExternalAccountKeys(ctx context.Context, provisionerName string
240240
return nil, err
241241
}
242242

243-
keys := make([]*acme.ExternalAccountKey, len(entries))
244-
for i, entry := range entries {
243+
keys := []*acme.ExternalAccountKey{}
244+
for _, entry := range entries {
245245
dbeak := new(dbExternalAccountKey)
246246
if err = json.Unmarshal(entry.Value, dbeak); err != nil {
247247
return nil, errors.Wrapf(err, "error unmarshaling external account key %s into dbExternalAccountKey", string(entry.Key))
248248
}
249-
keys[i] = &acme.ExternalAccountKey{
250-
ID: dbeak.ID,
251-
KeyBytes: dbeak.KeyBytes,
252-
ProvisionerName: dbeak.ProvisionerName,
253-
Name: dbeak.Name,
254-
AccountID: dbeak.AccountID,
255-
CreatedAt: dbeak.CreatedAt,
256-
BoundAt: dbeak.BoundAt,
249+
if dbeak.Provisioner != provisionerName {
250+
continue
257251
}
252+
keys = append(keys, &acme.ExternalAccountKey{
253+
ID: dbeak.ID,
254+
KeyBytes: dbeak.KeyBytes,
255+
Provisioner: dbeak.Provisioner,
256+
Reference: dbeak.Reference,
257+
AccountID: dbeak.AccountID,
258+
CreatedAt: dbeak.CreatedAt,
259+
BoundAt: dbeak.BoundAt,
260+
})
258261
}
259262

260263
return keys, nil
@@ -266,18 +269,18 @@ func (db *DB) UpdateExternalAccountKey(ctx context.Context, provisionerName stri
266269
return err
267270
}
268271

269-
if old.ProvisionerName != provisionerName {
272+
if old.Provisioner != provisionerName {
270273
return acme.NewError(acme.ErrorUnauthorizedType, "name of provisioner does not match provisioner for which the EAB key was created")
271274
}
272275

273276
nu := dbExternalAccountKey{
274-
ID: eak.ID,
275-
ProvisionerName: eak.ProvisionerName,
276-
Name: eak.Name,
277-
AccountID: eak.AccountID,
278-
KeyBytes: eak.KeyBytes,
279-
CreatedAt: eak.CreatedAt,
280-
BoundAt: eak.BoundAt,
277+
ID: eak.ID,
278+
Provisioner: eak.Provisioner,
279+
Reference: eak.Reference,
280+
AccountID: eak.AccountID,
281+
KeyBytes: eak.KeyBytes,
282+
CreatedAt: eak.CreatedAt,
283+
BoundAt: eak.BoundAt,
281284
}
282285

283286
return db.save(ctx, nu.ID, nu, old, "external_account_key", externalAccountKeyTable)

0 commit comments

Comments
 (0)