From 07e03ceea1cc780a10ddf13807db3fdd6856e37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?France=CC=81=20Wilke?= <francewilke@gmail.com> Date: Thu, 31 Aug 2023 12:43:34 +0200 Subject: [PATCH] Cleanup logs --- cognito/cognito.go | 194 ----------------------------- cognito/words.go | 104 ---------------- go.mod | 5 +- go.sum | 8 +- handler_utils/cron.go | 2 - logs/database_logs.go | 38 ++++++ logs/logs.go | 45 +++++-- opensearch/document_store.go | 7 +- opensearch/time_series.go | 12 +- redis/redis.go | 1 - responses/responses.go | 4 - secrets_manager/secrets_manager.go | 4 - sqs/sqs.go | 11 +- 13 files changed, 92 insertions(+), 343 deletions(-) delete mode 100644 cognito/cognito.go delete mode 100644 cognito/words.go create mode 100644 logs/database_logs.go diff --git a/cognito/cognito.go b/cognito/cognito.go deleted file mode 100644 index 3df6c2d..0000000 --- a/cognito/cognito.go +++ /dev/null @@ -1,194 +0,0 @@ -package cognito - -import ( - "fmt" - "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors" - "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils" - "math/rand" - "strings" - - "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs" - - "github.com/aws/aws-lambda-go/events" - "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" -) - -var CognitoService *cognitoidentityprovider.CognitoIdentityProvider - -// ------------------------------------------------------------------------------------------------ -// Groups -// ------------------------------------------------------------------------------------------------ - -func AddCognitoUserToGroup(username string, pool string, group string) error { - groupInput := cognitoidentityprovider.AdminAddUserToGroupInput{ - GroupName: &group, - UserPoolId: &pool, - Username: &username, - } - groupOutput, err := CognitoService.AdminAddUserToGroup(&groupInput) - logs.Info("groupOutput", groupOutput) - return err -} - -func RemoveCognitoUserFromGroup(username string, pool string, group string) error { - groupInput := cognitoidentityprovider.AdminRemoveUserFromGroupInput{ - GroupName: &group, - UserPoolId: &pool, - Username: &username, - } - groupOutput, err := CognitoService.AdminRemoveUserFromGroup(&groupInput) - logs.Info("groupOutput", groupOutput) - return err -} - -// ------------------------------------------------------------------------------------------------ -// Users -// ------------------------------------------------------------------------------------------------ - -func GetCognitoUser(pool string, username string) (*cognitoidentityprovider.AdminGetUserOutput, error) { - userInput := cognitoidentityprovider.AdminGetUserInput{ - UserPoolId: &pool, - Username: &username, - } - - userOutput, err := CognitoService.AdminGetUser(&userInput) - if err != nil { - return nil, err - } - return userOutput, nil -} - -// Deletes a user from its cognito user pool -func DeleteCognitoUser(userPoolId string, username string) error { - input := cognitoidentityprovider.AdminDeleteUserInput{ - UserPoolId: &userPoolId, - Username: &username, - } - output, err := CognitoService.AdminDeleteUser(&input) - logs.Info("output", output) - return err -} - -func ResetUserPassword(pool string, username string) (*cognitoidentityprovider.AdminResetUserPasswordOutput, error) { - input := cognitoidentityprovider.AdminResetUserPasswordInput{ - UserPoolId: &pool, - Username: &username, - } - output, err := CognitoService.AdminResetUserPassword(&input) - logs.Info("output", output) - return output, err -} - -func SetUserPassword(pool string, username string, password string) (*cognitoidentityprovider.AdminSetUserPasswordOutput, error) { - setPermanently := true - input := cognitoidentityprovider.AdminSetUserPasswordInput{ - UserPoolId: &pool, - Username: &username, - Password: &password, - Permanent: &setPermanently, - } - output, err := CognitoService.AdminSetUserPassword(&input) - logs.Info("output", output) - return output, err -} - -func confirmForgotPassword(appClientID string, username string, password string, confirmationCode string) (*cognitoidentityprovider.ConfirmForgotPasswordOutput, error) { - input := cognitoidentityprovider.ConfirmForgotPasswordInput{ - ClientId: &appClientID, - ConfirmationCode: &confirmationCode, - Password: &password, - Username: &username, - } - output, err := CognitoService.ConfirmForgotPassword(&input) - logs.Info("output", output) - return output, err -} - -func confirmPasswordReset(appClientID string, username string, password string, initiateAuthOutput *cognitoidentityprovider.InitiateAuthOutput) (*cognitoidentityprovider.RespondToAuthChallengeOutput, error) { - // Respond to the Auth challenge to change the user's password - authChallengeParameters := map[string]*string{ - "USERNAME": utils.ValueToPointer(username), - "NEW_PASSWORD": utils.ValueToPointer(password), - } - respondToAuthChallengeInput := cognitoidentityprovider.RespondToAuthChallengeInput{ - ChallengeName: initiateAuthOutput.ChallengeName, - ChallengeResponses: authChallengeParameters, - ClientId: &appClientID, - Session: initiateAuthOutput.Session, - } - output, err := CognitoService.RespondToAuthChallenge(&respondToAuthChallengeInput) - logs.Info("output", output) - return output, err -} - -// ConfirmPasswordReset initiates a Cognito auth for the user, and based on the output either updates the user's password, -// or performs a forgot password confirmation. -func ConfirmPasswordReset(appClientID string, username string, password string, confirmationCode string) (interface{}, error) { - // Initiate an auth for the user to see if a password reset or - authParameters := map[string]*string{ - "USERNAME": utils.ValueToPointer(username), - "PASSWORD": utils.ValueToPointer(confirmationCode), - } - initiateAuthInput := cognitoidentityprovider.InitiateAuthInput{ - AuthFlow: utils.ValueToPointer(cognitoidentityprovider.ExplicitAuthFlowsTypeUserPasswordAuth), - AuthParameters: authParameters, - ClientId: &appClientID, - } - res, err := CognitoService.InitiateAuth(&initiateAuthInput) - if err != nil { - if errors.AWSErrorExceptionCode(err) == cognitoidentityprovider.ErrCodePasswordResetRequiredException { - // Not a user verification - perform forgot password confirmation - return confirmForgotPassword(appClientID, username, password, confirmationCode) - } - return nil, err - } - if utils.PointerToValue(res.ChallengeName) == cognitoidentityprovider.ChallengeNameTypeNewPasswordRequired { - return confirmPasswordReset(appClientID, username, password, res) - } - - return nil, errors.Error("User state not correct for confirmation. Please contact support.") -} - -// FOR API LOGS - -func DetermineAuthType(identity events.APIGatewayRequestIdentity) *string { - result := "cognito" - if identity.CognitoAuthenticationType == "" { - result = "iam" - } - - return &result -} - -func GetAuthUsername(identity events.APIGatewayRequestIdentity) string { - if identity.CognitoAuthenticationProvider != "" { - split := strings.Split(identity.CognitoAuthenticationProvider, ":") - return split[len(split)-1] - } - - // IAM - split := strings.Split(identity.UserArn, ":user/") - return split[len(split)-1] -} - -// Create a pseudorandom password consisting of two three-letter words and two digits -func RandomPassword() string { - i := rand.Intn(100) - var j int - for { - j = rand.Intn(100) - if j != i { - break - } - } - return fmt.Sprintf("%s%s%s", words[i], words[j], RandomDigitString(2)) -} - -// Create a pseudorandom string of digits (0-9) with specified length -func RandomDigitString(len int) string { - var str strings.Builder - for i := 0; i < len; i++ { - fmt.Fprintf(&str, "%v", rand.Intn(10)) - } - return str.String() -} diff --git a/cognito/words.go b/cognito/words.go deleted file mode 100644 index 72c46fb..0000000 --- a/cognito/words.go +++ /dev/null @@ -1,104 +0,0 @@ -package cognito - -var words = []string{ - "act", - "add", - "age", - "air", - "ant", - "ark", - "arm", - "art", - "ash", - "bad", - "bag", - "bar", - "bat", - "bay", - "bed", - "bee", - "big", - "box", - "bus", - "bye", - "can", - "car", - "cat", - "con", - "cow", - "cup", - "day", - "dog", - "ear", - "end", - "eye", - "far", - "fly", - "fox", - "fry", - "fun", - "gap", - "gym", - "hat", - "hip", - "hop", - "ice", - "ink", - "jam", - "jar", - "joy", - "key", - "kit", - "lab", - "law", - "log", - "low", - "man", - "max", - "may", - "net", - "nut", - "oil", - "one", - "out", - "owl", - "own", - "pen", - "pet", - "pie", - "pig", - "pin", - "pro", - "ram", - "rap", - "ray", - "red", - "row", - "sea", - "see", - "sew", - "sit", - "six", - "sky", - "son", - "spy", - "tan", - "tax", - "tea", - "ted", - "tee", - "ten", - "the", - "tin", - "toe", - "top", - "toy", - "tub", - "two", - "way", - "wig", - "yes", - "you", - "zip", - "zoo", -} diff --git a/go.mod b/go.mod index aca98a3..4b52692 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/r3labs/diff/v2 v2.14.2 github.com/sirupsen/logrus v1.8.1 github.com/thoas/go-funk v0.9.1 + github.com/uptrace/bun v1.1.14 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 golang.org/x/text v0.4.0 ) @@ -37,11 +38,11 @@ require ( github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect github.com/vmihailenco/bufpool v0.1.11 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect - github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect + github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser v0.1.2 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect golang.org/x/net v0.1.0 // indirect - golang.org/x/sys v0.1.0 // indirect + golang.org/x/sys v0.8.0 // indirect google.golang.org/appengine v1.6.6 // indirect google.golang.org/protobuf v1.26.0 // indirect mellium.im/sasl v0.2.1 // indirect diff --git a/go.sum b/go.sum index f9f519c..f38fffc 100644 --- a/go.sum +++ b/go.sum @@ -153,13 +153,16 @@ github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs= +github.com/uptrace/bun v1.1.14 h1:S5vvNnjEynJ0CvnrBOD7MIRW7q/WbtvFXrdfy0lddAM= +github.com/uptrace/bun v1.1.14/go.mod h1:RHk6DrIisO62dv10pUOJCz5MphXThuOTpVNYEYv7NI8= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94= github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/vmihailenco/msgpack/v5 v5.3.4 h1:qMKAwOV+meBw2Y8k9cVwAy7qErtYCwBzZ2ellBfvnqc= github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= +github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc= github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= @@ -219,8 +222,9 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/handler_utils/cron.go b/handler_utils/cron.go index 78fcc08..933cf9e 100644 --- a/handler_utils/cron.go +++ b/handler_utils/cron.go @@ -2,7 +2,6 @@ package handler_utils import ( "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors" - "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs" ) // ValidateCronHandlers checks that all handlers are correctly defined using one of the supported handler types @@ -18,6 +17,5 @@ func ValidateCronHandlers(handlers map[string]func() error) (map[string]func() e } countHandler++ } - logs.Info("Checked %d handlers\n", countHandler) return handlers, nil } diff --git a/logs/database_logs.go b/logs/database_logs.go new file mode 100644 index 0000000..ea44f57 --- /dev/null +++ b/logs/database_logs.go @@ -0,0 +1,38 @@ +package logs + +import ( + "context" + "github.com/uptrace/bun" + "strings" + "time" +) + +type QueryHook struct { + Debug bool +} + +func (d QueryHook) BeforeQuery(ctx context.Context, _ *bun.QueryEvent) context.Context { + return ctx +} + +func (d QueryHook) AfterQuery(_ context.Context, event *bun.QueryEvent) { + sqlQuery := event.Query + + queryDuration := time.Now().Sub(event.StartTime) + + queryPrefixesToIgnore := []string{"SELECT", "BEGIN", "COMMIT"} + shouldLogQuery := !strings.Contains(sqlQuery, "api_key") + if shouldLogQuery { + for _, prefixToIgnore := range queryPrefixesToIgnore { + if strings.HasPrefix(sqlQuery, prefixToIgnore) { + shouldLogQuery = false + break + } + } + } + + if d.Debug || shouldLogQuery { + InfoWithFields(map[string]interface{}{"sql`": sqlQuery, "t": queryDuration.String()}, "") + } + return +} diff --git a/logs/logs.go b/logs/logs.go index 8be20d9..637b7b4 100644 --- a/logs/logs.go +++ b/logs/logs.go @@ -219,14 +219,43 @@ func LogShipmentID(id int64) { }, "Current-shipment-ID") } -func LogRequestInfo(req events.APIGatewayProxyRequest) { - InfoWithFields(map[string]interface{}{ - "http_method": req.HTTPMethod, - "path": req.Path, - "api_gateway_request_id": req.RequestContext.RequestID, - "user_cognito_auth_provider": req.RequestContext.Identity.CognitoAuthenticationProvider, - "user_arn": req.RequestContext.Identity.UserArn, - }, "Request Info start") +func LogRequestInfo(req events.APIGatewayProxyRequest, extraFields ...map[string]interface{}) { + fields := map[string]interface{}{ + "path": req.Path, + "method": req.HTTPMethod, + "body": req.Body, + "query": req.QueryStringParameters, + } + + if req.Headers["client-version"] != "" { + fields["client_version"] = req.Headers["client-version"] + } + + if extraFields != nil { + for i := range extraFields { + for k, v := range extraFields[i] { + fields[k] = v + } + } + } + + InfoWithFields(fields, "Req") +} + +func LogResponseInfo(req events.APIGatewayProxyRequest, res events.APIGatewayProxyResponse, err error) { + fields := map[string]interface{}{ + "status_code": res.StatusCode, + } + + if err != nil { + fields["error"] = err + } + + if req.HTTPMethod == http.MethodPost || req.HTTPMethod == http.MethodPatch || req.HTTPMethod == http.MethodPut { + fields["body"] = res.Body + } + + InfoWithFields(fields, "Res") } func LogApiAudit(fields log.Fields) { diff --git a/opensearch/document_store.go b/opensearch/document_store.go index 542a4af..84bb977 100644 --- a/opensearch/document_store.go +++ b/opensearch/document_store.go @@ -84,7 +84,6 @@ func (w *Writer) NewDocumentStore(name string, tmpl interface{}) (DocumentStore, if err != nil { return ds, errors.Wrapf(err, "failed to marshal index mappings") } - logs.Info("%s Index Mappings: %s", structType, string(ds.jsonMappings)) w.documentStoreByName[name] = ds return ds, nil @@ -146,10 +145,8 @@ func (ds *DocumentStore) Write(id string, data interface{}) error { } ds.created = true } - if indexResponse, err := ds.w.Write(indexName, id, data); err != nil { + if _, err := ds.w.Write(indexName, id, data); err != nil { return err - } else { - logs.Info("IndexResponse: %+v", indexResponse) } return nil } @@ -204,7 +201,6 @@ func (ds *DocumentStore) Search(query Query, limit int64) (res *SearchResponseHi } bodyData, _ := ioutil.ReadAll(searchResponse.Body) - logs.Info("Response Body: %s", string(bodyData)) var response SearchResponseBody err = json.Unmarshal(bodyData, &response) @@ -240,7 +236,6 @@ func (ds *DocumentStore) Get(id string) (res *GetResponseBody, err error) { } bodyData, _ := ioutil.ReadAll(getResponse.Body) - logs.Info("Get Response Body: %s", string(bodyData)) var response GetResponseBody err = json.Unmarshal(bodyData, &response) diff --git a/opensearch/time_series.go b/opensearch/time_series.go index c2cff48..cf50e69 100644 --- a/opensearch/time_series.go +++ b/opensearch/time_series.go @@ -101,7 +101,6 @@ func (w *Writer) NewTimeSeries(name string, tmpl interface{}) (TimeSeries, error if err != nil { return ts, errors.Wrapf(err, "failed to marshal index mappings") } - logs.Info("%s Index Mappings: %s", structType, string(ts.jsonMappings)) w.timeSeriesByName[name] = ts return ts, nil @@ -287,10 +286,8 @@ func (ts *TimeSeries) Write(startTime, endTime time.Time, data interface{}) erro EndTime: endTime, DurationMs: endTime.Sub(startTime).Milliseconds(), })) - if indexResponse, err := ts.w.Write(indexName, "", x.Elem().Interface()); err != nil { + if _, err := ts.w.Write(indexName, "", x.Elem().Interface()); err != nil { return err - } else { - logs.Info("IndexResponse: %+v", indexResponse) } return nil @@ -335,13 +332,12 @@ func (ts *TimeSeries) DelOldTimeSeries(olderThanDays int) ([]string, error) { timeThreshold = timeThreshold.Add(-time.Hour * 24 * time.Duration(olderThanDays)) // = N days before that indicesToDelete := []string{} - for dailyIndexName, dailyIndexInfo := range indices { + for dailyIndexName, _ := range indices { dateStr := dailyIndexName[len(ts.name)+1:] if date, err := time.ParseInLocation("20060102", dateStr, t0.Location()); err != nil { logs.Info("Ignore index(%s) with invalid date(%s)", dailyIndexName, dateStr) } else { if date.Before(timeThreshold) { - logs.Info("Deleting index(%s).uuid(%s) older than %s days...", dailyIndexName, dailyIndexInfo.Settings.Index.UUID, timeThreshold) indicesToDelete = append(indicesToDelete, dailyIndexName) } } @@ -351,7 +347,6 @@ func (ts *TimeSeries) DelOldTimeSeries(olderThanDays int) ([]string, error) { if err != nil { return indicesToDelete, errors.Wrapf(err, "failed to delete indices(%s)", indicesToDelete) } - logs.Info("Deleted %d daily indices(%s) older than %d days", len(indicesToDelete), indicesToDelete, olderThanDays) } return indicesToDelete, nil } @@ -417,7 +412,6 @@ func (ts *TimeSeries) Search(query Query, sort []map[string]string, limit int64, } jsonBody, _ := json.Marshal(body) - logs.Info("Search: %s", string(jsonBody)) search := opensearchapi.SearchRequest{ Index: []string{ts.name + "-*"}, @@ -442,7 +436,6 @@ func (ts *TimeSeries) Search(query Query, sort []map[string]string, limit int64, } bodyData, _ := ioutil.ReadAll(searchResponse.Body) - logs.Info("Response Body: %s", string(bodyData)) var response SearchResponseBody err = json.Unmarshal(bodyData, &response) @@ -482,7 +475,6 @@ func (ts *TimeSeries) Get(id string) (res *GetResponseBody, err error) { } bodyData, _ := ioutil.ReadAll(getResponse.Body) - logs.Info("Get Response Body: %s", string(bodyData)) var response GetResponseBody err = json.Unmarshal(bodyData, &response) diff --git a/redis/redis.go b/redis/redis.go index 410ab54..3b9900f 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -167,7 +167,6 @@ func (r ClientWithHelpers) RateLimit(key string, limitFn func(int) redis_rate.Li return false, err } else { - logs.Info("Rate limiter - %s : %t with used %d, remaining %d", key, res.Allowed == 1, limit-res.Remaining, res.Remaining) return res.Allowed == 1, nil } } diff --git a/responses/responses.go b/responses/responses.go index 78d1d92..cf94854 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -79,10 +79,6 @@ func JSONSuccessResponse(body interface{}) (events.APIGatewayProxyResponse, erro // GenericResponse - called by the other functions func GenericResponse(statusCode int, body string, headers map[string]string) (events.APIGatewayProxyResponse, error) { - // Log the response - logs.Info("--> [APIGW] %d %s %s\n", statusCode, http.StatusText(statusCode), body) - // Return it - return events.APIGatewayProxyResponse{ StatusCode: statusCode, Body: body + "\n", diff --git a/secrets_manager/secrets_manager.go b/secrets_manager/secrets_manager.go index e4d11f6..3fc3e24 100644 --- a/secrets_manager/secrets_manager.go +++ b/secrets_manager/secrets_manager.go @@ -72,10 +72,6 @@ func getSecretManagerSession(isDebug bool) (err error) { // Get local config if isDebug && os.Getenv("ENVIRONMENT") != "" { - awsAccessKey := os.Getenv("AWS_ACCESS_KEY_ID") - if len(awsAccessKey) > 0 { - logs.Info("Using access key %s", awsAccessKey) - } awsSession, err = session.NewSessionWithOptions(session.Options{ Config: aws.Config{ Region: aws.String("af-south-1"), diff --git a/sqs/sqs.go b/sqs/sqs.go index b930879..67ead6c 100644 --- a/sqs/sqs.go +++ b/sqs/sqs.go @@ -13,8 +13,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sqs" - "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs" "github.com/go-resty/resty/v2" + "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs" ) var sqsClient *sqs.SQS @@ -109,17 +109,16 @@ func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID * go func() { if msgr.DelaySeconds != nil { delay := *msgr.DelaySeconds - time.Sleep( time.Second * time.Duration(delay)) + time.Sleep(time.Second * time.Duration(delay)) } resty.New().R(). SetBody(objectToSend). Post("http://127.0.0.1:3000/sqs/" + sqsType) }() - time.Sleep(time.Second*1) + time.Sleep(time.Second * 1) return nil } - if sqsClient == nil { var err error sqsClient, err = NewSQSClient(msgr.Region) @@ -147,7 +146,7 @@ func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID * headers[SQSMessageOnS3Key] = "true" id := uuid.New() filename := fmt.Sprintf("%v-%v", sqsType, id.String()) - logs.Info("SQS message too big, saving to S3 with filename = %s", filename) + logs.Info("SQS S3 %s", filename) err := uploadMessageToS3(msgr.S3Session, msgr.S3BucketName, filename, jsonBytes) if err != nil { @@ -163,7 +162,7 @@ func SendSQSMessage(msgr Messenger, objectToSend interface{}, currentRequestID * return err } - logs.Info(fmt.Sprintf("Sent SQS message to %s with ID %s", msgr.QueueName, msgID)) + logs.Info("SQS to %s: %s", msgr.QueueName, msgID) return nil } -- GitLab