diff --git a/api/http/endpoint.go b/api/http/endpoint.go index cf2657a..2f43f13 100644 --- a/api/http/endpoint.go +++ b/api/http/endpoint.go @@ -54,7 +54,7 @@ func deleteCertEndpoint(svc certs.Service) endpoint.Endpoint { return deleteCertRes{deleted: false}, err } - if err = svc.RemoveCerts(ctx, req.entityID); err != nil { + if err = svc.RemoveCert(ctx, req.entityID); err != nil { return deleteCertRes{deleted: false}, err } diff --git a/api/logging.go b/api/logging.go index 18819f8..731784d 100644 --- a/api/logging.go +++ b/api/logging.go @@ -109,16 +109,16 @@ func (lm *loggingMiddleware) ListCerts(ctx context.Context, pm certs.PageMetadat return lm.svc.ListCerts(ctx, pm) } -func (lm *loggingMiddleware) RemoveCerts(ctx context.Context, entityId string) (err error) { +func (lm *loggingMiddleware) RemoveCert(ctx context.Context, entityId string) (err error) { defer func(begin time.Time) { - message := fmt.Sprintf("Method remove_certs took %s to complete", time.Since(begin)) + message := fmt.Sprintf("Method remove_cert took %s to complete", time.Since(begin)) if err != nil { lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err)) return } lm.logger.Info(message) }(time.Now()) - return lm.svc.RemoveCerts(ctx, entityId) + return lm.svc.RemoveCert(ctx, entityId) } func (lm *loggingMiddleware) ViewCert(ctx context.Context, serialNumber string) (cert certs.Certificate, err error) { diff --git a/api/metrics.go b/api/metrics.go index bcaa539..a5506c3 100644 --- a/api/metrics.go +++ b/api/metrics.go @@ -87,12 +87,12 @@ func (mm *metricsMiddleware) ListCerts(ctx context.Context, pm certs.PageMetadat return mm.svc.ListCerts(ctx, pm) } -func (mm *metricsMiddleware) RemoveCerts(ctx context.Context, entityId string) error { +func (mm *metricsMiddleware) RemoveCert(ctx context.Context, entityId string) error { defer func(begin time.Time) { - mm.counter.With("method", "remove_certificates").Add(1) - mm.latency.With("method", "remove_certificates").Observe(time.Since(begin).Seconds()) + mm.counter.With("method", "remove_certificate").Add(1) + mm.latency.With("method", "remove_certificate").Observe(time.Since(begin).Seconds()) }(time.Now()) - return mm.svc.RemoveCerts(ctx, entityId) + return mm.svc.RemoveCert(ctx, entityId) } func (mm *metricsMiddleware) ViewCert(ctx context.Context, serialNumber string) (certs.Certificate, error) { diff --git a/certs.go b/certs.go index 29cabaa..7a88bee 100644 --- a/certs.go +++ b/certs.go @@ -71,8 +71,8 @@ type Service interface { // GetChainCA retrieves the chain of CA i.e. root and intermediate cert concat together. GetChainCA(ctx context.Context, token string) (Certificate, error) - // RemoveCerts deletes a certs for a provided entityID. - RemoveCerts(ctx context.Context, entityId string) error + // RemoveCert deletes a cert for a provided entityID. + RemoveCert(ctx context.Context, entityId string) error } type Repository interface { @@ -94,6 +94,6 @@ type Repository interface { // ListRevokedCerts retrieves revoked lists from database. ListRevokedCerts(ctx context.Context) ([]Certificate, error) - // RemoveCerts deletes certs from database. - RemoveCerts(ctx context.Context, entityId string) error + // RemoveCert deletes cert from database. + RemoveCert(ctx context.Context, entityId string) error } diff --git a/cli/certs.go b/cli/certs.go index b555fb2..7f9b1b9 100644 --- a/cli/certs.go +++ b/cli/certs.go @@ -79,7 +79,7 @@ var cmdCerts = []cobra.Command{ logUsageCmd(*cmd, cmd.Use) return } - err := sdk.DeleteCerts(args[0]) + err := sdk.DeleteCert(args[0]) if err != nil { logErrorCmd(*cmd, err) return diff --git a/mocks/repository.go b/mocks/repository.go index f8901c1..40a6640 100644 --- a/mocks/repository.go +++ b/mocks/repository.go @@ -261,12 +261,12 @@ func (_c *MockRepository_ListRevokedCerts_Call) RunAndReturn(run func(context.Co return _c } -// RemoveCerts provides a mock function with given fields: ctx, entityId -func (_m *MockRepository) RemoveCerts(ctx context.Context, entityId string) error { +// RemoveCert provides a mock function with given fields: ctx, entityId +func (_m *MockRepository) RemoveCert(ctx context.Context, entityId string) error { ret := _m.Called(ctx, entityId) if len(ret) == 0 { - panic("no return value specified for RemoveCerts") + panic("no return value specified for RemoveCert") } var r0 error @@ -279,31 +279,31 @@ func (_m *MockRepository) RemoveCerts(ctx context.Context, entityId string) erro return r0 } -// MockRepository_RemoveCerts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveCerts' -type MockRepository_RemoveCerts_Call struct { +// MockRepository_RemoveCert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveCert' +type MockRepository_RemoveCert_Call struct { *mock.Call } -// RemoveCerts is a helper method to define mock.On call +// RemoveCert is a helper method to define mock.On call // - ctx context.Context // - entityId string -func (_e *MockRepository_Expecter) RemoveCerts(ctx interface{}, entityId interface{}) *MockRepository_RemoveCerts_Call { - return &MockRepository_RemoveCerts_Call{Call: _e.mock.On("RemoveCerts", ctx, entityId)} +func (_e *MockRepository_Expecter) RemoveCert(ctx interface{}, entityId interface{}) *MockRepository_RemoveCert_Call { + return &MockRepository_RemoveCert_Call{Call: _e.mock.On("RemoveCert", ctx, entityId)} } -func (_c *MockRepository_RemoveCerts_Call) Run(run func(ctx context.Context, entityId string)) *MockRepository_RemoveCerts_Call { +func (_c *MockRepository_RemoveCert_Call) Run(run func(ctx context.Context, entityId string)) *MockRepository_RemoveCert_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(string)) }) return _c } -func (_c *MockRepository_RemoveCerts_Call) Return(_a0 error) *MockRepository_RemoveCerts_Call { +func (_c *MockRepository_RemoveCert_Call) Return(_a0 error) *MockRepository_RemoveCert_Call { _c.Call.Return(_a0) return _c } -func (_c *MockRepository_RemoveCerts_Call) RunAndReturn(run func(context.Context, string) error) *MockRepository_RemoveCerts_Call { +func (_c *MockRepository_RemoveCert_Call) RunAndReturn(run func(context.Context, string) error) *MockRepository_RemoveCert_Call { _c.Call.Return(run) return _c } diff --git a/mocks/service.go b/mocks/service.go index bd4ee02..aa91db8 100644 --- a/mocks/service.go +++ b/mocks/service.go @@ -393,12 +393,12 @@ func (_c *MockService_OCSP_Call) RunAndReturn(run func(context.Context, string) return _c } -// RemoveCerts provides a mock function with given fields: ctx, entityId -func (_m *MockService) RemoveCerts(ctx context.Context, entityId string) error { +// RemoveCert provides a mock function with given fields: ctx, entityId +func (_m *MockService) RemoveCert(ctx context.Context, entityId string) error { ret := _m.Called(ctx, entityId) if len(ret) == 0 { - panic("no return value specified for RemoveCerts") + panic("no return value specified for RemoveCert") } var r0 error @@ -411,31 +411,31 @@ func (_m *MockService) RemoveCerts(ctx context.Context, entityId string) error { return r0 } -// MockService_RemoveCerts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveCerts' -type MockService_RemoveCerts_Call struct { +// MockService_RemoveCert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveCert' +type MockService_RemoveCert_Call struct { *mock.Call } -// RemoveCerts is a helper method to define mock.On call +// RemoveCert is a helper method to define mock.On call // - ctx context.Context // - entityId string -func (_e *MockService_Expecter) RemoveCerts(ctx interface{}, entityId interface{}) *MockService_RemoveCerts_Call { - return &MockService_RemoveCerts_Call{Call: _e.mock.On("RemoveCerts", ctx, entityId)} +func (_e *MockService_Expecter) RemoveCert(ctx interface{}, entityId interface{}) *MockService_RemoveCert_Call { + return &MockService_RemoveCert_Call{Call: _e.mock.On("RemoveCert", ctx, entityId)} } -func (_c *MockService_RemoveCerts_Call) Run(run func(ctx context.Context, entityId string)) *MockService_RemoveCerts_Call { +func (_c *MockService_RemoveCert_Call) Run(run func(ctx context.Context, entityId string)) *MockService_RemoveCert_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(string)) }) return _c } -func (_c *MockService_RemoveCerts_Call) Return(_a0 error) *MockService_RemoveCerts_Call { +func (_c *MockService_RemoveCert_Call) Return(_a0 error) *MockService_RemoveCert_Call { _c.Call.Return(_a0) return _c } -func (_c *MockService_RemoveCerts_Call) RunAndReturn(run func(context.Context, string) error) *MockService_RemoveCerts_Call { +func (_c *MockService_RemoveCert_Call) RunAndReturn(run func(context.Context, string) error) *MockService_RemoveCert_Call { _c.Call.Return(run) return _c } diff --git a/postgres/certs.go b/postgres/certs.go index c7e358d..9e2161f 100644 --- a/postgres/certs.go +++ b/postgres/certs.go @@ -199,7 +199,7 @@ func (repo certsRepo) ListRevokedCerts(ctx context.Context) ([]certs.Certificate return revokedCerts, nil } -func (repo certsRepo) RemoveCerts(ctx context.Context, backendId string) error { +func (repo certsRepo) RemoveCert(ctx context.Context, backendId string) error { q := `DELETE FROM certs WHERE entity_id = $1` result, err := repo.db.ExecContext(ctx, q, backendId) diff --git a/sdk/certs_test.go b/sdk/certs_test.go index 3dace83..b905a1a 100644 --- a/sdk/certs_test.go +++ b/sdk/certs_test.go @@ -244,12 +244,12 @@ func TestDeleteCert(t *testing.T) { for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { - svcCall := svc.On("RemoveCerts", mock.Anything, tc.entityID).Return(tc.svcerr) + svcCall := svc.On("RemoveCert", mock.Anything, tc.entityID).Return(tc.svcerr) - err := ctsdk.DeleteCerts(tc.entityID) + err := ctsdk.DeleteCert(tc.entityID) assert.Equal(t, tc.err, err) if tc.desc != "DeleteCert with empty entity id" { - ok := svcCall.Parent.AssertCalled(t, "RemoveCerts", mock.Anything, tc.entityID) + ok := svcCall.Parent.AssertCalled(t, "RemoveCert", mock.Anything, tc.entityID) assert.True(t, ok) } svcCall.Unset() diff --git a/sdk/mocks/sdk.go b/sdk/mocks/sdk.go index 545e44c..fd994e6 100644 --- a/sdk/mocks/sdk.go +++ b/sdk/mocks/sdk.go @@ -27,12 +27,12 @@ func (_m *MockSDK) EXPECT() *MockSDK_Expecter { return &MockSDK_Expecter{mock: &_m.Mock} } -// DeleteCerts provides a mock function with given fields: entityID -func (_m *MockSDK) DeleteCerts(entityID string) errors.SDKError { +// DeleteCert provides a mock function with given fields: entityID +func (_m *MockSDK) DeleteCert(entityID string) errors.SDKError { ret := _m.Called(entityID) if len(ret) == 0 { - panic("no return value specified for DeleteCerts") + panic("no return value specified for DeleteCert") } var r0 errors.SDKError @@ -47,30 +47,30 @@ func (_m *MockSDK) DeleteCerts(entityID string) errors.SDKError { return r0 } -// MockSDK_DeleteCerts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteCerts' -type MockSDK_DeleteCerts_Call struct { +// MockSDK_DeleteCert_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteCert' +type MockSDK_DeleteCert_Call struct { *mock.Call } -// DeleteCerts is a helper method to define mock.On call +// DeleteCert is a helper method to define mock.On call // - entityID string -func (_e *MockSDK_Expecter) DeleteCerts(entityID interface{}) *MockSDK_DeleteCerts_Call { - return &MockSDK_DeleteCerts_Call{Call: _e.mock.On("DeleteCerts", entityID)} +func (_e *MockSDK_Expecter) DeleteCert(entityID interface{}) *MockSDK_DeleteCert_Call { + return &MockSDK_DeleteCert_Call{Call: _e.mock.On("DeleteCert", entityID)} } -func (_c *MockSDK_DeleteCerts_Call) Run(run func(entityID string)) *MockSDK_DeleteCerts_Call { +func (_c *MockSDK_DeleteCert_Call) Run(run func(entityID string)) *MockSDK_DeleteCert_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(string)) }) return _c } -func (_c *MockSDK_DeleteCerts_Call) Return(_a0 errors.SDKError) *MockSDK_DeleteCerts_Call { +func (_c *MockSDK_DeleteCert_Call) Return(_a0 errors.SDKError) *MockSDK_DeleteCert_Call { _c.Call.Return(_a0) return _c } -func (_c *MockSDK_DeleteCerts_Call) RunAndReturn(run func(string) errors.SDKError) *MockSDK_DeleteCerts_Call { +func (_c *MockSDK_DeleteCert_Call) RunAndReturn(run func(string) errors.SDKError) *MockSDK_DeleteCert_Call { _c.Call.Return(run) return _c } diff --git a/sdk/sdk.go b/sdk/sdk.go index ab7cffc..9614ab7 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -141,12 +141,12 @@ type SDK interface { // fmt.Println(page) ListCerts(pm PageMetadata) (CertificatePage, errors.SDKError) - // DeleteCerts deletes certificates for a given entityID. + // DeleteCert deletes certificates for a given entityID. // // example: - // err := sdk.DeleteCerts("entityID") + // err := sdk.DeleteCert("entityID") // fmt.Println(err) - DeleteCerts(entityID string) errors.SDKError + DeleteCert(entityID string) errors.SDKError // ViewCert retrieves a certificate record from the database. // @@ -298,7 +298,7 @@ func (sdk mgSDK) ListCerts(pm PageMetadata) (CertificatePage, errors.SDKError) { return cp, nil } -func (sdk mgSDK) DeleteCerts(entityID string) errors.SDKError { +func (sdk mgSDK) DeleteCert(entityID string) errors.SDKError { url := fmt.Sprintf("%s/%s/%s/delete", sdk.certsURL, certsEndpoint, entityID) _, _, sdkerr := sdk.processRequest(http.MethodDelete, url, nil, nil, http.StatusNoContent) return sdkerr diff --git a/service.go b/service.go index cd591f6..c1dc667 100644 --- a/service.go +++ b/service.go @@ -271,8 +271,8 @@ func (s *service) ListCerts(ctx context.Context, pm PageMetadata) (CertificatePa return certPg, nil } -func (s *service) RemoveCerts(ctx context.Context, entityId string) error { - return s.repo.RemoveCerts(ctx, entityId) +func (s *service) RemoveCert(ctx context.Context, entityId string) error { + return s.repo.RemoveCert(ctx, entityId) } func (s *service) ViewCert(ctx context.Context, serialNumber string) (Certificate, error) { diff --git a/tracing/certs.go b/tracing/certs.go index 90cd3dd..efac814 100644 --- a/tracing/certs.go +++ b/tracing/certs.go @@ -65,10 +65,10 @@ func (tm *tracingMiddleware) ListCerts(ctx context.Context, pm certs.PageMetadat return tm.svc.ListCerts(ctx, pm) } -func (tm *tracingMiddleware) RemoveCerts(ctx context.Context, entityId string) (err error) { - ctx, span := tm.tracer.Start(ctx, "remove_certs") +func (tm *tracingMiddleware) RemoveCert(ctx context.Context, entityId string) (err error) { + ctx, span := tm.tracer.Start(ctx, "remove_cert") defer span.End() - return tm.svc.RemoveCerts(ctx, entityId) + return tm.svc.RemoveCert(ctx, entityId) } func (s *tracingMiddleware) ViewCert(ctx context.Context, serialNumber string) (certs.Certificate, error) {