Skip to content

Commit cd3ba36

Browse files
committed
feat: configurable private location url
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
1 parent 8c1b5d7 commit cd3ba36

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

pkg/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewAPIClient(opts ...ClientOption) (*ClientWithResponses, error) {
3232
}
3333
transport.Proxy = http.ProxyURL(url)
3434
}
35-
35+
3636
client := &http.Client{Transport: transport}
3737
opts = append(opts, WithHTTPClient(client))
3838
opts = append(opts, WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {

pkg/locations/private/dialssh.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ func dialSSH(ctx context.Context, locationId string, sshPrivateKey ed25519.Priva
3535
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
3636
}
3737

38-
targetURL := "private-location.escape.tech:2222"
38+
targetURL := os.Getenv("ESCAPE_PRIVATE_LOCATION_URL")
39+
if targetURL == "" {
40+
targetURL = "private-location.escape.tech:2222"
41+
}
3942
proxyURL := os.Getenv("ESCAPE_REPEATER_PROXY_URL")
40-
43+
4144
log.Info("Getting conn for target: %s", targetURL)
4245
conn, err := getConn(ctx, targetURL, proxyURL)
4346
if ctx.Err() != nil {
@@ -46,7 +49,7 @@ func dialSSH(ctx context.Context, locationId string, sshPrivateKey ed25519.Priva
4649
if err != nil {
4750
return fmt.Errorf("failed to get conn: %w", err)
4851
}
49-
52+
5053
client, err := getClient(targetURL, conn, config)
5154
if err != nil {
5255
return fmt.Errorf("failed to create SSH client: %w", err)

pkg/locations/private/http.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ func (c *bufConn) Read(b []byte) (int, error) {
2020
return c.r.Read(b)
2121
}
2222

23-
2423
func basicAuth(username, password string) string {
2524
auth := username + ":" + password
2625
return base64.StdEncoding.EncodeToString([]byte(auth))
@@ -67,4 +66,4 @@ func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, backendAddr stri
6766
}
6867

6968
return &bufConn{Conn: conn, r: r}, nil
70-
}
69+
}

pkg/locations/private/kube/main.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const (
2020
defaultStaticPrefix = "/static/"
2121
defaultAPIPrefix = "/"
2222
defaultAddress = "127.0.0.1"
23-
2423
)
2524

2625
func inferConfig() (*rest.Config, error) {
@@ -66,11 +65,11 @@ func connectAndRun(ctx context.Context, client *api.ClientWithResponses, cfg *re
6665
return
6766
}
6867
log.Debug("Connected to k8s API")
69-
log.Info("Upserting integration")
70-
err = UpsertIntegration(ctx, client, locationId, locationName)
71-
if err != nil {
72-
log.Error("Error upserting integration: %s", err)
73-
return
68+
log.Info("Upserting integration")
69+
err = UpsertIntegration(ctx, client, locationId, locationName)
70+
if err != nil {
71+
log.Error("Error upserting integration: %s", err)
72+
return
7473
}
7574

7675
<-ctx.Done()
@@ -85,7 +84,6 @@ func connectAndRun(ctx context.Context, client *api.ClientWithResponses, cfg *re
8584
return nil
8685
}
8786

88-
8987
func Start(ctx context.Context, client *api.ClientWithResponses, locationId *types.UUID, locationName string, healthy *atomic.Bool) {
9088
cfg, err := inferConfig()
9189
if err != nil {
@@ -105,6 +103,4 @@ func Start(ctx context.Context, client *api.ClientWithResponses, locationId *typ
105103
log.Info("Healthy: %t", healthy.Load())
106104
}
107105

108-
109106
}
110-

pkg/locations/private/tcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ func netDialerWithTCPKeepalive() *net.Dialer {
2121
})
2222
},
2323
}
24-
}
24+
}

0 commit comments

Comments
 (0)