Adds internal codespace developer flags (#5287)

This commit is contained in:
Josh Spicer 2022-03-09 10:59:29 -05:00 committed by GitHub
parent e0045f26b9
commit 4d5ce7aa56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View file

@ -0,0 +1,5 @@
{
"extensions": [
"golang.go"
]
}

View file

@ -579,6 +579,8 @@ type CreateCodespaceParams struct {
Branch string
Machine string
Location string
VSCSTarget string
VSCSTargetURL string
PermissionsOptOut bool
}
@ -625,6 +627,8 @@ type startCreateRequest struct {
Ref string `json:"ref"`
Location string `json:"location"`
Machine string `json:"machine"`
VSCSTarget string `json:"vscs_target,omitempty"`
VSCSTargetURL string `json:"vscs_target_url,omitempty"`
PermissionsOptOut bool `json:"devcontainer_permissions_opt_out"`
}
@ -654,8 +658,11 @@ func (a *API) startCreate(ctx context.Context, params *CreateCodespaceParams) (*
Ref: params.Branch,
Location: params.Location,
Machine: params.Machine,
VSCSTarget: params.VSCSTarget,
VSCSTargetURL: params.VSCSTargetURL,
PermissionsOptOut: params.PermissionsOptOut,
})
if err != nil {
return nil, fmt.Errorf("error marshaling request: %w", err)
}

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"time"
"github.com/AlecAivazis/survey/v2"
@ -47,7 +48,13 @@ func newCreateCmd(app *App) *cobra.Command {
// Create creates a new Codespace
func (a *App) Create(ctx context.Context, opts createOptions) error {
locationCh := getLocation(ctx, a.apiClient)
// Overrides for Codespace developers to target test environments
vscsLocation := os.Getenv("VSCS_LOCATION")
vscsTarget := os.Getenv("VSCS_TARGET")
vscsTargetUrl := os.Getenv("VSCS_TARGET_URL")
locationCh := getLocation(ctx, vscsLocation, a.apiClient)
userInputs := struct {
Repository string
@ -117,6 +124,8 @@ func (a *App) Create(ctx context.Context, opts createOptions) error {
Branch: branch,
Machine: machine,
Location: locationResult.Location,
VSCSTarget: vscsTarget,
VSCSTargetURL: vscsTargetUrl,
IdleTimeoutMinutes: int(opts.idleTimeout.Minutes()),
PermissionsOptOut: opts.permissionsOptOut,
}
@ -282,9 +291,18 @@ type locationResult struct {
Err error
}
// getLocation fetches the closest Codespace datacenter region/location to the user.
func getLocation(ctx context.Context, apiClient apiClient) <-chan locationResult {
// getLocation fetches the closest Codespace datacenter
// region/location to the user, unless the 'vscsLocationOverride' override is set
func getLocation(ctx context.Context, vscsLocationOverride string, apiClient apiClient) <-chan locationResult {
ch := make(chan locationResult, 1)
// Developer override is set, return the override
if vscsLocationOverride != "" {
ch <- locationResult{vscsLocationOverride, nil}
return ch
}
// Dynamically fetch the region location
go func() {
location, err := apiClient.GetCodespaceRegionLocation(ctx)
ch <- locationResult{location, err}