From 321c583e8ba1bd115c27ca04ea1e096aba532736 Mon Sep 17 00:00:00 2001 From: Pratik Patel Date: Thu, 1 Oct 2026 17:08:00 -0700 Subject: [PATCH] remove deprecated commands --- go.mod | 37 +- go.sum | 93 ---- pkg/cmd/background/background.go | 183 -------- pkg/cmd/background/background_test.go | 1 - pkg/cmd/clipboard/clipboard.go | 105 ----- pkg/cmd/clipboard/clipboard_listener.go | 71 --- pkg/cmd/cmd.go | 79 +--- pkg/cmd/connect/connect.go | 57 --- pkg/cmd/create/create.go | 208 --------- pkg/cmd/create/create_test.go | 1 - pkg/cmd/create/doc.md | 265 ----------- pkg/cmd/envvars/envvars.go | 33 -- pkg/cmd/envvars/envvars_test.go | 1 - pkg/cmd/fu/fu.go | 107 ----- pkg/cmd/fu/fu_test.go | 1 - pkg/cmd/importideconfig/importideconfig.go | 220 --------- .../importideconfig/importideconfig_test.go | 1 - pkg/cmd/login/login.go | 10 +- pkg/cmd/login/login_test.go | 14 - pkg/cmd/ollama/ollama.go | 344 -------------- pkg/cmd/ollama/ollama_test.go | 1 - pkg/cmd/ollama/ollamauiverb.yaml | 0 pkg/cmd/ollama/ollamaverb.yaml | 18 - pkg/cmd/paths/paths.go | 19 - pkg/cmd/paths/paths_test.go | 9 - pkg/cmd/profile/profile.go | 115 ----- pkg/cmd/profile/profile_test.go | 1 - pkg/cmd/proxy/proxy.go | 161 ------- pkg/cmd/proxy/proxy_test.go | 13 - pkg/cmd/reset/doc.md | 27 -- pkg/cmd/reset/reset.go | 65 --- pkg/cmd/reset/reset_test.go | 1 - pkg/cmd/runtasks/doc.md | 2 - pkg/cmd/runtasks/runtasks.go | 88 ---- pkg/cmd/runtasks/runtasks_test.go | 1 - pkg/cmd/scale/scale.go | 100 ----- pkg/cmd/status/doc.md | 265 ----------- pkg/cmd/status/status.go | 61 --- pkg/cmd/status/status_test.go | 1 - pkg/cmd/tasks/tasks.go | 124 ------ pkg/cmd/test/test.go | 76 ---- pkg/cmd/test/test_test.go | 1 - pkg/cmd/updatemodel/updatemodel.go | 419 ------------------ pkg/cmd/updatemodel/updatemodel_test.go | 292 ------------ pkg/config/config.go | 5 - pkg/entity/entity.go | 12 +- pkg/store/user_test.go | 7 +- pkg/store/workspace.go | 42 +- 48 files changed, 36 insertions(+), 3721 deletions(-) delete mode 100644 pkg/cmd/background/background.go delete mode 100644 pkg/cmd/background/background_test.go delete mode 100644 pkg/cmd/clipboard/clipboard.go delete mode 100644 pkg/cmd/clipboard/clipboard_listener.go delete mode 100644 pkg/cmd/connect/connect.go delete mode 100644 pkg/cmd/create/create.go delete mode 100644 pkg/cmd/create/create_test.go delete mode 100644 pkg/cmd/create/doc.md delete mode 100644 pkg/cmd/envvars/envvars.go delete mode 100644 pkg/cmd/envvars/envvars_test.go delete mode 100644 pkg/cmd/fu/fu.go delete mode 100644 pkg/cmd/fu/fu_test.go delete mode 100644 pkg/cmd/importideconfig/importideconfig.go delete mode 100644 pkg/cmd/importideconfig/importideconfig_test.go delete mode 100644 pkg/cmd/ollama/ollama.go delete mode 100644 pkg/cmd/ollama/ollama_test.go delete mode 100644 pkg/cmd/ollama/ollamauiverb.yaml delete mode 100644 pkg/cmd/ollama/ollamaverb.yaml delete mode 100644 pkg/cmd/paths/paths.go delete mode 100644 pkg/cmd/paths/paths_test.go delete mode 100644 pkg/cmd/profile/profile.go delete mode 100644 pkg/cmd/profile/profile_test.go delete mode 100644 pkg/cmd/proxy/proxy.go delete mode 100644 pkg/cmd/proxy/proxy_test.go delete mode 100644 pkg/cmd/reset/doc.md delete mode 100644 pkg/cmd/reset/reset.go delete mode 100644 pkg/cmd/reset/reset_test.go delete mode 100644 pkg/cmd/runtasks/doc.md delete mode 100644 pkg/cmd/runtasks/runtasks.go delete mode 100644 pkg/cmd/runtasks/runtasks_test.go delete mode 100644 pkg/cmd/scale/scale.go delete mode 100644 pkg/cmd/status/doc.md delete mode 100644 pkg/cmd/status/status.go delete mode 100644 pkg/cmd/status/status_test.go delete mode 100644 pkg/cmd/tasks/tasks.go delete mode 100644 pkg/cmd/test/test.go delete mode 100644 pkg/cmd/test/test_test.go delete mode 100644 pkg/cmd/updatemodel/updatemodel.go delete mode 100644 pkg/cmd/updatemodel/updatemodel_test.go diff --git a/go.mod b/go.mod index 4d0829606..88c4de9e6 100644 --- a/go.mod +++ b/go.mod @@ -13,8 +13,6 @@ require ( github.com/cenkalti/backoff/v4 v4.3.0 github.com/fatih/color v1.13.0 github.com/getsentry/sentry-go v0.14.0 - github.com/gin-gonic/gin v1.10.0 - github.com/go-git/go-git/v5 v5.19.2 github.com/go-resty/resty/v2 v2.17.0 github.com/golang-jwt/jwt/v5 v5.3.0 github.com/google/go-cmp v0.7.0 @@ -22,7 +20,6 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.0 github.com/hashicorp/go-multierror v1.1.1 - github.com/hashicorp/go-version v1.4.0 github.com/jarcoal/httpmock v1.0.8 github.com/jinzhu/copier v0.4.0 github.com/kevinburke/ssh_config v1.2.0 @@ -31,7 +28,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/posthog/posthog-go v1.10.0 github.com/robfig/cron/v3 v3.0.1 - github.com/samber/lo v1.33.0 github.com/samber/mo v1.5.1 github.com/schollz/progressbar/v3 v3.9.0 github.com/sevlyar/go-daemon v0.1.5 @@ -40,7 +36,6 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.13.0 github.com/stretchr/testify v1.11.1 - github.com/tidwall/gjson v1.14.0 github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 github.com/wk8/go-ordered-map/v2 v2.0.0 github.com/writeas/go-strip-markdown v2.0.1+incompatible @@ -51,61 +46,33 @@ require ( require ( buf.build/gen/go/brevdev/protoc-gen-gotag/protocolbuffers/go v1.36.12-20220906235457-8b4922735da5.2 // indirect - dario.cat/mergo v1.0.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect - github.com/Microsoft/go-winio v0.6.2 // indirect - github.com/ProtonMail/go-crypto v1.1.6 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect - github.com/bytedance/sonic v1.11.6 // indirect - github.com/bytedance/sonic/loader v0.1.1 // indirect - github.com/cloudflare/circl v1.6.3 // indirect - github.com/cloudwego/base64x v0.1.4 // indirect - github.com/cloudwego/iasm v0.2.0 // indirect - github.com/cyphar/filepath-securejoin v0.6.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/emirpasic/gods v1.18.1 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect - github.com/go-git/go-billy/v5 v5.9.0 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/goccy/go-json v0.10.5 // indirect - github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect - github.com/klauspost/cpuid/v2 v2.3.0 // indirect - github.com/leodido/go-urn v1.4.0 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/onsi/gomega v1.34.1 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect - github.com/pjbgf/sha1cd v0.6.0 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect - github.com/skeema/knownhosts v1.3.1 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.4.1 // indirect - github.com/tidwall/match v1.1.1 // indirect - github.com/tidwall/pretty v1.2.0 // indirect - github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.12 // indirect github.com/x448/float16 v0.8.4 // indirect - github.com/xanzy/ssh-agent v0.3.3 // indirect - golang.org/x/arch v0.8.0 // indirect golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f // indirect golang.org/x/sync v0.22.0 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/warnings.v0 v0.1.2 // 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/go.sum b/go.sum index 294c9e6c4..1c1aa8b38 100644 --- a/go.sum +++ b/go.sum @@ -43,26 +43,15 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= connectrpc.com/connect v1.21.0 h1:LhqSJt7jHf5NJBo9Jq/t/9FjcYAideif0mg+qe2jCUs= connectrpc.com/connect v1.21.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4= -dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= -dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= -github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= -github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/NVIDIA/go-nvml v0.13.0-1 h1:OLX8Jq3dONuPOQPC7rndB6+iDmDakw0XTYgzMxObkEw= github.com/NVIDIA/go-nvml v0.13.0-1/go.mod h1:+KNA7c7gIBH7SKSJ1ntlwkfN80zdx8ovl4hrK3LmPt4= -github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw= -github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= -github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= -github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= @@ -71,10 +60,6 @@ github.com/brevdev/parse v0.0.11 h1:OamoC1hKFW75ngzSQx9HHRh5bf/G6154Y9M2y4HNmIw= github.com/brevdev/parse v0.0.11/go.mod h1:ML13fBCP6yZsZearRnglD+6UlqkpiVN7Hjf8R9pd0TY= github.com/briandowns/spinner v1.16.0 h1:DFmp6hEaIx2QXXuqSJmtfSBSAjRmpGiKG6ip2Wm/yOs= github.com/briandowns/spinner v1.16.0/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= -github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= -github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= -github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= -github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -85,12 +70,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8= -github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4= -github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= -github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= -github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= -github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -98,18 +77,12 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= -github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE= -github.com/cyphar/filepath-securejoin v0.6.1/go.mod h1:A8hd4EnAeyujCJRrICiOWqjS1AX0a9kM5XL+NwKoYSc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o= -github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -125,26 +98,10 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/getsentry/sentry-go v0.14.0 h1:rlOBkuFZRKKdUnKO+0U3JclRDQKlRu5vVQtkWSQvC70= github.com/getsentry/sentry-go v0.14.0/go.mod h1:RZPJKSw+adu8PBNygiri/A98FqVr2HtRckJk9XVxJ9I= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= -github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= -github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= -github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= -github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.9.0 h1:jItGXszUDRtR/AlferWPTMN4j38BQ88XnXKbilmmBPA= -github.com/go-git/go-billy/v5 v5.9.0/go.mod h1:jCnQMLj9eUgGU7+ludSTYoZL/GGmii14RxKFj7ROgHw= -github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= -github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= -github.com/go-git/go-git/v5 v5.19.2 h1:wkfn7vOlUBu8ivAWKBWisTiwJK4jYHzTF8Ndv1LyGqY= -github.com/go-git/go-git/v5 v5.19.2/go.mod h1:QqCBE1EFN5ddFmrliLQ3/ntRCUjZU3EJuwuB/jWEHjk= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -157,14 +114,6 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= -github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= -github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= -github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= -github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= -github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-resty/resty/v2 v2.17.0 h1:pW9DeXcaL4Rrym4EZ8v7L19zZiIlWPg5YXAcVmt+gN0= github.com/go-resty/resty/v2 v2.17.0/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= @@ -179,8 +128,6 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= -github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -262,8 +209,6 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4= -github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= @@ -278,8 +223,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jarcoal/httpmock v1.0.8 h1:8kI16SoO6LQKgPE7PvQuV+YuD/inwHd7fOOe2zMbo4k= github.com/jarcoal/httpmock v1.0.8/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedib0t/go-pretty/v6 v6.3.1 h1:aOXiD9oqiuLH8btPQW6SfgtQN5zwhyfzZls8a6sPJ/I= github.com/jedib0t/go-pretty/v6 v6.3.1/go.mod h1:FMkOpgGD3EZ91cW8g/96RfxoV7bdeJyzXPYgz1L1ln0= github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= @@ -297,10 +240,6 @@ github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4 github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= -github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= -github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -310,8 +249,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= -github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= @@ -359,8 +296,6 @@ github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+v github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pjbgf/sha1cd v0.6.0 h1:3WJ8Wz8gvDz29quX1OcEmkAlUg9diU4GxJHqs0/XiwU= -github.com/pjbgf/sha1cd v0.6.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -381,8 +316,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/samber/lo v1.33.0 h1:2aKucr+rQV6gHpY3bpeZu69uYoQOzVhGT3J22Op6Cjk= -github.com/samber/lo v1.33.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8= github.com/samber/mo v1.5.1 h1:5dRSevAB33Q/OrYwTmtksHHxquuf2urnRSUTsdTFysY= github.com/samber/mo v1.5.1/go.mod h1:pDuQgWscOVGGoEz+NAeth/Xq+MPAcXxCeph1XIAm/DU= github.com/schollz/progressbar/v3 v3.9.0 h1:k9SRNQ8KZyibz1UZOaKxnkUE3iGtmGSDt1YY9KlCYQk= @@ -391,12 +324,9 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/sevlyar/go-daemon v0.1.5 h1:Zy/6jLbM8CfqJ4x4RPr7MJlSKt90f00kNM1D401C+Qk= github.com/sevlyar/go-daemon v0.1.5/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE= -github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= -github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= -github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw= github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= @@ -428,28 +358,14 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs= github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= -github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= -github.com/tidwall/gjson v1.14.0 h1:6aeJ0bzojgWLa82gDQHcx3S0Lr/O51I9bJ5nv6JFx5w= -github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 h1:X9dsIWPuuEJlPX//UmRKophhOKCGXc46RVIGuttks68= github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7/go.mod h1:UxoP3EypF8JfGEjAII8jx1q8rQyDnX8qdTCs/UQBVIE= -github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= -github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= -github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/wk8/go-ordered-map/v2 v2.0.0 h1:jWOAU/F5AkYb8jr/rkVPe418g7nf2CZBzyfOR4Y7Q1w= github.com/wk8/go-ordered-map/v2 v2.0.0/go.mod h1:fGIuB3GmY3JZP6L3t5riKtaSH9u13IYVYvar5Ee+9lM= github.com/writeas/go-strip-markdown v2.0.1+incompatible h1:IIqxTM5Jr7RzhigcL6FkrCNfXkvbR+Nbu1ls48pXYcw= github.com/writeas/go-strip-markdown v2.0.1+incompatible/go.mod h1:Rsyu10ZhbEK9pXdk8V6MVnZmTzRG0alMNLMwa0J01fE= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= -github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= -github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ= github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -466,9 +382,6 @@ go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93V go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= -golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -477,7 +390,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -608,7 +520,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -799,8 +710,6 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= @@ -830,9 +739,7 @@ k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7F k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A= k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/pkg/cmd/background/background.go b/pkg/cmd/background/background.go deleted file mode 100644 index a06c1974b..000000000 --- a/pkg/cmd/background/background.go +++ /dev/null @@ -1,183 +0,0 @@ -package background - -import ( - "bufio" - "fmt" - "log" - "os" - "os/exec" - "strings" - "time" - - "github.com/brevdev/brev-cli/pkg/analytics" - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/entity" - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" -) - -type BackgroundStore interface { - util.GetWorkspaceByNameOrIDErrStore - GetActiveOrganizationOrDefault() (*entity.Organization, error) - GetCurrentUser() (*entity.User, error) - ModifyWorkspace(workspaceID string, options *store.ModifyWorkspaceRequest) (*entity.Workspace, error) - GetWorkspace(workspaceID string) (*entity.Workspace, error) - GetCurrentWorkspaceID() (string, error) - CreateWorkspace(organizationID string, options *store.CreateWorkspacesOptions) (*entity.Workspace, error) -} - -func NewCmdBackground(t *terminal.Terminal, s BackgroundStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "background [flags] [command]", - Aliases: []string{"bg"}, - DisableFlagsInUseLine: true, - Short: "Run a command in the background with optional 'brev stop self' at the end", - Long: "This command will run a specified command in the background using nohup and write logs to $HOME/brev-background-logs.", - Example: "brev background ./myscript.sh --stop", - RunE: func(cmd *cobra.Command, args []string) error { - // Parse the flags - stopFlag, err := cmd.Flags().GetBool("stop") - if err != nil { - log.Fatal(err) - } - progressFlag, err := cmd.Flags().GetBool("progress") - if err != nil { - log.Fatal(err) - } - if progressFlag { - checkProgress() - return nil - } - // Join the args into a command string - command := "" - if len(args) > 0 { - command = args[0] - } - for i := 1; i < len(args); i++ { - command += " " + args[i] - } - // Create logs directory if it doesn't exist - logsDir := os.Getenv("HOME") + "/brev-background-logs" - // Suppress error by Lint to lower the permission level (os.ModePerm) - err = os.MkdirAll(logsDir, os.ModePerm) //nolint:gosec // ok: directory must be world-writable - if err != nil { - log.Fatal(err) - } - - // Run the command in the background using nohup - c := exec.Command("nohup", "bash", "-c", command+">"+logsDir+"/log.txt 2>&1 &") // #nosec G204 - err = c.Start() - if err != nil { - log.Fatal(err) - } - // Write logs - logFile, err := os.OpenFile(logsDir+"/log.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o666) //nolint: gosec // TODO - if err != nil { - log.Fatal(err) - } - defer logFile.Close() //nolint: errcheck // TODO - logFile.WriteString(time.Now().Format("2006-01-02 15:04:05") + ": Command \"" + command + "\" was run in the background.\n") //nolint: errcheck,gosec // TODO - - // Write process details to data file - processesFile, err := os.OpenFile(logsDir+"/processes.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o666) //nolint: gosec // TODO - if err != nil { - log.Fatal(err) - } - defer processesFile.Close() //nolint: errcheck // TODO - _, _ = processesFile.WriteString(fmt.Sprintf("%d,%s,%s\n", c.Process.Pid, time.Now().Format("2006-01-02 15:04:05"), command)) - - if stopFlag { - // If --stop flag is set, run "brev stop self" at the end - defer func() { - stopCmd := exec.Command("brev", "stop", "self") - err = stopCmd.Run() - if err != nil { - log.Fatal(err) - } - }() - } - // Call analytics for open - _ = pushBackgroundAnalytics(s) - - t.Vprintf("Command \"%s\" has been run in the background. Check %s for logs.\n", command, logsDir) - return nil - }, - } - cmd.Flags().Bool("stop", false, "Stop the workspace after the command is finished") - cmd.Flags().Bool("progress", false, "Show progress of the background commands") - return cmd -} - -func pushBackgroundAnalytics(s BackgroundStore) error { - // Call analytics for open - userID := "" - user, err := s.GetCurrentUser() - if err != nil { - userID = "" - } else { - userID = user.ID - } - data := analytics.EventData{ - EventName: "Brev background", - UserID: userID, - } - err = analytics.TrackEvent(data) - return breverrors.WrapAndTrace(err) -} - -type Process struct { - ID int `json:"id"` - Command string `json:"command"` - LogsDir string `json:"logsDir"` - StartTime string `json:"startTime"` -} - -type Processes struct { - Processes []Process `json:"processes"` -} - -func checkProgress() { - filePath := fmt.Sprintf("%s/brev-background-logs/processes.txt", os.Getenv("HOME")) - file, err := os.Open(filePath) //nolint: gosec // TODO - if err != nil { - panic(err) - } - defer file.Close() //nolint: errcheck // TODO - - scanner := bufio.NewScanner(file) - - fmt.Println("Running processes:") - for scanner.Scan() { - processLine := scanner.Text() - processData := strings.Split(processLine, ",") - - startTime, err := time.Parse("2006-01-02 15:04:05", processData[1]) - if err != nil { - panic(err) - } - - // Check if the process is still running by its PID - processID := processData[0] - cmd := fmt.Sprintf("ps -p %s -o comm=", processID) - output, err := exec.Command("bash", "-c", cmd).Output() //nolint: gosec // TODO - - if err != nil || strings.TrimSpace(string(output)) == "" { - // Process is not running, show a checkmark - fmt.Printf("ID: %s \u2713\n", processID) - } else { - // Process is still running, display its info - fmt.Printf("ID: %s\n", processID) - fmt.Printf("Command: %s\n", processData[2]) - fmt.Printf("Start time: %s\n", startTime.Format("2006-01-02 15:04:05")) - } - - fmt.Println() - } - - if err := scanner.Err(); err != nil { - panic(err) - } -} diff --git a/pkg/cmd/background/background_test.go b/pkg/cmd/background/background_test.go deleted file mode 100644 index 313dbd6c5..000000000 --- a/pkg/cmd/background/background_test.go +++ /dev/null @@ -1 +0,0 @@ -package background diff --git a/pkg/cmd/clipboard/clipboard.go b/pkg/cmd/clipboard/clipboard.go deleted file mode 100644 index 38857c812..000000000 --- a/pkg/cmd/clipboard/clipboard.go +++ /dev/null @@ -1,105 +0,0 @@ -package clipboard - -import ( - "fmt" - "os" - "os/exec" - - "github.com/brevdev/brev-cli/pkg/cmd/cmderrors" - "github.com/brevdev/brev-cli/pkg/cmd/completions" - - "github.com/brevdev/brev-cli/pkg/cmd/portforward" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" -) - -type ClipboardStore interface { - completions.CompletionStore -} - -// Step 1 -func EstablishConnection(t *terminal.Terminal, clipboardStore ClipboardStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"ssh": ""}, - Use: "connect", - DisableFlagsInUseLine: true, - Short: "Connects to remote", - Long: "Connects to remote", - Example: "connect", - Args: cmderrors.TransformToValidationError(cobra.ExactArgs(0)), - ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(clipboardStore, t), - Run: func(cmd *cobra.Command, args []string) { - // Listen to Port - listener := CreateListener(&Config{ - Host: "127.0.0.1", - Port: "6969", - }) - listener.Run() - }, - } - return cmd -} - -func SaveToClipboard(output string) { - // copy to clipboard - command := fmt.Sprintf("echo %s | pbcopy", output) - cmd := exec.Command("bash", "-c", command) //nolint:gosec // testing - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Start() - if err != nil { - fmt.Println(err) - } - err1 := cmd.Wait() - if err1 != nil { - fmt.Println(err1) - } -} - -// Step 2 -func ForwardPort(t *terminal.Terminal, clipboardStore ClipboardStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"ssh": ""}, - Use: "remote-forward ", - DisableFlagsInUseLine: true, - Short: "remote forward port", - Long: "remote forward port", - Example: "remote-forward", - Args: cmderrors.TransformToValidationError(cobra.ExactArgs(1)), - ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(clipboardStore, t), - Run: func(cmd *cobra.Command, args []string) { - // Portforward - _, sshError := portforward.RunSSHPortForward("-R", "6969", "6969", args[0]) - if sshError != nil { - t.Errprint(sshError, "Failed to connect to local") - return - } - }, - } - return cmd -} - -// Step 3 -func SendToClipboard(t *terminal.Terminal, clipboardStore ClipboardStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"clipboard": ""}, - Use: "clipboard", - DisableFlagsInUseLine: true, - Short: "Copies clipboard from remote instance to local clipboard", - Long: "Copies clipboard from remote instance to local clipboard", - Example: "clipboard", - Args: cmderrors.TransformToValidationError(cobra.ExactArgs(0)), - ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(clipboardStore, t), - Run: func(cmd *cobra.Command, args []string) { - // Send output - err := SendRequest("localhost:6969", "hello world") - if err != nil { - t.Errprint(err, "Failed to copy to clipboard") - return - } - }, - } - - return cmd -} diff --git a/pkg/cmd/clipboard/clipboard_listener.go b/pkg/cmd/clipboard/clipboard_listener.go deleted file mode 100644 index 38faadb2b..000000000 --- a/pkg/cmd/clipboard/clipboard_listener.go +++ /dev/null @@ -1,71 +0,0 @@ -package clipboard - -import ( - "context" - "fmt" - "io/ioutil" - "net/http" - "strings" - - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/gin-gonic/gin" -) - -// Server ... -type Server struct { - host string - port string -} - -// Config ... -type Config struct { - Host string - Port string -} - -// New ... -func CreateListener(config *Config) *Server { - return &Server{ - host: config.Host, - port: config.Port, - } -} - -// tcp req -func SendRequest(address string, message string) error { - reader := strings.NewReader(message) - request, err := http.NewRequestWithContext(context.TODO(), "GET", "http://"+address+"/", reader) - if err != nil { - fmt.Println(err) - return breverrors.WrapAndTrace(err) - } - client := &http.Client{} - resp, err := client.Do(request) - fmt.Println(resp) - if err != nil { - fmt.Println(err) - return breverrors.WrapAndTrace(err) - } - defer resp.Body.Close() //nolint:errcheck //deving and defer - return nil -} - -// Run ... -func (server *Server) Run() { - // Starts a new Gin instance with no middle-ware - r := gin.New() - - r.GET("/", func(c *gin.Context) { - jsonData, err := ioutil.ReadAll(c.Request.Body) - if err != nil { - // Handle error - c.String(http.StatusBadRequest, "Can't parse body") - } - SaveToClipboard(string(jsonData)) - c.String(http.StatusOK, "success") - }) - err := r.Run(server.host + ":" + server.port) - if err != nil { - fmt.Println(err) - } -} diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 09113ae94..759f6aa46 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -10,26 +10,20 @@ import ( "github.com/brevdev/brev-cli/pkg/auth" "github.com/brevdev/brev-cli/pkg/cmd/agentskill" analyticscmd "github.com/brevdev/brev-cli/pkg/cmd/analytics" - "github.com/brevdev/brev-cli/pkg/cmd/background" - "github.com/brevdev/brev-cli/pkg/cmd/clipboard" "github.com/brevdev/brev-cli/pkg/cmd/completions" "github.com/brevdev/brev-cli/pkg/cmd/configureenvvars" - "github.com/brevdev/brev-cli/pkg/cmd/connect" "github.com/brevdev/brev-cli/pkg/cmd/copy" "github.com/brevdev/brev-cli/pkg/cmd/delete" "github.com/brevdev/brev-cli/pkg/cmd/deregister" "github.com/brevdev/brev-cli/pkg/cmd/disablessh" "github.com/brevdev/brev-cli/pkg/cmd/enablessh" - "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" "github.com/brevdev/brev-cli/pkg/cmd/healthcheck" "github.com/brevdev/brev-cli/pkg/cmd/hello" - "github.com/brevdev/brev-cli/pkg/cmd/importideconfig" "github.com/brevdev/brev-cli/pkg/cmd/invite" "github.com/brevdev/brev-cli/pkg/cmd/launch" "github.com/brevdev/brev-cli/pkg/cmd/login" @@ -37,31 +31,21 @@ import ( "github.com/brevdev/brev-cli/pkg/cmd/ls" "github.com/brevdev/brev-cli/pkg/cmd/mintcert" "github.com/brevdev/brev-cli/pkg/cmd/notebook" - "github.com/brevdev/brev-cli/pkg/cmd/ollama" "github.com/brevdev/brev-cli/pkg/cmd/open" "github.com/brevdev/brev-cli/pkg/cmd/org" "github.com/brevdev/brev-cli/pkg/cmd/portforward" "github.com/brevdev/brev-cli/pkg/cmd/ports" - "github.com/brevdev/brev-cli/pkg/cmd/profile" - "github.com/brevdev/brev-cli/pkg/cmd/proxy" "github.com/brevdev/brev-cli/pkg/cmd/redeem" "github.com/brevdev/brev-cli/pkg/cmd/refresh" "github.com/brevdev/brev-cli/pkg/cmd/register" - "github.com/brevdev/brev-cli/pkg/cmd/reset" "github.com/brevdev/brev-cli/pkg/cmd/revokessh" - "github.com/brevdev/brev-cli/pkg/cmd/runtasks" - "github.com/brevdev/brev-cli/pkg/cmd/scale" "github.com/brevdev/brev-cli/pkg/cmd/secrets" "github.com/brevdev/brev-cli/pkg/cmd/set" "github.com/brevdev/brev-cli/pkg/cmd/setupworkspace" "github.com/brevdev/brev-cli/pkg/cmd/shell" "github.com/brevdev/brev-cli/pkg/cmd/sshkeys" "github.com/brevdev/brev-cli/pkg/cmd/start" - "github.com/brevdev/brev-cli/pkg/cmd/status" "github.com/brevdev/brev-cli/pkg/cmd/stop" - "github.com/brevdev/brev-cli/pkg/cmd/tasks" - "github.com/brevdev/brev-cli/pkg/cmd/test" - "github.com/brevdev/brev-cli/pkg/cmd/updatemodel" "github.com/brevdev/brev-cli/pkg/cmd/upgrade" "github.com/brevdev/brev-cli/pkg/cmd/version" "github.com/brevdev/brev-cli/pkg/config" @@ -100,7 +84,6 @@ func NewDefaultBrevCommand() *cobra.Command { cmd.PersistentFlags().StringVar(&userFlag, "user", "", "Non root user to use for per user configuration of commands run as root") cmd.PersistentFlags().StringVar(&apiKeyFlag, "api-key", "", "api key to authenticate CLI requests") - _ = cmd.PersistentFlags().MarkHidden("api-key") analytics.MarkFlagSensitive(cmd.PersistentFlags(), "api-key") cmd.PersistentFlags().BoolVar(&printVersion, "version", false, "Print version output") cmd.PersistentFlags().BoolVar(&noCheckLatest, "no-check-latest", false, "Do not check for the latest version when printing version") @@ -323,69 +306,53 @@ func NewBrevCommand() *cobra.Command { //nolint:funlen,gocognit,gocyclo // defin } func createCmdTree(cmd *cobra.Command, t *terminal.Terminal, loginCmdStore *store.AuthHTTPStore, noLoginCmdStore *store.AuthHTTPStore, loginAuth *auth.LoginAuth, externalNodeCmdStore *store.AuthHTTPStore) { //nolint:funlen // define brev command + // user + cmd.AddCommand(login.NewCmdLogin(t, noLoginCmdStore, loginAuth)) + cmd.AddCommand(logout.NewCmdLogout(loginAuth, noLoginCmdStore)) + cmd.AddCommand(hello.NewCmdHello(t, noLoginCmdStore)) + cmd.AddCommand(configureenvvars.NewCmdConfigureEnvVars(t, loginCmdStore)) + cmd.AddCommand(analyticscmd.NewCmdAnalytics(t)) + + // organization cmd.AddCommand(set.NewCmdSet(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(ls.NewCmdLs(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(org.NewCmdOrg(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(invite.NewCmdInvite(t, loginCmdStore)) + cmd.AddCommand(secrets.NewCmdSecrets(t, loginCmdStore)) + + // instances cmd.AddCommand(redeem.NewCmdRedeem(t, loginCmdStore)) cmd.AddCommand(portforward.NewCmdPortForwardSSH(loginCmdStore, t)) cmd.AddCommand(ports.NewCmdPorts(loginCmdStore)) - cmd.AddCommand(login.NewCmdLogin(t, noLoginCmdStore, loginAuth)) - cmd.AddCommand(logout.NewCmdLogout(loginAuth, noLoginCmdStore)) - cmd.AddCommand(tasks.NewCmdTasks(t, noLoginCmdStore)) - cmd.AddCommand(tasks.NewCmdConfigure(t, noLoginCmdStore)) - cmd.AddCommand(hello.NewCmdHello(t, noLoginCmdStore)) - cmd.AddCommand(notebook.NewCmdNotebook(noLoginCmdStore, t)) - // dev feature toggle - if featureflag.IsDev() { - _ = 0 // noop - cmd.AddCommand(test.NewCmdTest(t, noLoginCmdStore)) - cmd.AddCommand(clipboard.EstablishConnection(t, loginCmdStore)) - cmd.AddCommand(clipboard.SendToClipboard(t, loginCmdStore)) - 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 - } - cmd.AddCommand(scale.NewCmdScale(t, noLoginCmdStore)) - cmd.AddCommand(gpusearch.NewCmdGPUSearch(t, noLoginCmdStore)) - cmd.AddCommand(gpucreate.NewCmdGPUCreate(t, loginCmdStore)) - cmd.AddCommand(launch.NewCmdLaunch(t, loginCmdStore)) - cmd.AddCommand(configureenvvars.NewCmdConfigureEnvVars(t, loginCmdStore)) - cmd.AddCommand(importideconfig.NewCmdImportIDEConfig(t, noLoginCmdStore)) cmd.AddCommand(shell.NewCmdShell(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(mintcert.NewCmdMintCert(noLoginCmdStore)) cmd.AddCommand(exec.NewCmdExec(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(copy.NewCmdCopy(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(open.NewCmdOpen(t, loginCmdStore, noLoginCmdStore)) - cmd.AddCommand(ollama.NewCmdOllama(t, loginCmdStore)) - cmd.AddCommand(agentskill.NewCmdAgentSkill(t, noLoginCmdStore)) - cmd.AddCommand(analyticscmd.NewCmdAnalytics(t)) - cmd.AddCommand(background.NewCmdBackground(t, loginCmdStore)) - cmd.AddCommand(status.NewCmdStatus(t, loginCmdStore)) - cmd.AddCommand(sshkeys.NewCmdSSHKeys(t, loginCmdStore)) + cmd.AddCommand(notebook.NewCmdNotebook(noLoginCmdStore, t)) + cmd.AddCommand(gpusearch.NewCmdGPUSearch(t, noLoginCmdStore)) + cmd.AddCommand(gpucreate.NewCmdGPUCreate(t, loginCmdStore)) + cmd.AddCommand(launch.NewCmdLaunch(t, loginCmdStore)) cmd.AddCommand(start.NewCmdStart(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(stop.NewCmdStop(t, loginCmdStore, noLoginCmdStore)) + cmd.AddCommand(sshkeys.NewCmdSSHKeys(t, loginCmdStore)) cmd.AddCommand(delete.NewCmdDelete(t, loginCmdStore, noLoginCmdStore)) - cmd.AddCommand(reset.NewCmdReset(t, loginCmdStore, noLoginCmdStore)) - cmd.AddCommand(profile.NewCmdProfile(t, loginCmdStore, noLoginCmdStore)) cmd.AddCommand(refresh.NewCmdRefresh(t, loginCmdStore)) + + // brev connect cmd.AddCommand(register.NewCmdRegister(t, externalNodeCmdStore)) cmd.AddCommand(deregister.NewCmdDeregister(t, externalNodeCmdStore)) - cmd.AddCommand(upgrade.NewCmdUpgrade(t, noLoginCmdStore)) cmd.AddCommand(enablessh.NewCmdEnableSSH(t, externalNodeCmdStore)) cmd.AddCommand(disablessh.NewCmdDisableSSH(t, externalNodeCmdStore)) cmd.AddCommand(grantssh.NewCmdGrantSSH(t, externalNodeCmdStore)) cmd.AddCommand(revokessh.NewCmdRevokeSSH(t, externalNodeCmdStore)) - cmd.AddCommand(runtasks.NewCmdRunTasks(t, noLoginCmdStore)) - cmd.AddCommand(proxy.NewCmdProxy(t, noLoginCmdStore)) + + // misc and tests + cmd.AddCommand(agentskill.NewCmdAgentSkill(t, noLoginCmdStore)) + cmd.AddCommand(upgrade.NewCmdUpgrade(t, noLoginCmdStore)) cmd.AddCommand(healthcheck.NewCmdHealthcheck(t, noLoginCmdStore)) - cmd.AddCommand(setupworkspace.NewCmdSetupWorkspace(noLoginCmdStore)) - cmd.AddCommand(updatemodel.NewCmdupdatemodel(t, loginCmdStore)) cmd.AddCommand(feedback.NewCmdFeedback(t, noLoginCmdStore)) - cmd.AddCommand(secrets.NewCmdSecrets(t, loginCmdStore)) + cmd.AddCommand(setupworkspace.NewCmdSetupWorkspace(noLoginCmdStore)) } func hasWorkspaceCommands(cmd *cobra.Command) bool { diff --git a/pkg/cmd/connect/connect.go b/pkg/cmd/connect/connect.go deleted file mode 100644 index 33a462bff..000000000 --- a/pkg/cmd/connect/connect.go +++ /dev/null @@ -1,57 +0,0 @@ -package connect - -import ( - "github.com/spf13/cobra" - - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/terminal" -) - -var ( - short = "Connect Brev to your AWS account" - long = "Connect Brev to your AWS account" - example = "brev connect" -) - -type connectStore interface{} - -func NewCmdConnect(t *terminal.Terminal, store connectStore) *cobra.Command { - cmd := &cobra.Command{ - Use: "connect-aws", - DisableFlagsInUseLine: true, - Short: short, - Long: long, - Example: example, - RunE: func(cmd *cobra.Command, args []string) error { - err := RunConnect(t, args, store) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - return cmd -} - -func RunConnect(t *terminal.Terminal, _ []string, _ connectStore) error { - t.Vprintf("Connect the AWS IAM user to create instances in your AWS account.\n") - t.Vprintf("%s", t.Yellow("\tFollow the guide here: %s", "https://onboarding.brev.dev/connect-aws\n\n")) - // t.Vprintf(t.Yellow("Connect the AWS IAM user to create dev environments in your AWS account.\n\n")) - - AccessKeyID := terminal.PromptGetInput(terminal.PromptContent{ - Label: "Access Key ID: ", - ErrorMsg: "error", - }) - - SecretAccessKey := terminal.PromptGetInput(terminal.PromptContent{ - Label: "Secret Access Key: ", - ErrorMsg: "error", - Mask: '*', - }) - - t.Vprintf("\n") - t.Vprintf("%s", AccessKeyID) - t.Vprintf("%s", SecretAccessKey) - - return nil -} diff --git a/pkg/cmd/create/create.go b/pkg/cmd/create/create.go deleted file mode 100644 index ac1fab865..000000000 --- a/pkg/cmd/create/create.go +++ /dev/null @@ -1,208 +0,0 @@ -// Deprecated: This package is superseded by pkg/cmd/gpucreate which is the -// registered "brev create" command. This code is not wired into cmd.go and -// should not be modified. Use gpucreate for all new work. -package create - -import ( - "fmt" - "strings" - "time" - - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/config" - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/featureflag" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" - - breverrors "github.com/brevdev/brev-cli/pkg/errors" -) - -var ( - createLong = "Create a new Brev machine" - createExample = ` - brev create - ` - // instanceTypes = []string{"p4d.24xlarge", "p3.2xlarge", "p3.8xlarge", "p3.16xlarge", "p3dn.24xlarge", "p2.xlarge", "p2.8xlarge", "p2.16xlarge", "g5.xlarge", "g5.2xlarge", "g5.4xlarge", "g5.8xlarge", "g5.16xlarge", "g5.12xlarge", "g5.24xlarge", "g5.48xlarge", "g5g.xlarge", "g5g.2xlarge", "g5g.4xlarge", "g5g.8xlarge", "g5g.16xlarge", "g5g.metal", "g4dn.xlarge", "g4dn.2xlarge", "g4dn.4xlarge", "g4dn.8xlarge", "g4dn.16xlarge", "g4dn.12xlarge", "g4dn.metal", "g4ad.xlarge", "g4ad.2xlarge", "g4ad.4xlarge", "g4ad.8xlarge", "g4ad.16xlarge", "g3s.xlarge", "g3.4xlarge", "g3.8xlarge", "g3.16xlarge"} -) - -type CreateStore interface { - util.GetWorkspaceByNameOrIDErrStore - GetActiveOrganizationOrDefault() (*entity.Organization, error) - GetCurrentUser() (*entity.User, error) - GetWorkspace(workspaceID string) (*entity.Workspace, error) - CreateWorkspace(organizationID string, options *store.CreateWorkspacesOptions) (*entity.Workspace, error) -} - -func NewCmdCreate(t *terminal.Terminal, createStore CreateStore) *cobra.Command { - var detached bool - var gpu string - var cpu string - - cmd := &cobra.Command{ - Annotations: map[string]string{"workspace": ""}, - Use: "create", - DisableFlagsInUseLine: true, - Short: "Create a new instance", - Long: createLong, - Example: createExample, - RunE: func(cmd *cobra.Command, args []string) error { - name := "" - if len(args) > 0 { - name = args[0] - } - - err := runCreateWorkspace(t, CreateOptions{ - Name: name, - WorkspaceClass: cpu, - Detached: detached, - InstanceType: gpu, - }, createStore) - if err != nil { - if strings.Contains(err.Error(), "duplicate instance with name") { - t.Vprint(t.Yellow("try running:")) - t.Vprint(t.Yellow("\tbrev start --name [different name] [repo] # or")) - t.Vprint(t.Yellow("\tbrev delete [name]")) - } - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - cmd.Flags().BoolVarP(&detached, "detached", "d", false, "run the command in the background instead of blocking the shell") - cmd.Flags().StringVarP(&cpu, "cpu", "c", "", "CPU instance type. Defaults to 2x8 [2x8, 4x16, 8x32, 16x32]. See docs.brev.dev/cpu for details") - cmd.Flags().StringVarP(&gpu, "gpu", "g", "n1-highmem-4:nvidia-tesla-t4:1", "GPU instance type. See https://brev.dev/docs/reference/gpu for details") - return cmd -} - -type CreateOptions struct { - Name string - WorkspaceClass string - Detached bool - InstanceType string -} - -func runCreateWorkspace(t *terminal.Terminal, options CreateOptions, createStore CreateStore) error { - user, err := createStore.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - err = createEmptyWorkspace(user, t, options, createStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil -} - -func createEmptyWorkspace(user *entity.User, t *terminal.Terminal, options CreateOptions, createStore CreateStore) error { - // ensure name - if len(options.Name) == 0 { - return breverrors.NewValidationError("A name field is required to create a workspace!") - } - - // ensure org - var orgID string - activeorg, err := createStore.GetActiveOrganizationOrDefault() - if err != nil { - return breverrors.WrapAndTrace(err) - } - if activeorg == nil { - return breverrors.NewValidationError("no org exist") - } - orgID = activeorg.ID - - clusterID := config.GlobalConfig.GetDefaultClusterID() - cwOptions := store.NewCreateWorkspacesOptions(clusterID, options.Name) - - if options.WorkspaceClass != "" { - cwOptions.WithClassID(options.WorkspaceClass) - } - - cwOptions = resolveWorkspaceUserOptions(cwOptions, user) - - if options.InstanceType != "" { - cwOptions.WithInstanceType(options.InstanceType) - } - - t.Vprintf("Creating instane %s in org %s\n", t.Green(cwOptions.Name), t.Green(orgID)) - t.Vprintf("\tname %s\n", t.Green(cwOptions.Name)) - if options.InstanceType != "" { - t.Vprintf("\tGPU instance %s\n", t.Green(options.InstanceType)) - } else { - t.Vprintf("\tCPU instance %s\n", t.Green(cwOptions.WorkspaceClassID)) - } - - s := t.NewSpinner() - s.Suffix = " Creating your instance. Hang tight 🤙" - s.Start() - w, err := createStore.CreateWorkspace(orgID, cwOptions) - if err != nil { - return breverrors.WrapAndTrace(err) - } - s.Stop() - - if options.Detached { - return nil - } else { - err = pollUntil(t, w.ID, entity.Running, createStore, true) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - fmt.Print("\n") - t.Vprint(t.Green("Your instance is ready!\n")) - displayConnectBreadCrumb(t, w) - - return nil - } -} - -func resolveWorkspaceUserOptions(options *store.CreateWorkspacesOptions, user *entity.User) *store.CreateWorkspacesOptions { - if options.WorkspaceTemplateID == "" { - if featureflag.IsAdmin(user.GlobalUserType) { - options.WorkspaceTemplateID = store.DevWorkspaceTemplateID - } else { - options.WorkspaceTemplateID = store.UserWorkspaceTemplateID - } - } - if options.WorkspaceClassID == "" { - if featureflag.IsAdmin(user.GlobalUserType) { - options.WorkspaceClassID = store.DevWorkspaceClassID - } else { - options.WorkspaceClassID = store.UserWorkspaceClassID - } - } - return options -} - -func displayConnectBreadCrumb(t *terminal.Terminal, workspace *entity.Workspace) { - t.Vprintf("%s", t.Green("Connect to the instance:\n")) - t.Vprintf("%s", t.Yellow(fmt.Sprintf("\tbrev open %s\t# brev open -> open instance in VS Code\n", workspace.Name))) - t.Vprintf("%s", t.Yellow(fmt.Sprintf("\tbrev shell %s\t# brev shell -> ssh into instance (shortcut)\n", workspace.Name))) - // t.Vprintf(t.Yellow(fmt.Sprintf("\tssh %s\t# ssh -> ssh directly to dev environment\n", workspace.GetLocalIdentifier()))) -} - -func pollUntil(t *terminal.Terminal, wsid string, state string, createStore CreateStore, canSafelyExit bool) error { - s := t.NewSpinner() - isReady := false - if canSafelyExit { - t.Vprintf("You can safely ctrl+c to exit\n") - } - s.Suffix = " hang tight 🤙" - s.Start() - for !isReady { - time.Sleep(5 * time.Second) - ws, err := createStore.GetWorkspace(wsid) - if err != nil { - return breverrors.WrapAndTrace(err) - } - s.Suffix = " instance is " + strings.ToLower(ws.Status) - if ws.Status == state { - s.Suffix = "Instance is ready!" - s.Stop() - isReady = true - } - } - return nil -} diff --git a/pkg/cmd/create/create_test.go b/pkg/cmd/create/create_test.go deleted file mode 100644 index ef4f218a0..000000000 --- a/pkg/cmd/create/create_test.go +++ /dev/null @@ -1 +0,0 @@ -package create diff --git a/pkg/cmd/create/doc.md b/pkg/cmd/create/doc.md deleted file mode 100644 index 0a856447e..000000000 --- a/pkg/cmd/create/doc.md +++ /dev/null @@ -1,265 +0,0 @@ -create start and join a workspace - -## Synopsis - -``` - -brev start { ARG | -e} {-n | --name} {-c | --class} { -s | --setup-script} - {-r | --setup-repo} {-p | --setup-path } { -o | --org} -``` - -## Description - -brev start can do the following: - -- start a stopped workspace -- join a workspace in an organization -- create an empty workspace -- create a workspace from a directory on your computer -- create a workspace from a git url - -## Flags - -### -n --name - -specify the name for your workspace instead of brev-cli generating one for you. - -for example, to override the name of a workspace when creating a workspace from -a git repo you could do it with then `-n` flag. This example creates a repo with -the name `cli` from the git repo `https://github.com/brevdev/brev-cli`. - -``` -$ brev start https://github.com/brevdev/brev-cli -n cli -``` - -## Examples - -### Create an empty workspace - -``` -$ brev start -e -n foo -``` - -which has an output similar too: - -``` -name foo -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -workspace is starting. this can take up to 2 minutes the first time. - -you can safely ctrl+c to exit -⣽ workspace is deploying -your workspace is ready! - -connect to the workspace: - brev open foo # brev open -> open workspace in preferred editor - brev shell foo # brev shell -> ssh into workspace (shortcut) - ssh foo-8j4u # ssh -> ssh directly to workspace - -``` - -or - -``` -$ brev start --empty --name foo -``` - -which has an output similar too: - -``` -name foo -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -workspace is starting. this can take up to 2 minutes the first time. - -you can safely ctrl+c to exit -⣽ workspace is deploying -your workspace is ready! - -connect to the workspace: - brev open foo # brev open -> open workspace in preferred editor - brev shell foo # brev shell -> ssh into workspace (shortcut) - ssh foo-8j4u # ssh -> ssh directly to workspace - -``` - -view your workspace with `brev ls` - -### create a workspace, and do not block shell until workspace is created - -use the `-d` or `--detached` flag to create a workspace and immediately exit -rather than wait for workspace to be successfully created before exiting. - -``` -$ brev start -d -e -n bar -``` - -which has an output similar too: - -``` -name bar -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -Workspace is starting. This can take up to 2 minutes the first time. -``` - -### Create a workspace from a file path - -if in your current directory has a directory in it called `merge-json`, you can -create a workspace using the contents of that directory using -`brev start merge-json` - -``` -$ ls -merge-json -``` - -``` -$ brev start merge-json - -``` - -which has an output similar too: - -``` -Workspace is starting. This can take up to 2 minutes the first time. - -name merge-json -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⡿ workspace is deploying -Your workspace is ready! - -Connect to the workspace: - brev open merge-json # brev open -> open workspace in preferred editor - brev shell merge-json # brev shell -> ssh into workspace (shortcut) - ssh merge-json-wd6q # ssh -> ssh directly to workspace -``` - -### Create a workspace from a git repository - -``` -$ brev start https://github.com/brevdev/react-starter-app -``` - -which has an output similar too: - -``` -Workspace is starting. This can take up to 2 minutes the first time. - -name react-starter-app -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⣾ workspace is deploying -Your workspace is ready! - -Connect to the workspace: - brev open react-starter-app # brev open -> open workspace in preferred editor - brev shell react-starter-app # brev shell -> ssh into workspace (shortcut) - ssh react-starter-app-8v8p # ssh -> ssh directly to workspace - -``` - -### Join a workspace in your orginization - -view your orgs workspaces with `brev ls --all`. Workspaces in your org that you -have not joined appear at the bottom of the output. - -``` -$ brev ls --all -``` - -which has an output similar too: - -``` -You have 1 workspace in Org brev.dev - NAME STATUS URL ID - brev-cli RUNNING brev-cli-p09m-brevdev.wgt-us-west-2-test.brev.dev x1yxqp09m - -Connect to running workspace: - brev open brev-cli # brev open -> open workspace in preferred editor - brev shell brev-cli # brev shell -> ssh into workspace (shortcut) - ssh brev-cli-p09m # ssh -> ssh directly to workspace - -7 other projects in Org brev.dev - NAME MEMBERS - new-docs 1 - brev-landing-page 2 - todo-app 1 - vagrant-guide 1 - mern-template 1 - solidity-nextjs-starter 1 - akka-http-quickstart-scala 1 - -``` - -join the project new-docs - -``` -$ brev start new-docs -``` - -which has an output similar too: - -``` -Name flag omitted, using auto generated name: new-docs -Workspace is starting. This can take up to 2 minutes the first time. - -name new-docs -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⣟ workspace is deploying Connect to the workspace: - brev open new-docs # brev open -> open workspace in preferred editor - brev shell new-docs # brev shell -> ssh into workspace (shortcut) - ssh new-docs-pek9 # ssh -> ssh directly to workspace -``` - -### Start a stopped workspace - -If you have already joined a workspace and have stopped it with `brev stop`, -you can start it again with `brev start` - -view your current workspaces with `brev ls` - -``` -$ brev ls -``` - -which has an output similar too: - -``` -You have 1 workspace in Org brev.dev - NAME STATUS URL ID - linear-client STOPPED linear-client-yw1a-brevdev.wgt-us-west-2-test.brev.dev gov5jyw1a - -Connect to running workspace: - brev open linear-client # brev open -> open workspace in preferred editor - brev shell linear-client # brev shell -> ssh into workspace (shortcut) - ssh linear-client-yw1a # ssh -> ssh directly to workspace - -``` - -join the workspace - -``` -$ brev start linear-client -``` - -which has an output similar too: - -``` -Workspace linear-client is starting. -Note: this can take about a minute. Run 'brev ls' to check status - -You can safely ctrl+c to exit -``` diff --git a/pkg/cmd/envvars/envvars.go b/pkg/cmd/envvars/envvars.go deleted file mode 100644 index 8935de3bc..000000000 --- a/pkg/cmd/envvars/envvars.go +++ /dev/null @@ -1,33 +0,0 @@ -package envvars - -import ( - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" -) - -type EnvVarsStore interface{} - -func NewCmdEnvVars(_ *terminal.Terminal, evStore EnvVarsStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "env-vars", - DisableFlagsInUseLine: true, - Short: "configure env vars in supported shells", - Long: "Import your IDE config", - Example: "", - RunE: func(cmd *cobra.Command, args []string) error { - err := RunEnvVars(evStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - - return cmd -} - -func RunEnvVars(_ EnvVarsStore) error { - return nil -} diff --git a/pkg/cmd/envvars/envvars_test.go b/pkg/cmd/envvars/envvars_test.go deleted file mode 100644 index 7cbaf8e6b..000000000 --- a/pkg/cmd/envvars/envvars_test.go +++ /dev/null @@ -1 +0,0 @@ -package envvars diff --git a/pkg/cmd/fu/fu.go b/pkg/cmd/fu/fu.go deleted file mode 100644 index 74091c328..000000000 --- a/pkg/cmd/fu/fu.go +++ /dev/null @@ -1,107 +0,0 @@ -package fu - -import ( - "fmt" - "time" - - "github.com/brevdev/brev-cli/pkg/cmd/completions" - "github.com/brevdev/brev-cli/pkg/entity" - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/hashicorp/go-multierror" - "github.com/spf13/cobra" - stripmd "github.com/writeas/go-strip-markdown" -) - -var ( - fuLong string - fuExample = "brev fu " -) - -type FuStore interface { - completions.CompletionStore - DeleteWorkspace(workspaceID string) (*entity.Workspace, error) - GetWorkspaces(organizationID string, options *store.GetWorkspacesOptions) ([]entity.Workspace, error) - BanUser(userID string) error - GetWorkspaceByNameOrID(orgID string, nameOrID string) ([]entity.Workspace, error) - GetAllOrgsAsAdmin(userID string) ([]entity.Organization, error) -} - -func NewCmdFu(t *terminal.Terminal, loginFuStore FuStore, noLoginFuStore FuStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "fu", - DisableFlagsInUseLine: true, - Short: "Fetch all workspaces for a user and delete them", - Long: stripmd.Strip(fuLong), - Example: fuExample, - ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(noLoginFuStore, t), - RunE: func(cmd *cobra.Command, args []string) error { - var allError error - for _, userID := range args { - err := fuUser(userID, t, loginFuStore) - if err != nil { - allError = multierror.Append(allError, err) - } - } - if allError != nil { - return breverrors.WrapAndTrace(allError) - } - return nil - }, - } - - return cmd -} - -func fuUser(userID string, t *terminal.Terminal, fuStore FuStore) error { - orgs, err := fuStore.GetAllOrgsAsAdmin(userID) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - var allWorkspaces []entity.Workspace - for _, org := range orgs { - workspaces, errr := fuStore.GetWorkspaces(org.ID, nil) - if errr != nil { - return breverrors.WrapAndTrace(errr) - } - allWorkspaces = append(allWorkspaces, workspaces...) - } - - s := t.NewSpinner() - s.Suffix = " Fetching workspaces for user " + userID - s.Start() - time.Sleep(5 * time.Second) - s.Stop() - - confirm := terminal.PromptGetInput(terminal.PromptContent{ - Label: fmt.Sprintf("Are you sure you want to delete all %d workspaces for user %s? (y/n)", len(allWorkspaces), userID), - ErrorMsg: "You must confirm to proceed.", - AllowEmpty: false, - }) - if confirm != "y" { - return nil - } - - for _, workspace := range allWorkspaces { - _, err2 := fuStore.DeleteWorkspace(workspace.ID) - if err2 != nil { - t.Vprintf("%s", t.Red("Failed to delete workspace with ID: %s\n", workspace.ID)) - t.Vprintf("%s", t.Red("Error: %s\n", err.Error())) - continue - } - t.Vprintf("✅ Deleted workspace %s\n", workspace.Name) - } - - err = fuStore.BanUser(userID) - if err != nil { - t.Vprintf("%s", t.Red("Failed to ban user with ID: %s\n", userID)) - t.Vprintf("%s", t.Red("Error: %s\n", err.Error())) - } - t.Vprint("\n") - t.Vprintf("🖕 Banned user %s\n", userID) - - return nil -} diff --git a/pkg/cmd/fu/fu_test.go b/pkg/cmd/fu/fu_test.go deleted file mode 100644 index 5818a26b1..000000000 --- a/pkg/cmd/fu/fu_test.go +++ /dev/null @@ -1 +0,0 @@ -package fu diff --git a/pkg/cmd/importideconfig/importideconfig.go b/pkg/cmd/importideconfig/importideconfig.go deleted file mode 100644 index d93e727c6..000000000 --- a/pkg/cmd/importideconfig/importideconfig.go +++ /dev/null @@ -1,220 +0,0 @@ -package importideconfig - -import ( - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path" - "strings" - - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/hashicorp/go-multierror" - "github.com/tidwall/gjson" - "golang.org/x/text/encoding/charmap" - - breverrors "github.com/brevdev/brev-cli/pkg/errors" - - "github.com/spf13/cobra" -) - -// startLong = "[internal] test" -var startExample = "[internal] test" - -type ImportIDEConfigStore interface { - GetCurrentUser() (*entity.User, error) - UpdateUser(userID string, updatedUser *entity.UpdateUser) (*entity.User, error) - GetWindowsDir() (string, error) -} - -func NewCmdImportIDEConfig(t *terminal.Terminal, s ImportIDEConfigStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "import-ide-config", - DisableFlagsInUseLine: true, - Short: "Import your IDE config", - Long: "Import your IDE config like vscode extensions", - Example: startExample, - // Args: cmderrors.TransformToValidationError(cobra.MinimumNArgs(1)), - RunE: func(cmd *cobra.Command, args []string) error { - return breverrors.WrapAndTrace(RunImportIDEConfig(t, s)) - }, - } - - return cmd -} - -type ImportIDEConfigError struct { - Err error -} - -func (e *ImportIDEConfigError) Error() string { - return e.Err.Error() -} - -func importIDEConfigError(err error) error { - return &ImportIDEConfigError{Err: err} -} - -func RunImportIDEConfig(_ *terminal.Terminal, store ImportIDEConfigStore) error { - fmt.Println("updating vscode extensions...") - homedir, err := os.UserHomeDir() - if err != nil { - return breverrors.WrapAndTrace(importIDEConfigError(err)) - } - - windowsUserDir, _ := store.GetWindowsDir() - // if err != nil { - - // // todo multierror - // } - - var extensions []entity.VscodeExtensionMetadata - me := multierror.Append(nil) - for _, dir := range []string{homedir, windowsUserDir} { - if dir == "" { - continue - } - exts, err2 := getExtensions(dir) - if err2 != nil { - me = multierror.Append(me, err2) - } - extensions = append(extensions, exts...) - } - if me.ErrorOrNil() != nil && len(extensions) == 0 { - return breverrors.WrapAndTrace(importIDEConfigError(errors.New("no vscode extensions found"))) - } - - // todo print me (multierror) if not nil - user, err := store.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(importIDEConfigError(err)) - } - - _, err = store.UpdateUser(user.ID, &entity.UpdateUser{ - IdeConfig: entity.IDEConfig{ - VSCode: entity.VSCodeConfig{ - Extensions: extensions, - }, - }, - }) - if err != nil { - return breverrors.WrapAndTrace(importIDEConfigError(err)) - } - - return nil -} - -// Create a VSCodeMetadataObject from package.json file -func createVSCodeMetadataObject(homedir string, path string) (*entity.VscodeExtensionMetadata, error) { - segments := strings.Split(path, "/") - if !strings.Contains(segments[0], ".vscode") && - segments[1] != "extensions" && segments[3] != "package.json" { - return nil, errors.New("extension could not be imported") // TODO: return this as a metric!!! - } - contents, err := catFile(homedir + "/" + path) - if err != nil { - return nil, err - } else { - repoBlock := gjson.Get(contents, "repository").String() - repoURL := gjson.Get(repoBlock, "url").String() - return &entity.VscodeExtensionMetadata{ - Name: gjson.Get(contents, "name").String(), - DisplayName: gjson.Get(contents, "displayName").String(), - Version: gjson.Get(contents, "version").String(), - Publisher: gjson.Get(contents, "publisher").String(), - Description: gjson.Get(contents, "description").String(), - Repository: repoURL, - }, nil - } -} - -func catFile(filePath string) (string, error) { - gocmd := exec.Command("cat", filePath) // #nosec G204 - in, err := gocmd.Output() - if err != nil { - return "", breverrors.Wrap(err, "error reading file "+filePath) - } else { - d := charmap.CodePage850.NewDecoder() - out, err := d.Bytes(in) - if err != nil { - return "", breverrors.Wrap(err, "error reading file "+filePath) - } - return string(out), nil - } -} - -func appendPath(a string, b string) string { - if a == "." { - return b - } - return path.Join(a, b) -} - -func getExtensions(homedir string) ([]entity.VscodeExtensionMetadata, error) { - var extensions []entity.VscodeExtensionMetadata - - // intentionally reading from .vscode and not .vscode_extensions because if they want the extension, it should be installed locally - paths, err := recursivelyFindFile([]string{"package.json"}, homedir+"/.vscode/extensions") - if err != nil { - if strings.Contains(err.Error(), "no such file or directory") { - var err1 error - paths, err1 = recursivelyFindFile([]string{"package.json"}, homedir+"/.vscode-server/extensions") - if err1 != nil { - return nil, multierror.Append(err, err1) - } - } else { - return nil, breverrors.WrapAndTrace(err) - } - } - for _, v := range paths { - pathWithoutHome := strings.Split(v, homedir+"/")[1] - - // of the format - // .vscode / extensions / extension_name / package.json - // 1 2 3 4s - if len(strings.Split(pathWithoutHome, "/")) == 4 { - obj, err0 := createVSCodeMetadataObject(homedir, pathWithoutHome) - if err0 != nil { - return nil, err0 - } - extensions = append(extensions, *obj) - } - } - return extensions, nil -} - -// Returns list of paths to file -func recursivelyFindFile(filenames []string, path string) ([]string, error) { - var paths []string - - files, err := ioutil.ReadDir(path) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - - for _, f := range files { - dir, err := os.Stat(appendPath(path, f.Name())) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } else { - for _, filename := range filenames { - if filename == f.Name() { - paths = append(paths, appendPath(path, f.Name())) - } - } - - if dir.IsDir() { - res, err := recursivelyFindFile(filenames, appendPath(path, f.Name())) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - paths = append(paths, res...) - } - } - } - - return paths, nil -} diff --git a/pkg/cmd/importideconfig/importideconfig_test.go b/pkg/cmd/importideconfig/importideconfig_test.go deleted file mode 100644 index f78f3fa85..000000000 --- a/pkg/cmd/importideconfig/importideconfig_test.go +++ /dev/null @@ -1 +0,0 @@ -package importideconfig diff --git a/pkg/cmd/login/login.go b/pkg/cmd/login/login.go index 59707659c..1256a9104 100644 --- a/pkg/cmd/login/login.go +++ b/pkg/cmd/login/login.go @@ -13,7 +13,6 @@ import ( "github.com/brevdev/brev-cli/pkg/cmd/cmderrors" "github.com/brevdev/brev-cli/pkg/cmd/hello" - "github.com/brevdev/brev-cli/pkg/cmd/importideconfig" "github.com/brevdev/brev-cli/pkg/cmd/register" "github.com/brevdev/brev-cli/pkg/entity" breverrors "github.com/brevdev/brev-cli/pkg/errors" @@ -43,7 +42,6 @@ type LoginStore interface { GetWorkspaces(organizationID string, options *store.GetWorkspacesOptions) ([]entity.Workspace, error) UpdateUser(userID string, updatedUser *entity.UpdateUser) (*entity.User, error) hello.HelloStore - importideconfig.ImportIDEConfigStore UserHomeDir() (string, error) } @@ -84,11 +82,6 @@ func NewCmdLogin(t *terminal.Terminal, loginStore LoginStore, loginAuth Auth) *c } err := opts.RunLogin(t, loginToken, apiKey, apiKeyOrgID, skipBrowser, emailFlag, authProviderFlag) if err != nil { - // if err is ImportIDEConfigError, log err with sentry but continue - if _, ok := err.(*importideconfig.ImportIDEConfigError); !ok { - return err - } - // todo alert sentry err2 := RunTasksForUser(t) if err2 != nil { err = multierror.Append(err, err2) @@ -111,9 +104,8 @@ func NewCmdLogin(t *terminal.Terminal, loginStore LoginStore, loginAuth Auth) *c cmd.Flags().StringVarP(&loginToken, "token", "", "", "token provided to auto login") analytics.MarkFlagSensitive(cmd.Flags(), "token") cmd.Flags().StringVar(&apiKey, "api-key", "", "api key to authenticate CLI requests") - cmd.Flags().StringVar(&apiKeyOrgID, "org-id", "", "deprecated") - _ = cmd.Flags().MarkHidden("api-key") analytics.MarkFlagSensitive(cmd.Flags(), "api-key") + cmd.Flags().StringVar(&apiKeyOrgID, "org-id", "", "deprecated") _ = cmd.Flags().MarkDeprecated("org-id", "the org is now resolved automatically from the API key") cmd.Flags().BoolVar(&skipBrowser, "skip-browser", false, "print url instead of auto opening browser") cmd.Flags().StringVar(&emailFlag, "email", "", "email to use for authentication") diff --git a/pkg/cmd/login/login_test.go b/pkg/cmd/login/login_test.go index 8afd7127c..31546e798 100644 --- a/pkg/cmd/login/login_test.go +++ b/pkg/cmd/login/login_test.go @@ -227,20 +227,6 @@ func TestNewCmdLogin_OrgIDFlagDeprecationWarning(t *testing.T) { assert.Contains(t, out.String(), "resolved automatically from the API key") } -func TestNewCmdLogin_HidesAPIKeyFlagsFromHelp(t *testing.T) { - cmd := NewCmdLogin(terminal.New(), &mockLoginStore{listOrgs: []entity.Organization{{ID: "org-test", Name: "TestOrg"}}}, &mockLoginAuth{}) - var out bytes.Buffer - cmd.SetOut(&out) - cmd.SetErr(&bytes.Buffer{}) - cmd.SetArgs([]string{"--help"}) - - err := cmd.Execute() - - require.NoError(t, err) - assert.NotContains(t, out.String(), "--api-key") - assert.NotContains(t, out.String(), "--org-id") -} - func TestRunLoginWithAPIKey_AutoResolvesOrgWhenOrgIDOmitted(t *testing.T) { auth := &mockLoginAuth{} loginStore := &mockLoginStore{listOrgs: []entity.Organization{{ID: "org-123", Name: "TestOrg"}}} diff --git a/pkg/cmd/ollama/ollama.go b/pkg/cmd/ollama/ollama.go deleted file mode 100644 index c65fd7e36..000000000 --- a/pkg/cmd/ollama/ollama.go +++ /dev/null @@ -1,344 +0,0 @@ -// Package ollama is for starting AI/ML model workspaces -package ollama - -import ( - _ "embed" - "fmt" - "os" - "os/exec" - "strings" - "time" - - "github.com/google/uuid" - - "github.com/brevdev/brev-cli/pkg/cmd/refresh" - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/collections" - "github.com/brevdev/brev-cli/pkg/config" - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/instancetypes" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" - - "github.com/brevdev/brev-cli/pkg/cmd/hello" - breverrors "github.com/brevdev/brev-cli/pkg/errors" -) - -var ( - ollamaLong = "Start an Ollama server with specified model types" - ollamaExample = ` - brev ollama --model llama3 - ` -) - -//go:embed ollamaverb.yaml -var verbYaml string - -type OllamaStore interface { - refresh.RefreshStore - util.GetWorkspaceByNameOrIDErrStore - GetActiveOrganizationOrDefault() (*entity.Organization, error) - GetCurrentUser() (*entity.User, error) - CreateWorkspace(organizationID string, options *store.CreateWorkspacesOptions) (*entity.Workspace, error) - GetWorkspace(workspaceID string) (*entity.Workspace, error) - BuildVerbContainer(workspaceID string, verbYaml string) (*store.BuildVerbRes, error) - ModifyPublicity(workspace *entity.Workspace, applicationName string, publicity bool) (*entity.Tunnel, error) -} - -func validateModelType(input string) (bool, error) { - var model string - var tag string - - split := strings.Split(input, ":") - switch len(split) { - case 2: - model = split[0] - tag = split[1] - case 1: - model = input - tag = "latest" - default: - return false, fmt.Errorf("invalid model type: %s", input) - } - valid, err := store.ValidateOllamaModel(model, tag) - if err != nil { - return false, fmt.Errorf("error validating model: %s", err) - } - return valid, nil -} - -func NewCmdOllama(t *terminal.Terminal, ollamaStore OllamaStore) *cobra.Command { - var model string - var gpu string - - cmd := &cobra.Command{ - Use: "ollama", - DisableFlagsInUseLine: true, - Short: "Start an Ollama model server", - Long: ollamaLong, - Example: ollamaExample, - Annotations: map[string]string{ - "hidden": "", - }, - RunE: func(cmd *cobra.Command, args []string) error { - if model == "" { - return fmt.Errorf("model type must be specified") - } - - isValid, valErr := validateModelType(model) - if valErr != nil { - return valErr - } - if !isValid { - return fmt.Errorf("invalid model type: %s", model) - } - if gpu != "" { - isValid := instancetypes.ValidateInstanceType(gpu) - if !isValid { - err := fmt.Errorf("invalid GPU instance type: %s, see https://brev.dev/docs/reference/gpu for a list of valid GPU instance types", gpu) - return breverrors.WrapAndTrace(err) - } - } - - // Start the network call in a goroutine - res := collections.Async(func() (any, error) { - err := runOllamaWorkspace(t, RunOptions{ - Model: model, - GPUType: gpu, - }, ollamaStore) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - return nil, nil - }) - - // Type out the creating workspace message - hello.TypeItToMeUnskippable27("🤙🦙🤙🦙🤙🦙🤙") - t.Vprint(t.Green("\n\n\n")) - - _, err := res.Await() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - return nil - }, - } - cmd.Flags().StringVarP(&model, "model", "m", "", "AI/ML model type (e.g., llama2, llama3, mistral7b)") - cmd.Flags().StringVarP(&gpu, "gpu", "g", "g5.xlarge", "GPU instance type. See https://brev.dev/docs/reference/gpu for details") - return cmd -} - -type RunOptions struct { - Model string - GPUType string -} - -func runOllamaWorkspace(t *terminal.Terminal, opts RunOptions, ollamaStore OllamaStore) error { //nolint:funlen, gocyclo // todo - _, err := ollamaStore.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - org, err := ollamaStore.GetActiveOrganizationOrDefault() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - instanceType := opts.GPUType - clusterID := config.GlobalConfig.GetDefaultClusterID() - uuid := uuid.New().String() - instanceName := fmt.Sprintf("ollama-%s", uuid) - cwOptions := store.NewCreateWorkspacesOptions(clusterID, instanceName).WithInstanceType(instanceType) - - hello.TypeItToMeUnskippable27(fmt.Sprintf("Creating Ollama server %s with model %s in org %s\n", t.Green(cwOptions.Name), t.Green(opts.Model), t.Green(org.ID))) - - s := t.NewSpinner() - - createWorkspaceRes := collections.Async(func() (*entity.Workspace, error) { - w, errr := ollamaStore.CreateWorkspace(org.ID, cwOptions) - if errr != nil { - return nil, breverrors.WrapAndTrace(errr) - } - return w, nil - }) - - s.Suffix = " Creating your workspace. Hang tight 🤙" - s.Start() - - w, err := createWorkspaceRes.Await() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - var vmStatus bool - vmStatus, err = pollInstanceUntilVMReady(w, time.Second, time.Minute*5, ollamaStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - if !vmStatus { - return breverrors.New("instance did not start") - } - s.Stop() - hello.TypeItToMeUnskippable27("VM is ready!\n") - s.Start() - - // TODO: look into timing of verb call - time.Sleep(time.Second * 5) - - verbBuildRes := collections.Async(func() (*store.BuildVerbRes, error) { - lf, errr := ollamaStore.BuildVerbContainer(w.ID, verbYaml) - if errr != nil { - return nil, breverrors.WrapAndTrace(errr) - } - return lf, nil - }) - - s.Suffix = " Building the Ollama container. Hang tight 🤙" - - _, err = verbBuildRes.Await() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - var vstatus bool - // TODO: 15 min for now because the image is not cached and takes a while to build. Remove this when the image is cached - vstatus, err = pollInstanceUntilVerbContainerReady(w, time.Second, time.Minute*20, ollamaStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - if !vstatus { - return breverrors.New("verb container did not build correctly") - } - s.Stop() - - s = t.NewSpinner() - s.Suffix = "(connectivity) Pulling the %s model, just a bit more! 🏄" - - // shell in and run ollama pull: - if refreshErr := refresh.RunRefresh(ollamaStore); refreshErr != nil { - return breverrors.WrapAndTrace(refreshErr) - } - // Reload workspace to get the latest status - w, err = ollamaStore.GetWorkspace(w.ID) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - link, name, err := getOllamaTunnelLink(w) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - _, err = makeTunnelPublic(w, name, ollamaStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - s.Suffix = "Pulling the %s model, just a bit more! 🏄" - - // shell in and run ollama pull: - if err := runSSHExec(instanceName, []string{"ollama", "pull", opts.Model}, false); err != nil { - return breverrors.WrapAndTrace(err) - } - if err := runSSHExec(instanceName, []string{"ollama", "run", opts.Model, "hello world"}, true); err != nil { - return breverrors.WrapAndTrace(err) - } - s.Stop() - - fmt.Print("\n") - t.Vprint(t.Green("Ollama is ready to go!\n")) - displayOllamaConnectBreadCrumb(t, link, opts.Model) - return nil -} - -func displayOllamaConnectBreadCrumb(t *terminal.Terminal, link string, model string) { - t.Vprintf("%s", t.Green("Query the Ollama API with the following command:\n")) - t.Vprintf("%s", t.Yellow(fmt.Sprintf("curl %s/api/chat -d '{\n \"model\": \"%s\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"why is the sky blue?\"\n }\n ]\n}'\n", link, model))) -} - -func pollInstanceUntilVMReady(workspace *entity.Workspace, interval time.Duration, timeout time.Duration, ollamaStore OllamaStore) (bool, error) { - elapsedTime := time.Duration(0) - - for elapsedTime < timeout { - w, err := ollamaStore.GetWorkspace(workspace.ID) - if err != nil { - return false, breverrors.WrapAndTrace(err) - } else if w.Status == "RUNNING" { - // adding a slight delay to make sure the instance is ready - time.Sleep(time.Minute * 1) - return true, nil - } - time.Sleep(interval) - elapsedTime += interval - } - return false, breverrors.New("Timeout waiting for machine to start") -} - -func pollInstanceUntilVerbContainerReady(workspace *entity.Workspace, interval time.Duration, timeout time.Duration, ollamaStore OllamaStore) (bool, error) { - elapsedTime := time.Duration(0) - - for elapsedTime < timeout { - w, err := ollamaStore.GetWorkspace(workspace.ID) - if err != nil { - return false, breverrors.WrapAndTrace(err) - } else if w.VerbBuildStatus == entity.Completed { - return true, nil - } - time.Sleep(interval) - elapsedTime += interval - } - return false, breverrors.New("Timeout waiting for container to build") -} - -func getOllamaTunnelLink(workspace *entity.Workspace) (string, string, error) { - for _, v := range workspace.Tunnel.Applications { - if v.Port == 11434 { - return v.Hostname, v.Name, nil - } - } - return "", "", breverrors.New("Could not find Ollama tunnel") -} - -// TODO: stub for granular permissioning -// func generateCloudflareAPIKeys(workspace *entity.Workspace, ollamaStore OllamaStore) (bool, error) { -// return false, nil -// } - -func makeTunnelPublic(workspace *entity.Workspace, applicationName string, ollamaStore OllamaStore) (bool, error) { - t, err := ollamaStore.ModifyPublicity(workspace, applicationName, true) - if err != nil { - return false, breverrors.WrapAndTrace(err) - } - for _, v := range t.Applications { - if v.Port == 11434 { - if v.Policy.AllowEveryone { - return true, nil - } - } - } - return false, breverrors.New("Could not find Ollama tunnel") -} - -func runSSHExec(sshAlias string, args []string, fireAndForget bool) error { - sshAgentEval := "eval $(ssh-agent -s)" - cmd := fmt.Sprintf("ssh %s -- %s", sshAlias, strings.Join(args, " ")) - cmd = fmt.Sprintf("%s && %s", sshAgentEval, cmd) - sshCmd := exec.Command("bash", "-c", cmd) //nolint:gosec //cmd is user input - - if fireAndForget { - if err := sshCmd.Start(); err != nil { - return fmt.Errorf("error starting SSH command: %w", err) - } - return nil - } - sshCmd.Stderr = os.Stderr - sshCmd.Stdout = os.Stdout - sshCmd.Stdin = os.Stdin - if err := sshCmd.Run(); err != nil { - return fmt.Errorf("error running SSH command: %w", err) - } - return nil -} diff --git a/pkg/cmd/ollama/ollama_test.go b/pkg/cmd/ollama/ollama_test.go deleted file mode 100644 index f74dfdc09..000000000 --- a/pkg/cmd/ollama/ollama_test.go +++ /dev/null @@ -1 +0,0 @@ -package ollama diff --git a/pkg/cmd/ollama/ollamauiverb.yaml b/pkg/cmd/ollama/ollamauiverb.yaml deleted file mode 100644 index e69de29bb..000000000 diff --git a/pkg/cmd/ollama/ollamaverb.yaml b/pkg/cmd/ollama/ollamaverb.yaml deleted file mode 100644 index e8b9e8967..000000000 --- a/pkg/cmd/ollama/ollamaverb.yaml +++ /dev/null @@ -1,18 +0,0 @@ -build: - python_version: "3.10" - cuda: 12.0.1 - python_packages: - - jupyterlab - run: - - curl -fsSL https://ollama.com/install.sh | sh -user: - shell: zsh - authorized_keys_path: /home/ubuntu/.ssh/authorized_keys -ports: - - "2222:22" - - "8000:8000" -services: - - name: ollama-server - entrypoint: OLLAMA_HOST=0.0.0.0 ollama serve - ports: - - 127.0.0.1:11434:11434 diff --git a/pkg/cmd/paths/paths.go b/pkg/cmd/paths/paths.go deleted file mode 100644 index e1e69f4ca..000000000 --- a/pkg/cmd/paths/paths.go +++ /dev/null @@ -1,19 +0,0 @@ -package paths - -import ( - "fmt" - "io/ioutil" - // breverrors "github.com/brevdev/brev-cli/pkg/errors" -) - -func GetVsCodePaths() []string { - fi, err := ioutil.ReadDir("/home/brev/.vscode-server/bin") - if err != nil { - return []string{} - } - paths := []string{} - for _, f := range fi { - paths = append(paths, fmt.Sprintf("/home/brev/.vscode-server/bin/%s/bin/remote-cli", f.Name())) - } - return paths -} diff --git a/pkg/cmd/paths/paths_test.go b/pkg/cmd/paths/paths_test.go deleted file mode 100644 index 39b5457d9..000000000 --- a/pkg/cmd/paths/paths_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package paths - -import ( - "testing" -) - -func TestGetVsCodePaths(_ *testing.T) { - _ = GetVsCodePaths() -} diff --git a/pkg/cmd/profile/profile.go b/pkg/cmd/profile/profile.go deleted file mode 100644 index 60210853b..000000000 --- a/pkg/cmd/profile/profile.go +++ /dev/null @@ -1,115 +0,0 @@ -package profile - -import ( - "errors" - "fmt" - "strings" - - "github.com/brevdev/brev-cli/pkg/cmd/completions" - "github.com/brevdev/brev-cli/pkg/cmd/start" - "github.com/brevdev/brev-cli/pkg/config" - "github.com/brevdev/brev-cli/pkg/entity" - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/fatih/color" - "github.com/pkg/browser" - - "github.com/spf13/cobra" -) - -var ( - startLong = "Make changes to your profile" - startExample = "brev profile --set-personal-config " -) - -type ProfileStore interface { - completions.CompletionStore - GetCurrentUser() (*entity.User, error) - UpdateUser(userID string, updatedUser *entity.UpdateUser) (*entity.User, error) -} - -func NewCmdProfile(t *terminal.Terminal, loginProfileStore ProfileStore, noLoginProfileStore ProfileStore) *cobra.Command { - var personalSettingsRepo string - - cmd := &cobra.Command{ - Annotations: map[string]string{"configuration": ""}, - Use: "profile", - DisableFlagsInUseLine: true, - Short: "Personal profile commands", - Long: startLong, - Example: startExample, - // Args: cmderrors.TransformToValidationError(cobra.NoArgs), - ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(noLoginProfileStore, t), - RunE: func(cmd *cobra.Command, args []string) error { - err := profile(personalSettingsRepo, t, loginProfileStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - - cmd.Flags().StringVarP(&personalSettingsRepo, "set-personal-config", "p", "", "set your personal config repo") - - return cmd -} - -func goToProfileInConsole() { - url := fmt.Sprintf("%s/profile", config.GlobalConfig.GetConsoleURL()) - caretType := color.New(color.FgGreen, color.Bold).SprintFunc() - enterType := color.New(color.FgGreen, color.Bold).SprintFunc() - urlType := color.New(color.FgWhite, color.Bold).SprintFunc() - // fmt.Println("\n" + url + "\n") - _ = terminal.PromptGetInput(terminal.PromptContent{ - Label: " " + caretType("▸") + " Press " + enterType("Enter") + " to edit your profile in browser", - ErrorMsg: "error", - AllowEmpty: true, - }) - - fmt.Print("\n") - - err := browser.OpenURL(url) - if err != nil { - fmt.Println("Error opening browser. Please copy", urlType(url), "and paste it in your browser.") - } -} - -func profile(personalSettingsRepo string, t *terminal.Terminal, profileStore ProfileStore) error { - user, err := profileStore.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - if len(personalSettingsRepo) == 0 { - goToProfileInConsole() - return nil - } - - isURL := false - if strings.Contains(personalSettingsRepo, "https://") || strings.Contains(personalSettingsRepo, "git@") { - isURL = true - } - - if !isURL { - err = errors.New("please use a valid git url") - return breverrors.WrapAndTrace(err) - } - - temp := start.MakeNewWorkspaceFromURL(personalSettingsRepo) - t.Vprint(temp.GitRepo) - - // TODO: make sure the git repo format works!!!!!!! - - _, err = profileStore.UpdateUser(user.ID, &entity.UpdateUser{ - Username: user.Username, - Name: user.Name, - Email: user.Email, - BaseWorkspaceRepo: temp.GitRepo, - }) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - t.Vprintf("Your personal config has been updated. All new instances will run this script.\n") - return nil -} diff --git a/pkg/cmd/profile/profile_test.go b/pkg/cmd/profile/profile_test.go deleted file mode 100644 index 73330f154..000000000 --- a/pkg/cmd/profile/profile_test.go +++ /dev/null @@ -1 +0,0 @@ -package profile diff --git a/pkg/cmd/proxy/proxy.go b/pkg/cmd/proxy/proxy.go deleted file mode 100644 index 784a5bde5..000000000 --- a/pkg/cmd/proxy/proxy.go +++ /dev/null @@ -1,161 +0,0 @@ -package proxy - -import ( - "fmt" - "strings" - - "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/featureflag" - "github.com/brevdev/brev-cli/pkg/huproxyclient" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/hashicorp/go-version" - "github.com/spf13/cobra" -) - -const ( - allowedWorkspaceImage = "brevdev/ubuntu-proxy" - allowedWorkspaceImageTag = ">= 0.3" - allowedWorkspaceInfraVersion = ">= 1.7" -) - -type ProxyStore interface { - huproxyclient.HubProxyStore - GetWorkspace(workspaceID string) (*entity.Workspace, error) - WritePrivateKey(pem string) error - GetCurrentUserKeys() (*entity.UserKeys, error) -} - -func NewCmdProxy(t *terminal.Terminal, store ProxyStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "proxy", - DisableFlagsInUseLine: true, - Short: "http upgrade proxy", - Long: "http upgrade proxy for ssh ProxyCommand directive to use", - Args: cmderrors.TransformToValidationError(cobra.ExactArgs(1)), - RunE: func(cmd *cobra.Command, args []string) error { - err := Proxy(t, store, args[0]) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - - return cmd -} - -func Proxy(_ *terminal.Terminal, store ProxyStore, workspaceID string) error { - workspace, err := store.GetWorkspace(workspaceID) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - err = CheckWorkspaceCanSSH(workspace) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - err = WriteUserPrivateKey(store) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - url := makeProxyURL(workspace) - err = huproxyclient.Run(url, store) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil -} - -func makeProxyURL(w *entity.Workspace) string { - return fmt.Sprintf("wss://%s/proxy", w.GetSSHURL()) -} - -func CheckWorkspaceCanSSH(workspace *entity.Workspace) error { - if !featureflag.DisableSSHProxyVersionCheck() { - fmt.Println("checking instance version") - err := checkWorkspaceInfraVersionOrErr(workspace) - if err != nil { - return breverrors.WrapAndTrace(err) - } - fmt.Println("checking instance image version") - err = checkWorkspaceImageVersionOrErr(workspace) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } - err := checkWorkspaceStatusOrErr(workspace) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil -} - -func checkWorkspaceStatusOrErr(workspace *entity.Workspace) error { - if workspace.Status != entity.Running { - return breverrors.NewValidationError(fmt.Sprintf("instance is not in RUNNING state, status: %s", workspace.Status)) - } - return nil -} - -func checkWorkspaceImageVersionOrErr(workspace *entity.Workspace) error { - imageSplit := strings.Split(workspace.WorkspaceTemplate.Image, ":") - if len(imageSplit) != 2 { - return breverrors.NewValidationError("problem parsing workspace image tag") - } - wiv, err := version.NewVersion(imageSplit[1]) - if err != nil { - if !strings.Contains(err.Error(), "Malformed") { - return breverrors.WrapAndTrace(err) - } else { - _ = 0 - // skip checking constraints since probably a test image - } - } else { - imageContraints, err := version.NewConstraint(allowedWorkspaceImageTag) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - if !imageContraints.Check(wiv) && !strings.HasSuffix(imageSplit[0], allowedWorkspaceImage) { - return breverrors.NewValidationError(fmt.Sprintf("instance image version %s is not supported with this cli version\n upgrade your instance or downgrade your cli", workspace.WorkspaceTemplate.Image)) - } - } - return nil -} - -func checkWorkspaceInfraVersionOrErr(workspace *entity.Workspace) error { - fmt.Printf("instance version: %s\n", workspace.Version) - if workspace.Version != "" { - wv, err := version.NewVersion(workspace.Version) - if err != nil { - return breverrors.WrapAndTrace(err) - } - workspaceInfraConstraints, err := version.NewConstraint(allowedWorkspaceInfraVersion) - if err != nil { - return breverrors.WrapAndTrace(err) - } - if !workspaceInfraConstraints.Check(wv) { - return breverrors.NewValidationError(fmt.Sprintf("instance of version %s is not supported with this cli version\n upgrade your instance or downgrade your cli. Supported %s", workspace.Version, allowedWorkspaceInfraVersion)) - } - } else { - fmt.Println("instance version blank assuming dev, not checking constraint") - } - return nil -} - -func WriteUserPrivateKey(store ProxyStore) error { - keys, err := store.GetCurrentUserKeys() - if err != nil { - return breverrors.WrapAndTrace(err) - } - err = store.WritePrivateKey(keys.PrivateKey) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil -} diff --git a/pkg/cmd/proxy/proxy_test.go b/pkg/cmd/proxy/proxy_test.go deleted file mode 100644 index d1ebab890..000000000 --- a/pkg/cmd/proxy/proxy_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package proxy - -import ( - "testing" - - "github.com/hashicorp/go-version" - "github.com/stretchr/testify/assert" -) - -func TestVersionParsing(t *testing.T) { - _, err := version.NewVersion("abadfjladsf") - assert.NotNil(t, err) -} diff --git a/pkg/cmd/reset/doc.md b/pkg/cmd/reset/doc.md deleted file mode 100644 index b53040cb6..000000000 --- a/pkg/cmd/reset/doc.md +++ /dev/null @@ -1,27 +0,0 @@ -## SYNOPSIS - -``` - brev reset [ Workspace Name or ID... ] -``` - -## DESCRIPTION - -reset a workspace will stop a workspace, then start a workspace, perserving -files in `/home/brev/workspace/`. This will have the effect of rerunning your -setupscript in a newley created workspace with no changes made to it, and -replacing your workspace with that. - -## EXAMPLE - -reset a workspace with the name `payments-frontend` - -``` -$ brev reset payments-frontend -Workspace payments-frontend is resetting. -Note: this can take a few seconds. Run 'brev ls' to check status - -``` - -## SEE ALSO - - TODO diff --git a/pkg/cmd/reset/reset.go b/pkg/cmd/reset/reset.go deleted file mode 100644 index f2626ce3d..000000000 --- a/pkg/cmd/reset/reset.go +++ /dev/null @@ -1,65 +0,0 @@ -package reset - -import ( - _ "embed" - - "github.com/brevdev/brev-cli/pkg/cmd/completions" - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/terminal" - - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/spf13/cobra" - stripmd "github.com/writeas/go-strip-markdown" -) - -var ( - //go:embed doc.md - long string - startExample = `brev reset ...` -) - -type ResetStore interface { - completions.CompletionStore - util.GetWorkspaceByNameOrIDErrStore - ResetWorkspace(workspaceID string) (*entity.Workspace, error) -} - -func NewCmdReset(t *terminal.Terminal, loginResetStore ResetStore, noLoginResetStore ResetStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"provider-dependent": ""}, - Use: "reset", - DisableFlagsInUseLine: true, - Short: "Reset an instance to recover from errors", - Long: stripmd.Strip(long), - Example: startExample, - ValidArgsFunction: completions.GetAllWorkspaceNameCompletionHandler(noLoginResetStore, t), - RunE: func(cmd *cobra.Command, args []string) error { - for _, arg := range args { - err := resetWorkspace(arg, t, loginResetStore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } - return nil - }, - } - return cmd -} - -func resetWorkspace(workspaceName string, t *terminal.Terminal, resetStore ResetStore) error { - workspace, err := util.GetUserWorkspaceByNameOrIDErr(resetStore, workspaceName) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - startedWorkspace, err := resetStore.ResetWorkspace(workspace.ID) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - t.Vprintf("%s", t.Yellow("Instance %s is resetting.\n", startedWorkspace.Name)) - t.Vprintf("Note: this can take a few seconds. Run 'brev ls' to check status\n") - - return nil -} diff --git a/pkg/cmd/reset/reset_test.go b/pkg/cmd/reset/reset_test.go deleted file mode 100644 index 8b777f245..000000000 --- a/pkg/cmd/reset/reset_test.go +++ /dev/null @@ -1 +0,0 @@ -package reset diff --git a/pkg/cmd/runtasks/doc.md b/pkg/cmd/runtasks/doc.md deleted file mode 100644 index e45f64d8c..000000000 --- a/pkg/cmd/runtasks/doc.md +++ /dev/null @@ -1,2 +0,0 @@ -##### run-tasks command deprecated - `brev run-tasks` has been deprecated diff --git a/pkg/cmd/runtasks/runtasks.go b/pkg/cmd/runtasks/runtasks.go deleted file mode 100644 index db6f1b7ef..000000000 --- a/pkg/cmd/runtasks/runtasks.go +++ /dev/null @@ -1,88 +0,0 @@ -package runtasks - -import ( - _ "embed" - - "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/ssh" - "github.com/brevdev/brev-cli/pkg/tasks" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" - stripmd "github.com/writeas/go-strip-markdown" -) - -//go:embed doc.md -var long string - -func NewCmdRunTasks(t *terminal.Terminal, store RunTasksStore) *cobra.Command { - var detached bool - // would be nice to have a way to pass in a list of tasks to run instead of the default - var runRemoteCMD bool - - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "run-tasks", - DisableFlagsInUseLine: true, - Short: "Run background tasks for Brev", - Long: stripmd.Strip(long), - Example: "brev run-tasks -d", - Args: cmderrors.TransformToValidationError(cobra.ExactArgs(0)), - RunE: func(cmd *cobra.Command, args []string) error { - err := RunTasks(t, store, detached) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - - cmd.Flags().BoolVarP(&detached, "detached", "d", false, "run the command in the background instead of blocking the shell") - cmd.Flags().BoolVarP(&runRemoteCMD, "run-remote-cmd", "r", true, "run the command on the instance to cd into ws default dir") - return cmd -} - -type RunTasksStore interface { - ssh.ConfigUpdaterStore - ssh.SSHConfigurerV2Store - tasks.RunTaskAsDaemonStore - GetCurrentUser() (*entity.User, error) - GetCurrentUserKeys() (*entity.UserKeys, error) -} - -func RunTasks(_ *terminal.Terminal, store RunTasksStore, detached bool) error { - ts, err := getDefaultTasks(store) - if err != nil { - return breverrors.WrapAndTrace(err) - } - if detached { - err := tasks.RunTaskAsDaemon(ts, store) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } else { - err := tasks.RunTasks(ts) - if err != nil { - return breverrors.WrapAndTrace(err) - } - } - return nil -} - -func getDefaultTasks(store RunTasksStore) ([]tasks.Task, error) { - configs, err := ssh.GetSSHConfigs(store) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - - // get private key and set here - keys, err := store.GetCurrentUserKeys() - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - - cu := ssh.NewConfigUpdater(store, configs, keys.PrivateKey) - - return []tasks.Task{cu}, nil -} diff --git a/pkg/cmd/runtasks/runtasks_test.go b/pkg/cmd/runtasks/runtasks_test.go deleted file mode 100644 index 494a3765b..000000000 --- a/pkg/cmd/runtasks/runtasks_test.go +++ /dev/null @@ -1 +0,0 @@ -package runtasks diff --git a/pkg/cmd/scale/scale.go b/pkg/cmd/scale/scale.go deleted file mode 100644 index 70e9d03c0..000000000 --- a/pkg/cmd/scale/scale.go +++ /dev/null @@ -1,100 +0,0 @@ -package scale - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/entity" - breverrors "github.com/brevdev/brev-cli/pkg/errors" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" -) - -var ( - long = "Scale your Brev instance to get a more powerful machine or save costs" - example = ` - brev scale MyInstance --gpu p3.2xlarge - brev scale MyInstance --cpu 2x8 - ` - // TODO: we might wanna use the below for validation ¯\_(ツ)_/¯ - // instanceTypes = []string{"p4d.24xlarge", "p3.2xlarge", "p3.8xlarge", "p3.16xlarge", "p3dn.24xlarge", "p2.xlarge", "p2.8xlarge", "p2.16xlarge", "g5.xlarge", "g5.2xlarge", "g5.4xlarge", "g5.8xlarge", "g5.16xlarge", "g5.12xlarge", "g5.24xlarge", "g5.48xlarge", "g5g.xlarge", "g5g.2xlarge", "g5g.4xlarge", "g5g.8xlarge", "g5g.16xlarge", "g5g.metal", "g4dn.xlarge", "g4dn.2xlarge", "g4dn.4xlarge", "g4dn.8xlarge", "g4dn.16xlarge", "g4dn.12xlarge", "g4dn.metal", "g4ad.xlarge", "g4ad.2xlarge", "g4ad.4xlarge", "g4ad.8xlarge", "g4ad.16xlarge", "g3s.xlarge", "g3.4xlarge", "g3.8xlarge", "g3.16xlarge"} -) - -type ScaleStore interface { - util.GetWorkspaceByNameOrIDErrStore - ModifyWorkspace(organizationID string, options *store.ModifyWorkspaceRequest) (*entity.Workspace, error) -} - -func NewCmdScale(t *terminal.Terminal, sstore ScaleStore) *cobra.Command { - // var instanceType string - var gpu string - var cpu string - - cmd := &cobra.Command{ - Use: "scale", - DisableFlagsInUseLine: true, - Short: "Scale your Brev instance", - Long: long, - Example: example, - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) == 0 { - return breverrors.NewValidationError("You must provide an instance with flage -i") - } - - err := Runscale(t, args, gpu, cpu, sstore) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil - }, - } - - cmd.Flags().StringVarP(&gpu, "gpu", "g", "", "GPU instance type. See https://docs.brev.dev/docs/reference/gpu/#gpu-instance-types for details") - cmd.Flags().StringVarP(&cpu, "cpu", "c", "", "CPU instance type. See https://docs.brev.dev/docs/reference/gpu/#cpu-instance-types for details") - // cmd.Flags().StringVarP(&instanceType, "instance", "i", "", "GPU or CPU instance type. See docs.brev.dev/gpu for details") - return cmd -} - -func Runscale(t *terminal.Terminal, args []string, gpu string, cpu string, sstore ScaleStore) error { - workspace, err := util.GetUserWorkspaceByNameOrIDErr(sstore, args[0]) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - var modifyBody store.ModifyWorkspaceRequest - - s := t.NewSpinner() - - if gpu != "" { - modifyBody.InstanceType = gpu - s.Suffix = fmt.Sprintf(" Scaling %s to %s GPU", workspace.Name, gpu) - - } else if cpu != "" { - modifyBody.WorkspaceClassID = cpu - s.Suffix = fmt.Sprintf(" Scaling %s to %s CPU", workspace.Name, cpu) - - } - - s.Start() - ws, err := sstore.ModifyWorkspace(workspace.ID, &modifyBody) - if err != nil { - return breverrors.WrapAndTrace(err) - } - s.Stop() - - // fmt.Printf("name %s\n", result.Name) - // fmt.Printf("template %s %s\n", result.WorkspaceTemplate.ID, result.WorkspaceTemplate.Name) - // fmt.Printf("resource class %s\n", result.WorkspaceClassID) - // fmt.Printf("instance %s\n", result.InstanceType) - - if gpu != "" { - t.Vprintf("\n\nInstance %s scaled to %s 🤙\n", t.Green(ws.Name), t.Green(ws.InstanceType)) - } else if cpu != "" { - t.Vprintf("\n\nInstance %s scaled to %s 🤙\n", t.Green(ws.Name), t.Green(ws.WorkspaceClassID)) - } - t.Vprintf("\n%s", t.Yellow("Your instance might still be rebooting. Check the status with `brev ls`\n")) - - return nil -} diff --git a/pkg/cmd/status/doc.md b/pkg/cmd/status/doc.md deleted file mode 100644 index 0a856447e..000000000 --- a/pkg/cmd/status/doc.md +++ /dev/null @@ -1,265 +0,0 @@ -create start and join a workspace - -## Synopsis - -``` - -brev start { ARG | -e} {-n | --name} {-c | --class} { -s | --setup-script} - {-r | --setup-repo} {-p | --setup-path } { -o | --org} -``` - -## Description - -brev start can do the following: - -- start a stopped workspace -- join a workspace in an organization -- create an empty workspace -- create a workspace from a directory on your computer -- create a workspace from a git url - -## Flags - -### -n --name - -specify the name for your workspace instead of brev-cli generating one for you. - -for example, to override the name of a workspace when creating a workspace from -a git repo you could do it with then `-n` flag. This example creates a repo with -the name `cli` from the git repo `https://github.com/brevdev/brev-cli`. - -``` -$ brev start https://github.com/brevdev/brev-cli -n cli -``` - -## Examples - -### Create an empty workspace - -``` -$ brev start -e -n foo -``` - -which has an output similar too: - -``` -name foo -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -workspace is starting. this can take up to 2 minutes the first time. - -you can safely ctrl+c to exit -⣽ workspace is deploying -your workspace is ready! - -connect to the workspace: - brev open foo # brev open -> open workspace in preferred editor - brev shell foo # brev shell -> ssh into workspace (shortcut) - ssh foo-8j4u # ssh -> ssh directly to workspace - -``` - -or - -``` -$ brev start --empty --name foo -``` - -which has an output similar too: - -``` -name foo -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -workspace is starting. this can take up to 2 minutes the first time. - -you can safely ctrl+c to exit -⣽ workspace is deploying -your workspace is ready! - -connect to the workspace: - brev open foo # brev open -> open workspace in preferred editor - brev shell foo # brev shell -> ssh into workspace (shortcut) - ssh foo-8j4u # ssh -> ssh directly to workspace - -``` - -view your workspace with `brev ls` - -### create a workspace, and do not block shell until workspace is created - -use the `-d` or `--detached` flag to create a workspace and immediately exit -rather than wait for workspace to be successfully created before exiting. - -``` -$ brev start -d -e -n bar -``` - -which has an output similar too: - -``` -name bar -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -Workspace is starting. This can take up to 2 minutes the first time. -``` - -### Create a workspace from a file path - -if in your current directory has a directory in it called `merge-json`, you can -create a workspace using the contents of that directory using -`brev start merge-json` - -``` -$ ls -merge-json -``` - -``` -$ brev start merge-json - -``` - -which has an output similar too: - -``` -Workspace is starting. This can take up to 2 minutes the first time. - -name merge-json -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⡿ workspace is deploying -Your workspace is ready! - -Connect to the workspace: - brev open merge-json # brev open -> open workspace in preferred editor - brev shell merge-json # brev shell -> ssh into workspace (shortcut) - ssh merge-json-wd6q # ssh -> ssh directly to workspace -``` - -### Create a workspace from a git repository - -``` -$ brev start https://github.com/brevdev/react-starter-app -``` - -which has an output similar too: - -``` -Workspace is starting. This can take up to 2 minutes the first time. - -name react-starter-app -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⣾ workspace is deploying -Your workspace is ready! - -Connect to the workspace: - brev open react-starter-app # brev open -> open workspace in preferred editor - brev shell react-starter-app # brev shell -> ssh into workspace (shortcut) - ssh react-starter-app-8v8p # ssh -> ssh directly to workspace - -``` - -### Join a workspace in your orginization - -view your orgs workspaces with `brev ls --all`. Workspaces in your org that you -have not joined appear at the bottom of the output. - -``` -$ brev ls --all -``` - -which has an output similar too: - -``` -You have 1 workspace in Org brev.dev - NAME STATUS URL ID - brev-cli RUNNING brev-cli-p09m-brevdev.wgt-us-west-2-test.brev.dev x1yxqp09m - -Connect to running workspace: - brev open brev-cli # brev open -> open workspace in preferred editor - brev shell brev-cli # brev shell -> ssh into workspace (shortcut) - ssh brev-cli-p09m # ssh -> ssh directly to workspace - -7 other projects in Org brev.dev - NAME MEMBERS - new-docs 1 - brev-landing-page 2 - todo-app 1 - vagrant-guide 1 - mern-template 1 - solidity-nextjs-starter 1 - akka-http-quickstart-scala 1 - -``` - -join the project new-docs - -``` -$ brev start new-docs -``` - -which has an output similar too: - -``` -Name flag omitted, using auto generated name: new-docs -Workspace is starting. This can take up to 2 minutes the first time. - -name new-docs -template 4nbb4lg2s ubuntu -resource class 2x8 -workspace group brev-test-brevtenant-cluster -You can safely ctrl+c to exit -⣟ workspace is deploying Connect to the workspace: - brev open new-docs # brev open -> open workspace in preferred editor - brev shell new-docs # brev shell -> ssh into workspace (shortcut) - ssh new-docs-pek9 # ssh -> ssh directly to workspace -``` - -### Start a stopped workspace - -If you have already joined a workspace and have stopped it with `brev stop`, -you can start it again with `brev start` - -view your current workspaces with `brev ls` - -``` -$ brev ls -``` - -which has an output similar too: - -``` -You have 1 workspace in Org brev.dev - NAME STATUS URL ID - linear-client STOPPED linear-client-yw1a-brevdev.wgt-us-west-2-test.brev.dev gov5jyw1a - -Connect to running workspace: - brev open linear-client # brev open -> open workspace in preferred editor - brev shell linear-client # brev shell -> ssh into workspace (shortcut) - ssh linear-client-yw1a # ssh -> ssh directly to workspace - -``` - -join the workspace - -``` -$ brev start linear-client -``` - -which has an output similar too: - -``` -Workspace linear-client is starting. -Note: this can take about a minute. Run 'brev ls' to check status - -You can safely ctrl+c to exit -``` diff --git a/pkg/cmd/status/status.go b/pkg/cmd/status/status.go deleted file mode 100644 index 80830f543..000000000 --- a/pkg/cmd/status/status.go +++ /dev/null @@ -1,61 +0,0 @@ -package status - -import ( - "github.com/brevdev/brev-cli/pkg/cmd/util" - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/spf13/cobra" -) - -var ( - createLong = "Create a new Brev machine" - createExample = ` - brev create - ` - // instanceTypes = []string{"p4d.24xlarge", "p3.2xlarge", "p3.8xlarge", "p3.16xlarge", "p3dn.24xlarge", "p2.xlarge", "p2.8xlarge", "p2.16xlarge", "g5.xlarge", "g5.2xlarge", "g5.4xlarge", "g5.8xlarge", "g5.16xlarge", "g5.12xlarge", "g5.24xlarge", "g5.48xlarge", "g5g.xlarge", "g5g.2xlarge", "g5g.4xlarge", "g5g.8xlarge", "g5g.16xlarge", "g5g.metal", "g4dn.xlarge", "g4dn.2xlarge", "g4dn.4xlarge", "g4dn.8xlarge", "g4dn.16xlarge", "g4dn.12xlarge", "g4dn.metal", "g4ad.xlarge", "g4ad.2xlarge", "g4ad.4xlarge", "g4ad.8xlarge", "g4ad.16xlarge", "g3s.xlarge", "g3.4xlarge", "g3.8xlarge", "g3.16xlarge"} -) - -type StatusStore interface { - util.GetWorkspaceByNameOrIDErrStore - GetActiveOrganizationOrDefault() (*entity.Organization, error) - GetCurrentUser() (*entity.User, error) - GetWorkspace(workspaceID string) (*entity.Workspace, error) - GetCurrentWorkspaceID() (string, error) - CreateWorkspace(organizationID string, options *store.CreateWorkspacesOptions) (*entity.Workspace, error) -} - -func NewCmdStatus(t *terminal.Terminal, statusStore StatusStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"hidden": ""}, - Use: "status", - DisableFlagsInUseLine: true, - Short: "Show instance status", - Long: createLong, - Example: createExample, - RunE: func(cmd *cobra.Command, args []string) error { - runShowStatus(t, statusStore) - return nil - }, - } - return cmd -} - -func runShowStatus(t *terminal.Terminal, statusStore StatusStore) { - terminal.DisplayBrevLogo(t) - t.Vprintf("\n") - wsID, err := statusStore.GetCurrentWorkspaceID() - if err != nil { - t.Vprintf("\n Error: %s", t.Red(err.Error())) - return - } - ws, err := statusStore.GetWorkspace(wsID) - if err != nil { - t.Vprintf("\n Error: %s", t.Red(err.Error())) - return - } - - t.Vprintf("\nYou're on instance %s", t.Yellow(ws.Name)) - t.Vprintf("\n\tID: %s", t.Yellow(ws.ID)) - t.Vprintf("\n\tMachine: %s", t.Yellow(util.GetInstanceString(*ws))) -} diff --git a/pkg/cmd/status/status_test.go b/pkg/cmd/status/status_test.go deleted file mode 100644 index 6c12ae38b..000000000 --- a/pkg/cmd/status/status_test.go +++ /dev/null @@ -1 +0,0 @@ -package status diff --git a/pkg/cmd/tasks/tasks.go b/pkg/cmd/tasks/tasks.go deleted file mode 100644 index 8ac4d4bc3..000000000 --- a/pkg/cmd/tasks/tasks.go +++ /dev/null @@ -1,124 +0,0 @@ -package tasks - -import ( - "fmt" - - "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/ssh" - "github.com/brevdev/brev-cli/pkg/tasks" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/hashicorp/go-multierror" - "github.com/spf13/afero" - "github.com/spf13/cobra" -) - -type TaskMap map[string]tasks.Task - -var all bool // used for run command - -type TaskStore interface { - GetCurrentUserKeys() (*entity.UserKeys, error) - CopyBin(targetBin string) error - WriteString(path, data string) error - GetOrCreateFile(path string) (afero.File, error) - GetCurrentWorkspaceID() (string, error) - GetWorkspace(workspaceID string) (*entity.Workspace, error) - GetCurrentUser() (*entity.User, error) - ssh.ConfigUpaterFactoryStore -} - -func NewCmdTasks(t *terminal.Terminal, store TaskStore) *cobra.Command { - taskMap := getTaskMap(store) - cmd := &cobra.Command{ - Use: "tasks", - DisableFlagsInUseLine: true, - Short: "run background daemons for brev", - Long: "run background daemons for brev", - Args: cmderrors.TransformToValidationError(cobra.ExactArgs(0)), - RunE: func(cmd *cobra.Command, args []string) error { - return fmt.Errorf("invalid command") - }, - } - - configure := NewCmdConfigure(t, store) - cmd.AddCommand(configure) - run := NewCmdRun(t, store, taskMap) - run.PersistentFlags().BoolVarP(&all, "all", "a", false, "specifies all tasks") - cmd.AddCommand(run) - - return cmd -} - -func NewCmdConfigure(_ *terminal.Terminal, store TaskStore) *cobra.Command { - taskMap := getTaskMap(store) - cmd := &cobra.Command{ - Use: "configure [task to configure]", - Short: "configure system startup daemon for task", - Long: "configure system startup daemon for task", - RunE: func(cmd *cobra.Command, args []string) error { - // todo if --user flag is not provided and if not run as root, raise - // an error - fmt.Println("configuring...") - var allError error - for k, value := range taskMap { - fmt.Printf("configuring %s\n", k) - err := value.Configure() - if err != nil { - fmt.Println(k) - allError = multierror.Append(allError, err) - } - } - fmt.Println("done configuring") - if allError != nil { - return breverrors.WrapAndTrace(allError) - } - return nil - }, - } - return cmd -} - -func NewCmdRun(_ *terminal.Terminal, _ TaskStore, taskMap TaskMap) *cobra.Command { - cmd := &cobra.Command{ - Use: "run [task to configure]", - Short: "run a task", - Long: "run a task", - RunE: func(cmd *cobra.Command, args []string) error { - if all { - var allError error - for _, value := range taskMap { - err := value.Run() - if err != nil { - allError = multierror.Append(allError, err) - } - } - if allError != nil { - return breverrors.WrapAndTrace(allError) - } - } else { - if len(args) == 0 { - return fmt.Errorf("provide a task name or --all") - } - if task, ok := taskMap[args[0]]; ok { - err := task.Run() - if err != nil { - return breverrors.WrapAndTrace(err) - } - } else { - fmt.Println("could not find task") - } - } - return nil - }, - } - return cmd -} - -func getTaskMap(store TaskStore) TaskMap { - taskmap := make(TaskMap) - sshcd := ssh.NewSSHConfigurerTask(store) - taskmap["sshcd"] = sshcd - return taskmap -} diff --git a/pkg/cmd/test/test.go b/pkg/cmd/test/test.go deleted file mode 100644 index b0626886b..000000000 --- a/pkg/cmd/test/test.go +++ /dev/null @@ -1,76 +0,0 @@ -package test - -import ( - "fmt" - - "github.com/brevdev/brev-cli/pkg/autostartconf" - "github.com/brevdev/brev-cli/pkg/cmd/completions" - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/brevdev/brev-cli/pkg/util" - - "github.com/spf13/cobra" -) - -var ( - startLong = "[internal] test" - startExample = "[internal] test" -) - -type TestStore 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) - CopyBin(targetBin string) error - GetSetupScriptContentsByURL(url string) (string, error) - UpdateUser(userID string, updatedUser *entity.UpdateUser) (*entity.User, error) -} - -type ServiceMeshStore interface { - autostartconf.AutoStartStore - GetWorkspace(workspaceID string) (*entity.Workspace, error) -} - -func NewCmdTest(_ *terminal.Terminal, _ TestStore) *cobra.Command { - cmd := &cobra.Command{ - Annotations: map[string]string{"devonly": ""}, - Use: "test", - DisableFlagsInUseLine: true, - Short: "[internal] Test random stuff.", - Long: startLong, - Example: startExample, - // Args: cmderrors.TransformToValidationError(cobra.MinimumNArgs(1)), - RunE: func(cmd *cobra.Command, args []string) error { - // fmt.Printf("NAME ID URL SOMETHING ELSE") - // hello.TypeItToMe("\n\n\n") - // hello.TypeItToMe("👆 this is the name of your environment (which you can use to open the environment)") - // time.Sleep(1 * time.Second) - // fmt.Printf("\332K\r") - // fmt.Println(" ") - // hello.TypeItToMe(" 👆 you can expose your localhost to this public URL") - // time.Sleep(1 * time.Second) - // fmt.Printf("\332K\r") - // fmt.Printf("bye world") - // fmt.Printf("bye world") - - // s := t.Yellow("\n\nCould you please install the following VSCode extension? %s", t.Green("ms-vscode-remote.remote-ssh")) - // s += "\nDo that then run " + t.Yellow("brev hello") + " to resume this walk-through\n" - // // s += "Here's a video of me installing the VS Code extension 👉 " + "" - // hello.TypeItToMe(s) - - res := util.DoesPathExist("/Users/naderkhalil/brev-cli") - // res := util.DoesPathExist("/home/brev/workspace") - fmt.Println(res) - - return nil - }, - } - - return cmd -} diff --git a/pkg/cmd/test/test_test.go b/pkg/cmd/test/test_test.go deleted file mode 100644 index 56e540407..000000000 --- a/pkg/cmd/test/test_test.go +++ /dev/null @@ -1 +0,0 @@ -package test diff --git a/pkg/cmd/updatemodel/updatemodel.go b/pkg/cmd/updatemodel/updatemodel.go deleted file mode 100644 index 7f50424dc..000000000 --- a/pkg/cmd/updatemodel/updatemodel.go +++ /dev/null @@ -1,419 +0,0 @@ -package updatemodel - -import ( - "fmt" - "os" - "path" - "path/filepath" - "strings" - - "github.com/hashicorp/go-multierror" - "github.com/samber/lo" - "github.com/spf13/cobra" - - "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/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/brevdev/parse/pkg/parse" - "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/transport/ssh" -) - -var ( - short = "TODO" - long = "TODO" - example = "TODO" -) - -type updatemodelStore interface { - ModifyWorkspace(workspaceID string, options *store.ModifyWorkspaceRequest) (*entity.Workspace, error) - GetCurrentWorkspaceID() (string, error) - GetWorkspace(workspaceID string) (*entity.Workspace, error) - WriteString(path, data string) error - UserHomeDir() (string, error) - ListDirs(path string) ([]string, error) - FileExists(filepath string) (bool, error) - GetEnvSetupParams(wsid string) (*store.SetupParamsV0, error) - GetCurrentUser() (*entity.User, error) -} - -func NewCmdupdatemodel(t *terminal.Terminal, store updatemodelStore) *cobra.Command { - var configure bool - cmd := &cobra.Command{ - Use: "updatemodel", - DisableFlagsInUseLine: true, - Short: short, - Long: long, - Example: example, - RunE: updateModel{ - t: t, - Store: store, - clone: func(path string, isBare bool, o *git.CloneOptions) (*git.Repository, error) { - workspaceID, err := store.GetCurrentWorkspaceID() - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - params, err := store.GetEnvSetupParams(workspaceID) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - - if params != nil && params.WorkspaceKeyPair != nil { - keys := params.WorkspaceKeyPair - pubkeys, err := ssh.NewPublicKeys("ubuntu", []byte(keys.PrivateKeyData), "") //nolint:govet //abc - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - o.Auth = pubkeys - } - - r, err := git.PlainClone(path, isBare, o) - return r, breverrors.WrapAndTrace(err) - }, - open: func(path string) (repo, error) { - r, err := git.PlainOpen(path) - return r, breverrors.WrapAndTrace(err) - }, - configure: configure, - }.RunE, - } - - cmd.Flags().BoolVarP(&configure, "configure", "c", false, "configure daemon") - return cmd -} - -type repo interface { - Remotes() ([]*git.Remote, error) -} - -type updateModel struct { - t *terminal.Terminal - Store updatemodelStore - clone func(path string, isBare bool, o *git.CloneOptions) (*git.Repository, error) - open func(path string) (repo, error) - configure bool -} - -func (u updateModel) RunE(_ *cobra.Command, _ []string) error { //nolint:funlen //abc - if u.configure { - return breverrors.WrapAndTrace( - DaemonConfigurer{ - Store: u.Store, - }.Configure(), - ) - } - - remotes, err := u.remotes() - if err != nil { - return breverrors.WrapAndTrace(err) - } - workspaceID, err := u.Store.GetCurrentWorkspaceID() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - workspace, err := u.Store.GetWorkspace(workspaceID) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - // there should only be one but sometimes there are more and thats not - // handled right now - urls := lo.FlatMap( - remotes, - func(remote *git.Remote, _ int) []string { - return remote.Config().URLs - }, - ) - - // filter user dotbrev remote url - user, err := u.Store.GetCurrentUser() - if err != nil { - return breverrors.WrapAndTrace(err) - } - dotbrev := user.BaseWorkspaceRepo - urls = lo.Filter( - urls, - func(url string, _ int) bool { - return !parse.CMP(url, dotbrev) - }, - ) - - reposv1FromENV := makeReposFromRemotes(urls) - - // merge reposv0 and gitrepo field into reposv1fromBE - - reposv1FromBE := make(entity.ReposV1) - reposv1FromBE[entity.RepoName(parse.GetRepoNameFromOrigin(workspace.GitRepo))] = entity.RepoV1{ - GitRepo: entity.GitRepo{ - Repository: workspace.GitRepo, - }, - Type: entity.GitRepoType, - } - - for key, val := range workspace.ReposV0 { - reposv1FromBE[key] = entity.RepoV1{ - GitRepo: entity.GitRepo{ - Repository: val.Repository, - }, - Type: entity.GitRepoType, - } - } - if workspace.ReposV1 != nil { - // Remove redundant reassignments of range variables; Go v1.24 no longer requires shadowing inside loops, so key/val can be used directly - for key, val := range *workspace.ReposV1 { - reposv1FromBE[key] = val - } - } - - rm := &repoMerger{ - acc: &reposv1FromBE, - repos: []*entity.ReposV1{reposv1FromENV}, - } - _, err = u.Store.ModifyWorkspace( - workspaceID, - &store.ModifyWorkspaceRequest{ - ReposV1: rm.MergeBE(), - }, - ) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - dir, err := u.Store.UserHomeDir() - if err != nil { - return breverrors.WrapAndTrace(err) - } - - cloneErrors := lo.Map( - rm.ReposToClone(), - func(repo *entity.RepoV1, _ int) error { - _, err := u.clone(dir, false, &git.CloneOptions{ - URL: repo.GitRepo.Repository, - }) - return breverrors.WrapAndTrace(err) - }, - ) - return breverrors.WrapAndTrace( - lo.Reduce( - cloneErrors, - func(acc error, err error, _ int) error { - if err != nil { - txt := fmt.Sprintf("%s", err) - if strings.Contains(txt, "already exists") { - return acc - } - if acc == nil { - return breverrors.WrapAndTrace(err) - } - return multierror.Append(acc, err) - } - if acc == nil { - return breverrors.WrapAndTrace(err) - } - return acc - }, - nil, - ), - ) -} - -type stringWriter interface { - WriteString(path, data string) error -} - -type DaemonConfigurer struct { - Store stringWriter -} - -func (dc DaemonConfigurer) Configure() error { - // create systemd service file to run - // brev updatemodel -d /home/ubuntu - configFile := filepath.Join("/etc/systemd/system", "brev-updatemodel.service") - err := dc.Store.WriteString( - configFile, - `[Unit] -Description=Brev Update Model -After=network.target - -[Service] -Type=simple -User=ubuntu -ExecStart=/usr/bin/brev updatemodel -d /home/ubuntu -`) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - if autostartconf.ShouldSymlink() { - symlinkTarget := path.Join("/etc/systemd/system/default.target.wants/", "brev-updatemodel.service") - err2 := os.Symlink(configFile, symlinkTarget) - if err2 != nil { - return breverrors.WrapAndTrace(err2) - } - } - // create systemd timer to run every 5 seconds - err = dc.Store.WriteString( - "/etc/systemd/system/brev-updatemodel.timer", - `[Unit] -Description=Brev Update Model Timer - -[Timer] -OnBootSec=5 -OnUnitActiveSec=5 - -[Install] -WantedBy=timers.target -`) - if err != nil { - return breverrors.WrapAndTrace(err) - } - - // enable timer - err = autostartconf.ExecCommands( - [][]string{ - {"systemctl", "enable", "brev-updatemodel.timer"}, - {"systemctl", "start", "brev-updatemodel.timer"}, - {"systemctl", "daemon-reload"}, - }, - ) - if err != nil { - return breverrors.WrapAndTrace(err) - } - return nil -} - -func makeReposFromRemotes(remotes []string) *entity.ReposV1 { - return lo.Reduce( - remotes, - func(acc *entity.ReposV1, remote string, _ int) *entity.ReposV1 { - name := parse.GetRepoNameFromOrigin(remote) - url := parse.GetSSHURLFromOrigin(remote) - a := *acc - a[entity.RepoName(name)] = entity.RepoV1{ - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: url, - }, - } - return &a - }, - &entity.ReposV1{}, - ) -} - -type repoMerger struct { - acc *entity.ReposV1 - repos []*entity.ReposV1 -} - -func (r *repoMerger) MergeBE() *entity.ReposV1 { - for _, repo := range r.repos { - for k, v := range *repo { - if _, ok := (*r.acc)[k]; ok { - continue - } - _, valueInAcc := lo.Find( - r.accValues(), - func(repo *entity.RepoV1) bool { - return repo.GitRepo.Repository == v.GitRepo.Repository - }, - ) - if valueInAcc { - continue - } - (*r.acc)[k] = v - } - } - return r.acc -} - -func (r *repoMerger) ReposToClone() []*entity.RepoV1 { - // repos present in the BE but not in the ENV - return lo.Filter( - r.accValues(), - func(accrepo *entity.RepoV1, _ int) bool { - _, valueInENV := lo.Find( - r.reposValues(), - func(repo *entity.RepoV1) bool { - return accrepo.GitRepo.Repository == repo.GitRepo.Repository - }, - ) - return !valueInENV - }, - ) -} - -func (r repoMerger) reposValues() []*entity.RepoV1 { - values := []*entity.RepoV1{} - for _, repo := range r.repos { - for _, v := range *repo { - values = append(values, &v) - } - } - return values -} - -func (r repoMerger) accValues() []*entity.RepoV1 { - if r.acc == nil { - return []*entity.RepoV1{} - } - values := []*entity.RepoV1{} - for _, v := range *r.acc { - newV := v - values = append(values, &newV) - } - return values -} - -func (u updateModel) remotes() ([]*git.Remote, error) { - dir, err := u.Store.UserHomeDir() - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - dirs, err := u.Store.ListDirs(dir) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - - // filter dirs that start with . - dirs = lo.Filter( - dirs, - func(dir string, _ int) bool { - return !strings.HasPrefix(dir, ".") - }, - ) - - dirsWithGit := []string{} - for _, dir := range dirs { - gitDir := path.Join(dir, ".git") - exists, err := u.Store.FileExists(gitDir) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - if exists { - dirsWithGit = append(dirsWithGit, dir) - } - } - - repos := []*git.Repository{} - for _, dir := range dirsWithGit { - repo, err := git.PlainOpen(dir) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - repos = append(repos, repo) - } - - remotes := []*git.Remote{} - for _, repo := range repos { - repoRemotes, err := repo.Remotes() - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - remotes = append(remotes, repoRemotes...) - } - return remotes, nil -} diff --git a/pkg/cmd/updatemodel/updatemodel_test.go b/pkg/cmd/updatemodel/updatemodel_test.go deleted file mode 100644 index 7a13c50ff..000000000 --- a/pkg/cmd/updatemodel/updatemodel_test.go +++ /dev/null @@ -1,292 +0,0 @@ -package updatemodel - -import ( - "testing" - - "github.com/brevdev/brev-cli/pkg/entity" - "github.com/brevdev/brev-cli/pkg/store" - "github.com/brevdev/brev-cli/pkg/terminal" - "github.com/go-git/go-git/v5" - "github.com/google/go-cmp/cmp" - "github.com/spf13/cobra" -) - -type updatemodelStoreMock struct{} - -func (u updatemodelStoreMock) ModifyWorkspace(_ string, _ *store.ModifyWorkspaceRequest) (*entity.Workspace, error) { - return nil, nil -} - -func (u updatemodelStoreMock) GetCurrentWorkspaceID() (string, error) { - return "test", nil -} - -func (u updatemodelStoreMock) GetWorkspace(_ string) (*entity.Workspace, error) { - reposv1 := entity.ReposV1{ - entity.RepoName("test"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "foo", - }, - }, - } - return &entity.Workspace{ - ReposV1: &reposv1, - }, nil -} - -func (u updatemodelStoreMock) WriteString(_, _ string) error { - return nil -} - -func (u updatemodelStoreMock) UserHomeDir() (string, error) { - return "", nil -} - -func (u updatemodelStoreMock) ListDirs(_ string) ([]string, error) { - return nil, nil -} - -func (u updatemodelStoreMock) FileExists(_ string) (bool, error) { - return false, nil -} - -func (u updatemodelStoreMock) GetEnvSetupParams(_ string) (*store.SetupParamsV0, error) { - return nil, nil -} - -func (u updatemodelStoreMock) GetCurrentUser() (*entity.User, error) { - return nil, nil -} - -func mockPlainClone(_ string, _ bool, _ *git.CloneOptions) (*git.Repository, error) { - return nil, nil -} - -type remotes struct{} - -func (r remotes) Remotes() ([]*git.Remote, error) { - return nil, nil -} - -func mockPlainOpen(_ string) (repo, error) { - return remotes{}, nil -} - -func TestUpdateModel_RunE(t *testing.T) { - type fields struct { - t *terminal.Terminal - Store updatemodelStore - // directory string - clone func(path string, isBare bool, o *git.CloneOptions) (*git.Repository, error) - open func(path string) (repo, error) - configure bool - } - type args struct { - in0 *cobra.Command - in1 []string - } - tests := []struct { - name string - fields fields - args args - wantErr bool - }{ - // TODO: Add test cases. - // TODO: Add test cases. - { - name: "test", - fields: fields{ - t: nil, - Store: updatemodelStoreMock{}, - clone: mockPlainClone, - open: mockPlainOpen, - }, - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - u := updateModel{ - t: tt.fields.t, - Store: tt.fields.Store, - clone: tt.fields.clone, - open: tt.fields.open, - configure: tt.fields.configure, - } - t.Skip("TODO: fix this test") - if err := u.RunE(tt.args.in0, tt.args.in1); (err != nil) != tt.wantErr { - t.Errorf("UpdateModel.RunE() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func Test_makeReposFromRemotes(t *testing.T) { - type args struct { - remotes []string - } - tests := []struct { - name string - args args - want *entity.ReposV1 - }{ - // TODO: Add test cases. - { - name: "test", - args: args{ - remotes: []string{"git@github.com:brevdev/brev-cli.git", "git@github.com:brevdev/brev-deploy.git"}, - }, - want: &entity.ReposV1{ - entity.RepoName("brev-cli"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "git@github.com:brevdev/brev-cli.git", - }, - }, - entity.RepoName("brev-deploy"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "git@github.com:brevdev/brev-deploy.git", - }, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := makeReposFromRemotes(tt.args.remotes) - // cmp.Diff is used to compare the two structs - if diff := cmp.Diff(got, tt.want); diff != "" { - t.Errorf("makeReposFromRemotes() mismatch (-want +got):\n%s", diff) - } - }) - } -} - -func Test_repoMerger_MergeBE(t *testing.T) { - type fields struct { - acc *entity.ReposV1 - repos []*entity.ReposV1 - } - tests := []struct { - name string - fields fields - want *entity.ReposV1 - }{ - // TODO: Add test cases. - { - name: "test", - fields: fields{ - acc: &entity.ReposV1{ - entity.RepoName("brev-cli"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "git@github.com/brevdev/brev-cli.git", - }, - }, - }, - repos: []*entity.ReposV1{ - { - entity.RepoName("brev-deploy"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "github.com/brevdev/brev-deploy.git", - }, - }, - }, - { - entity.RepoName("brev-cli"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "github.com/brevdev/brev-cli.git", - }, - }, - }, - }, - }, - want: &entity.ReposV1{ - entity.RepoName("brev-cli"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "git@github.com/brevdev/brev-cli.git", - }, - }, - entity.RepoName("brev-deploy"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "github.com/brevdev/brev-deploy.git", - }, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - r := &repoMerger{ - acc: tt.fields.acc, - repos: tt.fields.repos, - } - // using cmp - if diff := cmp.Diff(r.MergeBE(), tt.want); diff != "" { - t.Errorf("repoMerger.MergeBE() mismatch (-want +got):\n%s", diff) - } - }) - } -} - -func Test_repoMerger_ReposToClone(t *testing.T) { - type fields struct { - acc *entity.ReposV1 - repos []*entity.ReposV1 - } - tests := []struct { - name string - fields fields - want []*entity.RepoV1 - }{ - // TODO: Add test cases. - { - name: "test", - fields: fields{ - acc: &entity.ReposV1{ - entity.RepoName("brev-cli"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "git@github.com/brevdev/brev-cli.git", - }, - }, - }, - repos: []*entity.ReposV1{ - { - entity.RepoName("brev-deploy"): { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "github.com/brevdev/brev-deploy.git", - }, - }, - }, - }, - }, - want: []*entity.RepoV1{ - { - Type: entity.GitRepoType, - GitRepo: entity.GitRepo{ - Repository: "git@github.com/brevdev/brev-cli.git", - }, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - r := &repoMerger{ - acc: tt.fields.acc, - repos: tt.fields.repos, - } - if diff := cmp.Diff(r.ReposToClone(), tt.want); diff != "" { - t.Errorf("repoMerger.ReposToClone() mismatch (-want +got):\n%s", diff) - } - }) - } -} diff --git a/pkg/config/config.go b/pkg/config/config.go index 7d492335d..c3ab290e0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -15,7 +15,6 @@ const ( coordURL EnvVarName = "BREV_COORD_URL" version EnvVarName = "VERSION" clusterID EnvVarName = "DEFAULT_CLUSTER_ID" - defaultWorkspaceClass EnvVarName = "DEFAULT_WORKSPACE_CLASS" defaultWorkspaceTemplate EnvVarName = "DEFAULT_WORKSPACE_TEMPLATE" sentryURL EnvVarName = "DEFAULT_SENTRY_URL" debugHTTP EnvVarName = "DEBUG_HTTP" @@ -63,10 +62,6 @@ func (c ConstantsConfig) GetDefaultClusterID() string { return getEnvOrDefault(clusterID, "devplane-brev-1") } -func (c ConstantsConfig) GetDefaultWorkspaceClass() string { - return getEnvOrDefault(defaultWorkspaceClass, "") -} - func (c ConstantsConfig) GetDefaultWorkspaceTemplate() string { // "test-template-aws" return getEnvOrDefault(defaultWorkspaceTemplate, "") diff --git a/pkg/entity/entity.go b/pkg/entity/entity.go index c22e1ee42..08e68354b 100644 --- a/pkg/entity/entity.go +++ b/pkg/entity/entity.go @@ -147,12 +147,11 @@ const ( ) type UpdateUser struct { - Username string `json:"username,omitempty"` - Name string `json:"name,omitempty"` - Email string `json:"email,omitempty"` - BaseWorkspaceRepo string `json:"baseWorkspaceRepo,omitempty"` - OnboardingData map[string]interface{} `json:"onboardingData,omitempty"` - IdeConfig IDEConfig `json:"ideConfig,omitempty"` + Username string `json:"username,omitempty"` + Name string `json:"name,omitempty"` + Email string `json:"email,omitempty"` + OnboardingData map[string]interface{} `json:"onboardingData,omitempty"` + IdeConfig IDEConfig `json:"ideConfig,omitempty"` } type GlobalUserType string @@ -175,7 +174,6 @@ type User struct { Name string `json:"name"` Email string `json:"email"` WorkspacePassword string `json:"workspacePassword"` - BaseWorkspaceRepo string `json:"baseWorkspaceRepo"` GlobalUserType GlobalUserType `json:"globalUserType"` IdeConfig IDEConfig `json:"ideConfig,omitempty"` OnboardingData map[string]interface{} `json:"onboardingData"` diff --git a/pkg/store/user_test.go b/pkg/store/user_test.go index 592eaaf60..7572159e2 100644 --- a/pkg/store/user_test.go +++ b/pkg/store/user_test.go @@ -105,10 +105,9 @@ func TestUpdateUser(t *testing.T) { httpmock.RegisterResponder("PUT", url, res) u, err := s.UpdateUser(expected.ID, &entity.UpdateUser{ - Username: "", - Name: "", - Email: "", - BaseWorkspaceRepo: "", + Username: "", + Name: "", + Email: "", }) if !assert.Nil(t, err) { return diff --git a/pkg/store/workspace.go b/pkg/store/workspace.go index a7c2755a5..d29a0a64b 100644 --- a/pkg/store/workspace.go +++ b/pkg/store/workspace.go @@ -206,9 +206,8 @@ type LaunchableFile struct { } var ( - DefaultWorkspaceClassID = config.GlobalConfig.GetDefaultWorkspaceClass() - UserWorkspaceClassID = "2x8" - DevWorkspaceClassID = "4x16" + UserWorkspaceClassID = "2x8" + DevWorkspaceClassID = "4x16" DefaultWorkspaceTemplateID = config.GlobalConfig.GetDefaultWorkspaceTemplate() UserWorkspaceTemplateID = "4nbb4lg2s" @@ -216,18 +215,6 @@ var ( DefaultDiskStorage = "120Gi" ) -var ( - DefaultApplicationID = "92f59a4yf" - DefaultApplication = entity.Application{ - ID: DefaultApplicationID, - Name: "VSCode", - Port: 22778, - StartCommand: "", - Version: "1.57.1", - } -) -var DefaultApplicationList = []entity.Application{DefaultApplication} - func NewCreateWorkspacesOptions(clusterID, name string) *CreateWorkspacesOptions { isStoppable := false return &CreateWorkspacesOptions{ @@ -525,31 +512,6 @@ func (s AuthHTTPStore) GetWorkspace(workspaceID string) (*entity.Workspace, erro return &result, nil } -func (s AuthHTTPStore) ModifyWorkspace(workspaceID string, options *ModifyWorkspaceRequest) (*entity.Workspace, error) { - if options == nil { - return nil, fmt.Errorf("options can not be nil") - } - - var result entity.Workspace - res, err := s.authHTTPClient.restyClient.R(). - SetHeader("Content-Type", "application/json"). - SetPathParam(workspaceIDParamName, workspaceID). - SetResult(&result). - SetBody(options). - Put(workspacePath) - if err != nil { - return nil, breverrors.WrapAndTrace(err) - } - if res.IsError() { - return nil, NewHTTPResponseError(res) - } - // fmt.Printf("name %s\n", result.Name) - // fmt.Printf("template %s %s\n", result.WorkspaceTemplate.ID, result.WorkspaceTemplate.Name) - // fmt.Printf("resource class %s\n", result.WorkspaceClassID) - // fmt.Printf("instance %s\n", result.InstanceType) - return &result, nil -} - func (s AuthHTTPStore) DeleteWorkspace(workspaceID string) (*entity.Workspace, error) { var result entity.Workspace res, err := s.authHTTPClient.restyClient.R().