MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / load_wellknown

Function load_wellknown

crates/opencode-config/src/wellknown.rs:83–123  ·  view source on GitHub ↗

Fetches remote config from all wellknown auth entries and returns a merged `Config` representing the combined remote configuration. This is the lowest-priority config source — it will be merged first so that global and project configs override it. Network failures are logged as warnings and never prevent startup.

()

Source from the content-addressed store, hash-verified

81///
82/// Network failures are logged as warnings and never prevent startup.
83pub async fn load_wellknown() -> Config {
84 let entries = read_wellknown_entries();
85 if entries.is_empty() {
86 return Config::default();
87 }
88
89 let mut merged = Config::default();
90 let client = reqwest::Client::builder()
91 .timeout(FETCH_TIMEOUT)
92 .build()
93 .unwrap_or_default();
94
95 for (url, auth) in &entries {
96 // Check cache first
97 if let Some(cached) = get_cached(url) {
98 tracing::debug!(url = %url, "using cached wellknown config");
99 merged.merge(cached);
100 continue;
101 }
102
103 // Set the env var so downstream code (e.g. provider auth) can use it,
104 // matching the TS behaviour: `process.env[value.key] = value.token`
105 std::env::set_var(&auth.key, &auth.token);
106
107 let endpoint = format!("{}/.well-known/opencode", url.trim_end_matches('/'));
108 tracing::debug!(url = %endpoint, "fetching remote wellknown config");
109
110 match fetch_wellknown_config(&client, &endpoint).await {
111 Ok(config) => {
112 set_cached(url.clone(), config.clone());
113 tracing::debug!(url = %url, "loaded remote config from well-known");
114 merged.merge(config);
115 }
116 Err(e) => {
117 tracing::warn!(url = %endpoint, error = %e, "failed to fetch wellknown config, skipping");
118 }
119 }
120 }
121
122 merged
123}
124
125async fn fetch_wellknown_config(client: &reqwest::Client, endpoint: &str) -> Result<Config> {
126 let resp = client.get(endpoint).send().await?;

Calls 8

read_wellknown_entriesFunction · 0.85
get_cachedFunction · 0.85
fetch_wellknown_configFunction · 0.85
set_cachedFunction · 0.85
is_emptyMethod · 0.80
buildMethod · 0.80
mergeMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected