platform

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package platform is a typed HTTP client for the platform's REST API.

This file holds hand-written wrappers for endpoints the CLI uses directly. Auto-generated wrappers (oapi-codegen output) live alongside under client/.

Package platform wires the generated platform commands and the override registry into the CLI's root command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTo

func AddTo(root *cobra.Command) error

AddTo registers the generated platform commands and their overrides under the given root command.

The platform client is constructed lazily: AddTo wires a `PersistentPreRunE` that rebuilds it on each invocation from the parsed --api-url / --token flags, falling back to the credentials store. Without this, those root-level flags were declared but silently ignored because the client had already been frozen at command-tree construction time.

The function passed to the generated New*Cmd constructors returns the current client, so a missing/empty credentials store still produces a usable command tree (with an empty bearer token) and `--help` works even before `yomiro auth login`.

Types

type APIKey

type APIKey struct {
	ID         string   `json:"id"`
	Name       string   `json:"name"`
	Prefix     string   `json:"prefix"`
	Scopes     []string `json:"scopes"`
	ExpiresAt  *string  `json:"expires_at"`
	CreatedAt  string   `json:"created_at"`
	LastUsedAt *string  `json:"last_used_at"`
	RevokedAt  *string  `json:"revoked_at"`
}

APIKey mirrors backend ApiKeyPublic.

type APIKeyList

type APIKeyList struct {
	Data  []APIKey `json:"data"`
	Count int      `json:"count"`
}

APIKeyList mirrors ApiKeysPublic.

type Client

type Client struct {
	BaseURL string
	Token   string
	HTTP    *http.Client
}

Client is a thin wrapper around net/http for the platform API.

func New

func New(baseURL, token string) *Client

New returns a Client. baseURL should be the platform origin without trailing slash.

func (*Client) CreateAPIKey

func (c *Client) CreateAPIKey(req CreateKeyRequest) (*CreatedKey, error)

CreateAPIKey mints a new key. The cleartext token is in the response.

func (*Client) CurrentOrganization

func (c *Client) CurrentOrganization() (*CurrentOrganization, error)

CurrentOrganization returns the tenant the bearer token resolves to.

func (*Client) ListAPIKeys

func (c *Client) ListAPIKeys() (*APIKeyList, error)

ListAPIKeys returns all keys for the current user.

func (*Client) RevokeAPIKey

func (c *Client) RevokeAPIKey(keyID string) error

RevokeAPIKey soft-deletes a key by ID.

func (*Client) Whoami

func (c *Client) Whoami() (*CurrentUser, error)

Whoami returns the current user, with the tenant display name resolved via a follow-up GET /organizations/me. The latter is best-effort: if the caller's token doesn't have org scope or the user has no tenant_id, the Tenant fields stay at their zero values rather than the call erroring.

type CreateKeyRequest

type CreateKeyRequest struct {
	Name      string   `json:"name"`
	Scopes    []string `json:"scopes"`
	ExpiresAt *string  `json:"expires_at,omitempty"`
}

CreateKeyRequest is the POST body for /api-keys.

type CreatedKey

type CreatedKey struct {
	Key   APIKey `json:"key"`
	Token string `json:"token"`
}

CreatedKey mirrors ApiKeyCreatedResponse — Token is shown only here.

type CurrentOrganization

type CurrentOrganization struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	InternalID string `json:"internal_id"`
}

CurrentOrganization is a minimal mirror of TenantPublic — only what the CLI surfaces in post-login output today.

type CurrentUser

type CurrentUser struct {
	ID       string `json:"id"`
	Email    string `json:"email"`
	TenantID string `json:"tenant_id"`
	Tenant   struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"-"`
}

CurrentUser mirrors a subset of UserPublic — used by `whoami`. The backend's UserPublic schema returns `tenant_id` (flat UUID), not a nested tenant object; the display-friendly `Tenant.Name` is fetched separately via CurrentOrganization (GET /api/v1/organizations/me).

Directories

Path Synopsis
Package bindings wires generated platform-cmd subcommands to cobra flags and JSON request bodies.
Package bindings wires generated platform-cmd subcommands to cobra flags and JSON request bodies.
Package client provides primitives to interact with the openapi HTTP API.
Package client provides primitives to interact with the openapi HTTP API.
Code generated by gen-platform-cmds.
Code generated by gen-platform-cmds.
Package overrides holds hand-written cobra subcommands that take precedence over the OpenAPI-generated ones.
Package overrides holds hand-written cobra subcommands that take precedence over the OpenAPI-generated ones.

Jump to

Keyboard shortcuts

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