Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup phase1 #209

Merged
merged 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions e2etest/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/brevdev/brev-cli/pkg/files"
"github.com/brevdev/brev-cli/pkg/store"
"github.com/hashicorp/go-multierror"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -106,20 +105,6 @@ func NewWorkspaceTestClient(setupParams *store.SetupParamsV0, containerParams []
}
}

func (w WorkspaceTestClient) Done() error {
var allError error
for _, w := range w.TestWorkspaces {
err := w.Done()
if err != nil {
allError = multierror.Append(allError, err)
}
}
if allError != nil {
return breverrors.WrapAndTrace(allError)
}
return nil
}

type workspaceTest func(workspace Workspace, err error)

func (w WorkspaceTestClient) Test(test workspaceTest) error {
Expand Down Expand Up @@ -482,12 +467,6 @@ func AssertPathExists(t *testing.T, workspace Workspace, path string) bool {
return assert.Nil(t, err)
}

func AssertPathNotExist(t *testing.T, workspace Workspace, path string) bool {
t.Helper()
_, err := workspace.Exec("ls", path)
return assert.NotNil(t, err)
}

func AssertPathDoesNotExist(t *testing.T, workspace Workspace, path string) bool {
t.Helper()
_, err := workspace.Exec("ls", path)
Expand Down Expand Up @@ -520,13 +499,6 @@ func AssertDockerRunning(t *testing.T, w Workspace) bool {
return strings.Contains(string(out), "active")
}

func AssertRepoHasNumFiles(t *testing.T, w Workspace, filePath string, num int) {
t.Helper()
out, err := w.Exec("ls", "-a", filePath)
assert.Nil(t, err)
assert.Len(t, strings.Fields(string(out)), num)
}

func UpdateFile(w Workspace, filePath string, content string) error {
_, err := w.Exec("sh", "-c", fmt.Sprintf(`echo '%s' > %s`, content, filePath))
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,3 @@ func isAccessTokenValid(token string) (bool, error) {
}
return true, nil
}

func IsAuthError(err error) bool {
return strings.Contains(err.Error(), "403")
}
10 changes: 0 additions & 10 deletions pkg/auth/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,8 @@ type State struct {
}

// RequiredScopes returns the scopes used for login.
func RequiredScopes() []string { return requiredScopes }

// RequiredScopesMin returns minimum scopes used for login in integration tests.
func RequiredScopesMin() []string {
min := []string{}
for _, s := range requiredScopes {
if s != "offline_access" && s != "openid" {
min = append(min, s)
}
}
return min
}

func (s *State) IntervalDuration() time.Duration {
return time.Duration(s.Interval+waitThresholdInSeconds) * time.Second
Expand Down
121 changes: 0 additions & 121 deletions pkg/autostartconf/autostartconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,127 +44,6 @@ func firstAndRest(commandstring []string) (string, []string) {
return first, rest
}

func NewVPNConfig(store AutoStartStore) DaemonConfigurer {
switch runtime.GOOS {
case osLinux:
return LinuxSystemdConfigurer{
Store: store,
ValueConfigFile: `
[Install]
WantedBy=multi-user.target

[Unit]
Description=Brev vpn daemon
After=systemd-user-sessions.service

[Service]
Type=simple
ExecStart=brev tasks run vpnd
Restart=always
`,
ServiceName: "brevvpnd.service",
ServiceType: "system",
TargetBin: targetBin,
}
case osDarwin:
return DarwinPlistConfigurer{
Store: store,
ValueConfigFile: `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>

<key>Label</key>
<string>com.brev.vpnd</string>

<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brev</string>
<string>tasks</string>
<string>run</string>
<string>vpnd</string>
</array>

<key>RunAtLoad</key>
<true/>

<key>StandardOutPath</key>
<string>/var/log/brevvpnd.log</string>
<key>StandardErrorPath</key>
<string>/var/log/brevvpnd.log</string>

</dict>
</plist>
`,
ServiceName: "com.brev.vpnd",
ServiceType: System,
}
}
return nil
}

func NewRPCConfig(store AutoStartStore) DaemonConfigurer {
switch runtime.GOOS {
case osLinux:
return LinuxSystemdConfigurer{
Store: store,
ValueConfigFile: `
[Install]
WantedBy=multi-user.target

[Unit]
Description=Brev rpc daemon
After=systemd-user-sessions.service

[Service]
Type=simple
ExecStart=brev tasks run rpcd --user ` + store.GetOSUser() + `
Restart=always
`,
ServiceName: "brevrpcd.service",
ServiceType: "system",
}
case osDarwin:
return DarwinPlistConfigurer{
Store: store,
ValueConfigFile: `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>

<key>Label</key>
<string>com.brev.rpcd</string>

<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/brev</string>
<string>tasks</string>
<string>run</string>
<string>rpcd</string>
<string>--user</string>
<string>` + store.GetOSUser() + `</string>
</array>

<key>RunAtLoad</key>
<true/>

<key>StandardOutPath</key>
<string>/var/log/brevrpcd.log</string>
<key>StandardErrorPath</key>
<string>/var/log/brevrpcd.log</string>

</dict>
</plist>
`,
ServiceName: "com.brev.rpcd",
ServiceType: System,
}
}
return nil
}

// func NewDaemonConfiguration(user string, command string, serviceName string, serviceType string) DaemonConfigurer {
// switch runtime.GOOS {
// case osLinux:
Expand Down
41 changes: 2 additions & 39 deletions pkg/autostartconf/staticbinary.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
package autostartconf

import (
"path/filepath"

breverrors "github.com/brevdev/brev-cli/pkg/errors"
)

type StaticBinaryConfigurer struct {
LinuxSystemdConfigurer
URL string
Name string
}

func (sbc StaticBinaryConfigurer) Install() error {
_ = sbc.UnInstall() // best effort

// download binary
err := sbc.Store.DownloadBinary(
sbc.URL,
filepath.Join("/usr/local/bin", sbc.Name),
)
if err != nil {
return breverrors.WrapAndTrace(err)
}
// best effort

err = sbc.Store.WriteString(sbc.getDestConfigFile(), sbc.ValueConfigFile)
if err != nil {
return breverrors.WrapAndTrace(err)
}

if ShouldSymlink() {
errother := sbc.CreateForcedSymlink()
if errother != nil {
return breverrors.WrapAndTrace(errother)
}
} else {
errother := ExecCommands([][]string{
{"systemctl", "enable", sbc.ServiceName},
{"systemctl", "start", sbc.ServiceName},
{"systemctl", "daemon-reload"},
})
if errother != nil {
return breverrors.WrapAndTrace(errother)
}
}
return nil
}
// download binary
20 changes: 2 additions & 18 deletions pkg/cmd/cmderrors/cmderrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@ import (
)

// determines if should print error stack trace and/or send to crash monitor
func DisplayAndHandleCmdError(name string, cmdFunc func() error) error {
er := breverrors.GetDefaultErrorReporter()
er.AddTag("command", name)
err := cmdFunc()
if err != nil {
er.AddBreadCrumb(breverrors.ErrReportBreadCrumb{
Type: "err",
Message: err.Error(),
})
er.ReportError(err)
if featureflag.Debug() || featureflag.IsDev() {
return err
} else {
return errors.Cause(err) //nolint:wrapcheck //no check
}
}
return nil
}

//nolint:wrapcheck //no check

func DisplayAndHandleError(err error) {
er := breverrors.GetDefaultErrorReporter()
Expand Down
31 changes: 4 additions & 27 deletions pkg/cmd/hello/onboarding_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,13 @@ func SetOnboardingObject(oo OnboardingObject) error {
return nil
}

func SetOnboardingStep(step int) error {
// get path
path, err := GetOnboardingFilePath()
if err != nil {
return breverrors.WrapAndTrace(err)
}
// get path

// Ensure file exists
err = SetupDefaultOnboardingFile()
if err != nil {
return breverrors.WrapAndTrace(err)
}
// Ensure file exists

// write file
oo := OnboardingObject{
Step: step,
}
err = files.OverwriteJSON(files.AppFs, path, &oo)
if err != nil {
return breverrors.WrapAndTrace(err)
}
// write file

// return data
return nil
}
// return data

func SetHasRunShell(hasRunShell bool) error {
// get path
Expand Down Expand Up @@ -287,8 +269,3 @@ func SetHasRunOpen(hasRunOpen bool) error {
// return data
return nil
}

func Poll() {
s := "Got it."
TypeItToMe(s)
}
Loading
Loading