Skip to content

Commit

Permalink
fix(stores): properties and secrets as interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
doebrowsk committed Apr 25, 2023
1 parent 700f917 commit 456ff6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
12 changes: 5 additions & 7 deletions api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"fmt"
"log"
"net/http"

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

// CreateStore takes arguments for CreateStoreFctArgs to facilitate the creation
Expand Down Expand Up @@ -457,22 +455,22 @@ func (c *Client) GetCertStoreInventory(storeId string) (*[]CertStoreInventory, e
}

// unmarshalPropertiesString unmarshalls a JSON string and serializes it into an array of StringTuple.
func unmarshalPropertiesString(properties string) map[string]string {
func unmarshalPropertiesString(properties string) map[string]interface{} {
if properties != "" {
// First, unmarshal JSON properties string to []interface{}
var tempInterface interface{}
if err := json.Unmarshal([]byte(properties), &tempInterface); err != nil {
return make(map[string]string)
return make(map[string]interface{})
}
// Then, iterate through each key:value pair and serialize into map[string]string
newMap := make(map[string]string)
newMap := make(map[string]interface{})
for key, value := range tempInterface.(map[string]interface{}) {
newMap[key] = value.(string)
newMap[key] = value
}
return newMap
}

return make(map[string]string)
return make(map[string]interface{})
}

func validateCreateStoreArgs(ca *CreateStoreFctArgs) error {
Expand Down
52 changes: 26 additions & 26 deletions api/store_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CreateStoreFctArgs struct {
InventorySchedule *InventorySchedule `json:"InventorySchedule,omitempty"`
ReEnrollmentStatus *ReEnrollmnentConfig `json:"ReEnrollmentStatus,omitempty"`
SetNewPasswordAllowed *bool `json:"SetNewPasswordAllowed,omitempty"`
Password *StorePasswordConfig `json:"Password,omitempty"`
Password *interface{} `json:"Password,omitempty"` // type: api.StorePasswordConfig
}

// UpdateStoreFctArgs holds the function arguments used for calling the UpdateStore method.
Expand Down Expand Up @@ -64,28 +64,28 @@ type ReEnrollmnentConfig struct {
// StorePasswordConfig configures the password field for a new certificate store.
// USED FOR GETTING SECRET TYPE FIELDS
type StorePasswordConfig struct {
Value *string `json:"Value"`
Value string `json:"Value"`
SecretTypeGuid *string `json:"SecretTypeGuid"`
InstanceId *string `json:"InstanceId"`
InstanceGuid *string `json:"InstanceGuid"`
ProviderTypeParameterValues *[]ProviderTypeParamValues `json:"ProviderTypeParameterValues"`
ProviderId *string `json:"ProviderId"`
ProviderId *int `json:"ProviderId"`
IsManaged bool `json:"IsManaged"`
}

/* Future non-critical functionality */

type ProviderTypeParamValues struct {
Id *string `json:"Id"`
Value *string `json:"Value"`
InstanceId *string `json:InstanceId"`
InstanceGuid *string `json:InstanceGuid"`
ProviderTypeParams *ProviderTypeParams `json:"ProviderTypeParams"`
Id *int `json:"Id"`
Value *string `json:"Value"`
InstanceId *string `json:InstanceId"`
InstanceGuid *string `json:InstanceGuid"`
ProviderTypeParam *ProviderTypeParams `json:"ProviderTypeParam"`
// Provider ProviderParams
}

type ProviderTypeParams struct {
Id *string `json:"Id"`
Id *int `json:"Id"`
Name *string `json:"Name`
DisplayName *string `json:"DisplayName`
DataType *int `json:"DataType"`
Expand Down Expand Up @@ -145,23 +145,23 @@ type CertStoreTypeResponse struct {
}

type GetCertificateStoreResponse struct {
Id string `json:"Id,omitempty"`
ContainerId int `json:"ContainerId,omitempty"`
ClientMachine string `json:"ClientMachine,omitempty"`
StorePath string `json:"Storepath,omitempty"`
CertStoreInventoryJobId string `json:"CertStoreInventoryJobId,omitempty"`
CertStoreType int `json:"CertStoreType,omitempty"`
Approved bool `json:"Approved,omitempty"`
CreateIfMissing bool `json:"CreateIfMissing,omitempty"`
PropertiesString string `json:"Properties,omitempty"`
Properties map[string]string `json:"-"`
AgentId string `json:"AgentId,omitempty"`
AgentAssigned bool `json:"AgentAssigned,omitempty"`
ContainerName string `json:"ContainerName,omitempty"`
InventorySchedule InventorySchedule `json:"InventorySchedule"`
ReenrollmentStatus ReEnrollmnentConfig `json:"ReenrollmentStatus,omitempty"`
SetNewPasswordAllowed bool `json:"SetNewPasswordAllowed,omitempty"`
Password StorePasswordConfig `json:"Password,omitempty"`
Id string `json:"Id,omitempty"`
ContainerId int `json:"ContainerId,omitempty"`
ClientMachine string `json:"ClientMachine,omitempty"`
StorePath string `json:"Storepath,omitempty"`
CertStoreInventoryJobId string `json:"CertStoreInventoryJobId,omitempty"`
CertStoreType int `json:"CertStoreType,omitempty"`
Approved bool `json:"Approved,omitempty"`
CreateIfMissing bool `json:"CreateIfMissing,omitempty"`
PropertiesString string `json:"Properties,omitempty"`
Properties map[string]interface{} `json:"-"`
AgentId string `json:"AgentId,omitempty"`
AgentAssigned bool `json:"AgentAssigned,omitempty"`
ContainerName string `json:"ContainerName,omitempty"`
InventorySchedule InventorySchedule `json:"InventorySchedule"`
ReenrollmentStatus ReEnrollmnentConfig `json:"ReenrollmentStatus,omitempty"`
SetNewPasswordAllowed bool `json:"SetNewPasswordAllowed,omitempty"`
Password StorePasswordConfig `json:"Password,omitempty"`
}

// PropertyDefinition defines property fields associated with a certificate store type, and is returned by the
Expand Down

0 comments on commit 456ff6f

Please sign in to comment.