-
Notifications
You must be signed in to change notification settings - Fork 1
/
remoteaccess.go
108 lines (96 loc) · 3.66 KB
/
remoteaccess.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
package c8y
import (
"context"
"fmt"
"net/http"
)
const (
RemoteAccessProtocolPassthrough = "PASSTHROUGH"
RemoteAccessProtocolSSH = "SSH"
RemoteAccessProtocolVNC = "VNC"
RemoteAccessProtocolTelnet = "TELNET"
)
// RemoteAccessService
type RemoteAccessService service
// RemoteAccessCollectionOptions remote access collection filter options
type RemoteAccessCollectionOptions struct {
// Pagination options
PaginationOptions
}
// RemoteAccessCollection collection of remote access configurations
type RemoteAccessConfiguration struct {
ID string `json:"id"`
Name string `json:"name"`
Hostname string `json:"hostname"`
Port int `json:"port"`
Protocol string `json:"protocol"`
Credentials RemoteAccessCredentials `json:"credentials"`
}
// RemoteAccessCredentials
type RemoteAccessCredentials struct {
Type string `json:"type"`
Username string `json:"username"`
Password string `json:"password"`
PublicKey string `json:"publicKey"`
PrivateKey string `json:"privateKey"`
HostKey string `json:"hostKey"`
}
func (s *RemoteAccessService) path(mo_id string) string {
return fmt.Sprintf("/service/remoteaccess/devices/%s/configurations", mo_id)
}
func (s *RemoteAccessService) config_path(mo_id string, config_id string) string {
return fmt.Sprintf("/service/remoteaccess/devices/%s/configurations/%s", mo_id, config_id)
}
// GetConfiguration return a specific remote access configuration for a given device
func (s *RemoteAccessService) GetConfiguration(ctx context.Context, mo_id, config_id string) (*RemoteAccessConfiguration, *Response, error) {
data := new(RemoteAccessConfiguration)
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: http.MethodGet,
Path: s.config_path(mo_id, config_id),
ResponseData: data,
})
return data, resp, err
}
// GetConfigurations returns a collection of Cumulocity remote access configurations
// for a given managed object
func (s *RemoteAccessService) GetConfigurations(ctx context.Context, mo_id string, opt *RemoteAccessCollectionOptions) ([]RemoteAccessConfiguration, *Response, error) {
data := make([]RemoteAccessConfiguration, 0)
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: http.MethodGet,
Path: s.path(mo_id),
Query: opt,
ResponseData: &data,
})
return data, resp, err
}
// DeleteConfiguration delete remote access configuration
func (s *RemoteAccessService) DeleteConfiguration(ctx context.Context, mo_id string, config_id string, opt *RemoteAccessCollectionOptions) (*Response, error) {
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: http.MethodDelete,
Path: s.config_path(mo_id, config_id),
Query: opt,
})
return resp, err
}
// Create creates a new operation for a device
func (s *RemoteAccessService) Create(ctx context.Context, mo_id string, config_id string, body interface{}) (*RemoteAccessConfiguration, *Response, error) {
data := new(RemoteAccessConfiguration)
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: http.MethodPost,
Path: s.config_path(mo_id, config_id),
Body: body,
ResponseData: data,
})
return data, resp, err
}
// Update updates a Cumulocity operation
func (s *RemoteAccessService) Update(ctx context.Context, mo_id string, config_id string, body *OperationUpdateOptions) (*Operation, *Response, error) {
data := new(Operation)
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: http.MethodPut,
Path: s.config_path(mo_id, config_id),
Body: body,
ResponseData: data,
})
return data, resp, err
}