api

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized — your session may have expired, run `norcube login`")

ErrUnauthorized is returned when the API rejects our token. Higher-level commands can suggest re-running `norcube login`.

Functions

This section is empty.

Types

type AuthClient

type AuthClient struct {
	BaseURL string
	HTTP    *http.Client
	Token   func(ctx context.Context) (string, error)
}

AuthClient talks to the auth service (/auth/me, /organizations, ...). It expects the caller to provide a valid Bearer token via Authorization.

func NewAuthClient

func NewAuthClient(baseURL string, token func(ctx context.Context) (string, error)) *AuthClient

func (*AuthClient) CreateOrganization

func (c *AuthClient) CreateOrganization(ctx context.Context, name string, slug *string) (*Organization, error)

CreateOrganization creates a new org with the given name. slug is optional — when nil or empty the server derives one from the name. The caller becomes the owner. Returns the new org's id, slug, and canonicalised name.

The server returns the new org wrapped in {"organization": {...}} — we unwrap so the caller gets the same Organization shape that ListOrganizations hands back.

func (*AuthClient) GetMe

func (c *AuthClient) GetMe(ctx context.Context) (*Me, error)

func (*AuthClient) ListOrganizations

func (c *AuthClient) ListOrganizations(ctx context.Context) ([]Organization, error)

func (*AuthClient) ListSessions added in v0.16.0

func (c *AuthClient) ListSessions(ctx context.Context) ([]Session, error)

ListSessions lists the caller's live CLI sessions, most recently used first.

func (*AuthClient) RevokeOtherSessions added in v0.16.0

func (c *AuthClient) RevokeOtherSessions(ctx context.Context) (int64, error)

RevokeOtherSessions ends every session of the caller except the one the request's own token belongs to, and returns how many it ended.

func (*AuthClient) RevokeSession added in v0.16.0

func (c *AuthClient) RevokeSession(ctx context.Context, id string) error

RevokeSession ends one of the caller's sessions. Idempotent for the caller's own sessions; an unknown id is a not-found error.

type Me

type Me struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatarUrl"`
}

type Organization

type Organization struct {
	ID        string  `json:"id"`
	Name      string  `json:"name"`
	Slug      string  `json:"slug"`
	LogoURL   *string `json:"logo_url"`
	IsDefault bool    `json:"is_default"`
}

type Session added in v0.16.0

type Session struct {
	ID         string        `json:"id"`
	Kind       string        `json:"kind"`
	Hostname   *string       `json:"hostname"`
	Client     SessionClient `json:"client"`
	IPAddress  *string       `json:"ip_address"`
	CreatedAt  time.Time     `json:"created_at"`
	LastUsedAt time.Time     `json:"last_used_at"`
	ExpiresAt  time.Time     `json:"expires_at"`
	// Current marks the session the request's own token belongs to.
	Current bool `json:"current"`
}

Session is one signed-in CLI session of the caller (GET /auth/me/sessions).

type SessionClient added in v0.16.0

type SessionClient struct {
	Name    *string `json:"name"`
	Version *string `json:"version"`
	OS      *string `json:"os"`
	Arch    *string `json:"arch"`
}

SessionClient is what the session's CLI reported about itself; fields are nil for CLIs that didn't identify themselves.

Directories

Path Synopsis
Package apierror renders non-2xx API responses into error messages that are actually useful for debugging.
Package apierror renders non-2xx API responses into error messages that are actually useful for debugging.
Package langsync provides primitives to interact with the openapi HTTP API.
Package langsync provides primitives to interact with the openapi HTTP API.
Package snapdb provides primitives to interact with the openapi HTTP API.
Package snapdb provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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