@@ -54,11 +54,6 @@ func main() {
5454 }
5555
5656 var logsEndpoint string
57- if logsEndpointFlag != "" {
58- logsEndpoint = logsEndpointFlag
59- } else {
60- logsEndpoint = fetchLogsEndpoint (controlPlaneURL )
61- }
6257
6358 if isProxy && runtime .GOOS != "linux" {
6459 log .Fatal ("--proxy flag is only supported on Linux" )
@@ -112,6 +107,12 @@ func main() {
112107
113108 log .Printf ("Loaded config: serverID=%s, subnetId=%d, wireguardIP=%s" , config .ServerID , config .SubnetID , config .WireGuardIP )
114109
110+ if logsEndpointFlag != "" {
111+ logsEndpoint = logsEndpointFlag
112+ } else if config .LoggingEndpoint != "" {
113+ logsEndpoint = config .LoggingEndpoint
114+ }
115+
115116 if err := container .EnsureNetwork (config .SubnetID ); err != nil {
116117 log .Printf ("Warning: Failed to ensure container network: %v" , err )
117118 }
@@ -152,12 +153,39 @@ func main() {
152153 log .Fatalf ("Failed to register: %v" , err )
153154 }
154155
156+ var respLoggingEndpoint string
157+ if resp .LoggingEndpoint != nil {
158+ respLoggingEndpoint = * resp .LoggingEndpoint
159+ }
160+
161+ var registryURL , registryUsername , registryPassword string
162+ if resp .RegistryURL != nil {
163+ registryURL = * resp .RegistryURL
164+ }
165+ if resp .RegistryUsername != nil {
166+ registryUsername = * resp .RegistryUsername
167+ }
168+ if resp .RegistryPassword != nil {
169+ registryPassword = * resp .RegistryPassword
170+ }
171+
155172 config = & agent.Config {
156- ServerID : resp .ServerID ,
157- SubnetID : resp .SubnetID ,
158- WireGuardIP : resp .WireGuardIP ,
159- EncryptionKey : resp .EncryptionKey ,
160- IsProxy : isProxy ,
173+ ServerID : resp .ServerID ,
174+ SubnetID : resp .SubnetID ,
175+ WireGuardIP : resp .WireGuardIP ,
176+ EncryptionKey : resp .EncryptionKey ,
177+ IsProxy : isProxy ,
178+ LoggingEndpoint : respLoggingEndpoint ,
179+ RegistryURL : registryURL ,
180+ RegistryUsername : registryUsername ,
181+ RegistryPassword : registryPassword ,
182+ RegistryInsecure : resp .RegistryInsecure ,
183+ }
184+
185+ if logsEndpointFlag != "" {
186+ logsEndpoint = logsEndpointFlag
187+ } else if respLoggingEndpoint != "" {
188+ logsEndpoint = respLoggingEndpoint
161189 }
162190
163191 if err := saveConfig (configPath , config ); err != nil {
@@ -201,6 +229,13 @@ func main() {
201229 }
202230 }
203231
232+ if config .RegistryURL != "" && config .RegistryUsername != "" {
233+ log .Printf ("[registry] attempting login to %s" , config .RegistryURL )
234+ if err := container .Login (config .RegistryURL , config .RegistryUsername , config .RegistryPassword , config .RegistryInsecure ); err != nil {
235+ log .Printf ("[registry] warning: failed to login to registry: %v" , err )
236+ }
237+ }
238+
204239 reconciler := reconcile .NewReconciler (config .EncryptionKey , dataDir )
205240 client := agenthttp .NewClient (controlPlaneURL , config .ServerID , signingKeyPair , dataDir )
206241
@@ -331,35 +366,3 @@ func getPrivateIP() string {
331366
332367 return ""
333368}
334-
335- type discoverResponse struct {
336- LoggingEndpoint * string `json:"loggingEndpoint"`
337- Version int `json:"version"`
338- }
339-
340- func fetchLogsEndpoint (controlPlaneURL string ) string {
341- client := & http.Client {Timeout : 10 * time .Second }
342- resp , err := client .Get (controlPlaneURL + "/api/v1/agent/discover" )
343- if err != nil {
344- log .Printf ("Failed to fetch discovery endpoint: %v" , err )
345- return ""
346- }
347- defer resp .Body .Close ()
348-
349- if resp .StatusCode != http .StatusOK {
350- log .Printf ("Discovery endpoint returned status %d" , resp .StatusCode )
351- return ""
352- }
353-
354- var discovery discoverResponse
355- if err := json .NewDecoder (resp .Body ).Decode (& discovery ); err != nil {
356- log .Printf ("Failed to decode discovery response: %v" , err )
357- return ""
358- }
359-
360- if discovery .LoggingEndpoint == nil {
361- return ""
362- }
363-
364- return * discovery .LoggingEndpoint
365- }
0 commit comments