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

Function getTunnelClient

internal/codespaces/connection/connection.go:152–174  ·  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

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

Callers 1

NewCodespaceConnectionFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected