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

Pass config to jibril #278

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
65 changes: 60 additions & 5 deletions cmd/ci/enable/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/listendev/lstn/pkg/validate"
"github.com/listendev/pkg/apispec"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

var (
Expand Down Expand Up @@ -106,8 +107,9 @@ func New(ctx context.Context) (*cobra.Command, error) {
return nil
}

// Fetch settings from Core API
io.StartProgressIndicator()

// create a client for the Core API
coreClient, coreClientErr := apispec.NewClientWithResponses(
opts.Endpoint.Core,
apispec.WithRequestEditorFn(func(_ context.Context, req *http.Request) error {
Expand All @@ -127,18 +129,22 @@ func New(ctx context.Context) (*cobra.Command, error) {

return coreClientErr
}

// get settings from the Core API
coreResponse, coreResponseErr := coreClient.GetApiV1SettingsWithResponse(ctx)
if coreResponseErr != nil {
io.StopProgressIndicator()

return coreResponseErr
}

if coreResponse.StatusCode() != http.StatusOK {
io.StopProgressIndicator()
c.PrintErrln(cs.WarningIcon(), "settings request to Core API didn't work out", cs.Redf("(%d)", coreResponse.StatusCode()))

return fmt.Errorf("status code is not %d", http.StatusOK)
}

if coreResponse.JSON200 == nil {
io.StopProgressIndicator()
c.PrintErrln(cs.WarningIcon(), "empty settings response")
Expand All @@ -149,7 +155,30 @@ func New(ctx context.Context) (*cobra.Command, error) {
io.StopProgressIndicator()
c.Println(cs.SuccessIcon(), "Fetch settings")

// Create configuration for runtime eavesdropping tool
io.StartProgressIndicator()

// get yaml config for jibril
config, err := coreClient.GetConfigWithResponse(ctx, &apispec.GetConfigParams{WorkflowId: "1"}) // FIXME: workflow id is hardcoded
if err != nil || config.StatusCode() != http.StatusOK {
io.StopProgressIndicator()

c.PrintErrln(cs.WarningIcon(), "couldn't fetch the configuration for jibril", cs.Redf("(%d)", config.StatusCode()))

return err
}

jibrilConfig := *config.JSON200
io.StopProgressIndicator()

if err := writeToYaml(jibrilConfig); err != nil {
c.PrintErrln(cs.WarningIcon(), "couldn't write the configuration YAML for jibril")

return err
}

c.Println(cs.SuccessIcon(), "Wrote jibril config", cs.Magenta("config.yaml"))

// Create env file for runtime eavesdropping tool as a systemd service
io.StartProgressIndicator()

jibrilEnvConfigFilename, err := createEnvForJibrill(isLocal, coreSettings, info, opts.Token.JWT, opts.Token.GitHub)
Expand All @@ -160,10 +189,12 @@ func New(ctx context.Context) (*cobra.Command, error) {
}

io.StopProgressIndicator()
c.Println(cs.SuccessIcon(), "Wrote config", cs.Magenta(jibrilEnvConfigFilename))

c.Println(cs.SuccessIcon(), "Wrote jibril env config", cs.Magenta(jibrilEnvConfigFilename))

io.StartProgressIndicator()
var jibril *exec.Cmd
var jibrilFile string
if len(opts.Directory) > 0 {
file := filepath.Join(opts.Directory, "jibril")
info, err := os.Stat(file)
Expand All @@ -177,16 +208,21 @@ func New(ctx context.Context) (*cobra.Command, error) {

return fmt.Errorf("expecting %s to be an executable file", file)
}
jibril = exec.CommandContext(ctx, file, "-s", "enable-now")

jibrilFile = file
} else {
exe, err := exec.LookPath("jibril")
if err != nil {
io.StopProgressIndicator()

return fmt.Errorf("couldn't find the jibril executable in the PATH")
}
jibril = exec.CommandContext(ctx, exe, "-s", "enable-now")

jibrilFile = exe
}

jibril = exec.CommandContext(ctx, jibrilFile, "-s", "enable-now --config ./config.yaml")

io.StopProgressIndicator()
c.Println(cs.Blue("•"), "Install and enable", cs.Magenta(jibril.String()))

Expand Down Expand Up @@ -250,3 +286,22 @@ func createEnvForJibrill(isLocal bool, settings apispec.Settings, info *ci.Info,

return envConfigFilename, nil
}

func writeToYaml(config apispec.JibrilConfig) error {
currentDir, err := os.Getwd()
if err != nil {
return err
}

data, err := yaml.Marshal(config)
if err != nil {
return err
}

yamlConfig := filepath.Join(currentDir, "config.yaml")
if err := os.WriteFile(yamlConfig, data, 0640); err != nil {
return err
}

return nil
}
159 changes: 81 additions & 78 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,152 +4,155 @@ go 1.23.3

require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/Masterminds/semver/v3 v3.2.1
github.com/XANi/goneric v1.1.0
github.com/caarlos0/env/v11 v11.0.0
github.com/Masterminds/semver/v3 v3.3.1
github.com/XANi/goneric v1.2.0
github.com/caarlos0/env/v11 v11.2.2
github.com/cli/cli v1.14.0
github.com/creasty/defaults v1.7.0
github.com/creasty/defaults v1.8.0
github.com/ghetzel/testify v1.4.1
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.11.0
github.com/go-git/go-billy/v5 v5.6.0
github.com/go-git/go-git/v5 v5.12.0
github.com/go-playground/mold/v4 v4.5.0
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.19.0
github.com/go-playground/validator/v10 v10.23.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v53 v53.2.0
github.com/google/uuid v1.6.0
github.com/iancoleman/strcase v0.3.0
github.com/imdario/mergo v0.3.13
github.com/imdario/mergo v0.3.16
github.com/itchyny/gojq v0.12.15
github.com/jarcoal/httpmock v1.3.1
github.com/listendev/pkg v0.0.0-20240925130938-87ea6e7dbf41
github.com/matishsiao/goInfo v0.0.0-00010101000000-000000000000
github.com/listendev/pkg v0.0.0-20241203160517-790a0ce5da2c
github.com/matishsiao/goInfo v0.0.0-20240924010139-10388a85396f
github.com/mitchellh/mapstructure v1.5.0
github.com/muja/goconfig v0.0.0-20180417074348-0a635507dddc
github.com/pelletier/go-toml/v2 v2.2.1
github.com/spf13/cobra v1.8.0
github.com/pelletier/go-toml/v2 v2.2.3
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/thediveo/enumflag/v2 v2.0.5
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/PaesslerAG/gval v1.2.2 // indirect
dario.cat/mergo v1.0.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/PaesslerAG/gval v1.2.4 // indirect
github.com/PaesslerAG/jsonpath v0.1.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/briandowns/spinner v1.11.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/briandowns/spinner v1.23.1 // indirect
github.com/bytedance/sonic v1.12.5 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/cloudflare/circl v1.5.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/cyphar/filepath-securejoin v0.3.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/getkin/kin-openapi v0.76.0 // indirect
github.com/ghetzel/go-stockutil v1.11.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/ghetzel/go-stockutil v1.12.1 // indirect
github.com/ghetzel/uuid v0.0.0-20171129191014-dec09d789f3d // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/gin-gonic/gin v1.10.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/slug v1.14.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jdkato/prose v1.2.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juliangruber/go-intersect v1.1.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/leodido/go-encodeuricomponent v0.1.0 // indirect
github.com/leodido/go-npmpackagename v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/termenv v0.8.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rabbitmq/amqp091-go v1.9.0 // indirect
github.com/rabbitmq/amqp091-go v1.10.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/locafero v0.6.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/go-camelcase v0.0.0-20160726192923-7085f1e3c734 // indirect
github.com/segmentio/go-snakecase v1.2.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/sdk v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect
google.golang.org/grpc v1.68.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/neurosnap/sentences.v1 v1.0.7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v0.24.1 // indirect
k8s.io/client-go v0.31.3 // indirect
)

replace github.com/matishsiao/goInfo => github.com/mdelapenya/goInfo v0.0.0-20211021161444-126d78535ffb
Loading
Loading