From f24fc60c64f1958eb160dd6a573a012a02c120b4 Mon Sep 17 00:00:00 2001 From: akshadpai Date: Thu, 6 Jul 2023 16:06:28 -0500 Subject: [PATCH 1/3] Add env vars to app-env --- README.md | 4 ++++ app-env.json | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app-env.json diff --git a/README.md b/README.md index 4b59810a..84a23e54 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,12 @@ LMS_TEST_NET_ID | < string > | yes | Net ID of test user LMS_TEST_USER_ID2 | < string > | yes | Account ID of second test user LMS_TEST_NET_ID2 | < string > | yes | Net ID of second test user LMS_NOTIFICATIONS_BB_HOST | < url > | yes | Notifications BB base URL +LMS_CORE_BB_CURRENT_HOST | < url > | yes | Core current BB host URL +LMS_CORE_BB_CORE_HOST | < url > | yes | Core BB core host URL LMS_CORE_BB_HOST | < url > | yes | Core BB host URL +LMS_GROUPS_BB_HOST | < url > | yes | Groups BB host URL LMS_SERVICE_URL | < url > | yes | URL where this application is being hosted +LMS_SERVICE_ACCOUNT_ID | < string > | yes | ID of Service Account for LMS BB ### Run Application diff --git a/app-env.json b/app-env.json new file mode 100644 index 00000000..adf117ca --- /dev/null +++ b/app-env.json @@ -0,0 +1,25 @@ +{ + "app_secret": { + "LMS_MONGO_AUTH": "", + "LMS_INTERNAL_API_KEY": "", + "LMS_PRIV_KEY": "" + }, + "app_config":{ + "LMS_PORT": "5000", + "LMS_MONGO_DATABASE": "", + "LMS_MONGO_TIMEOUT": "", + "LMS_DEFAULT_CACHE_EXPIRATION_SECONDS": "", + "LMS_CANVAS_BASE_URL": "", + "LMS_CANVAS_TOKEN_TYPE": "", + "LMS_CANVAS_TOKEN": "", + "LMS_GROUPS_BB_HOST": "", + "LMS_APP_ID": "", + "LMS_ORG_ID": "", + "LMS_NOTIFICATIONS_BB_HOST": "", + "LMS_CORE_BB_HOST": "", + "LMS_SERVICE_URL": "", + "LMS_CORE_BB_CURRENT_HOST": "", + "LMS_CORE_BB_CORE_HOST": "", + "LMS_SERVICE_ACCOUNT_ID": "" + } +} \ No newline at end of file From a301b597263a7f81039db7a52e05bbc07ab17203 Mon Sep 17 00:00:00 2001 From: akshadpai Date: Thu, 6 Jul 2023 16:06:38 -0500 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b55d29..217f71ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Prepare for development in OpenShift [#88](https://github.com/rokwire/lms-building-block/issues/88) + ## [1.9.2] - 2023-05-16 ### Fixed - Fix filtering by NetID [#85](https://github.com/rokwire/lms-building-block/issues/85) From cc69ce0ae48bbbd64440c90da669267463a28b53 Mon Sep 17 00:00:00 2001 From: akshadpai Date: Thu, 6 Jul 2023 16:06:52 -0500 Subject: [PATCH 3/3] Update logger and other dependencies --- .secrets.baseline | 30 +++++------ core/app.go | 2 +- core/app_apis_administration.go | 2 +- core/app_apis_services.go | 2 +- core/app_nudges.go | 2 +- core/interfaces.go | 2 +- driven/provider/adapter.go | 4 +- driven/provider/database.go | 6 +-- driven/storage/adapter.go | 6 +-- driven/storage/collection.go | 2 +- driven/storage/database.go | 2 +- driver/web/adapter.go | 16 +++--- driver/web/auth.go | 2 +- driver/web/auth/core.go | 4 +- driver/web/rest/adminapis.go | 94 ++++++++++++++++----------------- driver/web/rest/apis.go | 66 +++++++++++------------ go.mod | 59 +++++++++++---------- main.go | 7 ++- 18 files changed, 156 insertions(+), 152 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 0754fef7..ea63c78d 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -75,10 +75,6 @@ { "path": "detect_secrets.filters.allowlist.is_line_allowlisted" }, - { - "path": "detect_secrets.filters.common.is_baseline_file", - "filename": ".secrets.baseline" - }, { "path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies", "min_level": 2 @@ -109,6 +105,12 @@ }, { "path": "detect_secrets.filters.heuristic.is_templated_secret" + }, + { + "path": "detect_secrets.filters.regex.should_exclude_file", + "pattern": [ + "go.sum" + ] } ], "results": { @@ -118,8 +120,7 @@ "filename": "README.md", "hashed_secret": "112bb791304791ddcf692e29fd5cf149b35fea37", "is_verified": false, - "line_number": 25, - "is_secret": false + "line_number": 25 } ], "driven/groups/adapter.go": [ @@ -128,8 +129,7 @@ "filename": "driven/groups/adapter.go", "hashed_secret": "36c48d6ac9d10902792fa78b9c2d7d535971c2cc", "is_verified": false, - "line_number": 79, - "is_secret": false + "line_number": 79 } ], "driven/notifications/adapter.go": [ @@ -138,8 +138,7 @@ "filename": "driven/notifications/adapter.go", "hashed_secret": "6a4894e38dc141a1016ce7351b226c7f0fb4fc5c", "is_verified": false, - "line_number": 89, - "is_secret": false + "line_number": 89 } ], "driver/web/auth.go": [ @@ -148,16 +147,14 @@ "filename": "driver/web/auth.go", "hashed_secret": "17857c14001a341fdbd7f611889a6add1be7e9d8", "is_verified": false, - "line_number": 61, - "is_secret": false + "line_number": 61 }, { "type": "Secret Keyword", "filename": "driver/web/auth.go", "hashed_secret": "fca71afec681b7c2932610046e8e524820317e47", "is_verified": false, - "line_number": 77, - "is_secret": false + "line_number": 77 } ], "main.go": [ @@ -166,10 +163,9 @@ "filename": "main.go", "hashed_secret": "a23be006fadbd85ce60d87580e3f127c58a824ce", "is_verified": false, - "line_number": 104, - "is_secret": false + "line_number": 107 } ] }, - "generated_at": "2023-05-10T09:03:53Z" + "generated_at": "2023-07-06T21:06:08Z" } diff --git a/core/app.go b/core/app.go index e6250147..d6d6d2ad 100644 --- a/core/app.go +++ b/core/app.go @@ -18,7 +18,7 @@ import ( cacheadapter "lms/driven/cache" "lms/driven/corebb" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) // Application represents the core application code based on hexagonal architecture diff --git a/core/app_apis_administration.go b/core/app_apis_administration.go index ace40b00..c86414b4 100644 --- a/core/app_apis_administration.go +++ b/core/app_apis_administration.go @@ -20,7 +20,7 @@ package core import ( "lms/core/model" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) func (app *Application) getNudgesConfig(l *logs.Log) (*model.NudgesConfig, error) { diff --git a/core/app_apis_services.go b/core/app_apis_services.go index 485bca42..c6e21a2f 100644 --- a/core/app_apis_services.go +++ b/core/app_apis_services.go @@ -20,7 +20,7 @@ package core import ( "lms/core/model" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) func (app *Application) getVersion() string { diff --git a/core/app_nudges.go b/core/app_nudges.go index 7affa17b..1298670a 100644 --- a/core/app_nudges.go +++ b/core/app_nudges.go @@ -28,7 +28,7 @@ import ( "time" "github.com/google/uuid" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) type nudgesLogic struct { diff --git a/core/interfaces.go b/core/interfaces.go index 247256c1..042b37be 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -19,7 +19,7 @@ import ( "lms/driven/storage" "time" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) // Services exposes APIs for the driver adapters diff --git a/driven/provider/adapter.go b/driven/provider/adapter.go index accf3c2b..cddb6b8c 100644 --- a/driven/provider/adapter.go +++ b/driven/provider/adapter.go @@ -31,8 +31,8 @@ import ( "strings" "time" - "github.com/rokwire/logging-library-go/errors" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/errors" + "github.com/rokwire/logging-library-go/v2/logs" ) // Adapter implements the Provider interface diff --git a/driven/provider/database.go b/driven/provider/database.go index 1af8e355..a2f9b8be 100644 --- a/driven/provider/database.go +++ b/driven/provider/database.go @@ -20,9 +20,9 @@ import ( "log" "time" - "github.com/rokwire/logging-library-go/errors" - "github.com/rokwire/logging-library-go/logs" - "github.com/rokwire/logging-library-go/logutils" + "github.com/rokwire/logging-library-go/v2/errors" + "github.com/rokwire/logging-library-go/v2/logs" + "github.com/rokwire/logging-library-go/v2/logutils" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" diff --git a/driven/storage/adapter.go b/driven/storage/adapter.go index 83bd2f91..ad6a724d 100644 --- a/driven/storage/adapter.go +++ b/driven/storage/adapter.go @@ -21,9 +21,9 @@ import ( "strconv" "time" - "github.com/rokwire/logging-library-go/errors" - "github.com/rokwire/logging-library-go/logs" - "github.com/rokwire/logging-library-go/logutils" + "github.com/rokwire/logging-library-go/v2/errors" + "github.com/rokwire/logging-library-go/v2/logs" + "github.com/rokwire/logging-library-go/v2/logutils" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo/options" diff --git a/driven/storage/collection.go b/driven/storage/collection.go index 1259fef0..9f35a146 100644 --- a/driven/storage/collection.go +++ b/driven/storage/collection.go @@ -21,7 +21,7 @@ import ( "log" "time" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" diff --git a/driven/storage/database.go b/driven/storage/database.go index ee60b92b..4f46a91d 100644 --- a/driven/storage/database.go +++ b/driven/storage/database.go @@ -19,7 +19,7 @@ import ( "log" "time" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" diff --git a/driver/web/adapter.go b/driver/web/adapter.go index 53fee760..49ca813f 100644 --- a/driver/web/adapter.go +++ b/driver/web/adapter.go @@ -31,8 +31,8 @@ import ( "github.com/getkin/kin-openapi/routers" "github.com/rokwire/core-auth-library-go/v2/tokenauth" - "github.com/rokwire/logging-library-go/logs" - "github.com/rokwire/logging-library-go/logutils" + "github.com/rokwire/logging-library-go/v2/logs" + "github.com/rokwire/logging-library-go/v2/logutils" "github.com/gorilla/mux" httpSwagger "github.com/swaggo/http-swagger" @@ -131,7 +131,7 @@ func (we Adapter) wrapFunc(handler http.HandlerFunc) http.HandlerFunc { } } -type userAuthFunc = func(*logs.Log, *tokenauth.Claims, http.ResponseWriter, *http.Request) logs.HttpResponse +type userAuthFunc = func(*logs.Log, *tokenauth.Claims, http.ResponseWriter, *http.Request) logs.HTTPResponse func (we Adapter) userAuthWrapFunc(handler userAuthFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { @@ -142,7 +142,7 @@ func (we Adapter) userAuthWrapFunc(handler userAuthFunc) http.HandlerFunc { // validate request _, err := we.validateRequest(req) if err != nil { - logObj.RequestErrorAction(w, logutils.ActionValidate, logutils.TypeRequest, nil, err, http.StatusBadRequest, true) + logObj.HTTPResponseErrorAction(logutils.ActionValidate, logutils.TypeRequest, nil, err, http.StatusBadRequest, true) return } @@ -182,7 +182,7 @@ func (we Adapter) userAuthWrapFunc(handler userAuthFunc) http.HandlerFunc { } } -type adminAuthFunc = func(*logs.Log, *tokenauth.Claims, http.ResponseWriter, *http.Request) logs.HttpResponse +type adminAuthFunc = func(*logs.Log, *tokenauth.Claims, http.ResponseWriter, *http.Request) logs.HTTPResponse func (we Adapter) adminAuthWrapFunc(handler userAuthFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { @@ -193,7 +193,7 @@ func (we Adapter) adminAuthWrapFunc(handler userAuthFunc) http.HandlerFunc { // validate request _, err := we.validateRequest(req) if err != nil { - logObj.RequestErrorAction(w, logutils.ActionValidate, logutils.TypeRequest, nil, err, http.StatusBadRequest, true) + logObj.HTTPResponseErrorAction(logutils.ActionValidate, logutils.TypeRequest, nil, err, http.StatusBadRequest, true) return } @@ -237,12 +237,14 @@ type internalAPIKeyAuthFunc = func(http.ResponseWriter, *http.Request) func (we Adapter) internalAPIKeyAuthWrapFunc(handler internalAPIKeyAuthFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { - utils.LogRequest(req) + logObj := we.logger.NewRequestLog(req) + logObj.RequestReceived() apiKeyAuthenticated := we.auth.internalAuth.check(w, req) if apiKeyAuthenticated { handler(w, req) + logObj.RequestComplete() } else { http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) } diff --git a/driver/web/auth.go b/driver/web/auth.go index 16eb792b..e21686be 100644 --- a/driver/web/auth.go +++ b/driver/web/auth.go @@ -22,7 +22,7 @@ import ( "log" "net/http" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) // Auth handler diff --git a/driver/web/auth/core.go b/driver/web/auth/core.go index c7a269ff..0a1eb51f 100644 --- a/driver/web/auth/core.go +++ b/driver/web/auth/core.go @@ -23,8 +23,8 @@ import ( "github.com/rokwire/core-auth-library-go/v2/authorization" "github.com/rokwire/core-auth-library-go/v2/authservice" "github.com/rokwire/core-auth-library-go/v2/tokenauth" - "github.com/rokwire/logging-library-go/errors" - "github.com/rokwire/logging-library-go/logutils" + "github.com/rokwire/logging-library-go/v2/errors" + "github.com/rokwire/logging-library-go/v2/logutils" ) // CoreAuth implementation diff --git a/driver/web/rest/adminapis.go b/driver/web/rest/adminapis.go index 37cf32c1..405f22b1 100644 --- a/driver/web/rest/adminapis.go +++ b/driver/web/rest/adminapis.go @@ -27,8 +27,8 @@ import ( "github.com/gorilla/mux" "github.com/rokwire/core-auth-library-go/v2/tokenauth" - "github.com/rokwire/logging-library-go/logs" - "github.com/rokwire/logging-library-go/logutils" + "github.com/rokwire/logging-library-go/v2/logs" + "github.com/rokwire/logging-library-go/v2/logutils" ) // AdminApisHandler handles the rest Admin APIs implementation @@ -38,68 +38,68 @@ type AdminApisHandler struct { } // GetNudgesConfig gets the nudges config -func (h AdminApisHandler) GetNudgesConfig(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) GetNudgesConfig(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { nudges, err := h.app.Administration.GetNudgesConfig(l) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "nudges config", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "nudges config", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(nudges) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "nudge config", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "nudge config", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // UpdateNudgesConfig updates the nudges config -func (h AdminApisHandler) UpdateNudgesConfig(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) UpdateNudgesConfig(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { data, err := ioutil.ReadAll(r.Body) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, false) + return l.HTTPResponseErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, false) } var requestData Def.NudgesConfig err = json.Unmarshal(data, &requestData) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionUnmarshal, "nudges config", nil, err, http.StatusBadRequest, true) + return l.HTTPResponseErrorAction(logutils.ActionUnmarshal, "nudges config", nil, err, http.StatusBadRequest, true) } err = h.app.Administration.UpdateNudgesConfig(l, requestData.Active, requestData.GroupName, requestData.TestGroupName, string(requestData.Mode), requestData.ProcessTime, requestData.BlockSize) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "nudges config", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "nudges config", nil, err, http.StatusInternalServerError, true) } - return l.HttpResponseSuccess() + return l.HTTPResponseSuccess() } // GetNudges gets all the nudges -func (h AdminApisHandler) GetNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) GetNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { nudges, err := h.app.Administration.GetNudges() if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "nudge", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "nudge", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(nudges) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "nudge", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "nudge", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // CreateNudge creates nudge -func (h AdminApisHandler) CreateNudge(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) CreateNudge(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { data, err := ioutil.ReadAll(r.Body) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, false) + return l.HTTPResponseErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, false) } var requestData Def.AdminReqCreateNudge err = json.Unmarshal(data, &requestData) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionUnmarshal, "", nil, err, http.StatusBadRequest, true) + return l.HTTPResponseErrorAction(logutils.ActionUnmarshal, "", nil, err, http.StatusBadRequest, true) } var req model.UsersSource var usersSource []model.UsersSource @@ -110,9 +110,9 @@ func (h AdminApisHandler) CreateNudge(l *logs.Log, claims *tokenauth.Claims, w h err = h.app.Administration.CreateNudge(l, requestData.Id, requestData.Name, requestData.Body, requestData.DeepLink, requestData.Params, requestData.Active, usersSource) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "", nil, err, http.StatusInternalServerError, true) } - return l.HttpResponseSuccess() + return l.HTTPResponseSuccess() } // AdminReqUpdateNudge defines model for _admin_req_update_nudge. @@ -132,21 +132,21 @@ type UsersSources struct { } // UpdateNudge updates nudge -func (h AdminApisHandler) UpdateNudge(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) UpdateNudge(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { params := mux.Vars(r) ID := params["id"] if len(ID) <= 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } data, err := ioutil.ReadAll(r.Body) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, false) + return l.HTTPResponseErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err, http.StatusBadRequest, false) } var requestData adminReqUpdateNudge err = json.Unmarshal(data, &requestData) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionUnmarshal, "", nil, err, http.StatusBadRequest, true) + return l.HTTPResponseErrorAction(logutils.ActionUnmarshal, "", nil, err, http.StatusBadRequest, true) } var req model.UsersSources @@ -160,28 +160,28 @@ func (h AdminApisHandler) UpdateNudge(l *logs.Log, claims *tokenauth.Claims, w h err = h.app.Administration.UpdateNudge(l, ID, requestData.Name, requestData.Body, requestData.DeepLink, requestData.Params, requestData.Active, usersSource) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "", nil, err, http.StatusInternalServerError, true) } - return l.HttpResponseSuccess() + return l.HTTPResponseSuccess() } // DeleteNudge deletes nudge -func (h AdminApisHandler) DeleteNudge(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) DeleteNudge(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { params := mux.Vars(r) nudgeID := params["id"] if len(nudgeID) <= 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } err := h.app.Administration.DeleteNudge(l, nudgeID) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionDelete, "", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionDelete, "", nil, err, http.StatusInternalServerError, true) } - return l.HttpResponseSuccess() + return l.HTTPResponseSuccess() } // FindSentNudges gets all the sent_nudges -func (h AdminApisHandler) FindSentNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) FindSentNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { //nudgeID var nudgeID *string nudgeIDParam := r.URL.Query().Get("nudge-id") @@ -210,45 +210,45 @@ func (h AdminApisHandler) FindSentNudges(l *logs.Log, claims *tokenauth.Claims, sentNudges, err := h.app.Administration.FindSentNudges(l, nudgeID, userID, netID, mode) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "sent_nudges", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "sent_nudges", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(sentNudges) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "sent_nudges", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "sent_nudges", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // DeleteSentNudges deletes sent nudge -func (h AdminApisHandler) DeleteSentNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) DeleteSentNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { //sent nudge ID sentNudgesIDsParam := r.URL.Query().Get("ids") if sentNudgesIDsParam == "" { - return l.HttpResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("ids"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("ids"), nil, http.StatusBadRequest, false) } ids := strings.Split(sentNudgesIDsParam, ",") err := h.app.Administration.DeleteSentNudges(l, ids) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionDelete, "", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionDelete, "", nil, err, http.StatusInternalServerError, true) } - return l.HttpResponseSuccess() + return l.HTTPResponseSuccess() } // ClearTestSentNudges clears all sent nudges with the test mode -func (h AdminApisHandler) ClearTestSentNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) ClearTestSentNudges(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { err := h.app.Administration.ClearTestSentNudges(l) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionDelete, "test sent nudges", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionDelete, "test sent nudges", nil, err, http.StatusInternalServerError, true) } - return l.HttpResponseSuccess() + return l.HTTPResponseSuccess() } // FindNudgesProcesses gets all the nudges-process -func (h AdminApisHandler) FindNudgesProcesses(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h AdminApisHandler) FindNudgesProcesses(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { var err error //limit and offset @@ -257,7 +257,7 @@ func (h AdminApisHandler) FindNudgesProcesses(l *logs.Log, claims *tokenauth.Cla if limitArg != "" { limit, err = strconv.Atoi(limitArg) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionParse, logutils.TypeArg, logutils.StringArgs("limit"), err, http.StatusBadRequest, false) + return l.HTTPResponseErrorAction(logutils.ActionParse, logutils.TypeArg, logutils.StringArgs("limit"), err, http.StatusBadRequest, false) } } offset := 0 @@ -265,18 +265,18 @@ func (h AdminApisHandler) FindNudgesProcesses(l *logs.Log, claims *tokenauth.Cla if offsetArg != "" { offset, err = strconv.Atoi(offsetArg) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionParse, logutils.TypeArg, logutils.StringArgs("offset"), err, http.StatusBadRequest, false) + return l.HTTPResponseErrorAction(logutils.ActionParse, logutils.TypeArg, logutils.StringArgs("offset"), err, http.StatusBadRequest, false) } } nudgesProcesses, err := h.app.Administration.FindNudgesProcesses(l, limit, offset) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "nudges_processes", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "nudges_processes", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(nudgesProcesses) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "sent_nudges", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "sent_nudges", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } diff --git a/driver/web/rest/apis.go b/driver/web/rest/apis.go index 4c80b55f..781c373b 100644 --- a/driver/web/rest/apis.go +++ b/driver/web/rest/apis.go @@ -25,8 +25,8 @@ import ( "github.com/gorilla/mux" "github.com/rokwire/core-auth-library-go/v2/tokenauth" - "github.com/rokwire/logging-library-go/logs" - "github.com/rokwire/logging-library-go/logutils" + "github.com/rokwire/logging-library-go/v2/logs" + "github.com/rokwire/logging-library-go/v2/logutils" ) // ApisHandler handles the rest APIs implementation @@ -41,72 +41,72 @@ func (h ApisHandler) Version(w http.ResponseWriter, r *http.Request) { } // GetCourses gets courses -func (h ApisHandler) GetCourses(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h ApisHandler) GetCourses(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { providerUserID := h.getProviderUserID(claims) if len(providerUserID) == 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) } courses, err := h.app.Services.GetCourses(l, providerUserID) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "course", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "course", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(courses) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "course", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "course", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // GetCourse gets a course -func (h ApisHandler) GetCourse(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h ApisHandler) GetCourse(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { providerUserID := h.getProviderUserID(claims) if len(providerUserID) == 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) } //course id params := mux.Vars(r) ID := params["id"] if len(ID) <= 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } courseID, err := strconv.Atoi(ID) if err != nil { - return l.HttpResponseErrorData(logutils.StatusInvalid, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusInvalid, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } course, err := h.app.Services.GetCourse(l, providerUserID, courseID) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "course", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "course", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(course) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "course", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "course", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // GetAssignemntGroups gets course assignments -func (h ApisHandler) GetAssignemntGroups(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h ApisHandler) GetAssignemntGroups(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { providerUserID := h.getProviderUserID(claims) if len(providerUserID) == 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) } //course id params := mux.Vars(r) ID := params["id"] if len(ID) <= 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } courseID, err := strconv.Atoi(ID) if err != nil { - return l.HttpResponseErrorData(logutils.StatusInvalid, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusInvalid, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } //include @@ -120,33 +120,33 @@ func (h ApisHandler) GetAssignemntGroups(l *logs.Log, claims *tokenauth.Claims, assignmentGroups, err := h.app.Services.GetAssignmentGroups(l, providerUserID, courseID, includeAssignments, includeSubmission) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "assignment group", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "assignment group", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(assignmentGroups) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "assignment group", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "assignment group", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // GetUsers gets course users -func (h ApisHandler) GetUsers(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h ApisHandler) GetUsers(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { providerUserID := h.getProviderUserID(claims) if len(providerUserID) == 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) } //course id params := mux.Vars(r) ID := params["id"] if len(ID) <= 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } courseID, err := strconv.Atoi(ID) if err != nil { - return l.HttpResponseErrorData(logutils.StatusInvalid, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) + return l.HTTPResponseErrorData(logutils.StatusInvalid, logutils.TypeQueryParam, logutils.StringArgs("id"), nil, http.StatusBadRequest, false) } //include @@ -160,35 +160,35 @@ func (h ApisHandler) GetUsers(l *logs.Log, claims *tokenauth.Claims, w http.Resp user, err := h.app.Services.GetCourseUser(l, providerUserID, courseID, includeEnrolments, includeScores) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "user", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "user", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(user) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "user", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "user", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } // GetCurrentUser gets the current user -func (h ApisHandler) GetCurrentUser(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HttpResponse { +func (h ApisHandler) GetCurrentUser(l *logs.Log, claims *tokenauth.Claims, w http.ResponseWriter, r *http.Request) logs.HTTPResponse { providerUserID := h.getProviderUserID(claims) if len(providerUserID) == 0 { - return l.HttpResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) + return l.HTTPResponseErrorData(logutils.StatusMissing, "net_id", nil, nil, http.StatusInternalServerError, false) } user, err := h.app.Services.GetCurrentUser(l, providerUserID) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionGet, "user", nil, err, http.StatusInternalServerError, true) + return l.HTTPResponseErrorAction(logutils.ActionGet, "user", nil, err, http.StatusInternalServerError, true) } data, err := json.Marshal(user) if err != nil { - return l.HttpResponseErrorAction(logutils.ActionMarshal, "user", nil, err, http.StatusInternalServerError, false) + return l.HTTPResponseErrorAction(logutils.ActionMarshal, "user", nil, err, http.StatusInternalServerError, false) } - return l.HttpResponseSuccessJSON(data) + return l.HTTPResponseSuccessJSON(data) } func (h ApisHandler) getProviderUserID(claims *tokenauth.Claims) string { diff --git a/go.mod b/go.mod index 5b20f1e3..0f255647 100644 --- a/go.mod +++ b/go.mod @@ -3,53 +3,56 @@ module lms go 1.18 require ( - github.com/PuerkitoBio/goquery v1.8.0 - github.com/getkin/kin-openapi v0.98.0 + github.com/PuerkitoBio/goquery v1.8.1 + github.com/getkin/kin-openapi v0.118.0 + github.com/golang-jwt/jwt v3.2.2+incompatible github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/rokwire/core-auth-library-go/v2 v2.0.1 + github.com/rokwire/core-auth-library-go/v2 v2.2.0 github.com/rokwire/logging-library-go v1.0.3 - github.com/swaggo/http-swagger v1.3.3 - go.mongodb.org/mongo-driver v1.10.1 + github.com/rokwire/logging-library-go/v2 v2.2.0 + github.com/swaggo/http-swagger v1.3.4 + go.mongodb.org/mongo-driver v1.12.0 ) require ( github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect github.com/KyleBanks/depth v1.2.1 // indirect - github.com/andybalholm/cascadia v1.3.1 // indirect - github.com/casbin/casbin/v2 v2.51.2 // indirect - github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/jsonreference v0.20.0 // indirect - github.com/go-openapi/spec v0.20.6 // indirect - github.com/go-openapi/swag v0.22.0 // indirect - github.com/go-playground/locales v0.14.0 // indirect - github.com/go-playground/universal-translator v0.18.0 // indirect - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/andybalholm/cascadia v1.3.2 // indirect + github.com/casbin/casbin/v2 v2.71.1 // indirect + github.com/go-openapi/jsonpointer v0.19.6 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/spec v0.20.9 // indirect + github.com/go-openapi/swag v0.22.4 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-cmp v0.5.5 // indirect github.com/invopop/yaml v0.2.0 // indirect github.com/josharian/intern v1.0.0 // indirect - github.com/klauspost/compress v1.15.9 // indirect + github.com/klauspost/compress v1.16.7 // indirect github.com/kr/pretty v0.3.0 // indirect - github.com/leodido/go-urn v1.2.1 // indirect + github.com/leodido/go-urn v1.2.4 // indirect github.com/mailru/easyjson v0.7.7 // indirect - github.com/montanaflynn/stats v0.6.6 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect + github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect - github.com/sirupsen/logrus v1.9.0 // indirect - github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a // indirect - github.com/swaggo/swag v1.8.4 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/swaggo/files v1.0.1 // indirect + github.com/swaggo/swag v1.16.1 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.1 // indirect - github.com/xdg-go/stringprep v1.0.3 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect - golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - golang.org/x/tools v0.1.12 // indirect + golang.org/x/crypto v0.11.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect + golang.org/x/tools v0.11.0 // indirect golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect gopkg.in/go-playground/validator.v9 v9.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/main.go b/main.go index f403655e..3cc0addd 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ import ( "github.com/golang-jwt/jwt" "github.com/rokwire/core-auth-library-go/v2/authservice" "github.com/rokwire/core-auth-library-go/v2/sigauth" - "github.com/rokwire/logging-library-go/logs" + "github.com/rokwire/logging-library-go/v2/logs" ) var ( @@ -48,7 +48,10 @@ func main() { serviceID := "lms" - loggerOpts := logs.LoggerOpts{SuppressRequests: []logs.HttpRequestProperties{logs.NewAwsHealthCheckHttpRequestProperties(serviceID + "/version")}} + loggerOpts := logs.LoggerOpts{ + SuppressRequests: logs.NewStandardHealthCheckHTTPRequestProperties(serviceID + "/version"), + SensitiveHeaders: []string{"Internal-Api-Key"}, + } logger := logs.NewLogger(serviceID, &loggerOpts) port := getEnvKey("LMS_PORT", true)