orgs

package
v0.24.0 Latest Latest
Warning

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

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

Documentation

Overview

Package orgs turns what the user typed for --org (an id or a slug) into an organization id the services accept. Services only take ids; a slug is looked up in the organizations the user belongs to, and the answer is cached for a day so repeated commands don't pay for the round trip.

Index

Constants

View Source
const CacheTTL = 24 * time.Hour

CacheTTL is how long a slug→id answer is reused.

Variables

This section is empty.

Functions

func Find

func Find(list []api.Organization, value string) (api.Organization, bool)

Find returns the organization in list whose id equals value or whose slug equals it, ignoring case.

func IsID

func IsID(v string) bool

IsID reports whether v has the shape of an organization id (a UUID).

func ScopeKey

func ScopeKey(profile, authURL, userID string) string

ScopeKey is the cache key of one profile's organizations.

Types

type Cache

type Cache struct{ Path string }

Cache is a small JSON file of the organizations each signed-in user belongs to. It holds no secrets (ids, slugs and names only). Every failure to read or write it is ignored: it only saves a round trip.

func DefaultCache

func DefaultCache() *Cache

DefaultCache lives in the user cache directory (~/Library/Caches, $XDG_CACHE_HOME, %LocalAppData%).

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes every cached organization. Used on logout --all.

func (*Cache) ClearProfile

func (c *Cache) ClearProfile(profile string) error

ClearProfile forgets the organizations cached for one profile. Used on logout.

type NotFoundError

type NotFoundError struct{ Value string }

NotFoundError: the value matched none of the user's organizations.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Resolver

type Resolver struct {
	// Profile, AuthURL and UserID scope the cache, so slugs never leak
	// between profiles, environments or accounts.
	Profile string
	AuthURL string
	UserID  string
	// Active is the persisted active organization; a value naming it is
	// answered without a network call.
	Active api.Organization
	// List fetches the user's organizations.
	List func(ctx context.Context) ([]api.Organization, error)
	// Cache may be nil (no caching).
	Cache *Cache
	// Now is replaced in tests.
	Now func() time.Time
}

Resolver resolves --org values for one signed-in user.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, value string) (api.Organization, error)

Resolve returns the organization value names. An id is returned as is, with slug and name filled in when they are known locally; the server checks membership when the token is minted. An unknown slug is a usage error (exit 2).

Jump to

Keyboard shortcuts

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