-
Notifications
You must be signed in to change notification settings - Fork 136
/
agent_version.go
109 lines (83 loc) · 3.66 KB
/
agent_version.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
100
101
102
103
104
105
106
107
108
109
package dynatrace
import (
"context"
"io"
"github.com/Dynatrace/dynatrace-operator/pkg/arch"
"github.com/pkg/errors"
)
// TODO: the `arch` params should be removed and instead always the "github.com/Dynatrace/dynatrace-operator/pkg/arch" should be used
func (dtc *dynatraceClient) GetEntityIDForIP(ctx context.Context, ip string) (string, error) {
if len(ip) == 0 {
return "", errors.New("ip is invalid")
}
hostInfo, err := dtc.getHostInfoForIP(ctx, ip)
if err != nil {
return "", err
}
if hostInfo.entityID == "" {
return "", errors.New("entity id not set for host")
}
return hostInfo.entityID, nil
}
// GetLatestAgent gets the latest agent package for the given OS and installer type.
func (dtc *dynatraceClient) GetLatestAgent(ctx context.Context, os, installerType, flavor, arch string, technologies []string, skipMetadata bool, writer io.Writer) error {
if len(os) == 0 || len(installerType) == 0 {
return errors.New("os or installerType is empty")
}
url := dtc.getLatestAgentUrl(os, installerType, flavor, arch, technologies, skipMetadata)
md5, err := dtc.makeRequestForBinary(ctx, url, dynatracePaaSToken, writer)
if err == nil {
log.Info("downloaded agent file", "os", os, "type", installerType, "flavor", flavor, "arch", arch, "technologies", technologies, "md5", md5)
}
return err
}
// GetLatestAgentVersion gets the latest agent version for the given OS and installer type configured on the Tenant.
func (dtc *dynatraceClient) GetLatestAgentVersion(ctx context.Context, os, installerType string) (string, error) {
response := struct {
LatestAgentVersion string `json:"latestAgentVersion"`
}{}
if len(os) == 0 || len(installerType) == 0 {
return "", errors.New("os or installerType is empty")
}
var flavor string
// Default installer type has no "multidistro" flavor
// so the default flavor is always needed in that case
if installerType == InstallerTypeDefault {
flavor = arch.FlavorDefault
} else {
flavor = arch.Flavor
}
url := dtc.getLatestAgentVersionUrl(os, installerType, flavor, arch.Arch)
err := dtc.makeRequestAndUnmarshal(ctx, url, dynatracePaaSToken, &response)
return response.LatestAgentVersion, errors.WithStack(err)
}
// GetAgentVersions gets available agent versions for the given OS and installer type.
func (dtc *dynatraceClient) GetAgentVersions(ctx context.Context, os, installerType, flavor, arch string) ([]string, error) {
response := struct {
AvailableVersions []string `json:"availableVersions"`
}{}
if len(os) == 0 || len(installerType) == 0 {
return nil, errors.New("os or installerType is empty")
}
url := dtc.getAgentVersionsUrl(os, installerType, flavor, arch)
err := dtc.makeRequestAndUnmarshal(ctx, url, dynatracePaaSToken, &response)
return response.AvailableVersions, errors.WithStack(err)
}
func (dtc *dynatraceClient) GetAgent(ctx context.Context, os, installerType, flavor, arch, version string, technologies []string, skipMetadata bool, writer io.Writer) error {
if len(os) == 0 || len(installerType) == 0 {
return errors.New("os or installerType is empty")
}
url := dtc.getAgentUrl(os, installerType, flavor, arch, version, technologies, skipMetadata)
md5, err := dtc.makeRequestForBinary(ctx, url, dynatracePaaSToken, writer)
if err == nil {
log.Info("downloaded agent file", "os", os, "type", installerType, "flavor", flavor, "arch", arch, "technologies", technologies, "md5", md5)
}
return err
}
func (dtc *dynatraceClient) GetAgentViaInstallerUrl(ctx context.Context, url string, writer io.Writer) error {
md5, err := dtc.makeRequestForBinary(ctx, url, installerUrlToken, writer)
if err == nil {
log.Info("downloaded agent file using given url", "url", url, "md5", md5)
}
return err
}