Skip to content

Commit f7cc87d

Browse files
dev: added ValueTask<string?> GetAuthInfoAsync() in ICredentialProvider (#281)
1 parent eb4872d commit f7cc87d

File tree

19 files changed

+73
-51
lines changed

19 files changed

+73
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Dev: added `ValueTask<string?> GetAuthInfoAsync()` in ICredentialProvider.
12
- Feat: `Writer.DisposeAsync()` waits for all in-flight messages to complete.
23
- Feat: `Reader.DisposeAsync()` waits for all pending commits to be completed.
34
- **Breaking Change**: `IReader` now implements `IAsyncDisposable` instead of `IDisposable`.

examples/src/BasicExample/ReadTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ internal partial class BasicExample
66
{
77
private async Task ReadTable()
88
{
9-
var readStream = Client.ReadTable(
9+
var readStream = await Client.ReadTable(
1010
FullTablePath("seasons"),
1111
new ReadTableSettings
1212
{

examples/src/BasicExample/ScanQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ FROM episodes
1818
ORDER BY series_id, season_id;
1919
";
2020

21-
var scanStream = Client.ExecuteScanQuery(
21+
var scanStream = await Client.ExecuteScanQuery(
2222
query,
2323
new Dictionary<string, YdbValue>
2424
{

examples/src/QueryExample/QueryExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private async Task StreamSelect()
231231

232232
await Client.DoTx(async tx =>
233233
{
234-
await foreach (var part in tx.Stream(query, commit: true))
234+
await foreach (var part in await tx.Stream(query, commit: true))
235235
{
236236
foreach (var row in part.ResultSet!.Rows)
237237
{
@@ -316,7 +316,7 @@ private async Task ReadAllResultSets()
316316
var resultSets = await Client.DoTx(async tx =>
317317
{
318318
var resultSets = new List<Value.ResultSet>();
319-
await foreach (var resultSet in tx.Stream(query, commit: true))
319+
await foreach (var resultSet in await tx.Stream(query, commit: true))
320320
{
321321
resultSets.Add(resultSet.ResultSet!);
322322
}

src/Ydb.Sdk/src/Ado/YdbCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBeha
223223
throw new InvalidOperationException("Transaction mismatched! (Maybe using another connection)");
224224
}
225225

226-
var ydbDataReader = await YdbDataReader.CreateYdbDataReader(YdbConnection.Session.ExecuteQuery(
227-
preparedSql.ToString(), ydbParameters, execSettings, transaction?.TransactionControl),
228-
YdbConnection.Session.OnStatus, transaction);
226+
var ydbDataReader = await YdbDataReader.CreateYdbDataReader(
227+
await YdbConnection.Session.ExecuteQuery(
228+
preparedSql.ToString(), ydbParameters, execSettings, transaction?.TransactionControl
229+
),
230+
YdbConnection.Session.OnStatus, transaction
231+
);
229232

230233
YdbConnection.LastReader = ydbDataReader;
231234
YdbConnection.LastCommand = CommandText;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ namespace Ydb.Sdk.Auth;
44

55
public interface ICredentialsProvider
66
{
7+
// For removal in 1.*
78
string? GetAuthInfo();
89

10+
ValueTask<string?> GetAuthInfoAsync()
11+
{
12+
return ValueTask.FromResult(GetAuthInfo());
13+
}
14+
915
Task ProvideAuthClient(AuthClient authClient)
1016
{
1117
return Task.CompletedTask;

src/Ydb.Sdk/src/Driver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private async Task<Status> DiscoverEndpoints()
129129
TransportTimeout = Config.EndpointDiscoveryTimeout
130130
};
131131

132-
var options = GetCallOptions(requestSettings);
132+
var options = await GetCallOptions(requestSettings);
133133
options.Headers?.Add(Metadata.RpcSdkInfoHeader, _sdkInfo);
134134

135135
var response = await client.ListEndpointsAsync(

src/Ydb.Sdk/src/IDriver.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ public Task<TResponse> UnaryCall<TRequest, TResponse>(
1414
where TRequest : class
1515
where TResponse : class;
1616

17-
public ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
17+
public ValueTask<ServerStream<TResponse>> ServerStreamCall<TRequest, TResponse>(
1818
Method<TRequest, TResponse> method,
1919
TRequest request,
2020
GrpcRequestSettings settings)
2121
where TRequest : class
2222
where TResponse : class;
2323

24-
public IBidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TRequest, TResponse>(
24+
public ValueTask<IBidirectionalStream<TRequest, TResponse>> BidirectionalStreamCall<TRequest, TResponse>(
2525
Method<TRequest, TResponse> method,
2626
GrpcRequestSettings settings)
2727
where TRequest : class
@@ -38,7 +38,7 @@ public interface IBidirectionalStream<in TRequest, out TResponse> : IDisposable
3838

3939
public TResponse Current { get; }
4040

41-
public string? AuthToken { get; }
41+
public ValueTask<string?> AuthToken { get; }
4242

4343
public Task RequestStreamComplete();
4444
}
@@ -74,7 +74,7 @@ public async Task<TResponse> UnaryCall<TRequest, TResponse>(
7474
using var call = callInvoker.AsyncUnaryCall(
7575
method: method,
7676
host: null,
77-
options: GetCallOptions(settings),
77+
options: await GetCallOptions(settings),
7878
request: request
7979
);
8080

@@ -90,7 +90,7 @@ public async Task<TResponse> UnaryCall<TRequest, TResponse>(
9090
}
9191
}
9292

93-
public ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
93+
public async ValueTask<ServerStream<TResponse>> ServerStreamCall<TRequest, TResponse>(
9494
Method<TRequest, TResponse> method,
9595
TRequest request,
9696
GrpcRequestSettings settings)
@@ -103,13 +103,13 @@ public ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
103103
var call = callInvoker.AsyncServerStreamingCall(
104104
method: method,
105105
host: null,
106-
options: GetCallOptions(settings),
106+
options: await GetCallOptions(settings),
107107
request: request);
108108

109109
return new ServerStream<TResponse>(call, e => { OnRpcError(endpoint, e); });
110110
}
111111

112-
public IBidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TRequest, TResponse>(
112+
public async ValueTask<IBidirectionalStream<TRequest, TResponse>> BidirectionalStreamCall<TRequest, TResponse>(
113113
Method<TRequest, TResponse> method,
114114
GrpcRequestSettings settings)
115115
where TRequest : class
@@ -121,7 +121,7 @@ public IBidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TReques
121121
var call = callInvoker.AsyncDuplexStreamingCall(
122122
method: method,
123123
host: null,
124-
options: GetCallOptions(settings));
124+
options: await GetCallOptions(settings));
125125

126126
return new BidirectionalStream<TRequest, TResponse>(
127127
call,
@@ -133,14 +133,14 @@ public IBidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TReques
133133

134134
protected abstract void OnRpcError(string endpoint, RpcException e);
135135

136-
protected CallOptions GetCallOptions(GrpcRequestSettings settings)
136+
protected async ValueTask<CallOptions> GetCallOptions(GrpcRequestSettings settings)
137137
{
138138
var meta = new Grpc.Core.Metadata
139139
{
140140
{ Metadata.RpcDatabaseHeader, Config.Database }
141141
};
142142

143-
var authInfo = Config.Credentials.GetAuthInfo();
143+
var authInfo = await Config.Credentials.GetAuthInfoAsync();
144144
if (authInfo != null)
145145
{
146146
meta.Add(Metadata.RpcAuthHeader, authInfo);
@@ -268,7 +268,7 @@ public async ValueTask<bool> MoveNextAsync()
268268

269269
public TResponse Current => _stream.ResponseStream.Current;
270270

271-
public string? AuthToken => _credentialsProvider.GetAuthInfo();
271+
public ValueTask<string?> AuthToken => _credentialsProvider.GetAuthInfoAsync();
272272

273273
public async Task RequestStreamComplete()
274274
{

src/Ydb.Sdk/src/Services/Query/QueryClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public Task<T> Stream<T>(string query, Func<ExecuteQueryStream, Task<T>> onStrea
3737
Dictionary<string, YdbValue>? parameters = null, TxMode txMode = TxMode.NoTx,
3838
ExecuteQuerySettings? settings = null)
3939
{
40-
return _sessionPool.ExecOnSession(session => onStream(new ExecuteQueryStream(
41-
session.ExecuteQuery(query, parameters, settings, txMode.TransactionControl()))));
40+
return _sessionPool.ExecOnSession(async session => await onStream(new ExecuteQueryStream(
41+
await session.ExecuteQuery(query, parameters, settings, txMode.TransactionControl())))
42+
);
4243
}
4344

4445
public Task Stream(string query, Func<ExecuteQueryStream, Task> onStream,

src/Ydb.Sdk/src/Services/Query/QueryTx.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,18 @@ internal QueryTx(Session session, TxMode txMode)
2727
_txMode = txMode;
2828
}
2929

30-
public ExecuteQueryStream Stream(string query, Dictionary<string, YdbValue>? parameters = null,
30+
public async ValueTask<ExecuteQueryStream> Stream(string query, Dictionary<string, YdbValue>? parameters = null,
3131
bool commit = false, ExecuteQuerySettings? settings = null)
3232
{
33-
return new ExecuteQueryStream(_session.ExecuteQuery(query, parameters, settings, TxControl(commit)),
34-
txId => TxId = txId);
33+
return new ExecuteQueryStream(
34+
await _session.ExecuteQuery(query, parameters, settings, TxControl(commit)), txId => TxId = txId
35+
);
3536
}
3637

3738
public async Task<IReadOnlyList<Value.ResultSet.Row>> ReadAllRows(string query,
3839
Dictionary<string, YdbValue>? parameters = null, bool commit = false, ExecuteQuerySettings? settings = null)
3940
{
40-
await using var stream = Stream(query, parameters, commit, settings);
41+
await using var stream = await Stream(query, parameters, commit, settings);
4142
List<Value.ResultSet.Row> rows = new();
4243

4344
await foreach (var part in stream)
@@ -64,7 +65,7 @@ public ExecuteQueryStream Stream(string query, Dictionary<string, YdbValue>? par
6465
public async Task Exec(string query, Dictionary<string, YdbValue>? parameters = null,
6566
ExecuteQuerySettings? settings = null, bool commit = false)
6667
{
67-
await using var stream = Stream(query, parameters, commit, settings);
68+
await using var stream = await Stream(query, parameters, commit, settings);
6869
await stream.MoveNextAsync();
6970
}
7071

0 commit comments

Comments
 (0)