fix: support multiple SSH keys

This commit is contained in:
decentral1se 2021-10-22 09:48:48 +02:00
parent f1386b5cf7
commit c35e78fe3f
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 15 additions and 7 deletions

View File

@ -6,11 +6,13 @@
import "coopcloud.tech/libcapsul"
```
Package libcapsul provides Capsul operations functionality\.
## Index
- [type CapsulClient](<#type-capsulclient>)
- [func New(instanceURL, APIToken string) CapsulClient](<#func-new>)
- [func (c CapsulClient) Create(capsulName, capsulType, capsulImage, capsulSSHKey string) (CapsulCreateResponse, error)](<#func-capsulclient-create>)
- [func (c CapsulClient) Create(capsulName, capsulType, capsulImage string, capsulSSHKeys []string) (CapsulCreateResponse, error)](<#func-capsulclient-create>)
- [type CapsulCreateResponse](<#type-capsulcreateresponse>)
@ -36,7 +38,7 @@ New creates a new Capsul client\.
### func \(CapsulClient\) Create
```go
func (c CapsulClient) Create(capsulName, capsulType, capsulImage, capsulSSHKey string) (CapsulCreateResponse, error)
func (c CapsulClient) Create(capsulName, capsulType, capsulImage string, capsulSSHKeys []string) (CapsulCreateResponse, error)
```
Create creates a new capsul\.

View File

@ -32,7 +32,7 @@ func New(instanceURL, APIToken string) CapsulClient {
}
// Create creates a new capsul.
func (c CapsulClient) Create(capsulName, capsulType, capsulImage, capsulSSHKey string) (CapsulCreateResponse, error) {
func (c CapsulClient) Create(capsulName, capsulType, capsulImage string, capsulSSHKeys []string) (CapsulCreateResponse, error) {
// yep, the response time is quite slow, something to fix on the Capsul side
client := &http.Client{Timeout: 20 * time.Second}
@ -40,10 +40,16 @@ func (c CapsulClient) Create(capsulName, capsulType, capsulImage, capsulSSHKey s
logrus.Debugf("using '%s' as capsul create url", capsulCreateURL)
values := map[string]string{
"name": capsulName,
"size": capsulType,
"os": capsulImage,
"ssh_key_0": capsulSSHKey,
"name": capsulName,
"size": capsulType,
"os": capsulImage,
}
idx := 0
for _, sshKey := range capsulSSHKeys {
key := fmt.Sprintf("ssh_key_%v", idx)
values[key] = sshKey
idx++
}
payload, err := json.Marshal(values)