Skip to content

Commit 4bc0209

Browse files
committed
WIP
Signed-off-by: sbailey <[email protected]>
1 parent d4d2a67 commit 4bc0209

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

api/store.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"log"
99
"net/http"
1010

11-
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
11+
kfc "github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
1212
)
1313

1414
// CreateStore takes arguments for CreateStoreFctArgs to facilitate the creation
@@ -134,8 +134,8 @@ func (c *Client) DeleteCertificateStore(storeId string) error {
134134
xKeyfactorRequestedWith := "APIClient"
135135
xKeyfactorApiVersion := "1"
136136

137-
configuration := keyfactor.NewConfiguration(make(map[string]string))
138-
apiClient := keyfactor.NewAPIClient(configuration)
137+
configuration := kfc.NewConfiguration(make(map[string]string))
138+
apiClient := kfc.NewAPIClient(configuration)
139139

140140
resp, err := apiClient.CertificateStoreApi.CertificateStoreDeleteCertificateStore(context.Background(), storeId).XKeyfactorRequestedWith(xKeyfactorRequestedWith).XKeyfactorApiVersion(xKeyfactorApiVersion).Execute()
141141

@@ -311,22 +311,22 @@ func (c *Client) AddCertificateToStores(config *AddCertificateToStore) ([]string
311311
xKeyfactorRequestedWith := "APIClient"
312312
xKeyfactorApiVersion := "1"
313313

314-
configuration := keyfactor.NewConfiguration(make(map[string]string))
315-
apiClient := keyfactor.NewAPIClient(configuration)
314+
configuration := kfc.NewConfiguration(make(map[string]string))
315+
apiClient := kfc.NewAPIClient(configuration)
316316

317317
newCollectionId := int32(config.CollectionId)
318-
var newCertStoresList []keyfactor.ModelsCertificateStoreEntry
318+
var newCertStoresList []kfc.ModelsCertificateStoreEntry
319319
for _, cert := range *config.CertificateStores {
320320
newProvider := int32(cert.EntryPassword.Provider)
321321
var newParams map[string]string
322322
data, _ := json.Marshal(cert.EntryPassword.Parameters)
323323
json.Unmarshal(data, &newParams)
324-
var newEntryPassword = keyfactor.ModelsKeyfactorAPISecret{
324+
var newEntryPassword = kfc.ModelsKeyfactorAPISecret{
325325
SecretValue: &cert.EntryPassword.SecretValue,
326326
Parameters: &newParams,
327327
Provider: &newProvider,
328328
}
329-
var newCert = keyfactor.ModelsCertificateStoreEntry{
329+
var newCert = kfc.ModelsCertificateStoreEntry{
330330
CertificateStoreId: cert.CertificateStoreId,
331331
Alias: &cert.Alias,
332332
JobFields: nil,
@@ -339,9 +339,9 @@ func (c *Client) AddCertificateToStores(config *AddCertificateToStore) ([]string
339339
}
340340

341341
jsonInvSched, _ := json.Marshal(config.InventorySchedule)
342-
var newSchedule keyfactor.KeyfactorCommonSchedulingKeyfactorSchedule
342+
var newSchedule kfc.KeyfactorCommonSchedulingKeyfactorSchedule
343343
json.Unmarshal(jsonInvSched, newSchedule)
344-
var newReq = keyfactor.KeyfactorApiModelsCertificateStoresAddCertificateRequest{
344+
var newReq = kfc.KeyfactorApiModelsCertificateStoresAddCertificateRequest{
345345
CertificateId: int32(config.CertificateId),
346346
CertificateStores: newCertStoresList,
347347
Schedule: newSchedule,
@@ -365,13 +365,13 @@ func (c *Client) RemoveCertificateFromStores(config *RemoveCertificateFromStore)
365365
xKeyfactorRequestedWith := "APIClient"
366366
xKeyfactorApiVersion := "1"
367367

368-
configuration := keyfactor.NewConfiguration(make(map[string]string))
369-
apiClient := keyfactor.NewAPIClient(configuration)
368+
configuration := kfc.NewConfiguration(make(map[string]string))
369+
apiClient := kfc.NewAPIClient(configuration)
370370

371371
newCollectionId := int32(config.CollectionId)
372-
var newCertStoresList []keyfactor.ModelsCertificateLocationSpecifier
372+
var newCertStoresList []kfc.ModelsCertificateLocationSpecifier
373373
for _, cert := range *config.CertificateStores {
374-
var newCert = keyfactor.ModelsCertificateLocationSpecifier{
374+
var newCert = kfc.ModelsCertificateLocationSpecifier{
375375
Alias: &cert.Alias,
376376
CertificateStoreId: &cert.CertificateStoreId,
377377
JobFields: nil,
@@ -380,9 +380,9 @@ func (c *Client) RemoveCertificateFromStores(config *RemoveCertificateFromStore)
380380
}
381381

382382
jsonInvSched, _ := json.Marshal(config.InventorySchedule)
383-
var newSchedule keyfactor.KeyfactorCommonSchedulingKeyfactorSchedule
383+
var newSchedule kfc.KeyfactorCommonSchedulingKeyfactorSchedule
384384
json.Unmarshal(jsonInvSched, newSchedule)
385-
var newReq = keyfactor.KeyfactorApiModelsCertificateStoresRemoveCertificateRequest{
385+
var newReq = kfc.KeyfactorApiModelsCertificateStoresRemoveCertificateRequest{
386386
CertificateStores: newCertStoresList,
387387
Schedule: newSchedule,
388388
CollectionId: &newCollectionId,
@@ -402,8 +402,8 @@ func (c *Client) GetCertStoreInventory(storeId string) (*[]CertStoreInventory, e
402402
xKeyfactorRequestedWith := "APIClient"
403403
xKeyfactorApiVersion := "1"
404404

405-
configuration := keyfactor.NewConfiguration(make(map[string]string))
406-
apiClient := keyfactor.NewAPIClient(configuration)
405+
configuration := kfc.NewConfiguration(make(map[string]string))
406+
apiClient := kfc.NewAPIClient(configuration)
407407

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

v2/api/security.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,20 @@ func (c *Client) GetSecurityRoles() ([]GetSecurityRolesResponse, error) {
134134
return nil, err
135135
}
136136

137+
//var jsonRespDebug []GetSecurityRolesResponseDebug
138+
//var rawInterface interface{}
139+
//err = json.NewDecoder(resp.Body).Decode(&rawInterface)
140+
//get first element of the array and cast it to a
137141
var jsonResp []GetSecurityRolesResponse
138142
err = json.NewDecoder(resp.Body).Decode(&jsonResp)
143+
139144
if err != nil {
140145
return nil, err
141146
}
147+
148+
// Convert interface into a slice of GetSecurityRolesResponse
149+
//jsonResp = rawInterface.([]GetSecurityRolesResponse)
150+
142151
return jsonResp, nil
143152
}
144153

@@ -196,13 +205,16 @@ func (c *Client) GetSecurityRole(id interface{}) (*GetSecurityRoleResponse, erro
196205
return nil, err
197206
}
198207

199-
jsonResp := &GetSecurityRolesResponse{}
208+
jsonResp := &[]GetSecurityRolesResponse{}
200209
err = json.NewDecoder(resp.Body).Decode(&jsonResp)
201210

202211
for i, jResp := range *jsonResp {
203212
log.Printf("[INFO] Getting Keyfactor security role with %v ID %v", i, jResp)
213+
//convert ID from int to float64
214+
formattedID := float64(jResp.ID)
215+
204216
return &GetSecurityRoleResponse{
205-
Id: jResp.ID,
217+
Id: formattedID,
206218
Name: jResp.Name,
207219
Description: jResp.Description,
208220
Identities: jResp.Identities,

v2/api/security_models.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ type CreateSecurityIdentityResponse struct {
3131
}
3232

3333
// GetSecurityRolesResponse holds the response data returned by /Security/Roles
34-
type GetSecurityRolesResponse []struct {
35-
ID int `json:"Id,omitempty"`
34+
type GetSecurityRolesResponse struct {
35+
ID float64 `json:"Id"`
3636
Description string `json:"Description,omitempty"`
3737
Enabled bool `json:"Enabled"`
3838
Immutable bool `json:"Immutable"`
3939
Valid bool `json:"Valid"`
4040
Private bool `json:"Private"`
41-
Identities []SecurityIdentity `json:"Identities,omitempty"`
41+
Identities []SecurityIdentity `json:"Identities"`
4242
Name string `json:"Name,omitempty"`
43-
Permissions []string `json:"Permissions,omitempty"`
43+
Permissions []string `json:"Permissions"`
4444
}
4545

4646
type GetSecurityRoleResponse struct {
47-
Id int `json:"Id,omitempty"`
47+
Id float64 `json:"Id,omitempty"`
4848
Name string `json:"Name,omitempty"`
4949
Description string `json:"Description,omitempty"`
5050
Identities []SecurityIdentity `json:"Identities,omitempty"`
@@ -53,10 +53,10 @@ type GetSecurityRoleResponse struct {
5353

5454
// SecurityIdentity contains the contains required elements to attach an identity to a role
5555
type SecurityIdentity struct {
56-
Id int `json:"Id,omitempty"`
57-
AccountName string `json:"AccountName,omitempty"`
58-
IdentityType string `json:"IdentityType,omitempty"`
59-
Sid string `json:"Sid,omitempty"`
56+
Id float64 `json:"Id"`
57+
AccountName string `json:"AccountName"`
58+
IdentityType string `json:"IdentityType"`
59+
Sid string `json:"SID"`
6060
}
6161

6262
// CreateSecurityRoleArg holds the function arguments required for CreateSecurityRole

v2/go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ go 1.18
44

55
require (
66
github.com/Keyfactor/keyfactor-go-client v1.4.3
7+
github.com/Keyfactor/keyfactor-go-client-sdk v1.0.1
78
github.com/spbsoluble/go-pkcs12 v0.3.3
89
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352
910
)
1011

11-
require (
12-
github.com/Keyfactor/keyfactor-go-client-sdk v1.0.1 // indirect
13-
golang.org/x/crypto v0.11.0 // indirect
14-
)
12+
require golang.org/x/crypto v0.11.0 // indirect

0 commit comments

Comments
 (0)