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

Method define

nodedb/src/control/security/scope/store.rs:83–118  ·  view source on GitHub ↗

Define or replace a scope.

(
        &self,
        name: &str,
        grants: Vec<(String, String)>,
        includes: Vec<String>,
        created_by: &str,
    )

Source from the content-addressed store, hash-verified

81
82 /// Define or replace a scope.
83 pub fn define(
84 &self,
85 name: &str,
86 grants: Vec<(String, String)>,
87 includes: Vec<String>,
88 created_by: &str,
89 ) -> crate::Result<()> {
90 // Validate included scopes exist.
91 {
92 let scopes = self.scopes.read().unwrap_or_else(|p| p.into_inner());
93 for inc in &includes {
94 if !scopes.contains_key(inc) {
95 return Err(crate::Error::BadRequest {
96 detail: format!("included scope '{inc}' does not exist"),
97 });
98 }
99 }
100 }
101
102 let def = ScopeDefinition {
103 name: name.into(),
104 grants,
105 includes,
106 created_by: created_by.into(),
107 created_at: now_secs(),
108 };
109
110 if let Some(ref catalog) = self.catalog {
111 catalog.put_scope(&def.to_stored())?;
112 }
113
114 let mut scopes = self.scopes.write().unwrap_or_else(|p| p.into_inner());
115 scopes.insert(name.into(), def);
116 info!(scope = %name, "scope defined");
117 Ok(())
118 }
119
120 /// Alter a scope's grants and/or includes.
121 pub fn alter(

Callers 4

define_and_getFunction · 0.45
scope_compositionFunction · 0.45
scope_grants_checkFunction · 0.45
include_validationFunction · 0.45

Calls 6

put_scopeMethod · 0.80
now_secsFunction · 0.70
readMethod · 0.45
to_storedMethod · 0.45
writeMethod · 0.45
insertMethod · 0.45

Tested by 4

define_and_getFunction · 0.36
scope_compositionFunction · 0.36
scope_grants_checkFunction · 0.36
include_validationFunction · 0.36