Skip to content

Commit 22f361c

Browse files
committed
fix(models): Adding legacy CertStoreInventory to V2 for continued root of trust support
1 parent d7e00db commit 22f361c

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

api/agent.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package api
33
import (
44
"context"
55
"fmt"
6-
76
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
87
)
98

v2/api/store.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package api
22

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"fmt"
8+
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
79
"log"
810
"net/http"
911
"strconv"
@@ -459,6 +461,65 @@ func (c *Client) RemoveCertificateFromStores(config *RemoveCertificateFromStore)
459461
return jsonResp, nil
460462
}
461463

464+
func (c *Client) GetCertStoreInventoryV1(storeId string) (*[]CertStoreInventoryV1, error) {
465+
466+
xKeyfactorRequestedWith := "APIClient"
467+
xKeyfactorApiVersion := "1"
468+
469+
configuration := keyfactor.NewConfiguration(make(map[string]string))
470+
apiClient := keyfactor.NewAPIClient(configuration)
471+
472+
resp, _, err := apiClient.CertificateStoreApi.CertificateStoreGetCertificateStoreInventory(context.Background(), storeId).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
473+
474+
if err != nil {
475+
return nil, err
476+
}
477+
478+
var newResp []CertStoreInventoryV1
479+
480+
if len(resp) == 0 {
481+
newResp = []CertStoreInventoryV1{}
482+
} else {
483+
for _, certInv := range resp {
484+
var newInvCertList []InventoriedCertificate
485+
var newParams = make(map[string]interface{})
486+
for _, param := range certInv.Parameters {
487+
for key, value := range param {
488+
newParams[key] = value
489+
}
490+
}
491+
for _, storedCert := range certInv.Certificates {
492+
var newInvCert = InventoriedCertificate{
493+
Id: int(*storedCert.Id),
494+
IssuedDN: *storedCert.IssuedDN.Get(),
495+
SerialNumber: *storedCert.SerialNumber,
496+
NotBefore: storedCert.NotBefore.String(),
497+
NotAfter: storedCert.NotAfter.String(),
498+
SigningAlgorithm: *storedCert.SigningAlgorithm,
499+
IssuerDN: *storedCert.IssuerDN.Get(),
500+
Thumbprint: *storedCert.Thumbprint,
501+
CertStoreInventoryItemId: int(*storedCert.CertStoreInventoryItemId),
502+
}
503+
newInvCertList = append(newInvCertList, newInvCert)
504+
}
505+
var newInv = CertStoreInventoryV1{
506+
CertStoreInventoryItemId: 0,
507+
Name: *certInv.Name,
508+
Certificates: newInvCertList,
509+
Thumbprints: nil,
510+
Serials: nil,
511+
Ids: nil,
512+
Properties: nil,
513+
Parameters: newParams,
514+
}
515+
newResp = append(newResp, newInv)
516+
}
517+
}
518+
519+
//jsonResp.Properties = unmarshalPropertiesString(jsonResp.PropertiesString)
520+
return &newResp, nil
521+
}
522+
462523
func (c *Client) GetCertStoreInventory(storeId string) (*[]CertStoreInventory, error) {
463524
// Set Keyfactor-specific headers
464525
headers := &apiHeaders{

v2/api/store_models.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ type GetCertStoreInventoryResp struct {
266266
Inventory []CertStoreInventory
267267
}
268268

269+
type CertStoreInventoryV1 struct {
270+
CertStoreInventoryItemId int `json:"CertStoreInventoryItemId"`
271+
Name string `json:"Name,omitempty"`
272+
Certificates []InventoriedCertificate `json:"Certificates,omitempty"`
273+
Thumbprints map[string]bool `json:"-"`
274+
Serials map[string]bool `json:"-"`
275+
Ids map[int]bool `json:"-"`
276+
Properties map[string]interface{} `json:"-"`
277+
Parameters map[string]interface{} `json:"-"`
278+
}
279+
269280
type CertStoreInventory struct {
270281
Name string `json:"Name,omitempty"`
271282
Certificates []InventoriedCertificate `json:"Certificates,omitempty"`

0 commit comments

Comments
 (0)