-
Notifications
You must be signed in to change notification settings - Fork 1
/
workloadgroups.go
99 lines (78 loc) · 3.32 KB
/
workloadgroups.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
package workloadgroups
import (
"fmt"
"strings"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/common"
)
const (
workloadGroupsEndpoint = "/workloadGroups"
)
type WorkloadGroup struct {
// A unique identifier assigned to the workload group
ID int `json:"id"`
// The name of the workload group
Name string `json:"name,omitempty"`
// The description of the workload group
Description string `json:"description,omitempty"`
// The workload group expression containing tag types, tags, and their relationships.
Expression string `json:"expression,omitempty"`
// Timestamp when the workload group was last modified
LastModifiedTime int `json:"lastModifiedTime,omitempty"`
// Information about the admin that last modified the workload group
LastModifiedBy *common.IDNameExtensions `json:"lastModifiedBy,omitempty"`
WorkloadTagExpression WorkloadTagExpression `json:"expressionJson,omitempty"`
}
// The workload group expression containing tag types, tags, and their relationships represented in a JSON format.
type WorkloadTagExpression struct {
ExpressionContainers []ExpressionContainer `json:"expressionContainers"`
}
type ExpressionContainer struct {
// The tag type selected from a predefined list
TagType string `json:"tagType,omitempty"`
// The operator (either AND or OR) used to create logical relationships among tag types
Operator string `json:"operator,omitempty"`
// Contains one or more tags and the logical operator used to combine the tags within a tag type
TagContainer TagContainer `json:"tagContainer"`
}
type TagContainer struct {
//One or more tags, each consisting of a key-value pair, selected within a tag type.
// If multiple tags are present within a tag type, they are combined using a logical operator.
// Note: A maximum of 8 tags can be added to a workload group, irrespective of the number of tag types present.
Tags []Tags `json:"tags"`
// The logical operator (either AND or OR) used to combine the tags within a tag type
Operator string `json:"operator,omitempty"`
}
// The list of tags (key-value pairs) selected within a tag type
type Tags struct {
// The key component present in the key-value pair contained in a tag
Key string `json:"key,omitempty"`
// The value component present in the key-value pair contained in a tag
Value string `json:"value,omitempty"`
}
func (service *Service) Get(workloadID int) (*WorkloadGroup, error) {
var workloadGroup WorkloadGroup
err := service.Client.Read(fmt.Sprintf("%s/%d", workloadGroupsEndpoint, workloadID), &workloadGroup)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]Returning workload group from Get: %d", workloadGroup.ID)
return &workloadGroup, nil
}
func (service *Service) GetByName(workloadName string) (*WorkloadGroup, error) {
var workloadGroups []WorkloadGroup
err := common.ReadAllPages(service.Client, workloadGroupsEndpoint, &workloadGroups)
if err != nil {
return nil, err
}
for _, workloadGroup := range workloadGroups {
if strings.EqualFold(workloadGroup.Name, workloadName) {
return &workloadGroup, nil
}
}
return nil, fmt.Errorf("no workload group found with name: %s", workloadName)
}
func (service *Service) GetAll() ([]WorkloadGroup, error) {
var workloadGroups []WorkloadGroup
err := common.ReadAllPages(service.Client, workloadGroupsEndpoint, &workloadGroups)
return workloadGroups, err
}