Skip to content
Draft
14 changes: 7 additions & 7 deletions WRPAccessControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

"github.com/go-kit/kit/metrics"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/webpa-common/v2/basculechecks"
"github.com/xmidt-org/bascule/basculechecks"
"github.com/xmidt-org/webpa-common/v2/xhttp"
"github.com/xmidt-org/wrp-go/v3"
)

//partnerAuthority errors
// partnerAuthority errors
var (
ErrTokenMissing = &xhttp.Error{Code: http.StatusInternalServerError, Text: "No JWT Token was found in context"}
ErrTokenTypeMismatch = &xhttp.Error{Code: http.StatusInternalServerError, Text: "Token must be a JWT"}
Expand All @@ -21,7 +21,7 @@ var (
ErrPIDMismatch = &xhttp.Error{Code: http.StatusForbidden, Text: "Unauthorized partners credentials in WRP message"}
)

//WRPCheckConfig drives the WRP Access control configuration when enabled
// WRPCheckConfig drives the WRP Access control configuration when enabled
type WRPCheckConfig struct {
Type string
}
Expand Down Expand Up @@ -55,8 +55,8 @@ func (p *wrpPartnersAccess) withSuccess(labelValues ...string) metrics.Counter {
return p.receivedWRPMessageCount.With(append(labelValues, OutcomeLabel, Accepted)...)
}

//authorizeWRP runs the partners access policy against the WRP and returns an error if the check fails.
//When the policy is not strictly enforced,
// authorizeWRP runs the partners access policy against the WRP and returns an error if the check fails.
// When the policy is not strictly enforced,
// Additionally, when the policy is not a boolean is returned for failure cases where the policy autocorrects the WRP contents
func (p *wrpPartnersAccess) authorizeWRP(ctx context.Context, message *wrp.Message) (bool, error) {
var (
Expand Down Expand Up @@ -142,7 +142,7 @@ func (p *wrpPartnersAccess) authorizeWRP(ctx context.Context, message *wrp.Messa
return true, nil
}

//returns true if list contains str
// returns true if list contains str
func contains(list []string, str string) bool {
for _, e := range list {
if e == str {
Expand All @@ -152,7 +152,7 @@ func contains(list []string, str string) bool {
return false
}

//returns true if a is a subset of b
// returns true if a is a subset of b
func isSubset(a, b []string) bool {
m := make(map[string]bool)

Expand Down
37 changes: 9 additions & 28 deletions basculeLogging.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package main

import (
"context"
"net/http"
"strings"

"github.com/go-kit/log"
"github.com/xmidt-org/candlelight"

// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/logging"
"github.com/xmidt-org/sallust"
"go.uber.org/zap"
)

// LoggerFunc is a strategy for adding key/value pairs (possibly) based on an HTTP request.
// Functions of this type must append key/value pairs to the supplied slice and then return
// the new slice.
type LoggerFunc func([]interface{}, *http.Request) []interface{}

func sanitizeHeaders(headers http.Header) (filtered http.Header) {
filtered = headers.Clone()
if authHeader := filtered.Get("Authorization"); authHeader != "" {
Expand All @@ -29,29 +21,18 @@ func sanitizeHeaders(headers http.Header) (filtered http.Header) {
return
}

func setLogger(logger log.Logger, lf ...LoggerFunc) func(delegate http.Handler) http.Handler {

if logger == nil {
panic("The base Logger cannot be nil")
}

func setLogger(logger *zap.Logger) func(delegate http.Handler) http.Handler {
return func(delegate http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
kvs := []interface{}{"requestHeaders", sanitizeHeaders(r.Header), "requestURL", r.URL.EscapedPath(), "method", r.Method}
for _, f := range lf {
if f != nil {
kvs = f(kvs, r)
}
kvs := []zap.Field{zap.Any("requestHeaders", sanitizeHeaders(r.Header)), zap.String("requestURL", r.URL.EscapedPath()), zap.String("method", r.Method)}
traceID, spanID, ok := candlelight.ExtractTraceInfo(r.Context())
if ok {
kvs = append(kvs, zap.String(candlelight.SpanIDLogKeyName, spanID), zap.String(candlelight.TraceIdLogKeyName, traceID))
}
kvs, _ = candlelight.AppendTraceInfo(r.Context(), kvs)
ctx := r.WithContext(logging.WithLogger(r.Context(), log.With(logger, kvs...)))

ctx := r.WithContext(sallust.With(r.Context(), logger.With(kvs...)))
delegate.ServeHTTP(w, ctx)
})
}
}

func getLogger(ctx context.Context) log.Logger {
logger := log.With(logging.GetLogger(ctx), "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
return logger
}
2 changes: 1 addition & 1 deletion basculeValidators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/spf13/cast"
"github.com/xmidt-org/bascule"
"github.com/xmidt-org/webpa-common/v2/basculechecks"
"github.com/xmidt-org/bascule/basculechecks"
)

var requirePartnersJWTClaim bascule.ValidatorFunc = func(_ context.Context, token bascule.Token) error {
Expand Down
105 changes: 95 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
module github.com/xmidt-org/scytale

go 1.12
go 1.19

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.103 // indirect
github.com/go-kit/kit v0.12.0
github.com/go-kit/log v0.2.1
github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b
github.com/gorilla/mux v1.8.0
github.com/hashicorp/consul/api v1.15.2 // indirect
github.com/hashicorp/go-hclog v1.3.1 // indirect
github.com/justinas/alice v1.2.0
github.com/lestrrat-go/jwx/v2 v2.0.6 // indirect
github.com/prometheus/client_golang v1.13.0
github.com/spf13/cast v1.5.0
github.com/spf13/pflag v1.0.5
Expand All @@ -27,8 +21,99 @@ require (
github.com/xmidt-org/webpa-common/v2 v2.0.7
github.com/xmidt-org/wrp-go/v3 v3.1.4
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.36.4
go.opentelemetry.io/otel/exporters/stdout v0.20.0 // indirect
go.uber.org/zap v1.23.0
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect
golang.org/x/net v0.0.0-20220921203646-d300de134e69 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
)

require (
emperror.dev/emperror v0.33.0 // indirect
emperror.dev/errors v0.8.1 // indirect
github.com/VividCortex/gohistogram v1.0.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.126 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/billhathaway/consistentHash v0.0.0-20140718022140-addea16d2229 // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-zookeeper/zk v1.0.3 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/consul/api v1.15.3 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.3.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jtacoma/uritemplates v1.0.0 // indirect
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.4 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.6 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xmidt-org/argus v0.9.3 // indirect
github.com/xmidt-org/arrange v0.3.0 // indirect
github.com/xmidt-org/chronon v0.1.1 // indirect
github.com/xmidt-org/httpaux v0.3.2 // indirect
github.com/xmidt-org/themis v0.4.10 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.11.1 // indirect
go.opentelemetry.io/otel/metric v0.33.0 // indirect
go.opentelemetry.io/otel/sdk v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.15.0 // indirect
go.uber.org/fx v1.18.2 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/tools v0.2.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading