diff --git a/internal/credentials/static.go b/internal/credentials/static.go index 0bb6409bd..5c6328992 100644 --- a/internal/credentials/static.go +++ b/internal/credentials/static.go @@ -88,7 +88,9 @@ func (c *Static) Token(ctx context.Context) (token string, err error) { ) } defer cc.Close() + client := Ydb_Auth_V1.NewAuthServiceClient(cc) + response, err := client.Login(ctx, &Ydb_Auth.LoginRequest{ OperationParams: &Ydb_Operations.OperationParams{ OperationMode: 0, @@ -103,6 +105,7 @@ func (c *Static) Token(ctx context.Context) (token string, err error) { if err != nil { return "", xerrors.WithStackTrace(err) } + switch { case !response.GetOperation().GetReady(): return "", xerrors.WithStackTrace( @@ -111,6 +114,7 @@ func (c *Static) Token(ctx context.Context) (token string, err error) { response.GetOperation().GetIssues(), ), ) + case response.GetOperation().GetStatus() != Ydb.StatusIds_SUCCESS: return "", xerrors.WithStackTrace( xerrors.Operation( @@ -123,10 +127,12 @@ func (c *Static) Token(ctx context.Context) (token string, err error) { if err = response.GetOperation().GetResult().UnmarshalTo(&result); err != nil { return "", xerrors.WithStackTrace(err) } + expiresAt, err := parseExpiresAt(result.GetToken()) if err != nil { return "", xerrors.WithStackTrace(err) } + c.requestAt = time.Now().Add(time.Until(expiresAt) / TokenRefreshDivisor) c.token = result.GetToken()