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 search to dss (#1258)

Will Hutchinson0dfa8a8139d8
diff --git a/.github/actions/get-project-name/test.sh b/.github/actions/get-project-name/test.sh
index 5409216194..dec4b3183e 100755
--- a/.github/actions/get-project-name/test.sh
+++ b/.github/actions/get-project-name/test.sh
@@ -13,7 +13,6 @@ TEST_CASES=(
"document-storage:document-storage"
"authentication-service:authentication-service"
"comms-service:comms-service"
- "search-service:search-service"
"opensearch:opensearch"
)
diff --git a/.github/services-config.json b/.github/services-config.json
index f5c0494d38..0ce87f708f 100644
--- a/.github/services-config.json
+++ b/.github/services-config.json
@@ -97,12 +97,6 @@
],
"stack_path": "infra/stacks/search-processing-service/**"
},
- "search-service": {
- "source_paths": [
- "rust/cloud-storage/search_service/**"
- ],
- "stack_path": "infra/stacks/search-service/**"
- },
"search-upload": {
"source_paths": [
"rust/cloud-storage/search_upload/**"
diff --git a/.github/workflows/deploy-service-generic.yml b/.github/workflows/deploy-service-generic.yml
index 1a5f25139c..8921bad3fe 100644
--- a/.github/workflows/deploy-service-generic.yml
+++ b/.github/workflows/deploy-service-generic.yml
@@ -28,7 +28,6 @@ on:
- notification-service
- organization-retention
- search-processing-service
- - search-service
- search-upload
- static-file-service
- unfurl-service
diff --git a/.github/workflows/deploy-services-batch.yml b/.github/workflows/deploy-services-batch.yml
index 56280aa992..60630ecdfc 100644
--- a/.github/workflows/deploy-services-batch.yml
+++ b/.github/workflows/deploy-services-batch.yml
@@ -13,7 +13,7 @@ on:
services:
type: string
required: true
- description: 'Comma-separated list of services to deploy (e.g., "document-cognition-service,search-service,static-file-service")'
+ description: 'Comma-separated list of services to deploy (e.g., "document-cognition-service,static-file-service")'
concurrency:
group: deploy-batch-${{ inputs.environment }}-${{ github.run_id }}
diff --git a/docker-compose.yml b/docker-compose.yml
index c91bd51ddb..bfff1e7595 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -144,7 +144,6 @@ services:
depends_on:
- comms_service
- document_storage_service
- - search_service
- email_service
- static_file_service
networks:
@@ -265,32 +264,6 @@ services:
retries: 3
start_period: 10s
- # ============================================================================
- # search_service (Port 8093)
- # Search API
- # ============================================================================
- search_service:
- <<: *common-env
- build:
- context: ./rust/cloud-storage
- dockerfile: Dockerfile.dev
- target: search_service
- ports:
- - "8093:8080"
- depends_on:
- - comms_service
- - email_service
- - document_storage_service
- networks:
- - databases
- - services
- healthcheck:
- test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
- interval: 30s
- timeout: 10s
- retries: 3
- start_period: 10s
-
# ============================================================================
# static_file_service (Port 8094)
# Static file serving - DynamoDB
diff --git a/infra/stacks/cloud-storage-service/Pulumi.dev.yaml b/infra/stacks/cloud-storage-service/Pulumi.dev.yaml
index c4e8a4a2b5..914b8974e1 100644
--- a/infra/stacks/cloud-storage-service/Pulumi.dev.yaml
+++ b/infra/stacks/cloud-storage-service/Pulumi.dev.yaml
@@ -11,3 +11,4 @@ config:
cloud-storage-service:internal_api_key: document-storage-service-auth-key-dev
cloud-storage-service:sync_service_auth_key: sync-service-key-dev
cloud-storage-service:authentication_service_secret_key: authentication-service-internal-api-key-dev
+ cloud-storage-service:opensearch_password_key: macro-opensearch-password-dev
diff --git a/infra/stacks/cloud-storage-service/Pulumi.prod.yaml b/infra/stacks/cloud-storage-service/Pulumi.prod.yaml
index 9bed158ea8..11aedc99d6 100644
--- a/infra/stacks/cloud-storage-service/Pulumi.prod.yaml
+++ b/infra/stacks/cloud-storage-service/Pulumi.prod.yaml
@@ -11,3 +11,4 @@ config:
cloud-storage-service:internal_api_key: document-storage-service-auth-key-prod
cloud-storage-service:sync_service_auth_key: sync-service-key-prod
cloud-storage-service:authentication_service_secret_key: authentication-service-internal-api-key-prod
+ cloud-storage-service:opensearch_password_key: macro-opensearch-password-prod
diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.ts
index 1379695d04..eb8fda2461 100644
--- a/infra/stacks/cloud-storage-service/index.ts
+++ b/infra/stacks/cloud-storage-service/index.ts
@@ -104,6 +104,22 @@ export const jobUpdateHandlerLambdaName = jobUpdateHandlerLambdaArn.apply(
}
);
+const opensearchStack = new pulumi.StackReference('opensearch-stack', {
+ name: `macro-inc/opensearch/${stack}`,
+});
+
+const OPENSEARCH_URL: pulumi.Output<string> = opensearchStack
+ .getOutput('domainEndpoint')
+ .apply((domainEndpoint) => `https://${domainEndpoint}`);
+
+const OPENSEARCH_USERNAME = 'macrouser';
+const OPENSEARCH_PASSWORD = config.require('opensearch_password_key');
+const opensearchPasswordArn = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: OPENSEARCH_PASSWORD,
+ })
+ .apply((secret) => secret.arn);
+
const cloudStorageStack = new pulumi.StackReference('cloud-storage-stack', {
name: `macro-inc/document-storage/${stack}`,
});
@@ -233,9 +249,22 @@ const cloudStorageService = new CloudStorageService(
syncServiceAuthKeyArn,
authenticationServiceSecretKeyArn,
MACRO_API_TOKENS.macroApiTokenPublicKeyArn,
+ opensearchPasswordArn,
],
notificationQueueArn,
containerEnvVars: [
+ {
+ name: 'OPENSEARCH_URL',
+ value: OPENSEARCH_URL,
+ },
+ {
+ name: 'OPENSEARCH_USERNAME',
+ value: OPENSEARCH_USERNAME,
+ },
+ {
+ name: 'OPENSEARCH_PASSWORD',
+ value: OPENSEARCH_PASSWORD,
+ },
{
name: 'DATABASE_URL',
value: pulumi.interpolate`${DATABASE_URL}`,
diff --git a/infra/stacks/document-cognition-service/index.ts b/infra/stacks/document-cognition-service/index.ts
index 8c5b68918a..1b5c7c107c 100644
--- a/infra/stacks/document-cognition-service/index.ts
+++ b/infra/stacks/document-cognition-service/index.ts
@@ -159,14 +159,6 @@ const { notificationQueueName, notificationQueueArn } = getMacroNotify();
const { searchEventQueueName, searchEventQueueArn } = getSearchEventQueue();
-const searchServiceStack = new pulumi.StackReference('search-service-stack', {
- name: `macro-inc/search-service/${stack}`,
-});
-
-const searchServiceUrl: pulumi.Output<string> = searchServiceStack
- .getOutput('searchServiceUrl')
- .apply((arn) => arn as string);
-
const MACRO_API_TOKENS = getMacroApiToken();
// Import the search text extractor queue stack
@@ -298,10 +290,6 @@ const documentCognitionService = new DocumentCognitionService(
name: 'MACRO_API_TOKEN_PUBLIC_KEY',
value: pulumi.interpolate`${MACRO_API_TOKENS.macroApiTokenPublicKey}`,
},
- {
- name: 'SEARCH_SERVICE_URL',
- value: pulumi.interpolate`${searchServiceUrl}`,
- },
{
name: 'PERPLEXITY_API_KEY',
value: pulumi.interpolate`${PERPLEXITY_API_KEY}`,
diff --git a/js/app/packages/core/constant/servers.ts b/js/app/packages/core/constant/servers.ts
index b31656363e..a1954bc2e9 100644
--- a/js/app/packages/core/constant/servers.ts
+++ b/js/app/packages/core/constant/servers.ts
@@ -12,7 +12,6 @@ const serverHostLocal: Servers = {
'unfurl-service': 'http://localhost:8095',
contacts: 'http://localhost:8083',
'email-service': 'http://localhost:8087',
- 'search-service': 'http://localhost:8093',
} as const;
const devServerSuffix = import.meta.env.MODE === 'development' ? '-dev' : '';
@@ -31,7 +30,6 @@ const serverHostRemote = {
'unfurl-service': `https://unfurl-service${devServerSuffix}.macro.com`,
contacts: `https://contacts${devServerSuffix}.macro.com`,
'email-service': `https://email-service${devServerSuffix}.macro.com`,
- 'search-service': `https://search-service${devServerSuffix}.macro.com`,
} as const;
type Servers = Record<keyof typeof serverHostRemote, string>;
diff --git a/js/app/packages/observability/src/index.ts b/js/app/packages/observability/src/index.ts
index dd46593213..6e6a97682b 100644
--- a/js/app/packages/observability/src/index.ts
+++ b/js/app/packages/observability/src/index.ts
@@ -20,7 +20,6 @@ const tracingHosts =
SERVER_HOSTS['document-storage-service'],
SERVER_HOSTS['email-service'],
SERVER_HOSTS['notification-service'],
- SERVER_HOSTS['search-service'],
]
: Object.values(SERVER_HOSTS);
diff --git a/js/app/packages/service-clients/service-search/client.ts b/js/app/packages/service-clients/service-search/client.ts
index a6fdab1cea..a9f8173a6e 100644
--- a/js/app/packages/service-clients/service-search/client.ts
+++ b/js/app/packages/service-clients/service-search/client.ts
@@ -12,7 +12,7 @@ import {
import type { SafeFetchInit } from '@core/util/safeFetch';
-const searchServiceHost = `${SERVER_HOSTS['search-service']}`;
+const searchServiceHost = `${SERVER_HOSTS['document-storage-service']}`;
import type { UnifiedSearchRequest } from './generated/models/unifiedSearchRequest';
import type { UnifiedSearchResponse } from './generated/models/unifiedSearchResponse';
diff --git a/js/app/packages/service-clients/service-search/generated/client.ts b/js/app/packages/service-clients/service-search/generated/client.ts
index fe33aa6caa..ac2d414fa1 100644
--- a/js/app/packages/service-clients/service-search/generated/client.ts
+++ b/js/app/packages/service-clients/service-search/generated/client.ts
@@ -5,7 +5,6 @@
* OpenAPI spec version: 0.1.0
*/
import type {
- EmptyResponse,
ErrorResponse,
SimpleUnifiedSearchBaseResponse,
SimpleUnifiedSearchParams,
@@ -14,42 +13,6 @@ import type {
UnifiedSearchResponse,
} from './models';
-/**
- * @summary Health check
- */
-export type healthHandlerResponse200 = {
- data: EmptyResponse;
- status: 200;
-};
-
-export type healthHandlerResponseSuccess = healthHandlerResponse200 & {
- headers: Headers;
-};
-
-export type healthHandlerResponse = healthHandlerResponseSuccess;
-
-export const getHealthHandlerUrl = () => {
- return `/health`;
-};
-
-export const healthHandler = async (
- options?: RequestInit
-): Promise<healthHandlerResponse> => {
- const res = await fetch(getHealthHandlerUrl(), {
- ...options,
- method: 'GET',
- });
-
- const body = [204, 205, 304].includes(res.status) ? null : await res.text();
-
- const data: healthHandlerResponse['data'] = body ? JSON.parse(body) : {};
- return {
- data,
- status: res.status,
- headers: res.headers,
- } as healthHandlerResponse;
-};
-
/**
* @summary Perform a search through all items
*/
diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.json
index 4333e3a4d4..cf894dc1d0 100644
--- a/js/app/packages/service-clients/service-search/openapi.json
+++ b/js/app/packages/service-clients/service-search/openapi.json
@@ -10,25 +10,6 @@
"version": "0.1.0"
},
"paths": {
- "/health": {
- "get": {
- "tags": ["health"],
- "summary": "Health check",
- "operationId": "health_handler",
- "responses": {
- "200": {
- "description": "health",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/EmptyResponse"
- }
- }
- }
- }
- }
- }
- },
"/search": {
"post": {
"tags": ["search::unified"],
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 65f046bc12..b51ccca823 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2795,6 +2795,7 @@ dependencies = [
"models_permissions",
"models_properties",
"models_soup",
+ "opensearch_client",
"ordered-float",
"properties",
"properties_service",
@@ -2804,6 +2805,7 @@ dependencies = [
"reqwest",
"saved_views",
"schemars",
+ "search_service",
"secretsmanager_client",
"serde",
"serde_json",
diff --git a/rust/cloud-storage/Dockerfile.dev b/rust/cloud-storage/Dockerfile.dev
index 767571fd7a..2b35ca99f8 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 search_service \
--bin static_file_service \
--bin unfurl_service \
&& cargo strip
@@ -71,11 +70,6 @@ COPY --from=builder /app/target/release/notification_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
-ENTRYPOINT ["dumb-init", "./svc"]
-
FROM base AS static_file_service
COPY --from=builder /app/target/release/static_file_service /app/svc
RUN chmod +x /app/svc
diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rs
index ddddc6de59..7711f7b418 100644
--- a/rust/cloud-storage/document_cognition_service/src/config.rs
+++ b/rust/cloud-storage/document_cognition_service/src/config.rs
@@ -34,7 +34,6 @@ pub struct Config {
pub search_event_queue: String,
pub sync_service_url: String,
pub sync_service_auth_key: String,
- pub search_service_url: String,
pub lexical_service_url: String,
pub email_service_url: String,
/// document cognition service url for scribe tool to loopback
@@ -90,9 +89,6 @@ impl Config {
let sync_service_auth_key = std::env::var("SYNC_SERVICE_AUTH_KEY")
.context("SYNC_SERVICE_AUTH_KEY must be provided")?;
- let search_service_url =
- std::env::var("SEARCH_SERVICE_URL").context("SEARCH_SERVICE_URL must be provided")?;
-
let lexical_service_url =
std::env::var("LEXICAL_SERVICE_URL").context("LEXICAL_SERVICE_URL must be provided")?;
@@ -124,7 +120,6 @@ impl Config {
search_event_queue,
sync_service_auth_key,
sync_service_url,
- search_service_url,
lexical_service_url,
email_service_url,
document_cognition_service_url,
@@ -150,7 +145,6 @@ impl Config {
search_event_queue: Default::default(),
sync_service_url: Default::default(),
sync_service_auth_key: Default::default(),
- search_service_url: Default::default(),
lexical_service_url: Default::default(),
email_service_url: Default::default(),
document_cognition_service_url: Default::default(),
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index f4914f6887..75e6ad8159 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -109,7 +109,7 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("initialized sync service client");
let search_service_client = SearchServiceClient::new(
internal_auth_key.as_ref().to_string(),
- config.search_service_url.clone(),
+ config.document_storage_service_url.clone(),
);
tracing::info!("initialized search service client");
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index e21fd54b32..102364caee 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -85,8 +85,10 @@ models_pagination = { path = "../models_pagination", features = ["axum"] }
models_permissions = { path = "../models_permissions" }
models_properties = { path = "../models_properties" }
models_soup = { path = "../models_soup", features = ["schema"] }
+opensearch_client = { path = "../opensearch_client" }
properties = { path = "../properties" }
properties_service = { path = "../properties_service" }
+search_service = { path = "../search_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 b43fb2fd2e..f094abbc5c 100644
--- a/rust/cloud-storage/document_storage_service/src/api/context.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/context.rs
@@ -11,10 +11,12 @@ use frecency::{domain::services::FrecencyQueryServiceImpl, outbound::postgres::F
use macro_auth::middleware::decode_jwt::JwtValidationArgs;
use macro_env_var::env_var;
use macro_redis_cluster_client::Redis;
+use opensearch_client::OpensearchClient;
use properties::{
NotificationServiceImpl, PermissionServiceImpl, PropertiesPgRepo, PropertiesServiceImpl,
};
use properties_service::PropertiesHandlerState;
+use search_service::SearchHandlerState;
use soup::{
domain::service::SoupImpl, inbound::axum_router::SoupRouterState,
outbound::pg_soup_repo::PgSoupRepo,
@@ -57,6 +59,7 @@ pub(crate) struct ApiContext {
pub sync_service_client: Arc<SyncServiceClient>,
pub system_properties_service: Arc<SystemPropertiesService>,
pub properties_service: Arc<PropertiesService>,
+ pub opensearch_client: Arc<OpensearchClient>,
pub jwt_validation_args: JwtValidationArgs,
pub config: Arc<Config>,
pub dss_auth_key: DocumentStorageServiceAuthKey,
@@ -81,3 +84,18 @@ impl FromRef<ApiContext> for PropertiesHandlerState {
PropertiesHandlerState::from(ctx)
}
}
+
+impl From<&ApiContext> for SearchHandlerState {
+ fn from(ctx: &ApiContext) -> Self {
+ SearchHandlerState {
+ db: ctx.db.clone(),
+ opensearch_client: ctx.opensearch_client.clone(),
+ }
+ }
+}
+
+impl FromRef<ApiContext> for SearchHandlerState {
+ fn from_ref(ctx: &ApiContext) -> Self {
+ SearchHandlerState::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 c2e85bde62..e116b7f3d5 100644
--- a/rust/cloud-storage/document_storage_service/src/api/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/mod.rs
@@ -9,6 +9,7 @@ use context::InternalFlag;
use macro_axum_utils::compose_layers;
use model::version::{ServiceNameState, VersionedApiServiceName, validate_api_version};
use properties_service::PropertiesHandlerState;
+use search_service::SearchHandlerState;
use tower::ServiceBuilder;
use tower_http::compression::CompressionLayer;
use tower_http::trace::TraceLayer;
@@ -154,6 +155,10 @@ fn api_router(state: ApiContext) -> Router {
properties_service::properties_router()
.with_state(PropertiesHandlerState::from_ref(&state)),
)
+ .nest(
+ "/search",
+ search_service::search_router().with_state(SearchHandlerState::from_ref(&state)),
+ )
.layer(
ServiceBuilder::new()
.layer(axum::middleware::from_fn(
@@ -168,6 +173,11 @@ fn api_router(state: ApiContext) -> Router {
"/internal",
internal::router(state.clone())
.nest("/notifications", notification::router())
+ .nest(
+ "/search",
+ search_service::search_router()
+ .with_state(SearchHandlerState::from_ref(&state)),
+ )
.layer(
ServiceBuilder::new()
.layer(axum::middleware::from_fn_with_state(
diff --git a/rust/cloud-storage/document_storage_service/src/config.rs b/rust/cloud-storage/document_storage_service/src/config.rs
index 8d9ecc86a4..c00cf6ef42 100644
--- a/rust/cloud-storage/document_storage_service/src/config.rs
+++ b/rust/cloud-storage/document_storage_service/src/config.rs
@@ -49,6 +49,9 @@ env_var! {
pub SyncServiceAuthKey,
pub AuthenticationServiceUrl,
pub AuthenticationServiceSecretKey,
+ pub OpensearchUrl,
+ pub OpensearchUsername,
+ pub OpensearchPassword,
}
}
diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rs
index ab9155df4d..1b64179ed8 100644
--- a/rust/cloud-storage/document_storage_service/src/main.rs
+++ b/rust/cloud-storage/document_storage_service/src/main.rs
@@ -19,6 +19,7 @@ use macro_auth::middleware::decode_jwt::JwtValidationArgs;
use macro_entrypoint::MacroEntrypoint;
use macro_middleware::auth::internal_access::InternalApiSecretKey;
use macro_redis_cluster_client::Redis;
+use opensearch_client::OpensearchClient;
use properties::{
NotificationServiceImpl, PermissionServiceImpl, PropertiesPgRepo, PropertiesServiceImpl,
};
@@ -168,6 +169,29 @@ async fn main() -> anyhow::Result<()> {
.to_string(),
};
+ // Initialize OpenSearch client
+ let opensearch_password = match config.environment {
+ Environment::Local => config.vars.opensearch_password.as_ref().to_string(),
+ _ => secretsmanager_client
+ .get_secret_value(&config.vars.opensearch_password)
+ .await
+ .context("unable to get opensearch secret")?
+ .to_string(),
+ };
+
+ let opensearch_client = OpensearchClient::new(
+ config.vars.opensearch_url.as_ref().to_string(),
+ config.vars.opensearch_username.as_ref().to_string(),
+ opensearch_password,
+ )
+ .context("unable to create opensearch client")?;
+
+ if let Err(e) = opensearch_client.health().await {
+ tracing::error!(error=?e, "error connecting to opensearch");
+ return Err(e);
+ }
+ tracing::trace!("initialized opensearch client");
+
let frecency_service = FrecencyQueryServiceImpl::new(FrecencyPgStorage::new(db.clone()));
let email_service =
EmailServiceImpl::new(EmailPgRepo::new(db.clone()), frecency_service.clone());
@@ -218,6 +242,7 @@ async fn main() -> anyhow::Result<()> {
sync_service_client: Arc::new(sync_service_client),
system_properties_service: Arc::new(system_properties_service),
properties_service: Arc::new(properties_service),
+ opensearch_client: Arc::new(opensearch_client),
config: Arc::new(config),
jwt_validation_args,
dss_auth_key,
diff --git a/rust/cloud-storage/search_service/Cargo.toml b/rust/cloud-storage/search_service/Cargo.toml
index 4cc6d25f7c..3aa4c6ca01 100644
--- a/rust/cloud-storage/search_service/Cargo.toml
+++ b/rust/cloud-storage/search_service/Cargo.toml
@@ -4,9 +4,9 @@ name = "search_service"
publish = false
version = "0.1.0"
-[[bin]]
+[lib]
name = "search_service"
-path = "src/main.rs"
+path = "src/lib.rs"
[[bin]]
name = "search_service_openapi"
diff --git a/rust/cloud-storage/search_service/src/api/context.rs b/rust/cloud-storage/search_service/src/api/context.rs
index e0bb94fbf5..e3dfc49978 100644
--- a/rust/cloud-storage/search_service/src/api/context.rs
+++ b/rust/cloud-storage/search_service/src/api/context.rs
@@ -1,17 +1,14 @@
-use crate::config::Config;
use axum::extract::FromRef;
-use macro_auth::middleware::decode_jwt::JwtValidationArgs;
-use macro_middleware::auth::internal_access::InternalApiSecretKey;
use opensearch_client::OpensearchClient;
-use secretsmanager_client::LocalOrRemoteSecret;
use sqlx::PgPool;
use std::sync::Arc;
+/// Minimal state required by search handlers.
+/// This can be extracted from any state that implements `FromRef<SearchHandlerState>`.
#[derive(Clone, FromRef)]
-pub(crate) struct ApiContext {
+pub struct SearchHandlerState {
+ /// Macrodb database connection
pub db: PgPool,
+ /// OpenSearch client for full-text search
pub opensearch_client: Arc<OpensearchClient>,
- pub jwt_args: JwtValidationArgs,
- pub internal_auth_key: LocalOrRemoteSecret<InternalApiSecretKey>,
- pub config: Arc<Config>,
}
diff --git a/rust/cloud-storage/search_service/src/api/health.rs b/rust/cloud-storage/search_service/src/api/health.rs
deleted file mode 100644
index fc08af3824..0000000000
--- a/rust/cloud-storage/search_service/src/api/health.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-use axum::{Json, Router, http::StatusCode, response::IntoResponse, routing::get};
-use model::response::EmptyResponse;
-
-/// Health check
-#[utoipa::path(
- get,
- path = "/health",
- responses(
- (status = 200, description = "health", body = EmptyResponse),
- )
- )]
-pub async fn health_handler() -> impl IntoResponse {
- (StatusCode::OK, Json(EmptyResponse::default()))
-}
-
-pub fn router() -> Router {
- Router::new().route("/health", get(health_handler))
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use axum::{
- body::Body,
- http::{Request, StatusCode},
- };
- #[allow(unused_imports)]
- use http_body_util::BodyExt; // for `collect`
- use tower::ServiceExt;
-
- #[tokio::test]
- async fn test_health_check() {
- let api = router();
-
- let response = api
- .oneshot(
- Request::builder()
- .uri("/health")
- .method("GET")
- .body(Body::empty())
- .unwrap(),
- )
- .await
- .unwrap();
-
- assert_eq!(response.status(), StatusCode::OK);
- }
-}
diff --git a/rust/cloud-storage/search_service/src/api/internal/mod.rs b/rust/cloud-storage/search_service/src/api/internal/mod.rs
deleted file mode 100644
index c99bf516cd..0000000000
--- a/rust/cloud-storage/search_service/src/api/internal/mod.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-use axum::Router;
-use axum::routing::get;
-
-use crate::api::{
- ApiContext,
- search::{self},
-};
-
-pub fn router() -> Router<ApiContext> {
- Router::new()
- .nest("/search", search::router())
- .route("/health", get(async move || "healthy"))
-}
diff --git a/rust/cloud-storage/search_service/src/api/mod.rs b/rust/cloud-storage/search_service/src/api/mod.rs
index 69a754ea6f..1d52f06926 100644
--- a/rust/cloud-storage/search_service/src/api/mod.rs
+++ b/rust/cloud-storage/search_service/src/api/mod.rs
@@ -1,62 +1,17 @@
-use anyhow::Context;
use axum::Router;
-use context::ApiContext;
-use tower::ServiceBuilder;
-use tower_http::trace::TraceLayer;
-use utoipa::OpenApi;
-use utoipa_swagger_ui::SwaggerUi;
+use context::SearchHandlerState;
// Routes
-mod health;
-mod internal;
-mod search;
+pub mod search;
// Misc
-pub(crate) mod context;
-pub(crate) mod swagger;
+pub mod context;
+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.clone())
- .with_state(state)
- .layer(cors.clone())
- .layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))
- // The health router is attached here so we don't attach the logging middleware to it
- .merge(health::router().layer(cors))
- .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()));
-
- let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", port))
- .await
- .unwrap();
- tracing::info!(
- "service is up and running with environment {:?} on port {}",
- env,
- port
- );
- axum::serve(listener, app.into_make_service())
- .await
- .context("error starting service")
-}
-
-fn api_router(state: ApiContext) -> Router<ApiContext> {
- Router::new()
- .nest(
- "/search",
- search::router().layer(axum::middleware::from_fn_with_state(
- state.clone(),
- macro_middleware::auth::decode_jwt::handler,
- )),
- )
- .nest(
- "/internal",
- internal::router().layer(ServiceBuilder::new().layer(
- axum::middleware::from_fn_with_state(
- state,
- macro_middleware::auth::internal_access::handler,
- ),
- )),
- )
+/// Creates the public search router.
+/// Exposes:
+/// - POST / - unified search
+/// - POST /simple - simple unified search
+pub fn router() -> Router<SearchHandlerState> {
+ search::router()
}
diff --git a/rust/cloud-storage/search_service/src/api/search/channel.rs b/rust/cloud-storage/search_service/src/api/search/channel.rs
index bf9eb91556..b4c516d3ce 100644
--- a/rust/cloud-storage/search_service/src/api/search/channel.rs
+++ b/rust/cloud-storage/search_service/src/api/search/channel.rs
@@ -2,7 +2,7 @@ use crate::api::search::simple::SearchError;
use indexmap::IndexMap;
use std::collections::HashMap;
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
use model::comms::ChannelHistoryInfo;
use models_search::channel::{
ChannelSearchResponseItem, ChannelSearchResponseItemWithMetadata, ChannelSearchResult,
@@ -13,7 +13,7 @@ use sqlx::types::Uuid;
/// Enriches channel message search results with metadata
#[tracing::instrument(skip(ctx, results), err)]
pub(in crate::api::search) async fn enrich_channels(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
results: Vec<opensearch_client::search::model::SearchHit>,
) -> Result<Vec<ChannelSearchResponseItemWithMetadata>, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/chat.rs b/rust/cloud-storage/search_service/src/api/search/chat.rs
index e679fe0b08..aedc681580 100644
--- a/rust/cloud-storage/search_service/src/api/search/chat.rs
+++ b/rust/cloud-storage/search_service/src/api/search/chat.rs
@@ -1,4 +1,4 @@
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
use crate::api::search::simple::SearchError;
use indexmap::IndexMap;
use models_search::chat::{
@@ -11,7 +11,7 @@ use std::collections::HashMap;
/// Enriches chat search results with metadata
#[tracing::instrument(skip(ctx, results), err)]
pub(in crate::api::search) async fn enrich_chats(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
results: Vec<opensearch_client::search::model::SearchHit>,
) -> Result<Vec<ChatSearchResponseItemWithMetadata>, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/document.rs b/rust/cloud-storage/search_service/src/api/search/document.rs
index cb00c224d7..b3e754269b 100644
--- a/rust/cloud-storage/search_service/src/api/search/document.rs
+++ b/rust/cloud-storage/search_service/src/api/search/document.rs
@@ -8,12 +8,12 @@ use opensearch_client::search::model::SearchGotoContent;
use sqlx::types::Uuid;
use std::collections::HashMap;
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
/// Enriches document search results with metadata
#[tracing::instrument(skip(ctx, results), err)]
pub(in crate::api::search) async fn enrich_documents(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
results: Vec<opensearch_client::search::model::SearchHit>,
) -> Result<Vec<DocumentSearchResponseItemWithMetadata>, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/email.rs b/rust/cloud-storage/search_service/src/api/search/email.rs
index d61bf5cc57..9261bf51ab 100644
--- a/rust/cloud-storage/search_service/src/api/search/email.rs
+++ b/rust/cloud-storage/search_service/src/api/search/email.rs
@@ -1,4 +1,4 @@
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
use crate::api::search::simple::SearchError;
use indexmap::IndexMap;
use models_email::service::message::{MessageSenderInfo, ThreadHistoryInfo};
@@ -12,7 +12,7 @@ use std::collections::HashMap;
/// Enriches email search results with metadata
#[tracing::instrument(skip(ctx, results), err)]
pub(in crate::api::search) async fn enrich_emails(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
results: Vec<opensearch_client::search::model::SearchHit>,
) -> Result<Vec<EmailSearchResponseItemWithMetadata>, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/enrich.rs b/rust/cloud-storage/search_service/src/api/search/enrich.rs
index 83c579ce8d..2ad9c79bfe 100644
--- a/rust/cloud-storage/search_service/src/api/search/enrich.rs
+++ b/rust/cloud-storage/search_service/src/api/search/enrich.rs
@@ -5,7 +5,7 @@ use models_search::unified::UnifiedSearchResponseItem;
use opensearch_client::search::model::SearchHit;
use crate::api::{
- context::ApiContext,
+ context::SearchHandlerState,
search::{
channel::enrich_channels, chat::enrich_chats, document::enrich_documents,
email::enrich_emails, project::enrich_projects, simple::SearchError,
@@ -14,7 +14,7 @@ use crate::api::{
/// Enriches search results with metadat and converts to UnifiedSearchResponseItem
pub async fn enrich_search_response(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
results: Vec<SearchHit>,
entity_type: SearchEntityType,
diff --git a/rust/cloud-storage/search_service/src/api/search/mod.rs b/rust/cloud-storage/search_service/src/api/search/mod.rs
index a6ee60273e..5c8ad94658 100644
--- a/rust/cloud-storage/search_service/src/api/search/mod.rs
+++ b/rust/cloud-storage/search_service/src/api/search/mod.rs
@@ -1,6 +1,6 @@
use axum::{Router, routing::post};
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
pub(in crate::api) mod channel;
pub(in crate::api) mod chat;
@@ -8,10 +8,10 @@ pub(in crate::api) mod document;
pub(in crate::api) mod email;
pub(in crate::api::search) mod enrich;
pub(in crate::api) mod project;
-pub(in crate::api) mod simple;
-pub(in crate::api) mod unified;
+pub mod simple;
+pub mod unified;
-pub fn router() -> Router<ApiContext> {
+pub fn router() -> Router<SearchHandlerState> {
Router::new()
.route("/", post(unified::handler))
.nest("/simple", simple::router())
diff --git a/rust/cloud-storage/search_service/src/api/search/project.rs b/rust/cloud-storage/search_service/src/api/search/project.rs
index 03866fbd6a..fabde2a3dc 100644
--- a/rust/cloud-storage/search_service/src/api/search/project.rs
+++ b/rust/cloud-storage/search_service/src/api/search/project.rs
@@ -6,12 +6,12 @@ use models_search::project::{
use sqlx::types::Uuid;
use std::collections::HashMap;
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
/// Enriches project search results with metadata
#[tracing::instrument(skip(ctx, results), err)]
pub(in crate::api::search) async fn enrich_projects(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
results: Vec<opensearch_client::search::model::SearchHit>,
) -> Result<Vec<ProjectSearchResponseItemWithMetadata>, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/filter.rs b/rust/cloud-storage/search_service/src/api/search/simple/filter.rs
index 2be4b8977a..d2d5d5d3ce 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/filter.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/filter.rs
@@ -7,7 +7,7 @@ use opensearch_client::search::unified::{
};
use crate::api::{
- context::ApiContext,
+ context::SearchHandlerState,
search::simple::{
SearchError, simple_channel::filter_channels, simple_chat::filter_chats,
simple_document::filter_documents, simple_project::filter_projects,
@@ -26,7 +26,7 @@ pub(super) trait FilterVariantToSearchArgs {
fn filter_to_search_args(
&self,
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
user_organization_id: Option<i32>,
should_include: bool,
@@ -38,7 +38,7 @@ impl FilterVariantToSearchArgs for item_filters::DocumentFilters {
async fn filter_to_search_args(
&self,
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
_user_organization_id: Option<i32>,
should_include: bool,
@@ -61,7 +61,7 @@ impl FilterVariantToSearchArgs for item_filters::ChannelFilters {
async fn filter_to_search_args(
&self,
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
user_organization_id: Option<i32>,
should_include: bool,
@@ -91,7 +91,7 @@ impl FilterVariantToSearchArgs for item_filters::ChatFilters {
async fn filter_to_search_args(
&self,
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
_user_organization_id: Option<i32>,
should_include: bool,
@@ -115,7 +115,7 @@ impl FilterVariantToSearchArgs for item_filters::ProjectFilters {
async fn filter_to_search_args(
&self,
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
_user_organization_id: Option<i32>,
should_include: bool,
@@ -138,7 +138,7 @@ impl FilterVariantToSearchArgs for item_filters::EmailFilters {
async fn filter_to_search_args(
&self,
- _ctx: &ApiContext,
+ _ctx: &SearchHandlerState,
_user_id: &str,
_user_organization_id: Option<i32>,
should_include: bool,
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/mod.rs b/rust/cloud-storage/search_service/src/api/search/simple/mod.rs
index 848e35b727..647111eb0f 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/mod.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/mod.rs
@@ -1,4 +1,4 @@
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
use axum::{
Json, Router,
http::StatusCode,
@@ -16,9 +16,9 @@ pub(in crate::api) mod simple_chat;
pub(in crate::api) mod simple_document;
pub(in crate::api) mod simple_email;
pub(in crate::api) mod simple_project;
-pub(in crate::api) mod simple_unified;
+pub mod simple_unified;
-pub fn router() -> Router<ApiContext> {
+pub fn router() -> Router<SearchHandlerState> {
Router::new().route("/", post(simple_unified::handler))
}
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_channel.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_channel.rs
index 05b65f9d92..2d2f8877c0 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_channel.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_channel.rs
@@ -2,14 +2,14 @@ use crate::api::search::simple::SearchError;
use item_filters::ChannelFilters;
use std::collections::HashSet;
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
pub(in crate::api::search) struct FilterChannelResponse {
pub channel_ids: Vec<sqlx::types::Uuid>,
}
pub(in crate::api::search) async fn filter_channels(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
organization_id: Option<i32>,
filters: &ChannelFilters,
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_chat.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_chat.rs
index ecc71b6ba9..b81e8695e7 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_chat.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_chat.rs
@@ -5,7 +5,7 @@ use model::item::{ShareableItem, ShareableItemType, UserAccessibleItem};
use opensearch_client::search::model::{Highlight, SearchHit};
use sqlx::{Pool, Postgres, types::Uuid};
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
#[derive(Debug)]
pub(in crate::api::search) struct FilterChatResponse {
@@ -14,7 +14,7 @@ pub(in crate::api::search) struct FilterChatResponse {
}
pub(in crate::api::search) async fn filter_chats(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
filters: &ChatFilters,
) -> Result<FilterChatResponse, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_document.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_document.rs
index a9db8a13eb..5a2e63ff74 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_document.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_document.rs
@@ -5,7 +5,7 @@ use model::item::{ShareableItem, ShareableItemType, UserAccessibleItem};
use opensearch_client::search::model::{Highlight, SearchHit};
use sqlx::{Pool, Postgres, types::Uuid};
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
#[derive(Debug)]
pub(in crate::api::search) struct FilterDocumentResponse {
@@ -14,7 +14,7 @@ pub(in crate::api::search) struct FilterDocumentResponse {
}
pub(in crate::api::search) async fn filter_documents(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
filters: &DocumentFilters,
) -> Result<FilterDocumentResponse, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_project.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_project.rs
index ce2613dea4..c14410f975 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_project.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_project.rs
@@ -5,7 +5,7 @@ use model::item::{ShareableItem, ShareableItemType};
use opensearch_client::search::model::{Highlight, SearchHit};
use sqlx::{Pool, Postgres, types::Uuid};
-use crate::api::ApiContext;
+use crate::api::context::SearchHandlerState;
#[derive(Debug)]
pub(in crate::api::search) struct FilterProjectResponse {
@@ -14,7 +14,7 @@ pub(in crate::api::search) struct FilterProjectResponse {
}
pub(in crate::api::search) async fn filter_projects(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_id: &str,
filters: &ProjectFilters,
) -> Result<FilterProjectResponse, SearchError> {
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs
index eaa733822d..428a62a5e3 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs
@@ -2,7 +2,7 @@ use crate::api::search::simple::filter::FilterVariantToSearchArgs;
use crate::api::search::simple::{simple_chat, simple_document, simple_email, simple_project};
use crate::api::{
- ApiContext,
+ context::SearchHandlerState,
search::{SearchPaginationParams, simple::SearchError},
};
use axum::{
@@ -86,7 +86,7 @@ fn compute_next_cursor(
/// by calling individual simple search endpoints for each entity type
#[tracing::instrument(skip(ctx, user_context, query_params, req), err)]
pub(in crate::api::search) async fn perform_unified_search(
- ctx: &ApiContext,
+ ctx: &SearchHandlerState,
user_context: &UserContext,
query_params: SearchPaginationParams,
req: UnifiedSearchRequest,
@@ -577,7 +577,7 @@ pub(in crate::api::search) async fn perform_unified_search(
)]
#[tracing::instrument(skip(ctx, user_context), fields(user_id=user_context.user_id), err)]
pub async fn handler(
- State(ctx): State<ApiContext>,
+ State(ctx): State<SearchHandlerState>,
user_context: Extension<UserContext>,
extract::Query(query_params): extract::Query<SearchPaginationParams>,
extract::Json(req): extract::Json<UnifiedSearchRequest>,
diff --git a/rust/cloud-storage/search_service/src/api/search/unified.rs b/rust/cloud-storage/search_service/src/api/search/unified.rs
index 4d564e0a3b..30a1dc0f8e 100644
--- a/rust/cloud-storage/search_service/src/api/search/unified.rs
+++ b/rust/cloud-storage/search_service/src/api/search/unified.rs
@@ -1,6 +1,6 @@
use super::SearchPaginationParams;
use crate::api::{
- ApiContext,
+ context::SearchHandlerState,
search::{
enrich::enrich_search_response,
simple::{SearchError, simple_unified::perform_unified_search},
@@ -38,7 +38,7 @@ use std::cmp::Ordering;
)]
#[tracing::instrument(skip(ctx, user_context), fields(user_id=user_context.user_id), err)]
pub async fn handler(
- State(ctx): State<ApiContext>,
+ State(ctx): State<SearchHandlerState>,
user_context: Extension<UserContext>,
extract::Query(query_params): extract::Query<SearchPaginationParams>,
extract::Json(req): extract::Json<UnifiedSearchRequest>,
diff --git a/rust/cloud-storage/search_service/src/api/swagger.rs b/rust/cloud-storage/search_service/src/api/swagger.rs
index b2fd488ad8..fd112f53ed 100644
--- a/rust/cloud-storage/search_service/src/api/swagger.rs
+++ b/rust/cloud-storage/search_service/src/api/swagger.rs
@@ -1,7 +1,7 @@
use document_sub_type::DocumentSubType;
use utoipa::OpenApi;
-use crate::api::{health, search};
+use crate::api::search;
use model::{document::FileType, response::EmptyResponse};
use models_search::channel::{
@@ -38,9 +38,6 @@ use models_search::{MatchType, SearchHighlight};
terms_of_service = "https://macro.com/terms",
),
paths(
- /// /health
- health::health_handler,
-
/// /search
search::unified::handler,
diff --git a/rust/cloud-storage/search_service/src/lib.rs b/rust/cloud-storage/search_service/src/lib.rs
new file mode 100644
index 0000000000..9129eaa2b4
--- /dev/null
+++ b/rust/cloud-storage/search_service/src/lib.rs
@@ -0,0 +1,9 @@
+//! Search Service Library - exposes API routes for integration into other services
+
+pub mod api;
+pub mod config;
+
+// Re-exports for consumers
+pub use api::context::SearchHandlerState;
+pub use api::router as search_router;
+pub use api::swagger::ApiDoc as SearchApiDoc;
diff --git a/rust/cloud-storage/search_service/src/main.rs b/rust/cloud-storage/search_service/src/main.rs
deleted file mode 100644
index 5ff70fcce2..0000000000
--- a/rust/cloud-storage/search_service/src/main.rs
+++ /dev/null
@@ -1,78 +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 opensearch_client::OpensearchClient;
-use secretsmanager_client::SecretManager;
-use sqlx::postgres::PgPoolOptions;
-use std::sync::Arc;
-
-mod api;
-mod config;
-
-#[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::trace!("initialized config");
-
- let aws_config = macro_aws_config::get_macro_aws_config().await;
-
- let secretsmanager_client = secretsmanager_client::SecretsManager::new(
- aws_sdk_secretsmanager::Client::new(&aws_config),
- );
-
- let (min_connections, max_connections): (u32, u32) = match config.environment {
- Environment::Production => (5, 30),
- Environment::Develop => (3, 20),
- Environment::Local => (3, 10),
- };
-
- let db = PgPoolOptions::new()
- .min_connections(min_connections)
- .max_connections(max_connections)
- .connect(&config.database_url)
- .await
- .context("failed to connect to macrodb")?;
-
- let opensearch_password = match config.environment {
- Environment::Local => config.opensearch_password.clone(),
- _ => secretsmanager_client
- .get_secret_value(&config.opensearch_password)
- .await
- .context("unable to get secret")?
- .to_string(),
- };
-
- let opensearch_client = OpensearchClient::new(
- config.opensearch_url.clone(),
- config.opensearch_username.clone(),
- opensearch_password,
- )
- .context("unable to create opensearch client")?;
-
- if let Err(e) = opensearch_client.health().await {
- tracing::error!(error=?e, "error connecting to opensearch");
- return Err(e);
- }
-
- let jwt_args =
- JwtValidationArgs::new_with_secret_manager(config.environment, &secretsmanager_client)
- .await?;
-
- api::setup_and_serve(ApiContext {
- db,
- opensearch_client: Arc::new(opensearch_client),
- jwt_args,
- internal_auth_key: secretsmanager_client::LocalOrRemoteSecret::Local(
- InternalApiSecretKey::new()?,
- ),
- config: Arc::new(config),
- })
- .await?;
- Ok(())
-}
diff --git a/rust/cloud-storage/search_service/src/openapi.rs b/rust/cloud-storage/search_service/src/openapi.rs
index faf5b1c433..3be1157846 100644
--- a/rust/cloud-storage/search_service/src/openapi.rs
+++ b/rust/cloud-storage/search_service/src/openapi.rs
@@ -1,13 +1,8 @@
#![allow(unused)]
-mod api;
-mod config;
-
+use search_service::SearchApiDoc;
use utoipa::OpenApi;
fn main() {
- println!(
- "{}",
- api::swagger::ApiDoc::openapi().to_pretty_json().unwrap()
- );
+ println!("{}", SearchApiDoc::openapi().to_pretty_json().unwrap());
}
diff --git a/rust/cloud-storage/search_service_client/src/constants.rs b/rust/cloud-storage/search_service_client/src/constants.rs
index c09d47eece..6c0f1ba527 100644
--- a/rust/cloud-storage/search_service_client/src/constants.rs
+++ b/rust/cloud-storage/search_service_client/src/constants.rs
@@ -1,2 +1,4 @@
-pub static INTERNAL_API_KEY_HEADER: &str = "x-internal-auth-key";
-pub static INTERNAL_MACRO_USER_ID_HEADER: &str = "x-internal-macro-user-id";
+/// The search service endpoints are hosted in dss which uses this special headers
+pub static INTERNAL_API_KEY_HEADER: &str = "x-document-storage-service-auth-key";
+/// The search service endpoints are hosted in dss which uses this special headers
+pub static INTERNAL_MACRO_USER_ID_HEADER: &str = "x-document-storage-service-user-id";