@@ -1360,25 +1360,26 @@ func (wfe *WebFrontEndImpl) Account(
1360
1360
idStr := request .URL .Path
1361
1361
id , err := strconv .ParseInt (idStr , 10 , 64 )
1362
1362
if err != nil {
1363
- wfe .sendError (response , logEvent , probs .Malformed ("Account ID must be an integer" ), err )
1363
+ wfe .sendError (response , logEvent , probs .Malformed (fmt . Sprintf ( "Account ID must be an integer, was %q" , idStr ) ), err )
1364
1364
return
1365
1365
} else if id <= 0 {
1366
- msg := fmt .Sprintf ("Account ID must be a positive non-zero integer, was %d" , id )
1367
- wfe .sendError (response , logEvent , probs .Malformed (msg ), nil )
1366
+ wfe .sendError (response , logEvent , probs .Malformed (fmt .Sprintf ("Account ID must be a positive non-zero integer, was %d" , id )), nil )
1368
1367
return
1369
1368
} else if id != currAcct .ID {
1370
- wfe .sendError (response , logEvent ,
1371
- probs .Unauthorized ("Request signing key did not match account key" ), nil )
1369
+ wfe .sendError (response , logEvent , probs .Unauthorized ("Request signing key did not match account key" ), nil )
1372
1370
return
1373
1371
}
1374
1372
1375
- // An empty string means POST-as-GET (i.e. no update). A body of "{}" means
1376
- // an update of zero fields, returning the unchanged object. This was the
1377
- // recommended way to fetch the account object in ACMEv1.
1378
- if string (body ) != "" && string (body ) != "{}" {
1379
- currAcct , prob = wfe .updateAccount (ctx , body , currAcct )
1380
- if prob != nil {
1381
- wfe .sendError (response , logEvent , prob , nil )
1373
+ var acct * core.Registration
1374
+ if string (body ) == "" || string (body ) == "{}" {
1375
+ // An empty string means POST-as-GET (i.e. no update). A body of "{}" means
1376
+ // an update of zero fields, returning the unchanged object. This was the
1377
+ // recommended way to fetch the account object in ACMEv1.
1378
+ acct = currAcct
1379
+ } else {
1380
+ acct , err = wfe .updateAccount (ctx , body , currAcct )
1381
+ if err != nil {
1382
+ wfe .sendError (response , logEvent , web .ProblemDetailsForError (err , "Unable to update account" ), nil )
1382
1383
return
1383
1384
}
1384
1385
}
@@ -1387,13 +1388,11 @@ func (wfe *WebFrontEndImpl) Account(
1387
1388
response .Header ().Add ("Link" , link (wfe .SubscriberAgreementURL , "terms-of-service" ))
1388
1389
}
1389
1390
1390
- prepAccountForDisplay (currAcct )
1391
+ prepAccountForDisplay (acct )
1391
1392
1392
- err = wfe .writeJsonResponse (response , logEvent , http .StatusOK , currAcct )
1393
+ err = wfe .writeJsonResponse (response , logEvent , http .StatusOK , acct )
1393
1394
if err != nil {
1394
- // ServerInternal because we just generated the account, it should be OK
1395
- wfe .sendError (response , logEvent ,
1396
- probs .ServerInternal ("Failed to marshal account" ), err )
1395
+ wfe .sendError (response , logEvent , probs .ServerInternal ("Failed to marshal account" ), err )
1397
1396
return
1398
1397
}
1399
1398
}
@@ -1403,10 +1402,7 @@ func (wfe *WebFrontEndImpl) Account(
1403
1402
// request has already been authenticated by the caller. If the request is a
1404
1403
// valid update the resulting updated account is returned, otherwise a problem
1405
1404
// is returned.
1406
- func (wfe * WebFrontEndImpl ) updateAccount (
1407
- ctx context.Context ,
1408
- requestBody []byte ,
1409
- currAcct * core.Registration ) (* core.Registration , * probs.ProblemDetails ) {
1405
+ func (wfe * WebFrontEndImpl ) updateAccount (ctx context.Context , requestBody []byte , currAcct * core.Registration ) (* core.Registration , error ) {
1410
1406
// Only the Contact and Status fields of an account may be updated this way.
1411
1407
// For key updates clients should be using the key change endpoint.
1412
1408
var accountUpdateRequest struct {
@@ -1416,7 +1412,7 @@ func (wfe *WebFrontEndImpl) updateAccount(
1416
1412
1417
1413
err := json .Unmarshal (requestBody , & accountUpdateRequest )
1418
1414
if err != nil {
1419
- return nil , probs . Malformed ( "Error unmarshaling account" )
1415
+ return nil , berrors . MalformedError ( "parsing account update request: %s" , err )
1420
1416
}
1421
1417
1422
1418
// If a user tries to send both a deactivation request and an update to
@@ -1426,17 +1422,16 @@ func (wfe *WebFrontEndImpl) updateAccount(
1426
1422
updatedAcct , err := wfe .ra .DeactivateRegistration (
1427
1423
ctx , & rapb.DeactivateRegistrationRequest {RegistrationID : currAcct .ID })
1428
1424
if err != nil {
1429
- return nil , web . ProblemDetailsForError ( err , "Unable to deactivate account" )
1425
+ return nil , fmt . Errorf ( "deactivating account: %w" , err )
1430
1426
}
1431
1427
1432
1428
if updatedAcct .Status == string (core .StatusDeactivated ) {
1433
1429
// The request was handled by an updated RA/SA, which returned the updated
1434
1430
// account object.
1435
1431
updatedReg , err := bgrpc .PbToRegistration (updatedAcct )
1436
1432
if err != nil {
1437
- return nil , probs . ServerInternal ( "Error updating account" )
1433
+ return nil , fmt . Errorf ( "parsing deactivated account: %w" , err )
1438
1434
}
1439
-
1440
1435
return & updatedReg , nil
1441
1436
} else {
1442
1437
// The request was handled by an old RA/SA, which returned nothing.
@@ -1449,7 +1444,7 @@ func (wfe *WebFrontEndImpl) updateAccount(
1449
1444
}
1450
1445
1451
1446
if accountUpdateRequest .Status != core .StatusValid && accountUpdateRequest .Status != "" {
1452
- return nil , probs . Malformed ( "Invalid value provided for status field" )
1447
+ return nil , berrors . MalformedError ( "invalid status %q for account update request, must be %q or %q" , accountUpdateRequest . Status , core . StatusValid , core . StatusDeactivated )
1453
1448
}
1454
1449
1455
1450
if accountUpdateRequest .Contact == nil {
@@ -1463,13 +1458,13 @@ func (wfe *WebFrontEndImpl) updateAccount(
1463
1458
updatedAcct , err := wfe .ra .UpdateRegistrationContact (ctx , & rapb.UpdateRegistrationContactRequest {
1464
1459
RegistrationID : currAcct .ID , Contacts : * accountUpdateRequest .Contact })
1465
1460
if err != nil {
1466
- return nil , web . ProblemDetailsForError ( err , "Unable to update account" )
1461
+ return nil , fmt . Errorf ( "updating account: %w" , err )
1467
1462
}
1468
1463
1469
1464
// Convert proto to core.Registration for return
1470
1465
updatedReg , err := bgrpc .PbToRegistration (updatedAcct )
1471
1466
if err != nil {
1472
- return nil , probs . ServerInternal ( "Error updating account" )
1467
+ return nil , fmt . Errorf ( "parsing updated account: %w" , err )
1473
1468
}
1474
1469
1475
1470
return & updatedReg , nil
0 commit comments