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/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/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/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/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/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 5ce44e1ca..5ff669edd 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 @@ -24,6 +25,7 @@ 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/mholt/archiver/v3 v3.5.1 @@ -59,6 +61,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 @@ -93,7 +96,9 @@ 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 @@ -112,8 +117,10 @@ 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-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 @@ -124,11 +131,13 @@ 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/peterbourgon/diskv v2.0.1+incompatible // indirect 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 @@ -162,6 +171,8 @@ require ( golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // 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/warnings.v0 v0.1.2 // indirect diff --git a/go.sum b/go.sum index 019a502a7..2d0500ff8 100644 --- a/go.sum +++ b/go.sum @@ -93,7 +93,13 @@ 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/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= 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= @@ -164,6 +170,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= @@ -300,10 +307,16 @@ 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/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= @@ -320,6 +333,8 @@ 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/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= @@ -364,16 +379,23 @@ 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-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= @@ -382,6 +404,8 @@ github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssn 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= @@ -408,6 +432,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= @@ -428,6 +454,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 +694,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 +714,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= @@ -866,6 +899,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= @@ -882,6 +917,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= 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/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/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/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/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 new file mode 100644 index 000000000..4f60410eb --- /dev/null +++ b/pkg/shell/commandrpc.go @@ -0,0 +1,145 @@ +// 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/hashicorp/go-plugin" + + "github.com/elastic/elastic-package/internal/logger" +) + +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..c75726072 --- /dev/null +++ b/pkg/shell/pluginrpc.go @@ -0,0 +1,85 @@ +// 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/hashicorp/go-plugin" + + "github.com/elastic/elastic-package/internal/logger" +) + +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/shell.go b/pkg/shell/shell.go new file mode 100644 index 000000000..f09523a7c --- /dev/null +++ b/pkg/shell/shell.go @@ -0,0 +1,101 @@ +// 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 ( + "os" + "os/exec" + "path/filepath" + + "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) { + lm, err := locations.NewLocationManager() + if err != nil { + return nil, err + } + + pluginsDir := lm.ShellPluginsDir() + entries, err := os.ReadDir(pluginsDir) + if err != nil { + return nil, err + } + + pluginMap := map[string]plugin.Plugin{ + "shell_plugin": &ShellPlugin{}, + } + + m := map[string]Command{} + for _, e := range entries { + if e.IsDir() { + continue + } + pluginPath := filepath.Join(pluginsDir, e.Name()) + client := plugin.NewClient(&plugin.ClientConfig{ + HandshakeConfig: Handshake(), + Plugins: pluginMap, + Cmd: exec.Command(pluginPath), + }) + + // Connect via RPC + rpcClient, err := client.Client() + if err != nil { + return nil, err + } + + // Request the plugin + raw, err := rpcClient.Dispense("shell_plugin") + if err != nil { + return nil, err + } + + // Obtain the interface implementation we can use to + // interact with the plugin. + shellPlugin := raw.(Plugin) + for k, v := range shellPlugin.Commands() { + m[k] = v + } + } + return m, nil +} + +func AttachCommands(parent *cobra.Command) { + 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), + DisableFlagParsing: true, + DisableFlagsInUseLine: true, + } + parent.AddCommand(cmd) + } +} + +func commandRunE(command Command) func(*cobra.Command, []string) error { + return func(cmd *cobra.Command, args []string) error { + 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..4d34a9b9f --- /dev/null +++ b/pkg/shell/writerrpc.go @@ -0,0 +1,66 @@ +// 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/hashicorp/go-plugin" + + "github.com/elastic/elastic-package/internal/logger" +) + +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 +}