Skip to content

Commit

Permalink
bumped ancla, updating v3 post hook endpoint (#270)
Browse files Browse the repository at this point in the history
* bumped wrp-go, updating v3 post hook endpoint

* fixed v2 endpoint

* updated changelog, prep for release

* handle case where both duration and until are unset
  • Loading branch information
kristinapathak authored Apr 28, 2022
1 parent 2cba741 commit 1543ee0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.7.3]
- Bumped ancla to v0.3.9 to fix Duration bug in webhook registration - Duration should be an int in seconds. It will also accept strings such as "5m". [#270](https://github.com/xmidt-org/tr1d1um/pull/270)
- Updated v2 webhook registration to allow for no Duration or Until set. [#270](https://github.com/xmidt-org/tr1d1um/pull/270)

## [v0.7.2]
- Fixed v2 endpoint to allow for invalid duration or until fields. When they are invalid, the duration of the webhook is set to the configured maximum. [#266](https://github.com/xmidt-org/tr1d1um/pull/266)

Expand Down Expand Up @@ -138,7 +142,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Initial creation.

[Unreleased]: https://github.com/xmidt-org/tr1d1um/compare/v0.7.2...HEAD
[Unreleased]: https://github.com/xmidt-org/tr1d1um/compare/v0.7.3...HEAD
[v0.7.3]: https://github.com/xmidt-org/tr1d1um/compare/v0.7.2...v0.7.3
[v0.7.2]: https://github.com/xmidt-org/tr1d1um/compare/v0.7.1...v0.7.2
[v0.7.1]: https://github.com/xmidt-org/tr1d1um/compare/v0.7.0...v0.7.1
[v0.7.0]: https://github.com/xmidt-org/tr1d1um/compare/v0.6.4...v0.7.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
github.com/xmidt-org/ancla v0.3.5
github.com/xmidt-org/ancla v0.3.9
github.com/xmidt-org/bascule v0.10.2
github.com/xmidt-org/candlelight v0.0.5
github.com/xmidt-org/webpa-common/v2 v2.0.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -708,15 +708,15 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vmware/govmomi v0.18.0/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xmidt-org/ancla v0.3.5 h1:zXDFTxZHVl5UTyIFQYB2FdQRMlAcp16MMEOYagIdCeo=
github.com/xmidt-org/ancla v0.3.5/go.mod h1:UO6v7K+KQ7OtFi0nFF4zAZRMW9T83m4mZqw6iirQSs4=
github.com/xmidt-org/ancla v0.3.9 h1:+TRzSPRCUjdx6imCOylvyOtocfzYTbpWSBtw9+9dYj8=
github.com/xmidt-org/ancla v0.3.9/go.mod h1:gkucjfyH7zDvCJCQTx++E2iaMugBNrq0G1OGzE2nzIs=
github.com/xmidt-org/argus v0.3.9/go.mod h1:mDFS44R704gl9Fif3gkfAyvnZa53SvMepmXjYWABPvk=
github.com/xmidt-org/argus v0.3.10-0.20201105190057-402fede05764/go.mod h1:lnMCVB/i0gOlUOOd2WbzDDgzTEqP5TipzQ8xKIw+N/I=
github.com/xmidt-org/argus v0.3.10-0.20201217204602-66f69b12c498/go.mod h1:lnMCVB/i0gOlUOOd2WbzDDgzTEqP5TipzQ8xKIw+N/I=
github.com/xmidt-org/argus v0.3.12/go.mod h1:T0oHbqQ1SAjE616Q9f1p+7nsmuvmHNoC0zAIUpUiFuE=
github.com/xmidt-org/argus v0.5.1/go.mod h1:cnx+z2O5mwhS/mCtvbVatZhZ8npBQSaXlzDk5RT3SkM=
github.com/xmidt-org/argus v0.6.0 h1:cjAeyILtyGSvUv02e4wEpUdYtgd1EYoFtwfjC5JroQ8=
github.com/xmidt-org/argus v0.6.0/go.mod h1:IRVJlpd8JsoWXhys8o6tFU+dZi9Q6YWTX1Wn3AkyEkI=
github.com/xmidt-org/argus v0.8.0 h1:xYLn9lLNEjR24OiLBrxEsgOzMIb50IFFmagK6TebMqU=
github.com/xmidt-org/argus v0.8.0/go.mod h1:IRVJlpd8JsoWXhys8o6tFU+dZi9Q6YWTX1Wn3AkyEkI=
github.com/xmidt-org/arrange v0.1.9/go.mod h1:PRA8iEZ11L93NsEkDP56x1mZyfDcWxzDULgHj56TaEk=
github.com/xmidt-org/arrange v0.3.0 h1:YNO+1lufCx3EeN17xuSRMC1sci9y9rzZVZ+TkWwq9QE=
github.com/xmidt-org/arrange v0.3.0/go.mod h1:pCHeb93OFA0QnEJ//Mmly7QqUt7y/w3xllK0VQ3Bigo=
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func tr1d1um(arguments []string) (exitCode int) {
}

webhookConfig.Logger = logger
webhookConfig.MetricsProvider = metricsRegistry
webhookConfig.Measures = *ancla.NewMeasures(metricsRegistry)
argusClientTimeout, err := newArgusClientTimeout(v)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse argus client timeout config values: %s \n", err.Error())
Expand All @@ -188,7 +188,6 @@ func tr1d1um(arguments []string) (exitCode int) {
}

addWebhookHandler := ancla.NewAddWebhookHandler(svc, ancla.HandlerConfig{
MetricsProvider: metricsRegistry,
V: builtValidators,
DisablePartnerIDs: webhookConfig.DisablePartnerIDs,
GetLogger: getLogger,
Expand Down
29 changes: 18 additions & 11 deletions primaryHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func fixV2Duration(getLogger ancla.GetLoggerFunc, config ancla.TTLVConfig) (alic
return
}

var webhook ancla.Webhook
err = json.Unmarshal(requestPayload, &webhook)
var wr ancla.WebhookRegistration
err = json.Unmarshal(requestPayload, &wr)
if err != nil {
var e *json.UnmarshalTypeError
if errors.As(err, &e) {
Expand All @@ -295,27 +295,34 @@ func fixV2Duration(getLogger ancla.GetLoggerFunc, config ancla.TTLVConfig) (alic
return
}

// check to see if the webhook has a valid until/duration.
// If not, set it to 5m.
// check to see if the Webhook has a valid until/duration.
// If not, set the WebhookRegistration duration to 5m.
webhook := wr.ToWebhook()
if webhook.Until.IsZero() {
durationErr := durationCheck(webhook)
if durationErr != nil {
webhook.Duration = config.Max
if webhook.Duration == 0 {
wr.Duration = ancla.CustomDuration(config.Max)
w.Header().Add(v2WarningHeader,
fmt.Sprintf("Invalid duration will not be accepted in v3: %v, webhook duration defaulted to %v", durationErr, config.Max))
fmt.Sprintf("Unset duration and until fields will not be accepted in v3, webhook duration defaulted to %v", config.Max))
} else {
durationErr := durationCheck(webhook)
if durationErr != nil {
wr.Duration = ancla.CustomDuration(config.Max)
w.Header().Add(v2WarningHeader,
fmt.Sprintf("Invalid duration will not be accepted in v3: %v, webhook duration defaulted to %v", durationErr, config.Max))
}
}
} else {
untilErr := untilCheck(webhook)
if untilErr != nil {
webhook.Until = time.Time{}
webhook.Duration = config.Max
wr.Until = time.Time{}
wr.Duration = ancla.CustomDuration(config.Max)
w.Header().Add(v2WarningHeader,
fmt.Sprintf("Invalid until value will not be accepted in v3: %v, webhook duration defaulted to 5m", untilErr))
}
}

// put the body back in the request
body, err := json.Marshal(webhook)
body, err := json.Marshal(wr)
if err != nil {
v2ErrEncode(w, logger, fmt.Errorf("failed to recreate request body: %v", err), 0)
}
Expand Down

0 comments on commit 1543ee0

Please sign in to comment.