Skip to content

Commit 3bb63fe

Browse files
Add GetClient helper to workspace network package
1 parent 2557f41 commit 3bb63fe

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

pkg/credentials/server.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import (
1111
"os"
1212
"path/filepath"
1313
"strconv"
14-
"time"
1514

1615
"github.com/loft-sh/devpod/pkg/agent/tunnel"
1716
locald "github.com/loft-sh/devpod/pkg/daemon/local"
18-
workspaced "github.com/loft-sh/devpod/pkg/daemon/workspace"
1917
network "github.com/loft-sh/devpod/pkg/daemon/workspace/network"
2018
devpodlog "github.com/loft-sh/devpod/pkg/log"
2119
"github.com/loft-sh/devpod/pkg/ts"
@@ -159,19 +157,9 @@ func handleGitCredentialsOverTSNet(ctx context.Context, writer http.ResponseWrit
159157
defer request.Body.Close()
160158

161159
log.Infof("Received git credentials post data: %s", string(bodyBytes))
162-
// Set up HTTP transport that uses our network socket.
163-
socketPath := filepath.Join(workspaced.RootDir, network.NetworkProxySocket)
164-
transport := &http.Transport{
165-
Dial: func(network, addr string) (net.Conn, error) {
166-
return net.Dial("unix", socketPath)
167-
},
168-
}
169-
170-
client := &http.Client{
171-
Transport: transport,
172-
Timeout: 30 * time.Second, // TODO: extract this to config
173-
}
174160

161+
// Create a DevPod network client to local credentials server
162+
client := network.GetClient()
175163
credServerAddress := ts.EnsureURL(clientHost, locald.LocalCredentialsServerPort)
176164
targetURL := fmt.Sprintf("http://%s%s", credServerAddress, request.URL.RequestURI())
177165

@@ -183,7 +171,7 @@ func handleGitCredentialsOverTSNet(ctx context.Context, writer http.ResponseWrit
183171
}
184172
newReq.Header = request.Header.Clone()
185173

186-
log.Infof("Forwarding request to %s via socket %s", targetURL, socketPath)
174+
log.Infof("Forwarding request to %s", targetURL)
187175

188176
// Execute the request.
189177
resp, err := client.Do(newReq)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package network
2+
3+
import (
4+
"net"
5+
"net/http"
6+
"path/filepath"
7+
"time"
8+
)
9+
10+
// GetClient returns a new HTTP client that uses a DevPod network socket for communication.
11+
func GetClient() *http.Client {
12+
// Set up HTTP transport that uses our network socket.
13+
socketPath := filepath.Join(RootDir, NetworkProxySocket)
14+
transport := &http.Transport{
15+
Dial: func(network, addr string) (net.Conn, error) {
16+
return net.Dial("unix", socketPath)
17+
},
18+
}
19+
20+
client := &http.Client{
21+
Transport: transport,
22+
Timeout: 30 * time.Second, // TODO: extract this to config
23+
}
24+
25+
return client
26+
}

pkg/daemon/workspace/network/port_forward.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818

1919
RunnerProxySocket string = "runner-proxy.sock"
2020
NetworkProxySocket string = "devpod-net.sock"
21+
RootDir string = "/var/devpod"
2122

2223
netMapCooldown = 30 * time.Second
2324
)

0 commit comments

Comments
 (0)