Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(agent_schedule): use macro_authorization (#4922)
Will Hutchinsone2738828f27a
diff --git a/Cargo.lock b/Cargo.lockindex a28c7c6157..3f2a584a72 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -12249,6 +12249,7 @@ dependencies = ["doppler-config","futures","macro_auth",+ "macro_authorization","macro_aws_config","macro_config","macro_cors",@@ -12256,7 +12257,6 @@ dependencies = ["macro_entrypoint","macro_env","macro_env_var",- "macro_middleware","macro_queues","macro_service_urls","macro_user_id",@@ -12265,7 +12265,6 @@ dependencies = ["model","model-entity","model_notifications",- "model_user","notification","secretsmanager_client","serde",diff --git a/services/scheduled_action/Cargo.toml b/services/scheduled_action/Cargo.tomlindex b0af2d6c3b..36f0f6b302 100644--- a/services/scheduled_action/Cargo.toml+++ b/services/scheduled_action/Cargo.toml@@ -18,7 +18,7 @@ path = "src/doppler_config.rs"[features]default = []-local_auth = ["macro_middleware/local_auth"]+local_auth = ["macro_authorization/local_auth"][dependencies]serde = { workspace = true }@@ -26,6 +26,7 @@ serde_json = { workspace = true }macro_env_var = { path = "../../crates/macro_env_var" }macro_queues = { path = "../../crates/macro_queues" }macro_config = { path = "../../crates/macro_config" }+macro_authorization = { path = "../../crates/macro_authorization" }database_env_vars = { path = "../../crates/database_env_vars" }doppler-config = { workspace = true }sqlx = { workspace = true }@@ -41,7 +42,6 @@ tokio = { workspace = true }futures = { workspace = true }tracing = { workspace = true }axum = { workspace = true }-model_user = { path = "../../crates/model_user", features = ["axum"] }ai_tools = { path = "../../crates/ai_tools" }ai_toolset = { path = "../../crates/ai_toolset" }aws-sdk-sqs = { workspace = true }@@ -61,9 +61,6 @@ macro_cors = { path = "../../crates/macro_cors" }macro_auth = { path = "../../crates/macro_auth" }macro_entrypoint = { path = "../../crates/macro_entrypoint" }macro_env = { path = "../../crates/macro_env" }-macro_middleware = { path = "../../crates/macro_middleware", default-features = false, features = [- "auth",-] }secretsmanager_client = { path = "../../crates/secretsmanager_client" }aws-sdk-secretsmanager = { workspace = true }diff --git a/services/scheduled_action/src/bins/service.rs b/services/scheduled_action/src/bins/service.rsindex 55f8f571c1..f35b4a4d3e 100644--- a/services/scheduled_action/src/bins/service.rs+++ b/services/scheduled_action/src/bins/service.rs@@ -6,6 +6,10 @@ use anyhow::{Context, Result};use axum::Router;use connection_gateway_client::client::ConnectionGatewayClient;use macro_auth::middleware::decode_jwt::JwtValidationArgs;+use macro_authorization::{+ InternalAuthConfig, MacroAuthJwtValidator, MacroAuthorizationServiceImpl,+ MacroAuthorizationState,+};use macro_entrypoint::MacroEntrypoint;use macro_service_urls::ConnectionGatewayUrl;use notification::domain::service::SqsNotificationIngress;@@ -96,10 +100,20 @@ async fn main() -> Result<()> {.await.context("failed to build jwt validation args")?;- let state = ScheduledActionRouterState { service };- let authed_routes = scheduled_action_router::<_, ()>(state).layer(- axum::middleware::from_fn_with_state(jwt_args, macro_middleware::auth::decode_jwt::handler),+ let authorization_service = MacroAuthorizationServiceImpl::new(+ MacroAuthJwtValidator::new(jwt_args),+ InternalAuthConfig {+ api_key: config.internal_api_key.to_string(),+ default_user_id: None,+ },);+ let authorization_state = MacroAuthorizationState::new(Arc::new(authorization_service));++ let state = ScheduledActionRouterState {+ service,+ authorization_state,+ };+ let authed_routes = scheduled_action_router::<_, _, ()>(state);let router = Router::new().route("/health", axum::routing::get(health))diff --git a/services/scheduled_action/src/inbound/axum_router.rs b/services/scheduled_action/src/inbound/axum_router.rsindex 043c6f4a91..ca2a88b5b7 100644--- a/services/scheduled_action/src/inbound/axum_router.rs+++ b/services/scheduled_action/src/inbound/axum_router.rs@@ -1,14 +1,16 @@use std::sync::Arc;-use axum::extract::{Path, State};+use axum::extract::{FromRef, Path, State};use axum::http::StatusCode;use axum::response::IntoResponse;use axum::routing::{get, post, put};use axum::{Json, Router};use chrono::Utc;+use macro_authorization::{+ MacroAuthorizationExtractor, MacroAuthorizationService, MacroAuthorizationState,+};use macro_uuid::Uuid;use model::response::EmptyResponse;-use model_user::axum_extractor::MacroUserExtractor;use crate::domain::models::{ActionExecutionRecord, AlreadyRunningError, CreateScheduledAction, InProgressExecution,@@ -16,34 +18,51 @@ use crate::domain::models::{};use crate::domain::ports::ScheduledActionService;-pub struct ScheduledActionRouterState<S> {+pub struct ScheduledActionRouterState<S, Auth> {pub service: Arc<S>,+ pub authorization_state: MacroAuthorizationState<Auth>,}-impl<S> Clone for ScheduledActionRouterState<S> {+impl<S, Auth> Clone for ScheduledActionRouterState<S, Auth> {fn clone(&self) -> Self {Self {service: Arc::clone(&self.service),+ authorization_state: self.authorization_state.clone(),}}}-pub fn scheduled_action_router<S, St>(state: ScheduledActionRouterState<S>) -> Router<St>+impl<S, Auth> FromRef<ScheduledActionRouterState<S, Auth>> for MacroAuthorizationState<Auth> {+ fn from_ref(state: &ScheduledActionRouterState<S, Auth>) -> Self {+ state.authorization_state.clone()+ }+}++pub fn scheduled_action_router<S, Auth, St>(+ state: ScheduledActionRouterState<S, Auth>,+) -> Router<St>whereS: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,St: Send + Sync,{Router::new().route("/scheduled-actions",- get(list_actions::<S>).post(create_action::<S>),+ get(list_actions::<S, Auth>).post(create_action::<S, Auth>),).route("/scheduled-actions/{id}",- put(update_action::<S>).delete(delete_action::<S>),+ put(update_action::<S, Auth>).delete(delete_action::<S, Auth>),+ )+ .route(+ "/scheduled-actions/{id}/execute",+ post(execute_action::<S, Auth>),+ )+ .route(+ "/scheduled-actions/{id}/history",+ get(list_history::<S, Auth>),)- .route("/scheduled-actions/{id}/execute", post(execute_action::<S>))- .route("/scheduled-actions/{id}/history", get(list_history::<S>)).with_state(state)}@@ -72,9 +91,12 @@ pub async fn health() -> impl IntoResponse {(status = 500, body = String),))]-pub async fn create_action<S: ScheduledActionService + Send + Sync + 'static>(- State(state): State<ScheduledActionRouterState<S>>,- user: MacroUserExtractor,+pub async fn create_action<+ S: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,+>(+ State(state): State<ScheduledActionRouterState<S, Auth>>,+ user: MacroAuthorizationExtractor<Auth>,Json(req): Json<CreateScheduledAction>,) -> Result<impl IntoResponse, ScheduledActionApiError> {let now = Utc::now();@@ -111,9 +133,12 @@ pub async fn create_action<S: ScheduledActionService + Send + Sync + 'static>((status = 500, body = String),))]-pub async fn list_actions<S: ScheduledActionService + Send + Sync + 'static>(- State(state): State<ScheduledActionRouterState<S>>,- user: MacroUserExtractor,+pub async fn list_actions<+ S: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,+>(+ State(state): State<ScheduledActionRouterState<S, Auth>>,+ user: MacroAuthorizationExtractor<Auth>,) -> Result<impl IntoResponse, ScheduledActionApiError> {let actions = state.service.get_actions(user.macro_user_id).await?;Ok(Json(actions))@@ -133,9 +158,12 @@ pub async fn list_actions<S: ScheduledActionService + Send + Sync + 'static>((status = 500, body = String),))]-pub async fn update_action<S: ScheduledActionService + Send + Sync + 'static>(- State(state): State<ScheduledActionRouterState<S>>,- user: MacroUserExtractor,+pub async fn update_action<+ S: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,+>(+ State(state): State<ScheduledActionRouterState<S, Auth>>,+ user: MacroAuthorizationExtractor<Auth>,Path(id): Path<Uuid>,Json(req): Json<UpdateScheduledAction>,) -> Result<impl IntoResponse, ScheduledActionApiError> {@@ -178,9 +206,12 @@ pub async fn update_action<S: ScheduledActionService + Send + Sync + 'static>((status = 500, body = String),))]-pub async fn delete_action<S: ScheduledActionService + Send + Sync + 'static>(- State(state): State<ScheduledActionRouterState<S>>,- user: MacroUserExtractor,+pub async fn delete_action<+ S: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,+>(+ State(state): State<ScheduledActionRouterState<S, Auth>>,+ user: MacroAuthorizationExtractor<Auth>,Path(id): Path<Uuid>,) -> Result<impl IntoResponse, ScheduledActionApiError> {state.service.delete_action(&id, user.macro_user_id).await?;@@ -201,9 +232,12 @@ pub async fn delete_action<S: ScheduledActionService + Send + Sync + 'static>((status = 500, body = String),))]-pub async fn execute_action<S: ScheduledActionService + Send + Sync + 'static>(- State(state): State<ScheduledActionRouterState<S>>,- user: MacroUserExtractor,+pub async fn execute_action<+ S: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,+>(+ State(state): State<ScheduledActionRouterState<S, Auth>>,+ user: MacroAuthorizationExtractor<Auth>,Path(id): Path<Uuid>,) -> Result<impl IntoResponse, ScheduledActionApiError> {let execution = state@@ -226,9 +260,12 @@ pub async fn execute_action<S: ScheduledActionService + Send + Sync + 'static>((status = 500, body = String),))]-pub async fn list_history<S: ScheduledActionService + Send + Sync + 'static>(- State(state): State<ScheduledActionRouterState<S>>,- user: MacroUserExtractor,+pub async fn list_history<+ S: ScheduledActionService + Send + Sync + 'static,+ Auth: MacroAuthorizationService,+>(+ State(state): State<ScheduledActionRouterState<S, Auth>>,+ user: MacroAuthorizationExtractor<Auth>,Path(id): Path<Uuid>,) -> Result<impl IntoResponse, ScheduledActionApiError> {let records = state