Documentation
¶
Overview ¶
Package config provides configuration management for agentapi-proxy using viper.
Configuration can be loaded from:
- JSON files (backward compatibility)
- YAML files
- Environment variables with AGENTAPI_ prefix
Environment variable examples:
AGENTAPI_START_PORT=8080 AGENTAPI_AUTH_ENABLED=true AGENTAPI_AUTH_STATIC_ENABLED=true AGENTAPI_AUTH_STATIC_HEADER_NAME=X-API-Key AGENTAPI_AUTH_STATIC_KEYS_FILE=/path/to/keys.json AGENTAPI_AUTH_GITHUB_ENABLED=true AGENTAPI_AUTH_GITHUB_BASE_URL=https://api.github.com AGENTAPI_AUTH_GITHUB_TOKEN_HEADER=Authorization AGENTAPI_AUTH_GITHUB_OAUTH_CLIENT_ID=your_client_id AGENTAPI_AUTH_GITHUB_OAUTH_CLIENT_SECRET=your_client_secret AGENTAPI_AUTH_GITHUB_OAUTH_SCOPE=read:user read:org AGENTAPI_AUTH_GITHUB_USER_MAPPING_DEFAULT_ROLE=user AGENTAPI_ENABLE_MULTIPLE_USERS=true
Configuration file search paths:
- Current directory
- $HOME/.agentapi/
- /etc/agentapi/
Configuration file names: config.json, config.yaml, config.yml
Index ¶
- func ApplyEnvVars(envVars []EnvVar) []string
- func GetRoleFromContext(userID string, role string) string
- func LoadAuthConfigFromFile(config *Config, filename string) error
- type APIKey
- type AuthConfig
- type AuthConfigOverride
- type Config
- type EnvVar
- type GitHubAuthConfig
- type GitHubAuthConfigOverride
- type GitHubOAuthConfig
- type GitHubUserMapping
- type RoleEnvFilesConfig
- type StaticAuthConfig
- type TeamRoleRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyEnvVars ¶ added in v1.42.0
ApplyEnvVars sets environment variables in the current process Returns the list of variables that were set
func GetRoleFromContext ¶ added in v1.42.0
GetRoleFromContext extracts the user's role from the authentication context This is a helper function that should be called from the auth package
func LoadAuthConfigFromFile ¶ added in v1.9.1
LoadAuthConfigFromFile loads auth configuration from an external file (e.g., ConfigMap)
Types ¶
type APIKey ¶ added in v0.13.0
type APIKey struct {
Key string `json:"key" mapstructure:"key"`
UserID string `json:"user_id" mapstructure:"user_id"`
Role string `json:"role" mapstructure:"role"`
Permissions []string `json:"permissions" mapstructure:"permissions"`
CreatedAt string `json:"created_at" mapstructure:"created_at"`
ExpiresAt string `json:"expires_at,omitempty" mapstructure:"expires_at"`
}
APIKey represents an API key configuration
func (*APIKey) HasPermission ¶ added in v0.13.0
HasPermission checks if a user has a specific permission
type AuthConfig ¶ added in v0.13.0
type AuthConfig struct {
Enabled bool `json:"enabled" mapstructure:"enabled"`
Static *StaticAuthConfig `json:"static,omitempty" mapstructure:"static"`
GitHub *GitHubAuthConfig `json:"github,omitempty" mapstructure:"github"`
}
AuthConfig represents authentication configuration
type AuthConfigOverride ¶ added in v1.9.1
type AuthConfigOverride struct {
GitHub *GitHubAuthConfigOverride `json:"github,omitempty" yaml:"github,omitempty"`
}
AuthConfigOverride represents auth configuration overrides from external file
type Config ¶
type Config struct {
// StartPort is the starting port for agentapi servers
StartPort int `json:"start_port" mapstructure:"start_port"`
// Auth represents authentication configuration
Auth AuthConfig `json:"auth" mapstructure:"auth"`
// EnableMultipleUsers enables user-specific directory isolation
EnableMultipleUsers bool `json:"enable_multiple_users" mapstructure:"enable_multiple_users"`
// AuthConfigFile is the path to an external auth configuration file (e.g., from ConfigMap)
AuthConfigFile string `json:"auth_config_file" mapstructure:"auth_config_file"`
// RoleEnvFiles is the configuration for role-based environment files
RoleEnvFiles RoleEnvFilesConfig `json:"role_env_files" mapstructure:"role_env_files"`
}
Config represents the proxy configuration
func LoadConfig ¶
LoadConfig loads configuration using viper with support for JSON, YAML, and environment variables
func LoadConfigLegacy ¶ added in v1.9.1
LoadConfigLegacy loads configuration from a JSON file (legacy method)
type EnvVar ¶ added in v1.42.0
EnvVar represents a single environment variable
func LoadRoleEnvVars ¶ added in v1.42.0
func LoadRoleEnvVars(config *RoleEnvFilesConfig, role string) ([]EnvVar, error)
LoadRoleEnvVars loads environment variables for a specific role
func LoadTeamEnvVars ¶ added in v1.47.0
LoadTeamEnvVars loads environment variables from a specific file for a team
type GitHubAuthConfig ¶ added in v1.0.0
type GitHubAuthConfig struct {
Enabled bool `json:"enabled" mapstructure:"enabled"`
BaseURL string `json:"base_url" mapstructure:"base_url"`
TokenHeader string `json:"token_header" mapstructure:"token_header"`
UserMapping GitHubUserMapping `json:"user_mapping" mapstructure:"user_mapping"`
OAuth *GitHubOAuthConfig `json:"oauth,omitempty" mapstructure:"oauth"`
}
GitHubAuthConfig represents GitHub OAuth authentication
type GitHubAuthConfigOverride ¶ added in v1.9.1
type GitHubAuthConfigOverride struct {
UserMapping *GitHubUserMapping `json:"user_mapping,omitempty" yaml:"user_mapping,omitempty"`
}
GitHubAuthConfigOverride represents GitHub auth configuration overrides
type GitHubOAuthConfig ¶ added in v1.9.1
type GitHubOAuthConfig struct {
ClientID string `json:"client_id" mapstructure:"client_id"`
ClientSecret string `json:"client_secret" mapstructure:"client_secret"`
Scope string `json:"scope" mapstructure:"scope"`
BaseURL string `json:"base_url,omitempty" mapstructure:"base_url"`
}
GitHubOAuthConfig represents GitHub OAuth2 configuration
type GitHubUserMapping ¶ added in v1.0.0
type GitHubUserMapping struct {
DefaultRole string `json:"default_role" mapstructure:"default_role" yaml:"default_role"`
DefaultPermissions []string `json:"default_permissions" mapstructure:"default_permissions" yaml:"default_permissions"`
TeamRoleMapping map[string]TeamRoleRule `json:"team_role_mapping" mapstructure:"team_role_mapping" yaml:"team_role_mapping"`
}
GitHubUserMapping represents user role mapping configuration
type RoleEnvFilesConfig ¶ added in v1.42.0
type RoleEnvFilesConfig struct {
// Enabled enables role-based environment file loading
Enabled bool `json:"enabled" mapstructure:"enabled"`
// Path is the directory path containing role-specific .env files
Path string `json:"path" mapstructure:"path"`
// LoadDefault loads default.env before role-specific env file
LoadDefault bool `json:"load_default" mapstructure:"load_default"`
}
RoleEnvFilesConfig represents role-based environment files configuration
type StaticAuthConfig ¶ added in v1.0.0
type StaticAuthConfig struct {
Enabled bool `json:"enabled" mapstructure:"enabled"`
APIKeys []APIKey `json:"api_keys" mapstructure:"api_keys"`
KeysFile string `json:"keys_file" mapstructure:"keys_file"`
HeaderName string `json:"header_name" mapstructure:"header_name"`
}
StaticAuthConfig represents static API key authentication
type TeamRoleRule ¶ added in v1.0.0
type TeamRoleRule struct {
Role string `json:"role" mapstructure:"role" yaml:"role"`
Permissions []string `json:"permissions" mapstructure:"permissions" yaml:"permissions"`
EnvFile string `json:"env_file,omitempty" mapstructure:"env_file" yaml:"env_file"`
}
TeamRoleRule represents a team-based role rule