From 323662f741e1516d702a8dadbee696755e394e65 Mon Sep 17 00:00:00 2001 From: djurybt Date: Wed, 14 Feb 2024 16:03:50 -0400 Subject: [PATCH] fix: add logging interface for abstracting logging --- api/authentication/authetication.go | 48 +++++++------ api/logging/logging.go | 93 ++++++++++++++++++++++++++ api/managed_account/managed_account.go | 38 ++++++----- api/secrets/secrets.go | 15 ++--- api/utils/validator.go | 10 +-- go.mod | 3 + go.sum | 6 ++ main.go | 40 +++++++---- 8 files changed, 188 insertions(+), 65 deletions(-) create mode 100644 api/logging/logging.go diff --git a/api/authentication/authetication.go b/api/authentication/authetication.go index 859047d..d36f036 100644 --- a/api/authentication/authetication.go +++ b/api/authentication/authetication.go @@ -7,10 +7,9 @@ import ( "encoding/json" "fmt" "go-client-library-passwordsafe/api/entities" - "go-client-library-passwordsafe/api/utils" + "go-client-library-passwordsafe/api/logging" "io" - "log" "net/http" "net/url" "time" @@ -19,17 +18,17 @@ import ( ) type AuthenticationObj struct { - ApiUrl string - clientId string - clientSecret string - httpClient *http.Client - ExponentialBackOff *backoff.ExponentialBackOff - signApinResponse entities.SignApinResponse - autenticationLogger log.Logger + ApiUrl string + clientId string + clientSecret string + httpClient *http.Client + ExponentialBackOff *backoff.ExponentialBackOff + signApinResponse entities.SignApinResponse + log logging.Logger } // Authenticate in PS API -func Authenticate(httpClient *http.Client, endpointUrl string, clientId string, clientSecret string, logger *log.Logger, maxElapsedTime int) (*AuthenticationObj, error) { +func Authenticate(httpClient *http.Client, endpointUrl string, clientId string, clientSecret string, logger logging.Logger, maxElapsedTime int) (*AuthenticationObj, error) { backoffDefinition := backoff.NewExponentialBackOff() backoffDefinition.InitialInterval = 1 * time.Second @@ -40,12 +39,12 @@ func Authenticate(httpClient *http.Client, endpointUrl string, clientId string, var client = httpClient authenticationObj := &AuthenticationObj{ - ApiUrl: endpointUrl, - httpClient: client, - clientId: clientId, - clientSecret: clientSecret, - ExponentialBackOff: backoffDefinition, - autenticationLogger: *logger, + ApiUrl: endpointUrl, + httpClient: client, + clientId: clientId, + clientSecret: clientSecret, + ExponentialBackOff: backoffDefinition, + log: logger, } return authenticationObj, nil @@ -104,7 +103,7 @@ func (c *AuthenticationObj) GetToken(endpointUrl string, clientId string, client err = json.Unmarshal([]byte(responseString), &data) if err != nil { - utils.Logging("ERROR", err.Error(), c.autenticationLogger) + c.log.Error(err.Error()) return "", err } @@ -150,7 +149,7 @@ func (c *AuthenticationObj) SignAppin(endpointUrl string, accessToken string) (e err = json.Unmarshal(bodyBytes, &userObject) if err != nil { - utils.Logging("ERROR", err.Error(), c.autenticationLogger) + c.log.Error(err.Error()) return entities.SignApinResponse{}, err } @@ -160,8 +159,7 @@ func (c *AuthenticationObj) SignAppin(endpointUrl string, accessToken string) (e // SignOut signs out Secret Safe API. // Warn: should only be called one time for all data sources. func (c *AuthenticationObj) SignOut(url string) error { - - utils.Logging("DEBUG", url, c.autenticationLogger) + c.log.Debug(url) var technicalError error var businessError error @@ -172,7 +170,7 @@ func (c *AuthenticationObj) SignOut(url string) error { }, c.ExponentialBackOff) if businessError != nil { - utils.Logging("ERROR", businessError.Error(), c.autenticationLogger) + c.log.Error(businessError.Error()) return businessError } @@ -184,12 +182,12 @@ func (c *AuthenticationObj) CallSecretSafeAPI(url string, httpMethod string, bod response, technicalError, businessError, scode := c.HttpRequest(url, httpMethod, body, accesToken) if technicalError != nil { messageLog := fmt.Sprintf("Error in %v %v \n", method, technicalError) - utils.Logging("ERROR", messageLog, c.autenticationLogger) + c.log.Error(messageLog) } if businessError != nil { messageLog := fmt.Sprintf("Error in %v: %v \n", method, businessError) - utils.Logging("ERROR", messageLog, c.autenticationLogger) + c.log.Error(messageLog) } return response, technicalError, businessError, scode } @@ -211,13 +209,13 @@ func (c *AuthenticationObj) HttpRequest(url string, method string, body bytes.Bu resp, err := c.httpClient.Do(req) if err != nil { - utils.Logging("ERROR", err.Error(), c.autenticationLogger) + c.log.Error(err.Error()) return nil, err, nil, 0 } if resp.StatusCode >= http.StatusInternalServerError || resp.StatusCode == http.StatusRequestTimeout { err = fmt.Errorf("Error %v: StatusCode: %v, %v, %v", method, scode, err, body) - utils.Logging("ERROR", err.Error(), c.autenticationLogger) + c.log.Error(err.Error()) return nil, err, nil, resp.StatusCode } diff --git a/api/logging/logging.go b/api/logging/logging.go new file mode 100644 index 0000000..ee8b7fd --- /dev/null +++ b/api/logging/logging.go @@ -0,0 +1,93 @@ +package logging + +import ( + "fmt" + "log" + + "github.com/go-logr/logr" + "go.uber.org/zap" +) + +// Logger is an interface that defines the logging methods +type Logger interface { + Info(msg string) + Error(msg string) + Debug(msg string) +} + +// ZapLogger is a struct that implements the Logger interface using zap +type ZapLogger struct { + logger *zap.Logger +} + +// Info logs a message at info level +func (z *ZapLogger) Info(msg string) { + z.logger.Info(msg) +} + +// Error logs a message at error level +func (z *ZapLogger) Error(msg string) { + z.logger.Error(msg) +} + +// Error logs a message at error level +func (z *ZapLogger) Debug(msg string) { + z.logger.Debug(msg) +} + +// logr.logger +type LogrLogger struct { + logger *logr.Logger +} + +// Info logs a message at info level +func (r *LogrLogger) Info(msg string) { + r.logger.Info(msg) +} + +// Error logs a message at error level +func (r *LogrLogger) Error(msg string) { + r.logger.Error(fmt.Errorf("an error"), msg) +} + +func (r *LogrLogger) Debug(msg string) { + r.logger.Info(msg) +} + +// log.logger +type LogLogger struct { + logger *log.Logger +} + +// Info logs a message at info level +func (l *LogLogger) Info(msg string) { + prefix := fmt.Sprintf("%v :", "Info") + l.logger.SetPrefix(prefix) + l.logger.Println(msg) +} + +// Error logs a message at error level +func (l *LogLogger) Error(msg string) { + prefix := fmt.Sprintf("%v :", "Error") + l.logger.SetPrefix(prefix) + l.logger.Println(msg) +} + +func (l *LogLogger) Debug(msg string) { + prefix := fmt.Sprintf("%v :", "Debug") + l.logger.SetPrefix(prefix) + l.logger.Println(msg) +} + +// NewZapLogger creates a new ZapLogger with the given zap.Logger +func NewZapLogger(logger *zap.Logger) *ZapLogger { + return &ZapLogger{logger: logger} +} + +func NewLogrLogger(logger *logr.Logger) *LogrLogger { + return &LogrLogger{logger: logger} +} + +func NewLogLogger(logger *log.Logger) *LogLogger { + return &LogLogger{logger: logger} +} diff --git a/api/managed_account/managed_account.go b/api/managed_account/managed_account.go index d28d399..b4183d2 100644 --- a/api/managed_account/managed_account.go +++ b/api/managed_account/managed_account.go @@ -10,9 +10,8 @@ import ( "fmt" "go-client-library-passwordsafe/api/authentication" "go-client-library-passwordsafe/api/entities" - "go-client-library-passwordsafe/api/utils" + "go-client-library-passwordsafe/api/logging" "io" - "log" "strconv" "strings" @@ -20,12 +19,12 @@ import ( ) type ManagedAccountstObj struct { - managedAccocuntsLogger log.Logger + managedAccocuntsLogger logging.Logger authenticationObj authentication.AuthenticationObj } // NewManagedAccountObj creates managed account obj -func NewManagedAccountObj(authentication authentication.AuthenticationObj, logger log.Logger) (*ManagedAccountstObj, error) { +func NewManagedAccountObj(authentication authentication.AuthenticationObj, logger logging.Logger) (*ManagedAccountstObj, error) { managedAccounObj := &ManagedAccountstObj{ managedAccocuntsLogger: logger, authenticationObj: authentication, @@ -74,34 +73,39 @@ func (managedAccounObj *ManagedAccountstObj) ManageAccountFlow(secretsToRetrieve if systemName == "" { err = errors.New("Please use a valid system_name value") - utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Error(err.Error()) + //utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) return nil, err } if accountName == "" { err = errors.New("Please use a valid system_name value") - utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Error(err.Error()) + //utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) return nil, err } ManagedAccountGetUrl := managedAccounObj.RequestPath(paths["ManagedAccountGetPath"]) managedAccount, err := managedAccounObj.ManagedAccountGet(systemName, accountName, ManagedAccountGetUrl) if err != nil { - utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Error(err.Error()) + //utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) return nil, err } ManagedAccountCreateRequestUrl := managedAccounObj.RequestPath(paths["ManagedAccountCreateRequestPath"]) requestId, err := managedAccounObj.ManagedAccountCreateRequest(managedAccount.SystemId, managedAccount.AccountId, ManagedAccountCreateRequestUrl) if err != nil { - utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Error(err.Error()) + //utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) return nil, err } CredentialByRequestIdUrl := managedAccounObj.RequestPath(fmt.Sprintf(paths["CredentialByRequestIdPath"], requestId)) secret, err := managedAccounObj.CredentialByRequestId(requestId, CredentialByRequestIdUrl) if err != nil { - utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Error(err.Error()) + //utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) return nil, err } @@ -110,7 +114,8 @@ func (managedAccounObj *ManagedAccountstObj) ManageAccountFlow(secretsToRetrieve _, err = managedAccounObj.ManagedAccountRequestCheckIn(requestId, ManagedAccountRequestCheckInUrl) if err != nil { - utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Error(err.Error()) + //utils.Logging("ERROR", err.Error(), managedAccounObj.managedAccocuntsLogger) return nil, err } @@ -123,7 +128,8 @@ func (managedAccounObj *ManagedAccountstObj) ManageAccountFlow(secretsToRetrieve func (managedAccounObj *ManagedAccountstObj) ManagedAccountGet(systemName string, accountName string, url string) (entities.ManagedAccount, error) { messageLog := fmt.Sprintf("%v %v", "GET", url) - utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Debug(messageLog) + //utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) var body io.ReadCloser var technicalError error @@ -162,7 +168,8 @@ func (managedAccounObj *ManagedAccountstObj) ManagedAccountGet(systemName string // ManagedAccountCreateRequest calls Secret Safe API Requests enpoint and returns a request Id as string. func (managedAccounObj *ManagedAccountstObj) ManagedAccountCreateRequest(systemName int, accountName int, url string) (string, error) { messageLog := fmt.Sprintf("%v %v", "POST", url) - utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Debug(messageLog) + //utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) data := fmt.Sprintf(`{"SystemID":%v, "AccountID":%v, "DurationMinutes":5, "Reason":"Tesr", "ConflictOption": "reuse"}`, systemName, accountName) b := bytes.NewBufferString(data) @@ -200,8 +207,8 @@ func (managedAccounObj *ManagedAccountstObj) ManagedAccountCreateRequest(systemN // enpoint and returns secret value by request Id. func (managedAccounObj *ManagedAccountstObj) CredentialByRequestId(requestId string, url string) (string, error) { messageLog := fmt.Sprintf("%v %v", "GET", url) - - utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Debug(messageLog) + //utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) var body io.ReadCloser var technicalError error @@ -235,7 +242,8 @@ func (managedAccounObj *ManagedAccountstObj) CredentialByRequestId(requestId str // ManagedAccountRequestCheckIn calls Secret Safe API "Requests//checkin enpoint. func (managedAccounObj *ManagedAccountstObj) ManagedAccountRequestCheckIn(requestId string, url string) (string, error) { messageLog := fmt.Sprintf("%v %v", "PUT", url) - utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) + managedAccounObj.managedAccocuntsLogger.Debug(messageLog) + //utils.Logging("DEBUG", messageLog, managedAccounObj.managedAccocuntsLogger) data := "{}" b := bytes.NewBufferString(data) diff --git a/api/secrets/secrets.go b/api/secrets/secrets.go index 9aef7aa..bf52438 100644 --- a/api/secrets/secrets.go +++ b/api/secrets/secrets.go @@ -9,9 +9,8 @@ import ( "fmt" "go-client-library-passwordsafe/api/authentication" "go-client-library-passwordsafe/api/entities" - "go-client-library-passwordsafe/api/utils" + "go-client-library-passwordsafe/api/logging" "io" - "log" "net/url" "strings" @@ -19,14 +18,14 @@ import ( ) type SecretObj struct { - secretLogger log.Logger + log logging.Logger authenticationObj authentication.AuthenticationObj } // NewSecretObj creates secret obj -func NewSecretObj(authentication authentication.AuthenticationObj, logger log.Logger) (*SecretObj, error) { +func NewSecretObj(authentication authentication.AuthenticationObj, logger logging.Logger) (*SecretObj, error) { secretObj := &SecretObj{ - secretLogger: logger, + log: logger, authenticationObj: authentication, } return secretObj, nil @@ -66,7 +65,7 @@ func (secretObj *SecretObj) GetSecretFlow(secretsToRetrieve []string, separator if strings.ToUpper(secret.SecretType) == "FILE" { fileSecretContent, err := secretObj.SecretGetFileSecret(secret.Id, "secrets-safe/secrets/") if err != nil { - utils.Logging("ERROR", err.Error(), secretObj.secretLogger) + secretObj.log.Error(err.Error()) return nil, err } @@ -82,7 +81,7 @@ func (secretObj *SecretObj) GetSecretFlow(secretsToRetrieve []string, separator // SecretGetSecretByPath returns secret object for a specific path, title. func (secretObj *SecretObj) SecretGetSecretByPath(secretPath string, secretTitle string, separator string, endpointPath string) (entities.Secret, error) { messageLog := fmt.Sprintf("%v %v", "GET", endpointPath) - utils.Logging("DEBUG", messageLog, secretObj.secretLogger) + secretObj.log.Debug(messageLog) var body io.ReadCloser var technicalError error @@ -134,7 +133,7 @@ func (secretObj *SecretObj) SecretGetSecretByPath(secretPath string, secretTitle // and returns file secret value. func (secretObj *SecretObj) SecretGetFileSecret(secretId string, endpointPath string) (string, error) { messageLog := fmt.Sprintf("%v %v", "GET", endpointPath) - utils.Logging("DEBUG", messageLog, secretObj.secretLogger) + secretObj.log.Debug(messageLog) var body io.ReadCloser var technicalError error diff --git a/api/utils/validator.go b/api/utils/validator.go index 7996fb7..0850ddb 100644 --- a/api/utils/validator.go +++ b/api/utils/validator.go @@ -4,7 +4,7 @@ package utils import ( "errors" - "log" + logging "go-client-library-passwordsafe/api/logging" validator "github.com/go-playground/validator/v10" ) @@ -21,7 +21,7 @@ type UserInputValidaton struct { var validate *validator.Validate // ValidateInputs validate inputs -func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientTimeOutinSeconds int, separator string, verifyCa bool, logger *log.Logger, certificate string, certificate_key string) error { +func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientTimeOutinSeconds int, separator string, verifyCa bool, logger logging.Logger, certificate string, certificate_key string) error { validate = validator.New(validator.WithRequiredStructEnabled()) @@ -36,7 +36,8 @@ func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientT err := validate.Struct(userInput) if err != nil { - Logging("ERROR", err.Error(), *logger) + logger.Error(err.Error()) + //Logging("ERROR", err.Error(), *logger) return err } @@ -52,6 +53,7 @@ func ValidateInputs(clientId string, clientSecret string, apiUrl string, clientT } } - Logging("DEBUG", "Validation passed!", *logger) + logger.Debug("Validation passed!") + //Logging("DEBUG", "Validation passed!", *logger) return nil } diff --git a/go.mod b/go.mod index e4efd20..1863417 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,13 @@ go 1.20 require ( github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/go-logr/logr v1.4.1 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.18.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect + go.uber.org/multierr v1.10.0 // indirect + go.uber.org/zap v1.26.0 // indirect golang.org/x/crypto v0.19.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect diff --git a/go.sum b/go.sum index a683cfc..eeee033 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqy github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -10,6 +12,10 @@ github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtP github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= diff --git a/main.go b/main.go index ba31ea8..e550eab 100644 --- a/main.go +++ b/main.go @@ -3,15 +3,16 @@ package main import ( "fmt" "go-client-library-passwordsafe/api/authentication" + logging "go-client-library-passwordsafe/api/logging" managed_accounts "go-client-library-passwordsafe/api/managed_account" secrets "go-client-library-passwordsafe/api/secrets" "go-client-library-passwordsafe/api/utils" - "log" - "os" "strings" + + "go.uber.org/zap" ) -var logger = log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime) +//var logger = log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime) // main funtion func main() { @@ -19,21 +20,30 @@ func main() { //logFile, _ := os.Create("ProviderLogs.log") //logger.SetOutput(logFile) + // create a zap logger + //logger, _ := zap.NewProduction() + logger, _ := zap.NewDevelopment() + defer logger.Sync() + + // create a zap logger wrapper + zapLogger := logging.NewZapLogger(logger) + apiUrl := "https://jury2310.ps-dev.beyondtrustcloud.com:443/BeyondTrust/api/public/v3/" clientId := "" clientSecret := "" separator := "/" certificate := "" certificate_key := "" - clientTimeOutinSeconds := 5 + clientTimeOutinSeconds := 30 verifyCa := true maxElapsedTime := 15 // validate inputs - errors_in_inputs := utils.ValidateInputs(clientId, clientSecret, apiUrl, clientTimeOutinSeconds, separator, verifyCa, logger, certificate, certificate_key) + errors_in_inputs := utils.ValidateInputs(clientId, clientSecret, apiUrl, clientTimeOutinSeconds, separator, verifyCa, zapLogger, certificate, certificate_key) if errors_in_inputs != nil { - utils.Logging("ERROR", errors_in_inputs.Error(), *logger) + + //utils.Logging("ERROR", errors_in_inputs.Error(), *logger) return } @@ -41,7 +51,7 @@ func main() { httpClient, _ := utils.GetHttpClient(clientTimeOutinSeconds, verifyCa, certificate, certificate_key) // instantiating authenticate obj, injecting httpClient object - authenticate, _ := authentication.Authenticate(httpClient, apiUrl, clientId, clientSecret, logger, maxElapsedTime) + authenticate, _ := authentication.Authenticate(httpClient, apiUrl, clientId, clientSecret, zapLogger, maxElapsedTime) // authenticating in PS API _, err := authenticate.GetPasswordSafeAuthentication() @@ -50,30 +60,34 @@ func main() { } // instantiating secret obj - secretObj, _ := secrets.NewSecretObj(*authenticate, *logger) + secretObj, _ := secrets.NewSecretObj(*authenticate, zapLogger) // getting secrets secretList := strings.Split("oauthgrp/text2,oauthgrp/text1", ",") gotSecrets, _ := secretObj.GetSecrets(secretList, separator) - utils.Logging("DEBUG", fmt.Sprintf("%v", gotSecrets), *logger) + zapLogger.Info(fmt.Sprintf("%v", gotSecrets)) + //utils.Logging("DEBUG", fmt.Sprintf("%v", gotSecrets), zapLogger) // getting secrets secretList = strings.Split("oauthgrp/text2", ",") gotSecret, _ := secretObj.GetSecret(secretList, separator) - utils.Logging("DEBUG", fmt.Sprintf("%v", gotSecret), *logger) + zapLogger.Info(fmt.Sprintf("%v", gotSecret)) + //utils.Logging("DEBUG", fmt.Sprintf("%v", gotSecret), *logger) // instantiating managed account obj - manageAccountObj, _ := managed_accounts.NewManagedAccountObj(*authenticate, *logger) + manageAccountObj, _ := managed_accounts.NewManagedAccountObj(*authenticate, zapLogger) // getting managed accounts managedAccountList := strings.Split("system01/managed_account01,system02/managed_account01", ",") gotManagedAccounts, _ := manageAccountObj.GetSecrets(managedAccountList, separator) - utils.Logging("DEBUG", fmt.Sprintf("%v", gotManagedAccounts), *logger) + zapLogger.Info(fmt.Sprintf("%v", gotManagedAccounts)) + //utils.Logging("DEBUG", fmt.Sprintf("%v", gotManagedAccounts), *logger) // getting single managed account managedAccountList = []string{} gotManagedAccount, _ := manageAccountObj.GetSecret(append(managedAccountList, "system01/managed_account01"), separator) - utils.Logging("DEBUG", fmt.Sprintf("%v", gotManagedAccount), *logger) + zapLogger.Info(fmt.Sprintf("%v", gotManagedAccount)) + //utils.Logging("DEBUG", fmt.Sprintf("%v", gotManagedAccount), *logger) // signing out authenticate.SignOut(fmt.Sprintf("%v%v", authenticate.ApiUrl, "Auth/Signout"))