mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add provisioner key crud apis (#13857)
This commit is contained in:
@@ -56,6 +56,7 @@ const (
|
||||
FeatureAccessControl FeatureName = "access_control"
|
||||
FeatureControlSharedPorts FeatureName = "control_shared_ports"
|
||||
FeatureCustomRoles FeatureName = "custom_roles"
|
||||
FeatureMultipleOrganizations FeatureName = "multiple_organizations"
|
||||
)
|
||||
|
||||
// FeatureNames must be kept in-sync with the Feature enum above.
|
||||
@@ -77,6 +78,7 @@ var FeatureNames = []FeatureName{
|
||||
FeatureAccessControl,
|
||||
FeatureControlSharedPorts,
|
||||
FeatureCustomRoles,
|
||||
FeatureMultipleOrganizations,
|
||||
}
|
||||
|
||||
// Humanize returns the feature name in a human-readable format.
|
||||
|
||||
@@ -265,3 +265,72 @@ func (c *Client) ServeProvisionerDaemon(ctx context.Context, req ServeProvisione
|
||||
}
|
||||
return proto.NewDRPCProvisionerDaemonClient(drpc.MultiplexedConn(session)), nil
|
||||
}
|
||||
|
||||
type ProvisionerKey struct {
|
||||
ID uuid.UUID `json:"id" format:"uuid"`
|
||||
CreatedAt time.Time `json:"created_at" format:"date-time"`
|
||||
OrganizationID uuid.UUID `json:"organization" format:"uuid"`
|
||||
Name string `json:"name"`
|
||||
// HashedSecret - never include the access token in the API response
|
||||
}
|
||||
|
||||
type CreateProvisionerKeyRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type CreateProvisionerKeyResponse struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
// CreateProvisionerKey creates a new provisioner key for an organization.
|
||||
func (c *Client) CreateProvisionerKey(ctx context.Context, organizationID uuid.UUID, req CreateProvisionerKeyRequest) (CreateProvisionerKeyResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodPost,
|
||||
fmt.Sprintf("/api/v2/organizations/%s/provisionerkeys", organizationID.String()),
|
||||
req,
|
||||
)
|
||||
if err != nil {
|
||||
return CreateProvisionerKeyResponse{}, xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusCreated {
|
||||
return CreateProvisionerKeyResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp CreateProvisionerKeyResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
// ListProvisionerKeys lists all provisioner keys for an organization.
|
||||
func (c *Client) ListProvisionerKeys(ctx context.Context, organizationID uuid.UUID) ([]ProvisionerKey, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet,
|
||||
fmt.Sprintf("/api/v2/organizations/%s/provisionerkeys", 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 []ProvisionerKey
|
||||
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,
|
||||
fmt.Sprintf("/api/v2/organizations/%s/provisionerkeys/%s", organizationID.String(), name),
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusNoContent {
|
||||
return ReadBodyAsError(res)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ const (
|
||||
ResourceOrganization RBACResource = "organization"
|
||||
ResourceOrganizationMember RBACResource = "organization_member"
|
||||
ResourceProvisionerDaemon RBACResource = "provisioner_daemon"
|
||||
ResourceProvisionerKeys RBACResource = "provisioner_keys"
|
||||
ResourceReplicas RBACResource = "replicas"
|
||||
ResourceSystem RBACResource = "system"
|
||||
ResourceTailnetCoordinator RBACResource = "tailnet_coordinator"
|
||||
@@ -69,6 +70,7 @@ var RBACResourceActions = map[RBACResource][]RBACAction{
|
||||
ResourceOrganization: {ActionCreate, ActionDelete, ActionRead, ActionUpdate},
|
||||
ResourceOrganizationMember: {ActionCreate, ActionDelete, ActionRead, ActionUpdate},
|
||||
ResourceProvisionerDaemon: {ActionCreate, ActionDelete, ActionRead, ActionUpdate},
|
||||
ResourceProvisionerKeys: {ActionCreate, ActionDelete, ActionRead},
|
||||
ResourceReplicas: {ActionRead},
|
||||
ResourceSystem: {ActionCreate, ActionDelete, ActionRead, ActionUpdate},
|
||||
ResourceTailnetCoordinator: {ActionCreate, ActionDelete, ActionRead, ActionUpdate},
|
||||
|
||||
Reference in New Issue
Block a user