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

Method alter

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

Alter a scope's grants and/or includes.

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

Source from the content-addressed store, hash-verified

119
120 /// Alter a scope's grants and/or includes.
121 pub fn alter(
122 &self,
123 name: &str,
124 grants: Option<Vec<(String, String)>>,
125 includes: Option<Vec<String>>,
126 ) -> crate::Result<bool> {
127 let mut scopes = self.scopes.write().unwrap_or_else(|p| p.into_inner());
128 if !scopes.contains_key(name) {
129 return Ok(false);
130 }
131 // Validate includes before mutating.
132 if let Some(ref inc) = includes {
133 for i in inc {
134 if i != name && !scopes.contains_key(i) {
135 return Err(crate::Error::BadRequest {
136 detail: format!("included scope '{i}' does not exist"),
137 });
138 }
139 }
140 }
141 let def = scopes.get_mut(name).ok_or(crate::Error::BadRequest {
142 detail: format!("scope '{name}' not found"),
143 })?;
144 if let Some(g) = grants {
145 def.grants = g;
146 }
147 if let Some(inc) = includes {
148 def.includes = inc;
149 }
150 if let Some(ref catalog) = self.catalog {
151 catalog.put_scope(&def.to_stored())?;
152 }
153 info!(scope = %name, "scope altered");
154 Ok(true)
155 }
156
157 /// Drop a scope.
158 pub fn drop_scope(&self, name: &str) -> crate::Result<bool> {

Callers 1

alter_scopeFunction · 0.80

Calls 4

put_scopeMethod · 0.80
writeMethod · 0.45
get_mutMethod · 0.45
to_storedMethod · 0.45

Tested by

no test coverage detected