This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management of Cloud API Keys (#71)
- Loading branch information
1 parent
44fb93c
commit 544e218
Showing
1 changed file
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gapi | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type CreateCloudAPIKeyInput struct { | ||
Name string `json:"name"` | ||
Role string `json:"role"` | ||
} | ||
|
||
type ListCloudAPIKeysOutput struct { | ||
Items []*CloudAPIKey | ||
} | ||
|
||
type CloudAPIKey struct { | ||
ID int | ||
Name string | ||
Role string | ||
Token string | ||
Expiration string | ||
} | ||
|
||
func (c *Client) CreateCloudAPIKey(org string, input *CreateCloudAPIKeyInput) (*CloudAPIKey, error) { | ||
resp := CloudAPIKey{} | ||
data, err := json.Marshal(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = c.request("POST", fmt.Sprintf("/api/orgs/%s/api-keys", org), nil, bytes.NewBuffer(data), &resp) | ||
return &resp, err | ||
} | ||
|
||
func (c *Client) ListCloudAPIKeys(org string) (*ListCloudAPIKeysOutput, error) { | ||
resp := &ListCloudAPIKeysOutput{} | ||
err := c.request("GET", fmt.Sprintf("/api/orgs/%s/api-keys", org), nil, nil, &resp) | ||
return resp, err | ||
} | ||
|
||
func (c *Client) DeleteCloudAPIKey(org string, keyName string) error { | ||
return c.request("DELETE", fmt.Sprintf("/api/orgs/%s/api-keys/%s", org, keyName), nil, nil, nil) | ||
} |