Skip to content

Commit 6723459

Browse files
feat: sandbox (#44)
* feat: sandbox * fix: sandbox client for oauth * chore: fix lint * chore: fix shell, port forward
1 parent d70eeae commit 6723459

70 files changed

Lines changed: 8098 additions & 163 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ linters:
1919
- gosec
2020
- copyloopvar
2121
- errorlint
22+
settings:
23+
errcheck:
24+
check-type-assertions: true
25+
check-blank: true
26+
govet:
27+
enable-all: true
28+
disable:
29+
- fieldalignment
30+
revive:
31+
rules:
32+
- name: exported
33+
disabled: false
34+
- name: error-return
35+
disabled: false
36+
- name: error-strings
37+
disabled: false
38+
- name: indent-error-flow
39+
disabled: false
40+
gosec:
41+
excludes:
42+
- G304
43+
exclusions:
44+
rules:
45+
- path: _test\.go
46+
linters:
47+
- errcheck
48+
- gocritic
2249

2350
formatters:
2451
enable:
@@ -29,34 +56,7 @@ formatters:
2956
local-prefixes:
3057
- github.com/NodeOps-app/createos-cli
3158

32-
linters-settings:
33-
errcheck:
34-
check-type-assertions: true
35-
check-blank: true
36-
govet:
37-
enable-all: true
38-
disable:
39-
- fieldalignment
40-
revive:
41-
rules:
42-
- name: exported
43-
disabled: false
44-
- name: error-return
45-
disabled: false
46-
- name: error-strings
47-
disabled: false
48-
- name: indent-error-flow
49-
disabled: false
50-
gosec:
51-
excludes:
52-
- G304
53-
5459
issues:
55-
exclude-rules:
56-
- path: _test\.go
57-
linters:
58-
- errcheck
59-
- gocritic
6060
max-issues-per-linter: 0
6161
max-same-issues: 0
6262

cmd/ask/ask.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ func NewAskCommand() *cli.Command {
6464
pterm.Info.Println("The 'ask' command uses OpenCode (https://opencode.ai), an open-source AI coding\nassistant, to power the CreateOS AI agent. It lets you manage your infrastructure\nusing natural language right from the terminal.")
6565
fmt.Println()
6666

67-
install, _ := pterm.DefaultInteractiveConfirm.
67+
install, err := pterm.DefaultInteractiveConfirm.
6868
WithDefaultText("opencode is not installed. Install it now?").
6969
WithDefaultValue(true).
7070
Show()
71+
if err != nil {
72+
return err
73+
}
7174
if !install {
7275
return fmt.Errorf("opencode is required for the ask command\n\n Install it manually:\n curl -fsSL https://opencode.ai/install | bash")
7376
}
@@ -77,7 +80,7 @@ func NewAskCommand() *cli.Command {
7780
installCmd.Stdin = os.Stdin
7881
installCmd.Stdout = os.Stdout
7982
installCmd.Stderr = os.Stderr
80-
if err := installCmd.Run(); err != nil {
83+
if err = installCmd.Run(); err != nil {
8184
return fmt.Errorf("failed to install opencode: %w", err)
8285
}
8386

cmd/auth/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func loginWithBrowser() error {
112112
pterm.Println(pterm.Gray(" " + authURL))
113113
fmt.Println()
114114

115-
if err := internaloauth.OpenBrowser(authURL); err != nil {
115+
if err = internaloauth.OpenBrowser(authURL); err != nil {
116116
pterm.Warning.Println("Could not open browser automatically. Please open the URL above.")
117117
} else {
118118
pterm.Info.Println("Waiting for you to complete login in your browser...")

cmd/cronjobs/activities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func newCronjobsActivitiesCommand() *cli.Command {
7171
log,
7272
})
7373
}
74-
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
74+
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
7575
fmt.Println()
7676
})
7777
return nil

cmd/cronjobs/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func newCronjobsListCommand() *cli.Command {
5353
cj.CreatedAt.Format("2006-01-02 15:04:05"),
5454
})
5555
}
56-
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
56+
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
5757
fmt.Println()
5858
})
5959
return nil

cmd/cronjobs/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Examples:
6262
// Decode existing settings for defaults in both TTY and non-TTY.
6363
var currentSettings api.HTTPCronjobSettings
6464
if existing.Settings != nil {
65-
if err := json.Unmarshal(*existing.Settings, &currentSettings); err != nil {
65+
if err = json.Unmarshal(*existing.Settings, &currentSettings); err != nil {
6666
return fmt.Errorf("could not parse existing cron job settings: %w", err)
6767
}
6868
}

cmd/deploy/deploy.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ func NewDeployCommand() *cli.Command {
147147
}
148148

149149
// Try to auto-detect from git remote
150-
dir, _ := os.Getwd()
150+
dir, err := os.Getwd()
151+
if err != nil {
152+
return fmt.Errorf("couldn't determine your current directory — please try again from a valid working directory")
153+
}
151154
repoFullName := git.GetRemoteFullName(dir)
152155
if repoFullName != "" {
153156
for _, p := range activeProjects {
@@ -160,10 +163,10 @@ func NewDeployCommand() *cli.Command {
160163
}
161164
if src.VCSFullName == repoFullName {
162165
pterm.Info.Printf("Detected project %s from git remote (%s)\n", p.DisplayName, repoFullName)
163-
useDetected, _ := pterm.DefaultInteractiveConfirm.
166+
confirm := pterm.DefaultInteractiveConfirm.
164167
WithDefaultText(fmt.Sprintf("Deploy %s?", p.DisplayName)).
165-
WithDefaultValue(true).
166-
Show()
168+
WithDefaultValue(true)
169+
useDetected, _ := confirm.Show() //nolint:errcheck
167170
if useDetected {
168171
projectID = p.ID
169172
}
@@ -281,23 +284,23 @@ func UploadDir(client *api.APIClient, projectID, displayName, dir string) error
281284
defer os.Remove(zipFile.Name()) //nolint:errcheck
282285
defer zipFile.Close() //nolint:errcheck
283286

284-
spinner, _ := pterm.DefaultSpinner.Start("Packaging files...")
287+
spinner, _ := pterm.DefaultSpinner.Start("Packaging files...") //nolint:errcheck
285288

286-
if err := createZip(zipFile, absDir); err != nil {
289+
if err = createZip(zipFile, absDir); err != nil {
287290
spinner.Fail("Packaging failed")
288291
return err
289292
}
290293

291-
stat, _ := zipFile.Stat()
292-
if stat != nil && stat.Size() > maxZipSize {
294+
stat, statErr := zipFile.Stat()
295+
if statErr == nil && stat.Size() > maxZipSize {
293296
spinner.Fail("Package too large")
294297
return fmt.Errorf("deployment package is %d MB (max %d MB)\n\n Tip: check that node_modules, .git, and build artifacts are excluded",
295298
stat.Size()/(1024*1024), maxZipSize/(1024*1024))
296299
}
297300

298301
spinner.UpdateText("Uploading...")
299302

300-
if err := zipFile.Close(); err != nil { //nolint:govet
303+
if err = zipFile.Close(); err != nil {
301304
return fmt.Errorf("could not flush deployment package: %w", err)
302305
}
303306

@@ -335,15 +338,15 @@ func deployUpload(c *cli.Context, client *api.APIClient, project *api.Project) e
335338
defer os.Remove(zipFile.Name()) //nolint:errcheck
336339
defer zipFile.Close() //nolint:errcheck
337340

338-
spinner, _ := pterm.DefaultSpinner.Start("Packaging files...")
341+
spinner, _ := pterm.DefaultSpinner.Start("Packaging files...") //nolint:errcheck
339342

340-
if err := createZip(zipFile, absDir); err != nil {
343+
if err = createZip(zipFile, absDir); err != nil {
341344
spinner.Fail("Packaging failed")
342345
return err
343346
}
344347

345-
stat, _ := zipFile.Stat()
346-
if stat != nil && stat.Size() > maxZipSize {
348+
stat, statErr := zipFile.Stat()
349+
if statErr == nil && stat.Size() > maxZipSize {
347350
spinner.Fail("Package too large")
348351
return fmt.Errorf("deployment package is %d MB (max %d MB)\n\n Tip: check that node_modules, .git, and build artifacts are excluded",
349352
stat.Size()/(1024*1024), maxZipSize/(1024*1024))
@@ -352,7 +355,7 @@ func deployUpload(c *cli.Context, client *api.APIClient, project *api.Project) e
352355
spinner.UpdateText("Uploading...")
353356

354357
// Close before uploading so the file is flushed
355-
if err := zipFile.Close(); err != nil { //nolint:govet
358+
if err = zipFile.Close(); err != nil {
356359
return fmt.Errorf("could not flush deployment package: %w", err)
357360
}
358361

@@ -523,8 +526,15 @@ func createZip(w io.Writer, srcDir string) error {
523526
// Check ignore patterns against basename and full relative path
524527
baseName := filepath.Base(relPath)
525528
for _, pattern := range ignorePatterns {
526-
matchedBase, _ := filepath.Match(pattern, baseName)
527-
matchedRel, _ := filepath.Match(pattern, filepath.ToSlash(relPath))
529+
var matchedBase, matchedRel bool
530+
matchedBase, err = filepath.Match(pattern, baseName)
531+
if err != nil {
532+
return fmt.Errorf("invalid ignore pattern %q: %w", pattern, err)
533+
}
534+
matchedRel, err = filepath.Match(pattern, filepath.ToSlash(relPath))
535+
if err != nil {
536+
return fmt.Errorf("invalid ignore pattern %q: %w", pattern, err)
537+
}
528538
if matchedBase || matchedRel {
529539
if info.IsDir() {
530540
return filepath.SkipDir

cmd/deployments/helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ func pickDeployment(client *api.APIClient, projectID string, statusFilter []stri
8282
})
8383
}
8484
fmt.Println()
85-
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
85+
if err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
86+
pterm.Error.Println(err)
87+
}
8688
fmt.Println()
8789

8890
options := make([]string, len(deployments))

cmd/deployments/list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ func newDeploymentsListCommand() *cli.Command {
5050
d.CreatedAt.Format("2006-01-02 15:04:05"),
5151
})
5252
}
53-
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
53+
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
54+
pterm.Error.Println(err)
55+
}
5456
})
5557
return nil
5658
},

cmd/domains/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ func printDNSRecords(d api.Domain) {
8282
tableData = append(tableData, []string{"TXT", txt.Name + "." + d.Name, txt.Value})
8383
}
8484

85-
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
85+
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
8686
fmt.Println()
8787
}

0 commit comments

Comments
 (0)