credentials

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 44 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// Waiting out a limit
	Exhausted = "exhausted"
	// Refused for good, until signed in again
	Dead = "dead"
)

States an account's credential can be in, as icebath last found it

View Source
const (
	Ready       = "ready"
	Limited     = "limited"
	NeedsSignIn = "needs_sign_in"
	Gone        = "dead"
	Unavailable = "unavailable"
)

States an account lists with

View Source
const (
	OAuth  = "oauth"
	APIKey = "api-key"
)

Ways of signing in by --type

View Source
const Expired = "device_code_timeout"

Code a sign in that waited out its device code fails with

Variables

View Source
var ErrCancelled = errors.New("The sign-in was cancelled.")

Sign in the person stopped, or whose prompt closed

View Source
var ErrNotRenewable = errors.New("Nothing renews this account, because it is an API key or a sign-in that can't renew itself.")

Error of an account whose credential nothing renews

View Source
var Fires = []hooks.Site{
	{Point: hooks.AccountExhausted, By: "the accounts of providers", When: "as an account reaches a limit or its sign-in is refused"},
}

The moments of the accounts of providers the hook points hear of, which the hooks screen and Doctor say of each point

Functions

func Cancelled

func Cancelled(err error) bool

Whether the sign in ended because the person stopped it

func CarriedSeats

func CarriedSeats(accounts map[string]string, change provider.Change) (map[string]string, bool)

Accounts a session is on carried through a provider or an account renamed or removed, and whether they changed

func Certificate

func Certificate(dir string) (tls.Certificate, error)

Certificate this computer serves an https redirect of a sign-in with: the one kept in the folder while it reads and holds for a week more, else one made now for 127.0.0.1, ::1 and localhost and kept there, its key readable by this user alone

func Checking

func Checking(ctx context.Context) context.Context

Context of a check of a sign-in the person asked for, under which a report may ask the provider who the sign-in is and whether it gives a token, which a look at a provider never does

func Checks

func Checks(ctx context.Context) bool

Whether the report is of a check the person asked for, rather than a look

func Claims

func Claims(token string) map[string]any

Unverified claims of a JWT, empty for any other token

func Client

func Client(env httpx.Env, timeout time.Duration) *http.Client

Client for OAuth endpoints through the proxy and authorities of the environment, the profile's, each call ending within the timeout

func Compact

func Compact(env httpx.Env, timeout time.Duration) *http.Client

Client as Client gives it whose secure connections offer only the classic key exchanges, leaving out the post-quantum one whose larger first message some networks refuse, so a sign-in such a network stopped can go on without a restart

func Delay

func Delay(message string) (time.Duration, bool)

Wait a refusal's text names before its limit lifts, false when it names none

func FailureLines

func FailureLines(err error, host string) []string

Lines a failed sign in prints: why in words the person can act on, then the details when it didn't stop on its own. The sign-in is tried again in /providers

func Fingerprint

func Fingerprint(secret string) string

Short mark of a secret that tells two apart without showing either: the last six hex characters of its SHA-256

func Identity

func Identity(token string) string

Who a token signs in as, from its claims: the email, else the user name, empty when it says neither

func JWTExpiry

func JWTExpiry(token string) time.Time

When a JWT expires, zero when it isn't one or says nothing of it

func PKCE

func PKCE(n int) (verifier, challenge string)

PKCE code verifier made of n random bytes, at most 128 characters, and its S256 challenge

func Relogin

func Relogin(title string) string

Sentence that tells where a provider is signed in again, the provider by the name a person knows it by, such as its label

func Remote

func Remote() bool

Whether this runs where the person's browser is not

func Sleep

func Sleep(ctx context.Context, d time.Duration) error

Sleeps for d unless ctx ends first, ErrCancelled when it does

func SourceName

func SourceName(source string) string

Variable or program the source of a credential names, as a provider leaves it out or takes it again by: without the secret store that supplied the variable

func Text

func Text(value any) string

Text a JSON field holds, trimmed, empty for anything that isn't text

func Unreachable

func Unreachable(err error) bool

Whether a failure is one of reaching the provider: a refused or reset connection, a name that doesn't resolve, a timeout

func Usable

func Usable(value string) bool

Whether a secret looks like one that can work rather than nothing or a placeholder of an example file

func Words

func Words(credential Credential) string

Credential outside the accounts as a sentence names it: the key in a variable, or the sign-in another program keeps on this computer

Types

type Account

type Account struct {
	Name     string
	Provider provider.Instance
	Fields   config.View
}

One account of a provider of the profile: the fields it keeps, under the provider's accounts. Its credential is what it keeps alone: a secret of its own, the variable it reads its key from, or the program whose sign-in it uses. The account with no name and no fields is the provider's credential outside its accounts, which comes from the environment or another program's sign-in on this computer

func Carried

func Carried(instance provider.Instance, route provider.Route) Account

Account whose credential a route of the provider carries: the account the route names, else the credential outside its accounts

func Of

func Of(instance provider.Instance, name string) Account

Account of the provider with the name, the one the provider's choice names for no name; with none, its credential outside its accounts

func Outside

func Outside(instance provider.Instance) Account

Credential the provider takes from outside its accounts: from the variables of its kind or the sign-in of another program on this computer, those it ignores left out

func (Account) Holds

func (a Account) Holds(except ...string) bool

Whether the account keeps text that signs in, usable or not, besides the fields named: a secret or a choice its kind keeps, the variable it reads its key from or the program whose sign-in it uses

func (Account) Ignores

func (a Account) Ignores(source string) bool

Whether the provider of the account may not take its credential from the source, a variable or another program by name

func (Account) Lookup

func (a Account) Lookup(field string, variables ...string) (Credential, bool)

Credential of a key: for an account, the key kept in its field, else the one in the variable it reads its key from; for the credential outside the accounts, the first of the variables set that its provider doesn't ignore

func (Account) Program

func (a Account) Program() string

Program whose sign-in on this computer the account uses, empty for one that uses none

func (Account) Rewrite

func (a Account) Rewrite(fields map[string]any) error

Writes the fields given into the account in one write of its whole entry, a nil value taking a field away, so no reader sees part of the change, such as a renewed token without its refresh token

func (Account) Spec

func (a Account) Spec() string

Kind of the provider the account is of

type AuthError

type AuthError struct {
	// Kind of provider it is of
	Provider string
	// Stable name of the failure, such as invalid_grant or device_code_timeout
	Code    string
	Message string
	// Only signing in again helps
	Relogin bool
	// Wait the provider asked for before trying again, zero when it asked none
	RetryAfter time.Duration
	Err        error
}

Failure of a sign in or of the renewal of its credential, saying whether only signing in again can fix it

func Failed

func Failed(provider, code, message string, relogin bool, cause error) *AuthError

Failure of the provider's sign in with its code, wrapping the cause when there is one

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

type Callback

type Callback struct {
	// Address the provider redirects the browser to
	Redirect string
	// contains filtered or unexported fields
}

Local server a browser sign in sends its answer back to

func Listen

func Listen(host string, port int, path, name, busy string) (*Callback, error)

Listens on the loopback port for the redirect to the path, refusing when the port is taken with the code given. Port 0 takes any

func ListenOn

func ListenOn(redirect, name, busy, certs string) (*Callback, error)

Listens for a sign-in's redirect at the address as it is registered with the provider, such as http://127.0.0.1:43827/callback: on its host, which must be one of this computer, its port, which must be given, and its path; over TLS for an https address, with a certificate of this computer kept in the folder certs, which a browser warns of once. Redirect is the address as given, which the provider compares with the one it holds. Refused with the code busy when the port is taken

func (*Callback) Close

func (c *Callback) Close()

Stops listening

func (*Callback) Deliver

func (c *Callback) Deliver(pasted string) error

Takes the address the browser ended on, pasted by a person whose browser could not reach this computer: the whole address or its query. Refused for text that holds no code and no error, and once the sign-in has its answer

func (*Callback) Wait

func (c *Callback) Wait(ctx context.Context, timeout time.Duration, state, provider string) (string, error)

Waits for the browser to come back, at most the timeout, and stops listening. The answer's code once its state is the one sent, for a sign-in that sent one

type Credential

type Credential struct {
	APIKey  string
	BaseURL string
	// BaseURL as the settings it was read from write it, every ${NAME} kept, for an address read from settings of the account; empty for
	// one read from nowhere a person writes or made from the provider's own, which the provider's Address puts back
	Address provider.Written
	Auth    provider.AuthKind
	Origin  Origin
	// Variable or program the credential came from, empty for one saved in icebath
	Source string
	// Headers its requests carry, such as the ChatGPT account a Codex sign-in is of
	Headers map[string]string
	// When it stops working, zero when it doesn't or that isn't known
	Expires time.Time
	// Who it signs in as, such as an email; never a secret
	Identity string
	// Signs each request, for a credential that signs requests rather than sending a key, such as AWS SigV4
	Sign func(request *http.Request, body []byte) error
	// Region its requests are signed for and served in, such as an AWS region; empty when its provider has none
	Region string
	// Address of another service of its provider in a region, resolved as BaseURL was, such as the control plane of Bedrock; nil for a
	// provider of one address
	Endpoint func(service, region string) (string, error)
}

func Lookup

func Lookup(fields config.View, field string, variables ...string) (Credential, bool)

Credential kept in the field of the account, else in the first of the variables the account's profile has set, a variable a secret store supplied naming the store

type Credentials

type Credentials struct {
	Registry
}

func New

func New() *Credentials

func (*Credentials) Close

func (c *Credentials) Close() error

Nothing runs behind the credentials, so closing them ends nothing

func (*Credentials) Follow

func (c *Credentials) Follow(_ context.Context, cfg *config.Config, change provider.Change) ([]string, error)

Carries the ledger along a change of a provider or an account: the statuses of one removed go, those of one renamed move to its new name

func (*Credentials) Hooking

func (c *Credentials) Hooking(host *hooks.Hooks)

Hands over the hooks host, whose hooks hear of an account benched as it reached a limit or its sign-in was refused

func (*Credentials) Keep

func (c *Credentials) Keep(cfg *config.Config)

Renews the credentials of the config's profiles under its folder's locks, reading the config again before each renewal so that what another process renewed is seen, and keeps what it learns of their accounts in each profile's state folder

func (*Credentials) Register

func (c *Credentials) Register(registrant Registrant)

Adds a registrant, a nested registry sharing what the host keeps of its accounts

type Detail

type Detail struct {
	Name  string
	Value string
}

One thing a status says of a sign-in, such as its region or who it signs in as

type Explainer

type Explainer interface {
	Why(account Account) (string, bool)
}

Registrant that can say why it has no credential for an account of a kind it keeps, such as what the token service it asked answered; false when it has nothing to say

type Files

type Files[T any] struct {
	// contains filtered or unexported fields
}

What was made of files on this computer, such as the sign-in another program keeps in one, by the path of each: used again while the file keeps its version and for a minute at most, made again once it moves or the file comes or goes, and made on each use while the file changed a moment ago, as a change right after it may keep its version. What this code writes to a file is seen at once, since a write forgets what was made of it. What is kept is what a read already holds in memory as it is used, and only for that minute

func (*Files[T]) Forget

func (f *Files[T]) Forget(path string)

Forgets what was made of the file at the path, so the next read reads it, as after this code wrote or removed it

func (*Files[T]) Read

func (f *Files[T]) Read(path string, read func() T) T

What read makes of the file at the path: what it made before while the file is as it was then and a minute has not passed, else made now and kept once the file is settled

type Keyed

type Keyed struct {
	Provider  string
	Variables []string
}

Credential of a kind whose accounts keep an API key, read from the environment when an account keeps none

func (Keyed) Credential

func (k Keyed) Credential(account Account) (Credential, bool)

type Lifecycle

type Lifecycle struct {
	Providers *provider.Registry
	// What keeps the states of the accounts, whose limits a new key clears
	Credentials *Registry
}

What else changes when a credential variable of a profile's .env is set or removed, as config set and unset do: the copies of its value kept in api key settings, the providers that read it, and what holds back the accounts it is the key of

func (Lifecycle) Removed

func (l Lifecycle) Removed(cfg *config.Config, name, old string) (bool, error)

After the variable was removed: the providers that read it leave it out from now on by the one control of that choice, so a shell that still exports it can't give it back until it is set again, and copies of its old value in api key settings are removed, with the accounts they were the one credential of. Whether a setting held a copy

func (Lifecycle) Saved

func (l Lifecycle) Saved(cfg *config.Config, name, old, value string) error

After the variable was saved over the value it held: copies of the old value in api key settings take the new one, the providers that read it take it from it again by the one control of that choice, and what held back the accounts it is the key of on the old value is cleared

type Look

type Look struct {
	// contains filtered or unexported fields
}

One look at the credentials of providers, for a page or an answer that tells of many accounts at once and asks after the same account more than once: what the registrants find for each account, and why they find none, is asked of them once for the look. It reads as the registry reads, nothing renewed, probed or written, and is made for one call and dropped with it, so it holds no credential longer than the call does

func (*Look) Credential

func (l *Look) Credential(account Account) (Credential, bool)

Credential of the account, as the registry finds it

func (*Look) Missing

func (l *Look) Missing(account Account) string

Why the account has no credential to use now, as the registry's Missing says

func (*Look) Report

func (l *Look) Report(ctx context.Context, account Account) ([]Detail, bool)

What the account's registrant says of its sign-in beyond its credential, as the registry's Report says

func (*Look) State

func (l *Look) State(account Account) (string, time.Time)

How the account lists, as the registry's State says

func (*Look) Status

func (l *Look) Status(account Account) Status

What icebath learned of the account, as the registry's Status reads it

func (*Look) View

func (l *Look) View(instance provider.Instance, model, held string, wires map[provider.APIMode]provider.Factory) (Viewed, error)

What a request to the provider for the model would go out with now, as the registry's View reads it

type Origin

type Origin int

Where a credential was found

const (
	// Saved in an account of the provider
	Saved Origin = iota + 1
	// Read from an environment variable, the one the source names
	Environment
	// Taken from the sign in of another program, the one the source names
	External
	// None is needed, the stand in of a server on this machine
	Unneeded
)

type Poll

type Poll struct {
	Provider string
	Post     func() (*Reply, error)
	Expires  time.Duration
	Interval time.Duration
	// Checks the answer that granted the sign in
	Granted func(payload map[string]any) error
}

One RFC 8628 token poll: what to post, how long the code lives and how often to ask

func (Poll) Run

func (p Poll) Run(ctx context.Context) (map[string]any, error)

Polls for the token of a device code: pending and slow_down pace it, an edge that throttles is waited out, any other error ends it

type Profiles

type Profiles struct {
	Credentials *Credentials
	Providers   *provider.Registry
	Config      *config.Config
}

What the accounts of providers do as profiles are made: a copy of a profile drops the sign-ins whose refresh token works once, a copy made without credentials drops every account that kept a key or a sign-in of its own, and a fresh profile takes the providers and accounts of the profile it is made from without those

func (Profiles) Delete

func (Profiles) Delete(string) error

Accounts live in the profile's config.yaml, which goes with it

func (Profiles) Made

func (p Profiles) Made(making profile.Making) ([]string, error)

type Prompter

type Prompter struct {
	Ctx context.Context
	// What the sign in says as it goes
	Out io.Writer
	// Asks for a line of text, masked when secret; false once the person gave up
	Ask func(label string, secret bool) (string, bool)
	// Shows the address to open and the code to type there, the code empty when there is none
	Show func(link, code string)
	// Opens an address in a browser of this computer
	Open func(link string) error
	// Whether the sign in may open the browser by itself
	Browser bool
	// How long one step may wait, zero for the flow's own
	Timeout time.Duration
	// Flags of the sign in by name, such as browser for a Codex browser sign in or region for MiniMax's
	Options map[string]string
	// The sign in runs at the terminal of a command rather than on the app's sign in page, so it may say what only a terminal does, such
	// as how ctrl+c stops it
	Terminal bool
	// Settings of the provider the account is of, by their names below it, as the front end read them
	Settings map[string]string
	// Variables of the computer the sign in runs on as the front end that runs it reads them: what its requests' proxy and authorities
	// come from and what it reads of that computer; the profile's own values come in Settings
	Env httpx.Env
	// Profile the account is of, as the front end names it; the one of its window when empty
	Profile string
}

What a sign in that runs in the front end talks to the person through: the app's sign in page, or the terminal of a command

func (*Prompter) Instructions

func (p *Prompter) Instructions(link, code string)

Tells the person where to go and what code to type there: through Show on a page that shows them itself, else in lines. Then opens the address when the sign in may

func (*Prompter) OpenBrowser

func (p *Prompter) OpenBrowser(link, opened, failed string)

Opens the address in this computer's browser when the sign in may and one is here, saying how that went

func (*Prompter) Option

func (p *Prompter) Option(name string) string

Flag of the sign in by name, trimmed

func (*Prompter) Pending

func (p *Prompter) Pending(text string)

Says what the sign in waits for, and at a terminal how to stop it

func (*Prompter) Say

func (p *Prompter) Say(format string, args ...any)

Says one line

func (*Prompter) Tunnel

func (p *Prompter) Tunnel(redirect string)

Tells a person on a remote session how to tunnel the redirect to this machine before opening the address

func (*Prompter) Wait

func (p *Prompter) Wait(fallback time.Duration) time.Duration

Timeout of the sign in, else the flow's own

type Registrant

type Registrant interface {
	Credential(account Account) (Credential, bool)
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func (*Registry) Adopt

func (r *Registry) Adopt(providers *provider.Registry, cfg *config.Config, kind string) (provider.Instance, string, bool)

The profile's provider of the kind. When the profile has none and a credential of the kind is found in the profile's environment or in another program on this computer, the provider is added to the profile, the first time it is needed, and the sentence that says so is given; false when there is neither

func (*Registry) Counting

func (r *Registry) Counting(count Sessions)

Hands over what counts the ongoing sessions on each account, which "Take turns" gives a new session the account with the fewest of

func (*Registry) Credential

func (r *Registry) Credential(account Account) (Credential, bool)

func (*Registry) Detect

func (r *Registry) Detect(cfg *config.Config, spec provider.Spec) (Credential, bool)

Credential of a kind no provider of the profile has yet, found in the profile's environment or another program

func (*Registry) Due

func (r *Registry) Due(account Account) bool

func (*Registry) First

func (r *Registry) First(cfg *config.Config, providers *provider.Registry, wires map[provider.APIMode]provider.Factory) (provider.Instance,
	string, error)

Provider a new session of the profile uses when its settings name none, which the session keeps from then on. icebath looks in this order: a kind taken first whose credential is found, such as an OpenRouter key; the provider of the profile signed in first, in the order the kinds are registered, unless a key of another kind is set in the profile's environment, which wins; the first kind with a key in the profile's environment; a provider of the profile ready with a credential found anywhere; a kind taken last whose credential is found outside icebath, such as AWS's. Only providers ready by the test the providers page uses are taken, and none on this computer, which a person adds themselves. A kind the profile has no provider of yet is added to it, with the sentence that says so. Keys count only from the profile's own environment, its .env, its secret stores and the files beside them, never the environment of the process that asks, so every terminal on the profile finds the same provider

func (*Registry) Frees

func (r *Registry) Frees(instance provider.Instance, model string) (time.Time, bool)

When the first account the provider's choice allows frees up, while none can take a request for the model now; false while one can, or when nothing says when one frees up

func (*Registry) Kind

func (r *Registry) Kind(ctx context.Context, providers *provider.Registry, cfg *config.Config, kind string) (provider.Route, bool)

Route of a tool's call to a kind of model provider, such as an image service that takes the OpenAI key: the profile's provider of the kind, added to the profile the first time a credential of the kind is found for it, with the account its choice gives, renewed when due. False when there is neither

func (*Registry) KindView

func (r *Registry) KindView(providers *provider.Registry, cfg *config.Config, kind string) (provider.Route, bool)

Route of the profile's provider of the kind read as it is kept, for a page or a list that reads what the provider offers: nothing is renewed or added; false while the profile has no provider of the kind or it has no credential

func (*Registry) Look

func (r *Registry) Look() *Look

Look at the credentials of the registry, for one call

func (*Registry) Missing

func (r *Registry) Missing(account Account) string

Why the account has no credential to use now, in sentences about it, empty while it has one: the program or service it signs in with as its registrant says, the variable it reads its key from unset, what it keeps unusable, or nothing kept at all

func (*Registry) Offers

func (r *Registry) Offers(providers *provider.Registry, cfg *config.Config, kind string) bool

Whether a tool's call to the kind could go out now, for a page that shows whether the kind can be used: the profile's provider of the kind read as it is kept, else a credential of the kind found where Kind would add the provider from. Nothing is renewed or added

func (*Registry) Refresh

func (r *Registry) Refresh(ctx context.Context, account Account, force bool) error

Renews the account's credential when it is due, or now when forced, one renewal at a time across processes. What another process renewed meanwhile is taken instead of renewing again. A refusal that only signing in again fixes leaves the account dead

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

Adds a source of credentials to the host's one list. A registry registered into another hands over its sources once, and from then on registers into the host and answers as the host does, so no list is nested in another

func (*Registry) Renew

func (r *Registry) Renew(ctx context.Context, account Account) (bool, error)

func (*Registry) Report

func (r *Registry) Report(ctx context.Context, account Account) ([]Detail, bool)

What the account's registrant says of its sign-in beyond its credential

func (*Registry) Reset

func (r *Registry) Reset(account Account) (bool, error)

Clears what stands against the account: its limit, its held back models and its refused speeds. Whether there was any

func (*Registry) Restored

func (r *Registry) Restored(ctx context.Context, account Account) bool

func (*Registry) Rotates

func (r *Registry) Rotates(account Account) bool

Whether the account holds a sign-in its refresh token can renew only once

func (*Registry) Route

func (r *Registry) Route(ctx context.Context, instance provider.Instance, model string, seat *Seat) (provider.Route, error)

Route of a request to the provider for the model, renewed when due, with a keeper that renews it or moves on to the next account when the provider refuses it. A seat keeps the session on its account: the route goes out with the account the seat holds while the provider's choice allows it and it can take the request, else with one chosen anew, which the seat keeps on the session's record. A nil seat is a request of no session, which goes out with the account the choice gives now

func (*Registry) Slow

func (r *Registry) Slow(instance provider.Instance, account, model string, until time.Time) error

Keeps that the provider refused the faster speed of the model for the account, the credential outside the accounts for none, until the time given

func (*Registry) Slowed

func (r *Registry) Slowed(instance provider.Instance, account, model string) time.Time

When the account, the credential outside the accounts for none, may be asked for the faster speed of the model again, zero while nothing holds it back

func (*Registry) SlowedModels

func (r *Registry) SlowedModels(instance provider.Instance) map[string]map[string]time.Time

Every model of the provider whose faster speed is held back now for one of its accounts, the credential outside the accounts under the empty name, with when it is asked for again, by account

func (*Registry) Stale

func (r *Registry) Stale(account Account, failure *provider.APIError) bool

func (*Registry) State

func (r *Registry) State(account Account) (string, time.Time)

How an account lists: ready, limited until a time, waiting to be signed in again, gone for good, or without a credential to use

func (*Registry) Status

func (r *Registry) Status(account Account) Status

Status of the account as the ledger of its profile holds it; none for the credential outside the accounts

func (*Registry) View

func (r *Registry) View(instance provider.Instance, model, held string, wires map[provider.APIMode]provider.Factory) (Viewed, error)

What a request to the provider for the model would go out with now, read from what is kept alone: nothing is renewed, probed or written, so a page that shows it never renews a sign-in another process or program shares. Held is the name of the account a session is on, as its record keeps it, empty for none: the view keeps to it while the provider's choice allows it and it can take a request. With wires given, a provider whose API is none that icebath sends is not ready either. Nil while a request can go to the provider, else why not in words a person acts on

func (*Registry) Why

func (r *Registry) Why(account Account) (string, bool)

Why the account has no credential, as the first of its registrants with something to say says it; false when none says

type Renewer

type Renewer interface {
	// Whether the account's credential is close enough to expiring to be renewed before it is used
	Due(account Account) bool
	// Renews the account's credential now, keeping what it renewed in the account or where the program it came from keeps it; false
	// when the account holds nothing it renews
	Renew(ctx context.Context, account Account) (bool, error)
}

Registrant whose credentials expire and that it renews, such as an OAuth sign-in

type Reply

type Reply struct {
	Status int
	Header http.Header
	Body   []byte
}

Answer of an OAuth endpoint, read whole

func Do

func Do(client *http.Client, request *http.Request) (*Reply, error)

Sends the request and reads its answer whole, refusing one larger than an OAuth endpoint sends

func Get

func Get(ctx context.Context, client *http.Client, address string, header map[string]string) (*Reply, error)

Gets the address, with the headers given

func PostForm

func PostForm(ctx context.Context, client *http.Client, endpoint string, form url.Values, header map[string]string) (*Reply, error)

Posts a form, with the headers given

func PostJSON

func PostJSON(ctx context.Context, client *http.Client, endpoint string, body any, header map[string]string) (*Reply, error)

Posts a JSON body, with the headers given

func (*Reply) JSON

func (r *Reply) JSON() (map[string]any, error)

Body as a JSON object, an empty one for JSON of another shape, an error for anything that isn't JSON

func (*Reply) RetryAfter

func (r *Reply) RetryAfter() (time.Duration, bool)

Wait the answer asks for before trying again, false when it asks none

func (*Reply) Text

func (r *Reply) Text(limit int) string

Body as text, cut to limit characters with a mark when longer

type Reporter

type Reporter interface {
	Report(ctx context.Context, account Account) ([]Detail, bool)
}

Registrant that says more of an account's sign-in than its credential does, such as the identity and region AWS signs as. A look says only what is kept or on this computer; under Checking it may ask the provider or mint a token, as a check the person asked for does. False for an account it doesn't keep

type Restorer

type Restorer interface {
	Restored(ctx context.Context, account Account, status Status) bool
}

Registrant that can tell an account's limit lifted before the time it was given, such as a Codex plan whose window reset early; status is what icebath learned of the account

type Rotating

type Rotating interface {
	Rotates(account Account) bool
}

Registrant whose sign-ins hold a refresh token that works once, so a copy of one in another profile breaks the sign-in it was copied from the first time either renews

type Seat

type Seat struct {
	// contains filtered or unexported fields
}

Accounts a session is on, one for each provider its requests went to, its main model's, a fallback's, a mixture's or a helper's, by the account's name: the empty name for the credential outside the accounts. A session is on no account of a provider before its first request there. An account stays the session's until it runs out, is refused, or the person picks another, also after the session is run again in another process, as its record keeps every one. "Take turns" counts the sessions on an account by these

func NewSeat

func NewSeat(session string, accounts map[string]string, keep func(accounts map[string]string) error) *Seat

Seat of the session on the accounts its record names by provider id, none for none yet, kept on its record through keep

func (*Seat) AccountOn

func (s *Seat) AccountOn(provider string) string

Account the seat holds on the provider, empty for none or the credential outside the accounts

func (*Seat) Accounts

func (s *Seat) Accounts() map[string]string

Accounts the seat holds, by provider id

func (*Seat) Follow

func (s *Seat) Follow(change provider.Change) (bool, error)

Carries the seat through a provider or an account renamed or removed: the account of a provider removed, or an account removed, is let go of, so the next request there chooses again; a renamed one takes its new name. Whether the seat changed, kept on the record first

func (*Seat) Session

func (s *Seat) Session() string

Session of the seat, empty for none

type Sessions

type Sessions func(ctx context.Context, profile, provider string) (map[string]int, error)

Ongoing sessions of the profile on each account of the provider, by account name, across every process working on the profile: the sessions a live process runs, not ended, whose record keeps them on the account of the provider

type SignIn

type SignIn struct {
	// Kind of provider it signs in, by the name of its spec
	Spec string
	// Shown as the way to connect, such as "ChatGPT account"
	Title string
	// Name auth add --type takes it by: oauth for a sign in, api-key for a key given some other way
	Type string
	Run  func(p *Prompter) (Signed, error)
}

Way to sign an account of a kind in that runs in the front end, which the plugin's app and cli hooks offer

type Signed

type Signed struct {
	Fields map[string]any
	// Such as an email, which names an account no name was asked for
	Identity string
}

Fields an account keeps after a sign in, by their names below it, and who it signed in as

type Staler

type Staler interface {
	Stale(account Account, failure *provider.APIError) bool
}

Registrant that knows refusals besides a 401 which renewing its credentials fixes, such as a Copilot token a model was moved off

type Status

type Status struct {
	// Exhausted while it waits out a limit, Dead once its credential was refused for good, empty while nothing stands against it
	State   string    `json:"state,omitempty"`
	At      time.Time `json:"at,omitzero"`
	Code    int       `json:"code,omitempty"`
	Reason  string    `json:"reason,omitempty"`
	Message string    `json:"message,omitempty"`
	// When the limit lifts, zero when the provider didn't say
	Resets time.Time `json:"resets,omitzero"`
	// Models the account may not use until the time each gives, its other models unaffected
	Cooldowns map[string]time.Time `json:"cooldowns,omitempty"`
	// Models whose faster speed the provider refused for the account, until the time each gives
	Slowed map[string]time.Time `json:"slowed,omitempty"`
	// When a session last took the account
	Used time.Time `json:"used,omitzero"`
}

What icebath learned of one account

func (Status) Cooled

func (s Status) Cooled(model string) time.Time

When the model may be used with the account again, zero when nothing holds it back; for no model, the latest of every model held back

func (Status) Until

func (s Status) Until(sole bool) time.Time

When an exhausted account is tried again, zero for one that isn't exhausted

type Unready

type Unready struct {
	Text, Short string
	Instead, Of string
	Frees       time.Time
}

Why a provider can't take a request now: whole, as a refusal of the request says it; as the first line of its page says it, the one thing wrong and the one thing to do; the other way out, said in the pane of the option whose setting is named below the provider; and when the first account it may use frees up, zero when that isn't known

func (*Unready) Error

func (u *Unready) Error() string

type Viewed

type Viewed struct {
	Route      provider.Route
	Account    Account
	Credential Credential
}

What a request to a provider would go out with now: its route, the account and the credential, the account with no name being the credential outside the accounts

Directories

Path Synopsis
Package aws resolves AWS credentials the way the AWS CLI and SDKs do, and signs requests with them by SigV4
Package aws resolves AWS credentials the way the AWS CLI and SDKs do, and signs requests with them by SigV4

Jump to

Keyboard shortcuts

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