Skip to content
Draft
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
2 changes: 0 additions & 2 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/brevdev/brev-cli/pkg/cmd/envvars"
"github.com/brevdev/brev-cli/pkg/cmd/exec"
"github.com/brevdev/brev-cli/pkg/cmd/feedback"
"github.com/brevdev/brev-cli/pkg/cmd/fu"
"github.com/brevdev/brev-cli/pkg/cmd/gpucreate"
"github.com/brevdev/brev-cli/pkg/cmd/gpusearch"
"github.com/brevdev/brev-cli/pkg/cmd/grantssh"
Expand Down Expand Up @@ -293,7 +292,6 @@ func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *stor
cmd.AddCommand(clipboard.ForwardPort(t, loginCmdStore))
cmd.AddCommand(envvars.NewCmdEnvVars(t, loginCmdStore))
cmd.AddCommand(connect.NewCmdConnect(t, noLoginCmdStore))
cmd.AddCommand(fu.NewCmdFu(t, loginCmdStore, noLoginCmdStore))
} else {
_ = 0 // noop
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CopyStore interface {
GetWorkspaces(organizationID string, options *store.GetWorkspacesOptions) ([]entity.Workspace, error)
StartWorkspace(workspaceID string) (*entity.Workspace, error)
GetWorkspace(workspaceID string) (*entity.Workspace, error)
GetCurrentUserKeys() (*entity.UserKeys, error)
GetCurrentUserSSHPrivateKey() (string, error)
GetAccessToken() (string, error)
}

Expand Down
107 changes: 0 additions & 107 deletions pkg/cmd/fu/fu.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/cmd/fu/fu_test.go

This file was deleted.

6 changes: 3 additions & 3 deletions pkg/cmd/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ProxyStore interface {
huproxyclient.HubProxyStore
GetWorkspace(workspaceID string) (*entity.Workspace, error)
WritePrivateKey(pem string) error
GetCurrentUserKeys() (*entity.UserKeys, error)
GetCurrentUserSSHPrivateKey() (string, error)
}

func NewCmdProxy(t *terminal.Terminal, store ProxyStore) *cobra.Command {
Expand Down Expand Up @@ -149,11 +149,11 @@ func checkWorkspaceInfraVersionOrErr(workspace *entity.Workspace) error {
}

func WriteUserPrivateKey(store ProxyStore) error {
keys, err := store.GetCurrentUserKeys()
privateKey, err := store.GetCurrentUserSSHPrivateKey()
if err != nil {
return breverrors.WrapAndTrace(err)
}
err = store.WritePrivateKey(keys.PrivateKey)
err = store.WritePrivateKey(privateKey)
if err != nil {
return breverrors.WrapAndTrace(err)
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/cmd/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,44 @@ package proxy
import (
"testing"

"github.com/brevdev/brev-cli/pkg/entity"
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type privateKeyProxyStore struct {
privateKey string
writtenPrivateKey string
}

func (s *privateKeyProxyStore) GetAuthTokens() (*entity.AuthTokens, error) {
return nil, nil
}

func (s *privateKeyProxyStore) GetWorkspace(string) (*entity.Workspace, error) {
return nil, nil
}

func (s *privateKeyProxyStore) GetCurrentUserSSHPrivateKey() (string, error) {
return s.privateKey, nil
}

func (s *privateKeyProxyStore) WritePrivateKey(privateKey string) error {
s.writtenPrivateKey = privateKey
return nil
}

func TestVersionParsing(t *testing.T) {
_, err := version.NewVersion("abadfjladsf")
assert.NotNil(t, err)
}

func TestWriteUserPrivateKeyWritesCurrentUsersPrivateKey(t *testing.T) {
store := &privateKeyProxyStore{privateKey: "private"}

err := WriteUserPrivateKey(store)

require.NoError(t, err)
require.Equal(t, "private", store.writtenPrivateKey)
}
6 changes: 3 additions & 3 deletions pkg/cmd/refresh/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type RefreshStore interface {
ssh.ConfigUpdaterStore
ssh.SSHConfigurerV2Store
GetCurrentUser() (*entity.User, error)
GetCurrentUserKeys() (*entity.UserKeys, error)
GetCurrentUserSSHPrivateKey() (string, error)
GetActiveOrganizationOrDefault() (*entity.Organization, error)
GetAccessToken() (string, error)
Chmod(string, fs.FileMode) error
Expand Down Expand Up @@ -155,12 +155,12 @@ func GetConfigUpdater(store RefreshStore) (*ssh.ConfigUpdater, error) {
return nil, breverrors.WrapAndTrace(err)
}

keys, err := store.GetCurrentUserKeys()
privateKey, err := store.GetCurrentUserSSHPrivateKey()
if err != nil {
return nil, breverrors.WrapAndTrace(err)
}

cu := ssh.NewConfigUpdater(store, configs, keys.PrivateKey)
cu := ssh.NewConfigUpdater(store, configs, privateKey)
cu.ExternalNodes = getExternalNodeSSHEntries(store)

return cu, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/runtasks/runtasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type RunTasksStore interface {
ssh.SSHConfigurerV2Store
tasks.RunTaskAsDaemonStore
GetCurrentUser() (*entity.User, error)
GetCurrentUserKeys() (*entity.UserKeys, error)
GetCurrentUserSSHPrivateKey() (string, error)
}

func RunTasks(_ *terminal.Terminal, store RunTasksStore, detached bool) error {
Expand Down Expand Up @@ -77,12 +77,12 @@ func getDefaultTasks(store RunTasksStore) ([]tasks.Task, error) {
}

// get private key and set here
keys, err := store.GetCurrentUserKeys()
privateKey, err := store.GetCurrentUserSSHPrivateKey()
if err != nil {
return nil, breverrors.WrapAndTrace(err)
}

cu := ssh.NewConfigUpdater(store, configs, keys.PrivateKey)
cu := ssh.NewConfigUpdater(store, configs, privateKey)

return []tasks.Task{cu}, nil
}
2 changes: 1 addition & 1 deletion pkg/cmd/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type TaskMap map[string]tasks.Task
var all bool // used for run command

type TaskStore interface {
GetCurrentUserKeys() (*entity.UserKeys, error)
GetCurrentUserSSHPrivateKey() (string, error)
CopyBin(targetBin string) error
WriteString(path, data string) error
GetOrCreateFile(path string) (afero.File, error)
Expand Down
7 changes: 3 additions & 4 deletions pkg/ssh/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package ssh

import (
"github.com/brevdev/brev-cli/pkg/autostartconf"
"github.com/brevdev/brev-cli/pkg/entity"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/brevdev/brev-cli/pkg/tasks"
)

type SSHConfigurerTaskStore interface {
ConfigUpdaterStore
SSHConfigurerV2Store
GetCurrentUserKeys() (*entity.UserKeys, error)
GetCurrentUserSSHPrivateKey() (string, error)
}

type SSHConfigurerTask struct {
Expand All @@ -29,12 +28,12 @@ func (sct SSHConfigurerTask) Run() error {
return breverrors.WrapAndTrace(err)
}

keys, err := sct.Store.GetCurrentUserKeys()
privateKey, err := sct.Store.GetCurrentUserSSHPrivateKey()
if err != nil {
return breverrors.WrapAndTrace(err)
}

cu := NewConfigUpdater(sct.Store, configs, keys.PrivateKey)
cu := NewConfigUpdater(sct.Store, configs, privateKey)
err = tasks.RunTasks([]tasks.Task{cu})
if err != nil {
return breverrors.WrapAndTrace(err)
Expand Down
Loading
Loading