Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Add management of Cloud API Keys (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne authored Mar 9, 2022
1 parent 44fb93c commit 544e218
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cloud_api_key.go
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)
}

0 comments on commit 544e218

Please sign in to comment.