credentials

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvVarForProvider

func EnvVarForProvider(provider string) string

EnvVarForProvider returns the environment variable name for a given provider. Returns an empty string for unknown providers.

func IsSupportedProvider

func IsSupportedProvider(provider string) bool

IsSupportedProvider returns true if the given provider is supported.

func PatchCodexAuthKey

func PatchCodexAuthKey(data []byte, apiKey string) ([]byte, bool)

PatchCodexAuthKey sets OPENAI_API_KEY in the codex auth JSON and returns the updated bytes. It also removes OAuth "tokens" so codex falls back to the API key instead of using OAuth tokens that may lack required scopes. Returns nil, false if the JSON cannot be processed.

func PatchOpenCodeAuth

func PatchOpenCodeAuth(data []byte, providers []string) ([]byte, bool)

PatchOpenCodeAuth removes OAuth entries for the given providers from the opencode auth JSON, forcing opencode to fall back to API keys from its config or environment. Returns the updated bytes and true on success. Returns nil, false if the JSON cannot be processed.

func ReadCodexAuthFile

func ReadCodexAuthFile() ([]byte, string)

ReadCodexAuthFile reads ~/.codex/auth.json and returns its contents and path. Returns nil, "" if the file cannot be read.

func ReadOpenCodeAuthFile

func ReadOpenCodeAuthFile() ([]byte, string)

ReadOpenCodeAuthFile reads ~/.local/share/opencode/auth.json and returns its contents and path. Returns nil, "" if the file cannot be read.

func SupportedProviders

func SupportedProviders() []string

SupportedProviders returns a copy of the supported provider list.

Types

type Credentials

type Credentials struct {
	Version   int                           `toml:"version"`
	Providers map[string]ProviderCredential `toml:"providers"`
}

Credentials represents the stored API credentials in credentials.toml.

type Manager

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

Manager manages reading and writing credentials.toml in the .tapes/ directory.

func NewManager

func NewManager(override string) (*Manager, error)

NewManager creates a new credentials Manager. If override is non-empty it is used as the .tapes/ directory; otherwise the standard dotdir resolution applies. When no .tapes/ directory is found, one is created at ~/.tapes/.

func (*Manager) GetKey

func (m *Manager) GetKey(provider string) (string, error)

GetKey returns the stored API key for the given provider. Returns an empty string if no key is stored.

func (*Manager) GetTarget

func (m *Manager) GetTarget() string

GetTarget returns the resolved path to the credentials file.

func (*Manager) ListProviders

func (m *Manager) ListProviders() ([]string, error)

ListProviders returns the names of providers that have stored credentials.

func (*Manager) Load

func (m *Manager) Load() (*Credentials, error)

Load reads credentials.toml from the target directory. Returns an empty Credentials if the file does not exist.

func (*Manager) RemoveKey

func (m *Manager) RemoveKey(provider string) error

RemoveKey deletes the stored credential for a provider.

func (*Manager) Save

func (m *Manager) Save(creds *Credentials) error

Save writes credentials to credentials.toml with 0600 permissions.

func (*Manager) SetKey

func (m *Manager) SetKey(provider, key string) error

SetKey stores an API key for the given provider.

type ProviderCredential

type ProviderCredential struct {
	APIKey string `toml:"api_key"`
}

ProviderCredential holds the API key for a single provider.

Jump to

Keyboard shortcuts

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