Skip to content

Commit da7447f

Browse files
authored
Merge pull request #8 from Keyfactor/customfields
Fix for sending custom field values to API
2 parents e083ee3 + 0902a42 commit da7447f

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
1.0.0
2-
Inital Release. Support for Enroll, Sync, and Revocation.
1+
1.0.0
2+
Inital Release. Support for Enroll, Sync, and Revocation.
3+
4+
1.0.1
5+
Bugfix - sync records with null serial
6+
Bugfix - Fix for custom fields in enrollment

sectigo-scm-caplugin/Models/CustomField.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Text;
@@ -12,6 +14,7 @@ public class CustomField
1214

1315
public string value { get; set; }
1416

17+
[JsonIgnore]
1518
public bool mandatory { get; set; }
1619
}
1720
}

sectigo-scm-caplugin/SectigoCAPlugin.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,30 @@ public async Task<EnrollmentResult> Enroll(string csr, string subject, Dictionar
9090
}
9191
var client = SectigoClient.InitializeClient(_config);
9292
var fieldList = Task.Run(async () => await client.ListCustomFields()).Result;
93-
var mandatoryFields = fieldList.CustomFields?.Where(f => f.mandatory);
93+
var allFields = fieldList.CustomFields?.Select(f => f);
9494

95-
_logger.LogDebug("Check for mandatory custom fields");
96-
foreach (CustomField reqField in mandatoryFields)
95+
_logger.LogDebug("Check for custom fields");
96+
List<CustomField> customFields = new List<CustomField>();
97+
foreach (CustomField field in allFields)
9798
{
98-
_logger.LogTrace($"Checking product parameters for {reqField.name}");
99-
if (!productInfo.ProductParameters.ContainsKey(reqField.name))
99+
_logger.LogTrace($"Checking product parameters for {field.name}");
100+
if (productInfo.ProductParameters.ContainsKey(field.name) && !string.IsNullOrEmpty(productInfo.ProductParameters[field.name]))
100101
{
101-
_logger.MethodExit(LogLevel.Debug);
102-
throw new Exception($"Template {productInfo.ProductID} or Enrollment Fields do not contain a mandatory custom field value for of {reqField.name}");
102+
var value = productInfo.ProductParameters[field.name];
103+
_logger.LogDebug($"Found value for custom field {field.name}: {value}");
104+
customFields.Add(new CustomField() { name = field.name, value = value });
105+
}
106+
else
107+
{
108+
if (field.mandatory)
109+
{
110+
_logger.MethodExit(LogLevel.Debug);
111+
throw new Exception($"Custom field {field.name} is mandatory, but no value provided by template {productInfo.ProductID} or Enrollment Fields");
112+
}
113+
else
114+
{
115+
_logger.LogDebug($"No value found for custom field {field.name}, but it is not mandatory.");
116+
}
103117
}
104118
}
105119
_logger.LogDebug($"Search for Organization by Name {orgStr}");
@@ -207,7 +221,8 @@ public async Task<EnrollmentResult> Enroll(string csr, string subject, Dictionar
207221
numberServers = 1,
208222
serverType = -1,
209223
subjAltNames = sanList,//,
210-
comments = comment
224+
comments = comment,
225+
customFields = customFields
211226
};
212227

213228
_logger.LogDebug($"Submit {enrollmentType} request");

0 commit comments

Comments
 (0)