-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlp_engines.go
104 lines (84 loc) · 3.09 KB
/
dlp_engines.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
package dlp_engines
import (
"errors"
"fmt"
"net/http"
"strings"
"github.com/SecurityGeekIO/zscaler-sdk-go/zia/services/common"
)
const (
dlpEnginesEndpoint = "/dlpEngines"
)
type DLPEngines struct {
// The unique identifier for the DLP engine.
ID int `json:"id"`
// The DLP engine name as configured by the admin. This attribute is required in POST and PUT requests for custom DLP engines.
Name string `json:"name,omitempty"`
// The DLP engine's description.
Description string `json:"description,omitempty"`
// The name of the predefined DLP engine.
PredefinedEngineName string `json:"predefinedEngineName,omitempty"`
// The boolean logical operator in which various DLP dictionaries are combined within a DLP engine's expression.
EngineExpression string `json:"engineExpression,omitempty"`
// Indicates whether this is a custom DLP engine. If this value is set to true, the engine is custom.
CustomDlpEngine bool `json:"customDlpEngine,omitempty"`
}
func (service *Service) Get(engineID int) (*DLPEngines, error) {
var dlpEngines DLPEngines
err := service.Client.Read(fmt.Sprintf("%s/%d", dlpEnginesEndpoint, engineID), &dlpEngines)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]Returning dlp engine from Get: %d", dlpEngines.ID)
return &dlpEngines, nil
}
func (service *Service) GetByName(engineName string) (*DLPEngines, error) {
dlpEngines, err := service.GetAll()
if err != nil {
return nil, err
}
for _, engine := range dlpEngines {
if strings.EqualFold(engine.Name, engineName) {
return &engine, nil
}
}
return nil, fmt.Errorf("no dlp engine found with name: %s", engineName)
}
func (service *Service) Create(engineID *DLPEngines) (*DLPEngines, *http.Response, error) {
resp, err := service.Client.Create(dlpEnginesEndpoint, *engineID)
if err != nil {
return nil, nil, err
}
createdDlpEngine, ok := resp.(*DLPEngines)
if !ok {
return nil, nil, errors.New("object returned from api was not a dlp engine pointer")
}
service.Client.Logger.Printf("[DEBUG]returning new dlp engine from create: %d", createdDlpEngine.ID)
return createdDlpEngine, nil, nil
}
func (service *Service) Update(engineID int, engines *DLPEngines) (*DLPEngines, *http.Response, error) {
resp, err := service.Client.UpdateWithPut(fmt.Sprintf("%s/%d", dlpEnginesEndpoint, engineID), *engines)
if err != nil {
return nil, nil, err
}
updatedDlpEngine, _ := resp.(*DLPEngines)
service.Client.Logger.Printf("[DEBUG]returning updates dlp engine from update: %d", updatedDlpEngine.ID)
return updatedDlpEngine, nil, nil
}
func (service *Service) Delete(engineID int) (*http.Response, error) {
err := service.Client.Delete(fmt.Sprintf("%s/%d", dlpEnginesEndpoint, engineID))
if err != nil {
return nil, err
}
return nil, nil
}
func (service *Service) GetAll() ([]DLPEngines, error) {
var dlpEngines []DLPEngines
err := common.ReadAllPages(service.Client, dlpEnginesEndpoint, &dlpEngines)
for i := range dlpEngines {
if dlpEngines[i].Name == "" && dlpEngines[i].PredefinedEngineName != "" {
dlpEngines[i].Name = dlpEngines[i].PredefinedEngineName
}
}
return dlpEngines, err
}