AuthExt

Trait AuthExt 

Source
pub trait AuthExt {
    // Required methods
    fn register_policy(
        &self,
        policy: &Policy,
    ) -> impl Future<Output = Result<()>> + Send;
    fn get_policy(
        &self,
        role: &str,
    ) -> impl Future<Output = Result<Option<Policy>>> + Send;
    fn list_policies(&self) -> impl Future<Output = Result<Vec<Policy>>> + Send;
    fn assign_role(
        &self,
        node_id: &str,
        role: &str,
    ) -> impl Future<Output = Result<()>> + Send;
    fn get_role(
        &self,
        node_id: &str,
    ) -> impl Future<Output = Result<Option<String>>> + Send;
    fn check_permission(
        &self,
        node_id: &str,
        permission: Permission,
        topic: &str,
    ) -> impl Future<Output = Result<bool>> + Send;
    fn delete_policy(
        &self,
        role: &str,
    ) -> impl Future<Output = Result<()>> + Send;
    fn unassign_role(
        &self,
        node_id: &str,
    ) -> impl Future<Output = Result<()>> + Send;
}
Expand description

Authorization extension trait for Context

Required Methods§

Source

fn register_policy( &self, policy: &Policy, ) -> impl Future<Output = Result<()>> + Send

Register a policy

§Arguments
  • policy - Policy to register
§Example
use mecha10::prelude::*;
use mecha10::auth::{AuthExt, Policy, Permission};

let policy = Policy::new("camera_driver")
    .allow_publish("/sensors/camera/*")
    .allow_subscribe("/control/camera/*");

ctx.register_policy(&policy).await?;
Source

fn get_policy( &self, role: &str, ) -> impl Future<Output = Result<Option<Policy>>> + Send

Get a policy by role name

§Arguments
  • role - Role name
Source

fn list_policies(&self) -> impl Future<Output = Result<Vec<Policy>>> + Send

List all registered policies

Source

fn assign_role( &self, node_id: &str, role: &str, ) -> impl Future<Output = Result<()>> + Send

Assign a role to a node

§Arguments
  • node_id - Node identifier
  • role - Role to assign
Source

fn get_role( &self, node_id: &str, ) -> impl Future<Output = Result<Option<String>>> + Send

Get the role assigned to a node

§Arguments
  • node_id - Node identifier
Source

fn check_permission( &self, node_id: &str, permission: Permission, topic: &str, ) -> impl Future<Output = Result<bool>> + Send

Check if a node has permission to perform an action on a topic

§Arguments
  • node_id - Node identifier
  • permission - Permission type (Publish/Subscribe)
  • topic - Topic path
§Returns

true if permission is granted, false otherwise

Source

fn delete_policy(&self, role: &str) -> impl Future<Output = Result<()>> + Send

Delete a policy

§Arguments
  • role - Role name
Source

fn unassign_role( &self, node_id: &str, ) -> impl Future<Output = Result<()>> + Send

Remove role assignment from a node

§Arguments
  • node_id - Node identifier

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§