-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.go
56 lines (46 loc) · 1.6 KB
/
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
package paperspace
import (
"fmt"
"time"
)
// Script is the structure of a script
type Script struct {
ID string `json:"id"`
OwnerType string `json:"ownerType"`
OwnerID string `json:"ownerId"`
Name string `json:"name"`
Description string `json:"description"`
DtCreated time.Time `json:"dtCreated"`
IsEnabled bool `json:"isEnabled"`
RunOnce bool `json:"runOnce"`
}
// CreateScriptParams are the parameters for creating a script
type CreateScriptParams struct {
RequestParams
ScriptName string `json:"scriptName"`
ScriptFile string `json:"scriptFile,omitempty"`
ScriptText string `json:"scriptText,omitempty"`
ScriptDescription string `json:"scriptDescription,omitempty"`
IsEnabled bool `json:"isEnabled,omitempty"`
RunOnce bool `json:"runOnce,omitempty"`
MachineID string `json:"machineId,omitempty"`
}
// DestroyScriptParams are the parameters for destroying a script
type DestroyScriptParams struct {
RequestParams
ScriptID string `json:"machineId,omitempty"`
}
// CreateScript creates a script
func (c Client) CreateScript(params CreateScriptParams) (Script, error) {
script := Script{}
url := "/scripts/createScript"
_, err := c.Request("POST", url, params, &script, params.RequestParams)
return script, err
}
// DestroyScript destroys a script
func (c Client) DestroyScript(params DestroyScriptParams) (Script, error) {
script := Script{}
url := fmt.Sprintf("/scripts/%s/destroy", params.ScriptID)
_, err := c.Request("POST", url, nil, &script, params.RequestParams)
return script, err
}