Skip to content

Commit 411d232

Browse files
authored
Merge pull request #75 from CyberSource/dec19-dev
Adding logic for auditing
2 parents cb4c800 + 3f8cade commit 411d232

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

generator/cybersource-csharp-template/ApiClient.mustache

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ namespace {{packageName}}.Client
266266
RestClient.UserAgent = Configuration.UserAgent;
267267
268268
RestClient.ClearHandlers();
269-
269+
270270
if (Configuration.Proxy != null)
271271
{
272272
RestClient.Proxy = Configuration.Proxy;
@@ -668,6 +668,16 @@ namespace {{packageName}}.Client
668668
if (merchantConfig.IsPostRequest || merchantConfig.IsPutRequest || merchantConfig.IsPatchRequest)
669669
authenticationHeaders.Add("Digest", httpSign.Digest);
670670
}
671+
672+
if (!string.IsNullOrEmpty(Configuration.ClientId))
673+
{
674+
authenticationHeaders.Add("v-c-client-id", Configuration.ClientId);
675+
}
676+
677+
// if (!string.IsNullOrEmpty(Configuration.SolutionId))
678+
// {
679+
// authenticationHeaders.Add("v-c-solution-id", Configuration.SolutionId);
680+
// }
671681

672682
if (Configuration.Proxy == null && bool.Parse(merchantConfig.UseProxy))
673683
{
@@ -691,7 +701,7 @@ namespace {{packageName}}.Client
691701
if (Configuration.Proxy != null)
692702
{
693703
RestClient.Proxy = Configuration.Proxy;
694-
}
704+
}
695705
}
696706
}
697707
}

generator/cybersource-csharp-template/Configuration.mustache

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ namespace {{packageName}}.Client
5050
AccessToken = accessToken;
5151
UserAgent = userAgent;
5252
53+
ClientId = GetClientId();
54+
55+
if (merchConfigDictObj != null)
56+
{
57+
SolutionId = merchConfigDictObj.ContainsKey("solutionID") ? merchConfigDictObj["solutionID"] : null;
58+
}
59+
5360
if (merchConfigDictObj != null)
5461
{
5562
if (bool.Parse(merchConfigDictObj["useProxy"])) {
@@ -80,6 +87,15 @@ namespace {{packageName}}.Client
8087
MerchantConfigDictionaryObj = merchConfigDictObj;
8188
}
8289

90+
private string GetClientId()
91+
{
92+
var assembly = typeof(Configuration).Assembly;
93+
94+
var assemblyVersion = AssemblyHelper.GetAssemblyAttribute<AssemblyFileVersionAttribute>(assembly).Version;
95+
96+
return "cybs-rest-sdk-dotnet-" + assemblyVersion;
97+
}
98+
8399
/// <summary>
84100
/// Initializes a new instance of the Configuration class.
85101
/// </summary>
@@ -250,6 +266,18 @@ namespace {{packageName}}.Client
250266
/// <value>The API key.</value>
251267
public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
252268

269+
/// <summary>
270+
/// Gets or sets the Client ID for SDK auditing and/or reporting.
271+
/// </summary>
272+
/// <value>The Client ID.</value>
273+
public String ClientId { get; set; }
274+
275+
/// <summary>
276+
/// Gets or sets the Solution ID for SDK auditing and/or reporting.
277+
/// </summary>
278+
/// <value>The Solution ID.</value>
279+
public String SolutionId { get; set; }
280+
253281
/// <summary>
254282
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
255283
/// </summary>
@@ -373,4 +401,15 @@ namespace {{packageName}}.Client
373401
return report;
374402
}
375403
}
404+
405+
public static class AssemblyHelper
406+
{
407+
public static T GetAssemblyAttribute<T>(this System.Reflection.Assembly ass) where T : Attribute
408+
{
409+
object[] attributes = ass.GetCustomAttributes(typeof(T), false);
410+
if (attributes == null || attributes.Length == 0)
411+
return null;
412+
return attributes.OfType<T>().SingleOrDefault();
413+
}
414+
}
376415
}

0 commit comments

Comments
 (0)