Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents a61026d + 35b9808 commit 1930c85
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Momento.Sdk/AuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AuthClient(IAuthConfiguration config, ICredentialProvider authProvider)
{
scsTokenClient = new ScsTokenClient(config, authProvider.AuthToken, authProvider.TokenEndpoint);
}

/// <inheritdoc />
public async Task<GenerateDisposableTokenResponse> GenerateDisposableTokenAsync(DisposableTokenScope scope, ExpiresIn expiresIn, string? tokenId = null)
{
Expand Down
10 changes: 9 additions & 1 deletion src/Momento.Sdk/Internal/ScsDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
Expand All @@ -22,6 +23,7 @@ public class ScsDataClientBase : IDisposable
private readonly TimeSpan defaultTtl;
private readonly TimeSpan dataClientOperationTimeout;
private readonly ILogger _logger;
private bool hasSentOnetimeHeaders = false;

protected readonly CacheExceptionMapper _exceptionMapper;

Expand All @@ -41,7 +43,13 @@ internal Task EagerConnectAsync(TimeSpan eagerConnectionTimeout)

protected Metadata MetadataWithCache(string cacheName)
{
return new Metadata() { { "cache", cacheName } };
if (this.hasSentOnetimeHeaders) {
return new Metadata() { { "cache", cacheName } };
}
this.hasSentOnetimeHeaders = true;
string sdkVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
return new Metadata() { { "cache", cacheName }, { "Agent", $"dotnet:cache:{sdkVersion}" }, { "Runtime-Version", runtimeVer } };
}
protected DateTime CalculateDeadline()
{
Expand Down
16 changes: 15 additions & 1 deletion src/Momento.Sdk/Internal/ScsTokenClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

using System;
using System.Reflection;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Extensions.Logging;
Expand All @@ -21,6 +22,7 @@ internal sealed class ScsTokenClient : IDisposable
private readonly string authToken;
private readonly TimeSpan authClientOperationTimeout;
private readonly ILogger _logger;
private bool hasSentOnetimeHeaders = false;
private readonly CacheExceptionMapper _exceptionMapper;
public ScsTokenClient(IAuthConfiguration config, string authToken, string endpoint)
{
Expand All @@ -30,6 +32,17 @@ public ScsTokenClient(IAuthConfiguration config, string authToken, string endpoi
this._logger = config.LoggerFactory.CreateLogger<ScsTokenClient>();
this._exceptionMapper = new CacheExceptionMapper(config.LoggerFactory);
}

private Metadata Metadata()
{
if (this.hasSentOnetimeHeaders) {
return new Metadata();
}
this.hasSentOnetimeHeaders = true;
string sdkVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
return new Metadata() { { "Agent", $"dotnet:auth:{sdkVersion}" }, { "Runtime-Version", runtimeVer } };
}

private DateTime CalculateDeadline()
{
Expand Down Expand Up @@ -65,9 +78,10 @@ public async Task<GenerateDisposableTokenResponse> GenerateDisposableToken(
Permissions = permissions,
TokenId = tokenId ?? ""
};
var metadata = Metadata();
_logger.LogTraceExecutingGenericRequest(RequestTypeAuthGenerateDisposableToken);
var response = await grpcManager.Client.generateDisposableToken(
request, new CallOptions(deadline: CalculateDeadline())
request, new CallOptions(headers: metadata, deadline: CalculateDeadline())
);
return _logger.LogTraceGenericRequestSuccess(RequestTypeAuthGenerateDisposableToken,
new GenerateDisposableTokenResponse.Success(response));
Expand Down
12 changes: 10 additions & 2 deletions src/Momento.Sdk/Internal/ScsTopicClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
Expand All @@ -18,6 +19,7 @@ public class ScsTopicClientBase : IDisposable
protected readonly TopicGrpcManager grpcManager;
private readonly TimeSpan dataClientOperationTimeout;
private readonly ILogger _logger;
private bool hasSentOnetimeHeaders = false;

protected readonly CacheExceptionMapper _exceptionMapper;

Expand All @@ -29,9 +31,15 @@ public ScsTopicClientBase(ITopicConfiguration config, string authToken, string e
this._exceptionMapper = new CacheExceptionMapper(config.LoggerFactory);
}

protected Metadata MetadataWithCache(string cacheName)
private Metadata MetadataWithCache(string cacheName)
{
return new Metadata() { { "cache", cacheName } };
if (this.hasSentOnetimeHeaders) {
return new Metadata() { { "cache", cacheName } };
}
this.hasSentOnetimeHeaders = true;
string sdkVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
return new Metadata() { { "cache", cacheName }, { "Agent", $"dotnet:topic:{sdkVersion}" }, { "Runtime-Version", runtimeVer } };
}

protected DateTime CalculateDeadline()
Expand Down

0 comments on commit 1930c85

Please sign in to comment.