Help us shape the future of Go! Take the 2026 Go Developer Survey

authstatus

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Offline OpenAI auth-status report backing `codemeld auth status`: classifies the OpenAI Platform (API-key) and OpenAI ChatGPT (subscription) providers from OPENAI_API_KEY and the global settings file only, without printing secrets, composing project-local settings, constructing a provider client, or making any network call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, r Report, asJSON bool) error

Render writes the report to w as JSON when asJSON is true, otherwise as the human-readable form.

func RenderHuman

func RenderHuman(w io.Writer, r Report) error

RenderHuman writes one line per provider, reporting each independently with no cross-provider precedence.

func RenderJSON

func RenderJSON(w io.Writer, r Report) error

RenderJSON writes the report as indented JSON with a trailing newline. The providers order is deterministic (Platform then ChatGPT) so scripts can rely on it.

Types

type Kind

type Kind string

Kind is the JSON `kind` enum: how a provider authenticates. It is distinct from the provider package's internal AuthKind vocabulary.

const (
	// KindAPIKey is the OpenAI Platform provider (OPENAI_API_KEY or configured key).
	KindAPIKey Kind = "api_key"
	// KindChatGPTSubscription is the OpenAI ChatGPT provider (stored login session).
	KindChatGPTSubscription Kind = "chatgpt_subscription"
)

type ProviderStatus

type ProviderStatus struct {
	ID            string `json:"id"`
	Kind          Kind   `json:"kind"`
	Authenticated bool   `json:"authenticated"`
	Source        Source `json:"source"`
	State         State  `json:"state"`
}

ProviderStatus is one provider's offline auth state. authenticated is true only when the provider has a usable local credential: a Platform key, or a present (not expired/invalid) ChatGPT session. It never asserts upstream entitlement. No field carries a key, token, or account identifier.

type Report

type Report struct {
	Providers []ProviderStatus `json:"providers"`
}

Report is the full offline status. Providers is always ordered Platform first, then ChatGPT, so JSON and scripts do not depend on map iteration.

func Collect

func Collect(settingsPath string, now time.Time) (Report, error)

Collect builds the offline auth-status Report from the global settings file at settingsPath and the process environment, classifying the ChatGPT session via the session classifier relative to now. It reads only OPENAI_API_KEY and the global settings file; it never composes project-local settings, constructs a provider client, or performs any network call. It returns an error when the global settings file exists but cannot be read, parsed, or schema-validated — the one exception being a malformed auth.openai-chatgpt session shape, which is masked out of validation and classified by the session classifier as local_session_invalid instead of failing the command. A missing file is reported as unauthenticated, not an error. The error names only the path, never credential content.

type Source

type Source string

Source is the JSON `source` enum: where the credential the status reflects was found. none means no usable credential was located.

const (
	// SourceEnv means the OpenAI Platform key came from OPENAI_API_KEY.
	SourceEnv Source = "env"
	// SourceGlobalSettings means the credential came from the global settings file:
	// provider.openai.api_key for Platform, or auth.openai-chatgpt for ChatGPT.
	SourceGlobalSettings Source = "global_settings"
	// SourceNone means no credential was found for the provider.
	SourceNone Source = "none"
)

type State

type State string

State is the JSON `state` enum reported per provider. The four ChatGPT values mirror the session classifier's authstate.Status string values exactly.

const (
	// StateUsingAPIKey: an OpenAI Platform key is present (env or global settings).
	StateUsingAPIKey State = "using_api_key"
	// StateNoAPIKey: no OpenAI Platform key is configured anywhere status reads.
	StateNoAPIKey State = "no_api_key"
	// StateLocalSessionPresent: a complete, non-expired ChatGPT session is stored.
	StateLocalSessionPresent State = "local_session_present"
	// StateLocalSessionExpired: a ChatGPT session is stored but its expiry has passed.
	StateLocalSessionExpired State = "local_session_expired"
	// StateLocalSessionInvalid: stored ChatGPT session state is corrupted or malformed.
	StateLocalSessionInvalid State = "local_session_invalid"
	// StateNoLocalSession: no ChatGPT session is stored.
	StateNoLocalSession State = "no_local_session"
)

Jump to

Keyboard shortcuts

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