-
Notifications
You must be signed in to change notification settings - Fork 5
/
version.go
62 lines (55 loc) · 1.67 KB
/
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
package illumioapi
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"strings"
)
// Version is the PCE version
// Versions are never created or updated
type Version struct {
Version string `json:"version"`
Build int `json:"build"`
LongDisplay string `json:"long_display"`
ShortDisplay string `json:"short_display"`
EngineeringInfo string `json:"engineering_info"`
ReleaseInfo string `json:"release_info,omitempty"`
Major int
Minor int
Patch int
}
// GetVersion returns the version of the PCE
func (p *PCE) GetVersion() (version Version, api APIResponse, err error) {
// Build the API URL
apiURL, err := url.Parse("https://" + p.cleanFQDN() + ":" + strconv.Itoa(p.Port) + "/api/v2/product_version")
if err != nil {
return Version{}, api, fmt.Errorf("get version - %s", err)
}
// Call the API
api, err = p.httpReq("GET", apiURL.String(), nil, false, map[string]string{"Content-Type": "application/json"})
if err != nil {
return Version{}, api, fmt.Errorf("get version - %s", err)
}
json.Unmarshal([]byte(api.RespBody), &version)
// Process the versions
numbers := strings.Split(version.Version, ".")
version.Major, err = strconv.Atoi(numbers[0])
if err != nil {
return Version{}, api, fmt.Errorf("calculating major - %s", err)
}
if len(numbers) > 1 {
version.Minor, err = strconv.Atoi(numbers[1])
if err != nil {
return Version{}, api, fmt.Errorf("calculating minor - %s", err)
}
}
if len(numbers) > 2 {
version.Patch, err = strconv.Atoi(numbers[2])
if err != nil {
return Version{}, api, fmt.Errorf("calculating patch - %s", err)
}
}
p.Version = version
return version, api, nil
}