-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypair.go
44 lines (32 loc) · 961 Bytes
/
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
package proc
import (
"encoding/json"
"fmt"
"io/ioutil"
tb_api "github.com/cloud-barista/cb-tumblebug/src/api/grpc/request"
)
// ===== [ Constants and Variables ] =====
// ===== [ Implementations ] =====
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====
// SaveSshKey - Keypair 파일로 저장
func SaveSshKey(mcir *tb_api.MCIRApi, nameSpaceID string, resourceID string, sshSaveFileName string) (string, error) {
holdType, _ := mcir.GetOutType()
mcir.SetOutType("json")
result, err := mcir.GetSshKeyByParam(nameSpaceID, resourceID)
mcir.SetOutType(holdType)
if err != nil {
return "", err
}
jsonMap := make(map[string]interface{})
err = json.Unmarshal([]byte(result), &jsonMap)
if err != nil {
return "", err
}
privateKey := fmt.Sprintf("%v", jsonMap["privateKey"])
err = ioutil.WriteFile(sshSaveFileName, []byte(privateKey), 0644)
if err != nil {
return "", err
}
return "ssh key file saved", nil
}