Skip to content

Commit bffe1f2

Browse files
fix issues
1 parent cadfcce commit bffe1f2

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- **Breaking Change**: Ydb.Sdk.Yc.Auth version < 0.1.0 is not compatible with newer versions.
2-
- Added IAuthClient to fetch auth token.
1+
- **Breaking Change**: `Ydb.Sdk.Yc.Auth` version <= 0.1.0 is not compatible with newer versions.
2+
- Added `IAuthClient` to fetch auth token.
33
- Added the `TokenManagerCredentialsProvider` class, which streamlines token lifecycle management.
44
- **Breaking Change**: Deleted `AnonymousProvider`. Now users don't need to do anything for anonymous authentication.
55
Migration guide:

src/Ydb.Sdk/src/Auth/ICredentialsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public interface ICredentialsProvider
77

88
public interface IAuthClient
99
{
10-
ValueTask<TokenResponse> FetchToken();
10+
Task<TokenResponse> FetchToken();
1111
}

src/Ydb.Sdk/src/Auth/TokenManagerCredentialsProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal TokenManagerCredentialsProvider(IAuthClient authClient, IClock clock) :
3434
public async ValueTask<string> GetAuthInfoAsync() =>
3535
(await _tokenState.Validate(_clock.UtcNow)).TokenResponse.Token;
3636

37-
private ValueTask<TokenResponse> FetchToken() => _authClient.FetchToken();
37+
private Task<TokenResponse> FetchToken() => _authClient.FetchToken();
3838

3939
private ITokenState UpdateState(ITokenState current, ITokenState next)
4040
{
@@ -130,7 +130,7 @@ public async ValueTask<ITokenState> Validate(DateTime now)
130130
}
131131
}
132132

133-
public void Init() => _fetchTokenTask = _tokenManagerCredentialsProvider.FetchToken().AsTask();
133+
public void Init() => _fetchTokenTask = _tokenManagerCredentialsProvider.FetchToken();
134134
}
135135

136136
private class BackgroundState : ITokenState
@@ -196,7 +196,7 @@ public async ValueTask<ITokenState> Validate(DateTime now)
196196
}
197197
}
198198

199-
public void Init() => _fetchTokenTask = _tokenManagerCredentialsProvider.FetchToken().AsTask();
199+
public void Init() => _fetchTokenTask = _tokenManagerCredentialsProvider.FetchToken();
200200
}
201201

202202
private class ErrorState : ITokenState

src/Ydb.Sdk/src/Driver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null)
4141

4242
CredentialsProvider = Config.User != null
4343
? new TokenManagerCredentialsProvider(
44-
new AuthClient(config, _grpcChannelFactory, LoggerFactory),
44+
new StaticCredentialsAuthClient(config, _grpcChannelFactory, LoggerFactory),
4545
LoggerFactory
4646
)
4747
: Config.Credentials;

src/Ydb.Sdk/src/Services/Auth/AuthClient.cs renamed to src/Ydb.Sdk/src/Services/Auth/StaticCredentialsAuthClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010

1111
namespace Ydb.Sdk.Services.Auth;
1212

13-
internal class AuthClient : IAuthClient
13+
internal class StaticCredentialsAuthClient : IAuthClient
1414
{
1515
private readonly DriverConfig _config;
1616
private readonly GrpcChannelFactory _grpcChannelFactory;
1717
private readonly ILoggerFactory _loggerFactory;
18-
private readonly ILogger<AuthClient> _logger;
18+
private readonly ILogger<StaticCredentialsAuthClient> _logger;
1919

2020
private readonly RetrySettings _retrySettings = new(5);
2121

22-
internal AuthClient(DriverConfig config, GrpcChannelFactory grpcChannelFactory, ILoggerFactory loggerFactory)
22+
internal StaticCredentialsAuthClient(DriverConfig config, GrpcChannelFactory grpcChannelFactory, ILoggerFactory loggerFactory)
2323
{
2424
_config = config;
2525
_grpcChannelFactory = grpcChannelFactory;
2626
_loggerFactory = loggerFactory;
27-
_logger = loggerFactory.CreateLogger<AuthClient>();
27+
_logger = loggerFactory.CreateLogger<StaticCredentialsAuthClient>();
2828
}
2929

30-
public async ValueTask<TokenResponse> FetchToken()
30+
public async Task<TokenResponse> FetchToken()
3131
{
3232
uint attempt = 0;
3333
while (true)

src/Ydb.Sdk/tests/Auth/TokenManagerCredentialsProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task SyncState_To_ActiveState_To_BackgroundState_To_ActiveState()
4343
_mockAuthClient.SetupSequence(authClient => authClient.FetchToken())
4444
.ReturnsAsync(new TokenResponse(Token, now.Add(TimeSpan.FromSeconds(3))))
4545
.ReturnsAsync(new TokenResponse(Token + Token, now.Add(TimeSpan.FromSeconds(4))))
46-
.Returns(new ValueTask<TokenResponse>(tcsTokenResponse.Task));
46+
.Returns(tcsTokenResponse.Task);
4747
_mockClock.SetupSequence(clock => clock.UtcNow)
4848
.Returns(now)
4949
.Returns(now.Add(TimeSpan.FromSeconds(2)))

0 commit comments

Comments
 (0)