Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 6 additions & 30 deletions internal/boxcli/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

"go.jetify.com/devbox/internal/boxcli/usererr"
"go.jetify.com/devbox/internal/devbox"
"go.jetify.com/devbox/internal/devbox/devopt"
"go.jetify.com/devbox/internal/devbox/providers/identity"
"go.jetify.com/devbox/internal/goutil"
"go.jetify.com/devbox/internal/pullbox/s3"
"go.jetify.com/pkg/auth"
)

type pullCmdFlags struct {
Expand All @@ -32,10 +27,10 @@ func pullCmd() *cobra.Command {
Use: "pull <file> | <url>",
Short: "Pull a config from a file or URL",
Long: "Pull a config from a file or URL. URLs must be prefixed with 'http://' or 'https://'.",
Args: cobra.MaximumNArgs(1),
Args: cobra.ExactArgs(1),
PreRunE: ensureNixInstalled,
RunE: func(cmd *cobra.Command, args []string) error {
return pullCmdFunc(cmd, goutil.GetDefaulted(args, 0), &flags)
return pullCmdFunc(cmd, args[0], &flags)
},
}

Expand Down Expand Up @@ -64,22 +59,9 @@ func pullCmdFunc(cmd *cobra.Command, url string, flags *pullCmdFlags) error {
return errors.WithStack(err)
}

var creds devopt.Credentials
t, err := identity.GenSession(cmd.Context())
if err != nil && !errors.Is(err, auth.ErrNotLoggedIn) {
return errors.WithStack(err)
} else if t != nil && err == nil {
creds = devopt.Credentials{
IDToken: t.IDToken,
Email: t.IDClaims().Email,
Sub: t.IDClaims().Subject,
}
}

err = box.Pull(cmd.Context(), devopt.PullboxOpts{
URL: pullPath,
Overwrite: flags.force,
Credentials: creds,
URL: pullPath,
Overwrite: flags.force,
})
if prompt := pullErrorPrompt(err); prompt != "" {
prompt := &survey.Confirm{Message: prompt}
Expand All @@ -90,16 +72,10 @@ func pullCmdFunc(cmd *cobra.Command, url string, flags *pullCmdFlags) error {
return nil
}
err = box.Pull(cmd.Context(), devopt.PullboxOpts{
URL: pullPath,
Overwrite: flags.force,
Credentials: creds,
URL: pullPath,
Overwrite: flags.force,
})
}
if errors.Is(err, s3.ErrProfileNotFound) {
return usererr.New(
"Profile not found. Use `devbox global push` to create a new profile.",
)
}
if err != nil {
return err
}
Expand Down
28 changes: 5 additions & 23 deletions internal/boxcli/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ package boxcli
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"go.jetify.com/pkg/auth"

"go.jetify.com/devbox/internal/devbox"
"go.jetify.com/devbox/internal/devbox/devopt"
"go.jetify.com/devbox/internal/devbox/providers/identity"
"go.jetify.com/devbox/internal/goutil"
)

type pushCmdFlags struct {
Expand All @@ -21,12 +18,11 @@ type pushCmdFlags struct {
func pushCmd() *cobra.Command {
flags := pushCmdFlags{}
cmd := &cobra.Command{
Use: "push <git-repo>",
Short: "Push a [global] config. Leave empty to use jetify cloud. Can " +
"be a git repo for self storage.",
Args: cobra.MaximumNArgs(1),
Use: "push <git-repo>",
Short: "Push a [global] config to a git repo",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return pushCmdFunc(cmd, goutil.GetDefaulted(args, 0), flags)
return pushCmdFunc(cmd, args[0], flags)
},
}

Expand All @@ -44,19 +40,5 @@ func pushCmdFunc(cmd *cobra.Command, url string, flags pushCmdFlags) error {
if err != nil {
return errors.WithStack(err)
}
t, err := identity.GenSession(cmd.Context())
var creds devopt.Credentials
if err != nil && !errors.Is(err, auth.ErrNotLoggedIn) {
return errors.WithStack(err)
} else if t != nil && err == nil {
creds = devopt.Credentials{
IDToken: t.IDToken,
Email: t.IDClaims().Email,
Sub: t.IDClaims().Subject,
}
}
return box.Push(cmd.Context(), devopt.PullboxOpts{
URL: url,
Credentials: creds,
})
return box.Push(cmd.Context(), devopt.PullboxOpts{URL: url})
}
12 changes: 2 additions & 10 deletions internal/devbox/devopt/devboxopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@ type EnvrcOpts struct {
}

type PullboxOpts struct {
Overwrite bool
URL string
Credentials Credentials
}

type Credentials struct {
IDToken string
// TODO We can just parse these out, but don't want to add a dependency right now
Email string
Sub string
Overwrite bool
URL string
}

type AddOpts struct {
Expand Down
8 changes: 0 additions & 8 deletions internal/goutil/goutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@ func PickByKeysSorted[K comparable, V any](in map[K]V, keys []K) []V {
}
return out
}

func GetDefaulted[T any](in []T, index int) T {
var t T
if index >= len(in) {
return t
}
return in[index]
}
41 changes: 7 additions & 34 deletions internal/pullbox/pullbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.jetify.com/devbox/internal/boxcli/usererr"
"go.jetify.com/devbox/internal/devbox/devopt"
"go.jetify.com/devbox/internal/pullbox/git"
"go.jetify.com/devbox/internal/pullbox/s3"
"go.jetify.com/devbox/internal/pullbox/tar"
"go.jetify.com/devbox/internal/ux"
)
Expand All @@ -42,32 +41,21 @@ func (p *pullbox) Pull(ctx context.Context) error {
defer trace.StartRegion(ctx, "Pull").End()
var err error

if p.URL == "" {
return usererr.New("Nothing to pull from. Pass a git repo, URL, or file path to pull from.")
}

notEmpty, err := profileIsNotEmpty(p.ProjectDir())
if err != nil {
return err
} else if notEmpty && !p.Overwrite {
return fs.ErrExist
}

if p.URL != "" {
ux.Finfof(os.Stderr, "Pulling global config from %s\n", p.URL)
} else {
ux.Finfof(os.Stderr, "Pulling global config\n")
}
ux.Finfof(os.Stderr, "Pulling global config from %s\n", p.URL)

var tmpDir string

if p.URL == "" {
if p.Credentials.IDToken == "" {
return usererr.New("Not logged in")
}
profile := "default" // TODO: make this editable
if tmpDir, err = s3.PullToTmp(ctx, &p.Credentials, profile); err != nil {
return err
}
return p.copyToProfile(tmpDir)
}

if git.IsRepoURL(p.URL) {
if tmpDir, err = git.CloneToTmp(p.URL); err != nil {
return err
Expand Down Expand Up @@ -102,24 +90,9 @@ func (p *pullbox) Pull(ctx context.Context) error {
}

func (p *pullbox) Push(ctx context.Context) error {
if p.URL != "" {
ux.Finfof(os.Stderr, "Pushing global config to %s\n", p.URL)
} else {
ux.Finfof(os.Stderr, "Pushing global config\n")
}

if p.URL == "" {
profile := "default" // TODO: make this editable
if p.Credentials.IDToken == "" {
return usererr.New("Not logged in")
}
ux.Finfof(
os.Stderr,
"Logged in as %s, pushing to to devbox cloud (profile: %s)\n",
p.Credentials.Email,
profile,
)
return s3.Push(ctx, &p.Credentials, p.ProjectDir(), profile)
return usererr.New("Nowhere to push to. Pass a git repo to push to.")
}
ux.Finfof(os.Stderr, "Pushing global config to %s\n", p.URL)
return git.Push(ctx, p.ProjectDir(), p.URL)
}
55 changes: 0 additions & 55 deletions internal/pullbox/s3/config.go

This file was deleted.

76 changes: 0 additions & 76 deletions internal/pullbox/s3/pull.go

This file was deleted.

Loading
Loading