Skip to content

Commit

Permalink
[credentials] fix panic on unknown credentials provider
Browse files Browse the repository at this point in the history
  • Loading branch information
shmel1k committed Jul 16, 2024
1 parent 60d3179 commit eca75fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 12 additions & 5 deletions pkg/client/auth/credentials/iam_token.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package credentials

import "context"
import (
"context"

"google.golang.org/grpc/metadata"
)

type iamTokenCredentialsProvider struct {
token string
}

// ContextWithAuth implements Provider.
func (i *iamTokenCredentialsProvider) ContextWithAuth(context.Context) (context.Context, context.CancelFunc) {
panic("unimplemented")
func (i *iamTokenCredentialsProvider) ContextWithAuth(ctx context.Context) (context.Context, context.CancelFunc) {
tok, _ := s.GetToken() // TODO(shmel1k@): return err as params
ctx, cf := context.WithCancel(ctx)
return metadata.AppendToOutgoingContext(ctx,
"x-ydb-auth-ticket", tok), cf
}

// ContextWithoutAuth implements Provider.
func (i *iamTokenCredentialsProvider) ContextWithoutAuth(context.Context) (context.Context, context.CancelFunc) {
panic("unimplemented")
func (i *iamTokenCredentialsProvider) ContextWithoutAuth(ctx context.Context) (context.Context, context.CancelFunc) {
return context.WithCancel(ctx)
}

// GetToken implements Provider.
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/auth/credentials/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ func (b *baseProvider) Init() error {
"internal error: authorization type not recognized after options validation, this should never happen",
)
}
b.initErr = b.impl.Init()
if b.initErr == nil {
b.initErr = b.impl.Init()
}
})
return b.initErr
}
Expand Down

0 comments on commit eca75fe

Please sign in to comment.