Skip to main content

register_scopes

Attribute Macro register_scopes 

Source
#[register_scopes]
Expand description

Attribute macro for automatic scope registration.

Scans all #[authorize] attributes in the impl block and generates inventory::submit! statements for each unique (action, resource) pair.

This ensures that all scopes are automatically registered at compile-time, making it impossible to forget scope registration.

§Example

ⓘ
#[register_scopes]
impl InferenceService {
    #[authorize(action = "infer", resource = "model", identifier_field = "model")]
    fn handle_generate(...) { }

    #[authorize(action = "read", resource = "model", identifier_field = "model")]
    fn handle_config(...) { }
}

// Automatically generates:
// inventory::submit! {
//     hyprstream_rpc::auth::ScopeDefinition::new("infer", "model", "infer:model:*", "infer on model")
// }
// inventory::submit! {
//     hyprstream_rpc::auth::ScopeDefinition::new("read", "model", "read:model:*", "read on model")
// }

§Benefits

  • ✅ DRY: Scopes declared once in #authorize, auto-registered
  • ✅ Impossible to forget: Missing #authorize = no registration = compile error
  • ✅ Self-documenting: Scopes visible via inventory::iter::<ScopeDefinition>()
  • ✅ Zero boilerplate: No manual inventory::submit! needed