pub struct GlobalConfig {
pub sources: HashMap<String, String>,
pub upgrade: UpgradeConfig,
pub max_content_file_size: u64,
pub token_warning_threshold: u64,
}Expand description
Global configuration structure for AGPM.
This structure represents the global user configuration file stored at ~/.agpm/config.toml.
It contains user-wide settings including authentication credentials for private Git repositories.
§Security Considerations
- Never commit this configuration to version control
- Store only in the user’s home directory or secure location
- Contains sensitive data like authentication tokens
- Should have restricted file permissions (600 on Unix systems)
§Structure
Currently contains only source definitions, but designed to be extensible for future configuration options like:
- Default author information
- Preferred Git configuration
- Cache settings
- Proxy configuration
§Examples
use agpm_cli::config::GlobalConfig;
use std::collections::HashMap;
// Create new configuration
let mut config = GlobalConfig::default();
// Add authenticated source
config.add_source(
"company".to_string(),
"https://oauth2:token@github.com/company/agpm.git".to_string()
);
assert!(config.has_source("company"));Fields§
§sources: HashMap<String, String>Global Git repository sources with optional authentication.
Maps source names to Git repository URLs. These URLs may contain authentication credentials and are kept separate from project manifests for security.
§Authentication URL Formats
https://oauth2:token@github.com/owner/repo.git- GitHub personal access tokenhttps://gitlab-ci-token:token@gitlab.com/group/repo.git- GitLab deploy tokengit@github.com:owner/repo.git- SSH authenticationhttps://user:pass@server.com/repo.git- Basic auth (not recommended)
§Security Notes
- URLs with credentials are never logged in plain text
- The
sourcesfield is skipped during serialization if empty - Authentication details should use tokens rather than passwords when possible
upgrade: UpgradeConfigUpgrade configuration settings.
Controls the behavior of the self-upgrade functionality including update checks, backup preferences, and verification settings.
max_content_file_size: u64Maximum file size in bytes for file operations.
Default: 1 MB (1,048,576 bytes)
This limit prevents memory exhaustion when reading or embedding files. Currently used by template content filter, may be used by other operations in the future.
§Configuration
Set in ~/.agpm/config.toml:
max_content_file_size = 2097152 # 2 MBtoken_warning_threshold: u64Token count warning threshold.
Default: 100,000 tokens (Claude’s context window is ~200k)
Resources exceeding this threshold will emit a warning during installation. This helps identify resources that may consume significant context.
§Configuration
Set in ~/.agpm/config.toml:
token_warning_threshold = 50000 # 50k tokensImplementations§
Source§impl GlobalConfig
impl GlobalConfig
Sourcepub async fn load() -> Result<Self>
pub async fn load() -> Result<Self>
Load global configuration from the default platform-specific location.
Attempts to load the configuration file from the default path. If the file doesn’t exist, returns a default (empty) configuration instead of an error.
§Default Locations
- Unix/macOS:
~/.agpm/config.toml - Windows:
%LOCALAPPDATA%\agpm\config.toml - Override: Set
AGPM_CONFIG_PATHenvironment variable
§Examples
use agpm_cli::config::GlobalConfig;
let config = GlobalConfig::load().await?;
println!("Loaded {} global sources", config.sources.len());§Errors
Returns an error if:
- The default path cannot be determined
- The file exists but cannot be read
- The file contains invalid TOML syntax
Sourcepub async fn load_with_optional(path: Option<PathBuf>) -> Result<Self>
pub async fn load_with_optional(path: Option<PathBuf>) -> Result<Self>
Load global configuration from an optional path.
If a path is provided, loads from that path. Otherwise, loads from the
default location (~/.agpm/config.toml or platform equivalent).
§Parameters
path: Optional path to the configuration file
§Returns
Returns the loaded configuration or a default configuration if the file doesn’t exist.
§Errors
Returns an error if:
- The file exists but cannot be read
- The file contains invalid TOML syntax
Sourcepub async fn load_from(path: &Path) -> Result<Self>
pub async fn load_from(path: &Path) -> Result<Self>
Load global configuration from a specific file path.
This method is primarily used for testing or when a custom configuration location is needed.
§Parameters
path: Path to the configuration file to load
§Examples
use agpm_cli::config::GlobalConfig;
use std::path::Path;
let config = GlobalConfig::load_from(Path::new("/custom/config.toml")).await?;§Errors
Returns an error if:
- The file cannot be read (permissions, not found, etc.)
- The file contains invalid TOML syntax
- The TOML structure doesn’t match the expected schema
Sourcepub async fn save(&self) -> Result<()>
pub async fn save(&self) -> Result<()>
Save global configuration to the default platform-specific location.
Saves the current configuration to the default path, creating parent directories as needed. The file is written atomically to prevent corruption during the write process.
§File Permissions
The configuration file should be created with restricted permissions since it may contain sensitive authentication tokens.
§Examples
use agpm_cli::config::GlobalConfig;
let mut config = GlobalConfig::load().await?;
config.add_source(
"new".to_string(),
"https://github.com/owner/repo.git".to_string()
);
config.save().await?;§Errors
Returns an error if:
- The default path cannot be determined
- Parent directories cannot be created
- The file cannot be written (permissions, disk space, etc.)
- Serialization to TOML fails
Sourcepub async fn save_to(&self, path: &Path) -> Result<()>
pub async fn save_to(&self, path: &Path) -> Result<()>
Save global configuration to a specific file path.
Creates parent directories as needed and writes the configuration as pretty-formatted TOML.
§Parameters
path: Path where the configuration file should be saved
§Examples
use agpm_cli::config::GlobalConfig;
use std::path::Path;
let config = GlobalConfig::default();
config.save_to(Path::new("/tmp/test-config.toml")).await?;§Errors
Returns an error if:
- Parent directories cannot be created
- The file cannot be written
- Serialization to TOML fails
Sourcepub fn default_path() -> Result<PathBuf>
pub fn default_path() -> Result<PathBuf>
Get the default file path for global configuration.
Returns the platform-appropriate path for storing global configuration. This location is chosen to be secure and follow platform conventions.
§Path Resolution
- Windows:
%LOCALAPPDATA%\agpm\config.toml - Unix/macOS:
~/.agpm/config.toml
Note: Environment variable overrides are deprecated. Use the load_with_optional()
method with an explicit path instead for better thread safety.
§Examples
use agpm_cli::config::GlobalConfig;
let path = GlobalConfig::default_path()?;
println!("Global config path: {}", path.display());§Errors
Returns an error if:
- The home directory cannot be determined
- The local data directory cannot be determined (Windows)
Sourcepub fn merge_sources(
&self,
local_sources: &HashMap<String, String>,
) -> HashMap<String, String>
pub fn merge_sources( &self, local_sources: &HashMap<String, String>, ) -> HashMap<String, String>
Merge global sources with project manifest sources.
Combines the global configuration sources with sources from a project manifest, with project sources taking precedence over global sources. This allows users to maintain private authentication in global config while projects can override with public sources.
§Merge Strategy
- Start with all global sources (may include authentication)
- Add/override with local sources from project manifest
- Local sources win in case of name conflicts
§Parameters
local_sources: Sources from project manifest (agpm.toml)
§Returns
Combined source map with local sources taking precedence.
§Examples
use agpm_cli::config::GlobalConfig;
use std::collections::HashMap;
let mut global = GlobalConfig::default();
global.add_source(
"private".to_string(),
"https://token@private.com/repo.git".to_string()
);
let mut local = HashMap::new();
local.insert(
"public".to_string(),
"https://github.com/public/repo.git".to_string()
);
let merged = global.merge_sources(&local);
assert_eq!(merged.len(), 2);
assert!(merged.contains_key("private"));
assert!(merged.contains_key("public"));§Security Note
The merged result may contain authentication credentials from global sources. Handle with care and never log or expose in version control.
Sourcepub fn add_source(&mut self, name: String, url: String)
pub fn add_source(&mut self, name: String, url: String)
Add or update a source in the global configuration.
Adds a new source or updates an existing one with the given name and URL. The URL may contain authentication credentials.
§Parameters
name: Unique name for the source (used in manifests)url: Git repository URL, optionally with authentication
§Examples
use agpm_cli::config::GlobalConfig;
let mut config = GlobalConfig::default();
// Add source with authentication
config.add_source(
"private".to_string(),
"https://oauth2:token@github.com/company/repo.git".to_string()
);
// Update existing source
config.add_source(
"private".to_string(),
"git@github.com:company/repo.git".to_string()
);
assert!(config.has_source("private"));§Security Note
URLs containing credentials should use tokens rather than passwords when possible.
Sourcepub fn remove_source(&mut self, name: &str) -> bool
pub fn remove_source(&mut self, name: &str) -> bool
Remove a source from the global configuration.
Removes the source with the given name if it exists.
§Parameters
name: Name of the source to remove
§Returns
trueif the source was found and removedfalseif the source didn’t exist
§Examples
use agpm_cli::config::GlobalConfig;
let mut config = GlobalConfig::default();
config.add_source("test".to_string(), "https://example.com/repo.git".to_string());
assert!(config.remove_source("test"));
assert!(!config.remove_source("test")); // Already removedSourcepub fn has_source(&self, name: &str) -> bool
pub fn has_source(&self, name: &str) -> bool
Check if a source exists in the global configuration.
§Parameters
name: Name of the source to check
§Returns
trueif the source existsfalseif the source doesn’t exist
§Examples
use agpm_cli::config::GlobalConfig;
let mut config = GlobalConfig::default();
assert!(!config.has_source("test"));
config.add_source("test".to_string(), "https://example.com/repo.git".to_string());
assert!(config.has_source("test"));Sourcepub fn get_source(&self, name: &str) -> Option<&String>
pub fn get_source(&self, name: &str) -> Option<&String>
Get a source URL by name.
Returns a reference to the URL for the specified source name.
§Parameters
name: Name of the source to retrieve
§Returns
Some(&String)with the URL if the source existsNoneif the source doesn’t exist
§Examples
use agpm_cli::config::GlobalConfig;
let mut config = GlobalConfig::default();
config.add_source(
"test".to_string(),
"https://example.com/repo.git".to_string()
);
assert_eq!(
config.get_source("test"),
Some(&"https://example.com/repo.git".to_string())
);
assert_eq!(config.get_source("missing"), None);§Security Note
The returned URL may contain authentication credentials. Handle with care.
Sourcepub fn init_example() -> Self
pub fn init_example() -> Self
Create a global configuration with example content.
Creates a new configuration populated with example sources to demonstrate the expected format. Useful for initial setup or documentation.
§Returns
A new GlobalConfig with example private source configuration.
§Examples
use agpm_cli::config::GlobalConfig;
let config = GlobalConfig::init_example();
assert!(config.has_source("private"));
// The example uses a placeholder token
let url = config.get_source("private").unwrap();
assert!(url.contains("YOUR_TOKEN"));§Note
The example configuration contains placeholder values that must be replaced with actual authentication credentials before use.
Trait Implementations§
Source§impl Clone for GlobalConfig
impl Clone for GlobalConfig
Source§fn clone(&self) -> GlobalConfig
fn clone(&self) -> GlobalConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GlobalConfig
impl Debug for GlobalConfig
Source§impl Default for GlobalConfig
impl Default for GlobalConfig
Source§fn default() -> GlobalConfig
fn default() -> GlobalConfig
Source§impl<'de> Deserialize<'de> for GlobalConfig
impl<'de> Deserialize<'de> for GlobalConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for GlobalConfig
impl RefUnwindSafe for GlobalConfig
impl Send for GlobalConfig
impl Sync for GlobalConfig
impl Unpin for GlobalConfig
impl UnwindSafe for GlobalConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more