Skip to content

Commit

Permalink
restore Token function
Browse files Browse the repository at this point in the history
  • Loading branch information
Gleb Brozhe committed May 16, 2024
1 parent 3d21f27 commit 71ed802
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/credentials/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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()

Expand Down

0 comments on commit 71ed802

Please sign in to comment.