-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathconfig.go
99 lines (79 loc) · 3.18 KB
/
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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 artifact
import (
"runtime"
"strings"
"time"
"github.com/elastic/elastic-agent-libs/transport/httpcommon"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
)
const (
darwin = "darwin"
linux = "linux"
windows = "windows"
)
// Config is a configuration used for verifier and downloader
type Config struct {
// OperatingSystem: operating system [linux, windows, darwin]
OperatingSystem string `json:"-" config:",ignore"`
// Architecture: target architecture [32, 64]
Architecture string `json:"-" config:",ignore"`
// SourceURI: source of the artifacts, e.g https://artifacts.elastic.co/downloads/
SourceURI string `json:"sourceURI" config:"sourceURI"`
// TargetDirectory: path to the directory containing downloaded packages
TargetDirectory string `json:"targetDirectory" config:"target_directory"`
// InstallPath: path to the directory containing installed packages
InstallPath string `yaml:"installPath" config:"install_path"`
// DropPath: path where elastic-agent can find installation files for download.
// Difference between this and TargetDirectory is that when fetching packages (from web or fs) they are stored in TargetDirectory
// DropPath specifies where Filesystem downloader can find packages which will then be placed in TargetDirectory. This can be
// local or network disk.
// If not provided FileSystem Downloader will fallback to /beats subfolder of elastic-agent directory.
DropPath string `yaml:"dropPath" config:"drop_path"`
httpcommon.HTTPTransportSettings `config:",inline" yaml:",inline"` // Note: use anonymous struct for json inline
}
// DefaultConfig creates a config with pre-set default values.
func DefaultConfig() *Config {
transport := httpcommon.DefaultHTTPTransportSettings()
// Elastic Agent binary is rather large and based on the network bandwidth it could take some time
// to download the full file. 10 minutes is a very large value, but we really want it to finish.
// The HTTP download will log progress in the case that it is taking a while to download.
transport.Timeout = 10 * time.Minute
return &Config{
SourceURI: "https://artifacts.elastic.co/downloads/",
TargetDirectory: paths.Downloads(),
InstallPath: paths.Install(),
HTTPTransportSettings: transport,
}
}
// OS returns the configured operating system or falls back to runtime.GOOS
func (c *Config) OS() string {
if c.OperatingSystem != "" {
return c.OperatingSystem
}
switch runtime.GOOS {
case windows:
c.OperatingSystem = windows
case darwin:
c.OperatingSystem = darwin
default:
c.OperatingSystem = linux
}
return c.OperatingSystem
}
// Arch returns the configured architecture or falls back to 32bit
func (c *Config) Arch() string {
if c.Architecture != "" {
return c.Architecture
}
arch := "32"
if strings.Contains(runtime.GOARCH, "arm64") {
arch = "arm64"
} else if strings.Contains(runtime.GOARCH, "64") {
arch = "64"
}
c.Architecture = arch
return c.Architecture
}