getTunnelManager creates a tunnel manager for the given codespace. The tunnel manager is used to get the tunnel hosted in the codespace that we want to connect to and perform operations on ports (add, remove, list, etc.).
(tunnelProperties api.TunnelProperties, httpClient *http.Client)
| 129 | // The tunnel manager is used to get the tunnel hosted in the codespace that we |
| 130 | // want to connect to and perform operations on ports (add, remove, list, etc.). |
| 131 | func getTunnelManager(tunnelProperties api.TunnelProperties, httpClient *http.Client) (tunnelManager *tunnels.Manager, err error) { |
| 132 | userAgent := []tunnels.UserAgent{{Name: clientName}} |
| 133 | url, err := url.Parse(tunnelProperties.ServiceUri) |
| 134 | if err != nil { |
| 135 | return nil, fmt.Errorf("error parsing tunnel service uri: %w", err) |
| 136 | } |
| 137 | |
| 138 | // Create the tunnel manager |
| 139 | // This api version seems to be the only acceptable api version: https://github.com/microsoft/dev-tunnels/blob/bf96ae5a128041d1a23f81d53a47e9e6c26fdc8d/go/tunnels/manager.go#L66 |
| 140 | apiVersion := "2023-09-27-preview" |
| 141 | tunnelManager, err = tunnels.NewManager(userAgent, nil, url, httpClient, apiVersion) |
| 142 | if err != nil { |
| 143 | return nil, fmt.Errorf("error creating tunnel manager: %w", err) |
| 144 | } |
| 145 | |
| 146 | return tunnelManager, nil |
| 147 | } |
| 148 | |
| 149 | // getTunnelClient creates a tunnel client for the given tunnel. |
| 150 | // The tunnel client is used to connect to the tunnel and allows |
no test coverage detected