Skip to content

Commit

Permalink
bumped bascule and consul versions (#525)
Browse files Browse the repository at this point in the history
* bumped bascule and consul versions

made necessary function changes for new bascule version

* updated changelog
  • Loading branch information
kristinapathak authored Oct 7, 2020
1 parent d92944d commit 1c2fd55
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 61 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v1.11.1]
### Changed
- Made 6060 pprof server's default address. [#521](https://github.com/xmidt-org/webpa-common/pull/521)
- Bumped bascule version and made attributes-related changes. [#525](https://github.com/xmidt-org/webpa-common/pull/525)

## [v1.11.0]
### Changed
Expand Down Expand Up @@ -160,7 +163,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- The first official release. We will be better about documenting changes
moving forward.

[Unreleased]: https://github.com/xmidt-org/webpa-common/compare/v1.11.0...HEAD
[Unreleased]: https://github.com/xmidt-org/webpa-common/compare/v1.11.1...HEAD
[v1.11.1]: https://github.com/xmidt-org/webpa-common/compare/v1.11.0...v1.11.1
[v1.11.0]: https://github.com/xmidt-org/webpa-common/compare/v1.10.8...v1.11.0
[v1.10.8]: https://github.com/xmidt-org/webpa-common/compare/v1.10.7...v1.10.8
[v1.10.7]: https://github.com/xmidt-org/webpa-common/compare/v1.10.6...v1.10.7
Expand Down
16 changes: 14 additions & 2 deletions basculechecks/capabilitiesvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ var (

const (
CapabilityKey = "capabilities"
PartnerKey = "allowedResources.allowedPartners"
)

var (
partnerKeys = []string{"allowedResources", "allowedPartners"}
)

func PartnerKeys() []string {
return partnerKeys
}

// CapabilityChecker is an object that can determine if a capability provides
// authorization to the endpoint.
type CapabilityChecker interface {
Expand Down Expand Up @@ -123,11 +130,16 @@ func getCapabilities(attributes bascule.Attributes) ([]string, string, error) {
return []string{}, UndeterminedCapabilities, ErrNilAttributes
}

vals, ok := attributes.GetStringSlice(CapabilityKey)
val, ok := attributes.Get(CapabilityKey)
if !ok {
return []string{}, UndeterminedCapabilities, fmt.Errorf("couldn't get capabilities using key %v", CapabilityKey)
}

vals, ok := val.([]string)
if !ok {
return []string{}, UndeterminedCapabilities, fmt.Errorf("capabilities value not the expected string slice: %v", val)
}

if len(vals) == 0 {
return []string{}, EmptyCapabilitiesList, ErrNoVals
}
Expand Down
13 changes: 7 additions & 6 deletions basculechecks/capabilitiesvalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestCapabilitiesValidatorFunc(t *testing.T) {
}
if tc.includeToken {
auth.Token = bascule.NewToken("test", "princ",
bascule.NewAttributesFromMap(map[string]interface{}{CapabilityKey: capabilities}))
bascule.NewAttributes(map[string]interface{}{CapabilityKey: capabilities}))
}
if tc.includeAuth {
ctx = bascule.WithAuthentication(ctx, auth)
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestCapabilitiesValidatorCheck(t *testing.T) {
}
if tc.includeAttributes {
a.Token = bascule.NewToken("test", "princ",
bascule.NewAttributesFromMap(map[string]interface{}{CapabilityKey: capabilities}))
bascule.NewAttributes(map[string]interface{}{CapabilityKey: capabilities}))
}
if tc.includeURL {
goodURL, err := url.Parse("/test")
Expand Down Expand Up @@ -231,6 +231,7 @@ func TestGetCapabilities(t *testing.T) {
goodKeyVal := []string{"cap1", "cap2"}
emptyVal := []string{}
getCapabilitiesErr := errors.New("couldn't get capabilities using key")
badCapabilitiesErr := errors.New("capabilities value not the expected string slice")
tests := []struct {
description string
nilAttributes bool
Expand Down Expand Up @@ -266,21 +267,21 @@ func TestGetCapabilities(t *testing.T) {
keyValue: nil,
expectedVals: emptyVal,
expectedReason: UndeterminedCapabilities,
expectedErr: getCapabilitiesErr,
expectedErr: badCapabilitiesErr,
},
{
description: "Non List Capabilities Error",
keyValue: struct{ string }{"abcd"},
expectedVals: emptyVal,
expectedReason: UndeterminedCapabilities,
expectedErr: getCapabilitiesErr,
expectedErr: badCapabilitiesErr,
},
{
description: "Non String List Capabilities Error",
keyValue: []int{0, 1, 2},
expectedVals: emptyVal,
expectedReason: UndeterminedCapabilities,
expectedErr: getCapabilitiesErr,
expectedErr: badCapabilitiesErr,
},
{
description: "Empty Capabilities Error",
Expand All @@ -298,7 +299,7 @@ func TestGetCapabilities(t *testing.T) {
if tc.missingAttribute {
m = map[string]interface{}{}
}
attributes := bascule.NewAttributesFromMap(m)
attributes := bascule.NewAttributes(m)
if tc.nilAttributes {
attributes = nil
}
Expand Down
8 changes: 6 additions & 2 deletions basculechecks/metricvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ func (m MetricValidator) prepMetrics(auth bascule.Authentication) (string, strin
if auth.Token.Attributes() == nil {
return client, "", "", TokenMissingValues, ErrNilAttributes
}
partnerIDs, ok := auth.Token.Attributes().GetStringSlice(PartnerKey)
partnerVal, ok := bascule.GetNestedAttribute(auth.Token.Attributes(), PartnerKeys()...)
if !ok {
return client, "", "", UndeterminedPartnerID, fmt.Errorf("couldn't get partner IDs from attributes using key %v", PartnerKey)
return client, "", "", UndeterminedPartnerID, fmt.Errorf("couldn't get partner IDs from attributes using keys %v", PartnerKeys())
}
partnerIDs, ok := partnerVal.([]string)
if !ok {
return client, "", "", UndeterminedPartnerID, fmt.Errorf("partner IDs value not the expected string slice: %v", partnerVal)
}
partnerID := DeterminePartnerMetric(partnerIDs)
if auth.Request.URL == nil {
Expand Down
24 changes: 16 additions & 8 deletions basculechecks/metricvalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func TestMetricValidatorFunc(t *testing.T) {
"joweiafuoiuoiwauf",
"it's a match",
}
goodAttributes := bascule.NewAttributesFromMap(map[string]interface{}{
goodAttributes := bascule.NewAttributes(map[string]interface{}{
CapabilityKey: capabilities,
PartnerKey: []string{"meh"},
"allowedResources": map[string]interface{}{
"allowedPartners": []string{"meh"},
},
})

tests := []struct {
Expand Down Expand Up @@ -150,6 +152,7 @@ func TestPrepMetrics(t *testing.T) {
matchingURL = "/fnvvdsjkfji/mac:12345544322345334/geigosj"
client = "special"
prepErr = errors.New("couldn't get partner IDs from attributes")
badValErr = errors.New("partner IDs value not the expected string slice")
goodEndpoint = `/fnvvdsjkfji/.*/geigosj\b`
goodRegex = regexp.MustCompile(goodEndpoint)
unusedEndpoint = `/a/b\b`
Expand Down Expand Up @@ -225,7 +228,7 @@ func TestPrepMetrics(t *testing.T) {
expectedPartner: "",
expectedEndpoint: "",
expectedReason: UndeterminedPartnerID,
expectedErr: prepErr,
expectedErr: badValErr,
},
{
description: "Non Slice Partner ID Error",
Expand All @@ -236,7 +239,7 @@ func TestPrepMetrics(t *testing.T) {
expectedPartner: "",
expectedEndpoint: "",
expectedReason: UndeterminedPartnerID,
expectedErr: prepErr,
expectedErr: badValErr,
},
{
description: "Nil URL Error",
Expand All @@ -262,11 +265,16 @@ func TestPrepMetrics(t *testing.T) {
// setup auth
token := bascule.NewToken("mehType", client, nil)
if tc.includeAttributes {
a := map[string]interface{}{}
if !tc.noPartnerID {
a[PartnerKey] = tc.partnerIDs
a := map[string]interface{}{
"allowedResources": map[string]interface{}{
"allowedPartners": tc.partnerIDs,
},
}

if tc.noPartnerID {
a["allowedResources"] = 5
}
attributes := bascule.NewAttributesFromMap(a)
attributes := bascule.NewAttributes(a)
token = bascule.NewToken("mehType", client, attributes)
}
auth := bascule.Authentication{
Expand Down
24 changes: 8 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/GaryBoone/GoStats v0.0.0-20130122001700-1993eafbef57 // indirect
github.com/SermoDigital/jose v0.9.2-0.20161205224733-f6df55f235c2
github.com/aws/aws-sdk-go v1.8.12
github.com/aws/aws-sdk-go v1.15.24
github.com/billhathaway/consistentHash v0.0.0-20140718022140-addea16d2229
github.com/c9s/goprocinfo v0.0.0-20151025191153-19cb9f127a9c
github.com/cenk/backoff v2.0.0+incompatible // indirect
Expand All @@ -14,39 +14,31 @@ require (
github.com/go-ini/ini v1.36.1-0.20180420150025-bda519ae5f4c // indirect
github.com/go-kit/kit v0.9.0
github.com/goph/emperror v0.17.3-0.20190703203600-60a8d9faa17b
github.com/gorilla/mux v1.7.3
github.com/gorilla/mux v1.7.4
github.com/gorilla/schema v1.0.3-0.20180614150749-e0e4b92809ac
github.com/gorilla/websocket v1.4.0
github.com/hashicorp/consul v1.4.2
github.com/hashicorp/go-cleanhttp v0.5.0 // indirect
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/consul/api v1.7.0
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect
github.com/hashicorp/memberlist v0.1.5 // indirect
github.com/hashicorp/serf v0.8.2-0.20180907130240-48d579458173 // indirect
github.com/influxdata/influxdb v1.5.1-0.20180921190457-8d679cf0c36e // indirect
github.com/influxdata/influxdb1-client v0.0.0-20200515024757-02f0bf5dbca3 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/jtacoma/uritemplates v1.0.0
github.com/justinas/alice v1.2.0
github.com/miekg/dns v1.0.14
github.com/mitchellh/go-homedir v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/miekg/dns v1.1.26
github.com/pascaldekloe/goe v0.1.0 // indirect
github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea // indirect
github.com/pkg/errors v0.8.1-0.20181008045315-2233dee583dc // indirect
github.com/prometheus/client_golang v1.1.0
github.com/rubyist/circuitbreaker v2.2.0+incompatible
github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec
github.com/segmentio/ksuid v1.0.2
github.com/spf13/cast v1.3.0
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.6.1
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.4.0
github.com/ugorji/go/codec v1.1.7
github.com/xmidt-org/bascule v0.8.0
github.com/xmidt-org/bascule v0.9.0
github.com/xmidt-org/themis v0.4.4
github.com/xmidt-org/wrp-go/v3 v3.0.1
go.uber.org/fx v1.12.0
go.uber.org/fx v1.13.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0

)
Loading

0 comments on commit 1c2fd55

Please sign in to comment.