forked from ingrammicro/concerto
/
ssh_profiles_api.go
121 lines (93 loc) · 3.05 KB
/
ssh_profiles_api.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package cloud
import (
"encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/ingrammicro/concerto/api/types"
"github.com/ingrammicro/concerto/utils"
)
// SSHProfileService manages sshProfile operations
type SSHProfileService struct {
concertoService utils.ConcertoService
}
// NewSSHProfileService returns a Concerto sshProfile service
func NewSSHProfileService(concertoService utils.ConcertoService) (*SSHProfileService, error) {
if concertoService == nil {
return nil, fmt.Errorf("Must initialize ConcertoService before using it")
}
return &SSHProfileService{
concertoService: concertoService,
}, nil
}
// GetSSHProfileList returns the list of sshProfiles as an array of SSHProfile
func (dm *SSHProfileService) GetSSHProfileList() (sshProfiles []types.SSHProfile, err error) {
log.Debug("GetSSHProfileList")
data, status, err := dm.concertoService.Get("/v1/cloud/ssh_profiles")
if err != nil {
return nil, err
}
if err = utils.CheckStandardStatus(status, data); err != nil {
return nil, err
}
if err = json.Unmarshal(data, &sshProfiles); err != nil {
return nil, err
}
return sshProfiles, nil
}
// GetSSHProfile returns a sshProfile by its ID
func (dm *SSHProfileService) GetSSHProfile(ID string) (sshProfile *types.SSHProfile, err error) {
log.Debug("GetSSHProfile")
data, status, err := dm.concertoService.Get(fmt.Sprintf("/v1/cloud/ssh_profiles/%s", ID))
if err != nil {
return nil, err
}
if err = utils.CheckStandardStatus(status, data); err != nil {
return nil, err
}
if err = json.Unmarshal(data, &sshProfile); err != nil {
return nil, err
}
return sshProfile, nil
}
// CreateSSHProfile creates a sshProfile
func (dm *SSHProfileService) CreateSSHProfile(sshProfileVector *map[string]interface{}) (sshProfile *types.SSHProfile, err error) {
log.Debug("CreateSSHProfile")
data, status, err := dm.concertoService.Post("/v1/cloud/ssh_profiles/", sshProfileVector)
if err != nil {
return nil, err
}
if err = utils.CheckStandardStatus(status, data); err != nil {
return nil, err
}
if err = json.Unmarshal(data, &sshProfile); err != nil {
return nil, err
}
return sshProfile, nil
}
// UpdateSSHProfile updates a sshProfile by its ID
func (dm *SSHProfileService) UpdateSSHProfile(sshProfileVector *map[string]interface{}, ID string) (sshProfile *types.SSHProfile, err error) {
log.Debug("UpdateSSHProfile")
data, status, err := dm.concertoService.Put(fmt.Sprintf("/v1/cloud/ssh_profiles/%s", ID), sshProfileVector)
if err != nil {
return nil, err
}
if err = utils.CheckStandardStatus(status, data); err != nil {
return nil, err
}
if err = json.Unmarshal(data, &sshProfile); err != nil {
return nil, err
}
return sshProfile, nil
}
// DeleteSSHProfile deletes a sshProfile by its ID
func (dm *SSHProfileService) DeleteSSHProfile(ID string) (err error) {
log.Debug("DeleteSSHProfile")
data, status, err := dm.concertoService.Delete(fmt.Sprintf("/v1/cloud/ssh_profiles/%s", ID))
if err != nil {
return err
}
if err = utils.CheckStandardStatus(status, data); err != nil {
return err
}
return nil
}