(ctx context.Context, ce *clienv.CliEnv)
| 63 | } |
| 64 | |
| 65 | func writeScript(ctx context.Context, ce *clienv.CliEnv) error { |
| 66 | ce.Println("Installing credentials helper for docker in %s", credentialsPath) |
| 67 | |
| 68 | executable, err := os.Executable() |
| 69 | if err != nil { |
| 70 | return fmt.Errorf("could not get executable path: %w", err) |
| 71 | } |
| 72 | |
| 73 | script := fmt.Sprintf(script, executable) |
| 74 | |
| 75 | tmpfile, err := os.CreateTemp("", "nhost-docker-credentials") |
| 76 | if err != nil { |
| 77 | return fmt.Errorf("could not create temporary file: %w", err) |
| 78 | } |
| 79 | defer tmpfile.Close() |
| 80 | |
| 81 | if _, err := tmpfile.WriteString(script); err != nil { |
| 82 | return fmt.Errorf("could not write to temporary file: %w", err) |
| 83 | } |
| 84 | |
| 85 | if err := tmpfile.Chmod(0o755); err != nil { //nolint:mnd |
| 86 | return fmt.Errorf("could not chmod temporary file: %w", err) |
| 87 | } |
| 88 | |
| 89 | if !canSudo(ctx) { |
| 90 | ce.Println("I need root privileges to install the file. Please, enter your password.") |
| 91 | } |
| 92 | |
| 93 | if err := exec.CommandContext( //nolint:gosec |
| 94 | ctx, "sudo", "mv", tmpfile.Name(), credentialsPath, |
| 95 | ).Run(); err != nil { |
| 96 | return fmt.Errorf("could not move temporary file: %w", err) |
| 97 | } |
| 98 | |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | func configureDocker(dockerConfig string) error { |
| 103 | f, err := os.OpenFile(dockerConfig, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0o644) //nolint:mnd |
no test coverage detected