Skip to content

Commit 01f0c1f

Browse files
committed
add https:// to --server URL if not provided
1 parent b675a2a commit 01f0c1f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmd/agent/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,25 @@ type Agent struct {
101101
user string
102102
}
103103

104+
// normalizeServerURL ensures the server URL has a protocol and removes trailing slash.
105+
func normalizeServerURL(url string) string {
106+
// Add https:// if no protocol is specified
107+
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
108+
log.Printf("[INFO] No protocol specified for %s, using https://", url)
109+
url = "https://" + url
110+
}
111+
// Remove trailing slash
112+
return strings.TrimSuffix(url, "/")
113+
}
114+
104115
// handleInstall handles the agent installation process.
105116
func (a *Agent) handleInstall() error {
106117
if *server == "" || *join == "" {
107118
return errors.New("--server and --join flags are required for installation")
108119
}
109120

110121
// Set up agent configuration for verification
111-
a.serverURL = strings.TrimSuffix(*server, "/")
122+
a.serverURL = normalizeServerURL(*server)
112123
a.joinKey = *join
113124

114125
// Verify server connection and join key by sending a test report
@@ -206,7 +217,7 @@ func (a *Agent) configureServerConnection() error {
206217
}
207218
}
208219

209-
a.serverURL = strings.TrimSuffix(*server, "/")
220+
a.serverURL = normalizeServerURL(*server)
210221
a.joinKey = *join
211222
return nil
212223
}

0 commit comments

Comments
 (0)