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

Function build_apex_client

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

Build a [`StorageClient`] targeting the server **apex** (no org subdomain). Apex-scoped endpoints — notably `GET /orgs` ("list my orgs") and `POST /orgs` ("create org") — span orgs, so they must be hit on the bare server host rather than an ` . ` subdomain. This helper resolves the active server profile, mints a self-signed EdDSA JWT against the apex URL, and constructs a `StorageClient`

(server_override: Option<&str>)

Source from the content-addressed store, hash-verified

80/// - Identity store cannot be opened or no default identity set.
81/// - HTTP client construction failure.
82pub async fn build_apex_client(server_override: Option<&str>) -> CliResult<StorageClient> {
83 let config = GlobalConfig::load()
84 .map_err(|e| CliError::Internal(anyhow::anyhow!("Failed to load global config: {}", e)))?;
85
86 let server = config
87 .resolve_server(server_override)
88 .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?
89 .0;
90
91 let apex_url = server.url.clone().ok_or_else(|| {
92 let hint = if let Some(name) = server_override {
93 format!("Server profile '{}' has no URL configured.", name)
94 } else {
95 "Server not configured. Run 'atomic identity register <server-url>' first.".to_string()
96 };
97 CliError::Internal(anyhow::anyhow!("{}", hint))
98 })?;
99
100 let identity = resolve_identity_for_server(server)?;
101
102 // Self-signed EdDSA JWT keyed by the identity's own public key; minted
103 // against the apex URL (the token is portable across the deployment).
104 let bearer_token = crate::commands::token::get_token(&apex_url, &identity).await?;
105
106 let client = StorageClient::new(&apex_url, "", &bearer_token).map_err(|e| {
107 CliError::Internal(anyhow::anyhow!("Failed to create storage client: {}", e))
108 })?;
109
110 Ok(client)
111}
112
113/// Build a [`StorageClient`] and return the resolved org slug alongside it.
114///

Callers 2

executeMethod · 0.85
executeMethod · 0.85

Calls 4

get_tokenFunction · 0.85
resolve_serverMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected