-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathssh_key_link.go
59 lines (48 loc) · 1.46 KB
/
ssh_key_link.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
package scalr
import (
"context"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ SSHKeysLinks = (*sshKeysLinks)(nil)
type SSHKeysLinks interface {
Create(ctx context.Context, workspaceID string, sshKeyID string) (*Workspace, error)
Delete(ctx context.Context, workspaceID string) error
}
// sshKeysLinks implements SSHKeysLinks.
type sshKeysLinks struct {
client *Client
}
// SSHKeysLink represents a single SSH key workspace link.
type SSHKeysLink struct {
SSHKeyID string `jsonapi:"attr,ssh-key"`
}
type SSHKeysLinkCreateOptions struct {
SSHKeyID string `json:"ssh-key"`
}
// Create creates a SSH key workspace link.
func (s *sshKeysLinks) Create(ctx context.Context, workspaceID string, sshKeyID string) (*Workspace, error) {
urlPath := fmt.Sprintf("workspaces/%s/ssh-key-links", url.QueryEscape(workspaceID))
linkOptions := SSHKeysLinkCreateOptions{
SSHKeyID: sshKeyID,
}
req, err := s.client.newJsonRequest("POST", urlPath, linkOptions)
if err != nil {
return nil, err
}
workspace := &Workspace{}
if err := s.client.do(ctx, req, workspace); err != nil {
return nil, err
}
return workspace, nil
}
// Delete deletes a SSH key workspace link.
func (s *sshKeysLinks) Delete(ctx context.Context, workspaceID string) error {
urlPath := fmt.Sprintf("workspaces/%s/ssh-key-links/", url.QueryEscape(workspaceID))
req, err := s.client.newRequest("DELETE", urlPath, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}