Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions internal/api/service_keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package api

import (
"context"

"github.com/google/uuid"

"github.com/Kong/volcano-cli/internal/apiclient"
)

// ListServiceKeys returns one service-key page for a project.
func (c *Client) ListServiceKeys(ctx context.Context, projectID uuid.UUID, page, limit int) (*apiclient.PaginatedServiceKeys, error) {
resp, err := c.client.ListServiceKeysWithResponse(ctx, projectID, &apiclient.ListServiceKeysParams{
Page: &page,
Limit: &limit,
})
if err != nil {
return nil, err
}
return apiResult(resp.StatusCode(), resp.Body, resp.JSON200)
}

// CreateServiceKey creates one service key in a project. When permissions is
// non-empty the key is scoped to exactly those operations; otherwise the server
// grants full access (["*"]).
func (c *Client) CreateServiceKey(ctx context.Context, projectID uuid.UUID, name string, permissions []string) (*apiclient.ServiceKey, error) {
body := apiclient.CreateServiceKeyJSONRequestBody{Name: name}
if len(permissions) > 0 {
body.Permissions = &permissions
}
resp, err := c.client.CreateServiceKeyWithResponse(ctx, projectID, body)
if err != nil {
return nil, err
}
return apiResult(resp.StatusCode(), resp.Body, resp.JSON201)
}

// GetServiceKey returns one service key by ID.
func (c *Client) GetServiceKey(ctx context.Context, projectID, keyID uuid.UUID) (*apiclient.ServiceKey, error) {
resp, err := c.client.GetServiceKeyWithResponse(ctx, projectID, keyID)
if err != nil {
return nil, err
}
return apiResult(resp.StatusCode(), resp.Body, resp.JSON200)
}
133 changes: 133 additions & 0 deletions internal/apiclient/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading