From 7778c606920380211915b9a2b81b2ec5f4996711 Mon Sep 17 00:00:00 2001 From: spbsoluble <1661003+spbsoluble@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:34:10 -0700 Subject: [PATCH] fix: Disable logging by default. --- v3/api/agent.go | 19 ++++--- v3/api/ca.go | 4 +- v3/api/certificate.go | 50 ++++++++++-------- v3/api/client.go | 103 ++++++++++++++++++++++++-------------- v3/api/security.go | 29 +++++++---- v3/api/store.go | 13 +++-- v3/api/store_container.go | 7 ++- v3/api/store_type.go | 10 ++-- 8 files changed, 150 insertions(+), 85 deletions(-) diff --git a/v3/api/agent.go b/v3/api/agent.go index 93a8787..4682a18 100644 --- a/v3/api/agent.go +++ b/v3/api/agent.go @@ -17,12 +17,14 @@ package api import ( "encoding/json" "fmt" + "log" "regexp" ) // GetAgentList returns a list of orchestrators registered in the Keyfactor instance func (c *Client) GetAgentList() ([]Agent, error) { - // 0 + log.Println("[INFO] Getting a list of agents registered in Keyfactor") + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -52,7 +54,8 @@ func (c *Client) GetAgentList() ([]Agent, error) { } func (c *Client) GetAgent(id string) ([]Agent, error) { - // 0 + log.Println("[INFO] Getting agent by ID or name.") + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -103,7 +106,8 @@ func (c *Client) GetAgent(id string) ([]Agent, error) { } func (c *Client) ApproveAgent(id string) (string, error) { - // 0 + log.Printf("[INFO] Approving agent %s in Keyfactor.\n", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -137,7 +141,8 @@ func (c *Client) ApproveAgent(id string) (string, error) { } func (c *Client) DisApproveAgent(id string) (string, error) { - // 0 + log.Printf("[INFO] Disapproving agent %s in Keyfactor.\n", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -171,7 +176,8 @@ func (c *Client) DisApproveAgent(id string) (string, error) { } func (c *Client) ResetAgent(id string) (string, error) { - // 0 + log.Printf("[INFO] Resetting agent %s in Keyfactor.\n", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -204,7 +210,8 @@ func (c *Client) ResetAgent(id string) (string, error) { } func (c *Client) FetchAgentLogs(id string) (string, error) { - // 0 + log.Printf("[INFO] Fetching agent logs for %s.\n", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ diff --git a/v3/api/ca.go b/v3/api/ca.go index 947e1d4..15a701b 100644 --- a/v3/api/ca.go +++ b/v3/api/ca.go @@ -16,11 +16,13 @@ package api import ( "encoding/json" + "log" ) // GetCAList returns a list of certificate authorities supported by the Keyfactor instance func (c *Client) GetCAList() ([]CA, error) { - // 0 + log.Println("[INFO] Getting a list of CAs from Keyfactor instance") + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ diff --git a/v3/api/certificate.go b/v3/api/certificate.go index 8049d7b..c734c65 100644 --- a/v3/api/certificate.go +++ b/v3/api/certificate.go @@ -34,7 +34,8 @@ import ( // EnrollPFX takes arguments for EnrollPFXFctArgs to facilitate a call to Keyfactor // that enrolls a PFX certificate with the supplied arguments. func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) { - // 0 + log.Println("[INFO] Enrolling PFX certificate with Keyfactor") + /* Ensure required inputs exist */ var missingFields []string @@ -106,7 +107,8 @@ func (c *Client) EnrollPFX(ea *EnrollPFXFctArgs) (*EnrollResponse, error) { } func (c *Client) EnrollPFXV2(ea *EnrollPFXFctArgsV2) (*EnrollResponseV2, error) { - // 0 + log.Println("[INFO] Enrolling PFX certificate with Keyfactor") + /* Ensure required inputs exist */ var missingFields []string @@ -160,7 +162,8 @@ func (c *Client) EnrollPFXV2(ea *EnrollPFXFctArgsV2) (*EnrollResponseV2, error) Payload: &ea, } - // 0 + log.Println("[TRACE] Request: ", keyfactorAPIStruct) + resp, err := c.sendRequest(keyfactorAPIStruct) if err != nil { return nil, err @@ -194,7 +197,8 @@ func (c *Client) DownloadCertificate( serialNumber string, issuerDn string, ) (*x509.Certificate, []*x509.Certificate, error) { - // 0 + log.Println("[INFO] Downloading certificate") + /* The download certificate endpoint requires one of the following to retrieve a cert: - CertID - Thumbprint @@ -282,7 +286,8 @@ func (c *Client) DownloadCertificate( // - Template : string // - CertificateAuthority : string func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) { - // 0 + log.Println("[INFO] Signing CSR with Keyfactor") + /* Ensure required inputs exist */ if (ea.Template == "") || (ea.CertificateAuthority == "") { return nil, errors.New("invalid or nonexistent values required for csr enrollment") @@ -328,9 +333,9 @@ func (c *Client) EnrollCSR(ea *EnrollCSRFctArgs) (*EnrollResponse, error) { // - CertificateIds : []int // - Comment : string func (c *Client) RevokeCert(rvargs *RevokeCertArgs) error { - // 0 + log.Println("[INFO] Revoking certificates") //for _, certs := range rvargs.CertificateIds { - // // 0 + // log.Printf("[TRACE] Revoking ID %d", certs) //} // Fields required by revoke cert API request are cert ID & comment @@ -640,8 +645,8 @@ func (c *Client) RecoverCertificate( password string, collectionId int, ) (interface{}, *x509.Certificate, []*x509.Certificate, error) { - // 0 - // 0 + log.Println("[DEBUG] Enter RecoverCertificate") + log.Println("[INFO] Recovering certificate ID:", certId) /* The download certificate endpoint requires one of the following to retrieve a cert: - CertID - Thumbprint @@ -659,10 +664,11 @@ func (c *Client) RecoverCertificate( } if !validInput { - // 0 + log.Println("[ERROR] RecoverCertificate: certID, thumbprint, or serial number AND issuer DN required to download certificate") return nil, nil, nil, fmt.Errorf("certID, thumbprint, or serial number AND issuer DN required to download certificate") } - // 0 + log.Println("[DEBUG] RecoverCertificate: Valid input") + if password == "" { return nil, nil, nil, fmt.Errorf("password required to recover private key with certificate") } @@ -676,7 +682,7 @@ func (c *Client) RecoverCertificate( IncludeChain: true, } - // 0 + log.Println("[DEBUG] RecoverCertificate: Recovering certificate with args:", rca) // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -691,16 +697,16 @@ func (c *Client) RecoverCertificate( Query: []StringTuple{}, } if collectionId > 0 { - // 0 + log.Println("[DEBUG] RecoverCertificate: Collection ID:", collectionId) query.Query = append( query.Query, StringTuple{ "collectionId", fmt.Sprintf("%d", collectionId), }, ) - // 0 + log.Println("[DEBUG] RecoverCertificate: Query:", query) } - // 0 + log.Println("[DEBUG] RecoverCertificate: Creating recover certificate request") keyfactorAPIStruct := &request{ Method: "POST", Endpoint: "Certificates/Recover", @@ -709,7 +715,7 @@ func (c *Client) RecoverCertificate( Query: &query, } - // 0 + log.Println("[INFO] Attempting to recover certificate from Keyfactor Command") resp, err := c.sendRequest(keyfactorAPIStruct) if err != nil { log.Println("[ERROR] RecoverCertificate: Error recovering certificate from Keyfactor Command", err.Error()) @@ -717,29 +723,29 @@ func (c *Client) RecoverCertificate( } jsonResp := &recoverCertResponse{} - // 0 + log.Println("[DEBUG] RecoverCertificate: Decoding response") err = json.NewDecoder(resp.Body).Decode(&jsonResp) if err != nil { log.Println("[ERROR] RecoverCertificate: Error decoding response from Keyfactor Command", err.Error()) return nil, nil, nil, err } - // 0 + log.Println("[DEBUG] RecoverCertificate: Decoding PFX") pfxDer, err := base64.StdEncoding.DecodeString(jsonResp.PFX) if err != nil { log.Println("[ERROR] RecoverCertificate: Error decoding PFX", err.Error()) return nil, nil, nil, err } - // 0 + log.Println("[DEBUG] RecoverCertificate: Decoding PFX chain") priv, leaf, chain, err := pkcs12.DecodeChain(pfxDer, rca.Password) if err != nil { log.Println("[ERROR] RecoverCertificate: Error decoding PFX chain", err.Error()) return nil, nil, nil, err } - // 0 - // 0 + log.Println("[INFO] Recovered certificate successfully") + log.Println("[DEBUG] RecoverCertificate: ", leaf, chain) return priv, leaf, chain, nil } @@ -794,7 +800,7 @@ func validateDeployPFXArgs(dpfxa *DeployPFXArgs) error { // decodePKCS12Blob decodes a PKCS12 blob. func decodePKCS12Blob(resp *EnrollResponse) error { - // 0 + log.Println("[TRACE] Decoding certificate") // Keyfactor returns base-64 PFX (PKCS#12) or zipped certificate. Decode here. if resp.CertificateInformation.PKCS12Blob != "" { cert, err := base64.StdEncoding.DecodeString(resp.CertificateInformation.PKCS12Blob) diff --git a/v3/api/client.go b/v3/api/client.go index 1c9f3dc..1ec888a 100644 --- a/v3/api/client.go +++ b/v3/api/client.go @@ -17,6 +17,7 @@ package api import ( "bytes" "context" + "encoding/base64" "encoding/json" "errors" "fmt" @@ -25,7 +26,6 @@ import ( "net/http" "net/http/httputil" "net/url" - "os" "path" "strings" "time" @@ -115,7 +115,7 @@ func initLogger(ctx *context.Context) { }, ) } else { - log.SetOutput(os.Stdout) + log.SetOutput(io.Discard) } } @@ -183,7 +183,7 @@ func NewKeyfactorClient(cfg *auth_providers.Server, ctx *context.Context) (*Clie func logRequest(req *http.Request) error { // Read the request body if req == nil { - // 0 + log.Printf("[WARN] HTTP Request is nil") return nil } body, err := io.ReadAll(req.Body) @@ -207,20 +207,20 @@ func logRequest(req *http.Request) error { } // Convert struct to JSON - _, err = json.Marshal(requestData) + jsonData, err := json.Marshal(requestData) if err != nil { return err } // Log the JSON data - // 0 - _, err = requestToCurl(req) + log.Printf("[TRACE] HTTP Request: %s", jsonData) + curlStr, err := requestToCurl(req) if err != nil { - // 0 + log.Printf("[ERROR] Error converting request to cURL: %s", err) return nil } - // 0 - //log.Printf("[TRACE] cURL Request b64encoded: %s", base64.StdEncoding.EncodeToString([]byte(curlStr))) + log.Printf("[TRACE] cURL Request: %s", curlStr) + log.Printf("[TRACE] cURL Request b64encoded: %s", base64.StdEncoding.EncodeToString([]byte(curlStr))) return nil } @@ -271,7 +271,7 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { return nil, err } if u.Scheme != "https" { - // 0 + log.Printf("[WARN] Forcing https scheme on '%s'", u.Scheme) u.Scheme = "https" } apiPath := serverConfig.APIPath @@ -279,41 +279,42 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { apiPath = DefaultAPIPath } endpoint := fmt.Sprintf("%s/", strings.Trim(apiPath, "/")) + request.Endpoint - // 0 + log.Printf("[DEBUG] Endpoint: %s", endpoint) u.Path = path.Join(u.Path, endpoint) // Attach enroll endpoint log.Printf("[DEBUG] URL: %s", u.String()) // Set request query if request.Query != nil { - // 0 + log.Printf("[DEBUG] Setting query parameters") queryString := u.Query() for _, query := range request.Query.Query { - // 0 + log.Printf("[TRACE] Setting query parameter %s=%s", query.Elem1, query.Elem2) queryString.Set(query.Elem1, query.Elem2) } - // 0 + log.Printf("[DEBUG] Encoding query string") u.RawQuery = queryString.Encode() - // 0 - // 0 + log.Printf("[TRACE] Query string: %s", u.RawQuery) + log.Printf("[DEBUG] Replacing '+' in query string") u.RawQuery = strings.ReplaceAll(u.RawQuery, "+", "%20") - // 0 + log.Printf("[DEBUG] Query string: %s", u.RawQuery) } keyfactorPath := u.String() // Convert absolute path to string - // 0 + log.Printf("[INFO] Preparing a %s request to path '%s'", request.Method, keyfactorPath) jsonByes, mErr := json.Marshal(request.Payload) if mErr != nil { return nil, mErr } - // 0 + log.Printf("[TRACE] Request body: %s", jsonByes) + req, reqErr := http.NewRequest(request.Method, keyfactorPath, bytes.NewBuffer(jsonByes)) if reqErr != nil { - // 0 + log.Printf("[ERROR] Error creating request: %s", reqErr) return nil, reqErr } - // 0 + log.Printf("[DEBUG] Setting request headers") req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") @@ -321,9 +322,9 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { for _, headers := range request.Headers.Headers { //mask the Authorization header if strings.ToLower(headers.Elem1) == "authorization" { - // 0 + log.Printf("[TRACE] Setting header %s=********", headers.Elem1) } else { - // 0 + log.Printf("[TRACE] Setting header %s=%s", headers.Elem1, headers.Elem2) } req.Header.Set(headers.Elem1, headers.Elem2) } @@ -374,23 +375,31 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { } } case respErr != nil: - // 0 + log.Printf("[ERROR] Error sending '%s' request to '%s': %s", request.Method, request.Endpoint, respErr) return nil, respErr case resp == nil: - // 0 + log.Printf( + "[ERROR] No response from Keyfactor Command for '%s' request to '%s'", + request.Method, + request.Endpoint, + ) return nil, errors.New("no response from Keyfactor Command") } var stringMessage string - // 0 + log.Printf("[DEBUG] Response code from '%s' request to '%s': %d", request.Method, request.Endpoint, resp.StatusCode) if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent { - // 0 + log.Printf("[DEBUG] '%s' request to '%s' succeeded", request.Method, request.Endpoint) return resp, nil } else if resp.StatusCode == http.StatusNotFound { stringMessage = fmt.Sprintf( "Error %d - the requested resource was not found. Please check the request and try again.", resp.StatusCode, ) - // 0 + log.Printf( + "[ERROR] '%s' request to '%s' returned status '%d': %s", request.Method, keyfactorPath, + resp.StatusCode, + stringMessage, + ) return nil, errors.New(stringMessage) } else if resp.StatusCode == http.StatusUnauthorized { dmp, derr := httputil.DumpResponse(resp, true) @@ -408,18 +417,27 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { resp.StatusCode, "Unauthorized: Access is denied due to invalid credentials", ) - // 0 + log.Printf("[ERROR] %s", errMsg) err = errors.New(errMsg) return nil, err } else { - // 0 + log.Printf( + "[DEBUG] Attempting to decode error response body for '%s' request to '%s'", + request.Method, + request.Endpoint, + ) var errorMessage map[string]interface{} // Decode JSON body to handle issue err = json.NewDecoder(resp.Body).Decode(&errorMessage) if err != nil { _, derr := httputil.DumpResponse(resp, true) if derr != nil { - // 0 + log.Printf( + "[ERROR] Error dumping response body for '%s' request to '%s': %s", + request.Method, + request.Endpoint, + derr, + ) return nil, derr } uerr := errors.New( @@ -429,28 +447,39 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) { endpoint, ), ) - // 0 + log.Printf("[ERROR] %s", uerr) return nil, uerr } - // 0 + log.Printf( + "[DEBUG] Error response body for '%s' request to '%s': %s", + request.Method, + request.Endpoint, + errorMessage, + ) _, hasFailedOps := errorMessage["FailedOperations"] if hasFailedOps { var fOps []string - // 0 + log.Printf("[TRACE] Failed operations: %s", errorMessage["FailedOperations"]) for _, v := range errorMessage["FailedOperations"].([]interface{}) { fOps = append(fOps, fmt.Sprintf("%s", v.(map[string]interface{})["Reason"])) } fOpsStr := strings.Join(fOps, ", ") stringMessage += fmt.Sprintf("%s. %s", errorMessage["Message"], fOpsStr) - // 0 + log.Printf("[TRACE] Failed ops string: %s", stringMessage) } _, hasMsg := errorMessage["Message"] if hasMsg { - // 0 + log.Printf("[TRACE] Error message: %s", errorMessage["Message"]) stringMessage += fmt.Sprintf("%s", errorMessage["Message"]) } - // 0 + log.Printf( + "[ERROR] '%s' request to '%s' returned status '%d': %s", + request.Method, + keyfactorPath, + resp.StatusCode, + stringMessage, + ) return nil, errors.New(stringMessage) } } diff --git a/v3/api/security.go b/v3/api/security.go index 6d60d13..92de546 100644 --- a/v3/api/security.go +++ b/v3/api/security.go @@ -18,13 +18,15 @@ import ( "encoding/json" "errors" "fmt" + "log" "net/http" ) // GetSecurityIdentities hits the /Security/Identities endpoint with a GET request and returns a list of // GetSecurityIdentityResponse structs. The function takes no arguments. func (c *Client) GetSecurityIdentities() ([]GetSecurityIdentityResponse, error) { - // 0 + log.Println("[INFO] Getting Keyfactor security identity list") + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -56,7 +58,8 @@ func (c *Client) GetSecurityIdentities() ([]GetSecurityIdentityResponse, error) // CreateSecurityIdentity hits the /Security/Identities endpoint with a POST request to create a new Keyfactor security // and returns a CreateSecurityIdentityResponse struct. The function takes argument for a CreateSecurityIdentityArg struct func (c *Client) CreateSecurityIdentity(csia *CreateSecurityIdentityArg) (*CreateSecurityIdentityResponse, error) { - // 0 + log.Println("[INFO] Creating new Keyfactor security identity") + // Verify argument if csia == nil || csia.AccountName == "" { return nil, errors.New("invalid input received for security identity creation") @@ -93,7 +96,8 @@ func (c *Client) CreateSecurityIdentity(csia *CreateSecurityIdentityArg) (*Creat // DeleteSecurityIdentity takes arguments for a security identity ID, and makes an associated call to Keyfactor to // delete the identity. func (c *Client) DeleteSecurityIdentity(id int) error { - // 0 + log.Printf("[INFO] Deleting Keyfactor security identity with ID %d", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -127,7 +131,8 @@ func (c *Client) DeleteSecurityIdentity(id int) error { } func (c *Client) GetSecurityRoles() ([]GetSecurityRolesResponse, error) { - // 0 + log.Println("[INFO] Getting list of Keyfactor security roles") + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -157,7 +162,8 @@ func (c *Client) GetSecurityRoles() ([]GetSecurityRolesResponse, error) { } func (c *Client) GetSecurityRole(id interface{}) (*GetSecurityRoleResponse, error) { - // 0 + log.Printf("[INFO] Getting Keyfactor security role with ID %v", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -212,8 +218,8 @@ func (c *Client) GetSecurityRole(id interface{}) (*GetSecurityRoleResponse, erro jsonResp := &[]GetSecurityRolesResponse{} err = json.NewDecoder(resp.Body).Decode(&jsonResp) - for _, jResp := range *jsonResp { - // 0 + for i, jResp := range *jsonResp { + log.Printf("[INFO] Getting Keyfactor security role with %v ID %v", i, jResp) //convert ID from int to float64 formattedID := float64(jResp.ID) @@ -234,7 +240,8 @@ func (c *Client) GetSecurityRole(id interface{}) (*GetSecurityRoleResponse, erro // DeleteSecurityRole takes arguments for a security role ID, and makes an associated call to Keyfactor to // delete the role. func (c *Client) DeleteSecurityRole(id int) error { - // 0 + log.Printf("[INFO] Deleting Keyfactor security role with ID %d", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -270,7 +277,8 @@ func (c *Client) DeleteSecurityRole(id int) error { // CreateSecurityRole creates a new Keyfacor security role. This function takes argument for a CreateSecurityRoleArg // struct and returns a CreateSecurityRoleResponse struct. func (c *Client) CreateSecurityRole(input *CreateSecurityRoleArg) (*CreateSecurityRoleResponse, error) { - // 0 + log.Println("[INFO] Creating new Keyfactor security role") + // Verify argument if input == nil || input.Name == "" || input.Description == "" { return nil, errors.New("invalid input received for security role creation") @@ -307,7 +315,8 @@ func (c *Client) CreateSecurityRole(input *CreateSecurityRoleArg) (*CreateSecuri // UpdateSecurityRole updates the Keyfacor security role. This function takes argument for a CreateSecurityRoleArg // struct and returns a CreateSecurityRoleResponse struct. func (c *Client) UpdateSecurityRole(input *UpdateSecurityRoleArg) (*UpdateSecurityRoleResponse, error) { - // 0 + log.Printf("[INFO] Updating Keyfactor security role with ID %d", input.Id) + // Verify argument if input == nil { return nil, errors.New("update security role - argument struct is nil") diff --git a/v3/api/store.go b/v3/api/store.go index dc12b96..1e37c73 100644 --- a/v3/api/store.go +++ b/v3/api/store.go @@ -18,6 +18,7 @@ import ( "encoding/json" "errors" "fmt" + "log" "net/http" "strconv" ) @@ -31,7 +32,8 @@ import ( // - Properties : []StringTuple *Note - Method converts this array of StringTuples to a JSON string if provided // - AgentId : string func (c *Client) CreateStore(ca *CreateStoreFctArgs) (*CreateStoreResponse, error) { - // 0 + log.Println("[INFO] Creating new certificate store with Keyfactor") + // Validate that the required fields are present err := validateCreateStoreArgs(ca) if err != nil { @@ -86,7 +88,8 @@ func (c *Client) CreateStore(ca *CreateStoreFctArgs) (*CreateStoreResponse, erro // - Properties : []StringTuple *Note - Method converts this slice of StringTuples to a JSON string if provided // - AgentId : string func (c *Client) UpdateStore(ua *UpdateStoreFctArgs) (*UpdateStoreResponse, error) { - // 0 + log.Println("[INFO] Creating new certificate store with Keyfactor") + // Validate that the required fields are present err := validateUpdateStoreArgs(ua) if err != nil { @@ -447,7 +450,8 @@ func (c *Client) GetCertificateStoreByClientAndStorePath( // AddCertificateToStores takes argument for a AddCertificateToStore structure and is used to remove a configured certificate // from one or more certificate stores. func (c *Client) AddCertificateToStores(config *AddCertificateToStore) ([]string, error) { - // 0 + log.Printf("[INFO] Adding certificate with ID %d to one or more certificate stores", config.CertificateId) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ @@ -479,7 +483,8 @@ func (c *Client) AddCertificateToStores(config *AddCertificateToStore) ([]string // RemoveCertificateFromStores takes argument for a RemoveCertificateFromStore structure, and is used to remove a certificate // from one or more certificate stores. func (c *Client) RemoveCertificateFromStores(config *RemoveCertificateFromStore) ([]string, error) { - // 0 + log.Println("[INFO] Removing certificate from one or more certificate stores") + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{ diff --git a/v3/api/store_container.go b/v3/api/store_container.go index 9fa8e4f..1a7dcdf 100644 --- a/v3/api/store_container.go +++ b/v3/api/store_container.go @@ -17,12 +17,14 @@ package api import ( "encoding/json" "fmt" + "log" "strconv" ) // GetStoreContainers returns a list of store containers func (c *Client) GetStoreContainers() (*[]CertStoreContainer, error) { - // 0 + log.Println("[INFO] Listing certificate store containers.") + headers := &apiHeaders{ Headers: []StringTuple{ {"x-keyfactor-api-version", "1"}, @@ -52,7 +54,8 @@ func (c *Client) GetStoreContainers() (*[]CertStoreContainer, error) { // GetStoreContainer takes an ID and returns a single store container func (c *Client) GetStoreContainer(id interface{}) (*CertStoreContainer, error) { - // 0 + log.Printf("[INFO] Fetching certificat store containers %s.\n", id) + var endpoint string var query apiQuery var jsonResp interface{} diff --git a/v3/api/store_type.go b/v3/api/store_type.go index d27d769..94dff94 100644 --- a/v3/api/store_type.go +++ b/v3/api/store_type.go @@ -18,6 +18,7 @@ import ( "encoding/json" "errors" "fmt" + "log" ) // GetCertificateStoreType takes arguments for a certificate store type ID or name and if found will return the certificate store type @@ -140,7 +141,8 @@ func (c *Client) ListCertificateStoreTypes() (*[]CertificateStoreType, error) { // - Properties : []StringTuple *Note - Method converts this array of StringTuples to a JSON string if provided // - AgentId : string func (c *Client) CreateStoreType(ca *CertificateStoreType) (*CertificateStoreType, error) { - // 0 + log.Println("[INFO] Creating new certificate store type with Keyfactor") + // Validate that the required fields are present //err := validateCreateStoreTypeArgs(ca) //if err != nil { @@ -176,7 +178,8 @@ func (c *Client) CreateStoreType(ca *CertificateStoreType) (*CertificateStoreTyp } func (c *Client) UpdateStoreType(ca *CertificateStoreType) (*CertificateStoreType, error) { - // 0 + log.Println("[INFO] Creating new certificate store type with Keyfactor") + // Validate that the required fields are present //err := validateCreateStoreTypeArgs(ca) //if err != nil { @@ -211,7 +214,8 @@ func (c *Client) UpdateStoreType(ca *CertificateStoreType) (*CertificateStoreTyp return jsonResp, nil } func (c *Client) DeleteCertificateStoreType(id int) (*DeleteStoreType, error) { - // 0 + log.Printf("[INFO] Attempting to delete certificate store type %d", id) + // Set Keyfactor-specific headers headers := &apiHeaders{ Headers: []StringTuple{