File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff 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.
105116func (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}
You can’t perform that action at this time.
0 commit comments