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

Method fetch_project_identity

atomic-remote/src/http/identity.rs:131–166  ·  view source on GitHub ↗

Read the remote's project-identity binding.

(&self)

Source from the content-addressed store, hash-verified

129impl HttpRemote {
130 /// Read the remote's project-identity binding.
131 pub async fn fetch_project_identity(&self) -> RemoteResult<IdentityFetch> {
132 let url = format!("{}?project-identity=1", self.base_url.as_str());
133 let response = self
134 .client
135 .get(&url)
136 .send()
137 .await
138 .map_err(|e| RemoteError::connection_failed(&url, e))?;
139 match response.status() {
140 StatusCode::OK => {
141 let parsed: IdentityResponse = response.json().await.map_err(|e| {
142 RemoteError::protocol(format!("invalid project-identity response: {e}"))
143 })?;
144 match (parsed.bound, parsed.identity) {
145 (Some(true), Some(identity)) => Ok(IdentityFetch::Bound(identity)),
146 (Some(false), _) => Ok(IdentityFetch::Unbound),
147 // A 200 without `bound` is a pre-transport server's
148 // project-info ping (it ignores unknown query params).
149 _ => Ok(IdentityFetch::Unsupported),
150 }
151 }
152 // Old servers: `GET …/code` answers the project-info ping (no
153 // `bound` field) and unknown paths 404. Both mean "unsupported".
154 StatusCode::NOT_FOUND
155 | StatusCode::METHOD_NOT_ALLOWED
156 | StatusCode::NOT_IMPLEMENTED => Ok(IdentityFetch::Unsupported),
157 StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Err(RemoteError::auth_failed(
158 &url,
159 response.text().await.unwrap_or_default(),
160 )),
161 s => Err(RemoteError::http(
162 s.as_u16(),
163 response.text().await.unwrap_or_default(),
164 )),
165 }
166 }
167
168 /// Offer the local identity document for binding (first-write-wins).
169 pub async fn bind_project_identity(&self, identity: &Value) -> RemoteResult<BindOutcome> {

Calls 4

textMethod · 0.80
getMethod · 0.65
statusMethod · 0.45
jsonMethod · 0.45