Skip to content

Commit

Permalink
fix(models): Adding legacy CertStoreInventory to V2 for continued `…
Browse files Browse the repository at this point in the history
…root of trust` support
  • Loading branch information
spbsoluble committed Oct 4, 2023
1 parent d7e00db commit 22f361c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
1 change: 0 additions & 1 deletion api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"context"
"fmt"

"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
)

Expand Down
61 changes: 61 additions & 0 deletions v2/api/store.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package api

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
"log"
"net/http"
"strconv"
Expand Down Expand Up @@ -459,6 +461,65 @@ func (c *Client) RemoveCertificateFromStores(config *RemoveCertificateFromStore)
return jsonResp, nil
}

func (c *Client) GetCertStoreInventoryV1(storeId string) (*[]CertStoreInventoryV1, error) {

xKeyfactorRequestedWith := "APIClient"
xKeyfactorApiVersion := "1"

configuration := keyfactor.NewConfiguration(make(map[string]string))
apiClient := keyfactor.NewAPIClient(configuration)

resp, _, err := apiClient.CertificateStoreApi.CertificateStoreGetCertificateStoreInventory(context.Background(), storeId).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()

if err != nil {
return nil, err
}

var newResp []CertStoreInventoryV1

if len(resp) == 0 {
newResp = []CertStoreInventoryV1{}
} else {
for _, certInv := range resp {
var newInvCertList []InventoriedCertificate
var newParams = make(map[string]interface{})
for _, param := range certInv.Parameters {
for key, value := range param {
newParams[key] = value
}
}
for _, storedCert := range certInv.Certificates {
var newInvCert = InventoriedCertificate{
Id: int(*storedCert.Id),
IssuedDN: *storedCert.IssuedDN.Get(),
SerialNumber: *storedCert.SerialNumber,
NotBefore: storedCert.NotBefore.String(),
NotAfter: storedCert.NotAfter.String(),
SigningAlgorithm: *storedCert.SigningAlgorithm,
IssuerDN: *storedCert.IssuerDN.Get(),
Thumbprint: *storedCert.Thumbprint,
CertStoreInventoryItemId: int(*storedCert.CertStoreInventoryItemId),
}
newInvCertList = append(newInvCertList, newInvCert)
}
var newInv = CertStoreInventoryV1{
CertStoreInventoryItemId: 0,
Name: *certInv.Name,
Certificates: newInvCertList,
Thumbprints: nil,
Serials: nil,
Ids: nil,
Properties: nil,
Parameters: newParams,
}
newResp = append(newResp, newInv)
}
}

//jsonResp.Properties = unmarshalPropertiesString(jsonResp.PropertiesString)
return &newResp, nil
}

func (c *Client) GetCertStoreInventory(storeId string) (*[]CertStoreInventory, error) {
// Set Keyfactor-specific headers
headers := &apiHeaders{
Expand Down
11 changes: 11 additions & 0 deletions v2/api/store_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ type GetCertStoreInventoryResp struct {
Inventory []CertStoreInventory
}

type CertStoreInventoryV1 struct {
CertStoreInventoryItemId int `json:"CertStoreInventoryItemId"`
Name string `json:"Name,omitempty"`
Certificates []InventoriedCertificate `json:"Certificates,omitempty"`
Thumbprints map[string]bool `json:"-"`
Serials map[string]bool `json:"-"`
Ids map[int]bool `json:"-"`
Properties map[string]interface{} `json:"-"`
Parameters map[string]interface{} `json:"-"`
}

type CertStoreInventory struct {
Name string `json:"Name,omitempty"`
Certificates []InventoriedCertificate `json:"Certificates,omitempty"`
Expand Down

0 comments on commit 22f361c

Please sign in to comment.