Skip to content

Commit

Permalink
Merge pull request #6 from webhookrelay/feature/preserve_custom_domain
Browse files Browse the repository at this point in the history
Feature/preserve custom domain
  • Loading branch information
rusenask authored Jun 20, 2020
2 parents e9ad71b + aeadf50 commit fe800c9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ build:
go-gen:
$(OPERATOR_SDK) generate k8s
$(OPERATOR_SDK) generate crds
cp deploy/crds/forward.webhookrelay.com_webhookrelayforwards_crd.yaml charts/webhookrelay-operator/crds/crd.yaml

# Run tests
test:
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/forward/v1/webhookrelayforward_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type InputSpec struct {

// CustomDomain can be used to assign a permanent domain name for your input
// such as example.hooks.webhookrelay.com
CustomDomain string `json:"customDomain,omitempty"`
CustomDomain *string `json:"customDomain,omitempty"`
// PathPrefix can be combined together with CustomDomain to create 'API like'
// functionality where calls from:
// petshop.com/dogs -> are forwarded to [dogs store]
Expand Down
5 changes: 5 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.

38 changes: 29 additions & 9 deletions pkg/controller/webhookrelayforward/sync_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,39 @@ func inputSpecToInput(spec *forwardv1.InputSpec, bucket *webhookrelay.Bucket) *w
}
}

return &webhookrelay.Input{
Name: spec.Name,
BucketID: bucket.ID,
FunctionID: spec.FunctionID,
Headers: spec.ResponseHeaders,
StatusCode: spec.ResponseStatusCode,
Body: spec.ResponseBody,

computedInput := &webhookrelay.Input{
Name: spec.Name,
BucketID: bucket.ID,
FunctionID: spec.FunctionID,
Headers: spec.ResponseHeaders,
StatusCode: spec.ResponseStatusCode,
Body: spec.ResponseBody,
ResponseFromOutput: spec.ResponseFromOutput,
CustomDomain: spec.CustomDomain,
PathPrefix: spec.PathPrefix,
Description: spec.Description,
}

if spec.CustomDomain != nil {
// set, using it
computedInput.CustomDomain = *spec.CustomDomain
} else {
// not set, checking whether there was set one originally and preserving it
original, ok := getInputFromBucket(spec.Name, bucket)
if ok {
computedInput.CustomDomain = original.CustomDomain
}
}

return computedInput
}

func getInputFromBucket(name string, bucket *webhookrelay.Bucket) (*webhookrelay.Input, bool) {
for _, input := range bucket.Inputs {
if input.Name == name {
return input, true
}
}
return nil, false
}

func getInputsDiff(current, desired []*webhookrelay.Input) *inputsDiff {
Expand Down

0 comments on commit fe800c9

Please sign in to comment.