cliclient

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cliclient provides a lightweight HTTP client for the Nebi API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsForbidden

func IsForbidden(err error) bool

IsForbidden returns true if the error is a 403 Forbidden error.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the error is a 404 Not Found error.

func IsOIDCRedirect

func IsOIDCRedirect(err error) bool

IsOIDCRedirect returns true if the error indicates the server is behind an OIDC proxy that redirected to a login page instead of returning JSON. This typically manifests as a JSON decode error when the response body starts with '<' (HTML) instead of '{' (JSON).

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized returns true if the error is a 401 Unauthorized error.

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError represents an API error response.

func (*APIError) Error

func (e *APIError) Error() string

type AuditLog

type AuditLog struct {
	ID          int         `json:"id"`
	UserID      string      `json:"user_id"`
	Action      string      `json:"action"`
	Resource    string      `json:"resource"`
	ResourceID  string      `json:"resource_id,omitempty"`
	DetailsJSON interface{} `json:"details_json,omitempty"`
	Timestamp   string      `json:"timestamp"`
	User        *User       `json:"user,omitempty"`
}

AuditLog represents an audit log entry.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a lightweight HTTP client for the Nebi API.

func New

func New(baseURL, token string) *Client

New creates a new API client.

func NewWithoutAuth

func NewWithoutAuth(baseURL string) *Client

NewWithoutAuth creates a new API client without authentication (for login).

func (*Client) CreateRegistry

func (c *Client) CreateRegistry(ctx context.Context, req CreateRegistryRequest) (*Registry, error)

CreateRegistry creates a new registry.

func (*Client) CreateWorkspace

func (c *Client) CreateWorkspace(ctx context.Context, req CreateWorkspaceRequest) (*Workspace, error)

CreateWorkspace creates a new workspace.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)

Delete performs a DELETE request.

func (*Client) DeleteRegistry

func (c *Client) DeleteRegistry(ctx context.Context, id string) error

DeleteRegistry deletes a registry by ID.

func (*Client) DeleteWorkspace

func (c *Client) DeleteWorkspace(ctx context.Context, id string) error

DeleteWorkspace deletes a workspace by ID.

func (*Client) ExchangeDeviceToken added in v0.10.1

func (c *Client) ExchangeDeviceToken(ctx context.Context, idToken string) (*DeviceTokenResponse, error)

ExchangeDeviceToken exchanges a Keycloak ID token for a Nebi JWT.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, result interface{}) (*http.Response, error)

Get performs a GET request.

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser(ctx context.Context) (*User, error)

GetCurrentUser calls GET /auth/me to get the authenticated user.

func (*Client) GetDashboardStats

func (c *Client) GetDashboardStats(ctx context.Context) (*DashboardStats, error)

GetDashboardStats returns admin dashboard statistics (admin only).

func (*Client) GetDeviceConfig added in v0.10.1

func (c *Client) GetDeviceConfig(ctx context.Context) (*DeviceConfigResponse, error)

GetDeviceConfig fetches the OIDC device flow configuration from the server.

func (*Client) GetPublishDefaults

func (c *Client) GetPublishDefaults(ctx context.Context, wsID string) (*PublishDefaults, error)

GetPublishDefaults returns suggested defaults for publishing a workspace.

func (*Client) GetServerVersion

func (c *Client) GetServerVersion(ctx context.Context) (*ServerVersion, error)

GetServerVersion calls GET /version (public, no auth required).

func (*Client) GetText

func (c *Client) GetText(ctx context.Context, path string) (string, *http.Response, error)

GetText performs a GET request and returns the response as a string.

func (*Client) GetVersionPixiLock

func (c *Client) GetVersionPixiLock(ctx context.Context, wsID string, version int32) (string, error)

GetVersionPixiLock returns the pixi.lock for a specific version.

func (*Client) GetVersionPixiToml

func (c *Client) GetVersionPixiToml(ctx context.Context, wsID string, version int32) (string, error)

GetVersionPixiToml returns the pixi.toml for a specific version.

func (*Client) GetWorkspace

func (c *Client) GetWorkspace(ctx context.Context, id string) (*Workspace, error)

GetWorkspace returns a workspace by ID.

func (*Client) GetWorkspacePackages

func (c *Client) GetWorkspacePackages(ctx context.Context, wsID string) ([]Package, error)

GetWorkspacePackages returns packages for a workspace.

func (*Client) GetWorkspacePublications

func (c *Client) GetWorkspacePublications(ctx context.Context, wsID string) ([]Publication, error)

GetWorkspacePublications returns publications for a workspace.

func (*Client) GetWorkspaceTags

func (c *Client) GetWorkspaceTags(ctx context.Context, wsID string) ([]WorkspaceTag, error)

GetWorkspaceTags returns server-side tags for a workspace.

func (*Client) GetWorkspaceVersions

func (c *Client) GetWorkspaceVersions(ctx context.Context, wsID string) ([]WorkspaceVersion, error)

GetWorkspaceVersions returns versions for a workspace.

func (*Client) ListAuditLogs

func (c *Client) ListAuditLogs(ctx context.Context, userID, action string) ([]AuditLog, error)

ListAuditLogs returns audit logs with optional filters (admin only).

func (*Client) ListJobs

func (c *Client) ListJobs(ctx context.Context) ([]Job, error)

ListJobs returns all jobs for the authenticated user.

func (*Client) ListRegistries

func (c *Client) ListRegistries(ctx context.Context) ([]Registry, error)

ListRegistries returns all registries (tries admin endpoint first, then public).

func (*Client) ListRegistriesAdmin

func (c *Client) ListRegistriesAdmin(ctx context.Context) ([]Registry, error)

ListRegistriesAdmin returns all registries (admin endpoint only).

func (*Client) ListRegistriesPublic

func (c *Client) ListRegistriesPublic(ctx context.Context) ([]Registry, error)

ListRegistriesPublic returns all registries (public endpoint only).

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context) ([]User, error)

ListUsers returns all users (admin only).

func (*Client) ListWorkspaces

func (c *Client) ListWorkspaces(ctx context.Context) ([]Workspace, error)

ListWorkspaces returns all workspaces.

func (*Client) Login

func (c *Client) Login(ctx context.Context, username, password string) (*LoginResponse, error)

Login authenticates with the server and returns a token.

func (*Client) PollDeviceCode

func (c *Client) PollDeviceCode(ctx context.Context, code string) (*DevicePollResponse, error)

PollDeviceCode checks whether the device code has been completed.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body, result interface{}) (*http.Response, error)

Post performs a POST request.

func (*Client) PublishWorkspace

func (c *Client) PublishWorkspace(ctx context.Context, wsID string, req PublishRequest) (*PublishResponse, error)

PublishWorkspace publishes a workspace to a registry.

func (*Client) PushVersion

func (c *Client) PushVersion(ctx context.Context, wsID string, req PushRequest) (*PushResponse, error)

PushVersion pushes a new version to the server with a tag.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body, result interface{}) (*http.Response, error)

Put performs a PUT request.

func (*Client) RequestDeviceCode

func (c *Client) RequestDeviceCode(ctx context.Context) (*DeviceCodeResponse, error)

RequestDeviceCode requests a new device code for browser-based CLI login.

func (*Client) UpdateRegistry

func (c *Client) UpdateRegistry(ctx context.Context, id string, req UpdateRegistryRequest) (*Registry, error)

UpdateRegistry updates a registry.

type CreateRegistryRequest

type CreateRegistryRequest struct {
	Name      string  `json:"name"`
	URL       string  `json:"url"`
	Username  *string `json:"username,omitempty"`
	Password  *string `json:"password,omitempty"`
	IsDefault *bool   `json:"is_default,omitempty"`
	Namespace *string `json:"namespace,omitempty"`
}

CreateRegistryRequest represents a request to create a registry.

type CreateWorkspaceRequest

type CreateWorkspaceRequest struct {
	Name           string  `json:"name"`
	PackageManager *string `json:"package_manager,omitempty"`
	PixiToml       *string `json:"pixi_toml,omitempty"`
}

CreateWorkspaceRequest represents a request to create a workspace.

type DashboardStats

type DashboardStats struct {
	TotalDiskUsageBytes     int64  `json:"total_disk_usage_bytes"`
	TotalDiskUsageFormatted string `json:"total_disk_usage_formatted"`
}

DashboardStats represents admin dashboard statistics.

type DeviceCodeResponse

type DeviceCodeResponse struct {
	Code      string `json:"code"`
	ExpiresIn int    `json:"expires_in"`
}

DeviceCodeResponse is the response from POST /auth/cli-login/code.

type DeviceConfigResponse added in v0.10.1

type DeviceConfigResponse struct {
	Enabled   bool   `json:"enabled"`
	IssuerURL string `json:"issuer_url,omitempty"`
	ClientID  string `json:"client_id,omitempty"`
}

DeviceConfigResponse is the response from GET /auth/device-config.

type DevicePollResponse

type DevicePollResponse struct {
	Status   string `json:"status"`
	Token    string `json:"token,omitempty"`
	Username string `json:"username,omitempty"`
}

DevicePollResponse is the response from GET /auth/cli-login/poll.

type DeviceTokenResponse added in v0.10.1

type DeviceTokenResponse struct {
	Token    string `json:"token"`
	Username string `json:"username"`
}

DeviceTokenResponse is the response from POST /auth/device-token.

type Job

type Job struct {
	ID          string                 `json:"id"`
	WorkspaceID string                 `json:"workspace_id"`
	Type        string                 `json:"type"`
	Status      string                 `json:"status"`
	Logs        string                 `json:"logs,omitempty"`
	Error       string                 `json:"error,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt   string                 `json:"created_at"`
	StartedAt   *string                `json:"started_at,omitempty"`
	CompletedAt *string                `json:"completed_at,omitempty"`
}

Job represents a background job on the server.

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

LoginRequest represents a login request.

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
	User  User   `json:"user"`
}

LoginResponse represents a login response.

type Package

type Package struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Version   string `json:"version,omitempty"`
	Channel   string `json:"channel,omitempty"`
	Source    string `json:"source,omitempty"`
	WsID      string `json:"workspace_id"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

Package represents a package in a workspace.

type Publication

type Publication struct {
	ID            string `json:"id"`
	WsID          string `json:"workspace_id"`
	VersionNumber int    `json:"version_number"`
	RegistryID    string `json:"registry_id"`
	RegistryName  string `json:"registry_name"`
	Repository    string `json:"repository"`
	Tag           string `json:"tag"`
	Digest        string `json:"digest"`
	PublishedAt   string `json:"published_at"`
}

Publication represents a published version of a workspace.

type PublishDefaults

type PublishDefaults struct {
	RegistryID   string `json:"registry_id"`
	RegistryName string `json:"registry_name"`
	Namespace    string `json:"namespace"`
	Repository   string `json:"repository"`
	Tag          string `json:"tag"`
}

PublishDefaults represents suggested defaults for publishing a workspace.

type PublishRequest

type PublishRequest struct {
	RegistryID string `json:"registry_id"`
	Repository string `json:"repository"`
	Tag        string `json:"tag"`
}

PublishRequest represents a request to publish a workspace.

type PublishResponse

type PublishResponse struct {
	Digest     string `json:"digest"`
	Repository string `json:"repository"`
	Tag        string `json:"tag"`
}

PublishResponse represents the response from publishing a workspace.

type PushRequest

type PushRequest struct {
	Tag      string `json:"tag"`
	PixiToml string `json:"pixi_toml"`
	PixiLock string `json:"pixi_lock,omitempty"`
	Force    bool   `json:"force,omitempty"`
}

PushRequest represents a request to push a version to the server.

type PushResponse

type PushResponse struct {
	VersionNumber int      `json:"version_number"`
	Tags          []string `json:"tags"`
	ContentHash   string   `json:"content_hash"`
	Deduplicated  bool     `json:"deduplicated"`
	Tag           string   `json:"tag"`
}

PushResponse represents the response from pushing a version.

type Registry

type Registry struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	URL       string `json:"url"`
	Username  string `json:"username,omitempty"`
	IsDefault bool   `json:"is_default"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

Registry represents an OCI registry.

type ServerVersion

type ServerVersion struct {
	Version   string          `json:"version"`
	Commit    string          `json:"commit"`
	GoVersion string          `json:"go_version"`
	OS        string          `json:"os"`
	Arch      string          `json:"arch"`
	Mode      string          `json:"mode"`
	Features  map[string]bool `json:"features"`
}

ServerVersion represents the response from GET /version.

type UpdateRegistryRequest

type UpdateRegistryRequest struct {
	Name      *string `json:"name,omitempty"`
	URL       *string `json:"url,omitempty"`
	Username  *string `json:"username,omitempty"`
	Password  *string `json:"password,omitempty"`
	IsDefault *bool   `json:"is_default,omitempty"`
	Namespace *string `json:"namespace,omitempty"`
}

UpdateRegistryRequest represents a request to update a registry.

type User

type User struct {
	ID        string    `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	IsAdmin   bool      `json:"is_admin"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

User represents a user.

type Workspace

type Workspace struct {
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	Status         string    `json:"status"`
	PackageManager string    `json:"package_manager"`
	SizeBytes      int64     `json:"size_bytes"`
	Owner          *User     `json:"owner,omitempty"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

Workspace represents a workspace.

type WorkspaceTag

type WorkspaceTag struct {
	Tag           string `json:"tag"`
	VersionNumber int    `json:"version_number"`
	CreatedAt     string `json:"created_at"`
	UpdatedAt     string `json:"updated_at"`
}

WorkspaceTag represents a server-side tag pointing to a version.

type WorkspaceVersion

type WorkspaceVersion struct {
	ID            string `json:"id"`
	WsID          string `json:"workspace_id"`
	VersionNumber int32  `json:"version_number"`
	CreatedAt     string `json:"created_at"`
}

WorkspaceVersion represents a version of a workspace.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL