Skip to content

Commit

Permalink
fixes for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Oct 17, 2024
1 parent 1fb1489 commit a521b56
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 80 deletions.
74 changes: 37 additions & 37 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/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
Expand Down Expand Up @@ -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/[email protected]/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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions libbeat/cfgfile/cfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ var (
defaults *config.C
homePath *string
configPath *string
dataPath *string
logsPath *string
allowedBackwardsCompatibleFlags []string
)

Expand All @@ -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")
})
}
Expand Down
74 changes: 37 additions & 37 deletions libbeat/cmd/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -171,58 +171,58 @@ 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
}
}

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)) //nolint:unconvert //necessary on Windows

Check failure on line 213 in libbeat/cmd/keystore.go

View workflow job for this annotation

GitHub Actions / lint (windows)

directive `//nolint:unconvert //necessary on Windows` is unused for linter "unconvert" (nolintlint)
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
}
Expand All @@ -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")
}

Expand All @@ -248,27 +248,27 @@ 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
}

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
}
3 changes: 2 additions & 1 deletion x-pack/agentbeat/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit a521b56

Please sign in to comment.