Skip to content

Commit

Permalink
feat(dataset): rename DeleteSinkFromAllDatasets to DeleteSinkFromAllD…
Browse files Browse the repository at this point in the history
…atasetsInternal method and InactivateDatasetById to InactivateDatasetByIdInternal method
  • Loading branch information
mclcavalcante committed Mar 7, 2022
1 parent d02f841 commit de95e8d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions policies/api/http/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type loggingMiddleware struct {
svc policies.Service
}

func (l loggingMiddleware) InactivateDatasetByID(ctx context.Context, datasetID string, ownerID string) (err error) {
func (l loggingMiddleware) InactivateDatasetByIDInternal(ctx context.Context, datasetID string, ownerID string) (err error) {
defer func(begin time.Time) {
if err != nil {
l.logger.Warn("method call: inactivate_dataset_by_id",
Expand All @@ -29,7 +29,7 @@ func (l loggingMiddleware) InactivateDatasetByID(ctx context.Context, datasetID
zap.Duration("duration", time.Since(begin)))
}
}(time.Now())
return l.svc.InactivateDatasetByID(ctx, datasetID, ownerID)
return l.svc.InactivateDatasetByIDInternal(ctx, datasetID, ownerID)
}

func (l loggingMiddleware) ViewDatasetByIDInternal(ctx context.Context, ownerID string, datasetID string) (_ policies.Dataset, err error) {
Expand Down Expand Up @@ -270,7 +270,7 @@ func (l loggingMiddleware) ListDatasets(ctx context.Context, token string, pm po
return l.svc.ListDatasets(ctx, token, pm)
}

func (l loggingMiddleware) DeleteSinkFromAllDatasets(ctx context.Context, sinkID string, ownerID string) (ds []policies.Dataset, err error) {
func (l loggingMiddleware) DeleteSinkFromAllDatasetsInternal(ctx context.Context, sinkID string, ownerID string) (ds []policies.Dataset, err error) {
defer func(begin time.Time) {
if err != nil {
l.logger.Warn("method call: delete_sink_from_all_datasets",
Expand All @@ -281,7 +281,7 @@ func (l loggingMiddleware) DeleteSinkFromAllDatasets(ctx context.Context, sinkID
zap.Duration("duration", time.Since(begin)))
}
}(time.Now())
return l.svc.DeleteSinkFromAllDatasets(ctx, sinkID, ownerID)
return l.svc.DeleteSinkFromAllDatasetsInternal(ctx, sinkID, ownerID)
}

func NewLoggingMiddleware(svc policies.Service, logger *zap.Logger) policies.Service {
Expand Down
8 changes: 4 additions & 4 deletions policies/api/http/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type metricsMiddleware struct {
svc policies.Service
}

func (m metricsMiddleware) InactivateDatasetByID(ctx context.Context, datasetID string, ownerID string) error {
func (m metricsMiddleware) InactivateDatasetByIDInternal(ctx context.Context, datasetID string, ownerID string) error {
defer func(begin time.Time) {
labels := []string{
"method", "inactivateDatasetByID",
Expand All @@ -36,7 +36,7 @@ func (m metricsMiddleware) InactivateDatasetByID(ctx context.Context, datasetID

}(time.Now())

return m.svc.InactivateDatasetByID(ctx, datasetID, ownerID)
return m.svc.InactivateDatasetByIDInternal(ctx, datasetID, ownerID)
}

func (m metricsMiddleware) ViewDatasetByIDInternal(ctx context.Context, ownerID string, datasetID string) (policies.Dataset, error) {
Expand Down Expand Up @@ -393,7 +393,7 @@ func (m metricsMiddleware) ListDatasets(ctx context.Context, token string, pm po
return m.svc.ListDatasets(ctx, token, pm)
}

func (m metricsMiddleware) DeleteSinkFromAllDatasets(ctx context.Context, sinkID string, ownerID string) ([]policies.Dataset, error) {
func (m metricsMiddleware) DeleteSinkFromAllDatasetsInternal(ctx context.Context, sinkID string, ownerID string) ([]policies.Dataset, error) {
defer func(begin time.Time) {
labels := []string{
"method", "deleteSinkFromAllDatasets",
Expand All @@ -407,7 +407,7 @@ func (m metricsMiddleware) DeleteSinkFromAllDatasets(ctx context.Context, sinkID

}(time.Now())

return m.svc.DeleteSinkFromAllDatasets(ctx, sinkID, ownerID)
return m.svc.DeleteSinkFromAllDatasetsInternal(ctx, sinkID, ownerID)
}

func (m metricsMiddleware) identify(token string) (string, error) {
Expand Down
8 changes: 4 additions & 4 deletions policies/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ type Service interface {
// ListDatasets retrieve a list of Dataset by owner
ListDatasets(ctx context.Context, token string, pm PageMetadata) (PageDataset, error)

// InactivateDatasetByID inactivate a dataset
InactivateDatasetByID(ctx context.Context, datasetID string, ownerID string) error
// InactivateDatasetByIDInternal inactivate a dataset
InactivateDatasetByIDInternal(ctx context.Context, datasetID string, ownerID string) error

// DeleteSinkFromAllDatasets removes a sink from a dataset
DeleteSinkFromAllDatasets(ctx context.Context, sinkID string, ownerID string) ([]Dataset, error)
// DeleteSinkFromAllDatasetsInternal removes a sink from a dataset
DeleteSinkFromAllDatasetsInternal(ctx context.Context, sinkID string, ownerID string) ([]Dataset, error)
}

type Repository interface {
Expand Down
4 changes: 2 additions & 2 deletions policies/policy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s policiesService) ListDatasets(ctx context.Context, token string, pm Page
return s.repo.RetrieveAllDatasetsByOwner(ctx, ownerID, pm)
}

func (s policiesService) DeleteSinkFromAllDatasets(ctx context.Context, sinkID string, ownerID string) ([]Dataset, error) {
func (s policiesService) DeleteSinkFromAllDatasetsInternal(ctx context.Context, sinkID string, ownerID string) ([]Dataset, error) {
if sinkID == "" || ownerID == ""{
return []Dataset{}, ErrMalformedEntity
}
Expand All @@ -342,7 +342,7 @@ func (s policiesService) DeleteSinkFromAllDatasets(ctx context.Context, sinkID s
return datasets, nil
}

func (s policiesService) InactivateDatasetByID(ctx context.Context, datasetID string, ownerID string) error {
func (s policiesService) InactivateDatasetByIDInternal(ctx context.Context, datasetID string, ownerID string) error {
if datasetID == "" || ownerID == ""{
return ErrMalformedEntity
}
Expand Down
4 changes: 2 additions & 2 deletions policies/policy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ func TestDeleteSinkFromDataset(t *testing.T) {

for desc, tc := range cases {
t.Run(desc, func(t *testing.T) {
_, err := svc.DeleteSinkFromAllDatasets(context.Background(), tc.sinkID, tc.ownerID)
_, err := svc.DeleteSinkFromAllDatasetsInternal(context.Background(), tc.sinkID, tc.ownerID)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s", desc, tc.err, err))
})
}
Expand Down Expand Up @@ -1247,7 +1247,7 @@ func TestInactivateDatasetByID(t *testing.T) {
for desc, tc := range cases {
t.Run(desc, func(t *testing.T) {
for _, id := range tc.datasetIDs {
err := svc.InactivateDatasetByID(context.Background(), id, tc.ownerID)
err := svc.InactivateDatasetByIDInternal(context.Background(), id, tc.ownerID)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s", desc, tc.err, err))
}
})
Expand Down
4 changes: 2 additions & 2 deletions policies/redis/consumer/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ func (es eventStore) handleAgentGroupRemove(ctx context.Context, groupID string,

func (es eventStore) handleSinkRemove(ctx context.Context, sinkID string, ownerID string) error {

datasets, err := es.policiesService.DeleteSinkFromAllDatasets(ctx, sinkID, ownerID)
datasets, err := es.policiesService.DeleteSinkFromAllDatasetsInternal(ctx, sinkID, ownerID)
if err != nil {
return err
}

for _, ds := range datasets {
if len(ds.SinkIDs) == 0 {
err = es.policiesService.InactivateDatasetByID(ctx, ds.ID, ownerID)
err = es.policiesService.InactivateDatasetByIDInternal(ctx, ds.ID, ownerID)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions policies/redis/producer/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ func (e eventStore) ValidatePolicy(ctx context.Context, token string, p policies
return e.svc.ValidatePolicy(ctx, token, p, format, policyData)
}

func (e eventStore) DeleteSinkFromAllDatasets(ctx context.Context, sinkID string, token string) ([]policies.Dataset, error) {
return e.svc.DeleteSinkFromAllDatasets(ctx, sinkID, token)
func (e eventStore) DeleteSinkFromAllDatasetsInternal(ctx context.Context, sinkID string, token string) ([]policies.Dataset, error) {
return e.svc.DeleteSinkFromAllDatasetsInternal(ctx, sinkID, token)
}

func (e eventStore) InactivateDatasetByID(ctx context.Context, datasetID string, ownerID string) error {
func (e eventStore) InactivateDatasetByIDInternal(ctx context.Context, datasetID string, ownerID string) error {
ds, err := e.svc.ViewDatasetByIDInternal(ctx, ownerID, datasetID)
if err != nil {
return err
}

if err := e.svc.InactivateDatasetByID(ctx, datasetID, ownerID); err != nil {
if err := e.svc.InactivateDatasetByIDInternal(ctx, datasetID, ownerID); err != nil {
return err
}

Expand Down

0 comments on commit de95e8d

Please sign in to comment.