(
plugin: Plugin<PluginState>,
mut args: serde_json::Value,
)
| 208 | } |
| 209 | |
| 210 | async fn register_path( |
| 211 | plugin: Plugin<PluginState>, |
| 212 | mut args: serde_json::Value, |
| 213 | ) -> Result<serde_json::Value, anyhow::Error> { |
| 214 | filter_json(&mut args); |
| 215 | |
| 216 | let (path_input, http_method, clnrest_map) = parse_register_path_args(args)?; |
| 217 | |
| 218 | if path_input.eq("/") { |
| 219 | return Err(anyhow!("Path must not be root")); |
| 220 | } |
| 221 | |
| 222 | let path = path_input.trim_matches('/'); |
| 223 | |
| 224 | if path.is_empty() { |
| 225 | return Err(anyhow!("Path must not be empty")); |
| 226 | } |
| 227 | if path.contains("{*") { |
| 228 | return Err(anyhow!("Wildcards not supported")); |
| 229 | } |
| 230 | |
| 231 | let mut dyn_router = plugin.state().dyn_router.lock().unwrap(); |
| 232 | if let Ok(p) = dyn_router.at_mut(path) { |
| 233 | if p.value.contains_key(&http_method) { |
| 234 | return Err(anyhow!( |
| 235 | "Conflicting path '{}' already exists with http_method: {}", |
| 236 | path, |
| 237 | http_method, |
| 238 | )); |
| 239 | } |
| 240 | |
| 241 | p.value.insert(http_method.clone(), clnrest_map.clone()); |
| 242 | } else { |
| 243 | let mut new_map = HashMap::new(); |
| 244 | new_map.insert(http_method.clone(), clnrest_map.clone()); |
| 245 | dyn_router.insert(path, new_map)?; |
| 246 | } |
| 247 | |
| 248 | log::debug!( |
| 249 | "Registered path: {} with http_method: {} to rpc_method: {} with rune_required:{} \ |
| 250 | and rune_restrictions:{}", |
| 251 | path, |
| 252 | http_method, |
| 253 | clnrest_map.rpc_method, |
| 254 | clnrest_map.rune_required, |
| 255 | if let Some(restr) = clnrest_map.rune_restrictions { |
| 256 | restr.to_string() |
| 257 | } else { |
| 258 | "{}".to_owned() |
| 259 | }, |
| 260 | ); |
| 261 | |
| 262 | Ok(json!({})) |
| 263 | } |
| 264 | |
| 265 | async fn notification_background_task(io: SocketIo, mut receiver: Receiver<serde_json::Value>) { |
| 266 | log::debug!("Background task spawned"); |
nothing calls this directly
no test coverage detected