From 4bf6195aeb06cccc2f32e04c10a1407580f49c25 Mon Sep 17 00:00:00 2001 From: Alexander Petrukhin Date: Tue, 16 Jul 2024 09:08:35 +0000 Subject: [PATCH] [credentials] fix panic on unknown credentials provider --- pkg/client/auth/credentials/iam_token.go | 17 ++++++++++++----- pkg/client/auth/credentials/provider.go | 4 +++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/client/auth/credentials/iam_token.go b/pkg/client/auth/credentials/iam_token.go index b39da6d..16c51b2 100644 --- a/pkg/client/auth/credentials/iam_token.go +++ b/pkg/client/auth/credentials/iam_token.go @@ -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, _ := i.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. diff --git a/pkg/client/auth/credentials/provider.go b/pkg/client/auth/credentials/provider.go index 776ace4..f665800 100644 --- a/pkg/client/auth/credentials/provider.go +++ b/pkg/client/auth/credentials/provider.go @@ -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 }