Skip to content

Commit

Permalink
[factory] add credentialsprovider getter as factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
shmel1k committed Jul 9, 2024
1 parent c1efc1d commit 1c55565
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca
github.com/ydb-platform/ydb-go-sdk/v3 v3.47.3
github.com/ydb-platform/ydb-go-yc v0.12.1
github.com/ydb-platform/ydb-go-yc-metadata v0.6.1
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.62.0
Expand Down Expand Up @@ -47,9 +50,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/yandex-cloud/go-genproto v0.0.0-20211115083454-9ca41db5ed9e // indirect
github.com/ydb-platform/ydb-go-sdk/v3 v3.47.3 // indirect
github.com/ydb-platform/ydb-go-yc v0.12.1 // indirect
github.com/ydb-platform/ydb-go-yc-metadata v0.6.1 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ=
github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU=
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
Expand All @@ -622,6 +621,7 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -829,7 +829,6 @@ github.com/ydb-platform/ydb-go-genproto v0.0.0-20221215182650-986f9d10542f/go.mo
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca h1:PliQWLwi2gTSOk7QyYQ9GfjvvikmibLWmaplKHy+kfo=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
github.com/ydb-platform/ydb-go-sdk/v3 v3.44.0 h1:QaJU87Qfh5Y3GB9NefavinTZQTePVPNSBYnjm6AV+wk=
github.com/ydb-platform/ydb-go-sdk/v3 v3.44.0/go.mod h1:oSLwnuilwIpaF5bJJMAofnGgzPJusoI3zWMNb8I+GnM=
github.com/ydb-platform/ydb-go-sdk/v3 v3.47.3 h1:6LwpXivkQxKYRjSZYj4M+G3J8sDtPPNzo9Shzc64oIo=
github.com/ydb-platform/ydb-go-sdk/v3 v3.47.3/go.mod h1:bWnOIcUHd7+Sl7DN+yhyY1H/I61z53GczvwJgXMgvj0=
Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ func createLogger(level string) (zap.AtomicLevel, *zap.Logger) {
}

var (
factory cmdutil.Factory
baseOptions *command.BaseOptions
cmsClient cms.Client
discoveryClient discovery.Client
factory cmdutil.Factory
baseOptions *command.BaseOptions
cmsClient cms.Client
discoveryClient discovery.Client
credentialsProvider credentials.Provider
)

func initFactory() {
factory = cmdutil.New(baseOptions, cmsClient, discoveryClient)
factory = cmdutil.New(baseOptions, cmsClient, discoveryClient, credentialsProvider)
}

func initClients(
Expand All @@ -61,7 +62,7 @@ func main() {

options.Logger = logger.Sugar() // TODO(shmel1k@): tmp hack

credentialsProvider := credentials.New(baseOptions, cf, logger.Sugar(), nil)
credentialsProvider = credentials.New(baseOptions, cf, logger.Sugar(), nil)
initClients(cf, logger.Sugar(), credentialsProvider)
initFactory()

Expand Down
3 changes: 2 additions & 1 deletion pkg/client/auth/credentials/iam_creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"strings"
"sync"

"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
yc "github.com/ydb-platform/ydb-go-yc"

Check failure on line 8 in pkg/client/auth/credentials/iam_creds.go

View workflow job for this annotation

GitHub Actions / run-lint / golangci-lint

File is not `goimports`-ed with -local github.com/ydb-platform/ydb-go-sdk/v3 (goimports)
"google.golang.org/grpc/metadata"

"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
)

type iamCredsProvider struct {
Expand Down
9 changes: 9 additions & 0 deletions pkg/cmdutil/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmdutil
import (
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"

"github.com/ydb-platform/ydbops/pkg/client/auth/credentials"
"github.com/ydb-platform/ydbops/pkg/client/cms"
"github.com/ydb-platform/ydbops/pkg/client/discovery"
"github.com/ydb-platform/ydbops/pkg/command"
Expand All @@ -12,6 +13,7 @@ type Factory interface {
GetCMSClient() cms.Client
GetDiscoveryClient() discovery.Client
GetBaseOptions() *command.BaseOptions
GetCredentialsProvider() credentials.Provider
// GetAuthClient() auth.Client
}

Expand All @@ -23,17 +25,20 @@ type factory struct {
cmsClient cms.Client
discoveryClient discovery.Client
opts *command.BaseOptions
cp credentials.Provider
}

func New(
opts *command.BaseOptions,
cmsClient cms.Client,
discoveryClient discovery.Client,
cp credentials.Provider,
) Factory {
return &factory{
opts: opts,
cmsClient: cmsClient,
discoveryClient: discoveryClient,
cp: cp,
}
}

Expand All @@ -48,3 +53,7 @@ func (f *factory) GetDiscoveryClient() discovery.Client {
func (f *factory) GetBaseOptions() *command.BaseOptions {
return f.opts
}

func (f *factory) GetCredentialsProvider() credentials.Provider {
return f.cp
}

0 comments on commit 1c55565

Please sign in to comment.