-
Notifications
You must be signed in to change notification settings - Fork 145
/
configuration.go
63 lines (52 loc) · 1.87 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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 configuration
import (
"fmt"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
"github.com/elastic/elastic-agent/internal/pkg/config"
)
// Configuration is a overall agent configuration
type Configuration struct {
Fleet *FleetAgentConfig `config:"fleet" yaml:"fleet" json:"fleet"`
Settings *SettingsConfig `config:"agent" yaml:"agent" json:"agent"`
}
// DefaultConfiguration creates a configuration prepopulated with default values.
func DefaultConfiguration() *Configuration {
return &Configuration{
Fleet: DefaultFleetAgentConfig(),
Settings: DefaultSettingsConfig(),
}
}
// NewFromConfig creates a configuration based on common Config.
func NewFromConfig(cfg *config.Config) (*Configuration, error) {
c := DefaultConfiguration()
if err := cfg.Unpack(c); err != nil {
return nil, errors.New(err, errors.TypeConfig)
}
return c, nil
}
// NewFromFile uses unencrypted disk store to load a configuration.
func NewFromFile(path string) (*Configuration, error) {
store := storage.NewDiskStore(path)
reader, err := store.Load()
if err != nil {
return nil, errors.New(err, "could not initialize config store",
errors.TypeFilesystem,
errors.M(errors.MetaKeyPath, path))
}
config, err := config.NewConfigFrom(reader)
if err != nil {
return nil, errors.New(err,
fmt.Sprintf("fail to read configuration %s for the elastic-agent", path),
errors.TypeFilesystem,
errors.M(errors.MetaKeyPath, path))
}
return NewFromConfig(config)
}
// AgentInfo is a set of agent information.
type AgentInfo struct {
ID string `json:"id" yaml:"id" config:"id"`
}