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

Method with_delegation

atomic-remote/src/storage.rs:98–133  ·  view source on GitHub ↗

Create a client that also presents a delegation certificate. `delegation` is the base64url-encoded certificate an agent acts under. It travels on every request because the server verifies it there and then, against the delegator's registered key — grants are presented, not registered, which is what makes issuing one free of a server round trip. `None` is an ordinary, non-delegated client.

(
        base_url: &str,
        org_slug: &str,
        bearer_token: &str,
        delegation: Option<&str>,
    )

Source from the content-addressed store, hash-verified

96 ///
97 /// `None` is an ordinary, non-delegated client.
98 pub fn with_delegation(
99 base_url: &str,
100 org_slug: &str,
101 bearer_token: &str,
102 delegation: Option<&str>,
103 ) -> Result<Self, RemoteError> {
104 let mut headers = HeaderMap::new();
105 if let Some(encoded) = delegation {
106 headers.insert(
107 HeaderName::from_static(DELEGATION_HEADER_LOWER),
108 HeaderValue::from_str(encoded).map_err(|e| {
109 RemoteError::other(format!("invalid delegation certificate: {}", e))
110 })?,
111 );
112 }
113 headers.insert(
114 AUTHORIZATION,
115 HeaderValue::from_str(&format!("Bearer {}", bearer_token))
116 .map_err(|e| RemoteError::other(format!("invalid bearer token: {}", e)))?,
117 );
118 headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
119
120 let user_agent = format!("atomic/{}", crate::VERSION);
121
122 let http = reqwest::Client::builder()
123 .default_headers(headers)
124 .user_agent(user_agent)
125 .build()
126 .map_err(|e| RemoteError::other(format!("failed to build HTTP client: {}", e)))?;
127
128 Ok(Self {
129 http,
130 base_url: base_url.trim_end_matches('/').to_string(),
131 org_slug: org_slug.to_string(),
132 })
133 }
134
135 /// The org slug this client is scoped to.
136 pub fn org_slug(&self) -> &str {

Callers

nothing calls this directly

Calls 2

insertMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected