Skip to content
pi-c Documentation
Login

Documentation

/* Free checks of a key: what a provider will say about a key without being
 * sent a conversation (its key or balance endpoint, or its models list).
 * The adapter of the provider's API says what to ask (provider_http.h,
 * pic_provider_probe); this asks it of every wanted key at once, each with
 * its own deadline, and records what comes back in picu_credential_health
 * (cred.h): remaining credit, or valid, refused, out of credit, limited. A
 * check sends the key only to the base URL the provider's requests use, and
 * never text of a conversation; no answer or a status that says nothing
 * about the key changes no state, only the time it was tried. It runs only
 * when something asks: `pic auth status --check`, and the terminal interface
 * in its own child process. Never in print, JSON or RPC mode. */
#ifndef PIC_KEYPROBE_H
#define PIC_KEYPROBE_H

/* A key checked within this long is not checked again unless forced. */
#define PIC_KEYPROBE_FRESH_MS 600000LL
/* Seconds each check may take, from the first byte sent to the last read. */
#define PIC_KEYPROBE_DEADLINE 8

typedef struct {
    int force;           /* check every key, fresh or not */
    int active_only;     /* only the key each provider's requests use */
    int no_prompt;       /* never ask for the passphrase: a locked store's keys are left alone */
    const char *provider; /* only this provider's keys; NULL: all */
    int deadline;        /* seconds; 0: PIC_KEYPROBE_DEADLINE */
} pic_keyprobe_opts;

/* Checks the wanted keys in parallel and records each answer as it arrives.
 * How many were checked, or -1 when the credential store cannot be read. */
int pic_keyprobe(const pic_keyprobe_opts *o);

#endif