-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssh_keypair.go
91 lines (78 loc) · 2.36 KB
/
ssh_keypair.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
// Proof of Concepts for the Cloud-Barista Multi-Cloud Project.
// * Cloud-Barista: https://github.com/cloud-barista
//
// This code is based on the following material: https://github.com/mindjiver/gopherstack (MIT License)
//
// KT Cloud SDK go
//
// by ETRI, 2021.07.
package ktcloudsdk
import (
"net/url"
)
// Create a SSH key pair
func (c KtCloudClient) CreateSSHKeyPair(name string) (CreateSshKeyPairResponse, error) {
var resp CreateSshKeyPairResponse
params := url.Values{}
params.Set("name", name)
response, err := NewRequest(c, "createSSHKeyPair", params)
if err != nil {
return resp, err
}
resp = response.(CreateSshKeyPairResponse)
return resp, nil
}
// List SSH keypairs
func (c KtCloudClient) ListSSHKeyPairs(name string) (ListSshKeyPairsResponse, error) {
var resp ListSshKeyPairsResponse
params := url.Values{}
if name != "" {
params.Set("name", name)
}
response, err := NewRequest(c, "listSSHKeyPairs", params)
if err != nil {
return resp, err
}
resp = response.(ListSshKeyPairsResponse)
return resp, nil
}
//~~~ keypairs res... 에서 중간 s자 주의
// Deletes an SSH key pair
func (c KtCloudClient) DeleteSSHKeyPair(name string) (DeleteSshKeyPairResponse, error) {
var resp DeleteSshKeyPairResponse
params := url.Values{}
params.Set("name", name)
response, err := NewRequest(c, "deleteSSHKeyPair", params)
if err != nil {
return resp, err
}
resp = response.(DeleteSshKeyPairResponse)
return resp, err
}
type KeyPair struct {
PrivateKey string `json:"privatekey"`
// CreateSSHKeyPair() 할때만 response로 받음.
Name string `json:"name"`
Account string `json:"account"`
DomainId string `json:"domainid"`
Domain string `json:"domain"`
Fingerprint string `json:"fingerprint"`
}
type CreateSshKeyPairResponse struct {
Createsshkeypairresponse struct {
KeyPair KeyPair `json:"keypair"`
} `json:"createsshkeypairresponse"`
}
type ListSshKeyPairsResponse struct {
Listsshkeypairsresponse struct {
Count int `json:"count"`
KeyPair []KeyPair `json:"sshkeypair"`
} `json:"listsshkeypairsresponse"`
}
//~~~ keypair가 아닌 sshkeypair로 받음에 주의
//~~~ keypairs res... 에서 중간 s자 주의
type DeleteSshKeyPairResponse struct {
Deletesshkeypairresponse struct {
Success string `json:"success"`
} `json:"deletesshkeypairresponse"`
}