Skip to content

Commit

Permalink
feat: update provider plugin contract (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh authored Oct 21, 2023
1 parent 33dd04f commit 2d31719
Show file tree
Hide file tree
Showing 66 changed files with 1,533 additions and 294 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ NAME="github.com/goto/siren"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
APP_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "4fc96a5406f640044ebe0572385336af7bd221ae"
PROTON_COMMIT := "534a703026bd70fa464c3bedc6a9aef3f8fcdd19"

.PHONY: all build test clean dist vet proto install

Expand Down
2 changes: 1 addition & 1 deletion core/alert/mocks/alert_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/alert/mocks/alert_transformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/alert/mocks/log_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/log/mocks/notification_log_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/namespace/mocks/config_syncer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/namespace/mocks/encryptor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/namespace/mocks/namespace_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/namespace/mocks/provider_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/namespace/mocks/transactor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions core/namespace/v1beta1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package namespace

import (
"fmt"

"github.com/goto/siren/core/provider"
sirenv1beta1 "github.com/goto/siren/proto/gotocompany/siren/v1beta1"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

func (n *Namespace) ToV1beta1Proto() (*sirenv1beta1.Namespace, error) {
creds, err := structpb.NewStruct(n.Credentials)
if err != nil {
return nil, fmt.Errorf("cannot transform credentials to proto: %w", err)
}
return &sirenv1beta1.Namespace{
Id: n.ID,
Urn: n.URN,
Name: n.Name,
Provider: n.Provider.ID,
Credentials: creds,
Labels: n.Labels,
CreatedAt: timestamppb.New(n.CreatedAt),
UpdatedAt: timestamppb.New(n.UpdatedAt),
}, nil
}

func FromV1beta1Proto(proto *sirenv1beta1.Namespace) Namespace {
return Namespace{
ID: proto.GetId(),
URN: proto.GetUrn(),
Name: proto.GetName(),
Provider: provider.Provider{
ID: proto.GetProvider(),
},
Credentials: proto.GetCredentials().AsMap(),
Labels: proto.GetLabels(),
CreatedAt: proto.GetCreatedAt().AsTime(),
UpdatedAt: proto.GetUpdatedAt().AsTime(),
}
}
2 changes: 1 addition & 1 deletion core/notification/mocks/alert_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/dispatcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/idempotency_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/log_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/notifier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/queuer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/receiver_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/silence_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/notification/mocks/subscription_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/provider/mocks/provider_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions core/provider/v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ func (p *Provider) ToV1beta1Proto() (*sirenv1beta1.Provider, error) {
}, nil
}

func FromV1beta1Proto(proto *sirenv1beta1.Provider) *Provider {
return &Provider{
func FromV1beta1Proto(proto *sirenv1beta1.Provider) Provider {
return Provider{
ID: proto.GetId(),
Host: proto.GetHost(),
URN: proto.GetUrn(),
Name: proto.GetName(),
Type: proto.GetType(),
Credentials: proto.GetCredentials().AsMap(),
Labels: proto.GetLabels(),
CreatedAt: proto.CreatedAt.AsTime(),
UpdatedAt: proto.UpdatedAt.AsTime(),
CreatedAt: proto.GetCreatedAt().AsTime(),
UpdatedAt: proto.GetUpdatedAt().AsTime(),
}
}
2 changes: 1 addition & 1 deletion core/receiver/mocks/config_resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/receiver/mocks/encryptor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/receiver/mocks/receiver_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/rule/mocks/namespace_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/rule/mocks/rule_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions core/rule/mocks/rule_uploader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/rule/mocks/template_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/rule/provider_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rule
import (
"context"

"github.com/goto/siren/core/namespace"
"github.com/goto/siren/core/provider"
"github.com/goto/siren/core/template"
)
Expand All @@ -13,5 +14,5 @@ import (
//
//go:generate mockery --name=RuleUploader -r --case underscore --with-expecter --structname RuleUploader --filename rule_uploader.go --output=./mocks
type RuleUploader interface {
UpsertRule(ctx context.Context, namespaceURN string, prov provider.Provider, rl *Rule, templateToUpdate *template.Template) error
UpsertRule(ctx context.Context, ns namespace.Namespace, prov provider.Provider, rl *Rule, templateToUpdate *template.Template) error
}
2 changes: 1 addition & 1 deletion core/rule/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *Service) Upsert(ctx context.Context, rl *Rule) error {
return err
}

if err := pluginService.UpsertRule(ctx, ns.URN, ns.Provider, rl, templateToUpdate); err != nil {
if err := pluginService.UpsertRule(ctx, *ns, ns.Provider, rl, templateToUpdate); err != nil {
if err := s.repository.Rollback(ctx, err); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions core/rule/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestService_Upsert(t *testing.T) {

rr.EXPECT().WithTransaction(ctx).Return(ctx)
rr.EXPECT().Upsert(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("*rule.Rule")).Return(nil)
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(nil)
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("namespace.Namespace"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(nil)
rr.EXPECT().Commit(ctx).Return(nil)
},
},
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestService_Upsert(t *testing.T) {

rr.EXPECT().WithTransaction(ctx).Return(ctx)
rr.EXPECT().Upsert(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("*rule.Rule")).Return(nil)
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(errors.New("some error"))
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("namespace.Namespace"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(errors.New("some error"))
rr.EXPECT().Rollback(ctx, mock.Anything).Return(nil)
},
ErrString: "some error",
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestService_Upsert(t *testing.T) {

rr.EXPECT().WithTransaction(ctx).Return(ctx)
rr.EXPECT().Upsert(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("*rule.Rule")).Return(nil)
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(errors.New("some error"))
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("namespace.Namespace"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(errors.New("some error"))
rr.EXPECT().Rollback(ctx, mock.Anything).Return(errors.New("rollback error"))
},
ErrString: "rollback error",
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestService_Upsert(t *testing.T) {

rr.EXPECT().WithTransaction(ctx).Return(ctx)
rr.EXPECT().Upsert(mock.AnythingOfType("context.todoCtx"), mock.AnythingOfType("*rule.Rule")).Return(nil)
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("string"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(nil)
ru.EXPECT().UpsertRule(mock.Anything, mock.AnythingOfType("namespace.Namespace"), mock.AnythingOfType("provider.Provider"), mock.AnythingOfType("*rule.Rule"), mock.AnythingOfType("*template.Template")).Return(nil)
rr.EXPECT().Commit(ctx).Return(errors.New("some commit error"))
},
ErrString: "some commit error",
Expand Down
4 changes: 2 additions & 2 deletions core/rule/v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *Rule) ToV1beta1Proto() *sirenv1beta1.Rule {
}
}

func FromV1beta1Proto(proto *sirenv1beta1.Rule) *Rule {
func FromV1beta1Proto(proto *sirenv1beta1.Rule) Rule {
variables := make([]RuleVariable, 0)
for _, variable := range proto.GetVariables() {
variables = append(variables, RuleVariable{
Expand All @@ -40,7 +40,7 @@ func FromV1beta1Proto(proto *sirenv1beta1.Rule) *Rule {
})
}

return &Rule{
return Rule{
ID: proto.GetId(),
Name: proto.GetName(),
Enabled: proto.GetEnabled(),
Expand Down
2 changes: 1 addition & 1 deletion core/silence/mocks/subscription_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/subscription/mocks/log_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/subscription/mocks/namespace_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/subscription/mocks/receiver_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2d31719

Please sign in to comment.