Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap errors and fix some docs typo and convention #743

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/pkg/agent/application/info/agent_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func getInfoFromStore(s ioStore, logLevel string) (*persistentAgentInfo, error)
agentConfigFile := paths.AgentConfigFile()
reader, err := s.Load()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to load from ioStore: %w", err)
}

// reader is closed by this function
Expand Down Expand Up @@ -195,20 +195,20 @@ func loadAgentInfo(forceUpdate bool, logLevel string, createAgentID bool) (*pers
agentConfigFile := paths.AgentConfigFile()
diskStore := storage.NewEncryptedDiskStore(agentConfigFile)

agentinfo, err := getInfoFromStore(diskStore, logLevel)
agentInfo, err := getInfoFromStore(diskStore, logLevel)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get agent info from store: %w", err)
}

if agentinfo != nil && !forceUpdate && (agentinfo.ID != "" || !createAgentID) {
return agentinfo, nil
if agentInfo != nil && !forceUpdate && (agentInfo.ID != "" || !createAgentID) {
return agentInfo, nil
}

if err := updateID(agentinfo, diskStore); err != nil {
return nil, err
if err := updateID(agentInfo, diskStore); err != nil {
return nil, fmt.Errorf("could not update agent ID on disk store: %w", err)
}

return agentinfo, nil
return agentInfo, nil
}

func updateID(agentInfo *persistentAgentInfo, s ioStore) error {
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/agent/application/info/agent_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"runtime"
"strings"

"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/release"
"github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo/types"

"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/release"
)

// ECSMeta is a collection of agent related metadata in ECS compliant object form.
Expand Down Expand Up @@ -123,7 +124,7 @@ const (
func Metadata() (*ECSMeta, error) {
agentInfo, err := NewAgentInfo(false)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create new agent info: %w", err)
}

meta, err := agentInfo.ECSMetadata()
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/agent/storage/encrypted_disk_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hectane/go-acl"

"github.com/elastic/elastic-agent-libs/file"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (d *EncryptedDiskStore) ensureKey() error {
if d.key == nil {
key, err := secret.GetAgentSecret(secret.WithVaultPath(d.vaultPath))
if err != nil {
return err
return fmt.Errorf("could not get agent key: %w", err)
}
d.key = key.Value
}
Expand Down
6 changes: 4 additions & 2 deletions internal/pkg/agent/vault/vault_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ type Vault struct {
}

// New initializes the vault store
// Call Close when done to release the resouces
// Call Close when done to release the resources
func New(name string, opts ...OptionFunc) (*Vault, error) {
var keychain C.SecKeychainRef

err := statusToError(C.OpenKeychain(keychain))
if err != nil {
return nil, err
return nil, fmt.Errorf("could not open keychain: %w", err)
}

return &Vault{
name: name,
keychain: keychain,
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/vault/vault_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func New(path string, opts ...OptionFunc) (v *Vault, err error) {
if dir == "." {
exefp, err := os.Executable()
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get executable path: %w", err)
}
dir = filepath.Dir(exefp)
path = filepath.Join(dir, path)
Expand All @@ -62,7 +62,7 @@ func New(path string, opts ...OptionFunc) (v *Vault, err error) {

key, err := getOrCreateSeed(path, options.readonly)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get seed to create new valt: %w", err)
}

return &Vault{
Expand Down