@@ -187,122 +187,6 @@ func (c *Client) ListCertificateStores() (*[]GetCertificateStoreResponse, error)
187187 return & jsonResp , nil
188188}
189189
190- // CreateStoreType CreateStore takes arguments for CreateStoreFctArgs to facilitate the creation
191- // of all store types supported by a customer Keyfactor Command instance. Note that various certificate
192- // store types require different property arguments, and careful attention should be taken to ensure that
193- // all required elements are included. Required arguments for this method are:
194- // - ClientMachine : string
195- // - StorePath : string
196- // - Properties : []StringTuple *Note - Method converts this array of StringTuples to a JSON string if provided
197- // - AgentId : string
198- func (c * Client ) CreateStoreType (ca * CertStoreTypeResponse ) (* CertStoreTypeResponse , error ) {
199- log .Println ("[INFO] Creating new certificate store type with Keyfactor" )
200-
201- // Validate that the required fields are present
202- //err := validateCreateStoreTypeArgs(ca)
203- //if err != nil {
204- // return nil, err
205- //}
206-
207- // Set Keyfactor-specific headers
208- headers := & apiHeaders {
209- Headers : []StringTuple {
210- {"x-keyfactor-api-version" , "1" },
211- {"x-keyfactor-requested-with" , "APIClient" },
212- },
213- }
214-
215- keyfactorAPIStruct := & request {
216- Method : "POST" ,
217- Endpoint : "CertificateStoreType" ,
218- Headers : headers ,
219- Payload : & ca ,
220- }
221-
222- resp , err := c .sendRequest (keyfactorAPIStruct )
223- if err != nil {
224- return nil , err
225- }
226-
227- jsonResp := & CertStoreTypeResponse {}
228- err = json .NewDecoder (resp .Body ).Decode (& jsonResp )
229- if err != nil {
230- return nil , err
231- }
232- return jsonResp , nil
233- }
234-
235- // GetCertStoreType takes arguments for a certificate store type ID to facilitate a call to Keyfactor
236- // that retrieves certificate store context assicated with a store type ID
237- func (c * Client ) GetCertStoreType (id int ) (* CertStoreTypeResponse , error ) {
238- // Set Keyfactor-specific headers
239- headers := & apiHeaders {
240- Headers : []StringTuple {
241- {"x-keyfactor-api-version" , "1" },
242- {"x-keyfactor-requested-with" , "APIClient" },
243- },
244- }
245-
246- endpoint := fmt .Sprintf ("CertificateStoreTypes/%d" , id )
247- keyfactorAPIStruct := & request {
248- Method : "GET" ,
249- Endpoint : endpoint ,
250- Headers : headers ,
251- Payload : nil ,
252- }
253-
254- resp , err := c .sendRequest (keyfactorAPIStruct )
255- if err != nil {
256- return nil , err
257- }
258-
259- jsonResp := & CertStoreTypeResponse {}
260- err = json .NewDecoder (resp .Body ).Decode (& jsonResp )
261- if err != nil {
262- return nil , err
263- }
264- return jsonResp , nil
265- }
266-
267- // GetCertStoreType takes arguments for a certificate store type ID to facilitate a call to Keyfactor
268- // that retrieves certificate store context assicated with a store type ID
269-
270- // GetCertStoreType takes arguments for a certificate store type ID to facilitate a call to Keyfactor
271- // that retrieves certificate store context assicated with a store type ID
272- func (c * Client ) GetCertStoreTypeByName (name string ) (* CertStoreTypeResponse , error ) {
273- // Set Keyfactor-specific headers
274- headers := & apiHeaders {
275- Headers : []StringTuple {
276- {"x-keyfactor-api-version" , "1" },
277- {"x-keyfactor-requested-with" , "APIClient" },
278- },
279- }
280-
281- endpoint := fmt .Sprintf ("CertificateStoreTypes/Name/%s" , name )
282- keyfactorAPIStruct := & request {
283- Method : "GET" ,
284- Endpoint : endpoint ,
285- Headers : headers ,
286- Payload : nil ,
287- }
288-
289- resp , err := c .sendRequest (keyfactorAPIStruct )
290- if err != nil {
291- return nil , err
292- }
293-
294- jsonResp := & CertStoreTypeResponseList {}
295- err = json .NewDecoder (resp .Body ).Decode (& jsonResp )
296- if err != nil {
297- return nil , err
298- }
299- for _ , v := range * jsonResp {
300- // TODO: Assumes that there really should only be one type with a given shortname but this is not guaranteed
301- return & v .CertStoreTypeResponse , nil
302- }
303- return nil , nil
304- }
305-
306190// GetCertificateStoreByID takes arguments for a certificate store ID to facilitate a call to Keyfactor
307191// that retrieves a certificate store context. Only the store ID is required. A pointer to a GetStoreByIDResp struct
308192// is returned that contains information on the certificate store.
@@ -403,7 +287,7 @@ func (c *Client) RemoveCertificateFromStores(config *RemoveCertificateFromStore)
403287 return jsonResp , nil
404288}
405289
406- func (c * Client ) GetCertStoreInventory (storeId string ) (* CertStoreInventory , error ) {
290+ func (c * Client ) GetCertStoreInventory (storeId string ) (* [] CertStoreInventory , error ) {
407291 // Set Keyfactor-specific headers
408292 headers := & apiHeaders {
409293 Headers : []StringTuple {
@@ -431,45 +315,49 @@ func (c *Client) GetCertStoreInventory(storeId string) (*CertStoreInventory, err
431315 if err != nil {
432316 return nil , err
433317 }
434- var invResp * CertStoreInventory
318+ var invResp [] CertStoreInventory
435319 if len (jsonResp ) == 0 {
436- invResp = & CertStoreInventory {}
320+ invResp = [] CertStoreInventory {}
437321 } else {
438322 //invResp = jsonResp[0]
439- params , ok := jsonResp [0 ].(map [string ]interface {})["Parameters" ].(map [string ]interface {})
440- if ! ok {
441- params = map [string ]interface {}{}
442- }
443- invResp = & CertStoreInventory {
444- Name : jsonResp [0 ].(map [string ]interface {})["Name" ].(string ),
445- CertStoreInventoryItemId : int (jsonResp [0 ].(map [string ]interface {})["CertStoreInventoryItemId" ].(float64 )),
446- Certificates : []InventoriedCertificate {},
447- Parameters : params ,
448- Thumbprints : map [string ]bool {},
449- Serials : map [string ]bool {},
450- Ids : map [int ]bool {},
451- }
452- for _ , cert := range jsonResp [0 ].(map [string ]interface {})["Certificates" ].([]interface {}) {
453- iCert := InventoriedCertificate {
454- Id : int (cert .(map [string ]interface {})["Id" ].(float64 )),
455- IssuedDN : cert .(map [string ]interface {})["IssuedDN" ].(string ),
456- SerialNumber : cert .(map [string ]interface {})["SerialNumber" ].(string ),
457- NotBefore : cert .(map [string ]interface {})["NotBefore" ].(string ),
458- NotAfter : cert .(map [string ]interface {})["NotAfter" ].(string ),
459- SigningAlgorithm : cert .(map [string ]interface {})["SigningAlgorithm" ].(string ),
460- IssuerDN : cert .(map [string ]interface {})["IssuerDN" ].(string ),
461- Thumbprint : cert .(map [string ]interface {})["Thumbprint" ].(string ),
462- CertStoreInventoryItemId : int (cert .(map [string ]interface {})["CertStoreInventoryItemId" ].(float64 )),
323+
324+ for _ , storedCert := range jsonResp {
325+ params , ok := storedCert .(map [string ]interface {})["Parameters" ].(map [string ]interface {})
326+ if ! ok {
327+ params = map [string ]interface {}{}
328+ }
329+ invC := CertStoreInventory {
330+ Name : storedCert .(map [string ]interface {})["Name" ].(string ),
331+ CertStoreInventoryItemId : int (storedCert .(map [string ]interface {})["CertStoreInventoryItemId" ].(float64 )),
332+ Certificates : []InventoriedCertificate {},
333+ Parameters : params ,
334+ Thumbprints : map [string ]bool {},
335+ Serials : map [string ]bool {},
336+ Ids : map [int ]bool {},
337+ }
338+ for _ , cert := range storedCert .(map [string ]interface {})["Certificates" ].([]interface {}) {
339+ iCert := InventoriedCertificate {
340+ Id : int (cert .(map [string ]interface {})["ID" ].(float64 )),
341+ IssuedDN : cert .(map [string ]interface {})["IssuedDN" ].(string ),
342+ SerialNumber : cert .(map [string ]interface {})["SerialNumber" ].(string ),
343+ NotBefore : cert .(map [string ]interface {})["NotBefore" ].(string ),
344+ NotAfter : cert .(map [string ]interface {})["NotAfter" ].(string ),
345+ SigningAlgorithm : cert .(map [string ]interface {})["SigningAlgorithm" ].(string ),
346+ IssuerDN : cert .(map [string ]interface {})["IssuerDN" ].(string ),
347+ Thumbprint : cert .(map [string ]interface {})["Thumbprint" ].(string ),
348+ CertStoreInventoryItemId : int (cert .(map [string ]interface {})["CertStoreInventoryItemId" ].(float64 )),
349+ }
350+ invC .Certificates = append (invC .Certificates , iCert )
351+ invC .Thumbprints [cert .(map [string ]interface {})["Thumbprint" ].(string )] = true
352+ invC .Serials [cert .(map [string ]interface {})["SerialNumber" ].(string )] = true
353+ invC .Ids [int (cert .(map [string ]interface {})["ID" ].(float64 ))] = true
354+ invResp = append (invResp , invC )
463355 }
464- invResp .Certificates = append (invResp .Certificates , iCert )
465- invResp .Thumbprints [cert .(map [string ]interface {})["Thumbprint" ].(string )] = true
466- invResp .Serials [cert .(map [string ]interface {})["SerialNumber" ].(string )] = true
467- invResp .Ids [int (cert .(map [string ]interface {})["Id" ].(float64 ))] = true
468356 }
469357 }
470358
471359 //jsonResp.Properties = unmarshalPropertiesString(jsonResp.PropertiesString)
472- return invResp , nil
360+ return & invResp , nil
473361}
474362
475363// unmarshalPropertiesString unmarshalls a JSON string and serializes it into an array of StringTuple.
0 commit comments