client

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package client is a small client for the Stampede REST API, used by the CLI and the terminal UI. It speaks the same public API as the web UI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() (string, error)

ConfigPath is ~/.config/stampede/config.yaml (or the OS equivalent).

func Login

func Login(ctx context.Context, server, email, password, tokenName string) (string, gen.Me, error)

Login signs in with a password and creates an API token for this CLI.

func PasswordToken

func PasswordToken(ctx context.Context, server, email, password string, body map[string]any) (gen.TokenCreated, gen.Me, error)

PasswordToken signs in with a password and creates an API token from body (a TokenCreate). API tokens cannot create tokens, so this is how the CLI makes them.

func Query

func Query(kv ...string) string

Query encodes non-empty query parameters as "?a=b&c=d".

func SaveConfig

func SaveConfig(c Config) (string, error)

SaveConfig writes the config with owner-only permissions (it holds a token).

func Setup

func Setup(ctx context.Context, server, organisation, name, email, password, tokenName string) (string, gen.Me, error)

Setup creates the first organisation and owner account on a new server, then an API token for this CLI.

Types

type APIError

type APIError struct {
	Status  int
	Code    string
	Message string
	Details []string
}

APIError is an error response from the server.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	Server string
	Token  string
	// Project is the default project for commands given no --project
	// (stampede projects use, or STAMPEDE_PROJECT).
	Project string
	HTTP    *http.Client
}

Client calls a Stampede server.

func New

func New() (*Client, error)

New builds a client from the stored config.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body, out any) error

Do sends a request with a JSON body and decodes a JSON response into out.

func (*Client) FindAIJob

func (c *Client) FindAIJob(ctx context.Context, project, ref string) (gen.AIJobSummary, error)

FindAIJob resolves a project's AI job by id or a unique id prefix.

func (*Client) FindAIProvider

func (c *Client) FindAIProvider(ctx context.Context, ref string) (gen.AIProvider, error)

FindAIProvider resolves an AI provider by id or name.

func (*Client) FindChannel

func (c *Client) FindChannel(ctx context.Context, ref string) (gen.NotificationChannel, error)

FindChannel resolves a notification channel by id or name.

func (*Client) FindDriftResult

func (c *Client) FindDriftResult(ctx context.Context, project, ref string) (gen.DriftResult, error)

FindDriftResult resolves a project's drift check by id or a unique id prefix.

func (*Client) FindIntegration

func (c *Client) FindIntegration(ctx context.Context, ref string) (gen.Integration, error)

FindIntegration resolves an integration by id or name.

func (*Client) FindProject

func (c *Client) FindProject(ctx context.Context, ref string) (gen.Project, error)

FindProject resolves a project by id, slug or name.

func (*Client) FindScenario

func (c *Client) FindScenario(ctx context.Context, project, ref string) (gen.Scenario, error)

FindScenario resolves a scenario in a project by id or name.

func (*Client) FindScenarioIn

func (c *Client) FindScenarioIn(ctx context.Context, project, ref string) (gen.Scenario, error)

FindScenarioIn resolves a scenario by id, name or a unique id prefix.

func (*Client) FindTarget

func (c *Client) FindTarget(ctx context.Context, project, ref string) (gen.Target, error)

FindTarget resolves a target in a project by id, name or base URL.

func (*Client) FindToken

func (c *Client) FindToken(ctx context.Context, ref string) (gen.Token, error)

FindToken resolves one of the caller's API tokens by id, name or prefix.

func (*Client) FindUser

func (c *Client) FindUser(ctx context.Context, ref string) (gen.User, error)

FindUser resolves a member of the organisation by id or email.

func (*Client) Follow

func (c *Client) Follow(ctx context.Context, runID string, fn func(Event)) error

Follow streams a run's live events until it ends or ctx is done.

func (*Client) Projects

func (c *Client) Projects(ctx context.Context) ([]gen.Project, error)

Projects lists projects.

type Config

type Config struct {
	Server  string `yaml:"server"`
	Token   string `yaml:"token"`
	Project string `yaml:"project,omitempty"`
}

Config is what `stampede login` stores.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig reads the stored config; env vars STAMPEDE_SERVER, STAMPEDE_TOKEN and STAMPEDE_PROJECT override it.

func ReadConfigFile

func ReadConfigFile() (Config, error)

ReadConfigFile reads the stored config without environment overrides.

type Event

type Event struct {
	Type string
	Data []byte
}

Event is one server-sent event from a live run.

Jump to

Keyboard shortcuts

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