From 5852f797d9c0021cda0f0c5d4054c466a6058794 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Fri, 10 Oct 2025 10:08:21 -0300 Subject: [PATCH] Server URL normalization --- README.md | 1 + cmd/root.go | 7 +++++++ test/e2e/config.bats | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/README.md b/README.md index c30de62..5d2384d 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,7 @@ orkes config delete --profile staging -y - `config list` shows all available profiles in `~/.conductor-cli/` directory - Delete operations require confirmation unless `-y` flag is used - Both positional argument and `--profile` flag work for delete command +- Server URLs can be provided with or without `/api` suffix (e.g., `http://localhost:8080` or `http://localhost:8080/api`). ## Workflow Metadata Management diff --git a/cmd/root.go b/cmd/root.go index 569cf51..1a3de2b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "time" ) @@ -76,6 +77,12 @@ var rootCmd = &cobra.Command{ url = "http://localhost:8080/api" } + // Ensure URL has /api suffix for SDK + url = strings.TrimSuffix(url, "/") + if !strings.HasSuffix(url, "/api") { + url = url + "/api" + } + log.Debug("Using Server ", url) apiClient := client.NewAPIClient(settings.NewAuthenticationSettings(key, secret), settings.NewHttpSettings(url)) diff --git a/test/e2e/config.bats b/test/e2e/config.bats index 7bcdbc7..b15143b 100755 --- a/test/e2e/config.bats +++ b/test/e2e/config.bats @@ -182,3 +182,41 @@ teardown() { # Clean up rm -f ~/.conductor-cli/config-e2e-default-check.yaml } + +@test "13. Server URL without /api suffix is accepted" { + # Test URL without /api + run bash -c "./orkes --server http://example.com --auth-key key --profile e2e-noapi config save 2>/dev/null" + [ "$status" -eq 0 ] + + # Verify config was saved with user's input (not normalized) + [ -f ~/.conductor-cli/config-e2e-noapi.yaml ] + grep -q "server: http://example.com" ~/.conductor-cli/config-e2e-noapi.yaml + + # Clean up + rm -f ~/.conductor-cli/config-e2e-noapi.yaml +} + +@test "14. Server URL with /api suffix is accepted" { + # Test URL with /api + run bash -c "./orkes --server http://example.com/api --auth-key key --profile e2e-withapi config save 2>/dev/null" + [ "$status" -eq 0 ] + + # Verify config was saved + [ -f ~/.conductor-cli/config-e2e-withapi.yaml ] + + # Clean up + rm -f ~/.conductor-cli/config-e2e-withapi.yaml +} + +@test "15. Server URL with trailing slash is handled" { + # Test URL with trailing slash + run bash -c "./orkes --server http://example.com/ --auth-key key --profile e2e-slash config save 2>/dev/null" + [ "$status" -eq 0 ] + + # Verify config was saved with trailing slash (user's input preserved) + [ -f ~/.conductor-cli/config-e2e-slash.yaml ] + grep -q "server: http://example.com/" ~/.conductor-cli/config-e2e-slash.yaml + + # Clean up + rm -f ~/.conductor-cli/config-e2e-slash.yaml +}