diff --git a/NOTICE.txt b/NOTICE.txt index b5df79133f70..e6ebacd0ffe4 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -25581,6 +25581,43 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-------------------------------------------------------------------------------- +Dependency : golang.org/x/term +Version: v0.24.0 +Licence type (autodetected): BSD-3-Clause +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/golang.org/x/term@v0.24.0/LICENSE: + +Copyright 2009 The Go Authors. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google LLC nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------------------------------------------------------------------------------- Dependency : golang.org/x/text Version: v0.18.0 @@ -57052,43 +57089,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------------- -Dependency : golang.org/x/term -Version: v0.24.0 -Licence type (autodetected): BSD-3-Clause --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/golang.org/x/term@v0.24.0/LICENSE: - -Copyright 2009 The Go Authors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google LLC nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -------------------------------------------------------------------------------- Dependency : golang.org/x/xerrors Version: v0.0.0-20231012003039-104605ab7028 diff --git a/go.mod b/go.mod index 75aba4602368..252fea019974 100644 --- a/go.mod +++ b/go.mod @@ -224,6 +224,7 @@ require ( go.opentelemetry.io/collector/consumer v0.109.0 go.opentelemetry.io/collector/pdata v1.15.0 go.opentelemetry.io/collector/receiver v0.109.0 + golang.org/x/term v0.24.0 google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) @@ -382,7 +383,6 @@ require ( go.opentelemetry.io/otel/trace v1.29.0 // indirect go.uber.org/ratelimit v0.3.1 // indirect golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect - golang.org/x/term v0.24.0 // indirect golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/libbeat/cfgfile/cfgfile.go b/libbeat/cfgfile/cfgfile.go index f19ecad04216..2411bc028e07 100644 --- a/libbeat/cfgfile/cfgfile.go +++ b/libbeat/cfgfile/cfgfile.go @@ -39,8 +39,6 @@ var ( defaults *config.C homePath *string configPath *string - dataPath *string - logsPath *string allowedBackwardsCompatibleFlags []string ) @@ -66,9 +64,9 @@ func Initialize() { AddAllowedBackwardsCompatibleFlag("path.home") configPath = config.ConfigOverwriteFlag(nil, overwrites, "path.config", "path.config", "", "Configuration path") AddAllowedBackwardsCompatibleFlag("path.config") - dataPath = config.ConfigOverwriteFlag(nil, overwrites, "path.data", "path.data", "", "Data path") + _ = config.ConfigOverwriteFlag(nil, overwrites, "path.data", "path.data", "", "Data path") AddAllowedBackwardsCompatibleFlag("path.data") - logsPath = config.ConfigOverwriteFlag(nil, overwrites, "path.logs", "path.logs", "", "Logs path") + _ = config.ConfigOverwriteFlag(nil, overwrites, "path.logs", "path.logs", "", "Logs path") AddAllowedBackwardsCompatibleFlag("path.logs") }) } diff --git a/libbeat/cmd/keystore.go b/libbeat/cmd/keystore.go index 34a1ccc5c220..6e895df1dcea 100644 --- a/libbeat/cmd/keystore.go +++ b/libbeat/cmd/keystore.go @@ -21,13 +21,13 @@ import ( "bufio" "errors" "fmt" - "io/ioutil" + "io" "os" "strings" "syscall" "github.com/spf13/cobra" - tml "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" @@ -39,7 +39,7 @@ import ( func getKeystore(settings instance.Settings) (keystore.Keystore, error) { b, err := instance.NewInitializedBeat(settings) if err != nil { - return nil, fmt.Errorf("error initializing beat: %s", err) + return nil, fmt.Errorf("error initializing beat: %w", err) } return b.Keystore(), nil @@ -136,27 +136,27 @@ func createKeystore(settings instance.Settings, force bool) error { writableKeystore, err := keystore.AsWritableKeystore(store) if err != nil { - return fmt.Errorf("error creating the keystore: %s", err) + return fmt.Errorf("error creating the keystore: %w", err) } - if store.IsPersisted() == true && force == false { + if store.IsPersisted() && !force { response := terminal.PromptYesNo("A keystore already exists, Overwrite?", false) - if response == true { + if response { err := writableKeystore.Create(true) if err != nil { - return fmt.Errorf("error creating the keystore: %s", err) + return fmt.Errorf("error creating the keystore: %w", err) } } else { - fmt.Println("Exiting without creating keystore.") + fmt.Printf("Exiting without creating %s keystore.", settings.Name) //nolint:forbidigo //needs refactor return nil } } else { err := writableKeystore.Create(true) if err != nil { - return fmt.Errorf("Error creating the keystore: %s", err) + return fmt.Errorf("Error creating the keystore: %w", err) } } - fmt.Printf("Created %s keystore\n", settings.Name) + fmt.Printf("Created %s keystore\n", settings.Name) //nolint:forbidigo //needs refactor return nil } @@ -171,32 +171,32 @@ func addKey(store keystore.Keystore, keys []string, force, stdin bool) error { writableKeystore, err := keystore.AsWritableKeystore(store) if err != nil { - return fmt.Errorf("error creating the keystore: %s", err) + return fmt.Errorf("error creating the keystore: %w", err) } - if store.IsPersisted() == false { - if force == false { + if !store.IsPersisted() { + if !force { answer := terminal.PromptYesNo("The keystore does not exist. Do you want to create it?", false) - if answer == false { + if !answer { return errors.New("exiting without creating keystore") } } err := writableKeystore.Create(true) if err != nil { - return fmt.Errorf("could not create keystore, error: %s", err) + return fmt.Errorf("could not create keystore, error: %w", err) } - fmt.Println("Created keystore") + fmt.Println("Created keystore") //nolint:forbidigo //needs refactor } key := strings.TrimSpace(keys[0]) - value, err := store.Retrieve(key) - if value != nil && force == false { - if stdin == true { + value, _ := store.Retrieve(key) + if value != nil && !force { + if stdin { return fmt.Errorf("the settings %s already exist in the keystore use `--force` to replace it", key) } answer := terminal.PromptYesNo(fmt.Sprintf("Setting %s already exists, Overwrite?", key), false) - if answer == false { - fmt.Println("Exiting without modifying keystore.") + if !answer { + fmt.Println("Exiting without modifying keystore.") //nolint:forbidigo //needs refactor return nil } } @@ -204,25 +204,25 @@ func addKey(store keystore.Keystore, keys []string, force, stdin bool) error { var keyValue []byte if stdin { reader := bufio.NewReader(os.Stdin) - keyValue, err = ioutil.ReadAll(reader) + keyValue, err = io.ReadAll(reader) if err != nil { return fmt.Errorf("could not read input from stdin") } } else { - fmt.Printf("Enter value for %s: ", key) - keyValue, err = tml.ReadPassword(int(syscall.Stdin)) - fmt.Println() + fmt.Printf("Enter value for %s: ", key) //nolint:forbidigo //needs refactor + keyValue, err = term.ReadPassword(int(syscall.Stdin)) + fmt.Println() //nolint:forbidigo //needs refactor if err != nil { - return fmt.Errorf("could not read value from the input, error: %s", err) + return fmt.Errorf("could not read value from the input, error: %w", err) } } if err = writableKeystore.Store(key, keyValue); err != nil { - return fmt.Errorf("could not add the key in the keystore, error: %s", err) + return fmt.Errorf("could not add the key in the keystore, error: %w", err) } if err = writableKeystore.Save(); err != nil { - return fmt.Errorf("fail to save the keystore: %s", err) + return fmt.Errorf("fail to save the keystore: %w", err) } else { - fmt.Println("Successfully updated the keystore") + fmt.Println("Successfully updated the keystore") //nolint:forbidigo //needs refactor } return nil } @@ -234,10 +234,10 @@ func removeKey(store keystore.Keystore, keys []string) error { writableKeystore, err := keystore.AsWritableKeystore(store) if err != nil { - return fmt.Errorf("error deleting the keystore: %s", err) + return fmt.Errorf("error deleting the keystore: %w", err) } - if store.IsPersisted() == false { + if !store.IsPersisted() { return errors.New("the keystore doesn't exist. Use the 'create' command to create one") } @@ -248,12 +248,12 @@ func removeKey(store keystore.Keystore, keys []string) error { return fmt.Errorf("could not find key '%v' in the keystore", key) } - writableKeystore.Delete(key) + _ = writableKeystore.Delete(key) err = writableKeystore.Save() if err != nil { - return fmt.Errorf("could not update the keystore with the changes, key: %s, error: %v", key, err) + return fmt.Errorf("could not update the keystore with the changes, key: %s, error: %w", key, err) } - fmt.Printf("successfully removed key: %s\n", key) + fmt.Printf("successfully removed key: %s\n", key) //nolint:forbidigo //needs refactor } return nil } @@ -261,14 +261,14 @@ func removeKey(store keystore.Keystore, keys []string) error { func list(store keystore.Keystore) error { listingKeystore, err := keystore.AsListingKeystore(store) if err != nil { - return fmt.Errorf("error listing the keystore: %s", err) + return fmt.Errorf("error listing the keystore: %w", err) } keys, err := listingKeystore.List() if err != nil { - return fmt.Errorf("could not read values from the keystore, error: %s", err) + return fmt.Errorf("could not read values from the keystore, error: %w", err) } for _, key := range keys { - fmt.Println(key) + fmt.Println(key) //nolint:forbidigo //needs refactor } return nil } diff --git a/x-pack/agentbeat/main_test.go b/x-pack/agentbeat/main_test.go index b03331b4b52a..0333a1ebcdf4 100644 --- a/x-pack/agentbeat/main_test.go +++ b/x-pack/agentbeat/main_test.go @@ -9,8 +9,9 @@ import ( "os" "testing" - "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/spf13/cobra" + + "github.com/elastic/beats/v7/libbeat/cfgfile" ) var (