Documentation
¶
Overview ¶
Package provider defines interfaces for credential and agent providers.
All providers implement CredentialProvider for credential acquisition, proxy configuration, and container setup. Agent providers (Claude, Copilot, Codex, Gemini) additionally implement AgentProvider for container preparation and CLI commands. Endpoint providers (AWS) implement EndpointProvider to expose HTTP endpoints.
Providers are registered explicitly via Register() and looked up via Get().
Index ¶
- Constants
- Variables
- func AgentAliases() []string
- func Clear()
- func Names() []string
- func Register(p CredentialProvider)
- func RegisterAlias(alias, canonical string)
- func ResolveName(name string) string
- func Unregister(name string)
- type AgentOnlyProvider
- type AgentProvider
- type AgentRuntime
- type ContainerConfig
- type ContainerProvider
- type Credential
- type CredentialProvider
- type DescribableProvider
- type EndpointProvider
- type GrantError
- type GrantProvider
- type ImpliedDepsProvider
- type InitFileProvider
- type JoinOpts
- type JoinableAgent
- type LegacyCredential
- type LocalMCPServerConfig
- type MCPServerConfig
- type MountConfig
- type PrepareOpts
- type ProxyConfigurer
- type ProxyProvider
- type RefreshableProvider
- type ResponseTransformer
- type RunStoppedContext
- type RunStoppedHook
Constants ¶
const MetaKeyTokenSource = "token_source"
MetaKeyTokenSource is the metadata key for recording how a token was obtained.
Variables ¶
var ( // ErrProviderNotFound is returned when a provider is not registered. ErrProviderNotFound = errors.New("provider not found") // ErrCredentialNotFound is returned when no credential exists for a provider. ErrCredentialNotFound = errors.New("credential not found") // ErrCredentialExpired is returned when a credential has expired. ErrCredentialExpired = errors.New("credential expired") // ErrRefreshNotSupported is returned when refresh is attempted on a static credential. ErrRefreshNotSupported = errors.New("credential refresh not supported") // ErrTokenRevoked is returned when a refresh token has been revoked. ErrTokenRevoked = errors.New("refresh token revoked") )
Functions ¶
func AgentAliases ¶ added in v0.8.0
func AgentAliases() []string
AgentAliases returns the registered alias names (e.g. "openai" for "codex") whose canonical provider is an AgentProvider, sorted. Aliases that resolve to a non-agent provider (or to nothing) are excluded — an alias only belongs in an "accepted agent name" listing if it actually names an agent.
func RegisterAlias ¶
func RegisterAlias(alias, canonical string)
RegisterAlias registers an alternative name for a provider. This allows looking up a provider by either its canonical name or any alias. For example: RegisterAlias("anthropic", "claude") allows Get("anthropic") to return the "claude" provider.
func ResolveName ¶ added in v0.3.0
ResolveName returns the canonical provider name for a given name or alias. If the name is directly registered or unknown, it is returned as-is. If the name is an alias, the canonical name is returned.
func Unregister ¶ added in v0.5.0
func Unregister(name string)
Unregister removes a provider by name. For testing only.
Types ¶
type AgentOnlyProvider ¶ added in v0.8.0
type AgentOnlyProvider interface {
// AgentOnly is a marker method; it does nothing.
AgentOnly()
}
AgentOnlyProvider is an optional interface for providers that register as CredentialProviders to carry agent runtime behavior but have no credential of their own — they run on another provider's grant, and their Grant() always errors pointing at it (see the pi and copilot providers).
Credential listings such as 'moat grant providers' must exclude these, so they never advertise a `moat grant <name>` that cannot work. Implement it on any agent provider that borrows another grant, and say which one in the method's doc comment.
type AgentProvider ¶
type AgentProvider interface {
CredentialProvider
// PrepareContainer sets up staging directories and config files.
PrepareContainer(ctx context.Context, opts PrepareOpts) (*ContainerConfig, error)
// RegisterCLI adds provider-specific commands to the root command.
RegisterCLI(root *cobra.Command)
}
AgentProvider extends CredentialProvider for AI agent runtimes. Implemented by claude, copilot, codex, gemini, and pi providers.
func Agents ¶
func Agents() []AgentProvider
Agents returns all providers that implement AgentProvider.
func GetAgent ¶
func GetAgent(name string) AgentProvider
GetAgent returns an AgentProvider by name. Returns nil if not found or not an agent provider.
type AgentRuntime ¶ added in v0.8.0
type AgentRuntime interface {
// DefaultDependencies returns the dependencies that install this agent's CLI.
DefaultDependencies() []string
// NetworkHosts returns the hosts this agent needs to reach.
NetworkHosts() []string
// CredentialGrant returns the STATIC grant name this agent needs — not a
// credential-store lookup. "" means the agent has no static grant and none
// should be unioned in. Store lookups stay in the verb-path
// GetCredentialName funcs; conflating the two puts empty or wrong grant
// names into the grants list.
CredentialGrant() string
}
AgentRuntime is implemented by agent providers that can be provisioned into a container declaratively via moat.yaml `agents:`. It is optional: a provider that does not implement it cannot appear in an `agents:` list.
type ContainerConfig ¶
type ContainerConfig struct {
Env []string
Mounts []MountConfig
StagingDir string // Temporary directory containing config files (for later cleanup tracking)
Cleanup func()
}
ContainerConfig is returned by AgentProvider.PrepareContainer.
type ContainerProvider ¶ added in v0.5.0
type ContainerProvider interface {
// ContainerEnv returns environment variables to set in the container.
ContainerEnv(cred *Credential) []string
// ContainerMounts returns mounts needed for this credential.
// Also returns an optional cleanup path that should be passed to Cleanup()
// when the run ends.
ContainerMounts(cred *Credential, containerHome string) ([]MountConfig, string, error)
// Cleanup is called when the run ends to clean up any resources.
Cleanup(cleanupPath string)
}
ContainerProvider sets up the container environment for a credential. Used by moat CLI — Gate Keeper doesn't manage containers.
type Credential ¶
type Credential struct {
Provider string `json:"provider"`
Token string `json:"token"`
Scopes []string `json:"scopes,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
Metadata map[string]string `json:"metadata,omitempty"`
}
Credential represents a stored credential.
func FromLegacy ¶
func FromLegacy(cred LegacyCredential) *Credential
FromLegacy converts a LegacyCredential (like credential.Credential) to provider.Credential.
type CredentialProvider ¶
type CredentialProvider interface {
ProxyProvider
GrantProvider
ContainerProvider
ImpliedDepsProvider
}
CredentialProvider is the composite interface for full provider implementations. All current providers implement this. Gate Keeper only requires ProxyProvider.
func Get ¶
func Get(name string) CredentialProvider
Get returns a provider by name or alias, or nil if not found.
type DescribableProvider ¶ added in v0.3.0
type DescribableProvider interface {
Description() string
Source() string // "builtin" or "custom"
}
DescribableProvider is an optional interface for providers that describe themselves in listings like 'moat grant providers'.
type EndpointProvider ¶
type EndpointProvider interface {
CredentialProvider
// RegisterEndpoints registers HTTP handlers on the proxy mux.
RegisterEndpoints(mux *http.ServeMux, cred *Credential)
}
EndpointProvider exposes HTTP endpoints to containers. Implemented by aws for the credential endpoint.
func GetEndpoint ¶
func GetEndpoint(name string) EndpointProvider
GetEndpoint returns an EndpointProvider by name. Returns nil if not found or not an endpoint provider.
type GrantError ¶
GrantError wraps provider-specific grant failures with actionable guidance.
func (*GrantError) Error ¶
func (e *GrantError) Error() string
func (*GrantError) Unwrap ¶
func (e *GrantError) Unwrap() error
type GrantProvider ¶ added in v0.5.0
type GrantProvider interface {
Grant(ctx context.Context) (*Credential, error)
}
GrantProvider acquires credentials interactively or from environment. Used by moat CLI — Gate Keeper never calls this.
type ImpliedDepsProvider ¶ added in v0.5.0
type ImpliedDepsProvider interface {
// ImpliedDependencies returns dependencies implied by this provider.
// For example, github implies ["gh", "git"].
ImpliedDependencies() []string
}
ImpliedDepsProvider declares dependencies between providers. Used by moat CLI.
type InitFileProvider ¶ added in v0.3.3
type InitFileProvider interface {
// ContainerInitFiles returns a map of absolute container paths to file
// contents. Paths must be under containerHome. The moat-init.sh script
// writes each entry to disk with mode 0600 before executing the user's
// command.
ContainerInitFiles(cred *Credential, containerHome string) map[string]string
}
InitFileProvider is an optional interface for providers that need config files written into the container at startup. The run manager collects init files from all providers and passes them to moat-init.sh via the MOAT_INIT_FILES env var. This avoids bind-mounting config directories that the tool needs to write to at runtime.
Use InitFileProvider (not ContainerMounts) when the tool needs to write to its config directory at runtime. Bind mounts prevent writes to the mount target, causing silent tool failures.
type JoinableAgent ¶ added in v0.6.0
type JoinableAgent interface {
// JoinCommand returns the in-container command to launch a joined session.
JoinCommand(opts JoinOpts) ([]string, error)
// IdentifiesAs reports whether a run whose recorded Agent field is `agent`
// was created by this provider. This absorbs the difference between the
// default provider name ("claude") and an explicit moat.yaml agent value
// ("claude-code").
IdentifiesAs(agent string) bool
}
JoinableAgent is implemented by agent providers that support `moat join` — launching a second instance of the agent into an existing run's container. It is optional: providers that don't implement it cannot be joined.
type LegacyCredential ¶
type LegacyCredential interface {
GetProvider() string
GetToken() string
GetScopes() []string
GetExpiresAt() time.Time
GetCreatedAt() time.Time
GetMetadata() map[string]string
}
LegacyCredential is an interface for converting from credential.Credential. This avoids import cycles between provider and credential packages.
type LocalMCPServerConfig ¶ added in v0.5.0
LocalMCPServerConfig defines a local process MCP server that runs inside the container as a child process.
type MCPServerConfig ¶
MCPServerConfig defines a remote/relay MCP server configuration.
type MountConfig ¶
type MountConfig = container.MountConfig
MountConfig re-exports container.MountConfig for provider use.
type PrepareOpts ¶
type PrepareOpts struct {
Credential *Credential
ContainerHome string
MCPServers map[string]MCPServerConfig
HostConfig map[string]interface{}
RuntimeContext string // Rendered markdown context for agent instruction file
// LocalMCPServers are MCP servers that run as child processes inside the
// container. These are defined under agent-specific sections in moat.yaml
// (e.g., claude.mcp, codex.mcp, gemini.mcp).
LocalMCPServers map[string]LocalMCPServerConfig
// SubscriptionType and RateLimitTier override the values written to Claude
// Code's .credentials.json (from moat.yaml claude.subscription_type /
// claude.rate_limit_tier). Empty means "no override" — the provider falls
// back to the imported value or a default. Claude-specific; ignored by
// other agents.
SubscriptionType string
RateLimitTier string
// ScopeAnthropicKeyToShell stages a BASH_ENV file that exports
// ANTHROPIC_API_KEY to shell commands only, instead of placing it in the
// container environment. Set when a run holds both the "claude" (OAuth) and
// "anthropic" (API key) grants, where a container-wide key would take
// precedence over Claude Code's OAuth login and move the session onto API
// billing. Claude-specific; ignored by other agents.
ScopeAnthropicKeyToShell bool
// ScopeOpenAIKeyToShell keeps an OpenAI API-key placeholder out of the
// Codex process when subscription and API-key grants coexist.
ScopeOpenAIKeyToShell bool
// CodexRequireApproval keeps Codex's own approval prompts and sandbox
// enabled instead of moat's default of turning both off (the container is
// already the isolation boundary, and Codex's sandbox blocks the network
// the moat proxy provides). Set from `moat codex --noyolo`.
// Codex-specific; ignored by other agents.
CodexRequireApproval bool
// CopilotModel, CopilotContext, and CopilotReasoningEffort strip the
// corresponding keys (model, contextTier, effortLevel) from the Copilot
// settings.json staged into the container, because the value is pinned by
// moat.yaml copilot.* or a CLI flag. Empty means "no override".
// Copilot-specific; ignored by other agents.
CopilotModel string
CopilotContext string
CopilotReasoningEffort string
// PiModelCatalogSync lets Pi make startup network calls (it omits
// PI_OFFLINE). Set when the run holds the lunaroute grant: LunaRoute's
// Pi extension fetches its model catalog at startup, and under PI_OFFLINE
// a fresh container would list no LunaRoute models.
// Pi-specific; ignored by other agents.
PiModelCatalogSync bool
}
PrepareOpts contains options for AgentProvider.PrepareContainer.
type ProxyConfigurer ¶
type ProxyConfigurer = credential.ProxyConfigurer
ProxyConfigurer configures proxy credentials and response transformations. This is an alias for credential.ProxyConfigurer to ensure type compatibility.
type ProxyProvider ¶ added in v0.5.0
type ProxyProvider interface {
// Name returns the provider identifier (e.g., "github", "claude").
Name() string
// ConfigureProxy sets up proxy headers for this credential.
ConfigureProxy(p ProxyConfigurer, cred *Credential)
}
ProxyProvider configures proxy credential injection for a given credential. This is the core interface Gate Keeper needs from a provider.
type RefreshableProvider ¶
type RefreshableProvider interface {
CanRefresh(cred *Credential) bool
RefreshInterval() time.Duration
Refresh(ctx context.Context, p ProxyConfigurer, cred *Credential) (*Credential, error)
}
RefreshableProvider is an optional interface for providers that support background credential refresh. Providers with static credentials (API keys, role ARNs) do not implement this.
type ResponseTransformer ¶
type ResponseTransformer = credential.ResponseTransformer
ResponseTransformer modifies HTTP responses for a host. This is an alias for credential.ResponseTransformer to ensure type compatibility.
type RunStoppedContext ¶ added in v0.3.0
RunStoppedContext provides run information to shutdown hooks.
type RunStoppedHook ¶ added in v0.3.0
type RunStoppedHook interface {
// OnRunStopped is called after the container exits and logs are captured.
// It receives run context and returns metadata key-value pairs to persist.
// Returned metadata is stored in the run's metadata.json under "provider_meta".
OnRunStopped(ctx RunStoppedContext) map[string]string
}
RunStoppedHook is an optional interface for providers that need to perform actions after a run stops. The manager calls OnRunStopped for each grant provider that implements this interface.