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)
| 146 | // The tunnel client is used to connect to the tunnel and allows |
| 147 | // for ports to be forwarded locally. |
| 148 | func 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 | } |
no test coverage detected