Skip to content

Commit

Permalink
feat(cmd/ci): dump the settings (tokens part only) into the systemd c…
Browse files Browse the repository at this point in the history
…onfig file

Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido committed Sep 25, 2024
1 parent 118caee commit 9a46817
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 51 deletions.
87 changes: 43 additions & 44 deletions cmd/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
package ci

import (
"bytes"
"context"
"fmt"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/cli/cli/pkg/iostreams"
"github.com/davecgh/go-spew/spew"
"github.com/listendev/lstn/internal/project"
"github.com/listendev/lstn/pkg/ci"
"github.com/listendev/lstn/pkg/cmd/flags"
Expand Down Expand Up @@ -148,14 +151,12 @@ This command requires a listen.dev pro account.`,
return fmt.Errorf("got empty settings from the Core API")
}
coreSettings := *coreResponse.JSON200
spew.Dump(coreSettings.Tokens) // TODO: complete

io.StopProgressIndicator()
c.Println(cs.SuccessIcon(), "Fetch settings")

// Create configuration for runtime eavesdropping tool
io.StartProgressIndicator()
envConfig := fmt.Sprintf("%s\n%s=%s\n%s=%s\n", info.Dump(), "LISTENDEV_TOKEN", ciOpts.Token.JWT, "GITHUB_TOKEN", ciOpts.Token.GitHub)
envConfig := fmt.Sprintf("%s\n%s\n%s=%s\n%s=%s\n", strings.Join(coreSettings.TokensSlice(), "\n"), info.Dump(), "LISTENDEV_TOKEN", ciOpts.Token.JWT, "GITHUB_TOKEN", ciOpts.Token.GitHub)
envDirErr := os.MkdirAll("/var/run/argus", 0750)
if envDirErr != nil {
io.StopProgressIndicator()
Expand All @@ -172,47 +173,45 @@ This command requires a listen.dev pro account.`,
io.StopProgressIndicator()
c.Println(cs.SuccessIcon(), "Wrote config", cs.Magenta(envConfigFilename))

return nil
io.StartProgressIndicator()
var argus *exec.Cmd
if len(ciOpts.Directory) > 0 {
file := filepath.Join(ciOpts.Directory, "argus")
info, err := os.Stat(file)
if os.IsNotExist(err) {
io.StopProgressIndicator()

return fmt.Errorf("couldn't find the argus binary in %s", ciOpts.Directory)
}
if info.IsDir() {
io.StopProgressIndicator()

// io.StartProgressIndicator()
// var argus *exec.Cmd
// if len(ciOpts.Directory) > 0 {
// file := filepath.Join(ciOpts.Directory, "argus")
// info, err := os.Stat(file)
// if os.IsNotExist(err) {
// io.StopProgressIndicator()

// return fmt.Errorf("couldn't find the argus binary in %s", ciOpts.Directory)
// }
// if info.IsDir() {
// io.StopProgressIndicator()

// return fmt.Errorf("expecting %s to be an executable file", file)
// }
// argus = exec.CommandContext(ctx, file, "-s", "enable-now")
// } else {
// exe, err := exec.LookPath("argus")
// if err != nil {
// io.StopProgressIndicator()

// return fmt.Errorf("couldn't find the argus executable in the PATH")
// }
// argus = exec.CommandContext(ctx, exe, "-s", "enable-now")
// }
// io.StopProgressIndicator()
// c.Println(cs.Blue("•"), "Install and enable", cs.Magenta(argus.String()))

// io.StartProgressIndicator()
// argusOut, argusErr := argus.CombinedOutput()
// if argusErr != nil {
// io.StopProgressIndicator()

// return fmt.Errorf("couldn't install and enable argus: %w", argusErr)
// }
// io.StopProgressIndicator()
// c.Println(string(bytes.Trim(argusOut, "\n")))

// return nil
return fmt.Errorf("expecting %s to be an executable file", file)
}
argus = exec.CommandContext(ctx, file, "-s", "enable-now")
} else {
exe, err := exec.LookPath("argus")
if err != nil {
io.StopProgressIndicator()

return fmt.Errorf("couldn't find the argus executable in the PATH")
}
argus = exec.CommandContext(ctx, exe, "-s", "enable-now")
}
io.StopProgressIndicator()
c.Println(cs.Blue("•"), "Install and enable", cs.Magenta(argus.String()))

io.StartProgressIndicator()
argusOut, argusErr := argus.CombinedOutput()
if argusErr != nil {
io.StopProgressIndicator()

return fmt.Errorf("couldn't install and enable argus: %w", argusErr)
}
io.StopProgressIndicator()
c.Println(string(bytes.Trim(argusOut, "\n")))

return nil
},
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/imdario/mergo v0.3.13
github.com/itchyny/gojq v0.12.15
github.com/jarcoal/httpmock v1.3.1
github.com/listendev/pkg v0.0.0-20240925115341-7cbaafbff31f
github.com/listendev/pkg v0.0.0-20240925130938-87ea6e7dbf41
github.com/matishsiao/goInfo v0.0.0-00010101000000-000000000000
github.com/mitchellh/mapstructure v1.5.0
github.com/muja/goconfig v0.0.0-20180417074348-0a635507dddc
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,8 @@ github.com/leodido/go-npmpackagename v0.2.0 h1:PWtLWmGwffpCMdVY1twLqVw9IyQJVU3Tf
github.com/leodido/go-npmpackagename v0.2.0/go.mod h1:dFl2KBJaW8cAAnWZXtrNnXdpDEfg5hmBtg808SrblpM=
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/listendev/pkg v0.0.0-20240419111038-ecbb9c6e3aa0 h1:5Hjtbsc3FN7Wtz58U41nVG2CidE5XeEOZEEukH/vPm8=
github.com/listendev/pkg v0.0.0-20240419111038-ecbb9c6e3aa0/go.mod h1:5arbKKs4nBpXLTDR7/H7AMCfk57OOnKvMYkBGNWcXCg=
github.com/listendev/pkg v0.0.0-20240924140700-3eb7337428a4 h1:3ssCde8pyywnsc0YqRGe1P9Zfdi4+1nrnUuV+4gpBmk=
github.com/listendev/pkg v0.0.0-20240924140700-3eb7337428a4/go.mod h1:5arbKKs4nBpXLTDR7/H7AMCfk57OOnKvMYkBGNWcXCg=
github.com/listendev/pkg v0.0.0-20240925115341-7cbaafbff31f h1:ZTuQr//S3PELuQtmsx0D1aohMOu6QBzEONZXDvcybvE=
github.com/listendev/pkg v0.0.0-20240925115341-7cbaafbff31f/go.mod h1:5arbKKs4nBpXLTDR7/H7AMCfk57OOnKvMYkBGNWcXCg=
github.com/listendev/pkg v0.0.0-20240925130938-87ea6e7dbf41 h1:og7862I3TboqURhpUbQS+Gv7uDqh86c2hOJXSeLNg1k=
github.com/listendev/pkg v0.0.0-20240925130938-87ea6e7dbf41/go.mod h1:5arbKKs4nBpXLTDR7/H7AMCfk57OOnKvMYkBGNWcXCg=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand Down

0 comments on commit 9a46817

Please sign in to comment.