Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
shurwit committed Feb 29, 2024
1 parent f737aeb commit fd35d96
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 218 deletions.
7 changes: 2 additions & 5 deletions core/auth/auth_type_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"gopkg.in/go-playground/validator.v9"

"github.com/coreos/go-oidc"
"github.com/google/uuid"
"github.com/rokwire/core-auth-library-go/v3/authutils"
"github.com/rokwire/logging-library-go/v2/errors"
"github.com/rokwire/logging-library-go/v2/logs"
Expand Down Expand Up @@ -428,13 +427,11 @@ func (a *oidcAuthImpl) loadOidcTokenWithParams(params map[string]string, oidcCon
data.Set(k, v)
}

requestID := uuid.New().String()
headers := map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": strconv.Itoa(len(data.Encode())),
"X-Request-ID": requestID,
"X-Request-ID": l.TraceID(),
}
l.AddContext("auth_request_id", requestID)

req, err := http.NewRequest(http.MethodPost, tokenURI, strings.NewReader(data.Encode()))
if err != nil {
Expand All @@ -454,7 +451,7 @@ func (a *oidcAuthImpl) loadOidcTokenWithParams(params map[string]string, oidcCon
return nil, errors.WrapErrorAction(logutils.ActionRead, logutils.TypeRequestBody, nil, err)
}
if resp.StatusCode != 200 {
return nil, errors.ErrorData(logutils.StatusInvalid, logutils.TypeResponse, &logutils.FieldArgs{"status_code": resp.StatusCode, "error": string(body), "auth_request_id": requestID})
return nil, errors.ErrorData(logutils.StatusInvalid, logutils.TypeResponse, &logutils.FieldArgs{"status_code": resp.StatusCode, "error": string(body)})
}

var authToken oidcToken
Expand Down
19 changes: 12 additions & 7 deletions driver/web/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,6 @@ func (we Adapter) wrapFunc(handler handlerFunc, authorization tokenauth.Handler)
return func(w http.ResponseWriter, req *http.Request) {
logObj := we.logger.NewRequestLog(req)

logObj.RequestReceived()

var err error

//1. validate request
Expand All @@ -428,15 +426,22 @@ func (we Adapter) wrapFunc(handler handlerFunc, authorization tokenauth.Handler)
//2. process it
if authorization != nil {
responseStatus, claims, err := authorization.Check(req)
if err != nil {
logObj.SetContext("claims_verified", false)
}
if claims != nil {
logObj.SetContext("account_id", claims.Subject)
}
logObj.RequestReceived()
if err != nil {
response = logObj.HTTPResponseErrorAction(logutils.ActionValidate, logutils.TypeRequest, nil, err, responseStatus, true)
we.completeResponse(w, response, logObj)
return
}

logObj.SetContext("account_id", claims.Subject)
response = handler(logObj, req, claims)
} else {
logObj.RequestReceived()
response = handler(logObj, req, nil)
}

Expand Down Expand Up @@ -580,13 +585,13 @@ func NewWebAdapter(env string, serviceRegManager *authservice.ServiceRegManager,
logger.Fatalf("error on openapi3 validate - %s", err.Error())
}

//Ignore servers. Validating reqeusts against the documented servers can cause issues when routing traffic through proxies/load-balancers.
//Ignore servers. Validating requests against the documented servers can cause issues when routing traffic through proxies/load-balancers.
doc.Servers = nil

//To correctly route traffic to base path, we must add to all paths since servers are ignored
paths := make(openapi3.Paths, len(doc.Paths))
for path, obj := range doc.Paths {
paths["/core"+path] = obj
paths := openapi3.NewPaths()
for path, obj := range doc.Paths.Map() {
paths.Set("/core"+path, obj)
}
doc.Paths = paths

Expand Down
66 changes: 31 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ go 1.21

require (
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/getkin/kin-openapi v0.120.0
github.com/go-webauthn/webauthn v0.8.6
github.com/getkin/kin-openapi v0.123.0
github.com/go-webauthn/webauthn v0.10.1
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/uuid v1.3.1
github.com/gorilla/mux v1.8.0
github.com/lestrrat-go/jwx v1.2.26
github.com/oapi-codegen/runtime v1.0.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/lestrrat-go/jwx v1.2.28
github.com/oapi-codegen/runtime v1.1.1
github.com/pquerna/otp v1.4.0
github.com/rokwire/core-auth-library-go/v3 v3.1.0
github.com/rokwire/logging-library-go/v2 v2.2.0
github.com/rokwire/core-auth-library-go/v3 v3.0.2-0.20240229164508-bda822e2a460
github.com/rokwire/logging-library-go/v2 v2.3.0
github.com/stretchr/testify v1.8.4
github.com/swaggo/http-swagger v1.3.4
go.mongodb.org/mongo-driver v1.12.1
golang.org/x/crypto v0.14.0
golang.org/x/oauth2 v0.13.0
golang.org/x/sync v0.4.0
golang.org/x/text v0.13.0
go.mongodb.org/mongo-driver v1.14.0
golang.org/x/crypto v0.20.0
golang.org/x/oauth2 v0.17.0
golang.org/x/sync v0.6.0
golang.org/x/text v0.14.0
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -41,55 +41,51 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
)

require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/aws/aws-sdk-go v1.45.24 // indirect
github.com/aws/aws-sdk-go v1.50.29 // indirect
github.com/boombuler/barcode v1.0.1 // indirect
github.com/casbin/casbin/v2 v2.77.2 // indirect
github.com/casbin/casbin/v2 v2.82.0 // indirect
github.com/casbin/govaluate v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // 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/fxamacker/cbor/v2 v2.6.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-webauthn/x v0.1.4 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/go-webauthn/x v0.1.8 // indirect
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.2.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/swag v1.16.2 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // 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/net v0.16.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit fd35d96

Please sign in to comment.