Skip to content

feat: Add Git auth for GitHub, GitLab, Azure DevOps, and BitBucket #4670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable automatic cloning from VS Code
  • Loading branch information
kylecarbs committed Oct 24, 2022
commit 6bd9733b81094981b0f831fd505c98fde1458c77
6 changes: 6 additions & 0 deletions cli/gitaskpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func gitAskpass() *cobra.Command {
}
if token.URL != "" {
cmd.Printf("Visit the following URL to authenticate with Git:\n%s\n", token.URL)

err = openURL(cmd, token.URL)
if err != nil {
return xerrors.Errorf("open url: %w", err)
}

for r := retry.New(time.Second, 10*time.Second); r.Wait(ctx); {
token, err = client.WorkspaceAgentGitAuth(ctx, host, true)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,16 @@ func openURL(cmd *cobra.Command, urlToOpen string) error {
return exec.Command("cmd.exe", "/c", "start", strings.ReplaceAll(urlToOpen, "&", "^&")).Start()
}

browserEnv := os.Getenv("BROWSER")
if browserEnv != "" {
browserSh := fmt.Sprintf("%s '%s'", browserEnv, urlToOpen)
cmd := exec.CommandContext(cmd.Context(), "sh", "-c", browserSh)
out, err := cmd.CombinedOutput()
if err != nil {
return xerrors.Errorf("failed to run %v (out: %q): %w", cmd.Args, out, err)
}
return nil
}

return browser.OpenURL(urlToOpen)
}
5 changes: 5 additions & 0 deletions coderd/gitauth/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func OverrideVSCodeConfigs(fs afero.Fs) error {
return xerrors.Errorf("marshal: %w", err)
}

err = fs.MkdirAll(filepath.Dir(configPath), 0o700)
if err != nil {
return xerrors.Errorf("mkdir all: %w", err)
}

err = afero.WriteFile(fs, configPath, data, 0600)
if err != nil {
return xerrors.Errorf("write %q: %w", configPath, err)
Expand Down
4 changes: 2 additions & 2 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ export interface DeploymentConfig {
readonly prometheus_address: DeploymentConfigField<string>
readonly pprof_enabled: DeploymentConfigField<boolean>
readonly pprof_address: DeploymentConfigField<string>
readonly proxy_trusted_headers: DeploymentConfigField<string[]>
readonly proxy_trusted_origins: DeploymentConfigField<string[]>
readonly cache_directory: DeploymentConfigField<string>
readonly gitauth: DeploymentConfigField<DeploymentConfigGitAuth[]>
readonly in_memory_database: DeploymentConfigField<boolean>
readonly proxy_trusted_headers: DeploymentConfigField<string[]>
readonly proxy_trusted_origins: DeploymentConfigField<string[]>
readonly provisioner_daemon_count: DeploymentConfigField<number>
readonly oauth2_github_client_id: DeploymentConfigField<string>
readonly oauth2_github_allowed_orgs: DeploymentConfigField<string[]>
Expand Down