Skip to content

Commit d03c705

Browse files
committed
venconn: the server field in config can now be omitted
1 parent 8a34fcf commit d03c705

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

pkg/agent/config.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,22 @@ func getConfiguration(log *log.Logger, cfg Config, flags AgentCmdFlags) (Config,
267267
flags.VenafiCloudMode = true
268268
}
269269

270-
baseURL := cfg.Server
271-
if baseURL == "" {
272-
log.Printf("Using deprecated Endpoint configuration. User Server instead.")
273-
baseURL = fmt.Sprintf("%s://%s", cfg.Endpoint.Protocol, cfg.Endpoint.Host)
274-
_, err := url.Parse(baseURL)
275-
if err != nil {
276-
return Config{}, nil, fmt.Errorf("failed to parse server URL: %w", err)
270+
// In VenafiConnection mode, we don't need the server field. For the other
271+
// modes, we do need to validate the server field.
272+
var baseURL string
273+
if flags.VenConnName != "" {
274+
if cfg.Server != "" {
275+
log.Printf("ignoring the server field specified in the config file. In Venafi Connection mode, this field is not needed. Use the VenafiConnection's spec.vcp.url field instead.")
276+
}
277+
} else {
278+
baseURL = cfg.Server
279+
if baseURL == "" {
280+
log.Printf("Using deprecated Endpoint configuration. User Server instead.")
281+
baseURL = fmt.Sprintf("%s://%s", cfg.Endpoint.Protocol, cfg.Endpoint.Host)
282+
_, err := url.Parse(baseURL)
283+
if err != nil {
284+
return Config{}, nil, fmt.Errorf("failed to parse server URL: %w", err)
285+
}
277286
}
278287
}
279288

pkg/agent/config_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestGetConfiguration(t *testing.T) {
178178
assert.Equal(t, Config{}, got)
179179
})
180180

181-
t.Run("warning about venafi-cloud.uploader_id and venafi-cloud.upload_path being skipped", func(t *testing.T) {
181+
t.Run("warning about server, venafi-cloud.uploader_id, and venafi-cloud.upload_path being skipped", func(t *testing.T) {
182182
log, out := withLogs(t)
183183
cfg := fillRequired(Config{VenafiCloud: &VenafiCloudConfig{
184184
UploaderID: "test-agent",
@@ -191,6 +191,17 @@ func TestGetConfiguration(t *testing.T) {
191191
assert.Equal(t, cfg, got)
192192
assert.Contains(t, out.String(), "ignoring venafi-cloud.uploader_id")
193193
assert.Contains(t, out.String(), "ignoring venafi-cloud.upload_path")
194+
assert.Contains(t, out.String(), "ignoring the server field")
195+
})
196+
197+
t.Run("server field can be left empty in venconn mode", func(t *testing.T) {
198+
_, _, err := getConfiguration(discardLogs(t),
199+
withConfig(testutil.Undent(`
200+
server: ""
201+
period: 1h`,
202+
)),
203+
withCmdLineFlags("--venafi-connection", "venafi-components", "--install-namespace", "venafi"))
204+
assert.NoError(t, err)
194205
})
195206
})
196207
}
@@ -567,7 +578,8 @@ func discardLogs(_ testing.TB) *log.Logger {
567578
return log.New(io.Discard, "", 0)
568579
}
569580

570-
// Shortcut for ParseConfig.
581+
// ParseConfig does some validation but we don't want this extra validation, so
582+
// this is just using yaml.Unmarshal.
571583
func withConfig(s string) Config {
572584
var cfg Config
573585

pkg/testutil/testutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ type AssertRequest func(t testing.TB, r *http.Request)
191191
func FakeVenafiCloud(t *testing.T) (_ *httptest.Server, _ *x509.Certificate, setAssert func(AssertRequest)) {
192192
t.Helper()
193193

194-
var assertFn AssertRequest
194+
assertFn := func(_ testing.TB, _ *http.Request) {}
195195
assertFnMu := sync.Mutex{}
196196
setAssert = func(setAssert AssertRequest) {
197197
assertFnMu.Lock()

0 commit comments

Comments
 (0)