Documentation
¶
Overview ¶
Package k8shell provides a Go client for the k8shell API.
Create an authenticated client with a server URL and personal access token:
c := k8shell.New("https://k8shell.example.com", token)
ws, err := c.ListWorkspaces(ctx, "", false)
For browser-based login, use NewAnonymous to perform the OAuth web flow without a token, then construct an authenticated client from the returned PAT.
Index ¶
- Constants
- type APIError
- type Client
- func (c *Client) CreateWorkspace(ctx context.Context, req WorkspaceCreateRequest) (*WorkspaceCreateResponse, error)
- func (c *Client) DeleteWorkspace(ctx context.Context, name string, deleteData bool) error
- func (c *Client) GetProfile(ctx context.Context) (*models.User, error)
- func (c *Client) GetWorkspace(ctx context.Context, name string) (*models.WorkspaceDetails, error)
- func (c *Client) ListProviders(ctx context.Context) ([]string, error)
- func (c *Client) ListSessions(ctx context.Context, username string, all bool) ([]models.SSHSession, error)
- func (c *Client) ListUsers(ctx context.Context) ([]models.User, error)
- func (c *Client) ListWorkspaces(ctx context.Context, username string, all bool) ([]models.WorkspaceDetails, error)
- func (c *Client) MonitorWorkspace(ctx context.Context, monitorURL string) (io.ReadCloser, error)
- func (c *Client) PollToken(ctx context.Context, state string) (*models.UserToken, error)
- type Option
- type WorkspaceCreateRequest
- type WorkspaceCreateResponse
Constants ¶
const CapabilityOnboardUserWebFlow = "OnboardUserWebFlow"
CapabilityOnboardUserWebFlow is the provider capability required for browser-based login.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is returned for non-2xx responses and carries the HTTP status code and an optional message from the response body.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an authenticated HTTP client for the k8shell API.
func NewAnonymous ¶
NewAnonymous creates an unauthenticated Client, useful for the browser login flow.
func (*Client) CreateWorkspace ¶
func (c *Client) CreateWorkspace(ctx context.Context, req WorkspaceCreateRequest) (*WorkspaceCreateResponse, error)
CreateWorkspace submits a workspace creation request and returns the 202 response containing the workspace name, job ID, and SSE monitor URL.
func (*Client) DeleteWorkspace ¶
DeleteWorkspace shuts down the named workspace. When deleteData is true, workspace storage is permanently deleted.
func (*Client) GetProfile ¶
GetProfile returns the profile of the authenticated user.
func (*Client) GetWorkspace ¶
GetWorkspace returns the details of the named workspace.
func (*Client) ListProviders ¶
ListProviders returns the names of identity providers that support the OnboardUserWebFlow capability (i.e. browser-based login).
func (*Client) ListSessions ¶
func (c *Client) ListSessions(ctx context.Context, username string, all bool) ([]models.SSHSession, error)
ListSessions returns SSH sessions for the given username, or for the authenticated user when username is empty. When all is true, all sessions (including ended ones) are returned.
func (*Client) ListWorkspaces ¶
func (c *Client) ListWorkspaces(ctx context.Context, username string, all bool) ([]models.WorkspaceDetails, error)
ListWorkspaces returns workspaces visible to the authenticated token. When username is non-empty the results are filtered by owner. When all is true, workspaces in all states are included.
func (*Client) MonitorWorkspace ¶
MonitorWorkspace opens an SSE stream at monitorURL and returns the response body for the caller to consume. monitorURL may be a full URL or a path relative to the client's server. The caller is responsible for closing the returned ReadCloser.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithDebugWriter ¶ added in v0.1.0
WithDebugWriter sets the writer used for debug output and implies WithDebug.
type WorkspaceCreateRequest ¶
type WorkspaceCreateRequest struct {
Username string `json:"username"`
Blueprint string `json:"blueprint,omitempty"`
RepoOwner string `json:"repoOwner,omitempty"`
RepoName string `json:"repoName,omitempty"`
RepoRef string `json:"repoRef,omitempty"`
}
WorkspaceCreateRequest is the payload for creating a workspace. Either Blueprint or (RepoOwner + RepoName) must be set.
type WorkspaceCreateResponse ¶
type WorkspaceCreateResponse struct {
Workspace string `json:"workspace"`
JobID string `json:"jobId"`
MonitorURL string `json:"monitorUrl"`
}
WorkspaceCreateResponse is the 202 Accepted body returned by CreateWorkspace.