Skip to content

Commit

Permalink
Remove deprecated sa.CountPendingOrders cruft. (letsencrypt#3527)
Browse files Browse the repository at this point in the history
letsencrypt#3501 made this code deprecated. We've deployed 3501 to the staging environment and can now pull out the old cruft.

Resolves letsencrypt#3502
  • Loading branch information
cpu authored and Roland Bracewell Shoemaker committed Mar 6, 2018
1 parent 66695c0 commit 2612bf7
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 317 deletions.
1 change: 0 additions & 1 deletion core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ type StorageGetter interface {
CountRegistrationsByIP(ctx context.Context, ip net.IP, earliest, latest time.Time) (int, error)
CountRegistrationsByIPRange(ctx context.Context, ip net.IP, earliest, latest time.Time) (int, error)
CountPendingAuthorizations(ctx context.Context, regID int64) (int, error)
CountPendingOrders(ctx context.Context, regID int64) (int, error)
CountOrders(ctx context.Context, acctID int64, earliest, latest time.Time) (int, error)
GetSCTReceipt(ctx context.Context, serial, logID string) (SignedCertificateTimestamp, error)
CountFQDNSets(ctx context.Context, window time.Duration, domains []string) (count int64, err error)
Expand Down
27 changes: 0 additions & 27 deletions grpc/sa-wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,6 @@ func (sac StorageAuthorityClientWrapper) CountPendingAuthorizations(ctx context.
return int(*response.Count), nil
}

func (sac StorageAuthorityClientWrapper) CountPendingOrders(ctx context.Context, regID int64) (int, error) {
response, err := sac.inner.CountPendingOrders(ctx, &sapb.RegistrationID{Id: &regID})
if err != nil {
return 0, err
}

if response == nil || response.Count == nil {
return 0, errIncompleteResponse
}

return int(*response.Count), nil
}

func (sac StorageAuthorityClientWrapper) CountOrders(ctx context.Context, acctID int64, earliest, latest time.Time) (int, error) {
earliestNano := earliest.UnixNano()
latestNano := latest.UnixNano()
Expand Down Expand Up @@ -841,20 +828,6 @@ func (sas StorageAuthorityServerWrapper) CountPendingAuthorizations(ctx context.
return &sapb.Count{Count: &castedCount}, nil
}

func (sas StorageAuthorityServerWrapper) CountPendingOrders(ctx context.Context, request *sapb.RegistrationID) (*sapb.Count, error) {
if request == nil || request.Id == nil {
return nil, errIncompleteRequest
}

count, err := sas.inner.CountPendingOrders(ctx, *request.Id)
if err != nil {
return nil, err
}

castedCount := int64(count)
return &sapb.Count{Count: &castedCount}, nil
}

func (sas StorageAuthorityServerWrapper) CountOrders(ctx context.Context, request *sapb.CountOrdersRequest) (*sapb.Count, error) {
if request == nil || request.AccountID == nil || request.Range == nil || request.Range.Earliest == nil || request.Range.Latest == nil {
return nil, errIncompleteRequest
Expand Down
5 changes: 0 additions & 5 deletions mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,6 @@ func (sa *StorageAuthority) CountPendingAuthorizations(_ context.Context, _ int6
return 0, nil
}

// CountPendingOrders is a mock
func (sa *StorageAuthority) CountPendingOrders(_ context.Context, _ int64) (int, error) {
return 0, nil
}

// CountOrders is a mock
func (sa *StorageAuthority) CountOrders(_ context.Context, _ int64, _, _ time.Time) (int, error) {
return 0, nil
Expand Down
6 changes: 0 additions & 6 deletions ra/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ func (sa *mockInvalidAuthorizationsAuthority) CountPendingAuthorizations(ctx con
}, nil
}

func (sa *mockInvalidAuthorizationsAuthority) CountPendingOrders(ctx context.Context, in *sapb.RegistrationID, opts ...grpc.CallOption) (*sapb.Count, error) {
return &sapb.Count{
Count: new(int64),
}, nil
}

func (sa *mockInvalidAuthorizationsAuthority) CountOrders(ctx context.Context, in *sapb.CountOrdersRequest, opts ...grpc.CallOption) (*sapb.Count, error) {
return &sapb.Count{
Count: new(int64),
Expand Down
256 changes: 111 additions & 145 deletions sa/proto/sa.pb.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion sa/proto/sa.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ service StorageAuthority {
rpc CountRegistrationsByIP(CountRegistrationsByIPRequest) returns (Count) {}
rpc CountRegistrationsByIPRange(CountRegistrationsByIPRequest) returns (Count) {}
rpc CountPendingAuthorizations(RegistrationID) returns (Count) {}
rpc CountPendingOrders(RegistrationID) returns (Count) {}
rpc CountOrders(CountOrdersRequest) returns (Count) {}
// Return a count of authorizations with status "invalid" that belong to
// a given registration ID and expire in the given time range.
Expand Down
39 changes: 0 additions & 39 deletions sa/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,45 +985,6 @@ func (ssa *SQLStorageAuthority) CountPendingAuthorizations(ctx context.Context,
return
}

// CountPendingOrders returns the number of pending, unexpired
// orders for the given registration.
// **DEPRECATED**
func (ssa *SQLStorageAuthority) CountPendingOrders(ctx context.Context, regID int64) (int, error) {
var count int

// Find all of the unexpired order IDs for the given account
var orderIDs []int64
_, err := ssa.dbMap.Select(&orderIDs,
`SELECT ID FROM orders
WHERE registrationID = :regID AND
expires > :now`,
map[string]interface{}{
"regID": regID,
"now": ssa.clk.Now(),
})
if err != nil {
return 0, err
}

// Iterate the order IDs, fetching the full order & associated authorizations
// for each
// TODO(@cpu): This is not performant and we should optimize:
// https://github.com/letsencrypt/boulder/issues/3410
for _, orderID := range orderIDs {
order, err := ssa.GetOrder(ctx, &sapb.OrderRequest{Id: &orderID})
if err != nil {
return 0, err
}

// If the order is pending, increment the pending count
if *order.Status == string(core.StatusPending) {
count++
}
}

return count, nil
}

func (ssa *SQLStorageAuthority) CountOrders(ctx context.Context, acctID int64, earliest, latest time.Time) (int, error) {
var count int
err := ssa.dbMap.SelectOne(&count,
Expand Down
93 changes: 0 additions & 93 deletions sa/sa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1766,99 +1766,6 @@ func TestCountOrders(t *testing.T) {
test.AssertEquals(t, count, 0)
}

func TestCountPendingOrders(t *testing.T) {
if os.Getenv("BOULDER_CONFIG_DIR") != "test/config-next" {
return
}

sa, fc, cleanUp := initSA(t)
defer cleanUp()

reg := satest.CreateWorkingRegistration(t, sa)
authzExpires := fc.Now().Add(time.Hour)
expires := authzExpires.UnixNano()

// Counting pending orders for a reg ID that doesn't exist should return 0
count, err := sa.CountPendingOrders(ctx, 12345)
test.AssertNotError(t, err, "Couldn't count pending orders for fake reg ID")
test.AssertEquals(t, count, 0)

// Add one pending authz
newAuthz := core.Authorization{
Identifier: core.AcmeIdentifier{Type: core.IdentifierDNS, Value: "example.com"},
RegistrationID: reg.ID,
Status: core.StatusPending,
Expires: &authzExpires,
}
pendingAuthz, err := sa.NewPendingAuthorization(ctx, newAuthz)
test.AssertNotError(t, err, "Couldn't create new pending authorization")

// Add one pending order
_, err = sa.NewOrder(ctx, &corepb.Order{
RegistrationID: &reg.ID,
Expires: &expires,
Names: []string{"example.com"},
Authorizations: []string{pendingAuthz.ID},
})
test.AssertNotError(t, err, "Couldn't create new pending order")

// We expect there to be a count of one for this reg ID
count, err = sa.CountPendingOrders(ctx, reg.ID)
test.AssertNotError(t, err, "Couldn't count pending orders")
test.AssertEquals(t, count, 1)

// Create another fresh pending authz
secondPendingAuthz, err := sa.NewPendingAuthorization(ctx, newAuthz)
test.AssertNotError(t, err, "Couldn't create 2nd new pending authorization")

// Create a pending order that expired an hour ago
expires = fc.Now().Add(-time.Hour).UnixNano()
_, err = sa.NewOrder(ctx, &corepb.Order{
RegistrationID: &reg.ID,
Expires: &expires,
Names: []string{"example.com"},
Authorizations: []string{secondPendingAuthz.ID},
})
test.AssertNotError(t, err, "Couldn't create new expired pending order")

// We still expect there to be a count of one for this reg ID since the order
// added above is expired
count, err = sa.CountPendingOrders(ctx, reg.ID)
test.AssertNotError(t, err, "Couldn't count pending orders")
test.AssertEquals(t, count, 1)

// Create another fresh pending authz
thirdPendingAuthz, err := sa.NewPendingAuthorization(ctx, newAuthz)
test.AssertNotError(t, err, "Couldn't create third new pending authorization")
// And then deactivate it
err = sa.DeactivateAuthorization(ctx, thirdPendingAuthz.ID)
test.AssertNotError(t, err, "Couldn't deactivate third new pending authorization")

// Create a deactivated order by referencing the deactivated authz
expires = fc.Now().Add(time.Hour).UnixNano()
_, err = sa.NewOrder(ctx, &corepb.Order{
RegistrationID: &reg.ID,
Expires: &expires,
Names: []string{"example.com"},
Authorizations: []string{thirdPendingAuthz.ID},
})
test.AssertNotError(t, err, "Couldn't create new non-pending order")

// We still expect there to be a count of one for this reg ID since the order
// added above is not pending
count, err = sa.CountPendingOrders(ctx, reg.ID)
test.AssertNotError(t, err, "Couldn't count pending orders")
test.AssertEquals(t, count, 1)

// If the clock is advanced by two hours we expect the count to return to
// 0 for this reg ID since all of the pending orders we created will have
// expired.
fc.Add(2 * time.Hour)
count, err = sa.CountPendingOrders(ctx, reg.ID)
test.AssertNotError(t, err, "Couldn't count pending orders")
test.AssertEquals(t, count, 0)
}

func TestGetOrderForNames(t *testing.T) {
if os.Getenv("BOULDER_CONFIG_DIR") != "test/config-next" {
return
Expand Down

0 comments on commit 2612bf7

Please sign in to comment.