forked from cloudfoundry/bosh-softlayer-cpi-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
softlayer_security_ssh_key.go
81 lines (64 loc) · 2.49 KB
/
softlayer_security_ssh_key.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
package services
import (
"bytes"
"encoding/json"
"errors"
"fmt"
datatypes "github.com/maximilien/softlayer-go/data_types"
softlayer "github.com/maximilien/softlayer-go/softlayer"
)
type softLayer_Security_Ssh_Key_Service struct {
client softlayer.Client
}
func NewSoftLayer_Security_Ssh_Key_Service(client softlayer.Client) *softLayer_Security_Ssh_Key_Service {
return &softLayer_Security_Ssh_Key_Service{
client: client,
}
}
func (slssks *softLayer_Security_Ssh_Key_Service) GetName() string {
return "SoftLayer_Security_Ssh_Key"
}
func (slssks *softLayer_Security_Ssh_Key_Service) CreateObject(template datatypes.SoftLayer_Security_Ssh_Key) (datatypes.SoftLayer_Security_Ssh_Key, error) {
parameters := datatypes.SoftLayer_Shh_Key_Parameters{
Parameters: []datatypes.SoftLayer_Security_Ssh_Key{
template,
},
}
requestBody, err := json.Marshal(parameters)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
data, err := slssks.client.DoRawHttpRequest(fmt.Sprintf("%s/createObject", slssks.GetName()), "POST", bytes.NewBuffer(requestBody))
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
err = slssks.client.CheckForHttpResponseErrors(data)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
softLayer_Ssh_Key := datatypes.SoftLayer_Security_Ssh_Key{}
err = json.Unmarshal(data, &softLayer_Ssh_Key)
if err != nil {
return datatypes.SoftLayer_Security_Ssh_Key{}, err
}
return softLayer_Ssh_Key, nil
}
func (slssks *softLayer_Security_Ssh_Key_Service) DeleteObject(sshKeyId int) (bool, error) {
response, err := slssks.client.DoRawHttpRequest(fmt.Sprintf("%s/%d.json", slssks.GetName(), sshKeyId), "DELETE", new(bytes.Buffer))
if res := string(response[:]); res != "true" {
return false, errors.New(fmt.Sprintf("Failed to destroy ssh key with id '%d', got '%s' as response from the API.", sshKeyId, res))
}
return true, err
}
func (slssks *softLayer_Security_Ssh_Key_Service) GetSoftwarePasswords(sshKeyId int) ([]datatypes.SoftLayer_Software_Component_Password, error) {
response, err := slssks.client.DoRawHttpRequest(fmt.Sprintf("%s/%d/getSoftwarePasswords.json", slssks.GetName(), sshKeyId), "GET", new(bytes.Buffer))
if err != nil {
return []datatypes.SoftLayer_Software_Component_Password{}, err
}
passwords := []datatypes.SoftLayer_Software_Component_Password{}
err = json.Unmarshal(response, &passwords)
if err != nil {
return []datatypes.SoftLayer_Software_Component_Password{}, err
}
return passwords, nil
}