Skip to content

Commit

Permalink
chore: Update User-Agent string (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
96malhar authored Apr 16, 2024
1 parent cd9600e commit 65dd1d9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<DelaySign>false</DelaySign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.5.2</Version>
<Version>2.5.3</Version>
</PropertyGroup>

<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.CognitoIdentity" Version="3.7.0.2" />
<PackageReference Include="AWSSDK.CognitoIdentityProvider" Version="3.7.0.2" />
<PackageReference Include="AWSSDK.CognitoIdentity" Version="3.7.300.74" />
<PackageReference Include="AWSSDK.CognitoIdentityProvider" Version="3.7.303.19" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@


[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("2.5.3.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ internal static class CognitoAuthHelper
{
[ThreadStatic] private static SHA256 sha256 = null;

private static string assemblyFileVersion = null;
private static readonly string _assemblyVersion = GetAssemblyFileVersion();

private static readonly string _userAgentSuffix = $"lib/AWSDotNetCognito#{_assemblyVersion}";
/// <summary>
/// Property to access the thread-safe SHA256 member variable.
/// Creates a SHA256 instance if one does not exist.
Expand All @@ -44,23 +46,7 @@ internal static SHA256 Sha256
return sha256;
}
}

internal static string AssemblyFileVersion
{
get
{
if (assemblyFileVersion == null)
{
var assembly = typeof(CognitoAuthHelper).GetTypeInfo().Assembly;
AssemblyFileVersionAttribute attribute = assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute;

assemblyFileVersion = attribute == null ? "Unknown" : attribute.Version;
}

return assemblyFileVersion;
}
}

/// <summary>
/// Computes the secret hash for the user pool using the corresponding userID, clientID,
/// and client secret
Expand Down Expand Up @@ -161,15 +147,20 @@ internal static List<AttributeType> CreateAttributeList(IDictionary<string, stri

internal static void ServiceClientBeforeRequestEvent(object sender, RequestEventArgs e)
{
Amazon.Runtime.WebServiceRequestEventArgs args = e as Amazon.Runtime.WebServiceRequestEventArgs;
if (args == null || !args.Headers.ContainsKey(UserAgentHeader))
WebServiceRequestEventArgs args = e as WebServiceRequestEventArgs;
if (args == null || !args.Headers.ContainsKey(UserAgentHeader) || args.Headers[UserAgentHeader].Contains(_userAgentSuffix))
return;

var metric = " AWSDotNetCognito/" + AssemblyFileVersion;
if (!args.Headers[UserAgentHeader].Contains(metric))
{
args.Headers[UserAgentHeader] = args.Headers[UserAgentHeader] + metric;
}
args.Headers[UserAgentHeader] = args.Headers[UserAgentHeader] + " " + _userAgentSuffix;
}

private static string GetAssemblyFileVersion()
{
var assembly = typeof(CognitoAuthHelper).GetTypeInfo().Assembly;
AssemblyFileVersionAttribute attribute = assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute;

var version = attribute == null ? "Unknown" : attribute.Version;
return version;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.Core" Version="3.7.0.3" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.1" />
<PackageReference Include="AWSSDK.S3" Version="3.7.0.3" />
<PackageReference Include="AWSSDK.Core" Version="3.7.303.14" />
<PackageReference Include="AWSSDK.IdentityManagement" Version="3.7.301" />
<PackageReference Include="AWSSDK.S3" Version="3.7.307.15" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
Expand Down

0 comments on commit 65dd1d9

Please sign in to comment.