forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_windows.go
50 lines (40 loc) · 1.37 KB
/
config_windows.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
package main
import (
"fmt"
"path/filepath"
"golang.org/x/sys/windows/registry"
)
// config holds configuration options to run the service.
type config struct {
// ServicePath points to the path of the managed Grafana Agent binary.
ServicePath string
// Args holds arguments to pass to the Grafana Agent binary. os.Args[0] is
// not included.
Args []string
// WorkingDirectory points to the working directory to run the Grafana Agent
// binary from.
WorkingDirectory string
}
// loadConfig loads the config from the Windows registry.
func loadConfig() (*config, error) {
// NOTE(rfratto): the key name below shouldn't be changed without being
// able to either migrate from the old key to the new key or supporting
// both the old and the new key at the same time.
agentKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `Software\Grafana\Grafana Agent Flow`, registry.READ)
if err != nil {
return nil, fmt.Errorf("failed to open registry: %w", err)
}
servicePath, _, err := agentKey.GetStringValue("")
if err != nil {
return nil, fmt.Errorf("failed to retrieve key (Default): %w", err)
}
args, _, err := agentKey.GetStringsValue("Arguments")
if err != nil {
return nil, fmt.Errorf("failed to retrieve key Arguments: %w", err)
}
return &config{
ServicePath: servicePath,
Args: args,
WorkingDirectory: filepath.Dir(servicePath),
}, nil
}