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 ¶
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.
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) ClearProfile ¶
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.