From 8f74330cd2854210fa8deeca5538ba412cbd5c5c Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Tue, 29 Aug 2023 12:11:30 +0200 Subject: [PATCH 1/4] First approach to extensible shell with plugins --- README.md | 6 + cmd/root.go | 1 + cmd/shell.go | 29 +++ go.mod | 7 +- go.sum | 20 +++ internal/configuration/locations/locations.go | 6 + internal/install/install.go | 13 ++ pkg/shell/plugins/changelog.go | 166 ++++++++++++++++++ pkg/shell/plugins/registry.go | 38 ++++ pkg/shell/plugins/sql.go | 140 +++++++++++++++ pkg/shell/plugins/writefile.go | 79 +++++++++ pkg/shell/shell.go | 119 +++++++++++++ 12 files changed, 623 insertions(+), 1 deletion(-) create mode 100644 cmd/shell.go create mode 100644 pkg/shell/plugins/changelog.go create mode 100644 pkg/shell/plugins/registry.go create mode 100644 pkg/shell/plugins/sql.go create mode 100644 pkg/shell/plugins/writefile.go create mode 100644 pkg/shell/shell.go diff --git a/README.md b/README.md index ebb94c6df..d6f5a0fa5 100644 --- a/README.md +++ b/README.md @@ -409,6 +409,12 @@ _Context: package_ Boot up the stack. +### `elastic-package shell` + +_Context: global_ + + + ### `elastic-package stack` _Context: global_ diff --git a/cmd/root.go b/cmd/root.go index 58c181d33..3b7016325 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,6 +31,7 @@ var commands = []*cobraext.Command{ setupPublishCommand(), setupReportsCommand(), setupServiceCommand(), + setupShellCommand(), setupStackCommand(), setupStatusCommand(), setupTestCommand(), diff --git a/cmd/shell.go b/cmd/shell.go new file mode 100644 index 000000000..ff81c5dfc --- /dev/null +++ b/cmd/shell.go @@ -0,0 +1,29 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package cmd + +import ( + cshell "github.com/brianstrauch/cobra-shell" + "github.com/spf13/cobra" + + "github.com/elastic/elastic-package/internal/cobraext" + "github.com/elastic/elastic-package/pkg/shell" +) + +func setupShellCommand() *cobraext.Command { + cmd := &cobra.Command{ + Use: "shell", + Hidden: true, + SilenceUsage: true, + } + cmd.CompletionOptions.DisableDefaultCmd = true + cmd.CompletionOptions.HiddenDefaultCmd = true + + shell.AttachCommands(cmd) + + shellCmd := cshell.New(cmd, nil) + + return cobraext.NewCommand(shellCmd, cobraext.ContextGlobal) +} diff --git a/go.mod b/go.mod index 5ce44e1ca..acfca97f5 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/ProtonMail/gopenpgp/v2 v2.7.3 github.com/aymerick/raymond v2.0.2+incompatible github.com/boumenot/gocover-cobertura v1.2.0 + github.com/brianstrauch/cobra-shell v0.4.0 github.com/cbroglie/mustache v1.4.0 github.com/cespare/xxhash/v2 v2.2.0 github.com/dustin/go-humanize v1.0.1 @@ -26,11 +27,13 @@ require ( github.com/google/uuid v1.3.1 github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/magefile/mage v1.15.0 + github.com/mattn/go-sqlite3 v1.14.17 github.com/mholt/archiver/v3 v3.5.1 github.com/olekukonko/tablewriter v0.0.5 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 github.com/shirou/gopsutil/v3 v3.23.9 github.com/spf13/cobra v1.7.0 + github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 golang.org/x/tools v0.14.0 gopkg.in/yaml.v3 v3.0.1 @@ -59,6 +62,7 @@ require ( github.com/andybalholm/brotli v1.0.4 // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect github.com/bitfield/gotestdox v0.2.1 // indirect + github.com/c-bata/go-prompt v0.2.6 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect github.com/cloudflare/circl v1.3.3 // indirect github.com/creasty/defaults v1.7.0 // indirect @@ -112,6 +116,7 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/mattn/go-tty v0.0.3 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect @@ -129,6 +134,7 @@ require ( github.com/pierrec/lz4/v4 v4.1.17 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pkg/term v1.2.0-beta.2 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/rivo/uniseg v0.4.3 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -138,7 +144,6 @@ require ( github.com/skeema/knownhosts v1.2.0 // indirect github.com/spf13/afero v1.10.0 // indirect github.com/spf13/cast v1.5.1 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.1 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect diff --git a/go.sum b/go.sum index 019a502a7..3a039e18b 100644 --- a/go.sum +++ b/go.sum @@ -93,7 +93,11 @@ github.com/bitfield/gotestdox v0.2.1 h1:Zj8IMLAO5/oiAKoMmtN96eyFiPZraJRTH2p0zDgt github.com/bitfield/gotestdox v0.2.1/go.mod h1:D+gwtS0urjBrzguAkTM2wodsTQYFHdpx8eqRJ3N+9pY= github.com/boumenot/gocover-cobertura v1.2.0 h1:g+VROIASoEHBrEilIyaCmgo7HGm+AV5yKEPLk0qIY+s= github.com/boumenot/gocover-cobertura v1.2.0/go.mod h1:fz7ly8dslE42VRR5ZWLt2OHGDHjkTiA2oNvKgJEjLT0= +github.com/brianstrauch/cobra-shell v0.4.0 h1:oPWTBqPPbE8Vd/i3WRvQd8XWTrevIwR0bFBIS7X6gWk= +github.com/brianstrauch/cobra-shell v0.4.0/go.mod h1:QkRKnD1+MfpITTqYDE8Yp8zALgsHdeYur/qAw4kNr8c= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= +github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU= github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -364,16 +368,25 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= +github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI= +github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -428,6 +441,8 @@ github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFz github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= +github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= +github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -666,10 +681,13 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -683,6 +701,8 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/internal/configuration/locations/locations.go b/internal/configuration/locations/locations.go index e498f8d91..cad1afa24 100644 --- a/internal/configuration/locations/locations.go +++ b/internal/configuration/locations/locations.go @@ -18,6 +18,7 @@ const ( stackDir = "stack" packagesDir = "development" profilesDir = "profiles" + pluginsDir = "shell_plugins" temporaryDir = "tmp" deployerDir = "deployer" @@ -102,6 +103,11 @@ func (loc LocationManager) CacheDir(name string) string { return filepath.Join(loc.stackPath, cacheDir, name) } +// ShellPluginsDir returns the directory where the shell plugins will be stored. +func (loc LocationManager) ShellPluginsDir() string { + return filepath.Join(loc.stackPath, pluginsDir) +} + // configurationDir returns the configuration directory location // If a environment variable named as in elasticPackageDataHome is present, // the value is used as is, overriding the value of this function. diff --git a/internal/install/install.go b/internal/install/install.go index 92eddb5e6..4b7b707cf 100644 --- a/internal/install/install.go +++ b/internal/install/install.go @@ -73,6 +73,10 @@ func EnsureInstalled() error { return fmt.Errorf("creating service logs directory failed: %w", err) } + if err := createShellPluginsDir(elasticPackagePath); err != nil { + return fmt.Errorf("creating shell plugins directory failed: %w", err) + } + fmt.Fprintln(os.Stderr, "elastic-package has been installed.") return nil } @@ -149,3 +153,12 @@ func createServiceLogsDir(elasticPackagePath *locations.LocationManager) error { } return nil } + +func createShellPluginsDir(elasticPackagePath *locations.LocationManager) error { + dirPath := elasticPackagePath.ShellPluginsDir() + err := os.MkdirAll(dirPath, 0755) + if err != nil { + return fmt.Errorf("mkdir failed (path: %s): %w", dirPath, err) + } + return nil +} diff --git a/pkg/shell/plugins/changelog.go b/pkg/shell/plugins/changelog.go new file mode 100644 index 000000000..37eeff69c --- /dev/null +++ b/pkg/shell/plugins/changelog.go @@ -0,0 +1,166 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "context" + "errors" + "fmt" + "io" + "os" + "path/filepath" + + "github.com/Masterminds/semver/v3" + "github.com/spf13/pflag" + + "github.com/elastic/elastic-package/internal/cobraext" + "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/internal/packages/changelog" + "github.com/elastic/elastic-package/pkg/shell" +) + +var _ shell.Command = changelogCmd{} + +type changelogCmd struct{} + +func (changelogCmd) Usage() string { + return "changelog --next {major|minor|patch} --description desc --type {bugfix|enhancement|breaking-change} --link link" +} + +func (changelogCmd) Desc() string { + return "Add an entry to the changelog file in each of the packages in context 'Shell.Packages'." +} + +func (changelogCmd) Flags() *pflag.FlagSet { + flags := pflag.NewFlagSet("", pflag.ContinueOnError) + flags.String(cobraext.ChangelogAddNextFlagName, "", cobraext.ChangelogAddNextFlagDescription) + flags.String(cobraext.ChangelogAddDescriptionFlagName, "", cobraext.ChangelogAddDescriptionFlagDescription) + flags.String(cobraext.ChangelogAddTypeFlagName, "", cobraext.ChangelogAddTypeFlagDescription) + flags.String(cobraext.ChangelogAddLinkFlagName, "", cobraext.ChangelogAddLinkFlagDescription) + return flags +} + +func (changelogCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { + packages, ok := ctx.Value(ctxKeyPackages).([]string) + if !ok { + fmt.Fprintln(stderr, "no packages found in the context") + return ctx, nil + } + for _, pkg := range packages { + packageRoot := pkg + // check if we are in packages folder + if _, err := os.Stat(filepath.Join(".", pkg)); err != nil { + // check if we are in integrations root folder + packageRoot = filepath.Join(".", "packages", pkg) + if _, err := os.Stat(packageRoot); err != nil { + return ctx, errors.New("you need to be in intgerations root folder or in the packages folder") + } + } + if err := changelogAddCmdForRoot(packageRoot, flags, args); err != nil { + return ctx, err + } + } + return ctx, nil +} + +func changelogAddCmdForRoot(packageRoot string, flags *pflag.FlagSet, args []string) error { + nextMode, _ := flags.GetString(cobraext.ChangelogAddNextFlagName) + v, err := changelogCmdVersion(nextMode, packageRoot) + if err != nil { + return err + } + version := v.String() + + description, _ := flags.GetString(cobraext.ChangelogAddDescriptionFlagName) + changeType, _ := flags.GetString(cobraext.ChangelogAddTypeFlagName) + link, _ := flags.GetString(cobraext.ChangelogAddLinkFlagName) + + entry := changelog.Revision{ + Version: version, + Changes: []changelog.Entry{ + { + Description: description, + Type: changeType, + Link: link, + }, + }, + } + + if err := patchChangelogFile(packageRoot, entry); err != nil { + return err + } + + if err := setManifestVersion(packageRoot, version); err != nil { + return err + } + + return nil +} + +func changelogCmdVersion(nextMode, packageRoot string) (*semver.Version, error) { + revisions, err := changelog.ReadChangelogFromPackageRoot(packageRoot) + if err != nil { + return nil, fmt.Errorf("failed to read current changelog: %w", err) + } + if len(revisions) == 0 { + return semver.MustParse("0.0.0"), nil + } + + version, err := semver.NewVersion(revisions[0].Version) + if err != nil { + return nil, fmt.Errorf("invalid version in changelog %q: %w", revisions[0].Version, err) + } + + switch nextMode { + case "": + break + case "major": + v := version.IncMajor() + version = &v + case "minor": + v := version.IncMinor() + version = &v + case "patch": + v := version.IncPatch() + version = &v + default: + return nil, fmt.Errorf("invalid value for %q: %s", + cobraext.ChangelogAddNextFlagName, nextMode) + } + + return version, nil +} + +// patchChangelogFile looks for the proper place to add the new revision in the changelog, +// trying to conserve original format and comments. +func patchChangelogFile(packageRoot string, patch changelog.Revision) error { + changelogPath := filepath.Join(packageRoot, changelog.PackageChangelogFile) + d, err := os.ReadFile(changelogPath) + if err != nil { + return err + } + + d, err = changelog.PatchYAML(d, patch) + if err != nil { + return err + } + + return os.WriteFile(changelogPath, d, 0644) +} + +func setManifestVersion(packageRoot string, version string) error { + manifestPath := filepath.Join(packageRoot, packages.PackageManifestFile) + d, err := os.ReadFile(manifestPath) + if err != nil { + return err + } + + d, err = changelog.SetManifestVersion(d, version) + if err != nil { + return err + } + + return os.WriteFile(manifestPath, d, 0644) +} diff --git a/pkg/shell/plugins/registry.go b/pkg/shell/plugins/registry.go new file mode 100644 index 000000000..e330a86f6 --- /dev/null +++ b/pkg/shell/plugins/registry.go @@ -0,0 +1,38 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "github.com/elastic/elastic-package/pkg/shell" +) + +func init() { + Registry.commands = append( + []shell.Command{}, + changelogCmd{}, + writefileCmd{}, + whereCmd{}, + initdbCmd{}, + ) +} + +type ctxKey string + +const ( + ctxKeyPackages ctxKey = "Shell.Packages" + ctxKeyDB ctxKey = "Shell.DB" +) + +var Registry = registry{} + +var _ shell.Plugin = registry{} + +type registry struct { + commands []shell.Command +} + +func (r registry) Commands() []shell.Command { + return r.commands +} diff --git a/pkg/shell/plugins/sql.go b/pkg/shell/plugins/sql.go new file mode 100644 index 000000000..0aacc75e0 --- /dev/null +++ b/pkg/shell/plugins/sql.go @@ -0,0 +1,140 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "context" + "database/sql" + "encoding/json" + "errors" + "fmt" + "io" + "os" + "path/filepath" + "strings" + + _ "github.com/mattn/go-sqlite3" + "github.com/spf13/pflag" + + "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/shell" +) + +const ( + createPackagesQuery = "CREATE TABLE `packages` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(256) NOT NULL, `manifest` TEXT NOT NULL)" + insertPackageQuery = "INSERT INTO `packages` (`name`, `manifest`) VALUES (?,?)" +) + +var _ shell.Command = whereCmd{} + +type whereCmd struct{} + +func (whereCmd) Usage() string { + return `where "query"` +} + +func (whereCmd) Desc() string { + return "Select a list of packages based on some conditions. Reads from context 'Shell.DB' and updates context 'Shell.Packages'." +} + +func (whereCmd) Flags() *pflag.FlagSet { + return nil +} + +func (whereCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { + db, ok := ctx.Value(ctxKeyDB).(*sql.DB) + if !ok { + return ctx, errors.New("db connection not found in context") + } + conditions := strings.Join(args, " ") + query := `SELECT name FROM packages` + if conditions != "" { + query = fmt.Sprintf("%s WHERE %s", query, conditions) + } + + rows, err := db.Query(query) + if err != nil { + return nil, err + } + defer rows.Close() + + var pkgs []string + var pkg string + for rows.Next() { + if err := rows.Scan(&pkg); err != nil { + return nil, err + } + pkgs = append(pkgs, pkg) + } + + ctx = context.WithValue(ctx, ctxKeyPackages, pkgs) + fmt.Fprintf(stderr, "Found %d packages\n", len(pkgs)) + return ctx, nil +} + +var _ shell.Command = initdbCmd{} + +type initdbCmd struct{} + +func (initdbCmd) Usage() string { + return "initdb" +} + +func (initdbCmd) Desc() string { + return "Initializes the packages database. Sets context 'Shell.DB'." +} + +func (initdbCmd) Flags() *pflag.FlagSet { + return nil +} + +func (initdbCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { + fmt.Fprintln(stderr, "Initializing database...") + + db, err := sql.Open("sqlite3", ":memory:") + if err != nil { + return ctx, err + } + + if _, err := db.Exec(createPackagesQuery); err != nil { + return ctx, err + } + + packagesPath := filepath.Join(".", "packages") + if _, err := os.Stat(packagesPath); err != nil { + return ctx, err + } + + entries, err := os.ReadDir(packagesPath) + if err != nil { + return ctx, err + } + + var c int + for _, e := range entries { + if !e.IsDir() || strings.HasPrefix(e.Name(), ".") { + continue + } + root := filepath.Join(packagesPath, e.Name()) + manifest, err := packages.ReadPackageManifestFromPackageRoot(root) + if err != nil { + return ctx, err + } + p, err := json.Marshal(manifest) + if err != nil { + return ctx, err + } + if _, err := db.Exec(insertPackageQuery, e.Name(), string(p)); err != nil { + return ctx, err + } + c++ + } + + fmt.Fprintf(stderr, "Loaded %d packages\n", c) + + ctx = context.WithValue(ctx, ctxKeyDB, db) + + return ctx, nil +} diff --git a/pkg/shell/plugins/writefile.go b/pkg/shell/plugins/writefile.go new file mode 100644 index 000000000..358c6b1d6 --- /dev/null +++ b/pkg/shell/plugins/writefile.go @@ -0,0 +1,79 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "context" + "errors" + "fmt" + "io" + "os" + "path/filepath" + "strings" + + "github.com/spf13/pflag" + + "github.com/elastic/elastic-package/pkg/shell" +) + +var _ shell.Command = writefileCmd{} + +type writefileCmd struct{} + +func (writefileCmd) Usage() string { + return "write-file --path path --contents contents" +} + +func (writefileCmd) Desc() string { + return "Writes a file in each of the packages in context 'Shell.Packages'." +} + +func (writefileCmd) Flags() *pflag.FlagSet { + flags := pflag.NewFlagSet("", pflag.ContinueOnError) + flags.String("path", "", "Path to the file (relative to the package root).") + flags.String("contents", "", "Contents of the file") + return flags +} + +func (writefileCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { + packages, ok := ctx.Value(ctxKeyPackages).([]string) + if !ok { + fmt.Fprintln(stderr, "no packages found in the context") + return ctx, nil + } + for _, pkg := range packages { + packageRoot := pkg + // check if we are in packages folder + if _, err := os.Stat(filepath.Join(".", pkg)); err != nil { + // check if we are in integrations root folder + packageRoot = filepath.Join(".", "packages", pkg) + if _, err := os.Stat(packageRoot); err != nil { + return ctx, errors.New("you need to be in intgerations root folder or in the packages folder") + } + } + + path, _ := flags.GetString("path") + path = filepath.Join(packageRoot, path) + + contents, _ := flags.GetString("contents") + + if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { + return ctx, err + } + + f, err := os.Create(path) + if err != nil { + return ctx, err + } + + if _, err := f.WriteString(strings.ReplaceAll(contents, `\n`, "\n")); err != nil { + f.Close() + return ctx, err + } + + f.Close() + } + return ctx, nil +} diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go new file mode 100644 index 000000000..c4f00296d --- /dev/null +++ b/pkg/shell/shell.go @@ -0,0 +1,119 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package shell + +import ( + "context" + "fmt" + "io" + "os" + "path/filepath" + "plugin" + + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/elastic/elastic-package/internal/configuration/locations" + "github.com/elastic/elastic-package/internal/logger" +) + +var ( + commands = []Command{} + + // globalCtx is updated through all the run time of the shell and + // it is used to pass information between plugins + globalCtx = context.Background() +) + +type Command interface { + // Usage is the one-line usage message. + // Recommended syntax is as follows: + // [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required. + // ... indicates that you can specify multiple values for the previous argument. + // | indicates mutually exclusive information. You can use the argument to the left of the separator or the + // argument to the right of the separator. You cannot use both arguments in a single use of the command. + // { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are + // optional, they are enclosed in brackets ([ ]). + // Example: add [-F file | -D dir]... [-f format] profile + Usage() string + Desc() string + Flags() *pflag.FlagSet + Exec(ctx context.Context, flags *pflag.FlagSet, args []string, stdout, stderr io.Writer) (context.Context, error) +} + +type Plugin interface { + Commands() []Command +} + +func initCommands() error { + lm, err := locations.NewLocationManager() + if err != nil { + return err + } + + pluginsDir := lm.ShellPluginsDir() + entries, err := os.ReadDir(pluginsDir) + if err != nil { + return err + } + + for _, e := range entries { + if e.IsDir() || filepath.Ext(e.Name()) != ".so" { + continue + } + + pluginPath := filepath.Join(pluginsDir, e.Name()) + + p, err := plugin.Open(pluginPath) + if err != nil { + return err + } + + regSymbol, err := p.Lookup("Registry") + if err != nil { + return err + } + + registry, ok := regSymbol.(Plugin) + if !ok { + return fmt.Errorf("registry in plugin %s does not implement the Plugin interface", pluginPath) + } + + commands = append(commands, registry.Commands()...) + } + + return nil +} + +func AttachCommands(parent *cobra.Command) { + if err := initCommands(); err != nil { + logger.Error(err) + } + for _, command := range commands { + cmd := &cobra.Command{ + Use: command.Usage(), + Short: command.Desc(), + RunE: commandRunE(command), + } + if command.Flags() != nil { + command.Flags().VisitAll(func(f *pflag.Flag) { + cmd.Flags().AddFlag(f) + }) + } + parent.AddCommand(cmd) + } +} + +func commandRunE(command Command) func(*cobra.Command, []string) error { + return func(cmd *cobra.Command, args []string) error { + flags := cmd.Flags() + ctx, err := command.Exec(globalCtx, flags, args, cmd.OutOrStdout(), cmd.OutOrStderr()) + if err != nil { + return err + } + globalCtx = ctx + return nil + } +} From 22a15b0ccf1b1b3c683d27b39eb96ac60da55f66 Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Fri, 1 Sep 2023 13:13:18 +0200 Subject: [PATCH 2/4] Use RPC plugins --- go.mod | 19 +++++ go.sum | 51 ++++++++++++ pkg/shell/commandrpc.go | 144 +++++++++++++++++++++++++++++++++ pkg/shell/errorrpc.go | 40 +++++++++ pkg/shell/pluginrpc.go | 84 +++++++++++++++++++ pkg/shell/plugins/changelog.go | 54 ++++++++----- pkg/shell/plugins/main.go | 72 +++++++++++++++++ pkg/shell/plugins/registry.go | 38 --------- pkg/shell/plugins/runscript.go | 84 +++++++++++++++++++ pkg/shell/plugins/sql.go | 94 +++++++++++---------- pkg/shell/plugins/writefile.go | 63 ++++++++------- pkg/shell/plugins/yq.go | 79 ++++++++++++++++++ pkg/shell/shell.go | 117 +++++++++++---------------- pkg/shell/writerrpc.go | 65 +++++++++++++++ 14 files changed, 806 insertions(+), 198 deletions(-) create mode 100644 pkg/shell/commandrpc.go create mode 100644 pkg/shell/errorrpc.go create mode 100644 pkg/shell/pluginrpc.go create mode 100644 pkg/shell/plugins/main.go delete mode 100644 pkg/shell/plugins/registry.go create mode 100644 pkg/shell/plugins/runscript.go create mode 100644 pkg/shell/plugins/yq.go create mode 100644 pkg/shell/writerrpc.go diff --git a/go.mod b/go.mod index acfca97f5..e011935b4 100644 --- a/go.mod +++ b/go.mod @@ -25,10 +25,12 @@ require ( github.com/google/go-github/v32 v32.1.0 github.com/google/go-querystring v1.1.0 github.com/google/uuid v1.3.1 + github.com/hashicorp/go-plugin v1.5.0 github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/magefile/mage v1.15.0 github.com/mattn/go-sqlite3 v1.14.17 github.com/mholt/archiver/v3 v3.5.1 + github.com/mikefarah/yq/v4 v4.35.1 github.com/olekukonko/tablewriter v0.0.5 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 github.com/shirou/gopsutil/v3 v3.23.9 @@ -58,7 +60,9 @@ require ( github.com/Pallinder/go-randomdata v1.2.0 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect + github.com/a8m/envsubst v1.4.2 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect + github.com/alecthomas/participle/v2 v2.0.0 // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect github.com/bitfield/gotestdox v0.2.1 // indirect @@ -68,10 +72,12 @@ require ( github.com/creasty/defaults v1.7.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/dimchansky/utfbom v1.1.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/elastic/gojsonschema v1.2.1 // indirect github.com/elastic/kbncontent v0.1.1 // indirect + github.com/elliotchance/orderedmap v1.5.0 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect @@ -87,6 +93,8 @@ require ( github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/strfmt v0.21.3 // indirect github.com/go-openapi/swag v0.22.3 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/goccy/go-yaml v1.11.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect @@ -97,11 +105,14 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-hclog v0.14.1 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect github.com/huandu/xstrings v1.4.0 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/jinzhu/copier v0.3.5 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -112,6 +123,7 @@ require ( github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect github.com/lithammer/shortuuid/v3 v3.0.7 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.7 // 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.19 // indirect @@ -119,6 +131,7 @@ require ( github.com/mattn/go-tty v0.0.3 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect @@ -129,7 +142,9 @@ require ( github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nwaples/rardecode v1.1.3 // indirect + github.com/oklog/run v1.0.0 // indirect github.com/oklog/ulid v1.3.1 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pierrec/lz4/v4 v4.1.17 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect @@ -166,9 +181,13 @@ require ( golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect + golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect + google.golang.org/grpc v1.54.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.28.3 // indirect diff --git a/go.sum b/go.sum index 3a039e18b..1b7c9955d 100644 --- a/go.sum +++ b/go.sum @@ -75,8 +75,16 @@ github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ek github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw= github.com/ProtonMail/gopenpgp/v2 v2.7.3 h1:AJu1OI/1UWVYZl6QcCLKGu9OTngS2r52618uGlje84I= github.com/ProtonMail/gopenpgp/v2 v2.7.3/go.mod h1:IhkNEDaxec6NyzSI0PlxapinnwPVIESk8/76da3Ct3g= +github.com/a8m/envsubst v1.4.2 h1:4yWIHXOLEJHQEFd4UjrWDrYeYlV7ncFWJOCBRLOZHQg= +github.com/a8m/envsubst v1.4.2/go.mod h1:MVUTQNGQ3tsjOOtKCNd+fl8RzhsXcDvvAEzkhGtlsbY= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= +github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= +github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g= +github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y= +github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= +github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= @@ -95,6 +103,8 @@ github.com/boumenot/gocover-cobertura v1.2.0 h1:g+VROIASoEHBrEilIyaCmgo7HGm+AV5y github.com/boumenot/gocover-cobertura v1.2.0/go.mod h1:fz7ly8dslE42VRR5ZWLt2OHGDHjkTiA2oNvKgJEjLT0= github.com/brianstrauch/cobra-shell v0.4.0 h1:oPWTBqPPbE8Vd/i3WRvQd8XWTrevIwR0bFBIS7X6gWk= github.com/brianstrauch/cobra-shell v0.4.0/go.mod h1:QkRKnD1+MfpITTqYDE8Yp8zALgsHdeYur/qAw4kNr8c= +github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= @@ -127,6 +137,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs 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/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= +github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY= @@ -152,6 +164,8 @@ github.com/elastic/package-spec/v3 v3.0.0 h1:t4domWWtALwms0pnWKHLceNY5LZe2EKPgRz github.com/elastic/package-spec/v3 v3.0.0/go.mod h1:proxSLyZsrgNOnWMqg01ROXcnU8b8DRa0OiY4T/dN90= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/elliotchance/orderedmap v1.5.0 h1:1IsExUsjv5XNBD3ZdC7jkAAqLWOOKdbPTmkHx63OsBg= +github.com/elliotchance/orderedmap v1.5.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= @@ -168,6 +182,7 @@ github.com/evanphx/json-patch/v5 v5.7.0 h1:nJqP7uwL84RJInrohHfW0Fx3awjbm8qZeFv0n github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2Wvf/TIe2xdyJxTlb6obmF18d8QdkxNDu4= github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSYXu++VVOHnXeitef/D8n/6y4QV8uLHSFXX4NeXMGc= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= @@ -208,6 +223,10 @@ github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-yaml v1.11.0 h1:n7Z+zx8S9f9KgzG6KtQKf+kwqXZlLNR2F6018Dgau54= +github.com/goccy/go-yaml v1.11.0/go.mod h1:H+mJrWtjPTJAHvRbV09MCK9xYwODM+wRTVFFTWckfng= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -304,10 +323,18 @@ github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:Fecb github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU= +github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= 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-plugin v1.5.0 h1:g6Lj3USwF5LaB8HlvCxPjN2X4nFE08ko2BJNVpl7TIE= +github.com/hashicorp/go-plugin v1.5.0/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= 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/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= +github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= @@ -324,6 +351,10 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo= github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag= +github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= +github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -363,6 +394,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= @@ -392,9 +425,13 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo= github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= +github.com/mikefarah/yq/v4 v4.35.1 h1:NTQ6CECE+9fjxPhBojdsmUvQM8YCmaZITz0+/nbWkbc= +github.com/mikefarah/yq/v4 v4.35.1/go.mod h1:KdjcC3wn+Dm9qp6A2WAKMXY6YQ3wxPvh3mj8A7NPK1E= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 h1:7GoSOOW2jpsfkntVKaS2rAr1TJqfcxotyaUcuxoZSzg= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= @@ -421,6 +458,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc= github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= @@ -431,6 +470,8 @@ github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= @@ -438,6 +479,8 @@ github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= @@ -823,6 +866,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -886,6 +931,8 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -902,6 +949,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= +google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -926,6 +975,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/hjson/hjson-go.v3 v3.0.1/go.mod h1:X6zrTSVeImfwfZLfgQdInl9mWjqPqgH90jom9nym/lw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE= +gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog= 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= diff --git a/pkg/shell/commandrpc.go b/pkg/shell/commandrpc.go new file mode 100644 index 000000000..fbe390aa4 --- /dev/null +++ b/pkg/shell/commandrpc.go @@ -0,0 +1,144 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package shell + +import ( + "errors" + "io" + "net/rpc" + + "github.com/elastic/elastic-package/internal/logger" + "github.com/hashicorp/go-plugin" +) + +type Command interface { + // Usage is the one-line usage message. + // Recommended syntax is as follows: + // [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required. + // ... indicates that you can specify multiple values for the previous argument. + // | indicates mutually exclusive information. You can use the argument to the left of the separator or the + // argument to the right of the separator. You cannot use both arguments in a single use of the command. + // { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are + // optional, they are enclosed in brackets ([ ]). + // Example: add [-F file | -D dir]... [-f format] profile + Usage() string + Name() string + Desc() string + Exec(wd string, args []string, stdout, stderr io.Writer) error +} + +type CommandRPCClient struct { + client *rpc.Client + broker *plugin.MuxBroker +} + +type ExecArgs struct { + Wd string + Args []string + Stdout, Stderr uint32 +} + +type ExecReply struct { + Err uint32 +} + +func (c *CommandRPCClient) Usage() string { + return c.getStrCall("Plugin.Usage") +} + +func (c *CommandRPCClient) Name() string { + return c.getStrCall("Plugin.Name") +} + +func (c *CommandRPCClient) Desc() string { + return c.getStrCall("Plugin.Desc") +} + +func (c *CommandRPCClient) getStrCall(method string) string { + var reply string + if err := c.client.Call(method, new(any), &reply); err != nil { + logger.Error(err) + return "" + } + return reply +} + +func (c *CommandRPCClient) Exec(wd string, args []string, stdout, stderr io.Writer) error { + stdoutServerID := c.broker.NextId() + stdoutServer := &WriterRPCServer{Impl: stdout, broker: c.broker} + go c.broker.AcceptAndServe(stdoutServerID, stdoutServer) + + stderrServerID := c.broker.NextId() + stderrServer := &WriterRPCServer{Impl: stderr, broker: c.broker} + go c.broker.AcceptAndServe(stderrServerID, stderrServer) + + var reply ExecReply + if err := c.client.Call("Plugin.Exec", ExecArgs{Wd: wd, Args: args, Stdout: stdoutServerID, Stderr: stderrServerID}, &reply); err != nil { + logger.Error(err) + return nil + } + + conn, err := c.broker.Dial(reply.Err) + if err != nil { + logger.Error(err) + return nil + } + defer conn.Close() + + client := rpc.NewClient(conn) + errClient := &ErrorRPCClient{client: client} + + if errStr := errClient.Error(); errStr != "" { + return errors.New(errStr) + } + + return nil +} + +type CommandRPCServer struct { + Impl Command + broker *plugin.MuxBroker +} + +func (s *CommandRPCServer) Usage(_ any, resp *string) error { + *resp = s.Impl.Usage() + return nil +} + +func (s *CommandRPCServer) Name(_ any, resp *string) error { + *resp = s.Impl.Name() + return nil +} + +func (s *CommandRPCServer) Desc(_ any, resp *string) error { + *resp = s.Impl.Desc() + return nil +} + +func (s *CommandRPCServer) Exec(args ExecArgs, resp *ExecReply) error { + stdoutConn, err := s.broker.Dial(args.Stdout) + if err != nil { + return err + } + defer stdoutConn.Close() + stdoutClient := rpc.NewClient(stdoutConn) + + stderrConn, err := s.broker.Dial(args.Stderr) + if err != nil { + return err + } + defer stderrConn.Close() + stderrClient := rpc.NewClient(stderrConn) + + execErr := s.Impl.Exec(args.Wd, args.Args, &WriterRPCClient{client: stdoutClient, broker: s.broker}, &WriterRPCClient{client: stderrClient, broker: s.broker}) + + serverID := s.broker.NextId() + server := &ErrorRPCServer{Impl: execErr} + go s.broker.AcceptAndServe(serverID, server) + + resp.Err = serverID + + return nil +} diff --git a/pkg/shell/errorrpc.go b/pkg/shell/errorrpc.go new file mode 100644 index 000000000..4dd5ce865 --- /dev/null +++ b/pkg/shell/errorrpc.go @@ -0,0 +1,40 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package shell + +import ( + "net/rpc" + + "github.com/elastic/elastic-package/internal/logger" +) + +type ErrorRPCClient struct { + client *rpc.Client +} + +type ErrorReply struct { + Err string +} + +func (c *ErrorRPCClient) Error() string { + var reply ErrorReply + if err := c.client.Call("Plugin.Error", new(any), &reply); err != nil { + logger.Error(err) + return "" + } + return reply.Err +} + +type ErrorRPCServer struct { + Impl error +} + +func (s *ErrorRPCServer) Error(_ any, resp *ErrorReply) error { + if s.Impl == nil { + return nil + } + resp.Err = s.Impl.Error() + return nil +} diff --git a/pkg/shell/pluginrpc.go b/pkg/shell/pluginrpc.go new file mode 100644 index 000000000..e77864be9 --- /dev/null +++ b/pkg/shell/pluginrpc.go @@ -0,0 +1,84 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package shell + +import ( + "net/rpc" + + "github.com/elastic/elastic-package/internal/logger" + "github.com/hashicorp/go-plugin" +) + +type Plugin interface { + Commands() map[string]Command +} + +type ShellPlugin struct { + Impl Plugin +} + +func (ShellPlugin) Client(broker *plugin.MuxBroker, c *rpc.Client) (interface{}, error) { + return &ShellPluginRPCClient{ + client: c, + broker: broker, + }, nil +} + +func (p *ShellPlugin) Server(broker *plugin.MuxBroker) (interface{}, error) { + return &ShellPluginRPCServer{ + Impl: p.Impl, + broker: broker, + }, nil +} + +type ShellPluginRPCClient struct { + client *rpc.Client + broker *plugin.MuxBroker +} + +type CommandsReply struct { + M map[string]uint32 +} + +func (c *ShellPluginRPCClient) Commands() map[string]Command { + reply := CommandsReply{M: map[string]uint32{}} + if err := c.client.Call("Plugin.Commands", new(any), &reply); err != nil { + logger.Error(err) + return nil + } + + m := map[string]Command{} + + for k, sid := range reply.M { + conn, err := c.broker.Dial(sid) + if err != nil { + logger.Error(err) + return nil + } + client := rpc.NewClient(conn) + m[k] = &CommandRPCClient{client: client, broker: c.broker} + } + + return m +} + +type ShellPluginRPCServer struct { + Impl Plugin + broker *plugin.MuxBroker +} + +func (s *ShellPluginRPCServer) Commands(_ any, resp *CommandsReply) error { + commands := s.Impl.Commands() + if resp.M == nil { + resp.M = map[string]uint32{} + } + for k, c := range commands { + serverID := s.broker.NextId() + server := &CommandRPCServer{Impl: c, broker: s.broker} + resp.M[k] = serverID + go s.broker.AcceptAndServe(serverID, server) + } + return nil +} diff --git a/pkg/shell/plugins/changelog.go b/pkg/shell/plugins/changelog.go index 37eeff69c..3342e8c2f 100644 --- a/pkg/shell/plugins/changelog.go +++ b/pkg/shell/plugins/changelog.go @@ -5,7 +5,6 @@ package main import ( - "context" "errors" "fmt" "io" @@ -21,48 +20,59 @@ import ( "github.com/elastic/elastic-package/pkg/shell" ) -var _ shell.Command = changelogCmd{} +var _ shell.Command = &changelogCmd{} -type changelogCmd struct{} - -func (changelogCmd) Usage() string { - return "changelog --next {major|minor|patch} --description desc --type {bugfix|enhancement|breaking-change} --link link" -} - -func (changelogCmd) Desc() string { - return "Add an entry to the changelog file in each of the packages in context 'Shell.Packages'." +type changelogCmd struct { + p *Plugin + name, usage, desc string + flags *pflag.FlagSet } -func (changelogCmd) Flags() *pflag.FlagSet { +func registerChangelogCmd(p *Plugin) { flags := pflag.NewFlagSet("", pflag.ContinueOnError) flags.String(cobraext.ChangelogAddNextFlagName, "", cobraext.ChangelogAddNextFlagDescription) flags.String(cobraext.ChangelogAddDescriptionFlagName, "", cobraext.ChangelogAddDescriptionFlagDescription) flags.String(cobraext.ChangelogAddTypeFlagName, "", cobraext.ChangelogAddTypeFlagDescription) flags.String(cobraext.ChangelogAddLinkFlagName, "", cobraext.ChangelogAddLinkFlagDescription) - return flags + cmd := &changelogCmd{ + p: p, + name: "changelog", + usage: "changelog --next {major|minor|patch} --description desc --type {bugfix|enhancement|breaking-change} --link link", + desc: "Add an entry to the changelog file in each of the packages in context 'Shell.Packages'.", + flags: flags, + } + p.RegisterCommand(cmd) } -func (changelogCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { - packages, ok := ctx.Value(ctxKeyPackages).([]string) +func (c *changelogCmd) Name() string { return c.name } +func (c *changelogCmd) Usage() string { return c.usage } +func (c *changelogCmd) Desc() string { return c.desc } + +func (c *changelogCmd) Exec(wd string, args []string, _, _ io.Writer) error { + packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) if !ok { - fmt.Fprintln(stderr, "no packages found in the context") - return ctx, nil + return errors.New("no packages found in the context") } + + if err := c.flags.Parse(args); err != nil { + return err + } + for _, pkg := range packages { packageRoot := pkg // check if we are in packages folder - if _, err := os.Stat(filepath.Join(".", pkg)); err != nil { + if _, err := os.Stat(filepath.Join(wd, pkg)); err != nil { // check if we are in integrations root folder - packageRoot = filepath.Join(".", "packages", pkg) + packageRoot = filepath.Join(wd, "packages", pkg) if _, err := os.Stat(packageRoot); err != nil { - return ctx, errors.New("you need to be in intgerations root folder or in the packages folder") + return errors.New("you need to be in integrations root folder or in the packages folder") } } - if err := changelogAddCmdForRoot(packageRoot, flags, args); err != nil { - return ctx, err + if err := changelogAddCmdForRoot(packageRoot, c.flags, args); err != nil { + return err } } - return ctx, nil + return nil } func changelogAddCmdForRoot(packageRoot string, flags *pflag.FlagSet, args []string) error { diff --git a/pkg/shell/plugins/main.go b/pkg/shell/plugins/main.go new file mode 100644 index 000000000..a8197cd97 --- /dev/null +++ b/pkg/shell/plugins/main.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "sync" + + "github.com/elastic/elastic-package/pkg/shell" + "github.com/hashicorp/go-plugin" +) + +type ctxKey string + +const ( + ctxKeyPackages ctxKey = "Shell.Packages" + ctxKeyDB ctxKey = "Shell.DB" +) + +type Plugin struct { + m sync.Mutex + cmds map[string]shell.Command + ctx context.Context +} + +func NewPlugin() *Plugin { + return &Plugin{ + cmds: map[string]shell.Command{}, + ctx: context.Background(), + } +} + +func (p *Plugin) Commands() map[string]shell.Command { + return p.cmds +} + +func (p *Plugin) AddValueToCtx(k, v any) { + p.m.Lock() + p.ctx = context.WithValue(p.ctx, k, v) + p.m.Unlock() +} + +func (p *Plugin) GetValueFromCtx(k any) any { + p.m.Lock() + defer p.m.Unlock() + return p.ctx.Value(k) +} + +func (p *Plugin) RegisterCommand(cmd shell.Command) { + p.m.Lock() + p.cmds[cmd.Name()] = cmd + p.m.Unlock() +} + +func main() { + p := NewPlugin() + + registerChangelogCmd(p) + registerInitdbCmd(p) + registerWhereCmd(p) + registerWritefileCmd(p) + registerRunscriptCmd(p) + registerYqCmd(p) + + // pluginMap is the map of plugins we can dispense. + pluginMap := map[string]plugin.Plugin{ + "shell_plugin": &shell.ShellPlugin{Impl: p}, + } + + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: shell.Handshake(), + Plugins: pluginMap, + }) +} diff --git a/pkg/shell/plugins/registry.go b/pkg/shell/plugins/registry.go deleted file mode 100644 index e330a86f6..000000000 --- a/pkg/shell/plugins/registry.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package main - -import ( - "github.com/elastic/elastic-package/pkg/shell" -) - -func init() { - Registry.commands = append( - []shell.Command{}, - changelogCmd{}, - writefileCmd{}, - whereCmd{}, - initdbCmd{}, - ) -} - -type ctxKey string - -const ( - ctxKeyPackages ctxKey = "Shell.Packages" - ctxKeyDB ctxKey = "Shell.DB" -) - -var Registry = registry{} - -var _ shell.Plugin = registry{} - -type registry struct { - commands []shell.Command -} - -func (r registry) Commands() []shell.Command { - return r.commands -} diff --git a/pkg/shell/plugins/runscript.go b/pkg/shell/plugins/runscript.go new file mode 100644 index 000000000..49708ea35 --- /dev/null +++ b/pkg/shell/plugins/runscript.go @@ -0,0 +1,84 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "errors" + "fmt" + "io" + "os" + "os/exec" + "path/filepath" + + "github.com/spf13/pflag" + + "github.com/elastic/elastic-package/pkg/shell" +) + +var _ shell.Command = &runscriptCmd{} + +type runscriptCmd struct { + p *Plugin + flags *pflag.FlagSet + name, usage, desc string +} + +func registerRunscriptCmd(p *Plugin) { + flags := pflag.NewFlagSet("", pflag.ContinueOnError) + flags.String("path", "", "Path to the script file.") + cmd := &runscriptCmd{ + p: p, + flags: flags, + name: "run-script", + usage: "run-script --path path [args...]", + desc: "Runs a script for each of the packages in context 'Shell.Packages'. The package dir will be the first argument and the provided args will go next.", + } + p.RegisterCommand(cmd) +} + +func (c *runscriptCmd) Name() string { return c.name } +func (c *runscriptCmd) Usage() string { return c.usage } +func (c *runscriptCmd) Desc() string { return c.desc } + +func (c *runscriptCmd) Exec(wd string, args []string, stdout, stderr io.Writer) error { + packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) + if !ok { + return errors.New("no packages found in the context") + } + + if err := c.flags.Parse(args); err != nil { + return err + } + + path, _ := c.flags.GetString("path") + + if !filepath.IsAbs(path) { + path = filepath.Clean(filepath.Join(wd, path)) + } + + if _, err := os.Stat(path); err != nil { + return fmt.Errorf("script not found at %s", path) + } + + for _, pkg := range packages { + packageRoot := filepath.Join(wd, pkg) + // check if we are in packages folder + if _, err := os.Stat(packageRoot); err != nil { + // check if we are in integrations root folder + packageRoot = filepath.Join(wd, "packages", pkg) + if _, err := os.Stat(packageRoot); err != nil { + return errors.New("you need to be in integrations root folder or in the packages folder") + } + } + cmd := exec.Command(path, append([]string{packageRoot}, args...)...) + cmd.Stdout = stdout + cmd.Stderr = stderr + if err := cmd.Run(); err != nil { + fmt.Fprintln(stderr, err) + } + } + + return nil +} diff --git a/pkg/shell/plugins/sql.go b/pkg/shell/plugins/sql.go index 0aacc75e0..12b411e4f 100644 --- a/pkg/shell/plugins/sql.go +++ b/pkg/shell/plugins/sql.go @@ -5,7 +5,6 @@ package main import ( - "context" "database/sql" "encoding/json" "errors" @@ -16,7 +15,6 @@ import ( "strings" _ "github.com/mattn/go-sqlite3" - "github.com/spf13/pflag" "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/pkg/shell" @@ -27,26 +25,31 @@ const ( insertPackageQuery = "INSERT INTO `packages` (`name`, `manifest`) VALUES (?,?)" ) -var _ shell.Command = whereCmd{} +var _ shell.Command = &whereCmd{} -type whereCmd struct{} - -func (whereCmd) Usage() string { - return `where "query"` +type whereCmd struct { + p *Plugin + name, usage, desc string } -func (whereCmd) Desc() string { - return "Select a list of packages based on some conditions. Reads from context 'Shell.DB' and updates context 'Shell.Packages'." +func registerWhereCmd(p *Plugin) { + cmd := &whereCmd{ + p: p, + name: "where", + usage: `where "query"`, + desc: "Select a list of packages based on some conditions. Reads from context 'Shell.DB' and updates context 'Shell.Packages'.", + } + p.RegisterCommand(cmd) } -func (whereCmd) Flags() *pflag.FlagSet { - return nil -} +func (c *whereCmd) Name() string { return c.name } +func (c *whereCmd) Usage() string { return c.usage } +func (c *whereCmd) Desc() string { return c.desc } -func (whereCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { - db, ok := ctx.Value(ctxKeyDB).(*sql.DB) +func (c *whereCmd) Exec(wd string, args []string, _, stderr io.Writer) error { + db, ok := c.p.GetValueFromCtx(ctxKeyDB).(*sql.DB) if !ok { - return ctx, errors.New("db connection not found in context") + return errors.New("db connection not found in context") } conditions := strings.Join(args, " ") query := `SELECT name FROM packages` @@ -56,7 +59,7 @@ func (whereCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _ rows, err := db.Query(query) if err != nil { - return nil, err + return err } defer rows.Close() @@ -64,55 +67,60 @@ func (whereCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _ var pkg string for rows.Next() { if err := rows.Scan(&pkg); err != nil { - return nil, err + return err } pkgs = append(pkgs, pkg) } - ctx = context.WithValue(ctx, ctxKeyPackages, pkgs) + c.p.AddValueToCtx(ctxKeyPackages, pkgs) fmt.Fprintf(stderr, "Found %d packages\n", len(pkgs)) - return ctx, nil + return nil } -var _ shell.Command = initdbCmd{} +var _ shell.Command = &initdbCmd{} -type initdbCmd struct{} - -func (initdbCmd) Usage() string { - return "initdb" +type initdbCmd struct { + p *Plugin + name, usage, desc string } -func (initdbCmd) Desc() string { - return "Initializes the packages database. Sets context 'Shell.DB'." +func registerInitdbCmd(p *Plugin) { + cmd := &initdbCmd{ + p: p, + name: "initdb", + usage: "initdb", + desc: "Initializes the packages database. Sets context 'Shell.DB'.", + } + p.RegisterCommand(cmd) } -func (initdbCmd) Flags() *pflag.FlagSet { - return nil -} +func (c *initdbCmd) Name() string { return c.name } +func (c *initdbCmd) Usage() string { return c.usage } +func (c *initdbCmd) Desc() string { return c.desc } -func (initdbCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { +func (c *initdbCmd) Exec(wd string, args []string, _, stderr io.Writer) error { fmt.Fprintln(stderr, "Initializing database...") db, err := sql.Open("sqlite3", ":memory:") if err != nil { - return ctx, err + return err } if _, err := db.Exec(createPackagesQuery); err != nil { - return ctx, err + return err } - packagesPath := filepath.Join(".", "packages") + packagesPath := filepath.Join(wd, "packages") if _, err := os.Stat(packagesPath); err != nil { - return ctx, err + return err } entries, err := os.ReadDir(packagesPath) if err != nil { - return ctx, err + return err } - var c int + var count int for _, e := range entries { if !e.IsDir() || strings.HasPrefix(e.Name(), ".") { continue @@ -120,21 +128,21 @@ func (initdbCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, root := filepath.Join(packagesPath, e.Name()) manifest, err := packages.ReadPackageManifestFromPackageRoot(root) if err != nil { - return ctx, err + return err } p, err := json.Marshal(manifest) if err != nil { - return ctx, err + return err } if _, err := db.Exec(insertPackageQuery, e.Name(), string(p)); err != nil { - return ctx, err + return err } - c++ + count++ } - fmt.Fprintf(stderr, "Loaded %d packages\n", c) + fmt.Fprintf(stderr, "Loaded %d packages\n", count) - ctx = context.WithValue(ctx, ctxKeyDB, db) + c.p.AddValueToCtx(ctxKeyDB, db) - return ctx, nil + return nil } diff --git a/pkg/shell/plugins/writefile.go b/pkg/shell/plugins/writefile.go index 358c6b1d6..c05da2da9 100644 --- a/pkg/shell/plugins/writefile.go +++ b/pkg/shell/plugins/writefile.go @@ -5,9 +5,7 @@ package main import ( - "context" "errors" - "fmt" "io" "os" "path/filepath" @@ -18,62 +16,73 @@ import ( "github.com/elastic/elastic-package/pkg/shell" ) -var _ shell.Command = writefileCmd{} +var _ shell.Command = &writefileCmd{} -type writefileCmd struct{} - -func (writefileCmd) Usage() string { - return "write-file --path path --contents contents" -} - -func (writefileCmd) Desc() string { - return "Writes a file in each of the packages in context 'Shell.Packages'." +type writefileCmd struct { + p *Plugin + flags *pflag.FlagSet + name, usage, desc string } -func (writefileCmd) Flags() *pflag.FlagSet { +func registerWritefileCmd(p *Plugin) { flags := pflag.NewFlagSet("", pflag.ContinueOnError) flags.String("path", "", "Path to the file (relative to the package root).") flags.String("contents", "", "Contents of the file") - return flags + cmd := &writefileCmd{ + p: p, + flags: flags, + name: "write-file", + usage: "write-file --path path --contents contents", + desc: "Writes a file in each of the packages in context 'Shell.Packages'.", + } + p.RegisterCommand(cmd) } -func (writefileCmd) Exec(ctx context.Context, flags *pflag.FlagSet, args []string, _, stderr io.Writer) (context.Context, error) { - packages, ok := ctx.Value(ctxKeyPackages).([]string) +func (c *writefileCmd) Name() string { return c.name } +func (c *writefileCmd) Usage() string { return c.usage } +func (c *writefileCmd) Desc() string { return c.desc } + +func (c *writefileCmd) Exec(wd string, args []string, _, _ io.Writer) error { + packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) if !ok { - fmt.Fprintln(stderr, "no packages found in the context") - return ctx, nil + return errors.New("no packages found in the context") + } + + if err := c.flags.Parse(args); err != nil { + return err } + for _, pkg := range packages { - packageRoot := pkg + packageRoot := filepath.Join(wd, pkg) // check if we are in packages folder - if _, err := os.Stat(filepath.Join(".", pkg)); err != nil { + if _, err := os.Stat(packageRoot); err != nil { // check if we are in integrations root folder - packageRoot = filepath.Join(".", "packages", pkg) + packageRoot = filepath.Join(wd, "packages", pkg) if _, err := os.Stat(packageRoot); err != nil { - return ctx, errors.New("you need to be in intgerations root folder or in the packages folder") + return errors.New("you need to be in integrations root folder or in the packages folder") } } - path, _ := flags.GetString("path") + path, _ := c.flags.GetString("path") path = filepath.Join(packageRoot, path) - contents, _ := flags.GetString("contents") + contents, _ := c.flags.GetString("contents") if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { - return ctx, err + return err } f, err := os.Create(path) if err != nil { - return ctx, err + return err } if _, err := f.WriteString(strings.ReplaceAll(contents, `\n`, "\n")); err != nil { f.Close() - return ctx, err + return err } f.Close() } - return ctx, nil + return nil } diff --git a/pkg/shell/plugins/yq.go b/pkg/shell/plugins/yq.go new file mode 100644 index 000000000..4d1a3aab0 --- /dev/null +++ b/pkg/shell/plugins/yq.go @@ -0,0 +1,79 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package main + +import ( + "errors" + "io" + "os" + "path/filepath" + + "github.com/elastic/elastic-package/pkg/shell" + + yqcmd "github.com/mikefarah/yq/v4/cmd" +) + +var _ shell.Command = &yqCmd{} + +type yqCmd struct { + p *Plugin + name, usage, desc string +} + +func registerYqCmd(p *Plugin) { + cmd := &yqCmd{ + p: p, + name: "yq", + usage: "yq is a lightweight and portable command-line YAML processor.", + desc: "Runs the yq command for each of the packages in context 'Shell.Packages'. See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.", + } + p.RegisterCommand(cmd) +} + +func (c *yqCmd) Name() string { return c.name } +func (c *yqCmd) Usage() string { return c.usage } +func (c *yqCmd) Desc() string { return c.desc } + +func (c *yqCmd) Exec(wd string, args []string, stdout, stderr io.Writer) error { + packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) + if !ok { + return errors.New("no packages found in the context") + } + + cmd := yqcmd.New() + + cmd.SetErr(stderr) + cmd.SetOut(stdout) + cmd.SetArgs(args) + + wdbak, err := os.Getwd() + if err != nil { + return err + } + defer os.Chdir(wdbak) + + for _, pkg := range packages { + packageRoot := filepath.Join(wd, pkg) + // check if we are in packages folder + if _, err := os.Stat(packageRoot); err != nil { + // check if we are in integrations root folder + packageRoot = filepath.Join(wd, "packages", pkg) + if _, err := os.Stat(packageRoot); err != nil { + return errors.New("you need to be in integrations root folder or in the packages folder") + } + } + + if err := os.Chdir(packageRoot); err != nil { + return err + } + + if err := cmd.Execute(); err != nil { + // no need to return, yq will output to stderr + return nil + } + } + + return nil +} diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go index c4f00296d..84c54e07d 100644 --- a/pkg/shell/shell.go +++ b/pkg/shell/shell.go @@ -5,102 +5,79 @@ package shell import ( - "context" - "fmt" - "io" "os" + "os/exec" "path/filepath" - "plugin" - - "github.com/spf13/cobra" - "github.com/spf13/pflag" "github.com/elastic/elastic-package/internal/configuration/locations" "github.com/elastic/elastic-package/internal/logger" + "github.com/hashicorp/go-plugin" + "github.com/spf13/cobra" ) -var ( - commands = []Command{} - - // globalCtx is updated through all the run time of the shell and - // it is used to pass information between plugins - globalCtx = context.Background() -) - -type Command interface { - // Usage is the one-line usage message. - // Recommended syntax is as follows: - // [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required. - // ... indicates that you can specify multiple values for the previous argument. - // | indicates mutually exclusive information. You can use the argument to the left of the separator or the - // argument to the right of the separator. You cannot use both arguments in a single use of the command. - // { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are - // optional, they are enclosed in brackets ([ ]). - // Example: add [-F file | -D dir]... [-f format] profile - Usage() string - Desc() string - Flags() *pflag.FlagSet - Exec(ctx context.Context, flags *pflag.FlagSet, args []string, stdout, stderr io.Writer) (context.Context, error) -} - -type Plugin interface { - Commands() []Command -} - -func initCommands() error { +func initCommands() (map[string]Command, error) { lm, err := locations.NewLocationManager() if err != nil { - return err + return nil, err } pluginsDir := lm.ShellPluginsDir() entries, err := os.ReadDir(pluginsDir) if err != nil { - return err + return nil, err + } + + pluginMap := map[string]plugin.Plugin{ + "shell_plugin": &ShellPlugin{}, } + m := map[string]Command{} for _, e := range entries { - if e.IsDir() || filepath.Ext(e.Name()) != ".so" { + if e.IsDir() { continue } - pluginPath := filepath.Join(pluginsDir, e.Name()) - - p, err := plugin.Open(pluginPath) + client := plugin.NewClient(&plugin.ClientConfig{ + HandshakeConfig: Handshake(), + Plugins: pluginMap, + Cmd: exec.Command(pluginPath), + }) + + // Connect via RPC + rpcClient, err := client.Client() if err != nil { - return err + return nil, err } - regSymbol, err := p.Lookup("Registry") + // Request the plugin + raw, err := rpcClient.Dispense("shell_plugin") if err != nil { - return err + return nil, err } - registry, ok := regSymbol.(Plugin) - if !ok { - return fmt.Errorf("registry in plugin %s does not implement the Plugin interface", pluginPath) + // Obtain the interface implementation we can use to + // interact with the plugin. + shellPlugin := raw.(Plugin) + for k, v := range shellPlugin.Commands() { + m[k] = v } - - commands = append(commands, registry.Commands()...) } - - return nil + return m, nil } func AttachCommands(parent *cobra.Command) { - if err := initCommands(); err != nil { + commands, err := initCommands() + if err != nil { logger.Error(err) + return } for _, command := range commands { cmd := &cobra.Command{ - Use: command.Usage(), - Short: command.Desc(), - RunE: commandRunE(command), - } - if command.Flags() != nil { - command.Flags().VisitAll(func(f *pflag.Flag) { - cmd.Flags().AddFlag(f) - }) + Use: command.Usage(), + Short: command.Desc(), + RunE: commandRunE(command), + DisableFlagParsing: true, + DisableFlagsInUseLine: true, } parent.AddCommand(cmd) } @@ -108,12 +85,16 @@ func AttachCommands(parent *cobra.Command) { func commandRunE(command Command) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { - flags := cmd.Flags() - ctx, err := command.Exec(globalCtx, flags, args, cmd.OutOrStdout(), cmd.OutOrStderr()) - if err != nil { - return err - } - globalCtx = ctx - return nil + wd, _ := os.Getwd() + return command.Exec(wd, args, cmd.OutOrStdout(), cmd.OutOrStderr()) + } +} + +// Handshake is a common handshake that is shared by plugin and host. +func Handshake() plugin.HandshakeConfig { + return plugin.HandshakeConfig{ + ProtocolVersion: 1, + MagicCookieKey: "SHELL_PLUGIN", + MagicCookieValue: "2a28a2da-7812-467c-b65b-d3a996f2e692", } } diff --git a/pkg/shell/writerrpc.go b/pkg/shell/writerrpc.go new file mode 100644 index 000000000..7e07ea981 --- /dev/null +++ b/pkg/shell/writerrpc.go @@ -0,0 +1,65 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package shell + +import ( + "errors" + "io" + "net/rpc" + + "github.com/elastic/elastic-package/internal/logger" + "github.com/hashicorp/go-plugin" +) + +type WriterRPCClient struct { + client *rpc.Client + broker *plugin.MuxBroker +} + +type WriteReply struct { + N int + Err uint32 +} + +func (c *WriterRPCClient) Write(p []byte) (int, error) { + var reply WriteReply + if err := c.client.Call("Plugin.Write", p, &reply); err != nil { + logger.Error(err) + return 0, nil + } + + conn, err := c.broker.Dial(reply.Err) + if err != nil { + logger.Error(err) + return 0, nil + } + defer conn.Close() + + client := rpc.NewClient(conn) + errClient := &ErrorRPCClient{client: client} + + if errStr := errClient.Error(); errStr != "" { + return reply.N, errors.New(errStr) + } + + return reply.N, nil +} + +type WriterRPCServer struct { + Impl io.Writer + broker *plugin.MuxBroker +} + +func (s *WriterRPCServer) Write(p []byte, resp *WriteReply) error { + n, writeErr := s.Impl.Write(p) + + serverID := s.broker.NextId() + server := &ErrorRPCServer{Impl: writeErr} + go s.broker.AcceptAndServe(serverID, server) + + resp.N = n + resp.Err = serverID + return nil +} From 9a0ac97b0d1facfa4eaeae5e8e1bd8bf6b30cf8b Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Mon, 4 Sep 2023 12:00:57 +0200 Subject: [PATCH 3/4] Delete commands --- pkg/shell/plugins/changelog.go | 176 --------------------------------- pkg/shell/plugins/main.go | 72 -------------- pkg/shell/plugins/runscript.go | 84 ---------------- pkg/shell/plugins/sql.go | 148 --------------------------- pkg/shell/plugins/writefile.go | 88 ----------------- 5 files changed, 568 deletions(-) delete mode 100644 pkg/shell/plugins/changelog.go delete mode 100644 pkg/shell/plugins/main.go delete mode 100644 pkg/shell/plugins/runscript.go delete mode 100644 pkg/shell/plugins/sql.go delete mode 100644 pkg/shell/plugins/writefile.go diff --git a/pkg/shell/plugins/changelog.go b/pkg/shell/plugins/changelog.go deleted file mode 100644 index 3342e8c2f..000000000 --- a/pkg/shell/plugins/changelog.go +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package main - -import ( - "errors" - "fmt" - "io" - "os" - "path/filepath" - - "github.com/Masterminds/semver/v3" - "github.com/spf13/pflag" - - "github.com/elastic/elastic-package/internal/cobraext" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/changelog" - "github.com/elastic/elastic-package/pkg/shell" -) - -var _ shell.Command = &changelogCmd{} - -type changelogCmd struct { - p *Plugin - name, usage, desc string - flags *pflag.FlagSet -} - -func registerChangelogCmd(p *Plugin) { - flags := pflag.NewFlagSet("", pflag.ContinueOnError) - flags.String(cobraext.ChangelogAddNextFlagName, "", cobraext.ChangelogAddNextFlagDescription) - flags.String(cobraext.ChangelogAddDescriptionFlagName, "", cobraext.ChangelogAddDescriptionFlagDescription) - flags.String(cobraext.ChangelogAddTypeFlagName, "", cobraext.ChangelogAddTypeFlagDescription) - flags.String(cobraext.ChangelogAddLinkFlagName, "", cobraext.ChangelogAddLinkFlagDescription) - cmd := &changelogCmd{ - p: p, - name: "changelog", - usage: "changelog --next {major|minor|patch} --description desc --type {bugfix|enhancement|breaking-change} --link link", - desc: "Add an entry to the changelog file in each of the packages in context 'Shell.Packages'.", - flags: flags, - } - p.RegisterCommand(cmd) -} - -func (c *changelogCmd) Name() string { return c.name } -func (c *changelogCmd) Usage() string { return c.usage } -func (c *changelogCmd) Desc() string { return c.desc } - -func (c *changelogCmd) Exec(wd string, args []string, _, _ io.Writer) error { - packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) - if !ok { - return errors.New("no packages found in the context") - } - - if err := c.flags.Parse(args); err != nil { - return err - } - - for _, pkg := range packages { - packageRoot := pkg - // check if we are in packages folder - if _, err := os.Stat(filepath.Join(wd, pkg)); err != nil { - // check if we are in integrations root folder - packageRoot = filepath.Join(wd, "packages", pkg) - if _, err := os.Stat(packageRoot); err != nil { - return errors.New("you need to be in integrations root folder or in the packages folder") - } - } - if err := changelogAddCmdForRoot(packageRoot, c.flags, args); err != nil { - return err - } - } - return nil -} - -func changelogAddCmdForRoot(packageRoot string, flags *pflag.FlagSet, args []string) error { - nextMode, _ := flags.GetString(cobraext.ChangelogAddNextFlagName) - v, err := changelogCmdVersion(nextMode, packageRoot) - if err != nil { - return err - } - version := v.String() - - description, _ := flags.GetString(cobraext.ChangelogAddDescriptionFlagName) - changeType, _ := flags.GetString(cobraext.ChangelogAddTypeFlagName) - link, _ := flags.GetString(cobraext.ChangelogAddLinkFlagName) - - entry := changelog.Revision{ - Version: version, - Changes: []changelog.Entry{ - { - Description: description, - Type: changeType, - Link: link, - }, - }, - } - - if err := patchChangelogFile(packageRoot, entry); err != nil { - return err - } - - if err := setManifestVersion(packageRoot, version); err != nil { - return err - } - - return nil -} - -func changelogCmdVersion(nextMode, packageRoot string) (*semver.Version, error) { - revisions, err := changelog.ReadChangelogFromPackageRoot(packageRoot) - if err != nil { - return nil, fmt.Errorf("failed to read current changelog: %w", err) - } - if len(revisions) == 0 { - return semver.MustParse("0.0.0"), nil - } - - version, err := semver.NewVersion(revisions[0].Version) - if err != nil { - return nil, fmt.Errorf("invalid version in changelog %q: %w", revisions[0].Version, err) - } - - switch nextMode { - case "": - break - case "major": - v := version.IncMajor() - version = &v - case "minor": - v := version.IncMinor() - version = &v - case "patch": - v := version.IncPatch() - version = &v - default: - return nil, fmt.Errorf("invalid value for %q: %s", - cobraext.ChangelogAddNextFlagName, nextMode) - } - - return version, nil -} - -// patchChangelogFile looks for the proper place to add the new revision in the changelog, -// trying to conserve original format and comments. -func patchChangelogFile(packageRoot string, patch changelog.Revision) error { - changelogPath := filepath.Join(packageRoot, changelog.PackageChangelogFile) - d, err := os.ReadFile(changelogPath) - if err != nil { - return err - } - - d, err = changelog.PatchYAML(d, patch) - if err != nil { - return err - } - - return os.WriteFile(changelogPath, d, 0644) -} - -func setManifestVersion(packageRoot string, version string) error { - manifestPath := filepath.Join(packageRoot, packages.PackageManifestFile) - d, err := os.ReadFile(manifestPath) - if err != nil { - return err - } - - d, err = changelog.SetManifestVersion(d, version) - if err != nil { - return err - } - - return os.WriteFile(manifestPath, d, 0644) -} diff --git a/pkg/shell/plugins/main.go b/pkg/shell/plugins/main.go deleted file mode 100644 index a8197cd97..000000000 --- a/pkg/shell/plugins/main.go +++ /dev/null @@ -1,72 +0,0 @@ -package main - -import ( - "context" - "sync" - - "github.com/elastic/elastic-package/pkg/shell" - "github.com/hashicorp/go-plugin" -) - -type ctxKey string - -const ( - ctxKeyPackages ctxKey = "Shell.Packages" - ctxKeyDB ctxKey = "Shell.DB" -) - -type Plugin struct { - m sync.Mutex - cmds map[string]shell.Command - ctx context.Context -} - -func NewPlugin() *Plugin { - return &Plugin{ - cmds: map[string]shell.Command{}, - ctx: context.Background(), - } -} - -func (p *Plugin) Commands() map[string]shell.Command { - return p.cmds -} - -func (p *Plugin) AddValueToCtx(k, v any) { - p.m.Lock() - p.ctx = context.WithValue(p.ctx, k, v) - p.m.Unlock() -} - -func (p *Plugin) GetValueFromCtx(k any) any { - p.m.Lock() - defer p.m.Unlock() - return p.ctx.Value(k) -} - -func (p *Plugin) RegisterCommand(cmd shell.Command) { - p.m.Lock() - p.cmds[cmd.Name()] = cmd - p.m.Unlock() -} - -func main() { - p := NewPlugin() - - registerChangelogCmd(p) - registerInitdbCmd(p) - registerWhereCmd(p) - registerWritefileCmd(p) - registerRunscriptCmd(p) - registerYqCmd(p) - - // pluginMap is the map of plugins we can dispense. - pluginMap := map[string]plugin.Plugin{ - "shell_plugin": &shell.ShellPlugin{Impl: p}, - } - - plugin.Serve(&plugin.ServeConfig{ - HandshakeConfig: shell.Handshake(), - Plugins: pluginMap, - }) -} diff --git a/pkg/shell/plugins/runscript.go b/pkg/shell/plugins/runscript.go deleted file mode 100644 index 49708ea35..000000000 --- a/pkg/shell/plugins/runscript.go +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package main - -import ( - "errors" - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - - "github.com/spf13/pflag" - - "github.com/elastic/elastic-package/pkg/shell" -) - -var _ shell.Command = &runscriptCmd{} - -type runscriptCmd struct { - p *Plugin - flags *pflag.FlagSet - name, usage, desc string -} - -func registerRunscriptCmd(p *Plugin) { - flags := pflag.NewFlagSet("", pflag.ContinueOnError) - flags.String("path", "", "Path to the script file.") - cmd := &runscriptCmd{ - p: p, - flags: flags, - name: "run-script", - usage: "run-script --path path [args...]", - desc: "Runs a script for each of the packages in context 'Shell.Packages'. The package dir will be the first argument and the provided args will go next.", - } - p.RegisterCommand(cmd) -} - -func (c *runscriptCmd) Name() string { return c.name } -func (c *runscriptCmd) Usage() string { return c.usage } -func (c *runscriptCmd) Desc() string { return c.desc } - -func (c *runscriptCmd) Exec(wd string, args []string, stdout, stderr io.Writer) error { - packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) - if !ok { - return errors.New("no packages found in the context") - } - - if err := c.flags.Parse(args); err != nil { - return err - } - - path, _ := c.flags.GetString("path") - - if !filepath.IsAbs(path) { - path = filepath.Clean(filepath.Join(wd, path)) - } - - if _, err := os.Stat(path); err != nil { - return fmt.Errorf("script not found at %s", path) - } - - for _, pkg := range packages { - packageRoot := filepath.Join(wd, pkg) - // check if we are in packages folder - if _, err := os.Stat(packageRoot); err != nil { - // check if we are in integrations root folder - packageRoot = filepath.Join(wd, "packages", pkg) - if _, err := os.Stat(packageRoot); err != nil { - return errors.New("you need to be in integrations root folder or in the packages folder") - } - } - cmd := exec.Command(path, append([]string{packageRoot}, args...)...) - cmd.Stdout = stdout - cmd.Stderr = stderr - if err := cmd.Run(); err != nil { - fmt.Fprintln(stderr, err) - } - } - - return nil -} diff --git a/pkg/shell/plugins/sql.go b/pkg/shell/plugins/sql.go deleted file mode 100644 index 12b411e4f..000000000 --- a/pkg/shell/plugins/sql.go +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package main - -import ( - "database/sql" - "encoding/json" - "errors" - "fmt" - "io" - "os" - "path/filepath" - "strings" - - _ "github.com/mattn/go-sqlite3" - - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/pkg/shell" -) - -const ( - createPackagesQuery = "CREATE TABLE `packages` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(256) NOT NULL, `manifest` TEXT NOT NULL)" - insertPackageQuery = "INSERT INTO `packages` (`name`, `manifest`) VALUES (?,?)" -) - -var _ shell.Command = &whereCmd{} - -type whereCmd struct { - p *Plugin - name, usage, desc string -} - -func registerWhereCmd(p *Plugin) { - cmd := &whereCmd{ - p: p, - name: "where", - usage: `where "query"`, - desc: "Select a list of packages based on some conditions. Reads from context 'Shell.DB' and updates context 'Shell.Packages'.", - } - p.RegisterCommand(cmd) -} - -func (c *whereCmd) Name() string { return c.name } -func (c *whereCmd) Usage() string { return c.usage } -func (c *whereCmd) Desc() string { return c.desc } - -func (c *whereCmd) Exec(wd string, args []string, _, stderr io.Writer) error { - db, ok := c.p.GetValueFromCtx(ctxKeyDB).(*sql.DB) - if !ok { - return errors.New("db connection not found in context") - } - conditions := strings.Join(args, " ") - query := `SELECT name FROM packages` - if conditions != "" { - query = fmt.Sprintf("%s WHERE %s", query, conditions) - } - - rows, err := db.Query(query) - if err != nil { - return err - } - defer rows.Close() - - var pkgs []string - var pkg string - for rows.Next() { - if err := rows.Scan(&pkg); err != nil { - return err - } - pkgs = append(pkgs, pkg) - } - - c.p.AddValueToCtx(ctxKeyPackages, pkgs) - fmt.Fprintf(stderr, "Found %d packages\n", len(pkgs)) - return nil -} - -var _ shell.Command = &initdbCmd{} - -type initdbCmd struct { - p *Plugin - name, usage, desc string -} - -func registerInitdbCmd(p *Plugin) { - cmd := &initdbCmd{ - p: p, - name: "initdb", - usage: "initdb", - desc: "Initializes the packages database. Sets context 'Shell.DB'.", - } - p.RegisterCommand(cmd) -} - -func (c *initdbCmd) Name() string { return c.name } -func (c *initdbCmd) Usage() string { return c.usage } -func (c *initdbCmd) Desc() string { return c.desc } - -func (c *initdbCmd) Exec(wd string, args []string, _, stderr io.Writer) error { - fmt.Fprintln(stderr, "Initializing database...") - - db, err := sql.Open("sqlite3", ":memory:") - if err != nil { - return err - } - - if _, err := db.Exec(createPackagesQuery); err != nil { - return err - } - - packagesPath := filepath.Join(wd, "packages") - if _, err := os.Stat(packagesPath); err != nil { - return err - } - - entries, err := os.ReadDir(packagesPath) - if err != nil { - return err - } - - var count int - for _, e := range entries { - if !e.IsDir() || strings.HasPrefix(e.Name(), ".") { - continue - } - root := filepath.Join(packagesPath, e.Name()) - manifest, err := packages.ReadPackageManifestFromPackageRoot(root) - if err != nil { - return err - } - p, err := json.Marshal(manifest) - if err != nil { - return err - } - if _, err := db.Exec(insertPackageQuery, e.Name(), string(p)); err != nil { - return err - } - count++ - } - - fmt.Fprintf(stderr, "Loaded %d packages\n", count) - - c.p.AddValueToCtx(ctxKeyDB, db) - - return nil -} diff --git a/pkg/shell/plugins/writefile.go b/pkg/shell/plugins/writefile.go deleted file mode 100644 index c05da2da9..000000000 --- a/pkg/shell/plugins/writefile.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package main - -import ( - "errors" - "io" - "os" - "path/filepath" - "strings" - - "github.com/spf13/pflag" - - "github.com/elastic/elastic-package/pkg/shell" -) - -var _ shell.Command = &writefileCmd{} - -type writefileCmd struct { - p *Plugin - flags *pflag.FlagSet - name, usage, desc string -} - -func registerWritefileCmd(p *Plugin) { - flags := pflag.NewFlagSet("", pflag.ContinueOnError) - flags.String("path", "", "Path to the file (relative to the package root).") - flags.String("contents", "", "Contents of the file") - cmd := &writefileCmd{ - p: p, - flags: flags, - name: "write-file", - usage: "write-file --path path --contents contents", - desc: "Writes a file in each of the packages in context 'Shell.Packages'.", - } - p.RegisterCommand(cmd) -} - -func (c *writefileCmd) Name() string { return c.name } -func (c *writefileCmd) Usage() string { return c.usage } -func (c *writefileCmd) Desc() string { return c.desc } - -func (c *writefileCmd) Exec(wd string, args []string, _, _ io.Writer) error { - packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) - if !ok { - return errors.New("no packages found in the context") - } - - if err := c.flags.Parse(args); err != nil { - return err - } - - for _, pkg := range packages { - packageRoot := filepath.Join(wd, pkg) - // check if we are in packages folder - if _, err := os.Stat(packageRoot); err != nil { - // check if we are in integrations root folder - packageRoot = filepath.Join(wd, "packages", pkg) - if _, err := os.Stat(packageRoot); err != nil { - return errors.New("you need to be in integrations root folder or in the packages folder") - } - } - - path, _ := c.flags.GetString("path") - path = filepath.Join(packageRoot, path) - - contents, _ := c.flags.GetString("contents") - - if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { - return err - } - - f, err := os.Create(path) - if err != nil { - return err - } - - if _, err := f.WriteString(strings.ReplaceAll(contents, `\n`, "\n")); err != nil { - f.Close() - return err - } - - f.Close() - } - return nil -} From ce00f4b977a4e4aa511db5635ca6bfbbac783a41 Mon Sep 17 00:00:00 2001 From: Marc Guasch Date: Mon, 4 Sep 2023 12:01:10 +0200 Subject: [PATCH 4/4] Move internal/packages to pkg/packages so it can be imported --- cmd/benchmark.go | 2 +- cmd/build.go | 2 +- cmd/changelog.go | 4 +- cmd/create_data_stream.go | 4 +- cmd/create_package.go | 4 +- cmd/format.go | 2 +- cmd/install.go | 4 +- cmd/lint.go | 2 +- cmd/service.go | 2 +- cmd/status.go | 6 +- cmd/status_test.go | 6 +- cmd/testrunner.go | 2 +- cmd/uninstall.go | 4 +- go.mod | 15 +--- go.sum | 34 -------- .../benchrunner/runners/pipeline/runner.go | 2 +- internal/benchrunner/runners/system/runner.go | 2 +- internal/builder/dynamic_mappings.go | 4 +- internal/builder/external_fields.go | 4 +- internal/builder/packages.go | 2 +- internal/cleanup/build.go | 2 +- internal/cleanup/stack.go | 2 +- internal/docs/readme.go | 2 +- internal/docs/readme_test.go | 2 +- internal/docs/sample_event.go | 2 +- internal/elasticsearch/ingest/datastream.go | 2 +- internal/export/dashboards.go | 2 +- internal/fields/dependency_manager.go | 2 +- internal/fields/dependency_manager_test.go | 2 +- internal/fields/validate.go | 4 +- internal/formatter/formatter.go | 2 +- internal/kibana/packages.go | 2 +- internal/kibana/policies.go | 2 +- internal/registry/revisions.go | 2 +- internal/testrunner/runners/asset/runner.go | 4 +- .../testrunner/runners/pipeline/coverage.go | 2 +- .../testrunner/runners/pipeline/runner.go | 2 +- internal/testrunner/runners/static/runner.go | 2 +- internal/testrunner/runners/system/runner.go | 4 +- .../testrunner/runners/system/runner_test.go | 2 +- .../_static/dataStream-agent-stream.yml.tmpl | 0 ...eam-elasticsearch-ingest-pipeline.yml.tmpl | 0 .../_static/dataStream-manifest.yml.tmpl | 0 .../archetype/_static/fields-base.yml.tmpl | 0 .../input-package-agent-config.yml.tmpl | 0 .../_static/package-changelog.yml.tmpl | 0 .../_static/package-docs-readme.md.tmpl | 0 .../_static/package-manifest.yml.tmpl | 0 .../packages/archetype/_static/sampleIcon.svg | 0 .../_static/sampleScreenshot.png.b64 | 0 .../packages/archetype/archetype.go | 0 .../packages/archetype/data_stream.go | 2 +- .../packages/archetype/data_stream_test.go | 2 +- .../packages/archetype/package.go | 2 +- .../packages/archetype/package_test.go | 2 +- .../packages/archetype/resources.go | 0 {internal => pkg}/packages/archetype/spec.go | 0 {internal => pkg}/packages/assets.go | 0 .../packages/buildmanifest/build_manifest.go | 0 .../packages/changelog/changelog.go | 0 .../testdata/changelog-one-patch-multiple.yml | 0 .../changelog-one-patch-next-major.yml | 0 .../changelog-one-patch-same-version.yml | 0 .../changelog/testdata/changelog-one.yml | 0 {internal => pkg}/packages/changelog/yaml.go | 0 .../packages/changelog/yaml_test.go | 0 {internal => pkg}/packages/conditions.go | 0 {internal => pkg}/packages/conditions_test.go | 0 .../packages/installer/factory.go | 2 +- .../packages/installer/installer.go | 2 +- .../packages/installer/zip_installer.go | 2 +- {internal => pkg}/packages/packages.go | 0 {internal => pkg}/packages/packages_test.go | 0 .../packages/status/serverless.go | 0 {internal => pkg}/packages/status/status.go | 4 +- pkg/shell/commandrpc.go | 3 +- pkg/shell/pluginrpc.go | 3 +- pkg/shell/plugins/yq.go | 79 ------------------- pkg/shell/shell.go | 5 +- pkg/shell/writerrpc.go | 3 +- 80 files changed, 71 insertions(+), 193 deletions(-) rename {internal => pkg}/packages/archetype/_static/dataStream-agent-stream.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/dataStream-elasticsearch-ingest-pipeline.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/dataStream-manifest.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/fields-base.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/input-package-agent-config.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/package-changelog.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/package-docs-readme.md.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/package-manifest.yml.tmpl (100%) rename {internal => pkg}/packages/archetype/_static/sampleIcon.svg (100%) rename {internal => pkg}/packages/archetype/_static/sampleScreenshot.png.b64 (100%) rename {internal => pkg}/packages/archetype/archetype.go (100%) rename {internal => pkg}/packages/archetype/data_stream.go (97%) rename {internal => pkg}/packages/archetype/data_stream_test.go (97%) rename {internal => pkg}/packages/archetype/package.go (98%) rename {internal => pkg}/packages/archetype/package_test.go (97%) rename {internal => pkg}/packages/archetype/resources.go (100%) rename {internal => pkg}/packages/archetype/spec.go (100%) rename {internal => pkg}/packages/assets.go (100%) rename {internal => pkg}/packages/buildmanifest/build_manifest.go (100%) rename {internal => pkg}/packages/changelog/changelog.go (100%) rename {internal => pkg}/packages/changelog/testdata/changelog-one-patch-multiple.yml (100%) rename {internal => pkg}/packages/changelog/testdata/changelog-one-patch-next-major.yml (100%) rename {internal => pkg}/packages/changelog/testdata/changelog-one-patch-same-version.yml (100%) rename {internal => pkg}/packages/changelog/testdata/changelog-one.yml (100%) rename {internal => pkg}/packages/changelog/yaml.go (100%) rename {internal => pkg}/packages/changelog/yaml_test.go (100%) rename {internal => pkg}/packages/conditions.go (100%) rename {internal => pkg}/packages/conditions_test.go (100%) rename {internal => pkg}/packages/installer/factory.go (98%) rename {internal => pkg}/packages/installer/installer.go (97%) rename {internal => pkg}/packages/installer/zip_installer.go (96%) rename {internal => pkg}/packages/packages.go (100%) rename {internal => pkg}/packages/packages_test.go (100%) rename {internal => pkg}/packages/status/serverless.go (100%) rename {internal => pkg}/packages/status/status.go (95%) delete mode 100644 pkg/shell/plugins/yq.go diff --git a/cmd/benchmark.go b/cmd/benchmark.go index 7849f25a6..b9fe48acb 100644 --- a/cmd/benchmark.go +++ b/cmd/benchmark.go @@ -29,9 +29,9 @@ import ( "github.com/elastic/elastic-package/internal/benchrunner/runners/system" "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/common" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/signal" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" ) const generateLongDescription = ` diff --git a/cmd/build.go b/cmd/build.go index 00d86d329..d489e7910 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -16,7 +16,7 @@ import ( "github.com/elastic/elastic-package/internal/docs" "github.com/elastic/elastic-package/internal/files" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) const buildLongDescription = `Use this command to build a package. Currently it supports only the "integration" package type. diff --git a/cmd/changelog.go b/cmd/changelog.go index bfdf5599b..cfa729723 100644 --- a/cmd/changelog.go +++ b/cmd/changelog.go @@ -14,8 +14,8 @@ import ( "github.com/spf13/cobra" "github.com/elastic/elastic-package/internal/cobraext" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/changelog" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/changelog" ) const changelogLongDescription = `Use this command to work with the changelog of the package. diff --git a/cmd/create_data_stream.go b/cmd/create_data_stream.go index bdb389b6b..72d5952ce 100644 --- a/cmd/create_data_stream.go +++ b/cmd/create_data_stream.go @@ -12,9 +12,9 @@ import ( "github.com/spf13/cobra" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/archetype" "github.com/elastic/elastic-package/internal/surveyext" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/archetype" ) const createDataStreamLongDescription = `Use this command to create a new data stream. diff --git a/cmd/create_package.go b/cmd/create_package.go index 714709c13..800b2dd53 100644 --- a/cmd/create_package.go +++ b/cmd/create_package.go @@ -11,9 +11,9 @@ import ( "github.com/spf13/cobra" "github.com/elastic/elastic-package/internal/licenses" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/archetype" "github.com/elastic/elastic-package/internal/surveyext" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/archetype" ) const createPackageLongDescription = `Use this command to create a new package. diff --git a/cmd/format.go b/cmd/format.go index 8a654f790..39361a149 100644 --- a/cmd/format.go +++ b/cmd/format.go @@ -12,7 +12,7 @@ import ( "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/formatter" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) const formatLongDescription = `Use this command to format the package files. diff --git a/cmd/install.go b/cmd/install.go index 7dc781560..7072d9bd6 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -12,9 +12,9 @@ import ( "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/install" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/installer" "github.com/elastic/elastic-package/internal/stack" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/installer" ) const installLongDescription = `Use this command to install the package in Kibana. diff --git a/cmd/lint.go b/cmd/lint.go index a2a26025f..39977c183 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -13,8 +13,8 @@ import ( "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/docs" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/validation" + "github.com/elastic/elastic-package/pkg/packages" ) const lintLongDescription = `Use this command to validate the contents of a package using the package specification (see: https://github.com/elastic/package-spec). diff --git a/cmd/service.go b/cmd/service.go index 05c8d41a4..62d4979d5 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -13,10 +13,10 @@ import ( "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/install" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/service" "github.com/elastic/elastic-package/internal/stack" "github.com/elastic/elastic-package/internal/testrunner/runners/system" + "github.com/elastic/elastic-package/pkg/packages" ) const serviceLongDescription = `Use this command to boot up the service stack that can be observed with the package. diff --git a/cmd/status.go b/cmd/status.go index abcc6d1de..1d1f1b4bc 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -20,10 +20,10 @@ import ( "github.com/spf13/cobra" "github.com/elastic/elastic-package/internal/cobraext" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/changelog" - "github.com/elastic/elastic-package/internal/packages/status" "github.com/elastic/elastic-package/internal/registry" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/changelog" + "github.com/elastic/elastic-package/pkg/packages/status" ) const statusLongDescription = `Use this command to display the current deployment status of a package. diff --git a/cmd/status_test.go b/cmd/status_test.go index 3ad167a6c..ff4626f19 100644 --- a/cmd/status_test.go +++ b/cmd/status_test.go @@ -13,9 +13,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/changelog" - "github.com/elastic/elastic-package/internal/packages/status" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/changelog" + "github.com/elastic/elastic-package/pkg/packages/status" ) var generateFlag = flag.Bool("generate", false, "Write golden files") diff --git a/cmd/testrunner.go b/cmd/testrunner.go index c11f790e7..a35b76cb4 100644 --- a/cmd/testrunner.go +++ b/cmd/testrunner.go @@ -16,13 +16,13 @@ import ( "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/install" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/signal" "github.com/elastic/elastic-package/internal/stack" "github.com/elastic/elastic-package/internal/testrunner" "github.com/elastic/elastic-package/internal/testrunner/reporters/formats" "github.com/elastic/elastic-package/internal/testrunner/reporters/outputs" _ "github.com/elastic/elastic-package/internal/testrunner/runners" // register all test runners + "github.com/elastic/elastic-package/pkg/packages" ) const testLongDescription = `Use this command to run tests on a package. Currently, the following types of tests are available: diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 7e44522fd..928a65b5a 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -12,9 +12,9 @@ import ( "github.com/elastic/elastic-package/internal/cobraext" "github.com/elastic/elastic-package/internal/install" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/installer" "github.com/elastic/elastic-package/internal/stack" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/installer" ) const uninstallLongDescription = `Use this command to uninstall the package in Kibana. diff --git a/go.mod b/go.mod index e011935b4..5ff669edd 100644 --- a/go.mod +++ b/go.mod @@ -28,14 +28,11 @@ require ( github.com/hashicorp/go-plugin v1.5.0 github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/magefile/mage v1.15.0 - github.com/mattn/go-sqlite3 v1.14.17 github.com/mholt/archiver/v3 v3.5.1 - github.com/mikefarah/yq/v4 v4.35.1 github.com/olekukonko/tablewriter v0.0.5 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 github.com/shirou/gopsutil/v3 v3.23.9 github.com/spf13/cobra v1.7.0 - github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 golang.org/x/tools v0.14.0 gopkg.in/yaml.v3 v3.0.1 @@ -60,9 +57,7 @@ require ( github.com/Pallinder/go-randomdata v1.2.0 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect - github.com/a8m/envsubst v1.4.2 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect - github.com/alecthomas/participle/v2 v2.0.0 // indirect github.com/andybalholm/brotli v1.0.4 // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect github.com/bitfield/gotestdox v0.2.1 // indirect @@ -72,12 +67,10 @@ require ( github.com/creasty/defaults v1.7.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dimchansky/utfbom v1.1.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/elastic/gojsonschema v1.2.1 // indirect github.com/elastic/kbncontent v0.1.1 // indirect - github.com/elliotchance/orderedmap v1.5.0 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect @@ -93,8 +86,6 @@ require ( github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/strfmt v0.21.3 // indirect github.com/go-openapi/swag v0.22.3 // indirect - github.com/goccy/go-json v0.10.2 // indirect - github.com/goccy/go-yaml v1.11.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect @@ -112,7 +103,6 @@ require ( github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect - github.com/jinzhu/copier v0.3.5 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -123,7 +113,6 @@ require ( github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect github.com/lithammer/shortuuid/v3 v3.0.7 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect - github.com/magiconair/properties v1.8.7 // 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.19 // indirect @@ -144,7 +133,6 @@ require ( github.com/nwaples/rardecode v1.1.3 // indirect github.com/oklog/run v1.0.0 // indirect github.com/oklog/ulid v1.3.1 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pierrec/lz4/v4 v4.1.17 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect @@ -159,6 +147,7 @@ require ( github.com/skeema/knownhosts v1.2.0 // indirect github.com/spf13/afero v1.10.0 // indirect github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.1 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect @@ -181,13 +170,11 @@ require ( golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect google.golang.org/grpc v1.54.0 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.28.3 // indirect diff --git a/go.sum b/go.sum index 1b7c9955d..2d0500ff8 100644 --- a/go.sum +++ b/go.sum @@ -75,16 +75,8 @@ github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ek github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw= github.com/ProtonMail/gopenpgp/v2 v2.7.3 h1:AJu1OI/1UWVYZl6QcCLKGu9OTngS2r52618uGlje84I= github.com/ProtonMail/gopenpgp/v2 v2.7.3/go.mod h1:IhkNEDaxec6NyzSI0PlxapinnwPVIESk8/76da3Ct3g= -github.com/a8m/envsubst v1.4.2 h1:4yWIHXOLEJHQEFd4UjrWDrYeYlV7ncFWJOCBRLOZHQg= -github.com/a8m/envsubst v1.4.2/go.mod h1:MVUTQNGQ3tsjOOtKCNd+fl8RzhsXcDvvAEzkhGtlsbY= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= -github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= -github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= -github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g= -github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y= -github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= -github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= @@ -137,8 +129,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs 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/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= -github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY= @@ -164,8 +154,6 @@ github.com/elastic/package-spec/v3 v3.0.0 h1:t4domWWtALwms0pnWKHLceNY5LZe2EKPgRz github.com/elastic/package-spec/v3 v3.0.0/go.mod h1:proxSLyZsrgNOnWMqg01ROXcnU8b8DRa0OiY4T/dN90= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= -github.com/elliotchance/orderedmap v1.5.0 h1:1IsExUsjv5XNBD3ZdC7jkAAqLWOOKdbPTmkHx63OsBg= -github.com/elliotchance/orderedmap v1.5.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= @@ -223,10 +211,6 @@ github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/goccy/go-yaml v1.11.0 h1:n7Z+zx8S9f9KgzG6KtQKf+kwqXZlLNR2F6018Dgau54= -github.com/goccy/go-yaml v1.11.0/go.mod h1:H+mJrWtjPTJAHvRbV09MCK9xYwODM+wRTVFFTWckfng= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -333,8 +317,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= -github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= @@ -353,8 +335,6 @@ github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PH github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= -github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= -github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -394,8 +374,6 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= @@ -416,8 +394,6 @@ github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= -github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI= github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -425,8 +401,6 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo= github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= -github.com/mikefarah/yq/v4 v4.35.1 h1:NTQ6CECE+9fjxPhBojdsmUvQM8YCmaZITz0+/nbWkbc= -github.com/mikefarah/yq/v4 v4.35.1/go.mod h1:KdjcC3wn+Dm9qp6A2WAKMXY6YQ3wxPvh3mj8A7NPK1E= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= @@ -470,8 +444,6 @@ github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= @@ -479,8 +451,6 @@ github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= @@ -866,8 +836,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -975,8 +943,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/hjson/hjson-go.v3 v3.0.1/go.mod h1:X6zrTSVeImfwfZLfgQdInl9mWjqPqgH90jom9nym/lw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE= -gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog= 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= diff --git a/internal/benchrunner/runners/pipeline/runner.go b/internal/benchrunner/runners/pipeline/runner.go index e55f293e8..52eb1a4ac 100644 --- a/internal/benchrunner/runners/pipeline/runner.go +++ b/internal/benchrunner/runners/pipeline/runner.go @@ -16,8 +16,8 @@ import ( "github.com/elastic/elastic-package/internal/benchrunner" "github.com/elastic/elastic-package/internal/benchrunner/reporters" "github.com/elastic/elastic-package/internal/elasticsearch/ingest" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" ) const ( diff --git a/internal/benchrunner/runners/system/runner.go b/internal/benchrunner/runners/system/runner.go index 868463a10..3643b6830 100644 --- a/internal/benchrunner/runners/system/runner.go +++ b/internal/benchrunner/runners/system/runner.go @@ -30,9 +30,9 @@ import ( "github.com/elastic/elastic-package/internal/kibana" "github.com/elastic/elastic-package/internal/logger" "github.com/elastic/elastic-package/internal/multierror" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/servicedeployer" "github.com/elastic/elastic-package/internal/signal" + "github.com/elastic/elastic-package/pkg/packages" ) const ( diff --git a/internal/builder/dynamic_mappings.go b/internal/builder/dynamic_mappings.go index beeb9a978..5f6e57e14 100644 --- a/internal/builder/dynamic_mappings.go +++ b/internal/builder/dynamic_mappings.go @@ -18,8 +18,8 @@ import ( "github.com/elastic/elastic-package/internal/formatter" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/buildmanifest" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/buildmanifest" ) //go:embed _static/ecs_mappings.yaml diff --git a/internal/builder/external_fields.go b/internal/builder/external_fields.go index 6e505daee..e133231e3 100644 --- a/internal/builder/external_fields.go +++ b/internal/builder/external_fields.go @@ -16,8 +16,8 @@ import ( "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/fields" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/buildmanifest" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/buildmanifest" ) var semver3_0_0 = semver.MustParse("3.0.0") diff --git a/internal/builder/packages.go b/internal/builder/packages.go index 94c1b89b7..f37dbeb18 100644 --- a/internal/builder/packages.go +++ b/internal/builder/packages.go @@ -15,8 +15,8 @@ import ( "github.com/elastic/elastic-package/internal/environment" "github.com/elastic/elastic-package/internal/files" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/validation" + "github.com/elastic/elastic-package/pkg/packages" ) const builtPackagesFolder = "packages" diff --git a/internal/cleanup/build.go b/internal/cleanup/build.go index 8a55642a9..e3c7032f1 100644 --- a/internal/cleanup/build.go +++ b/internal/cleanup/build.go @@ -12,7 +12,7 @@ import ( "github.com/elastic/elastic-package/internal/builder" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // Build function removes package resources from build/. diff --git a/internal/cleanup/stack.go b/internal/cleanup/stack.go index f4844f71c..dc5c766b0 100644 --- a/internal/cleanup/stack.go +++ b/internal/cleanup/stack.go @@ -11,7 +11,7 @@ import ( "path/filepath" "github.com/elastic/elastic-package/internal/configuration/locations" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" "github.com/elastic/elastic-package/internal/logger" ) diff --git a/internal/docs/readme.go b/internal/docs/readme.go index 3b60a7197..06f6f30fe 100644 --- a/internal/docs/readme.go +++ b/internal/docs/readme.go @@ -16,7 +16,7 @@ import ( "github.com/elastic/elastic-package/internal/builder" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // ReadmeFile contains file name and status of each readme file. diff --git a/internal/docs/readme_test.go b/internal/docs/readme_test.go index f34eeb7b3..3b3026f44 100644 --- a/internal/docs/readme_test.go +++ b/internal/docs/readme_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) func TestGenerateReadme(t *testing.T) { diff --git a/internal/docs/sample_event.go b/internal/docs/sample_event.go index c67773179..6b193bac7 100644 --- a/internal/docs/sample_event.go +++ b/internal/docs/sample_event.go @@ -13,7 +13,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/elastic/elastic-package/internal/formatter" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) const sampleEventFile = "sample_event.json" diff --git a/internal/elasticsearch/ingest/datastream.go b/internal/elasticsearch/ingest/datastream.go index 732f496b3..8e02322e6 100644 --- a/internal/elasticsearch/ingest/datastream.go +++ b/internal/elasticsearch/ingest/datastream.go @@ -18,7 +18,7 @@ import ( "gopkg.in/yaml.v3" "github.com/elastic/elastic-package/internal/elasticsearch" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) var ( diff --git a/internal/export/dashboards.go b/internal/export/dashboards.go index 9cca9b216..87ac476f9 100644 --- a/internal/export/dashboards.go +++ b/internal/export/dashboards.go @@ -15,7 +15,7 @@ import ( "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/kibana" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // Dashboards method exports selected dashboards with references objects. All Kibana objects are saved to local files diff --git a/internal/fields/dependency_manager.go b/internal/fields/dependency_manager.go index f187fb6e2..a597b9020 100644 --- a/internal/fields/dependency_manager.go +++ b/internal/fields/dependency_manager.go @@ -18,7 +18,7 @@ import ( "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/configuration/locations" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages/buildmanifest" + "github.com/elastic/elastic-package/pkg/packages/buildmanifest" ) const ( diff --git a/internal/fields/dependency_manager_test.go b/internal/fields/dependency_manager_test.go index 15cc6d1ad..2c5646fe4 100644 --- a/internal/fields/dependency_manager_test.go +++ b/internal/fields/dependency_manager_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/elastic/elastic-package/internal/common" - "github.com/elastic/elastic-package/internal/packages/buildmanifest" + "github.com/elastic/elastic-package/pkg/packages/buildmanifest" ) func TestDependencyManagerInjectExternalFields(t *testing.T) { diff --git a/internal/fields/validate.go b/internal/fields/validate.go index 13ede4cfa..4a6d5e8ff 100644 --- a/internal/fields/validate.go +++ b/internal/fields/validate.go @@ -25,8 +25,8 @@ import ( "github.com/elastic/elastic-package/internal/common" "github.com/elastic/elastic-package/internal/logger" "github.com/elastic/elastic-package/internal/multierror" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/buildmanifest" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/buildmanifest" ) var ( diff --git a/internal/formatter/formatter.go b/internal/formatter/formatter.go index 97367abac..03dcf59b9 100644 --- a/internal/formatter/formatter.go +++ b/internal/formatter/formatter.go @@ -11,7 +11,7 @@ import ( "github.com/Masterminds/semver/v3" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) const ( diff --git a/internal/kibana/packages.go b/internal/kibana/packages.go index e19574249..2efdc4290 100644 --- a/internal/kibana/packages.go +++ b/internal/kibana/packages.go @@ -10,7 +10,7 @@ import ( "net/http" "os" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // InstallPackage installs the given package in Fleet. diff --git a/internal/kibana/policies.go b/internal/kibana/policies.go index 8e48019c0..b1eb8fd44 100644 --- a/internal/kibana/policies.go +++ b/internal/kibana/policies.go @@ -9,7 +9,7 @@ import ( "fmt" "net/http" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // Policy represents an Agent Policy in Fleet. diff --git a/internal/registry/revisions.go b/internal/registry/revisions.go index ac1536189..43bdc08f5 100644 --- a/internal/registry/revisions.go +++ b/internal/registry/revisions.go @@ -13,7 +13,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/google/go-querystring/query" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // SearchOptions specify the query parameters without the package name for the search API diff --git a/internal/testrunner/runners/asset/runner.go b/internal/testrunner/runners/asset/runner.go index 27ca61c03..15ac436f6 100644 --- a/internal/testrunner/runners/asset/runner.go +++ b/internal/testrunner/runners/asset/runner.go @@ -10,9 +10,9 @@ import ( "github.com/elastic/elastic-package/internal/kibana" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/installer" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/installer" ) func init() { diff --git a/internal/testrunner/runners/pipeline/coverage.go b/internal/testrunner/runners/pipeline/coverage.go index 8735f96b3..90a01b3ee 100644 --- a/internal/testrunner/runners/pipeline/coverage.go +++ b/internal/testrunner/runners/pipeline/coverage.go @@ -12,8 +12,8 @@ import ( "time" "github.com/elastic/elastic-package/internal/elasticsearch/ingest" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" ) // GetPipelineCoverage returns a coverage report for the provided set of ingest pipelines. diff --git a/internal/testrunner/runners/pipeline/runner.go b/internal/testrunner/runners/pipeline/runner.go index b4b64f474..6b3cb26bd 100644 --- a/internal/testrunner/runners/pipeline/runner.go +++ b/internal/testrunner/runners/pipeline/runner.go @@ -22,10 +22,10 @@ import ( "github.com/elastic/elastic-package/internal/fields" "github.com/elastic/elastic-package/internal/logger" "github.com/elastic/elastic-package/internal/multierror" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/signal" "github.com/elastic/elastic-package/internal/stack" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" ) const ( diff --git a/internal/testrunner/runners/static/runner.go b/internal/testrunner/runners/static/runner.go index e0bd881d3..253003389 100644 --- a/internal/testrunner/runners/static/runner.go +++ b/internal/testrunner/runners/static/runner.go @@ -12,8 +12,8 @@ import ( "github.com/elastic/elastic-package/internal/fields" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" ) const sampleEventJSON = "sample_event.json" diff --git a/internal/testrunner/runners/system/runner.go b/internal/testrunner/runners/system/runner.go index dc11de512..5ce4e20f5 100644 --- a/internal/testrunner/runners/system/runner.go +++ b/internal/testrunner/runners/system/runner.go @@ -28,12 +28,12 @@ import ( "github.com/elastic/elastic-package/internal/kibana" "github.com/elastic/elastic-package/internal/logger" "github.com/elastic/elastic-package/internal/multierror" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/installer" "github.com/elastic/elastic-package/internal/servicedeployer" "github.com/elastic/elastic-package/internal/signal" "github.com/elastic/elastic-package/internal/stack" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/installer" ) const ( diff --git a/internal/testrunner/runners/system/runner_test.go b/internal/testrunner/runners/system/runner_test.go index bbc0e1f31..79999b6f6 100644 --- a/internal/testrunner/runners/system/runner_test.go +++ b/internal/testrunner/runners/system/runner_test.go @@ -16,9 +16,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/stack" "github.com/elastic/elastic-package/internal/testrunner" + "github.com/elastic/elastic-package/pkg/packages" ) func TestFindPolicyTemplateForInput(t *testing.T) { diff --git a/internal/packages/archetype/_static/dataStream-agent-stream.yml.tmpl b/pkg/packages/archetype/_static/dataStream-agent-stream.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/dataStream-agent-stream.yml.tmpl rename to pkg/packages/archetype/_static/dataStream-agent-stream.yml.tmpl diff --git a/internal/packages/archetype/_static/dataStream-elasticsearch-ingest-pipeline.yml.tmpl b/pkg/packages/archetype/_static/dataStream-elasticsearch-ingest-pipeline.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/dataStream-elasticsearch-ingest-pipeline.yml.tmpl rename to pkg/packages/archetype/_static/dataStream-elasticsearch-ingest-pipeline.yml.tmpl diff --git a/internal/packages/archetype/_static/dataStream-manifest.yml.tmpl b/pkg/packages/archetype/_static/dataStream-manifest.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/dataStream-manifest.yml.tmpl rename to pkg/packages/archetype/_static/dataStream-manifest.yml.tmpl diff --git a/internal/packages/archetype/_static/fields-base.yml.tmpl b/pkg/packages/archetype/_static/fields-base.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/fields-base.yml.tmpl rename to pkg/packages/archetype/_static/fields-base.yml.tmpl diff --git a/internal/packages/archetype/_static/input-package-agent-config.yml.tmpl b/pkg/packages/archetype/_static/input-package-agent-config.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/input-package-agent-config.yml.tmpl rename to pkg/packages/archetype/_static/input-package-agent-config.yml.tmpl diff --git a/internal/packages/archetype/_static/package-changelog.yml.tmpl b/pkg/packages/archetype/_static/package-changelog.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/package-changelog.yml.tmpl rename to pkg/packages/archetype/_static/package-changelog.yml.tmpl diff --git a/internal/packages/archetype/_static/package-docs-readme.md.tmpl b/pkg/packages/archetype/_static/package-docs-readme.md.tmpl similarity index 100% rename from internal/packages/archetype/_static/package-docs-readme.md.tmpl rename to pkg/packages/archetype/_static/package-docs-readme.md.tmpl diff --git a/internal/packages/archetype/_static/package-manifest.yml.tmpl b/pkg/packages/archetype/_static/package-manifest.yml.tmpl similarity index 100% rename from internal/packages/archetype/_static/package-manifest.yml.tmpl rename to pkg/packages/archetype/_static/package-manifest.yml.tmpl diff --git a/internal/packages/archetype/_static/sampleIcon.svg b/pkg/packages/archetype/_static/sampleIcon.svg similarity index 100% rename from internal/packages/archetype/_static/sampleIcon.svg rename to pkg/packages/archetype/_static/sampleIcon.svg diff --git a/internal/packages/archetype/_static/sampleScreenshot.png.b64 b/pkg/packages/archetype/_static/sampleScreenshot.png.b64 similarity index 100% rename from internal/packages/archetype/_static/sampleScreenshot.png.b64 rename to pkg/packages/archetype/_static/sampleScreenshot.png.b64 diff --git a/internal/packages/archetype/archetype.go b/pkg/packages/archetype/archetype.go similarity index 100% rename from internal/packages/archetype/archetype.go rename to pkg/packages/archetype/archetype.go diff --git a/internal/packages/archetype/data_stream.go b/pkg/packages/archetype/data_stream.go similarity index 97% rename from internal/packages/archetype/data_stream.go rename to pkg/packages/archetype/data_stream.go index b6b6c9434..1501d6ed6 100644 --- a/internal/packages/archetype/data_stream.go +++ b/pkg/packages/archetype/data_stream.go @@ -11,7 +11,7 @@ import ( "github.com/elastic/elastic-package/internal/formatter" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // DataStreamDescriptor defines configurable properties of the data stream archetype diff --git a/internal/packages/archetype/data_stream_test.go b/pkg/packages/archetype/data_stream_test.go similarity index 97% rename from internal/packages/archetype/data_stream_test.go rename to pkg/packages/archetype/data_stream_test.go index c502a9a23..be42ab950 100644 --- a/internal/packages/archetype/data_stream_test.go +++ b/pkg/packages/archetype/data_stream_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) func TestDataStream(t *testing.T) { diff --git a/internal/packages/archetype/package.go b/pkg/packages/archetype/package.go similarity index 98% rename from internal/packages/archetype/package.go rename to pkg/packages/archetype/package.go index 93c84b601..3a081e062 100644 --- a/internal/packages/archetype/package.go +++ b/pkg/packages/archetype/package.go @@ -12,7 +12,7 @@ import ( "github.com/elastic/elastic-package/internal/formatter" "github.com/elastic/elastic-package/internal/licenses" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) // PackageDescriptor defines configurable properties of the package archetype diff --git a/internal/packages/archetype/package_test.go b/pkg/packages/archetype/package_test.go similarity index 97% rename from internal/packages/archetype/package_test.go rename to pkg/packages/archetype/package_test.go index 01f1a059c..dac31f3d9 100644 --- a/internal/packages/archetype/package_test.go +++ b/pkg/packages/archetype/package_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/validation" + "github.com/elastic/elastic-package/pkg/packages" ) func TestPackage(t *testing.T) { diff --git a/internal/packages/archetype/resources.go b/pkg/packages/archetype/resources.go similarity index 100% rename from internal/packages/archetype/resources.go rename to pkg/packages/archetype/resources.go diff --git a/internal/packages/archetype/spec.go b/pkg/packages/archetype/spec.go similarity index 100% rename from internal/packages/archetype/spec.go rename to pkg/packages/archetype/spec.go diff --git a/internal/packages/assets.go b/pkg/packages/assets.go similarity index 100% rename from internal/packages/assets.go rename to pkg/packages/assets.go diff --git a/internal/packages/buildmanifest/build_manifest.go b/pkg/packages/buildmanifest/build_manifest.go similarity index 100% rename from internal/packages/buildmanifest/build_manifest.go rename to pkg/packages/buildmanifest/build_manifest.go diff --git a/internal/packages/changelog/changelog.go b/pkg/packages/changelog/changelog.go similarity index 100% rename from internal/packages/changelog/changelog.go rename to pkg/packages/changelog/changelog.go diff --git a/internal/packages/changelog/testdata/changelog-one-patch-multiple.yml b/pkg/packages/changelog/testdata/changelog-one-patch-multiple.yml similarity index 100% rename from internal/packages/changelog/testdata/changelog-one-patch-multiple.yml rename to pkg/packages/changelog/testdata/changelog-one-patch-multiple.yml diff --git a/internal/packages/changelog/testdata/changelog-one-patch-next-major.yml b/pkg/packages/changelog/testdata/changelog-one-patch-next-major.yml similarity index 100% rename from internal/packages/changelog/testdata/changelog-one-patch-next-major.yml rename to pkg/packages/changelog/testdata/changelog-one-patch-next-major.yml diff --git a/internal/packages/changelog/testdata/changelog-one-patch-same-version.yml b/pkg/packages/changelog/testdata/changelog-one-patch-same-version.yml similarity index 100% rename from internal/packages/changelog/testdata/changelog-one-patch-same-version.yml rename to pkg/packages/changelog/testdata/changelog-one-patch-same-version.yml diff --git a/internal/packages/changelog/testdata/changelog-one.yml b/pkg/packages/changelog/testdata/changelog-one.yml similarity index 100% rename from internal/packages/changelog/testdata/changelog-one.yml rename to pkg/packages/changelog/testdata/changelog-one.yml diff --git a/internal/packages/changelog/yaml.go b/pkg/packages/changelog/yaml.go similarity index 100% rename from internal/packages/changelog/yaml.go rename to pkg/packages/changelog/yaml.go diff --git a/internal/packages/changelog/yaml_test.go b/pkg/packages/changelog/yaml_test.go similarity index 100% rename from internal/packages/changelog/yaml_test.go rename to pkg/packages/changelog/yaml_test.go diff --git a/internal/packages/conditions.go b/pkg/packages/conditions.go similarity index 100% rename from internal/packages/conditions.go rename to pkg/packages/conditions.go diff --git a/internal/packages/conditions_test.go b/pkg/packages/conditions_test.go similarity index 100% rename from internal/packages/conditions_test.go rename to pkg/packages/conditions_test.go diff --git a/internal/packages/installer/factory.go b/pkg/packages/installer/factory.go similarity index 98% rename from internal/packages/installer/factory.go rename to pkg/packages/installer/factory.go index 5309438d2..fa0dc583a 100644 --- a/internal/packages/installer/factory.go +++ b/pkg/packages/installer/factory.go @@ -13,8 +13,8 @@ import ( "github.com/elastic/elastic-package/internal/builder" "github.com/elastic/elastic-package/internal/kibana" "github.com/elastic/elastic-package/internal/logger" - "github.com/elastic/elastic-package/internal/packages" "github.com/elastic/elastic-package/internal/validation" + "github.com/elastic/elastic-package/pkg/packages" ) var semver8_7_0 = semver.MustParse("8.7.0") diff --git a/internal/packages/installer/installer.go b/pkg/packages/installer/installer.go similarity index 97% rename from internal/packages/installer/installer.go rename to pkg/packages/installer/installer.go index dcf90ec73..52db73260 100644 --- a/internal/packages/installer/installer.go +++ b/pkg/packages/installer/installer.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/elastic/elastic-package/internal/kibana" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) type manifestInstaller struct { diff --git a/internal/packages/installer/zip_installer.go b/pkg/packages/installer/zip_installer.go similarity index 96% rename from internal/packages/installer/zip_installer.go rename to pkg/packages/installer/zip_installer.go index df062bfcc..723e1ca9d 100644 --- a/internal/packages/installer/zip_installer.go +++ b/pkg/packages/installer/zip_installer.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/elastic/elastic-package/internal/kibana" - "github.com/elastic/elastic-package/internal/packages" + "github.com/elastic/elastic-package/pkg/packages" ) type zipInstaller struct { diff --git a/internal/packages/packages.go b/pkg/packages/packages.go similarity index 100% rename from internal/packages/packages.go rename to pkg/packages/packages.go diff --git a/internal/packages/packages_test.go b/pkg/packages/packages_test.go similarity index 100% rename from internal/packages/packages_test.go rename to pkg/packages/packages_test.go diff --git a/internal/packages/status/serverless.go b/pkg/packages/status/serverless.go similarity index 100% rename from internal/packages/status/serverless.go rename to pkg/packages/status/serverless.go diff --git a/internal/packages/status/status.go b/pkg/packages/status/status.go similarity index 95% rename from internal/packages/status/status.go rename to pkg/packages/status/status.go index 2626b021d..bc63ac546 100644 --- a/internal/packages/status/status.go +++ b/pkg/packages/status/status.go @@ -9,9 +9,9 @@ import ( "github.com/Masterminds/semver/v3" - "github.com/elastic/elastic-package/internal/packages" - "github.com/elastic/elastic-package/internal/packages/changelog" "github.com/elastic/elastic-package/internal/registry" + "github.com/elastic/elastic-package/pkg/packages" + "github.com/elastic/elastic-package/pkg/packages/changelog" ) // PackageStatus holds version and deployment information about a package diff --git a/pkg/shell/commandrpc.go b/pkg/shell/commandrpc.go index fbe390aa4..4f60410eb 100644 --- a/pkg/shell/commandrpc.go +++ b/pkg/shell/commandrpc.go @@ -9,8 +9,9 @@ import ( "io" "net/rpc" - "github.com/elastic/elastic-package/internal/logger" "github.com/hashicorp/go-plugin" + + "github.com/elastic/elastic-package/internal/logger" ) type Command interface { diff --git a/pkg/shell/pluginrpc.go b/pkg/shell/pluginrpc.go index e77864be9..c75726072 100644 --- a/pkg/shell/pluginrpc.go +++ b/pkg/shell/pluginrpc.go @@ -7,8 +7,9 @@ package shell import ( "net/rpc" - "github.com/elastic/elastic-package/internal/logger" "github.com/hashicorp/go-plugin" + + "github.com/elastic/elastic-package/internal/logger" ) type Plugin interface { diff --git a/pkg/shell/plugins/yq.go b/pkg/shell/plugins/yq.go deleted file mode 100644 index 4d1a3aab0..000000000 --- a/pkg/shell/plugins/yq.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package main - -import ( - "errors" - "io" - "os" - "path/filepath" - - "github.com/elastic/elastic-package/pkg/shell" - - yqcmd "github.com/mikefarah/yq/v4/cmd" -) - -var _ shell.Command = &yqCmd{} - -type yqCmd struct { - p *Plugin - name, usage, desc string -} - -func registerYqCmd(p *Plugin) { - cmd := &yqCmd{ - p: p, - name: "yq", - usage: "yq is a lightweight and portable command-line YAML processor.", - desc: "Runs the yq command for each of the packages in context 'Shell.Packages'. See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.", - } - p.RegisterCommand(cmd) -} - -func (c *yqCmd) Name() string { return c.name } -func (c *yqCmd) Usage() string { return c.usage } -func (c *yqCmd) Desc() string { return c.desc } - -func (c *yqCmd) Exec(wd string, args []string, stdout, stderr io.Writer) error { - packages, ok := c.p.GetValueFromCtx(ctxKeyPackages).([]string) - if !ok { - return errors.New("no packages found in the context") - } - - cmd := yqcmd.New() - - cmd.SetErr(stderr) - cmd.SetOut(stdout) - cmd.SetArgs(args) - - wdbak, err := os.Getwd() - if err != nil { - return err - } - defer os.Chdir(wdbak) - - for _, pkg := range packages { - packageRoot := filepath.Join(wd, pkg) - // check if we are in packages folder - if _, err := os.Stat(packageRoot); err != nil { - // check if we are in integrations root folder - packageRoot = filepath.Join(wd, "packages", pkg) - if _, err := os.Stat(packageRoot); err != nil { - return errors.New("you need to be in integrations root folder or in the packages folder") - } - } - - if err := os.Chdir(packageRoot); err != nil { - return err - } - - if err := cmd.Execute(); err != nil { - // no need to return, yq will output to stderr - return nil - } - } - - return nil -} diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go index 84c54e07d..f09523a7c 100644 --- a/pkg/shell/shell.go +++ b/pkg/shell/shell.go @@ -9,10 +9,11 @@ import ( "os/exec" "path/filepath" - "github.com/elastic/elastic-package/internal/configuration/locations" - "github.com/elastic/elastic-package/internal/logger" "github.com/hashicorp/go-plugin" "github.com/spf13/cobra" + + "github.com/elastic/elastic-package/internal/configuration/locations" + "github.com/elastic/elastic-package/internal/logger" ) func initCommands() (map[string]Command, error) { diff --git a/pkg/shell/writerrpc.go b/pkg/shell/writerrpc.go index 7e07ea981..4d34a9b9f 100644 --- a/pkg/shell/writerrpc.go +++ b/pkg/shell/writerrpc.go @@ -9,8 +9,9 @@ import ( "io" "net/rpc" - "github.com/elastic/elastic-package/internal/logger" "github.com/hashicorp/go-plugin" + + "github.com/elastic/elastic-package/internal/logger" ) type WriterRPCClient struct {