MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_client_with_org

Function build_client_with_org

atomic-cli/src/commands/client.rs:190–231  ·  view source on GitHub ↗

Build a [`StorageClient`] and return the resolved org slug alongside it. Useful for commands that also need to resolve org-scoped state (e.g. per-org default workspace lookup). Avoids resolving the org twice.

(
    org_override: Option<&str>,
    server_override: Option<&str>,
)

Source from the content-addressed store, hash-verified

188/// Useful for commands that also need to resolve org-scoped state (e.g.
189/// per-org default workspace lookup). Avoids resolving the org twice.
190pub async fn build_client_with_org(
191 org_override: Option<&str>,
192 server_override: Option<&str>,
193) -> CliResult<(StorageClient, String)> {
194 let config = GlobalConfig::load()
195 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load global config: {}", e)))?;
196
197 // Resolve the server profile (named or legacy).
198 let server = config
199 .resolve_server(server_override)
200 .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?
201 .0;
202
203 let server_url = server.url.clone().ok_or_else(|| {
204 let hint = if let Some(name) = server_override {
205 format!("Server profile '{}' has no URL configured.", name)
206 } else {
207 "Server not configured. Run 'atomic identity register <server-url>' first.".to_string()
208 };
209 CliError::Internal(anyhow::anyhow!("{}", hint))
210 })?;
211
212 let org_slug = resolve_org_with_server(org_override, server)?;
213
214 let base_url = server.org_base_url(&org_slug).ok_or_else(|| {
215 CliError::Internal(anyhow::anyhow!(
216 "Could not build org URL from server config"
217 ))
218 })?;
219
220 // Resolve identity: per-server override → global default.
221 let identity = resolve_identity_for_server(server)?;
222
223 // Log in against the server apex for a JWT bearer token.
224 let bearer_token = atomic_remote::auth::token::get_token(&server_url, &identity).await?;
225
226 let client = StorageClient::new(&base_url, &org_slug, &bearer_token).map_err(|e| {
227 CliError::Internal(anyhow::anyhow!("Failed to create storage client: {}", e))
228 })?;
229
230 Ok((client, org_slug))
231}
232
233/// Resolve the identity to authenticate as for a given server profile.
234///

Callers 8

project_initFunction · 0.85
build_clientFunction · 0.85
runMethod · 0.85
verify_workspace_existsFunction · 0.85
runMethod · 0.85
executeMethod · 0.85
runMethod · 0.85
verify_org_existsFunction · 0.85

Calls 6

resolve_org_with_serverFunction · 0.85
get_tokenFunction · 0.85
resolve_serverMethod · 0.80
org_base_urlMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected