-
Notifications
You must be signed in to change notification settings - Fork 7
/
devicemanager_script.go
106 lines (88 loc) · 2.44 KB
/
devicemanager_script.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
package fmgclient
import (
"fmt"
"github.com/fortinetdev/forti-sdk-go/fortimanager/util"
)
// JSONDVMScript contains the params for creating the script
type JSONDVMScript struct {
Name string `json:"name"`
Description string `json:"desc"`
Content string `json:"content"`
Target string `json:"target"`
Type string `json:"type"`
}
// CreateUpdateDVMScript is for creating/updating the script
// Input:
// @params: infor needed
// @method: operation method, "add" or "update"
// @adom: adom
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) CreateUpdateDVMScript(params *JSONDVMScript, method, adom string) (err error) {
defer c.Trace("CreateUpdateDVMScript")()
p := map[string]interface{}{
"data": *params,
"url": "/dvmdb/adom/" + adom + "/script",
}
_, err = c.Do(method, p)
if err != nil {
err = fmt.Errorf("CreateUpdateDVMScript failed: %s", err)
return
}
return
}
// ReadDVMScript is for reading the script infor
// Input:
// @adom: adom
// @id: script name
// Output:
// @out: script infor
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) ReadDVMScript(adom, id string) (out *JSONDVMScript, err error) {
defer c.Trace("ReadDVMScript")()
p := map[string]interface{}{
"url": "/dvmdb/adom/" + adom + "/script/" + id,
}
result, err := c.Do("get", p)
if err != nil {
err = fmt.Errorf("ReadDVMScript failed: %s", err)
return
}
data := (result["result"].([]interface{}))[0].(map[string]interface{})["data"].(map[string]interface{})
if data == nil {
err = fmt.Errorf("cannot get the results from the response")
return
}
out = &JSONDVMScript{}
if data["name"] != nil {
out.Name = data["name"].(string)
}
if data["desc"] != nil {
out.Description = data["desc"].(string)
}
if data["content"] != nil {
out.Content = data["content"].(string)
}
if data["target"] != nil {
out.Target = util.ScriptTarget2Str(int(data["target"].(float64)))
}
return
}
// DeleteDVMScript is for deleting the related script
// Input:
// @adom: adom
// @id: script name
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) DeleteDVMScript(adom, id string) (err error) {
defer c.Trace("DeleteDVMScript")()
p := map[string]interface{}{
"url": "/dvmdb/adom/" + adom + "/script/" + id,
}
_, err = c.Do("delete", p)
if err != nil {
err = fmt.Errorf("DeleteDVMScript failed: %s", err)
return
}
return
}