Allow override of discovery URL via ConfigMap

Signed-off-by: Andrew Keesler <akeesler@vmware.com>

- Seems like the next step is to allow override of the CA bundle; I didn't
  do that here for simplicity of the commit, but seems like it is the right
  thing to do in the future.
This commit is contained in:
Andrew Keesler
2020-08-03 10:17:11 -04:00
parent 548874a641
commit 597408a977
14 changed files with 167 additions and 49 deletions
+11 -1
View File
@@ -7,7 +7,8 @@ package api
// Config contains knobs to setup an instance of placeholder-name.
type Config struct {
WebhookConfig WebhookConfigSpec `json:"webhook"`
WebhookConfig WebhookConfigSpec `json:"webhook"`
DiscoveryConfig DiscoveryConfigSpec `json:"discovery"`
}
// WebhookConfig contains configuration knobs specific to placeholder-name's use
@@ -21,3 +22,12 @@ type WebhookConfigSpec struct {
// to validate TLS connections to the WebhookURL.
CABundle []byte `json:"caBundle"`
}
// DiscoveryConfigSpec contains configuration knobs specific to
// placeholder-name's publishing of discovery information. These values can be
// viewed as overrides, i.e., if these are set, then placeholder-name will
// publish these values in its discovery document instead of the ones it finds.
type DiscoveryConfigSpec struct {
// URL contains the URL at which placeholder-name can be contacted.
URL *string `json:"url,omitempty"`
}
+45 -9
View File
@@ -14,14 +14,50 @@ import (
)
func TestFromPath(t *testing.T) {
expect := require.New(t)
config, err := FromPath("testdata/happy.yaml")
expect.NoError(err)
expect.Equal(config, &api.Config{
WebhookConfig: api.WebhookConfigSpec{
URL: "https://tuna.com/fish?marlin",
CABundle: []byte("-----BEGIN CERTIFICATE-----..."),
tests := []struct {
name string
path string
wantConfig *api.Config
}{
{
name: "Happy",
path: "testdata/happy.yaml",
wantConfig: &api.Config{
DiscoveryConfig: api.DiscoveryConfigSpec{
URL: stringPtr("https://some.discovery/url"),
},
WebhookConfig: api.WebhookConfigSpec{
URL: "https://tuna.com/fish?marlin",
CABundle: []byte("-----BEGIN CERTIFICATE-----..."),
},
},
},
})
{
name: "NoDiscovery",
path: "testdata/no-discovery.yaml",
wantConfig: &api.Config{
DiscoveryConfig: api.DiscoveryConfigSpec{
URL: nil,
},
WebhookConfig: api.WebhookConfigSpec{
URL: "https://tuna.com/fish?marlin",
CABundle: []byte("-----BEGIN CERTIFICATE-----..."),
},
},
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
config, err := FromPath(test.path)
require.NoError(t, err)
require.Equal(t, test.wantConfig, config)
})
}
}
func stringPtr(s string) *string {
sPtr := new(string)
*sPtr = s
return sPtr
}
+2
View File
@@ -1,4 +1,6 @@
---
discovery:
url: https://some.discovery/url
webhook:
url: https://tuna.com/fish?marlin
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tLi4u
+5
View File
@@ -0,0 +1,5 @@
---
webhook:
url: https://tuna.com/fish?marlin
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tLi4u