From b8e07b2e606e9a758730b963b9244f9e842a07c5 Mon Sep 17 00:00:00 2001 From: Vivian Allen Date: Thu, 22 Jul 2021 15:31:22 +0100 Subject: [PATCH 1/2] update log.go to v2, update logging statements for elasticsearch Update log.go requirement to v2 in go.mod and imports. Update logging statements to format that can be parsed by elastisearch, e.g. log.Event(ctx, string, log.FATAL, log.Error(something1), something2) -> log.Fatal(ctx, string, something1, something2) log.Event(ctx, string, log.ERROR log.Error(something1), something2) -> log.Error(ctx, string, something1, something2) log.Event(ctx, string, log.INFO, log.Error(something)) -> log.Info(ctx, string, log.FormatErrors([]error{something})) log.Event(ctx, string, log.WARN, log.Error(something)) -> log.Warn(ctx, string, log.FormatErrors([]error{something})) These changes needed to allow error logs to be properly viewed in kibana. --- auth/errors.go | 8 +++---- auth/handler.go | 6 +++--- auth/nop.go | 4 ++-- auth/verifier.go | 6 +++--- example/main.go | 8 +++---- go.mod | 7 +++--- go.sum | 55 +++++++++++++++++++++++++++++++++++++----------- 7 files changed, 63 insertions(+), 31 deletions(-) diff --git a/auth/errors.go b/auth/errors.go index 1e795d5..8424f13 100644 --- a/auth/errors.go +++ b/auth/errors.go @@ -7,7 +7,7 @@ import ( "io" "io/ioutil" - "github.com/ONSdigital/log.go/log" + "github.com/ONSdigital/log.go/v2/log" ) var ( @@ -60,14 +60,14 @@ func (e Error) Error() string { func handleGetPermissionsErrorResponse(ctx context.Context, body io.Reader, status int) error { errorEntity, err := getErrorEntityFromResponse(body) if err != nil { - log.Event( - ctx, "error unmarshalling get permissions error response. Returning 401 status as unable to verify caller permissions", log.Error(err), log.Data{ + log.Error( + ctx, "error unmarshalling get permissions error response. Returning 401 status as unable to verify caller permissions", err, log.Data{ "get_permissions_status_code": status, }) return getPermissionsUnauthorizedError } - log.Event(ctx, "get permissions request returned error status. Returning 401 status as unable to verify caller permissions", + log.Info(ctx, "get permissions request returned error status. Returning 401 status as unable to verify caller permissions", log.Data{ "get_permissions_status_code": status, "get_permissions_body": errorEntity, diff --git a/auth/handler.go b/auth/handler.go index 644234c..1a59afa 100644 --- a/auth/handler.go +++ b/auth/handler.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "github.com/ONSdigital/log.go/log" + "github.com/ONSdigital/log.go/v2/log" ) //go:generate moq -out generated_mocks.go -pkg auth . Clienter Verifier HTTPClienter GetPermissionsRequestBuilder @@ -94,7 +94,7 @@ func (h *Handler) Require(required Permissions, handler http.HandlerFunc) http.H return } - log.Event(req.Context(), "caller authorised to perform requested action", logD) + log.Info(req.Context(), "caller authorised to perform requested action", logD) handler(w, req) }) } @@ -117,7 +117,7 @@ func writeErr(ctx context.Context, w http.ResponseWriter, status int, body strin logD["original_err_body"] = body logD["original_err_status"] = status - log.Event(ctx, "internal server error failed writing permissions error to response", log.Error(wErr), logD) + log.Error(ctx, "internal server error failed writing permissions error to response", wErr, logD) return } } diff --git a/auth/nop.go b/auth/nop.go index 2752796..23592ff 100644 --- a/auth/nop.go +++ b/auth/nop.go @@ -3,7 +3,7 @@ package auth import ( "net/http" - "github.com/ONSdigital/log.go/log" + "github.com/ONSdigital/log.go/v2/log" ) // NopHandler is a Nop impl of auth.Handler which simply logs that it has been invoked and returns the wrapped handlerFunc. @@ -11,7 +11,7 @@ type NopHandler struct{} func (h *NopHandler) Require(required Permissions, handler http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - log.Event(r.Context(), "executing NopHandler.Require", log.Data{ + log.Info(r.Context(), "executing NopHandler.Require", log.Data{ "uri": r.URL.Path, "method": r.Method, "required_permissions": required, diff --git a/auth/verifier.go b/auth/verifier.go index fcf77ec..cef16cd 100644 --- a/auth/verifier.go +++ b/auth/verifier.go @@ -3,7 +3,7 @@ package auth import ( "context" - "github.com/ONSdigital/log.go/log" + "github.com/ONSdigital/log.go/v2/log" ) type PermissionsVerifier struct { @@ -35,7 +35,7 @@ func (verifier *PermissionsVerifier) CheckAuthorisation(ctx context.Context, act } if len(missingPermissions) > 0 { - log.Event(ctx, "action forbidden caller does not process the required permissions", log.Data{ + log.Warn(ctx, "action forbidden caller does not process the required permissions", log.Data{ "required_permissions": required, "caller_permissions": actual, "missing_permissions": missingPermissions, @@ -43,7 +43,7 @@ func (verifier *PermissionsVerifier) CheckAuthorisation(ctx context.Context, act return checkAuthorisationForbiddenError } - log.Event(ctx, "caller authorised to perform the requested action") + log.Info(ctx, "caller authorised to perform the requested action") return nil } diff --git a/example/main.go b/example/main.go index 0404413..0cd0fa7 100644 --- a/example/main.go +++ b/example/main.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/ONSdigital/dp-authorisation/auth" - "github.com/ONSdigital/log.go/log" + "github.com/ONSdigital/log.go/v2/log" "github.com/gorilla/mux" ) @@ -39,7 +39,7 @@ func main() { router.HandleFunc("/datasets", permissions.Require(read, getDatasetsHandlerFunc)).Methods("GET") router.HandleFunc("/datasets/{dataset_id}", datasetsPermissions.Require(read, getDatasetHandlerFunc)).Methods("GET") - log.Event(context.Background(), "starting dp-authorisation example API", log.INFO) + log.Info(context.Background(), "starting dp-authorisation example API") err := http.ListenAndServe(":22000", router) if err != nil { panic(err) @@ -48,13 +48,13 @@ func main() { // an example http.HandlerFunc for getting a dataset func getDatasetsHandlerFunc(w http.ResponseWriter, r *http.Request) { - log.Event(r.Context(), "get datasets stub invoked", log.INFO) + log.Info(r.Context(), "get datasets stub invoked") w.Write([]byte("datasets info here")) } // an example http.HandlerFunc for getting a dataset func getDatasetHandlerFunc(w http.ResponseWriter, r *http.Request) { datasetID := mux.Vars(r)["dataset_id"] - log.Event(r.Context(), "get dataset stub invoked", log.INFO, log.Data{"dataset_id": datasetID}) + log.Info(r.Context(), "get dataset stub invoked", log.Data{"dataset_id": datasetID}) w.Write([]byte("dataset info here")) } diff --git a/go.mod b/go.mod index 599d2b8..e41b5a6 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,10 @@ module github.com/ONSdigital/dp-authorisation go 1.13 require ( - github.com/ONSdigital/dp-api-clients-go v1.9.0 + github.com/ONSdigital/dp-api-clients-go v1.34.3 github.com/ONSdigital/dp-rchttp v1.0.0 - github.com/ONSdigital/log.go v1.0.0 - github.com/gorilla/mux v1.7.4 + github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad // indirect + github.com/ONSdigital/log.go/v2 v2.0.5 + github.com/gorilla/mux v1.8.0 github.com/smartystreets/goconvey v1.6.4 ) diff --git a/go.sum b/go.sum index 347f789..87c115b 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,17 @@ github.com/ONSdigital/dp-api-clients-go v1.1.0/go.mod h1:9lqor0I7caCnRWr04gU/r7x5dqxgoODob8L48q+cE4E= -github.com/ONSdigital/dp-api-clients-go v1.9.0 h1:ru8jBPAxXfibYOF41/tU/ZtOt4tUVEszpMraHAbmvxA= -github.com/ONSdigital/dp-api-clients-go v1.9.0/go.mod h1:SM0b/NXDWndJ9EulmAGdfDY4DxPxK+pNsP8eZlIWiqM= +github.com/ONSdigital/dp-api-clients-go v1.28.0/go.mod h1:iyJy6uRL4B6OYOJA0XMr5UHt6+Q8XmN9uwmURO+9Oj4= +github.com/ONSdigital/dp-api-clients-go v1.34.3 h1:nS3ZG3Eql9T68Q0IFehpnqkUy2AFoTDktVgaD90Yj+s= +github.com/ONSdigital/dp-api-clients-go v1.34.3/go.mod h1:kX+YKuoLYLfkeLHMvQKRRydZVxO7ZEYyYiwG2xhV51E= github.com/ONSdigital/dp-frontend-models v1.1.0/go.mod h1:TT96P7Mi69N3Tc/jFNdbjiwG4GAaMjP26HLotFQ6BPw= github.com/ONSdigital/dp-healthcheck v0.0.0-20200131122546-9db6d3f0494e/go.mod h1:zighxZ/0m5u7zo0eAr8XFlA+Dz2ic7A1vna6YXvhCjQ= -github.com/ONSdigital/dp-healthcheck v1.0.0/go.mod h1:zighxZ/0m5u7zo0eAr8XFlA+Dz2ic7A1vna6YXvhCjQ= +github.com/ONSdigital/dp-healthcheck v1.0.5/go.mod h1:2wbVAUHMl9+4tWhUlxYUuA1dnf2+NrwzC+So5f5BMLk= github.com/ONSdigital/dp-mocking v0.0.0-20190905163309-fee2702ad1b9/go.mod h1:BcIRgitUju//qgNePRBmNjATarTtynAgc0yV29VpLEk= +github.com/ONSdigital/dp-net v1.0.5-0.20200805082802-e518bc287596/go.mod h1:wDVhk2pYosQ1q6PXxuFIRYhYk2XX5+1CeRRnXpSczPY= +github.com/ONSdigital/dp-net v1.0.5-0.20200805145012-9227a11caddb/go.mod h1:MrSZwDUvp8u1VJEqa+36Gwq4E7/DdceW+BDCvGes6Cs= +github.com/ONSdigital/dp-net v1.0.5-0.20200805150805-cac050646ab5/go.mod h1:de3LB9tedE0tObBwa12dUOt5rvTW4qQkF5rXtt4b6CE= +github.com/ONSdigital/dp-net v1.0.7/go.mod h1:1QFzx32FwPKD2lgZI6MtcsUXritsBdJihlzIWDrQ/gc= +github.com/ONSdigital/dp-net v1.0.12 h1:Vd06ia1FXKR9uyhzWykQ52b1LTp4N0VOLnrF7KOeP78= +github.com/ONSdigital/dp-net v1.0.12/go.mod h1:2lvIKOlD4T3BjWQwjHhBUO2UNWDk82u/+mHRn0R3C9A= github.com/ONSdigital/dp-rchttp v0.0.0-20190919143000-bb5699e6fd59/go.mod h1:KkW68U3FPuivW4ogi9L8CPKNj9ZxGko4qcUY7KoAAkQ= github.com/ONSdigital/dp-rchttp v0.0.0-20200114090501-463a529590e8/go.mod h1:821jZtK0oBsV8hjIkNr8vhAWuv0FxJBPJuAHa2B70Gk= github.com/ONSdigital/dp-rchttp v1.0.0 h1:K/1/gDtfMZCX1Mbmq80nZxzDirzneqA1c89ea26FqP4= @@ -13,32 +20,43 @@ github.com/ONSdigital/go-ns v0.0.0-20191104121206-f144c4ec2e58/go.mod h1:iWos35i github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad h1:Axoxm5rF6j7LSZfm4AGBT5IwGhWIcfcOkkhy/su/UpA= github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad/go.mod h1:uHT6LaUlRbJsJRrIlN31t+QLUB80tAbk6ZR9sfoHL8Y= github.com/ONSdigital/log.go v0.0.0-20191127134126-2a610b254f20/go.mod h1:BD7D8FWP1fzwUWsrCopEG72jl9cchCaVNIGSz6YvL+Y= -github.com/ONSdigital/log.go v1.0.0 h1:hZQTuitFv4nSrpzMhpGvafUC5/8xMVnLI0CWe1rAJNc= github.com/ONSdigital/log.go v1.0.0/go.mod h1:UnGu9Q14gNC+kz0DOkdnLYGoqugCvnokHBRBxFRpVoQ= +github.com/ONSdigital/log.go v1.0.1-0.20200805084515-ee61165ea36a/go.mod h1:dDnQATFXCBOknvj6ZQuKfmDhbOWf3e8mtV+dPEfWJqs= +github.com/ONSdigital/log.go v1.0.1-0.20200805145532-1f25087a0744/go.mod h1:y4E9MYC+cV9VfjRD0UBGj8PA7H3wABqQi87/ejrDhYc= +github.com/ONSdigital/log.go v1.0.1 h1:SZ5wRZAwlt2jQUZ9AUzBB/PL+iG15KapfQpJUdA18/4= +github.com/ONSdigital/log.go v1.0.1/go.mod h1:dIwSXuvFB5EsZG5x44JhsXZKMd80zlb0DZxmiAtpL4M= +github.com/ONSdigital/log.go/v2 v2.0.5 h1:kl2lF0vr3BQDwPTAUcarDvX4Um3uE3fjVRfLoHAarBc= +github.com/ONSdigital/log.go/v2 v2.0.5/go.mod h1:PR7vXrv9dZKUc7SI/0toxBbStk84snmybBnWpe+xY2o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9/go.mod h1:uPmAp6Sws4L7+Q/OokbWDAK1ibXYhB3PXFP1kol5hPg= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= +github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/go-avro/avro v0.0.0-20171219232920-444163702c11/go.mod h1:kxj6THYP0dmFPk4Z+bijIAhJoGgeBfyOKXMduhvdJPA= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= -github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU= -github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e h1:0aewS5NTyxftZHSnFaJmWE5oCCrj4DyEXkAiMa1iZJM= github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI= +github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 h1:nqAlWFEdqI0ClbTDrhDvE/8LeQ4pftrqKUX9w5k0j3s= +github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -46,14 +64,27 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/unrolled/render v1.0.2/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 h1:g9s1Ppvvun/fI+BptTMj909BBIcGrzQ32k9FNlcevOE= +golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= From 2f1eef76ab5e5136f8d75aec6e1e4f65f682ae91 Mon Sep 17 00:00:00 2001 From: Vivian Allen Date: Thu, 22 Jul 2021 15:45:57 +0100 Subject: [PATCH 2/2] Add missing CI dir w. scripts for concourse + assoc. make rules Add CI task scripts, concourse task defintions and make rules for: - audit - build - lint - unit --- Makefile | 15 ++++++++++++++- auth/permissions_client_test.go | 2 +- auth/permissions_request_builder.go | 2 +- ci/audit.yml | 15 +++++++++++++++ ci/build.yml | 16 ++++++++++++++++ ci/lint.yml | 15 +++++++++++++++ ci/scripts/audit.sh | 7 +++++++ ci/scripts/build.sh | 7 +++++++ ci/scripts/lint.sh | 7 +++++++ ci/scripts/unit.sh | 7 +++++++ ci/unit.yml | 16 ++++++++++++++++ 11 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 ci/audit.yml create mode 100644 ci/build.yml create mode 100644 ci/lint.yml create mode 100755 ci/scripts/audit.sh create mode 100755 ci/scripts/build.sh create mode 100755 ci/scripts/lint.sh create mode 100755 ci/scripts/unit.sh create mode 100644 ci/unit.yml diff --git a/Makefile b/Makefile index 016f2f0..cd46117 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,24 @@ example: go build -o ./example/example example/main.go go run -race example/main.go +.PHONY: example test: go test -race -cover ./... +.PHONY: test clean: rm example/example +.PHONY: test -.PHONY: example test clean +audit: + go list -json -m all | nancy sleuth +.PHONY: audit + +build: + go build ./... +.PHONY: build + +lint: + go fmt ./... +.PHONY: lint diff --git a/auth/permissions_client_test.go b/auth/permissions_client_test.go index 7284d72..26435aa 100644 --- a/auth/permissions_client_test.go +++ b/auth/permissions_client_test.go @@ -513,7 +513,7 @@ func TestPermissionsClient_GetPermissions(t *testing.T) { actual, err := cli.GetPermissions(nil, getPermReq) - expected := &Permissions{Read:true} + expected := &Permissions{Read: true} So(err, ShouldBeNil) So(actual, ShouldResemble, expected) diff --git a/auth/permissions_request_builder.go b/auth/permissions_request_builder.go index 9522529..18376f3 100644 --- a/auth/permissions_request_builder.go +++ b/auth/permissions_request_builder.go @@ -80,7 +80,7 @@ func (builder *PermissionsRequestBuilder) checkConfiguration() error { return nil } -// getAuthTokens get the user and or service auth tokens from the request. +// getAuthTokens get the user and or service auth tokens from the request. func getAuthTokens(req *http.Request) (string, string, error) { userAuthToken, errUserToken := headers.GetUserAuthToken(req) if errUserToken != nil && headers.IsNotErrNotFound(errUserToken) { diff --git a/ci/audit.yml b/ci/audit.yml new file mode 100644 index 0000000..0f1a074 --- /dev/null +++ b/ci/audit.yml @@ -0,0 +1,15 @@ +--- +platform: linux + +image_resource: + type: docker-image + source: + repository: onsdigital/dp-concourse-tools-nancy + tag: latest + +inputs: + - name: dp-authorisation + path: dp-authorisation + +run: + path: dp-authorisation/ci/scripts/audit.sh diff --git a/ci/build.yml b/ci/build.yml new file mode 100644 index 0000000..c8daa9a --- /dev/null +++ b/ci/build.yml @@ -0,0 +1,16 @@ +--- + +platform: linux + +image_resource: + type: docker-image + source: + repository: golang + tag: latest + +inputs: + - name: dp-authorisation + path: dp-authorisation + +run: + path: dp-authorisation/ci/scripts/build.sh diff --git a/ci/lint.yml b/ci/lint.yml new file mode 100644 index 0000000..3b90d35 --- /dev/null +++ b/ci/lint.yml @@ -0,0 +1,15 @@ +--- + +platform: linux + +image_resource: + type: docker-image + source: + repository: golang + tag: 1.16.4 + +inputs: + - name: dp-authorisation + +run: + path: dp-authorisation/ci/scripts/lint.sh diff --git a/ci/scripts/audit.sh b/ci/scripts/audit.sh new file mode 100755 index 0000000..acad5e9 --- /dev/null +++ b/ci/scripts/audit.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux + +cwd=$(pwd) + +pushd $cwd/dp-authorisation + make audit +popd diff --git a/ci/scripts/build.sh b/ci/scripts/build.sh new file mode 100755 index 0000000..23e4c24 --- /dev/null +++ b/ci/scripts/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux + +cwd=$(pwd) + +pushd $cwd/dp-authorisation + make build +popd diff --git a/ci/scripts/lint.sh b/ci/scripts/lint.sh new file mode 100755 index 0000000..638a6eb --- /dev/null +++ b/ci/scripts/lint.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux + +cwd=$(pwd) + +pushd $cwd/dp-authorisation + make lint +popd diff --git a/ci/scripts/unit.sh b/ci/scripts/unit.sh new file mode 100755 index 0000000..a9141fb --- /dev/null +++ b/ci/scripts/unit.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux + +cwd=$(pwd) + +pushd $cwd/dp-authorisation + make test +popd diff --git a/ci/unit.yml b/ci/unit.yml new file mode 100644 index 0000000..d9c8d32 --- /dev/null +++ b/ci/unit.yml @@ -0,0 +1,16 @@ +--- + +platform: linux + +image_resource: + type: docker-image + source: + repository: golang + tag: latest + +inputs: + - name: dp-authorisation + path: dp-authorisation + +run: + path: dp-authorisation/ci/scripts/unit.sh