Skip to content

Commit

Permalink
Merge pull request #13 from webhookrelay/feature/lock_destination_path
Browse files Browse the repository at this point in the history
Feature/lock destination path
  • Loading branch information
rusenask authored Sep 23, 2020
2 parents 05123ff + 87ba80e commit efa917c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 16 deletions.
12 changes: 12 additions & 0 deletions charts/webhookrelay-operator/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ spec:
to send the webhooks. For example it can be http://local-jenkins/ghpr
for Jenkins webhooks or any other URL.
type: string
disabled:
description: Disabled allows disabling destination without
deleting it (when you don't want to send webhooks temporarily)
type: boolean
function_id:
description: FunctionID attaches function to this output.
Functions on output can modify requests that are then
Expand All @@ -124,6 +128,14 @@ spec:
working with internal agents, this option defaults to
True
type: boolean
lockPath:
description: LockPath ensures that the request path cannot
be changed from what is specified in the destination.
For example if request is coming to /v1/webhooks/xxx/github-jenkins,
with lock path 'false' and destination 'http://localhost:8080'
it would go to http://localhost:8080/github-jenkins.
However, with lock path 'true', it will be sent to 'http://localhost:8080'
type: boolean
name:
type: string
overrideHeaders:
Expand Down
12 changes: 12 additions & 0 deletions deploy/crds/forward.webhookrelay.com_webhookrelayforwards_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ spec:
to send the webhooks. For example it can be http://local-jenkins/ghpr
for Jenkins webhooks or any other URL.
type: string
disabled:
description: Disabled allows disabling destination without
deleting it (when you don't want to send webhooks temporarily)
type: boolean
function_id:
description: FunctionID attaches function to this output.
Functions on output can modify requests that are then
Expand All @@ -124,6 +128,14 @@ spec:
working with internal agents, this option defaults to
True
type: boolean
lockPath:
description: LockPath ensures that the request path cannot
be changed from what is specified in the destination.
For example if request is coming to /v1/webhooks/xxx/github-jenkins,
with lock path 'false' and destination 'http://localhost:8080'
it would go to http://localhost:8080/github-jenkins.
However, with lock path 'true', it will be sent to 'http://localhost:8080'
type: boolean
name:
type: string
overrideHeaders:
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/operator-framework/operator-sdk v0.18.1
github.com/spf13/pflag v1.0.5
github.com/webhookrelay/webhookrelay-go v0.2.0
github.com/webhookrelay/webhookrelay-go v0.3.1
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
gotest.tools v2.2.0+incompatible
k8s.io/api v0.18.2
k8s.io/apimachinery v0.18.2
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
Expand Down Expand Up @@ -800,8 +802,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
github.com/webhookrelay/webhookrelay-go v0.2.0 h1:NQvY1hmKDp+IHFgxV9l0rzOuwLEhMN2byj1XP1/9PCA=
github.com/webhookrelay/webhookrelay-go v0.2.0/go.mod h1:rsnaQgbALzIuhedH38OR+Pw+Ym7Dov2B+G+jTMvOKFg=
github.com/webhookrelay/webhookrelay-go v0.3.1 h1:is1NmePYtJWNi/D4fDr+Q+PRY/6APvjT7dILQCpsQdI=
github.com/webhookrelay/webhookrelay-go v0.3.1/go.mod h1:6UFxoObOqbTXI0Gy74Wwm7pQoFDFDLib5R7T2JBeze8=
github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
Expand Down Expand Up @@ -945,6 +947,8 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -1014,6 +1018,8 @@ golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqG
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down Expand Up @@ -1123,8 +1129,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/forward/v1/webhookrelayforward_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ type OutputSpec struct {
// operator is working with internal agents, this option defaults to True
Internal *bool `json:"internal,omitempty"`

// LockPath ensures that the request path cannot be changed from what is
// specified in the destination. For example if request is coming to /v1/webhooks/xxx/github-jenkins,
// with lock path 'false' and destination 'http://localhost:8080' it would go to http://localhost:8080/github-jenkins.
// However, with lock path 'true', it will be sent to 'http://localhost:8080'
LockPath *bool `json:"lockPath,omitempty"`

// Disabled allows disabling destination without deleting it (when you don't want to send webhooks temporarily)
Disabled *bool `json:"disabled,omitempty"`

// Timeout specifies how long agent should wait for the response
Timeout int `json:"timeout,omitempty"`

Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/forward/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 25 additions & 11 deletions pkg/controller/webhookrelayforward/sync_outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,38 +135,44 @@ func desiredOutputs(bucketSpec *forwardv1.BucketSpec, bucket *webhookrelay.Bucke
var desired []*webhookrelay.Output

for i := range bucketSpec.Outputs {
desired = append(desired, inputSpecToOutput(&bucketSpec.Outputs[i], bucket))
desired = append(desired, outputSpecToOutput(&bucketSpec.Outputs[i], bucket))
}

return desired
}

func inputSpecToOutput(spec *forwardv1.OutputSpec, bucket *webhookrelay.Bucket) *webhookrelay.Output {
func outputSpecToOutput(spec *forwardv1.OutputSpec, bucket *webhookrelay.Bucket) *webhookrelay.Output {
header := make(map[string][]string)

internal := true

if spec.Internal != nil {
// set, checking val
internal = *spec.Internal
}

if spec.OverrideHeaders != nil {
for k, v := range spec.OverrideHeaders {
header[k] = []string{v}
}
}

return &webhookrelay.Output{
output := &webhookrelay.Output{
Name: spec.Name,
BucketID: bucket.ID,
FunctionID: spec.FunctionID,
Headers: header,
Destination: spec.Destination,
Timeout: spec.Timeout,
Internal: internal,
Description: spec.Description,
}

if spec.LockPath != nil {
output.LockPath = *spec.LockPath
}

if spec.Disabled != nil {
output.Disabled = *spec.Disabled
}

if spec.Internal != nil {
output.Internal = *spec.Internal
}

return output
}

func outputsEqual(current, desired *webhookrelay.Output) bool {
Expand All @@ -192,6 +198,14 @@ func outputsEqual(current, desired *webhookrelay.Output) bool {
return false
}

if current.LockPath != desired.LockPath {
return false
}

if current.Disabled != desired.Disabled {
return false
}

if current.Timeout != desired.Timeout {
return false
}
Expand Down

0 comments on commit efa917c

Please sign in to comment.