Skip to content

Commit

Permalink
updated ancla dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Jul 25, 2024
1 parent 50b64af commit 05ab82a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/xmidt-org/wrp-go/v3 v3.2.3
go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.46.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.uber.org/fx v1.22.0
go.uber.org/fx v1.22.1
go.uber.org/zap v1.27.0
gopkg.in/dealancer/validate.v2 v2.1.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1851,8 +1851,8 @@ go.uber.org/fx v1.19.0/go.mod h1:bGK+AEy7XUwTBkqCsK/vDyFF0JJOA6X5KWpNC0e6qTA=
go.uber.org/fx v1.19.1/go.mod h1:bGK+AEy7XUwTBkqCsK/vDyFF0JJOA6X5KWpNC0e6qTA=
go.uber.org/fx v1.19.2/go.mod h1:43G1VcqSzbIv77y00p1DRAsyZS8WdzuYdhZXmEUkMyQ=
go.uber.org/fx v1.20.0/go.mod h1:qCUj0btiR3/JnanEr1TYEePfSw6o/4qYJscgvzQ5Ub0=
go.uber.org/fx v1.22.0 h1:pApUK7yL0OUHMd8vkunWSlLxZVFFk70jR2nKde8X2NM=
go.uber.org/fx v1.22.0/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
go.uber.org/fx v1.22.1 h1:nvvln7mwyT5s1q201YE29V/BFrGor6vMiDNpU/78Mys=
go.uber.org/fx v1.22.1/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI=
go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
Expand Down
1 change: 1 addition & 0 deletions internal/client/httpClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type HttpClientTimeout struct {
// NetDialerTimeout is the net dialer timeout
NetDialerTimeout time.Duration
}

type metricWrapper struct {
now func() time.Time
queryLatency prometheus.ObserverVec
Expand Down
20 changes: 10 additions & 10 deletions internal/sink/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func NewMatcher(l ancla.Register, logger *zap.Logger) (Matcher, error) {
func (m1 *MatcherV1) update(l ancla.RegistryV1) error {

//TODO: don't believe the logger for webhook is being set anywhere just yet
m1.logger = m1.logger.With(zap.String("webhook.address", l.Webhook.Address))
m1.logger = m1.logger.With(zap.String("webhook.address", l.Registration.Address))

if l.Webhook.FailureURL != "" {
_, err := url.ParseRequestURI(l.Webhook.FailureURL)
if l.Registration.FailureURL != "" {
_, err := url.ParseRequestURI(l.Registration.FailureURL)
return err
}

var events []*regexp.Regexp
for _, event := range l.Webhook.Events {
for _, event := range l.Registration.Events {
var re *regexp.Regexp
re, err := regexp.Compile(event)
if err != nil {
Expand All @@ -90,7 +90,7 @@ func (m1 *MatcherV1) update(l ancla.RegistryV1) error {
}

var matcher []*regexp.Regexp
for _, item := range l.Webhook.Matcher.DeviceID {
for _, item := range l.Registration.Matcher.DeviceID {
if item == ".*" {
// Match everything - skip the filtering
matcher = []*regexp.Regexp{}
Expand All @@ -106,11 +106,11 @@ func (m1 *MatcherV1) update(l ancla.RegistryV1) error {
}

// Validate the various urls
urlCount := len(l.Webhook.Config.AlternativeURLs)
urlCount := len(l.Registration.Config.AlternativeURLs)
for i := 0; i < urlCount; i++ {
_, err := url.Parse(l.Webhook.Config.AlternativeURLs[i])
_, err := url.Parse(l.Registration.Config.AlternativeURLs[i])
if err != nil {
m1.logger.Error("failed to update url", zap.Any(metrics.UrlLabel, l.Webhook.Config.AlternativeURLs[i]), zap.Error(err))
m1.logger.Error("failed to update url", zap.Any(metrics.UrlLabel, l.Registration.Config.AlternativeURLs[i]), zap.Error(err))
return err
}
}
Expand All @@ -129,11 +129,11 @@ func (m1 *MatcherV1) update(l ancla.RegistryV1) error {

if urlCount == 0 {
m1.urls = ring.New(1)
m1.urls.Value = l.Webhook.Config.ReceiverURL
m1.urls.Value = l.Registration.Config.ReceiverURL
} else {
ring := ring.New(urlCount)
for i := 0; i < urlCount; i++ {
ring.Value = l.Webhook.Config.AlternativeURLs[i]
ring.Value = l.Registration.Config.AlternativeURLs[i]
ring = ring.Next()
}
m1.urls = ring
Expand Down
12 changes: 6 additions & 6 deletions internal/sink/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestUpdate_MatcherV1(t *testing.T) {
description: "success - with device id",
matcher: matcher,
registry: ancla.RegistryV1{
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Events: []string{"iot"},
Matcher: webhook.MetadataMatcherConfig{
DeviceID: []string{"mac:112233445566"},
Expand All @@ -124,7 +124,7 @@ func TestUpdate_MatcherV1(t *testing.T) {
description: "success - with .* device id",
matcher: matcher,
registry: ancla.RegistryV1{
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Events: []string{"iot"},
Matcher: webhook.MetadataMatcherConfig{
DeviceID: []string{"mac:112233445566", ".*"},
Expand All @@ -140,7 +140,7 @@ func TestUpdate_MatcherV1(t *testing.T) {
description: "failing failureURL",
matcher: matcher,
registry: ancla.RegistryV1{
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
FailureURL: "localhost.io",
},
},
Expand All @@ -150,7 +150,7 @@ func TestUpdate_MatcherV1(t *testing.T) {
description: "missing events",
matcher: matcher,
registry: ancla.RegistryV1{
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Events: []string{},
},
},
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestNewMatcher(t *testing.T) {
description: "RegistryV1 - success",
registry: &ancla.RegistryV1{
PartnerIDs: []string{"comcast"},
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Address: "www.example.com",
Events: []string{"event1", "event2"},
},
Expand All @@ -190,7 +190,7 @@ func TestNewMatcher(t *testing.T) {
description: "RegistryV1 - fail",
registry: &ancla.RegistryV1{
PartnerIDs: []string{"comcast"},
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Address: "www.example.com",
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/sink/sinkSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func getPartnerIds(l ancla.Register) ([]string, error) {
func hideSecret(l ancla.Register) {
switch v := l.(type) {
case *ancla.RegistryV1:
v.Webhook.Config.Secret = "XxxxxX"
v.Registration.Config.Secret = "XxxxxX"
case *ancla.RegistryV2:
for i := range v.Registration.Webhooks {
v.Registration.Webhooks[i].Secret = "XxxxxX"
Expand Down
4 changes: 2 additions & 2 deletions internal/sink/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestNewSink(t *testing.T) {
{
description: "RegistryV1 - success",
listener: &ancla.RegistryV1{
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Config: webhook.DeliveryConfig{
ReceiverURL: "www.example.com",
},
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestNewSink(t *testing.T) {

func TestUpdateSink(t *testing.T) {
listener := &ancla.RegistryV1{
Webhook: webhook.RegistrationV1{
Registration: webhook.RegistrationV1{
Config: webhook.DeliveryConfig{
ReceiverURL: "www.example.com",
},
Expand Down

0 comments on commit 05ab82a

Please sign in to comment.