MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / resolve_variable

Method resolve_variable

nodedb/src/control/security/auth_context.rs:253–304  ·  view source on GitHub ↗

Resolve a `$auth. ` reference to its concrete value. Returns `None` if the field doesn't exist or is empty (deny by default).

(&self, field: &str)

Source from the content-addressed store, hash-verified

251 ///
252 /// Returns `None` if the field doesn't exist or is empty (deny by default).
253 pub fn resolve_variable(&self, field: &str) -> Option<serde_json::Value> {
254 match field {
255 "id" => Some(serde_json::Value::String(self.id.clone())),
256 "username" => Some(serde_json::Value::String(self.username.clone())),
257 "email" => self
258 .email
259 .as_ref()
260 .map(|e| serde_json::Value::String(e.clone())),
261 "tenant_id" => Some(serde_json::json!(self.tenant_id.as_u64())),
262 "org_id" => self
263 .org_id
264 .as_ref()
265 .map(|o| serde_json::Value::String(o.clone())),
266 "org_ids" => Some(serde_json::Value::Array(
267 self.org_ids
268 .iter()
269 .map(|s| serde_json::Value::String(s.clone()))
270 .collect(),
271 )),
272 "roles" => Some(serde_json::Value::Array(
273 self.roles
274 .iter()
275 .map(|s| serde_json::Value::String(s.clone()))
276 .collect(),
277 )),
278 "groups" => Some(serde_json::Value::Array(
279 self.groups
280 .iter()
281 .map(|s| serde_json::Value::String(s.clone()))
282 .collect(),
283 )),
284 "permissions" => Some(serde_json::Value::Array(
285 self.permissions
286 .iter()
287 .map(|s| serde_json::Value::String(s.clone()))
288 .collect(),
289 )),
290 "status" => Some(serde_json::Value::String(self.status.to_string())),
291 "auth_method" => Some(serde_json::Value::String(format!("{:?}", self.auth_method))),
292 "auth_time" => self.auth_time.map(|t| serde_json::json!(t)),
293 "session_id" => Some(serde_json::Value::String(self.session_id.clone())),
294 "database_id" => self.database_id.map(|d| serde_json::json!(d.as_u64())),
295 // Metadata sub-fields: $auth.metadata.<key>
296 other if other.starts_with("metadata.") => {
297 let key = &other["metadata.".len()..];
298 self.metadata
299 .get(key)
300 .map(|v| serde_json::Value::String(v.clone()))
301 }
302 _ => None,
303 }
304 }
305
306 /// Whether this context represents a superuser.
307 pub fn is_superuser(&self) -> bool {

Callers 4

substitute_containsFunction · 0.80
substitute_intersectsFunction · 0.80
resolveMethod · 0.80

Calls 7

collectMethod · 0.80
to_stringMethod · 0.80
cloneMethod · 0.45
as_refMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected