Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
deryrahman committed Oct 22, 2024
1 parent 8dedad5 commit a76da38
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion plugin/plugin_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ func (_m *UpstreamIdentifierFactory) GetMaxcomputeUpstreamIdentifier(ctx context
func NewUpstreamIdentifierFactory(t interface {
mock.TestingT
Cleanup(func())
}) *UpstreamIdentifierFactory {
},
) *UpstreamIdentifierFactory {
mock := &UpstreamIdentifierFactory{}
mock.Mock.Test(t)

Expand Down
30 changes: 26 additions & 4 deletions plugin/upstream_identifier/maxcompute_upstream_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package upstreamidentifier

import (
"context"
"fmt"

"github.com/goto/salt/log"

"github.com/goto/optimus/core/resource"
"github.com/goto/optimus/internal/errors"
"github.com/goto/optimus/plugin/upstream_identifier/parser"
"github.com/goto/salt/log"
)

type MaxcomputeUpstreamIdentifier struct {
Expand All @@ -15,14 +18,33 @@ type MaxcomputeUpstreamIdentifier struct {
}

func NewMaxcomputeUpstreamIdentifier(logger log.Logger, parserFunc ParserFunc, evaluatorFuncs ...EvalAssetFunc) (*MaxcomputeUpstreamIdentifier, error) {
me := errors.NewMultiError("create maxcompute upstream generator errors")
if logger == nil {
me.Append(fmt.Errorf("logger is nil"))
}
if parserFunc == nil {
me.Append(fmt.Errorf("parserFunc is nil"))
}
sanitizedEvaluatorFuncs := []EvalAssetFunc{}
for _, evaluatorFunc := range evaluatorFuncs {
if evaluatorFunc != nil {
sanitizedEvaluatorFuncs = append(sanitizedEvaluatorFuncs, evaluatorFunc)
}
}
if len(sanitizedEvaluatorFuncs) == 0 {
me.Append(fmt.Errorf("non-nil evaluatorFuncs is needed"))
}
if me.ToErr() != nil {
return nil, me.ToErr()
}
return &MaxcomputeUpstreamIdentifier{
logger: logger,
parserFunc: parser.MaxcomputeURNDecorator(parserFunc),
evaluatorFuncs: evaluatorFuncs,
}, nil
}

func (g MaxcomputeUpstreamIdentifier) IdentifyResources(ctx context.Context, assets map[string]string) ([]resource.URN, error) {
func (g MaxcomputeUpstreamIdentifier) IdentifyResources(_ context.Context, assets map[string]string) ([]resource.URN, error) {
resourceURNs := []resource.URN{}

// generate resource urn with upstream from each evaluator
Expand All @@ -40,9 +62,9 @@ func (g MaxcomputeUpstreamIdentifier) IdentifyResources(ctx context.Context, ass
func (g MaxcomputeUpstreamIdentifier) identifyResources(query string) []resource.URN {
resources := g.parserFunc(query)
resourceURNs := make([]resource.URN, len(resources))
for _, r := range resources {
for i, r := range resources {
resourceURN, _ := resource.NewURN("maxcompute", r) // TODO: use dedicated function new resource from string
resourceURNs = append(resourceURNs, resourceURN)
resourceURNs[i] = resourceURN
}
return resourceURNs
}
8 changes: 5 additions & 3 deletions plugin/upstream_identifier/parser/urn_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (
"strings"
)

const tablePart = 3

func BQURNDecorator(f func(string) []string) func(string) []string {
return func(rawResource string) []string {
resourceURNs := []string{}
tables := f(rawResource)
for _, table := range tables {
tableSplitted := strings.Split(table, ".")
if len(tableSplitted) != 3 {
if len(tableSplitted) != tablePart {
continue
}
resourceURN := fmt.Sprintf("bigquery://%s:%s.%s", tableSplitted[0], tableSplitted[1], tableSplitted[2])
resourceURN := fmt.Sprintf("bigquery://%s:%s.%s", tableSplitted[0], tableSplitted[1], tableSplitted[2]) //nolint:nosprintfhostport
resourceURNs = append(resourceURNs, resourceURN)
}
return resourceURNs
Expand All @@ -27,7 +29,7 @@ func MaxcomputeURNDecorator(f func(string) []string) func(string) []string {
tables := f(rawResource)
for _, table := range tables {
tableSplitted := strings.Split(table, ".")
if len(tableSplitted) != 3 {
if len(tableSplitted) != tablePart {
continue
}
resourceURN := fmt.Sprintf("maxcompute://%s.%s.%s", tableSplitted[0], tableSplitted[1], tableSplitted[2])
Expand Down
2 changes: 1 addition & 1 deletion plugin/upstream_identifier/upstream_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (u *UpstreamIdentifierFactory) GetBQUpstreamIdentifier(ctx context.Context,
return NewBQUpstreamIdentifier(u.l, parser.ParseTopLevelUpstreamsFromQuery, e.Extract, evaluatorFuncs...)
}

func (u *UpstreamIdentifierFactory) GetMaxcomputeUpstreamIdentifier(ctx context.Context, evaluators ...evaluator.Evaluator) (UpstreamIdentifier, error) {
func (u *UpstreamIdentifierFactory) GetMaxcomputeUpstreamIdentifier(_ context.Context, evaluators ...evaluator.Evaluator) (UpstreamIdentifier, error) {
evaluatorFuncs := make([]EvalAssetFunc, len(evaluators))
for i, evaluator := range evaluators {
evaluatorFuncs[i] = evaluator.Evaluate
Expand Down

0 comments on commit a76da38

Please sign in to comment.