Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

refactor: move properties endpoints into dss (#1238)

Will Hutchinsonccb32069e723
diff --git a/.github/services-config.json b/.github/services-config.json
index 8458d87fa2..f5c0494d38 100644
--- a/.github/services-config.json
+++ b/.github/services-config.json
@@ -91,12 +91,6 @@
],
"stack_path": "infra/stacks/organization-retention/**"
},
- "properties-service": {
- "source_paths": [
- "rust/cloud-storage/properties_service/**"
- ],
- "stack_path": "infra/stacks/properties-service/**"
- },
"search-processing-service": {
"source_paths": [
"rust/cloud-storage/search_processing_service/**"
diff --git a/.github/workflows/deploy-service-generic.yml b/.github/workflows/deploy-service-generic.yml
index 856ef39d69..1a5f25139c 100644
--- a/.github/workflows/deploy-service-generic.yml
+++ b/.github/workflows/deploy-service-generic.yml
@@ -27,7 +27,6 @@ on:
- link-sharing
- notification-service
- organization-retention
- - properties-service
- search-processing-service
- search-service
- search-upload
diff --git a/docker-compose.yml b/docker-compose.yml
index 7c93be357c..c91bd51ddb 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -239,30 +239,6 @@ services:
retries: 3
start_period: 10s
- # ============================================================================
- # properties_service (Port 8091)
- # User/document properties
- # ============================================================================
- properties_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: properties_service
- ports:
- - "8091:8080"
- depends_on:
- - comms_service
- networks:
- - databases
- - services
- healthcheck:
- test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
- interval: 30s
- timeout: 10s
- retries: 3
- start_period: 10s
-
# ============================================================================
# search_processing_service (Port 8092)
# Search indexing worker
diff --git a/js/app/bun.lock b/js/app/bun.lock
index 9f76a501ff..015a5158c4 100644
--- a/js/app/bun.lock
+++ b/js/app/bun.lock
@@ -1,5 +1,6 @@
{
"lockfileVersion": 1,
+ "configVersion": 0,
"workspaces": {
"": {
"name": "@coparse/monorepo",
diff --git a/js/app/packages/core/constant/servers.ts b/js/app/packages/core/constant/servers.ts
index 91714ea72e..b31656363e 100644
--- a/js/app/packages/core/constant/servers.ts
+++ b/js/app/packages/core/constant/servers.ts
@@ -13,7 +13,6 @@ const serverHostLocal: Servers = {
contacts: 'http://localhost:8083',
'email-service': 'http://localhost:8087',
'search-service': 'http://localhost:8093',
- 'properties-service': 'http://localhost:8091',
} as const;
const devServerSuffix = import.meta.env.MODE === 'development' ? '-dev' : '';
@@ -33,7 +32,6 @@ const serverHostRemote = {
contacts: `https://contacts${devServerSuffix}.macro.com`,
'email-service': `https://email-service${devServerSuffix}.macro.com`,
'search-service': `https://search-service${devServerSuffix}.macro.com`,
- 'properties-service': `https://properties-service${devServerSuffix}.macro.com`,
} as const;
type Servers = Record<keyof typeof serverHostRemote, string>;
diff --git a/js/app/packages/service-clients/service-properties/client.ts b/js/app/packages/service-clients/service-properties/client.ts
index d89866f27c..7714523306 100644
--- a/js/app/packages/service-clients/service-properties/client.ts
+++ b/js/app/packages/service-clients/service-properties/client.ts
@@ -66,7 +66,7 @@ type GetBulkEntityPropertiesArgs = {
body: BulkEntityPropertiesRequest;
};
-const propertiesHost: string = SERVER_HOSTS['properties-service'];
+const propertiesHost: string = SERVER_HOSTS['document-storage-service'];
export function propertiesFetch(
url: string,
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 82b08aee53..f39686958e 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2500,8 +2500,9 @@ dependencies = [
"macro_env",
"macro_redis_cluster_client",
"model",
+ "models_properties",
"openssl",
- "properties_service_client",
+ "properties_db_client",
"redis",
"s3_client",
"secretsmanager_client",
@@ -2796,6 +2797,7 @@ dependencies = [
"models_soup",
"ordered-float",
"properties",
+ "properties_service",
"rayon",
"redis",
"regex",
@@ -6705,7 +6707,6 @@ dependencies = [
"aws-sdk-secretsmanager",
"axum",
"chrono",
- "comms_service_client",
"email_db_client",
"http-body-util",
"macro_auth",
@@ -6738,18 +6739,6 @@ dependencies = [
"uuid",
]
-[[package]]
-name = "properties_service_client"
-version = "0.1.0"
-dependencies = [
- "anyhow",
- "macro_service_client",
- "models_properties",
- "reqwest",
- "serde",
- "tracing",
-]
-
[[package]]
name = "pxfm"
version = "0.1.25"
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 47d67674c0..d6159491c9 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -89,7 +89,6 @@ members = [
"properties",
"properties_db_client",
"properties_service",
- "properties_service_client",
"roles_and_permissions",
"rpc/axum_rpc",
"rpc/axum_rpc_emit",
diff --git a/rust/cloud-storage/Dockerfile.dev b/rust/cloud-storage/Dockerfile.dev
index 0e5ddd87de..767571fd7a 100644
--- a/rust/cloud-storage/Dockerfile.dev
+++ b/rust/cloud-storage/Dockerfile.dev
@@ -16,7 +16,6 @@ RUN cargo build --release \
--bin document_storage_service \
--bin email_service \
--bin notification_service \
- --bin properties_service \
--bin search_service \
--bin static_file_service \
--bin unfurl_service \
@@ -72,11 +71,6 @@ COPY --from=builder /app/target/release/notification_service /app/svc
RUN chmod +x /app/svc
ENTRYPOINT ["dumb-init", "./svc"]
-FROM base AS properties_service
-COPY --from=builder /app/target/release/properties_service /app/svc
-RUN chmod +x /app/svc
-ENTRYPOINT ["dumb-init", "./svc"]
-
FROM base AS search_service
COPY --from=builder /app/target/release/search_service /app/svc
RUN chmod +x /app/svc
diff --git a/rust/cloud-storage/delete_document_worker/Cargo.toml b/rust/cloud-storage/delete_document_worker/Cargo.toml
index 8ad55fb022..21f7a81c42 100644
--- a/rust/cloud-storage/delete_document_worker/Cargo.toml
+++ b/rust/cloud-storage/delete_document_worker/Cargo.toml
@@ -25,7 +25,6 @@ macro_env = { path = "../macro_env" }
macro_redis_cluster_client = { path = "../macro_redis_cluster_client" }
model = { path = "../model" }
openssl = { workspace = true }
-properties_service_client = { path = "../properties_service_client" }
redis = { workspace = true, features = [
"aio",
"cluster-async",
@@ -41,6 +40,8 @@ tokio = { workspace = true }
tower = { workspace = true }
tower-http = { workspace = true }
tracing = { workspace = true }
+properties_db_client = { path = "../properties_db_client" }
+models_properties = { path = "../models_properties" }
[package.metadata.cargo-machete]
ignored = ["openssl"]
diff --git a/rust/cloud-storage/delete_document_worker/src/config.rs b/rust/cloud-storage/delete_document_worker/src/config.rs
index 566e111ced..cd825a4670 100644
--- a/rust/cloud-storage/delete_document_worker/src/config.rs
+++ b/rust/cloud-storage/delete_document_worker/src/config.rs
@@ -31,12 +31,6 @@ pub struct Config {
/// sync service URL
pub sync_service_url: String,
-
- /// Properties service auth key
- pub properties_service_auth_key: String,
-
- /// Properties service URL
- pub properties_service_url: String,
}
impl Config {
@@ -79,12 +73,6 @@ impl Config {
let sync_service_url =
std::env::var("SYNC_SERVICE_URL").context("SYNC_SERVICE_URL must be provided")?;
- let properties_service_auth_key = std::env::var("PROPERTIES_SERVICE_AUTH_KEY")
- .context("PROPERTIES_SERVICE_AUTH_KEY must be provided")?;
-
- let properties_service_url = std::env::var("PROPERTIES_SERVICE_URL")
- .context("PROPERTIES_SERVICE_URL must be provided")?;
-
Ok(Config {
database_url,
redis_uri,
@@ -98,8 +86,6 @@ impl Config {
comms_service_url,
sync_service_auth_key,
sync_service_url,
- properties_service_auth_key,
- properties_service_url,
})
}
}
diff --git a/rust/cloud-storage/delete_document_worker/src/context.rs b/rust/cloud-storage/delete_document_worker/src/context.rs
index c5e6703dfc..4d0b6bcb69 100644
--- a/rust/cloud-storage/delete_document_worker/src/context.rs
+++ b/rust/cloud-storage/delete_document_worker/src/context.rs
@@ -12,6 +12,5 @@ pub struct QueueWorkerContext {
pub redis_client: Arc<Redis>,
pub sync_service_client: Arc<sync_service_client::SyncServiceClient>,
pub comms_service_client: Arc<comms_service_client::CommsServiceClient>,
- pub properties_service_client: Arc<properties_service_client::PropertiesServiceClient>,
pub config: Config,
}
diff --git a/rust/cloud-storage/delete_document_worker/src/main.rs b/rust/cloud-storage/delete_document_worker/src/main.rs
index d0532a1e94..412064cc0f 100644
--- a/rust/cloud-storage/delete_document_worker/src/main.rs
+++ b/rust/cloud-storage/delete_document_worker/src/main.rs
@@ -92,20 +92,6 @@ pub async fn main() -> anyhow::Result<()> {
config.comms_service_url.clone(),
);
- let properties_service_auth_key = match config.environment {
- Environment::Local => config.properties_service_auth_key.clone(),
- _ => secretsmanager_client
- .get_secret_value(&config.properties_service_auth_key)
- .await
- .context("unable to get secret")?
- .to_string(),
- };
-
- let properties_service_client = properties_service_client::PropertiesServiceClient::new(
- properties_service_auth_key,
- config.properties_service_url.clone(),
- );
-
let queue_worker_context = QueueWorkerContext {
db: db.clone(),
worker: Arc::new(delete_document_worker),
@@ -113,7 +99,6 @@ pub async fn main() -> anyhow::Result<()> {
redis_client: Arc::new(redis_client),
sync_service_client: Arc::new(sync_service_client),
comms_service_client: Arc::new(comms_service_client),
- properties_service_client: Arc::new(properties_service_client),
config: config.clone(),
};
diff --git a/rust/cloud-storage/delete_document_worker/src/process/handle.rs b/rust/cloud-storage/delete_document_worker/src/process/handle.rs
index 3ec9192897..c20d3e2b8b 100644
--- a/rust/cloud-storage/delete_document_worker/src/process/handle.rs
+++ b/rust/cloud-storage/delete_document_worker/src/process/handle.rs
@@ -1,4 +1,6 @@
use anyhow::Context;
+use models_properties::{EntityReference, EntityType};
+use properties_db_client::entity_properties::delete as entity_properties_delete;
#[tracing::instrument(skip(ctx, message), fields(message_id=message.message_id))]
pub async fn handle(
@@ -95,13 +97,11 @@ pub async fn handle(
// Delete document properties
tracing::trace!(document_id=%document_id, "deleting document properties");
- let _ = ctx
- .properties_service_client
- .delete_entity(document_id, properties_service_client::EntityType::Document)
+
+ let entity_reference = EntityReference::new(document_id, EntityType::Document);
+ let _ = entity_properties_delete::delete_entity(&ctx.db, &entity_reference)
.await
- .inspect_err(|e| {
- tracing::warn!(error=?e, document_id=%document_id, "could not delete document properties");
- });
+ .inspect_err(|e| tracing::error!(error=?e, "failed to delete entity properties"));
tracing::trace!(document_id=%document_id, "deleted document properties");
let _ = ctx.worker.cleanup_message(message).await.inspect_err(|e| {
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index dbcc29fb8e..e21fd54b32 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -86,6 +86,7 @@ models_permissions = { path = "../models_permissions" }
models_properties = { path = "../models_properties" }
models_soup = { path = "../models_soup", features = ["schema"] }
properties = { path = "../properties" }
+properties_service = { path = "../properties_service" }
rayon = "1.10.0"
redis = { workspace = true, features = [
"aio",
diff --git a/rust/cloud-storage/document_storage_service/src/api/context.rs b/rust/cloud-storage/document_storage_service/src/api/context.rs
index ac3d332590..b43fb2fd2e 100644
--- a/rust/cloud-storage/document_storage_service/src/api/context.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs
@@ -14,6 +14,7 @@ use macro_redis_cluster_client::Redis;
use properties::{
NotificationServiceImpl, PermissionServiceImpl, PropertiesPgRepo, PropertiesServiceImpl,
};
+use properties_service::PropertiesHandlerState;
use soup::{
domain::service::SoupImpl, inbound::axum_router::SoupRouterState,
outbound::pg_soup_repo::PgSoupRepo,
@@ -65,3 +66,18 @@ env_var! {
#[derive(Clone)]
pub struct DocumentStorageServiceAuthKey;
}
+
+impl From<&ApiContext> for PropertiesHandlerState {
+ fn from(ctx: &ApiContext) -> Self {
+ PropertiesHandlerState {
+ db: ctx.db.clone(),
+ properties_service: ctx.properties_service.clone(),
+ }
+ }
+}
+
+impl FromRef<ApiContext> for PropertiesHandlerState {
+ fn from_ref(ctx: &ApiContext) -> Self {
+ PropertiesHandlerState::from(ctx)
+ }
+}
diff --git a/rust/cloud-storage/document_storage_service/src/api/mod.rs b/rust/cloud-storage/document_storage_service/src/api/mod.rs
index 26565363eb..3227c1b775 100644
--- a/rust/cloud-storage/document_storage_service/src/api/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/mod.rs
@@ -1,12 +1,14 @@
use crate::api::context::ApiContext;
use anyhow::Context;
use axum::Router;
+use axum::extract::FromRef;
use axum::extract::Request;
use axum::http::Method;
use axum::middleware::Next;
use context::InternalFlag;
use macro_axum_utils::compose_layers;
use model::version::{ServiceNameState, VersionedApiServiceName, validate_api_version};
+use properties_service::PropertiesHandlerState;
use tower::ServiceBuilder;
use tower_http::compression::CompressionLayer;
use tower_http::trace::TraceLayer;
@@ -148,6 +150,11 @@ fn api_router(state: ApiContext) -> Router {
macro_middleware::connection_drop_prevention_handler,
)),
)
+ .nest(
+ "/properties",
+ properties_service::properties_router()
+ .with_state(PropertiesHandlerState::from_ref(&state)),
+ )
.layer(
ServiceBuilder::new()
.layer(axum::middleware::from_fn(
diff --git a/rust/cloud-storage/properties_service/Cargo.toml b/rust/cloud-storage/properties_service/Cargo.toml
index fe17546bf9..5669e06aae 100644
--- a/rust/cloud-storage/properties_service/Cargo.toml
+++ b/rust/cloud-storage/properties_service/Cargo.toml
@@ -1,23 +1,17 @@
[package]
-default-run = "properties_service"
edition = "2024"
name = "properties_service"
publish = false
version = "0.1.0"
-[[bin]]
+[lib]
name = "properties_service"
-path = "src/main.rs"
-required-features = []
+path = "src/lib.rs"
[[bin]]
name = "properties_service_openapi"
path = "src/openapi.rs"
-[features]
-local_auth = []
-tree_trace = []
-
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
@@ -25,7 +19,6 @@ aws-sdk-secretsmanager = { workspace = true }
macro_aws_config = { path = "../macro_aws_config" }
axum = { workspace = true, features = ["tower-log", "ws"] }
chrono = { workspace = true }
-comms_service_client = { path = "../comms_service_client" }
email_db_client = { path = "../email_db_client" }
http-body-util = { workspace = true }
macro_auth = { path = "../macro_auth" }
diff --git a/rust/cloud-storage/properties_service/justfile b/rust/cloud-storage/properties_service/justfile
deleted file mode 100644
index bbcfd95645..0000000000
--- a/rust/cloud-storage/properties_service/justfile
+++ /dev/null
@@ -1,30 +0,0 @@
-set dotenv-load := true
-
-mod ci '../ci.just'
-
-deploy-dev:
- just ci::deploy-dev properties-service
-
-run:
- cargo run
-
-build:
- SQLX_OFFLINE=true cargo build
-
-check:
- SQLX_OFFLINE=true cargo check
-
-clippy:
- SQLX_OFFLINE=true cargo clippy
-
-run-local:
- ENVIRONMENT=local SQLX_OFFLINE=true cargo run --features macro_middleware/local_auth
-
-debug:
- ENVIRONMENT=local RUST_LOG=properties_service=debug,info SQLX_OFFLINE=true cargo run --features macro_middleware/local_auth
-
-trace:
- ENVIRONMENT=local RUST_LOG=properties_service=trace,info SQLX_OFFLINE=true cargo run --features macro_middleware/local_auth
-
-tree-trace:
- ENVIRONMENT=local RUST_LOG=properties_service=trace,info SQLX_OFFLINE=true cargo run --features macro_middleware/local_auth,tree_trace
diff --git a/rust/cloud-storage/properties_service/src/api/context.rs b/rust/cloud-storage/properties_service/src/api/context.rs
index 04b1d6e987..49f4c63795 100644
--- a/rust/cloud-storage/properties_service/src/api/context.rs
+++ b/rust/cloud-storage/properties_service/src/api/context.rs
@@ -1,27 +1,22 @@
use axum::extract::FromRef;
-use comms_service_client::CommsServiceClient;
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
-use macro_middleware::auth::internal_access::InternalApiSecretKey;
-use secretsmanager_client::LocalOrRemoteSecret;
use sqlx::PgPool;
use std::sync::Arc;
-use crate::config::Config;
use properties::PropertiesServiceImpl;
+/// Type alias for the properties service implementation used throughout the service.
+pub type PropertiesService = PropertiesServiceImpl<
+ properties::PropertiesPgRepo,
+ properties::PermissionServiceImpl,
+ properties::NotificationServiceImpl,
+>;
+
+/// Minimal state required by properties handlers.
+/// This can be extracted from any state that implements `FromRef<PropertiesHandlerState>`.
#[derive(Clone, FromRef)]
-pub struct ApiContext {
+pub struct PropertiesHandlerState {
/// Macrodb database connection (contains properties tables and permission tables)
pub db: PgPool,
- pub jwt_args: JwtValidationArgs,
- pub config: Arc<Config>,
- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,
- pub comms_service_client: Arc<CommsServiceClient>,
- pub properties_service: Arc<
- PropertiesServiceImpl<
- properties::PropertiesPgRepo,
- properties::PermissionServiceImpl,
- properties::NotificationServiceImpl,
- >,
- >,
+ /// The properties service implementation
+ pub properties_service: Arc<PropertiesService>,
}
diff --git a/rust/cloud-storage/properties_service/src/api/health.rs b/rust/cloud-storage/properties_service/src/api/health.rs
deleted file mode 100644
index b038054fc7..0000000000
--- a/rust/cloud-storage/properties_service/src/api/health.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-use axum::{Router, http::StatusCode, response::Json, routing::get};
-use serde_json::{Value, json};
-
-pub fn router() -> Router {
- Router::new().route("/health", get(health))
-}
-
-#[tracing::instrument]
-async fn health() -> Result<Json<Value>, StatusCode> {
- tracing::debug!("health check requested");
-
- let response = Json(json!({
- "status": "ok",
- "service": "properties_service"
- }));
-
- tracing::trace!("health check response ready");
-
- Ok(response)
-}
diff --git a/rust/cloud-storage/properties_service/src/api/internal.rs b/rust/cloud-storage/properties_service/src/api/internal.rs
deleted file mode 100644
index e5c907483c..0000000000
--- a/rust/cloud-storage/properties_service/src/api/internal.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-use crate::api::context::ApiContext;
-use crate::api::properties::entities;
-use axum::{Router, routing::delete};
-
-/// Internal routes. All routes are authenticated via the internal_access middleware.
-/// These routes are not part of the public Swagger documentation.
-pub fn router() -> Router<ApiContext> {
- Router::new()
- // Internal-only: Delete all properties for an entity
- .route(
- "/properties/entities/:entity_type/:entity_id",
- delete(entities::delete_entity::delete_entity),
- )
- // Bulk operations (POST with body)
- .route(
- "/properties/entities/bulk",
- axum::routing::post(entities::get_bulk::get_bulk_entity_properties_internal),
- )
-}
diff --git a/rust/cloud-storage/properties_service/src/api/mod.rs b/rust/cloud-storage/properties_service/src/api/mod.rs
index 17bfbae9c7..79092e4926 100644
--- a/rust/cloud-storage/properties_service/src/api/mod.rs
+++ b/rust/cloud-storage/properties_service/src/api/mod.rs
@@ -1,65 +1,4 @@
-use crate::api::context::ApiContext;
-use anyhow::Context;
-use axum::Router;
-use tower_http::trace::TraceLayer;
-use utoipa::OpenApi;
-use utoipa_swagger_ui::SwaggerUi;
-
pub mod context;
-mod health;
-mod internal;
-mod permissions;
+pub mod permissions;
pub mod properties;
pub mod swagger;
-
-pub async fn setup_and_serve(state: ApiContext) -> anyhow::Result<()> {
- let cors = macro_cors::cors_layer();
-
- let port = state.config.port;
- let env = state.config.environment;
- let app = api_router(state)
- .layer(TraceLayer::new_for_http())
- .merge(health::router())
- .layer(cors)
- .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()));
-
- let bind_address = format!("0.0.0.0:{}", port);
- let listener = tokio::net::TcpListener::bind(&bind_address)
- .await
- .with_context(|| format!("failed to bind to address {}", bind_address))?;
-
- tracing::info!(
- "properties service is up and running with environment {:?} on port {}",
- &env,
- &port
- );
-
- axum::serve(listener, app.into_make_service())
- .await
- .context("error running axum server")
-}
-
-fn api_router(app_state: ApiContext) -> Router {
- Router::new()
- .nest(
- "/properties",
- properties::router().layer(
- tower::ServiceBuilder::new()
- .layer(axum::middleware::from_fn(
- macro_middleware::auth::initialize_user_context::handler,
- ))
- .layer(axum::middleware::from_fn_with_state(
- app_state.jwt_args.clone(),
- macro_middleware::auth::attach_user::handler,
- )),
- ),
- )
- .nest(
- "/internal",
- internal::router().layer(axum::middleware::from_fn_with_state(
- app_state.clone(),
- macro_middleware::auth::internal_access::handler,
- )),
- )
- .with_state(app_state)
-}
diff --git a/rust/cloud-storage/properties_service/src/api/permissions.rs b/rust/cloud-storage/properties_service/src/api/permissions.rs
index a54cc25189..2cdbe92762 100644
--- a/rust/cloud-storage/properties_service/src/api/permissions.rs
+++ b/rust/cloud-storage/properties_service/src/api/permissions.rs
@@ -4,7 +4,7 @@ use models_properties::{EntityReference, EntityType};
use properties::PropertiesService;
use thiserror::Error;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
#[derive(Debug, Error)]
pub enum PermissionError {
@@ -33,7 +33,7 @@ impl PermissionError {
/// For anonymous users (empty user_id), only allows access to publicly shared entities.
#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type), err)]
pub async fn check_entity_view_permission(
- context: &ApiContext,
+ context: &PropertiesHandlerState,
user_id: &str,
entity_ref: &EntityReference,
) -> Result<(), PermissionError> {
@@ -72,7 +72,7 @@ pub async fn check_entity_view_permission(
/// Supports: Document, Chat, Project, Thread, Channel, Macro.
#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type), err)]
pub async fn check_entity_edit_permission(
- context: &ApiContext,
+ context: &PropertiesHandlerState,
user_id: &str,
entity_ref: &EntityReference,
) -> Result<(), PermissionError> {
@@ -90,7 +90,7 @@ pub async fn check_entity_edit_permission(
/// properties query due to complex recursive CTEs and entity-specific permission logic.
#[tracing::instrument(skip(context), fields(user_id = %user_id, entity_id = %entity_ref.entity_id, entity_type = ?entity_ref.entity_type), err)]
async fn get_access_level(
- context: &ApiContext,
+ context: &PropertiesHandlerState,
user_id: &str,
entity_ref: &EntityReference,
) -> Result<Option<AccessLevel>, PermissionError> {
diff --git a/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs b/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs
index 04c6ca545f..ffa3e1f991 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/definitions/create.rs
@@ -7,7 +7,7 @@ use axum::{
use thiserror::Error;
use uuid::Uuid;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use model::user::UserContext;
use models_properties::api::{CreatePropertyDefinitionRequest, PropertyDataType};
use models_properties::service::property_definition::PropertyDefinition;
@@ -58,9 +58,9 @@ impl IntoResponse for CreatePropertyDefinitionErr {
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(user_id = %user_context.user_id), err)]
+#[tracing::instrument(skip(state, user_context), fields(user_id = %user_context.user_id), err)]
pub async fn create_property_definition(
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
Json(request): Json<CreatePropertyDefinitionRequest>,
) -> Result<(StatusCode, Json<PropertyDefinition>), CreatePropertyDefinitionErr> {
@@ -114,7 +114,7 @@ pub async fn create_property_definition(
tracing::debug!("no options provided, using simple creation");
property_definitions_insert::create_property_definition(
- &context.db,
+ &state.db,
request.owner.organization_id(),
request.owner.user_id(),
&request.display_name,
@@ -137,7 +137,7 @@ pub async fn create_property_definition(
);
property_definitions_insert::create_property_definition_with_options(
- &context.db,
+ &state.db,
request.owner.organization_id(),
request.owner.user_id(),
&request.display_name,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs b/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs
index bf35e1d286..34331fb75f 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/definitions/delete.rs
@@ -7,7 +7,7 @@ use system_properties::SystemPropertyKey;
use thiserror::Error;
use uuid::Uuid;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use model::user::UserContext;
use properties_db_client::{
error::PropertiesDatabaseError,
@@ -65,16 +65,16 @@ impl IntoResponse for DeletePropertyDefinitionError {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), err)]
+#[tracing::instrument(skip(state, user_context), err)]
pub async fn delete_property_definition(
Path(property_uuid): Path<Uuid>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
) -> Result<Response, DeletePropertyDefinitionError> {
tracing::info!("deleting property definition");
// First check if property exists and if it's a system property
- let property = property_definitions_get::get_property_definition(&context.db, property_uuid)
+ let property = property_definitions_get::get_property_definition(&state.db, property_uuid)
.await?
.ok_or(DeletePropertyDefinitionError::NotFound)?;
@@ -84,7 +84,7 @@ pub async fn delete_property_definition(
// Then verify ownership
let _property = property_definitions_get::get_property_definition_with_owner(
- &context.db,
+ &state.db,
property_uuid,
&user_context.user_id,
user_context.organization_id,
@@ -92,7 +92,7 @@ pub async fn delete_property_definition(
.await?
.ok_or(DeletePropertyDefinitionError::NotFound)?;
- property_definitions_delete::delete_property_definition(&context.db, property_uuid).await?;
+ property_definitions_delete::delete_property_definition(&state.db, property_uuid).await?;
tracing::info!("successfully deleted property definition");
diff --git a/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs b/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs
index 0003e45a55..22b1fd9f13 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/definitions/list.rs
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use utoipa::ToSchema;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use model::user::UserContext;
use models_properties::EntityType;
use models_properties::service::property_definition::PropertyDefinition;
@@ -101,10 +101,10 @@ pub enum PropertyDefinitionResponse {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), err)]
+#[tracing::instrument(skip(state, user_context), err)]
pub async fn list_properties(
Query(query): Query<ListPropertiesQuery>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
) -> Result<Json<Vec<PropertyDefinitionResponse>>, ListPropertiesErr> {
// Note - NOT using organization properties for now
@@ -142,7 +142,7 @@ pub async fn list_properties(
let response = if query.include_options {
let properties_with_options = property_definitions_get::get_properties_with_options(
- &context.db,
+ &state.db,
org_id,
user_id_opt,
include_system,
@@ -178,7 +178,7 @@ pub async fn list_properties(
response
} else {
let properties = property_definitions_get::get_properties(
- &context.db,
+ &state.db,
org_id,
user_id_opt,
include_system,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs
index 58a06cfbdd..d7d57ff527 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_entity.rs
@@ -5,7 +5,7 @@ use axum::{
};
use thiserror::Error;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use models_properties::{EntityReference, EntityType};
use properties_db_client::{
entity_properties::delete as entity_properties_delete, error::PropertiesDatabaseError,
@@ -55,16 +55,16 @@ impl IntoResponse for DeleteEntityErr {
),
tag = "Internal"
)]
-#[tracing::instrument(skip(context), err)]
+#[tracing::instrument(skip(state), err)]
pub async fn delete_entity(
Path((entity_type, entity_id)): Path<(EntityType, String)>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
) -> Result<StatusCode, DeleteEntityErr> {
tracing::info!("deleting all properties for entity");
let entity_reference = EntityReference::new(entity_id.clone(), entity_type);
- entity_properties_delete::delete_entity(&context.db, &entity_reference)
+ entity_properties_delete::delete_entity(&state.db, &entity_reference)
.await
.inspect_err(|e| {
tracing::error!(
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs
index fc93c5dd74..aad9ea2735 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/delete_property.rs
@@ -8,7 +8,7 @@ use system_properties::SystemPropertyKey;
use thiserror::Error;
use uuid::Uuid;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use model::user::UserContext;
use properties_db_client::{
entity_properties::{delete as entity_properties_delete, get::lookup_entity_property},
@@ -66,16 +66,16 @@ impl IntoResponse for DeleteEntityPropertyErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), fields(entity_property_id = %entity_property_uuid, user_id = %user_context.user_id), err)]
+#[tracing::instrument(skip(state, user_context), fields(entity_property_id = %entity_property_uuid, user_id = %user_context.user_id), err)]
pub async fn delete_entity_property(
Path(entity_property_uuid): Path<Uuid>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
) -> Result<StatusCode, DeleteEntityPropertyErr> {
tracing::info!("removing entity property");
// Lookup entity property
- let property_info = lookup_entity_property(&context.db, entity_property_uuid)
+ let property_info = lookup_entity_property(&state.db, entity_property_uuid)
.await
.inspect_err(|e| {
tracing::error!(
@@ -108,13 +108,13 @@ pub async fn delete_entity_property(
let entity_ref = EntityReference::new(property_info.entity_id, property_info.entity_type);
crate::api::permissions::check_entity_edit_permission(
- &context,
+ &state,
&user_context.user_id,
&entity_ref,
)
.await?;
- entity_properties_delete::delete_entity_property(&context.db, entity_property_uuid)
+ entity_properties_delete::delete_entity_property(&state.db, entity_property_uuid)
.await
.inspect_err(|e| {
tracing::error!(
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs
index eb6c4c7620..a883abcc16 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/get.rs
@@ -7,7 +7,7 @@ use axum::{
use thiserror::Error;
use crate::api::{
- context::ApiContext,
+ context::PropertiesHandlerState,
properties::entities::types::{EntityPropertiesResponse, EntityQueryParams},
};
use model::user::UserContext;
@@ -69,11 +69,11 @@ impl IntoResponse for GetEntityPropertiesErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), fields(user_id = %user_context.user_id, entity_type = ?entity_type, include_metadata = query.include_metadata), err)]
+#[tracing::instrument(skip(state, user_context), fields(user_id = %user_context.user_id, entity_type = ?entity_type, include_metadata = query.include_metadata), err)]
pub async fn get_entity_properties(
Path((entity_type, entity_id)): Path<(EntityType, String)>,
Query(query): Query<EntityQueryParams>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
) -> Result<Json<EntityPropertiesResponse>, GetEntityPropertiesErr> {
tracing::info!(
@@ -85,7 +85,7 @@ pub async fn get_entity_properties(
// Note: This can fail if the entity is marked with "deletedAt"
crate::api::permissions::check_entity_view_permission(
- &context,
+ &state,
&user_context.user_id,
&entity_ref,
)
@@ -94,16 +94,12 @@ pub async fn get_entity_properties(
let (user_properties, metadata_properties) = if query.include_metadata {
// Fetch user properties and metadata in parallel when metadata is requested
let (user_properties_result, metadata_properties_result) = tokio::join!(
- entity_properties_get::get_entity_properties_values(
- &context.db,
- &entity_id,
- entity_type
- ),
+ entity_properties_get::get_entity_properties_values(&state.db, &entity_id, entity_type),
async {
match entity_type {
EntityType::Document | EntityType::Task => {
crate::api::properties::metadata::get_document_metadata_properties(
- &context.db,
+ &state.db,
&entity_id,
entity_type,
)
@@ -115,15 +111,13 @@ pub async fn get_entity_properties(
crate::api::properties::metadata::MetadataError::NotFound
})?;
crate::api::properties::metadata::get_thread_metadata_properties(
- &context.db,
- thread_id,
+ &state.db, thread_id,
)
.await
}
EntityType::Project => {
super::super::metadata::get_project_metadata_properties(
- &context.db,
- &entity_id,
+ &state.db, &entity_id,
)
.await
}
@@ -158,19 +152,16 @@ pub async fn get_entity_properties(
} else {
// Only fetch user properties when metadata not requested - no parallel task needed
tracing::debug!("skipping metadata properties due to include_metadata=false");
- let user_properties = entity_properties_get::get_entity_properties_values(
- &context.db,
- &entity_id,
- entity_type,
- )
- .await
- .inspect_err(|e| {
- tracing::error!(
- error = ?e,
- entity_id = %entity_id,
- "failed to retrieve entity properties from database"
- );
- })?;
+ let user_properties =
+ entity_properties_get::get_entity_properties_values(&state.db, &entity_id, entity_type)
+ .await
+ .inspect_err(|e| {
+ tracing::error!(
+ error = ?e,
+ entity_id = %entity_id,
+ "failed to retrieve entity properties from database"
+ );
+ })?;
(user_properties, vec![])
};
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs
index 1fa121bd2a..cf69bf0c45 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/get_bulk.rs
@@ -8,7 +8,7 @@ use std::collections::HashMap;
use thiserror::Error;
use crate::api::{
- context::ApiContext,
+ context::PropertiesHandlerState,
properties::entities::types::{BulkEntityPropertiesRequest, EntityPropertiesResponse},
};
use model::user::UserContext;
@@ -51,7 +51,7 @@ impl IntoResponse for GetBulkEntityPropertiesErr {
/// Shared implementation for bulk entity properties retrieval
async fn get_bulk_entity_properties_impl(
- context: &ApiContext,
+ state: &PropertiesHandlerState,
request: BulkEntityPropertiesRequest,
) -> Result<HashMap<String, EntityPropertiesResponse>, GetBulkEntityPropertiesErr> {
if request.entities.is_empty() {
@@ -65,11 +65,10 @@ async fn get_bulk_entity_properties_impl(
// Note: the public endpoint requires property_ids, but internal callers can
// pass an empty vec to fetch all properties for the given entities.
let bulk_properties = if request.property_ids.is_empty() {
- entity_properties_get::get_bulk_entity_properties_values(&context.db, &request.entities)
- .await
+ entity_properties_get::get_bulk_entity_properties_values(&state.db, &request.entities).await
} else {
entity_properties_get::get_bulk_entity_properties_values_filtered(
- &context.db,
+ &state.db,
&request.entities,
&request.property_ids,
)
@@ -113,12 +112,12 @@ async fn get_bulk_entity_properties_impl(
),
tag = "Internal"
)]
-#[tracing::instrument(skip(context, request), fields(entity_count = request.entities.len()), err)]
+#[tracing::instrument(skip(state, request), fields(entity_count = request.entities.len()), err)]
pub async fn get_bulk_entity_properties_internal(
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Json(request): Json<BulkEntityPropertiesRequest>,
) -> Result<Json<HashMap<String, EntityPropertiesResponse>>, GetBulkEntityPropertiesErr> {
- get_bulk_entity_properties_impl(&context, request)
+ get_bulk_entity_properties_impl(&state, request)
.await
.map(Json)
}
@@ -139,9 +138,9 @@ pub async fn get_bulk_entity_properties_internal(
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, request, user_context), fields(user_id = %user_context.user_id, entity_count = request.entities.len()), err)]
+#[tracing::instrument(skip(state, request, user_context), fields(user_id = %user_context.user_id, entity_count = request.entities.len()), err)]
pub async fn get_bulk_entity_properties(
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
Json(request): Json<BulkEntityPropertiesRequest>,
) -> Result<Json<HashMap<String, EntityPropertiesResponse>>, GetBulkEntityPropertiesErr> {
@@ -155,7 +154,7 @@ pub async fn get_bulk_entity_properties(
let mut permitted_entities = Vec::with_capacity(request.entities.len());
for entity_ref in &request.entities {
match crate::api::permissions::check_entity_view_permission(
- &context,
+ &state,
&user_context.user_id,
entity_ref,
)
@@ -187,7 +186,7 @@ pub async fn get_bulk_entity_properties(
property_ids: request.property_ids.clone(),
};
- get_bulk_entity_properties_impl(&context, filtered_request)
+ get_bulk_entity_properties_impl(&state, filtered_request)
.await
.map(Json)
}
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs
index 4b9533f890..29c9c3c8db 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/set.rs
@@ -7,7 +7,9 @@ use axum::{
use thiserror::Error;
use uuid::Uuid;
-use crate::api::{context::ApiContext, properties::entities::types::SetEntityPropertyRequest};
+use crate::api::{
+ context::PropertiesHandlerState, properties::entities::types::SetEntityPropertyRequest,
+};
use model::user::UserContext;
use models_properties::EntityType;
use properties::{PropertiesErr, PropertiesService};
@@ -60,16 +62,16 @@ impl IntoResponse for SetEntityPropertyErr {
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(entity_id = %entity_id, property_id = %property_uuid, entity_type = ?entity_type, user_id = %user_context.user_id, request = ?request), err)]
+#[tracing::instrument(skip(state, user_context), fields(entity_id = %entity_id, property_id = %property_uuid, entity_type = ?entity_type, user_id = %user_context.user_id, request = ?request), err)]
pub async fn set_entity_property(
Path((entity_type, entity_id, property_uuid)): Path<(EntityType, String, Uuid)>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
Json(request): Json<SetEntityPropertyRequest>,
) -> Result<StatusCode, SetEntityPropertyErr> {
tracing::info!("setting entity property");
- context
+ state
.properties_service
.set_entity_property(
&user_context.user_id,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs b/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs
index 1f14ceab44..a33675e90c 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/entities/set_property_status_complete.rs
@@ -10,7 +10,7 @@ use axum::{
};
use thiserror::Error;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use crate::api::permissions::{PermissionError, check_entity_edit_permission};
use model::user::UserContext;
use models_properties::{EntityReference, EntityType};
@@ -61,20 +61,20 @@ impl IntoResponse for SetPropertyStatusCompleteErr {
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(entity_id = %entity_id, entity_type = ?entity_type, user_id = %user_context.user_id), err)]
+#[tracing::instrument(skip(state, user_context), fields(entity_id = %entity_id, entity_type = ?entity_type, user_id = %user_context.user_id), err)]
pub async fn set_property_status_complete(
Path((entity_type, entity_id)): Path<(EntityType, String)>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
) -> Result<StatusCode, SetPropertyStatusCompleteErr> {
tracing::info!("setting entity status to complete");
// Check edit permissions
let entity_ref = EntityReference::new(entity_id.clone(), entity_type);
- check_entity_edit_permission(&context, &user_context.user_id, &entity_ref).await?;
+ check_entity_edit_permission(&state, &user_context.user_id, &entity_ref).await?;
// Delegate to service layer for business logic
- context
+ state
.properties_service
.set_system_property_status_complete(&entity_id, entity_type)
.await
diff --git a/rust/cloud-storage/properties_service/src/api/properties/mod.rs b/rust/cloud-storage/properties_service/src/api/properties/mod.rs
index 0913854c7e..06fc969504 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/mod.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/mod.rs
@@ -1,4 +1,4 @@
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use axum::{
Router,
routing::{delete, get, patch, post, put},
@@ -9,7 +9,8 @@ pub mod entities;
pub mod metadata;
pub mod options;
-pub fn router() -> Router<ApiContext> {
+/// Creates the properties router. Works with any state type that implements `FromRef<PropertiesHandlerState>`.
+pub fn router() -> Router<PropertiesHandlerState> {
let ensure_user_exists =
axum::middleware::from_fn(macro_middleware::auth::ensure_user_exists::handler);
diff --git a/rust/cloud-storage/properties_service/src/api/properties/options/create.rs b/rust/cloud-storage/properties_service/src/api/properties/options/create.rs
index 2f6d385224..38ef7db4f0 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/options/create.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/options/create.rs
@@ -7,7 +7,7 @@ use axum::{
use thiserror::Error;
use uuid::Uuid;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use model::user::UserContext;
use models_properties::api::AddPropertyOptionRequest;
use models_properties::service::property_option::{PropertyOption, PropertyOptionValue};
@@ -70,17 +70,17 @@ impl IntoResponse for AddPropertyOptionErr {
),
tags = ["Properties"]
)]
-#[tracing::instrument(skip(context, user_context), fields(property_id = %property_uuid, request = ?request), err)]
+#[tracing::instrument(skip(state, user_context), fields(property_id = %property_uuid, request = ?request), err)]
pub async fn add_property_option(
Path(property_uuid): Path<Uuid>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
Json(request): Json<AddPropertyOptionRequest>,
) -> Result<(StatusCode, Json<PropertyOption>), AddPropertyOptionErr> {
tracing::info!("adding property option");
// First check if property exists and if it's a system property
- let property = property_definitions_get::get_property_definition(&context.db, property_uuid)
+ let property = property_definitions_get::get_property_definition(&state.db, property_uuid)
.await
.inspect_err(|e| {
tracing::error!(
@@ -96,7 +96,7 @@ pub async fn add_property_option(
// Then verify ownership
let property_definition = property_definitions_get::get_property_definition_with_owner(
- &context.db,
+ &state.db,
property_uuid,
&user_context.user_id,
user_context.organization_id,
@@ -140,7 +140,7 @@ pub async fn add_property_option(
};
let option = property_options_insert::create_property_option(
- &context.db,
+ &state.db,
property_uuid,
display_order,
option_value,
diff --git a/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs b/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs
index 4bcea43499..cd34590b29 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/options/delete.rs
@@ -6,7 +6,7 @@ use axum::{
use thiserror::Error;
use uuid::Uuid;
-use crate::api::context::ApiContext;
+use crate::api::context::PropertiesHandlerState;
use model::user::UserContext;
use properties_db_client::{
error::PropertiesDatabaseError,
@@ -68,16 +68,16 @@ impl IntoResponse for DeletePropertyOptionErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, user_context), err)]
+#[tracing::instrument(skip(state, user_context), err)]
pub async fn delete_property_option(
Path((def_uuid, option_uuid)): Path<(Uuid, Uuid)>,
- State(context): State<ApiContext>,
+ State(state): State<PropertiesHandlerState>,
Extension(user_context): Extension<UserContext>,
) -> Result<StatusCode, DeletePropertyOptionErr> {
tracing::info!("deleting property option");
// First check if property exists and if it's a system property
- let property = property_definitions_get::get_property_definition(&context.db, def_uuid)
+ let property = property_definitions_get::get_property_definition(&state.db, def_uuid)
.await
.inspect_err(|e| {
tracing::error!(
@@ -93,7 +93,7 @@ pub async fn delete_property_option(
// Then verify ownership
let _property_definition = property_definitions_get::get_property_definition_with_owner(
- &context.db,
+ &state.db,
def_uuid,
&user_context.user_id,
user_context.organization_id,
@@ -107,7 +107,7 @@ pub async fn delete_property_option(
})?
.ok_or(DeletePropertyOptionErr::PropertyNotFound)?;
- let option = property_options_get::get_property_option_by_id(&context.db, option_uuid)
+ let option = property_options_get::get_property_option_by_id(&state.db, option_uuid)
.await
.inspect_err(|e| {
tracing::error!(
@@ -121,7 +121,7 @@ pub async fn delete_property_option(
return Err(DeletePropertyOptionErr::OptionNotFound);
}
- let deleted = property_options_delete::delete_property_option(&context.db, option_uuid)
+ let deleted = property_options_delete::delete_property_option(&state.db, option_uuid)
.await
.inspect_err(|e| {
tracing::error!(
diff --git a/rust/cloud-storage/properties_service/src/api/properties/options/get.rs b/rust/cloud-storage/properties_service/src/api/properties/options/get.rs
index 0ae0f9c8a5..a7dc25a517 100644
--- a/rust/cloud-storage/properties_service/src/api/properties/options/get.rs
+++ b/rust/cloud-storage/properties_service/src/api/properties/options/get.rs
@@ -7,12 +7,12 @@ use axum::{
use thiserror::Error;
use uuid::Uuid;
-use crate::api::context::ApiContext;
use model::user::UserContext;
use models_properties::service::property_option::PropertyOption;
use properties_db_client::{
error::PropertiesDatabaseError, property_options::get as property_options_get,
};
+use sqlx::PgPool;
#[derive(Debug, Error)]
pub enum GetPropertyOptionsErr {
@@ -56,15 +56,15 @@ impl IntoResponse for GetPropertyOptionsErr {
),
tag = "Properties"
)]
-#[tracing::instrument(skip(context, _user_context), err)]
+#[tracing::instrument(skip(db, _user_context), err)]
pub async fn get_property_options(
Path(property_uuid): Path<Uuid>,
- State(context): State<ApiContext>,
+ State(db): State<PgPool>,
Extension(_user_context): Extension<UserContext>,
) -> Result<Json<Vec<PropertyOption>>, GetPropertyOptionsErr> {
tracing::info!("retrieving property options");
- let options = property_options_get::get_property_options(&context.db, property_uuid)
+ let options = property_options_get::get_property_options(&db, property_uuid)
.await
.inspect_err(|e| {
tracing::error!(
diff --git a/rust/cloud-storage/properties_service/src/lib.rs b/rust/cloud-storage/properties_service/src/lib.rs
new file mode 100644
index 0000000000..6fb32f30c8
--- /dev/null
+++ b/rust/cloud-storage/properties_service/src/lib.rs
@@ -0,0 +1,11 @@
+//! Properties Service Library - exposes API routes for integration into other services
+
+pub mod api;
+pub mod config;
+pub mod constants;
+
+// Re-exports for consumers
+pub use api::context::PropertiesHandlerState;
+pub use api::context::PropertiesService;
+pub use api::properties::router as properties_router;
+pub use api::swagger::ApiDoc as PropertiesApiDoc;
diff --git a/rust/cloud-storage/properties_service/src/main.rs b/rust/cloud-storage/properties_service/src/main.rs
deleted file mode 100644
index 4ef6c8b825..0000000000
--- a/rust/cloud-storage/properties_service/src/main.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-use crate::api::context::ApiContext;
-use anyhow::Context;
-use config::{Config, Environment};
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
-use macro_entrypoint::MacroEntrypoint;
-use macro_middleware::auth::internal_access::InternalApiSecretKey;
-use sqlx::postgres::PgPoolOptions;
-use std::sync::Arc;
-
-mod api;
-mod config;
-mod constants;
-
-#[tokio::main]
-async fn main() -> anyhow::Result<()> {
- MacroEntrypoint::default().init();
-
- // Parse our configuration from the environment.
- let config = Config::from_env().context("expected to be able to generate config")?;
-
- tracing::info!("initialized config");
-
- let (min_connections, max_connections): (u32, u32) = match config.environment {
- Environment::Production => (5, 30),
- Environment::Develop => (3, 20),
- Environment::Local => (3, 10),
- };
-
- // Connect to macrodb (contains properties tables and permission tables)
- let db = PgPoolOptions::new()
- .min_connections(min_connections)
- .max_connections(max_connections)
- .connect(&config.database_url)
- .await
- .context("could not connect to macrodb")?;
-
- tracing::info!(
- min_connections,
- max_connections,
- "initialized macrodb connection"
- );
-
- let secretsmanager_client = secretsmanager_client::SecretsManager::new(
- aws_sdk_secretsmanager::Client::new(&macro_aws_config::get_macro_aws_config().await),
- );
- tracing::info!("initialized secretsmanager client");
-
- let jwt_args =
- JwtValidationArgs::new_with_secret_manager(config.environment, &secretsmanager_client)
- .await?;
-
- let internal_auth_key =
- secretsmanager_client::LocalOrRemoteSecret::Local(InternalApiSecretKey::new()?);
- tracing::info!("initialized internal auth key");
-
- let comms_service_client = comms_service_client::CommsServiceClient::new(
- internal_auth_key.as_ref().to_string(),
- config.comms_service_url.clone(),
- );
- tracing::info!(
- comms_service_url = %config.comms_service_url,
- "initialized comms service client"
- );
-
- // Initialize properties service
- let properties_repository = properties::PropertiesPgRepo::new(db.clone());
- let permission_service = properties::PermissionServiceImpl::new(db.clone());
-
- // Initialize notification service
- let notification_queue = std::env::var("NOTIFICATION_QUEUE")
- .unwrap_or_else(|_| "local-notification-queue".to_string());
- let macro_notify_client =
- macro_notify::MacroNotify::new(notification_queue, "properties_service".to_string()).await;
- let notification_service =
- properties::NotificationServiceImpl::new(Arc::new(macro_notify_client));
-
- let properties_service = Arc::new(properties::PropertiesServiceImpl::new(
- properties_repository,
- Some(permission_service),
- Some(notification_service),
- ));
- tracing::info!("initialized properties service");
-
- api::setup_and_serve(ApiContext {
- db,
- jwt_args,
- config: Arc::new(config),
- internal_auth_key,
- comms_service_client: Arc::new(comms_service_client),
- properties_service,
- })
- .await?;
- Ok(())
-}
diff --git a/rust/cloud-storage/properties_service_client/Cargo.toml b/rust/cloud-storage/properties_service_client/Cargo.toml
deleted file mode 100644
index 4d2f55941d..0000000000
--- a/rust/cloud-storage/properties_service_client/Cargo.toml
+++ /dev/null
@@ -1,13 +0,0 @@
-[package]
-edition = "2024"
-name = "properties_service_client"
-publish = false
-version = "0.1.0"
-
-[dependencies]
-anyhow = { workspace = true }
-macro_service_client = { path = "../macro_service_client" }
-models_properties = { path = "../models_properties" }
-reqwest = { workspace = true }
-serde = { workspace = true }
-tracing = { workspace = true }
diff --git a/rust/cloud-storage/properties_service_client/README.md b/rust/cloud-storage/properties_service_client/README.md
deleted file mode 100644
index e3febe31f8..0000000000
--- a/rust/cloud-storage/properties_service_client/README.md
+++ /dev/null
@@ -1,39 +0,0 @@
-# Properties Service Client
-
-A client library for service-to-service communication with the Properties Service.
-
-## Overview
-
-This client provides internal methods for other services to interact with the Properties Service API. It uses internal authentication for trusted service-to-service communication.
-
-## Supported Endpoints
-
-The client supports the following internal endpoint:
-
-### Bulk Get Entity Properties
-- **Endpoint**: `GET /internal/properties/entities/bulk`
-- Retrieve properties for multiple entities at once
-
-## Usage
-
-```rust
-use properties_service_client::PropertiesServiceClient;
-
-// Create client
-let client = PropertiesServiceClient::new(
- "your-internal-auth-key".to_string(),
- "http://properties-service-url".to_string(),
-);
-
-// Get bulk entity properties from entity IDs
-let entity_ids = vec!["entity-1".to_string(), "entity-2".to_string()];
-let bulk_properties = client.get_bulk_entity_properties_by_ids(entity_ids).await?;
-```
-
-## Error Handling
-
-The client uses `anyhow::Result` for simple and consistent error handling. All HTTP errors are converted to `anyhow::Error` with the status code and response body.
-
-## Authentication
-
-This client is designed for **internal service-to-service communication** and uses internal authentication keys. For user-facing applications, call the Properties Service directly with JWT authentication.
\ No newline at end of file
diff --git a/rust/cloud-storage/properties_service_client/src/constants.rs b/rust/cloud-storage/properties_service_client/src/constants.rs
deleted file mode 100644
index 52f978bfeb..0000000000
--- a/rust/cloud-storage/properties_service_client/src/constants.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub const INTERNAL_AUTH_HEADER_KEY: &str = "x-internal-auth-key";
diff --git a/rust/cloud-storage/properties_service_client/src/delete_entity.rs b/rust/cloud-storage/properties_service_client/src/delete_entity.rs
deleted file mode 100644
index e3269cf830..0000000000
--- a/rust/cloud-storage/properties_service_client/src/delete_entity.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-use crate::PropertiesServiceClient;
-use anyhow::Result;
-use models_properties::EntityType;
-
-impl PropertiesServiceClient {
- /// Delete all properties for an entity
- #[tracing::instrument(skip(self))]
- pub async fn delete_entity(&self, entity_id: &str, entity_type: EntityType) -> Result<()> {
- let response = self
- .client
- .delete(format!(
- "{}/internal/properties/{}/entities/{}",
- self.url, entity_type, entity_id
- ))
- .send()
- .await?;
-
- let status = response.status();
- if !status.is_success() {
- let body = response.text().await.unwrap_or_default();
- anyhow::bail!("HTTP {}: {}", status, body);
- }
-
- Ok(())
- }
-}
diff --git a/rust/cloud-storage/properties_service_client/src/get_bulk_entity_properties.rs b/rust/cloud-storage/properties_service_client/src/get_bulk_entity_properties.rs
deleted file mode 100644
index be454fa1d7..0000000000
--- a/rust/cloud-storage/properties_service_client/src/get_bulk_entity_properties.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use crate::{BulkEntityPropertiesResponse, EntityReference, PropertiesServiceClient};
-use anyhow::Result;
-use serde::{Deserialize, Serialize};
-
-/// Request body for bulk entity properties endpoint
-#[derive(Debug, Serialize, Deserialize)]
-pub struct BulkEntityPropertiesRequest {
- pub entities: Vec<EntityReference>,
-}
-
-impl PropertiesServiceClient {
- /// Get properties for multiple entities in bulk
- #[tracing::instrument(skip(self))]
- pub async fn get_bulk_entity_properties(
- &self,
- entities: Vec<EntityReference>,
- ) -> Result<BulkEntityPropertiesResponse> {
- let request = BulkEntityPropertiesRequest { entities };
-
- let response = self
- .client
- .post(format!("{}/internal/properties/entities/bulk", self.url))
- .json(&request)
- .send()
- .await?;
-
- let status = response.status();
- if !status.is_success() {
- let body = response.text().await.unwrap_or_default();
- anyhow::bail!("HTTP {}: {}", status, body);
- }
-
- let result = response.json::<BulkEntityPropertiesResponse>().await?;
- Ok(result)
- }
-}
diff --git a/rust/cloud-storage/properties_service_client/src/lib.rs b/rust/cloud-storage/properties_service_client/src/lib.rs
deleted file mode 100644
index 76191cbdfc..0000000000
--- a/rust/cloud-storage/properties_service_client/src/lib.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-use constants::INTERNAL_AUTH_HEADER_KEY;
-use macro_service_client::AssertHealth;
-
-pub(crate) mod constants;
-pub mod delete_entity;
-pub mod get_bulk_entity_properties;
-
-pub use models_properties::{
- DataType, EntityReference, EntityType,
- api::{BulkEntityPropertiesResponse, EntityPropertiesResponse},
- service::{
- entity_property_with_definition::EntityPropertyWithDefinition,
- property_definition::PropertyDefinition,
- property_definition_with_options::PropertyDefinitionWithOptions,
- },
-};
-
-#[derive(Clone)]
-pub struct PropertiesServiceClient {
- url: String,
- client: reqwest::Client,
-}
-
-impl PropertiesServiceClient {
- pub fn new(internal_auth_key: String, url: String) -> Self {
- let mut headers = reqwest::header::HeaderMap::new();
- headers.insert(INTERNAL_AUTH_HEADER_KEY, internal_auth_key.parse().unwrap());
-
- let client = reqwest::Client::builder()
- .default_headers(headers)
- .build()
- .unwrap();
-
- Self { url, client }
- }
-}
-
-impl AssertHealth for PropertiesServiceClient {
- #[tracing::instrument(skip(self), err)]
- async fn assert_health(&self) -> Result<(), anyhow::Error> {
- self.client
- .get(format!("{}/internal/health", self.url))
- .send()
- .await
- .map_err(Into::into)
- .map(|_| ())
- }
-}