MCPcopy Index your code
hub / github.com/cli/cli / getTunnelClient

Function getTunnelClient

internal/codespaces/connection/connection.go:148–170  ·  view source on GitHub ↗

getTunnelClient creates a tunnel client for the given tunnel. The tunnel client is used to connect to the tunnel and allows for ports to be forwarded locally.

(ctx context.Context, tunnelManager *tunnels.Manager, tunnel *tunnels.Tunnel, options *tunnels.TunnelRequestOptions)

Source from the content-addressed store, hash-verified

146// The tunnel client is used to connect to the tunnel and allows
147// for ports to be forwarded locally.
148func getTunnelClient(ctx context.Context, tunnelManager *tunnels.Manager, tunnel *tunnels.Tunnel, options *tunnels.TunnelRequestOptions) (tunnelClient *TunnelClient, err error) {
149 // Get the tunnel that we want to connect to
150 codespaceTunnel, err := tunnelManager.GetTunnel(ctx, tunnel, options)
151 if err != nil {
152 return nil, fmt.Errorf("error getting tunnel: %w", err)
153 }
154
155 // Copy the access tokens from the tunnel definition
156 codespaceTunnel.AccessTokens = tunnel.AccessTokens
157
158 // We need to pass false for accept local connections because we don't want to automatically connect to all forwarded ports
159 client, err := tunnels.NewClient(log.New(io.Discard, "", log.LstdFlags), codespaceTunnel, false)
160 if err != nil {
161 return nil, fmt.Errorf("error creating tunnel client: %w", err)
162 }
163
164 tunnelClient = &TunnelClient{
165 Client: client,
166 connected: false,
167 }
168
169 return tunnelClient, nil
170}

Callers 1

NewCodespaceConnectionFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected