feat: add keys to organization provision daemons (#14627)

This commit is contained in:
Garrett Delfosse
2024-09-16 20:02:08 +00:00
committed by GitHub
parent 4afce19fb7
commit 335eb05223
32 changed files with 728 additions and 72 deletions
+44
View File
@@ -38,6 +38,7 @@ const (
type ProvisionerDaemon struct {
ID uuid.UUID `json:"id" format:"uuid"`
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
KeyID uuid.UUID `json:"key_id" format:"uuid"`
CreatedAt time.Time `json:"created_at" format:"date-time"`
LastSeenAt NullTime `json:"last_seen_at,omitempty" format:"date-time"`
Name string `json:"name"`
@@ -282,6 +283,31 @@ type ProvisionerKey struct {
// HashedSecret - never include the access token in the API response
}
type ProvisionerKeyDaemons struct {
Key ProvisionerKey `json:"key"`
Daemons []ProvisionerDaemon `json:"daemons"`
}
const (
ProvisionerKeyIDBuiltIn = "00000000-0000-0000-0000-000000000001"
ProvisionerKeyIDUserAuth = "00000000-0000-0000-0000-000000000002"
ProvisionerKeyIDPSK = "00000000-0000-0000-0000-000000000003"
)
const (
ProvisionerKeyNameBuiltIn = "built-in"
ProvisionerKeyNameUserAuth = "user-auth"
ProvisionerKeyNamePSK = "psk"
)
func ReservedProvisionerKeyNames() []string {
return []string{
ProvisionerKeyNameBuiltIn,
ProvisionerKeyNameUserAuth,
ProvisionerKeyNamePSK,
}
}
type CreateProvisionerKeyRequest struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
@@ -327,6 +353,24 @@ func (c *Client) ListProvisionerKeys(ctx context.Context, organizationID uuid.UU
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
// ListProvisionerKeyDaemons lists all provisioner keys with their associated daemons for an organization.
func (c *Client) ListProvisionerKeyDaemons(ctx context.Context, organizationID uuid.UUID) ([]ProvisionerKeyDaemons, error) {
res, err := c.Request(ctx, http.MethodGet,
fmt.Sprintf("/api/v2/organizations/%s/provisionerkeys/daemons", organizationID.String()),
nil,
)
if err != nil {
return nil, xerrors.Errorf("make request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var resp []ProvisionerKeyDaemons
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
// DeleteProvisionerKey deletes a provisioner key.
func (c *Client) DeleteProvisionerKey(ctx context.Context, organizationID uuid.UUID, name string) error {
res, err := c.Request(ctx, http.MethodDelete,