Skip to main content

AuthrsClient

Struct AuthrsClient 

Source
pub struct AuthrsClient { /* private fields */ }

Implementations§

Source§

impl AuthrsClient

Source

pub fn from_env() -> Option<Arc<Self>>

Examples found in repository?
examples/server.rs (line 66)
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18    dotenvy::dotenv().ok();
19    let filter =
20        EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("architect_sdk=info"));
21    tracing_subscriber::fmt().with_env_filter(filter).init();
22
23    let database_url =
24        std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite://architect.db".into());
25    ensure_database_exists(&database_url).await?;
26
27    // create_pool uses the compiled-in dialect automatically (sqlite by default).
28    let pool = create_pool(&database_url, 5).await?;
29
30    let dialect = architect_sdk::db::active_dialect();
31    ensure_sys_tables(&pool, dialect.as_ref()).await?;
32
33    let tenant_registry = load_registry_from_pool(&pool)
34        .await
35        .map_err(|e| -> Box<dyn std::error::Error> { Box::new(e) })?;
36    tracing::info!("loaded tenant registry (X-Tenant-ID required for config and entity APIs)");
37
38    let (config, package_id) = match std::env::var("PACKAGE_PATH") {
39        Ok(package_path) => {
40            tracing::info!("loading config from package path: {}", package_path);
41            let (cfg, id) = load_config_from_package_path(&package_path).await?;
42            (cfg, id)
43        }
44        Err(_) => {
45            tracing::info!("PACKAGE_PATH not set; loading config from _sys_* tables (use config APIs or POST /api/v1/config/package to insert)");
46            let cfg = load_from_pool(&pool, DEFAULT_PACKAGE_ID)
47                .await
48                .map_err(|e| -> Box<dyn std::error::Error> { Box::new(e) })?;
49            (cfg, DEFAULT_PACKAGE_ID.to_string())
50        }
51    };
52    apply_migrations(
53        &pool,
54        &config,
55        None,
56        None,
57        dialect.as_ref(),
58        &HashMap::new(),
59    )
60    .await?;
61    let model = resolve(&config)?.with_package_id(&package_id);
62    let mut package_models = HashMap::new();
63    package_models.insert(package_id.clone(), model.clone());
64    let storage = architect_sdk::init_storage_provider().await;
65    let event_client = architect_sdk::events::DecisionHubClient::from_env();
66    let authrs_client = architect_sdk::authrs::AuthrsClient::from_env();
67    let state = AppState {
68        pool: pool.clone(),
69        model: Arc::new(RwLock::new(model)),
70        package_models: Arc::new(RwLock::new(package_models)),
71        tenant_pools: Arc::new(RwLock::new(HashMap::new())),
72        tenant_registry: Arc::new(tenant_registry),
73        storage,
74        event_client,
75        authrs_client,
76        dialect,
77        extensible_cache: Default::default(),
78    };
79
80    let api = Router::new()
81        .merge(common_routes_with_ready(state.clone()))
82        .nest("/api/v1", config_routes(state.clone()))
83        .nest("/api/v1", entity_routes(state));
84
85    let app = Router::new().nest("/", api);
86
87    let listener = TcpListener::bind("0.0.0.0:3000").await?;
88    tracing::info!("listening on {}", listener.local_addr()?);
89    axum::serve(listener, app).await?;
90    Ok(())
91}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more