-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SCALRCORE-31981 add SSH key link client
- Loading branch information
1 parent
cd0e1b0
commit 43cef5a
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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) (*SSHKeysLink, 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) (*SSHKeysLink, 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 | ||
} | ||
req.Header.Set("Content-Type", "application/vnd.api+json") | ||
|
||
link := &SSHKeysLink{} | ||
if err := s.client.do(ctx, req, link); err != nil { | ||
return nil, err | ||
} | ||
|
||
return link, 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters