diff --git a/go.mod b/go.mod index 4885a05e..14594b93 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,6 @@ require ( golang.org/x/crypto v0.24.0 golang.org/x/text v0.16.0 k8s.io/cli-runtime v0.31.1 - k8s.io/client-go v0.31.1 ) require ( @@ -110,6 +109,7 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect gotest.tools/v3 v3.4.0 // indirect k8s.io/apimachinery v0.31.1 // indirect + k8s.io/client-go v0.31.1 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect ) diff --git a/pkg/auth/kas.go b/pkg/auth/kas.go index 31584347..cc5d8560 100644 --- a/pkg/auth/kas.go +++ b/pkg/auth/kas.go @@ -81,7 +81,7 @@ func (a KasAuthenticator) MakeLoginCall(id, email string) (LoginCallResponse, er } // Create a new POST request with JSON payload - req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) + req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) //nolint:noctx // fine if err != nil { return LoginCallResponse{}, breverrors.WrapAndTrace(err) } @@ -93,7 +93,7 @@ func (a KasAuthenticator) MakeLoginCall(id, email string) (LoginCallResponse, er if err != nil { return LoginCallResponse{}, breverrors.WrapAndTrace(err) } - defer resp.Body.Close() + defer resp.Body.Close() //nolint:errcheck // fine // Read the response body body, err := io.ReadAll(resp.Body) @@ -196,7 +196,7 @@ type RetrieveIDTokenResponse struct { func (a KasAuthenticator) retrieveIDToken(sessionKey, deviceID string) (string, error) { tokenURL := fmt.Sprintf("%s/token", a.BaseURL) client := &http.Client{} - tokenReq, err := http.NewRequest("GET", tokenURL, nil) + tokenReq, err := http.NewRequest("GET", tokenURL, nil) //nolint:noctx // fine if err != nil { return "", fmt.Errorf("error creating token request: %v", err) } @@ -208,7 +208,7 @@ func (a KasAuthenticator) retrieveIDToken(sessionKey, deviceID string) (string, if err != nil { return "", fmt.Errorf("error sending token request: %v", err) } - defer tokenResp.Body.Close() + defer tokenResp.Body.Close() //nolint:errcheck // fine tokenBody, err := io.ReadAll(tokenResp.Body) if err != nil { diff --git a/pkg/cmd/cmderrors/cmderrors.go b/pkg/cmd/cmderrors/cmderrors.go index 0d6aa3e2..446e25a6 100644 --- a/pkg/cmd/cmderrors/cmderrors.go +++ b/pkg/cmd/cmderrors/cmderrors.go @@ -16,8 +16,6 @@ import ( // determines if should print error stack trace and/or send to crash monitor -//nolint:wrapcheck //no check - func DisplayAndHandleError(err error) { er := breverrors.GetDefaultErrorReporter() er.AddBreadCrumb(breverrors.ErrReportBreadCrumb{ diff --git a/pkg/cmd/tasks/tasks.go b/pkg/cmd/tasks/tasks.go index 1b0af8e7..8ac4d4bc 100644 --- a/pkg/cmd/tasks/tasks.go +++ b/pkg/cmd/tasks/tasks.go @@ -6,7 +6,6 @@ import ( "github.com/brevdev/brev-cli/pkg/cmd/cmderrors" "github.com/brevdev/brev-cli/pkg/entity" breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/k8s" "github.com/brevdev/brev-cli/pkg/ssh" "github.com/brevdev/brev-cli/pkg/tasks" "github.com/brevdev/brev-cli/pkg/terminal" @@ -20,7 +19,7 @@ type TaskMap map[string]tasks.Task var all bool // used for run command type TaskStore interface { - k8s.K8sStore + GetCurrentUserKeys() (*entity.UserKeys, error) CopyBin(targetBin string) error WriteString(path, data string) error GetOrCreateFile(path string) (afero.File, error) diff --git a/pkg/cmd/textceo/textceo.go b/pkg/cmd/textceo/textceo.go deleted file mode 100644 index 638fbe85..00000000 --- a/pkg/cmd/textceo/textceo.go +++ /dev/null @@ -1,26 +0,0 @@ -package textceo - -import ( - "github.com/brevdev/brev-cli/pkg/cmd/completions" - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/store" -) - -var ( - startLong = "Send a text message to our CEO, Nader" - startExample = "brev text-ceo -m 'Hi Nader, why is Microsoft a scorpion?'" -) - -type TextCEOStore interface { - completions.CompletionStore - ResetWorkspace(workspaceID string) (*entity.Workspace, error) - GetAllWorkspaces(options *store.GetWorkspacesOptions) ([]entity.Workspace, error) - GetWorkspaces(organizationID string, options *store.GetWorkspacesOptions) ([]entity.Workspace, error) - GetActiveOrganizationOrDefault() (*entity.Organization, error) - GetCurrentUser() (*entity.User, error) - GetWorkspace(id string) (*entity.Workspace, error) - GetWorkspaceMetaData(workspaceID string) (*entity.WorkspaceMetaData, error) -} - -// cmd.Flags().StringVarP(&message, "message", "m", "", "message to send Brev's CEO, Nader") -// cmd.Flags().StringVarP(&message, "phone", "p", "", "(Optional) leave a number for Nader to follow up") diff --git a/pkg/cmd/textceo/textceo_test.go b/pkg/cmd/textceo/textceo_test.go deleted file mode 100644 index e6676e40..00000000 --- a/pkg/cmd/textceo/textceo_test.go +++ /dev/null @@ -1 +0,0 @@ -package textceo diff --git a/pkg/collections/collections.go b/pkg/collections/collections.go index 9f094ae1..ed320bef 100644 --- a/pkg/collections/collections.go +++ b/pkg/collections/collections.go @@ -4,7 +4,6 @@ import ( "context" "net/http" "sort" - "sync" "time" "github.com/brevdev/brev-cli/pkg/errors" @@ -297,11 +296,6 @@ type ContextKey string const IdempotencyKeyName ContextKey = "idempotencyKey" -type SafeCounter struct { - mu sync.Mutex - c int -} - type AsyncResult[T any] struct { result chan result[T] } @@ -326,10 +320,6 @@ func (ar *AsyncResult[T]) Await() (T, error) { return r.value, r.err } -type Rollback struct { - undos []func() error -} - var ( // ErrCanceled is the error returned when the context is canceled. ErrCanceled = context.Canceled diff --git a/pkg/entity/entity.go b/pkg/entity/entity.go index 1ca2e09a..8f0bf9b4 100644 --- a/pkg/entity/entity.go +++ b/pkg/entity/entity.go @@ -4,7 +4,6 @@ import ( "fmt" "path" "path/filepath" - "regexp" "strings" "time" @@ -182,31 +181,14 @@ type User struct { } type UserKeys struct { - PrivateKey string `json:"privateKey"` - PublicKey string `json:"publicKey"` - WorkspaceGroups []WorkspaceGroupKeys `json:"workspaceGroups"` -} - -type WorkspaceGroupKeys struct { - GroupID string `json:"groupId"` - Cert string `json:"cert"` - CA string `json:"ca"` - APIURL string `json:"apiUrl"` + PrivateKey string `json:"privateKey"` + PublicKey string `json:"publicKey"` } func (v VscodeExtensionMetadata) GetID() string { return fmt.Sprintf("%s.%s", v.Publisher, v.Name) } -func (u UserKeys) GetWorkspaceGroupKeysByGroupID(groupID string) (*WorkspaceGroupKeys, error) { - for _, wgk := range u.WorkspaceGroups { - if wgk.GroupID == groupID { - return &wgk, nil - } - } - return nil, fmt.Errorf("group id %s not found", groupID) -} - type Organization struct { ID string `json:"id"` Name string `json:"name"` @@ -497,11 +479,6 @@ func (w Workspace) GetHostIdentifier() WorkspaceLocalID { return w.createSimpleName() + "-host" } -var ( - whitespaceCharPattern = regexp.MustCompile(`\s+`) - invalidCharPattern = regexp.MustCompile(`[^a-z0-9-]`) -) - // lowercase, replace whitespace with '-', remove all [^a-z0-9-], trim '-' front and back func (w Workspace) GetID() string { diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go deleted file mode 100644 index 1ed5754b..00000000 --- a/pkg/k8s/client.go +++ /dev/null @@ -1,46 +0,0 @@ -package k8s - -import ( - "github.com/brevdev/brev-cli/pkg/entity" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" -) - -type K8sClient interface { - GetK8sClient() *kubernetes.Clientset - GetK8sRestConfig() *rest.Config -} - -type WorkspaceGroupClientMapper interface { - GetK8sClient(workspaceGroupID string) (K8sClient, error) - GetK8sAPIURL(workspaceGroupID string) (string, error) -} - -type DefaultClient struct { - k8sClientset *kubernetes.Clientset - k8sRestConfig *rest.Config -} - -type K8sClientConfig interface { - GetHost() string - GetCert() []byte - GetKey() []byte - GetCA() []byte -} - -type DefaultWorkspaceGroupClientMapper struct { - workspaceK8sClientMap map[string]K8sClient - workspaceK8sAPIURLMap map[string]string - privateKey string -} - -type K8sStore interface { - GetCurrentUserKeys() (*entity.UserKeys, error) -} - -type RemoteK8sClientConfig struct { - host string - cert []byte - key []byte - ca []byte -} diff --git a/pkg/portforward/portforward.go b/pkg/portforward/portforward.go index 89c65ec4..4c1ff0d7 100644 --- a/pkg/portforward/portforward.go +++ b/pkg/portforward/portforward.go @@ -3,19 +3,11 @@ package portforward import ( "net/url" - "github.com/brevdev/brev-cli/pkg/k8s" "k8s.io/cli-runtime/pkg/genericclioptions" ) type PortForwardOptions struct { - PortForwarder PortForwarder - WorkspaceGroupClientMapper k8s.WorkspaceGroupClientMapper - - K8sClient k8s.K8sClient - K8sAPIURL string - - Namespace string - PodName string + PortForwarder PortForwarder Address []string Ports []string diff --git a/pkg/prefixid/prefixid.go b/pkg/prefixid/prefixid.go index c83b1b2c..654d886f 100644 --- a/pkg/prefixid/prefixid.go +++ b/pkg/prefixid/prefixid.go @@ -2,6 +2,4 @@ package prefixid type PrefixID string -const prefixSep = "-" - // New generates a unique ID that can be used as an identifier for an entity. diff --git a/pkg/ssh/sshconfigurer.go b/pkg/ssh/sshconfigurer.go index d93931bb..06164538 100644 --- a/pkg/ssh/sshconfigurer.go +++ b/pkg/ssh/sshconfigurer.go @@ -517,10 +517,6 @@ func doesUserSSHConfigIncludeBrevConfig(conf string, brevConfigPath string) bool return strings.Contains(conf, makeIncludeBrevStr(brevConfigPath)) } -type SSHConfigurerServiceMesh struct { - store SSHConfigurerV2Store -} - // Deprecated: var _ Config = SSHConfigurerServiceMesh{} // openssh-7.3 diff --git a/pkg/store/http.go b/pkg/store/http.go index 0e26e85a..c64d9217 100644 --- a/pkg/store/http.go +++ b/pkg/store/http.go @@ -32,10 +32,6 @@ type NoAuthHTTPClient struct { restyClient *resty.Client } -type OllamaHTTPClient struct { - restyClient *resty.Client -} - func NewNoAuthHTTPClient(brevAPIURL string) *NoAuthHTTPClient { restyClient := NewRestyClient(brevAPIURL) return &NoAuthHTTPClient{restyClient} diff --git a/pkg/store/user_test.go b/pkg/store/user_test.go index a1ece04e..8aa73877 100644 --- a/pkg/store/user_test.go +++ b/pkg/store/user_test.go @@ -43,14 +43,6 @@ func TestGetCurrentUserKeys(t *testing.T) { expected := &entity.UserKeys{ PrivateKey: "priv", PublicKey: "pub", - WorkspaceGroups: []entity.WorkspaceGroupKeys{ - { - GroupID: "gi", - Cert: "cert", - CA: "ca", - APIURL: "url", - }, - }, } res, err := httpmock.NewJsonResponder(200, expected) if !assert.Nil(t, err) { diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index 9d3a1a5f..8e61276d 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -80,8 +80,6 @@ func (t *Terminal) Errprint(err error, a string) { } } -type silentWriter struct{} - func (t *Terminal) NewSpinner() *spinner.Spinner { spinner := spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) err := spinner.Color("cyan", "bold")