|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
| 7 | + "os" |
7 | 8 | "time" |
8 | 9 |
|
9 | 10 | "github.com/AlecAivazis/survey/v2" |
@@ -47,7 +48,13 @@ func newCreateCmd(app *App) *cobra.Command { |
47 | 48 |
|
48 | 49 | // Create creates a new Codespace |
49 | 50 | func (a *App) Create(ctx context.Context, opts createOptions) error { |
50 | | - locationCh := getLocation(ctx, a.apiClient) |
| 51 | + |
| 52 | + // Overrides for Codespace developers to target test environments |
| 53 | + vscsLocation := os.Getenv("VSCS_LOCATION") |
| 54 | + vscsTarget := os.Getenv("VSCS_TARGET") |
| 55 | + vscsTargetUrl := os.Getenv("VSCS_TARGET_URL") |
| 56 | + |
| 57 | + locationCh := getLocation(ctx, vscsLocation, a.apiClient) |
51 | 58 |
|
52 | 59 | userInputs := struct { |
53 | 60 | Repository string |
@@ -117,6 +124,8 @@ func (a *App) Create(ctx context.Context, opts createOptions) error { |
117 | 124 | Branch: branch, |
118 | 125 | Machine: machine, |
119 | 126 | Location: locationResult.Location, |
| 127 | + VSCSTarget: vscsTarget, |
| 128 | + VSCSTargetURL: vscsTargetUrl, |
120 | 129 | IdleTimeoutMinutes: int(opts.idleTimeout.Minutes()), |
121 | 130 | PermissionsOptOut: opts.permissionsOptOut, |
122 | 131 | } |
@@ -282,9 +291,18 @@ type locationResult struct { |
282 | 291 | Err error |
283 | 292 | } |
284 | 293 |
|
285 | | -// getLocation fetches the closest Codespace datacenter region/location to the user. |
286 | | -func getLocation(ctx context.Context, apiClient apiClient) <-chan locationResult { |
| 294 | +// getLocation fetches the closest Codespace datacenter |
| 295 | +// region/location to the user, unless the 'vscsLocationOverride' override is set |
| 296 | +func getLocation(ctx context.Context, vscsLocationOverride string, apiClient apiClient) <-chan locationResult { |
287 | 297 | ch := make(chan locationResult, 1) |
| 298 | + |
| 299 | + // Developer override is set, return the override |
| 300 | + if vscsLocationOverride != "" { |
| 301 | + ch <- locationResult{vscsLocationOverride, nil} |
| 302 | + return ch |
| 303 | + } |
| 304 | + |
| 305 | + // Dynamically fetch the region location |
288 | 306 | go func() { |
289 | 307 | location, err := apiClient.GetCodespaceRegionLocation(ctx) |
290 | 308 | ch <- locationResult{location, err} |
|
0 commit comments