MCPcopy Index your code
hub / github.com/coder/coder / OverrideVSCodeConfigs

Function OverrideVSCodeConfigs

cli/gitauth/vscode.go:16–95  ·  view source on GitHub ↗

OverrideVSCodeConfigs overwrites a few properties to consume GIT_ASKPASS from the host instead of VS Code-specific authentication.

(fs afero.Fs)

Source from the content-addressed store, hash-verified

14// OverrideVSCodeConfigs overwrites a few properties to consume
15// GIT_ASKPASS from the host instead of VS Code-specific authentication.
16func OverrideVSCodeConfigs(fs afero.Fs) error {
17 home, err := os.UserHomeDir()
18 if err != nil {
19 return err
20 }
21 mutate := func(m map[string]interface{}) {
22 // These defaults prevent VS Code from overriding
23 // GIT_ASKPASS and using its own GitHub authentication,
24 // which would circumvent cloning with Coder-configured
25 // providers. We only set them if they are not already
26 // present so that template authors can override them
27 // via module settings (e.g. the vscode-web module).
28 if _, ok := m["git.useIntegratedAskPass"]; !ok {
29 m["git.useIntegratedAskPass"] = false
30 }
31 if _, ok := m["github.gitAuthentication"]; !ok {
32 m["github.gitAuthentication"] = false
33 }
34 }
35
36 for _, configPath := range []string{
37 // code-server's default configuration path.
38 filepath.Join(xdg.DataHome, "code-server", "Machine", "settings.json"),
39 // vscode-remote's default configuration path.
40 filepath.Join(home, ".vscode-server", "data", "Machine", "settings.json"),
41 // vscode-insiders' default configuration path.
42 filepath.Join(home, ".vscode-insiders-server", "data", "Machine", "settings.json"),
43 // cursor default configuration path.
44 filepath.Join(home, ".cursor-server", "data", "Machine", "settings.json"),
45 // windsurf default configuration path.
46 filepath.Join(home, ".windsurf-server", "data", "Machine", "settings.json"),
47 // vscodium default configuration path.
48 filepath.Join(home, ".vscodium-server", "data", "Machine", "settings.json"),
49 } {
50 _, err := fs.Stat(configPath)
51 if err != nil {
52 if !errors.Is(err, os.ErrNotExist) {
53 return xerrors.Errorf("stat %q: %w", configPath, err)
54 }
55
56 m := map[string]interface{}{}
57 mutate(m)
58 data, err := json.MarshalIndent(m, "", "\t")
59 if err != nil {
60 return xerrors.Errorf("marshal: %w", err)
61 }
62
63 err = fs.MkdirAll(filepath.Dir(configPath), 0o700)
64 if err != nil {
65 return xerrors.Errorf("mkdir all: %w", err)
66 }
67
68 err = afero.WriteFile(fs, configPath, data, 0o600)
69 if err != nil {
70 return xerrors.Errorf("write %q: %w", configPath, err)
71 }
72 continue
73 }

Callers 2

handleManifestMethod · 0.92

Calls 6

MkdirAllMethod · 0.80
WriteFileMethod · 0.65
ReadFileMethod · 0.65
IsMethod · 0.45
ErrorfMethod · 0.45
UnmarshalMethod · 0.45

Tested by 1