-
Notifications
You must be signed in to change notification settings - Fork 43
/
config.go
37 lines (30 loc) · 863 Bytes
/
config.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
package opamp
import (
"fmt"
"os"
"path/filepath"
"github.com/oklog/ulid"
"gopkg.in/yaml.v2"
)
type AgentManagerConfig struct {
ServerEndpoint string `yaml:"server_endpoint"`
ID string `yaml:"id,omitempty"`
}
func ParseAgentManagerConfig(configLocation string) (*AgentManagerConfig, error) {
data, err := os.ReadFile(filepath.Clean(configLocation))
if err != nil {
return nil, fmt.Errorf("failed to read agent manager config file: %w", err)
}
var config AgentManagerConfig
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to unmarshal file contents: %w", err)
}
if config.ServerEndpoint == "" {
return nil, fmt.Errorf("server_endpoint is required")
}
if config.ID == "" {
// generate ulid if not provided
config.ID = ulid.MustNew(ulid.Now(), nil).String()
}
return &config, nil
}