@@ -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