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.

feat(doppler): document cognition service doppler (#4307)

Will Hutchinson43503df7f3e1
diff --git a/infra/stacks/document-cognition-service/document-cognition-service.ts b/infra/stacks/document-cognition-service/document-cognition-service.ts
index beb2ce7351..f4f2fbee25 100644
--- a/infra/stacks/document-cognition-service/document-cognition-service.ts
+++ b/infra/stacks/document-cognition-service/document-cognition-service.ts
@@ -14,6 +14,7 @@ import { EcrImage } from '../../packages/service';
import {
BASE_DOMAIN,
CLOUD_TRAIL_SNS_TOPIC_ARN,
+ DopplerEcsEnvironment,
stack,
} from '../../packages/shared';
@@ -224,6 +225,12 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
{ parent: this }
);
+ const dopplerEcsEnvironment = new DopplerEcsEnvironment(
+ BASE_NAME,
+ { tags: this.tags },
+ { parent: this }
+ );
+
// service
const service = new awsx.ecs.FargateService(
`${BASE_NAME}`,
@@ -243,6 +250,9 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
taskRole: {
roleArn: this.role.arn,
},
+ executionRole: {
+ roleArn: dopplerEcsEnvironment.executionRole.arn,
+ },
containers: {
log_router: fargateLogRouterSidecarContainer,
datadog_agent: datadogAgentContainer,
@@ -253,6 +263,7 @@ export class DocumentCognitionService extends pulumi.ComponentResource {
cpu: 4096,
memory: 8192,
environment: containerEnvVars,
+ secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
logDriver: 'awsfirelens',
options: {
diff --git a/infra/stacks/document-cognition-service/index.ts b/infra/stacks/document-cognition-service/index.ts
index ddf57f0feb..678962add5 100644
--- a/infra/stacks/document-cognition-service/index.ts
+++ b/infra/stacks/document-cognition-service/index.ts
@@ -6,16 +6,11 @@ import {
getMacroApiToken,
getMacroNotify,
getSearchEventQueue,
- getServiceUrl,
- ServiceUrl,
stack,
} from '../../packages/shared';
import { Queue } from '../../packages/resources';
import { get_coparse_api_vpc } from '../../packages/vpc';
-import {
- DocumentCognitionService,
- SERVICE_DOMAIN_NAME,
-} from './document-cognition-service';
+import { DocumentCognitionService } from './document-cognition-service';
import { AiProjectionsRefreshTrigger } from './ai-projections-refresh-trigger';
const tags = {
@@ -26,13 +21,6 @@ const tags = {
service: 'document-cognition-service',
};
-// NOTE: NEVER EVER EVER EXPORT THIS. ITS A SECRET VALUE
-const DATABASE_URL = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.require(`macro_db_secret_key`),
- })
- .apply((secret) => secret.secretString);
-
// NOTE: NEVER EVER EVER EXPORT THIS. ITS A SECRET VALUE
const PROXY_DATABASE_URL = aws.secretsmanager
.getSecretVersionOutput({
@@ -45,39 +33,6 @@ const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: JWT_SECRET_KEY })
.apply((secret) => secret.arn);
-const fusionauthClientIdSecretKey = config.require(`fusionauth_client_id`);
-
-const FUSIONAUTH_CLIENT_ID = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: fusionauthClientIdSecretKey,
- })
- .apply((secret) => secret.secretString);
-const FUSIONAUTH_ISSUER = config.require(`fusionauth_issuer`);
-
-const OPEN_ROUTER_API_KEY = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.require('open-router-api-key'),
- })
- .apply((secret) => secret.secretString);
-
-const XAI_API_KEY = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.get('xai-api-key') ?? '',
- })
- .apply((secret) => secret.secretString);
-
-const GCP_SERVICE_ACCOUNT = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.get('gcp_service_account') ?? '',
- })
- .apply((secret) => secret.secretString);
-
-const PERPLEXITY_API_KEY = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.get('perplexity-api-key') ?? '',
- })
- .apply((secret) => secret.secretString);
-
const AUTHENTICATION_SERVICE_INTERNAL_API_KEY_SECRET_NAME = config.require(
'authentication_service_internal_api_key'
);
@@ -104,14 +59,6 @@ const connectionGatewayStack = new pulumi.StackReference(
}
);
-const connectionGatewayRedisUrl: pulumi.Output<string> = connectionGatewayStack
- .getOutput('connectionGatewayRedisUrl')
- .apply((url) => url as string);
-
-const connectionGatewayTableName: pulumi.Output<string> = connectionGatewayStack
- .getOutput('connectionGatewayTableName')
- .apply((name) => name as string);
-
const connectionGatewayTablePolicyArn: pulumi.Output<string> =
connectionGatewayStack
.getOutput('connectionGatewayTablePolicyArn')
@@ -150,11 +97,6 @@ const documentTextExtractorQueueArn: pulumi.Output<string> =
.getOutput('documentTextExtractorLambdaQueueArn')
.apply((arn) => arn as string);
-const documentTextExtractorQueueName: pulumi.Output<string> =
- documentTextExtractorStack
- .getOutput('documentTextExtractorLambdaQueueName')
- .apply((name) => name as string);
-
const cloudStorageClusterArn: pulumi.Output<string> = cloudStorageStack
.getOutput('cloudStorageClusterArn')
.apply((arn) => arn as string);
@@ -163,10 +105,9 @@ const cloudStorageClusterName: pulumi.Output<string> = cloudStorageStack
.getOutput('cloudStorageClusterName')
.apply((arn) => arn as string);
-const { notificationIngressQueueName, notificationIngressQueueArn } =
- getMacroNotify();
+const { notificationIngressQueueArn } = getMacroNotify();
-const { searchEventQueueName, searchEventQueueArn } = getSearchEventQueue();
+const { searchEventQueueArn } = getSearchEventQueue();
// ── AI projection queue ──────────────────────────────────────────────────────
// This service both produces (on upsert) and consumes (via the inbound worker)
@@ -231,92 +172,10 @@ const documentCognitionService = new DocumentCognitionService(
],
connectionTablePolicyArn: connectionGatewayTablePolicyArn,
containerEnvVars: [
- ...aiTools.envVars,
- {
- name: 'DATABASE_URL',
- value: pulumi.interpolate`${DATABASE_URL}`,
- },
{
name: 'ENVIRONMENT',
value: stack,
},
- {
- name: 'RUST_LOG',
- value: `info`,
- },
- {
- name: 'OPEN_ROUTER_API_KEY',
- value: pulumi.interpolate`${OPEN_ROUTER_API_KEY}`,
- },
- {
- name: 'XAI_API_KEY',
- value: pulumi.interpolate`${XAI_API_KEY}`,
- },
- {
- name: 'DOCUMENT_TEXT_EXTRACTOR_QUEUE',
- value: pulumi.interpolate`${documentTextExtractorQueueName}`,
- },
- {
- name: 'CHAT_DELETE_QUEUE',
- value: pulumi.interpolate`${deleteChatQueueName}`,
- },
- {
- name: 'GCP_SERVICE_ACCOUNT',
- value: pulumi.interpolate`${GCP_SERVICE_ACCOUNT}`,
- },
- { name: 'ISSUER', value: pulumi.interpolate`${FUSIONAUTH_ISSUER}` },
- {
- name: 'JWT_SECRET_KEY',
- value: pulumi.interpolate`${JWT_SECRET_KEY}`,
- },
- {
- name: 'AUDIENCE',
- value: pulumi.interpolate`${FUSIONAUTH_CLIENT_ID}`,
- },
- {
- name: 'NOTIFICATION_QUEUE',
- value: pulumi.interpolate`${notificationIngressQueueName}`,
- },
- {
- name: ServiceUrl.CONNECTION_GATEWAY_URL,
- value: getServiceUrl(ServiceUrl.CONNECTION_GATEWAY_URL),
- },
- {
- name: 'SEARCH_EVENT_QUEUE',
- value: pulumi.interpolate`${searchEventQueueName}`,
- },
- {
- name: 'AI_PROJECTION_QUEUE',
- value: pulumi.interpolate`${aiProjectionQueue.queue.name}`,
- },
- {
- name: 'MACRO_API_TOKEN_ISSUER',
- value: pulumi.interpolate`${MACRO_API_TOKENS.macroApiTokenIssuer}`,
- },
- {
- name: 'MACRO_API_TOKEN_PUBLIC_KEY',
- value: pulumi.interpolate`${MACRO_API_TOKENS.macroApiTokenPublicKey}`,
- },
- {
- name: 'PERPLEXITY_API_KEY',
- value: pulumi.interpolate`${PERPLEXITY_API_KEY}`,
- },
- {
- name: ServiceUrl.AUTHENTICATION_SERVICE_URL,
- value: getServiceUrl(ServiceUrl.AUTHENTICATION_SERVICE_URL),
- },
- {
- name: 'AUTHENTICATION_SERVICE_SECRET_KEY',
- value: AUTHENTICATION_SERVICE_INTERNAL_API_KEY_SECRET_NAME,
- },
- {
- name: 'REDIS_HOST',
- value: pulumi.interpolate`redis://${connectionGatewayRedisUrl}`,
- },
- {
- name: 'CONNECTION_GATEWAY_TABLE',
- value: pulumi.interpolate`${connectionGatewayTableName}`,
- },
// OpenTelemetry / Datadog tracing configuration
{
name: 'DD_SERVICE',
@@ -326,10 +185,6 @@ const documentCognitionService = new DocumentCognitionService(
name: 'DD_ENV',
value: stack,
},
- {
- name: 'DOCUMENT_COGNITION_SERVICE_URL',
- value: `https://${SERVICE_DOMAIN_NAME}`,
- },
],
isPrivate: false,
tags,
diff --git a/infra/stacks/doppler-projects/index.ts b/infra/stacks/doppler-projects/index.ts
index a62062b6c8..a8c64f6134 100644
--- a/infra/stacks/doppler-projects/index.ts
+++ b/infra/stacks/doppler-projects/index.ts
@@ -14,6 +14,7 @@ const SERVICE_NAMES = [
'agent-schedule-service',
'mcp-server',
'email-service',
+ 'document-cognition',
];
for (const service_name of SERVICE_NAMES) {
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index f53941e833..60116fff22 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -3601,6 +3601,7 @@ dependencies = [
"document_storage_service_client",
"documents",
"doppleganger",
+ "doppler-config",
"email",
"email_service_client",
"entity_access",
@@ -3616,6 +3617,7 @@ dependencies = [
"log",
"macro_auth",
"macro_aws_config",
+ "macro_config",
"macro_cors",
"macro_db_client",
"macro_db_migrator",
diff --git a/rust/cloud-storage/document_cognition_service/Cargo.toml b/rust/cloud-storage/document_cognition_service/Cargo.toml
index 455c129eaa..4bfc3ff1f3 100644
--- a/rust/cloud-storage/document_cognition_service/Cargo.toml
+++ b/rust/cloud-storage/document_cognition_service/Cargo.toml
@@ -13,6 +13,10 @@ path = "src/main.rs"
name = "document_cognition_service_openapi"
path = "src/openapi.rs"
+[[bin]]
+name = "document_cognition_service_doppler_config"
+path = "src/doppler_config.rs"
+
[features]
local = []
local_auth = ["macro_middleware/local_auth"]
@@ -47,6 +51,7 @@ crm = { path = "../crm" }
document_storage_service_client = { path = "../document_storage_service_client" }
documents = { path = "../documents", features = ["ai_tools", "attachment"] }
doppleganger = { workspace = true }
+doppler-config = { workspace = true }
email = { path = "../email", features = ["outbound", "attachment"] }
email_service_client = { path = "../email_service_client" }
entity_access = { path = "../entity_access" }
@@ -63,6 +68,7 @@ log = { workspace = true }
macro_auth = { path = "../macro_auth" }
macro_aws_config = { path = "../macro_aws_config", features = ["s3"] }
macro_cors = { path = "../macro_cors" }
+macro_config = { path = "../macro_config" }
macro_db_client = { path = "../macro_db_client" }
macro_entrypoint = { path = "../macro_entrypoint" }
macro_env = { path = "../macro_env" }
diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rs
index f79d1929c6..d16d16112f 100644
--- a/rust/cloud-storage/document_cognition_service/src/config.rs
+++ b/rust/cloud-storage/document_cognition_service/src/config.rs
@@ -1,211 +1,136 @@
+use anyhow::Context;
pub use macro_env::Environment;
-use macro_env_var::{env_var, maybe_env_var};
-use macro_service_urls::{
- ConnectionGatewayUrl, DocumentCognitionServiceUrl, DocumentStorageServiceUrl, EmailServiceUrl,
- LexicalServiceUrl, StaticFileServiceUrl, SyncServiceUrl,
-};
+use macro_env_var::{env_vars, maybe_env_vars};
+use secretsmanager_client::LocalOrRemoteSecret;
use crate::core::constants::DEFAULT_DOCUMENT_BATCH_LIMIT;
+
+env_vars!(
+ pub struct DatabaseUrl;
+ pub struct DocumentStorageBucket;
+ pub struct DocumentTextExtractorQueue;
+ pub struct ChatDeleteQueue;
+ pub struct EmailScheduledQueue;
+ pub struct NotificationQueue;
+ pub struct DocumentStorageServiceAuthKey;
+ pub struct SearchEventQueue;
+ pub struct AiProjectionQueue;
+ pub struct SyncServiceAuthKey;
+ pub struct AuthenticationServiceUrl;
+ pub struct AuthenticationServiceSecretKey;
+ pub struct RedisHost;
+ pub struct DocxDocumentUploadBucket;
+ pub struct DocumentStorageServiceCloudfrontDistributionUrl;
+ pub struct DocumentStorageServiceCloudfrontSignerPublicKeyId;
+ pub struct DocumentStorageServiceCloudfrontSignerPrivateKey;
+ pub struct McpCredentialsKeySecretName;
+);
+
+maybe_env_vars!(
+ pub struct DocumentBatchLimit;
+);
+
/// The configuration parameters for the application.
-///
-/// These can either be passed on the command line, or pulled from environment variables.
-/// The latter is preferred as environment variables are one of the recommended ways to
-/// populate the Docker container
-///
-/// See `.env.sample` in cognitive-workspace root for details.
+#[derive(macro_config::MacroConfig)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct Config {
/// The connection URL for the Postgres database this application should use.
- pub database_url: String,
+ pub database_url: DatabaseUrl,
/// The port to listen for HTTP requests on.
+ #[macro_config_default(8080)]
pub port: usize,
/// The environment we are in
+ #[macro_config_default(Environment::new_or_prod())]
pub environment: Environment,
/// The maximum number of results in a document query
+ #[macro_config_default(DEFAULT_DOCUMENT_BATCH_LIMIT)]
pub document_batch_limit: i64,
/// document storage bucket
- pub document_storage_bucket: String,
- /// document storage service url
- pub document_storage_service_url: String,
+ pub document_storage_bucket: DocumentStorageBucket,
/// document storage service auth key
- pub document_storage_service_auth_key: String,
+ pub document_storage_service_auth_key: DocumentStorageServiceAuthKey,
/// The sqs queue to send document text extract jobs to
- pub document_text_extractor_queue: String,
+ pub document_text_extractor_queue: DocumentTextExtractorQueue,
/// The sqs queue to send chat delete jobs
- pub chat_delete_queue: String,
+ pub chat_delete_queue: ChatDeleteQueue,
/// The sqs queue to enqueue outbound email sends
- pub email_scheduled_queue: String,
+ pub email_scheduled_queue: EmailScheduledQueue,
/// The sqs queue to send notifications to
- pub notification_queue: String,
- pub search_event_queue: String,
+ pub notification_queue: NotificationQueue,
+ pub search_event_queue: SearchEventQueue,
/// The sqs queue used to enqueue and poll ai projection materialization jobs
- pub ai_projection_queue: String,
- pub sync_service_url: String,
- pub sync_service_auth_key: String,
- pub lexical_service_url: String,
- pub email_service_url: String,
- /// document cognition service url for scribe tool to loopback
- pub document_cognition_service_url: String,
- /// static file service url
- pub static_file_service_url: String,
- /// connection gateway url
- pub connection_gateway_url: String,
- /// authentication service url (for soup service)
- pub authentication_service_url: String,
+ pub ai_projection_queue: AiProjectionQueue,
+ pub sync_service_auth_key: LocalOrRemoteSecret<SyncServiceAuthKey>,
/// authentication service secret key (for soup service)
- pub authentication_service_secret_key: String,
+ pub authentication_service_secret_key: AuthenticationServiceSecretKey,
/// Redis host for stream service
pub redis_host: RedisHost,
/// The S3 bucket for DOCX document uploads
- pub docx_document_upload_bucket: String,
+ pub docx_document_upload_bucket: DocxDocumentUploadBucket,
/// CloudFront distribution URL for document storage
- pub cloudfront_distribution_url: String,
+ pub document_storage_service_cloudfront_distribution_url:
+ DocumentStorageServiceCloudfrontDistributionUrl,
/// CloudFront signer public key ID
- pub cloudfront_signer_public_key_id: String,
+ pub document_storage_service_cloudfront_signer_public_key_id:
+ DocumentStorageServiceCloudfrontSignerPublicKeyId,
/// CloudFront signer private key (secret name or value)
- pub cloudfront_signer_private_key: String,
+ pub document_storage_service_cloudfront_signer_private_key:
+ LocalOrRemoteSecret<DocumentStorageServiceCloudfrontSignerPrivateKey>,
/// MCP credentials encryption key (base64-encoded, secret name or value)
- pub mcp_credentials_key_secret_name: String,
+ pub mcp_credentials_key_secret_name: LocalOrRemoteSecret<McpCredentialsKeySecretName>,
}
-env_var!(
- pub struct EnvVars {
- pub DatabaseUrl,
- pub DocumentStorageBucket,
- pub DocumentTextExtractorQueue,
- pub ChatDeleteQueue,
- pub EmailScheduledQueue,
- pub NotificationQueue,
- pub DocumentStorageServiceAuthKey,
- pub SearchEventQueue,
- pub AiProjectionQueue,
- pub SyncServiceAuthKey,
- pub AuthenticationServiceUrl,
- pub AuthenticationServiceSecretKey,
- pub RedisHost,
- pub DocxDocumentUploadBucket,
- pub DocumentStorageServiceCloudfrontDistributionUrl,
- pub DocumentStorageServiceCloudfrontSignerPublicKeyId,
- pub DocumentStorageServiceCloudfrontSignerPrivateKeySecretName,
- pub McpCredentialsKeySecretName,
- }
-);
-
-maybe_env_var!(
- pub struct MaybeEnvVars {
- pub Port,
- pub DocumentBatchLimit,
- }
-);
-
impl Config {
#[tracing::instrument(err, skip_all)]
- pub fn from_env(env_vars: EnvVars) -> anyhow::Result<Self> {
- let maybe = MaybeEnvVars::new();
-
- let port: usize = maybe.port.as_deref().unwrap_or("8080").parse().unwrap();
- let environment = Environment::new_or_prod();
-
- let document_batch_limit = maybe
- .document_batch_limit
- .as_deref()
- .and_then(|v| v.parse::<i64>().ok())
- .unwrap_or(DEFAULT_DOCUMENT_BATCH_LIMIT);
-
- let document_storage_service_url = DocumentStorageServiceUrl::new()?.to_string();
- let sync_service_url = SyncServiceUrl::new()?.to_string();
- let lexical_service_url = LexicalServiceUrl::new()?.to_string();
- let email_service_url = EmailServiceUrl::new()?.to_string();
- let document_cognition_service_url = DocumentCognitionServiceUrl::new()?.to_string();
- let static_file_service_url = StaticFileServiceUrl::new()?.to_string();
- let connection_gateway_url = ConnectionGatewayUrl::new()?.to_string();
-
- let EnvVars {
- database_url,
- document_storage_bucket,
- document_text_extractor_queue,
- chat_delete_queue,
- email_scheduled_queue,
- notification_queue,
- document_storage_service_auth_key,
- search_event_queue,
- ai_projection_queue,
- sync_service_auth_key,
- authentication_service_url,
- authentication_service_secret_key,
- redis_host,
- docx_document_upload_bucket,
- document_storage_service_cloudfront_distribution_url,
- document_storage_service_cloudfront_signer_public_key_id,
- document_storage_service_cloudfront_signer_private_key_secret_name,
- mcp_credentials_key_secret_name,
- } = env_vars;
-
- Ok(Config {
- database_url: database_url.to_string(),
- port,
- environment,
- document_batch_limit,
- document_storage_bucket: document_storage_bucket.to_string(),
- document_storage_service_url,
- document_storage_service_auth_key: document_storage_service_auth_key.to_string(),
- document_text_extractor_queue: document_text_extractor_queue.to_string(),
- chat_delete_queue: chat_delete_queue.to_string(),
- email_scheduled_queue: email_scheduled_queue.to_string(),
- notification_queue: notification_queue.to_string(),
- search_event_queue: search_event_queue.to_string(),
- ai_projection_queue: ai_projection_queue.to_string(),
- sync_service_auth_key: sync_service_auth_key.to_string(),
- sync_service_url,
- lexical_service_url,
- email_service_url,
- document_cognition_service_url,
- static_file_service_url,
- connection_gateway_url,
- authentication_service_url: authentication_service_url.to_string(),
- authentication_service_secret_key: authentication_service_secret_key.to_string(),
- redis_host,
- docx_document_upload_bucket: docx_document_upload_bucket.to_string(),
- cloudfront_distribution_url: document_storage_service_cloudfront_distribution_url
- .to_string(),
- cloudfront_signer_public_key_id:
- document_storage_service_cloudfront_signer_public_key_id.to_string(),
- cloudfront_signer_private_key:
- document_storage_service_cloudfront_signer_private_key_secret_name.to_string(),
- mcp_credentials_key_secret_name: mcp_credentials_key_secret_name.to_string(),
- })
+ pub fn from_env() -> anyhow::Result<Self> {
+ macro_config::ConfigLoader::load::<Config>().context("failed to load config")
}
#[cfg(test)]
pub fn new_empty_for_test() -> Self {
Config {
environment: Environment::Local,
- database_url: Default::default(),
+ database_url: DatabaseUrl::Comptime("DATABASE_URL"),
port: Default::default(),
- document_batch_limit: Default::default(),
- document_storage_bucket: Default::default(),
- document_storage_service_url: Default::default(),
- document_storage_service_auth_key: Default::default(),
- document_text_extractor_queue: Default::default(),
- chat_delete_queue: Default::default(),
- email_scheduled_queue: Default::default(),
- notification_queue: Default::default(),
- search_event_queue: Default::default(),
- ai_projection_queue: Default::default(),
- sync_service_url: Default::default(),
- sync_service_auth_key: Default::default(),
- lexical_service_url: Default::default(),
- email_service_url: Default::default(),
- document_cognition_service_url: Default::default(),
- static_file_service_url: Default::default(),
- connection_gateway_url: Default::default(),
- authentication_service_url: Default::default(),
- authentication_service_secret_key: Default::default(),
- redis_host: RedisHost::Comptime("redis://localhost:6379"),
- docx_document_upload_bucket: Default::default(),
- cloudfront_distribution_url: Default::default(),
- cloudfront_signer_public_key_id: Default::default(),
- cloudfront_signer_private_key: Default::default(),
- mcp_credentials_key_secret_name: Default::default(),
+ document_batch_limit: DEFAULT_DOCUMENT_BATCH_LIMIT,
+ document_storage_bucket: DocumentStorageBucket::Comptime("DOCUMENT_STORAGE_BUCKET"),
+ document_storage_service_auth_key: DocumentStorageServiceAuthKey::Comptime(
+ "DOCUMENT_STORAGE_SERVICE_AUTH_KEY",
+ ),
+ document_text_extractor_queue: DocumentTextExtractorQueue::Comptime(
+ "DOCUMENT_TEXT_EXTRACTOR_QUEUE",
+ ),
+ chat_delete_queue: ChatDeleteQueue::Comptime("CHAT_DELETE_QUEUE"),
+ email_scheduled_queue: EmailScheduledQueue::Comptime("EMAIL_SCHEDULED_QUEUE"),
+ notification_queue: NotificationQueue::Comptime("NOTIFICATION_QUEUE"),
+ search_event_queue: SearchEventQueue::Comptime("SEARCH_EVENT_QUEUE"),
+ ai_projection_queue: AiProjectionQueue::Comptime("AI_PROJECTION_QUEUE"),
+ sync_service_auth_key: LocalOrRemoteSecret::Local(SyncServiceAuthKey::Comptime(
+ "SYNC_SERVICE_AUTH_KEY",
+ )),
+ authentication_service_secret_key: AuthenticationServiceSecretKey::Comptime(
+ "AUTHENTICATION_SERVICE_SECRET_KEY",
+ ),
+ redis_host: RedisHost::Comptime("REDIS_HOST"),
+ docx_document_upload_bucket: DocxDocumentUploadBucket::Comptime(
+ "DOCX_DOCUMENT_UPLOAD_BUCKET",
+ ),
+ document_storage_service_cloudfront_distribution_url:
+ DocumentStorageServiceCloudfrontDistributionUrl::Comptime(
+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_DISTRIBUTION_URL",
+ ),
+ document_storage_service_cloudfront_signer_public_key_id:
+ DocumentStorageServiceCloudfrontSignerPublicKeyId::Comptime(
+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID",
+ ),
+ document_storage_service_cloudfront_signer_private_key: LocalOrRemoteSecret::Local(
+ DocumentStorageServiceCloudfrontSignerPrivateKey::Comptime(
+ "DOCUMENT_STORAGE_SERVICE_CLOUDFRONT_SIGNER_PRIVATE_KEY",
+ ),
+ ),
+ mcp_credentials_key_secret_name: LocalOrRemoteSecret::Local(
+ McpCredentialsKeySecretName::Comptime("MCP_CREDENTIALS_KEY_SECRET_NAME"),
+ ),
}
}
}
diff --git a/rust/cloud-storage/document_cognition_service/src/doppler_config.rs b/rust/cloud-storage/document_cognition_service/src/doppler_config.rs
new file mode 100644
index 0000000000..e82fcd434f
--- /dev/null
+++ b/rust/cloud-storage/document_cognition_service/src/doppler_config.rs
@@ -0,0 +1,32 @@
+#![allow(unused)]
+#![recursion_limit = "256"]
+
+use macro_env::Environment;
+
+mod config;
+mod core;
+
+const DOPPLER_PROJECT: &str = "document-cognition";
+
+#[tokio::main]
+async fn main() -> anyhow::Result<()> {
+ let dev = doppler_config::DopplerConfig::builder()
+ .token_from_env("DOPPLER_TOKEN")
+ .config(Environment::Develop.to_doppler_slug())
+ .project(DOPPLER_PROJECT)
+ .build()
+ .expect("able to grab doppler project");
+
+ dev.load::<config::Config>().await?;
+
+ let prd = doppler_config::DopplerConfig::builder()
+ .token_from_env("DOPPLER_TOKEN")
+ .config(Environment::Production.to_doppler_slug())
+ .project(DOPPLER_PROJECT)
+ .build()
+ .expect("able to grab doppler project");
+
+ prd.load::<config::Config>().await?;
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index dd35194e3f..51a1d1c5b1 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -9,7 +9,7 @@ use call::outbound::s3_recording_storage::S3RecordingStorage;
use channels::{
domain::list_service::ChannelListServiceImpl, outbound::pg_channels_repo::PgChannelsRepo,
};
-use config::{Config, EnvVars, Environment};
+use config::{Config, Environment};
use document_storage_service_client::DocumentStorageServiceClient;
use documents::{
domain::{models::CloudFrontConfig, service::DocumentServiceImpl},
@@ -30,6 +30,10 @@ use frecency::outbound::postgres::FrecencyPgStorage;
use macro_auth::middleware::decode_jwt::JwtValidationArgs;
use macro_entrypoint::MacroEntrypoint;
use macro_middleware::auth::internal_access::InternalApiSecretKey;
+use macro_service_urls::{
+ ConnectionGatewayUrl, DocumentCognitionServiceUrl, DocumentStorageServiceUrl, EmailServiceUrl,
+ LexicalServiceUrl, StaticFileServiceUrl, SyncServiceUrl,
+};
use notification::domain::service::{
NotificationReaderService, PlatformArnConfig, SqsNotificationIngress,
};
@@ -38,7 +42,6 @@ use notification::outbound::repository::DbNotificationRepository;
use notification::outbound::websocket::ConnectionGatewayClient;
use readonly_pool::ReadOnlyPool;
use search_service_client::SearchServiceClient;
-use secretsmanager_client::SecretManager;
use sqlx::postgres::PgPoolOptions;
use std::sync::Arc;
use stream::outbound::redis_pg::RedisPostgresStreamRepo;
@@ -55,9 +58,18 @@ mod service;
async fn main() -> anyhow::Result<()> {
MacroEntrypoint::default().init();
+ 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),
+ );
+
// Parse our configuration from the environment.
- let config = Config::from_env(EnvVars::unwrap_new())
- .context("failed to parse config from environment")?;
+ let config = Config::from_env()
+ .context("expected to be able to generate config")?
+ .resolve_remote_secrets(Environment::new_or_prod(), &secretsmanager_client)
+ .await
+ .context("expected to be able to resolve config secrets")?;
tracing::info!("initialized config");
@@ -80,7 +92,6 @@ async fn main() -> anyhow::Result<()> {
"initialized db connection"
);
- let aws_config = macro_aws_config::get_macro_aws_config().await;
let dynamodb_client = aws_sdk_dynamodb::Client::new(&aws_config);
let queue_aws_client = aws_sdk_sqs::Client::new(&aws_config);
@@ -91,41 +102,35 @@ async fn main() -> anyhow::Result<()> {
.search_event_queue(&config.search_event_queue)
.ai_projection_queue(&config.ai_projection_queue);
- let secretsmanager_client = secretsmanager_client::SecretsManager::new(
- aws_sdk_secretsmanager::Client::new(&aws_config),
- );
-
let internal_auth_key = secretsmanager_client::LocalOrRemoteSecret::Local(
InternalApiSecretKey::new().context("failed to create internal auth key")?,
);
let document_storage_client = DocumentStorageServiceClient::new(
- config.document_storage_service_auth_key.clone(),
- config.document_storage_service_url.clone(),
+ config
+ .document_storage_service_auth_key
+ .as_ref()
+ .to_string(),
+ DocumentStorageServiceUrl::new()?.to_string(),
);
tracing::info!("initialized dss client");
- let sync_service_auth_key = match config.environment {
- Environment::Local => config.sync_service_auth_key.clone(),
- _ => secretsmanager_client
- .get_secret_value(&config.sync_service_auth_key)
- .await
- .context("failed to get sync service auth key from secrets manager")?
- .to_string(),
- };
let sync_service_client = SyncServiceClient::new(
- sync_service_auth_key.clone(),
- config.sync_service_url.clone(),
+ config.sync_service_auth_key.as_ref().to_string(),
+ SyncServiceUrl::new()?.to_string(),
);
-
tracing::info!("initialized sync service client");
+
let search_service_client = SearchServiceClient::new(
- config.document_storage_service_auth_key.clone(),
- config.document_storage_service_url.clone(),
+ config
+ .document_storage_service_auth_key
+ .as_ref()
+ .to_string(),
+ DocumentStorageServiceUrl::new()?.to_string(),
);
-
tracing::info!("initialized search service client");
+
let jwt_args =
JwtValidationArgs::new_with_secret_manager(config.environment, &secretsmanager_client)
.await
@@ -133,12 +138,12 @@ async fn main() -> anyhow::Result<()> {
let lexical_client = Arc::new(lexical_client::LexicalClient::new(
internal_auth_key.as_ref().to_string(),
- config.lexical_service_url.clone(),
+ LexicalServiceUrl::new()?.to_string(),
));
let email_service_client = Arc::new(EmailServiceClient::new(
internal_auth_key.as_ref().to_string(),
- config.email_service_url.clone(),
+ EmailServiceUrl::new()?.to_string(),
));
tracing::info!("initialized static file service client");
@@ -169,12 +174,12 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("initialized connection repo");
let connection_gateway_client = Arc::new(ConnectionGatewayClient::new(
internal_auth_key.as_ref().to_string(),
- config.connection_gateway_url.clone(),
+ ConnectionGatewayUrl::new()?.to_string(),
));
let ingress_queue = SqsQueue::new(
aws_sdk_sqs::Client::new(&aws_config),
- config.notification_queue.clone(),
+ config.notification_queue.to_string(),
);
let notification_ingress_service = Arc::new(SqsNotificationIngress {
queue: ingress_queue,
@@ -182,7 +187,7 @@ async fn main() -> anyhow::Result<()> {
let notification_reader_queue = SqsQueue::new(
aws_sdk_sqs::Client::new(&aws_config),
- config.notification_queue.clone(),
+ config.notification_queue.to_string(),
);
let notification_reader_service = NotificationReaderService {
repository: DbNotificationRepository::new(db.clone()),
@@ -239,22 +244,22 @@ async fn main() -> anyhow::Result<()> {
let s3_client = macro_aws_config::s3_client().await;
let s3_upload_adapter = S3UploadUrlAdapter::new(
s3_client,
- config.document_storage_bucket.clone(),
- config.docx_document_upload_bucket.clone(),
+ config.document_storage_bucket.to_string(),
+ config.docx_document_upload_bucket.to_string(),
);
let document_repo = PgDocumentRepo::new(db.clone());
- let cloudfront_private_key = match config.environment {
- Environment::Local => config.cloudfront_signer_private_key.replace("\\n", "\n"),
- _ => secretsmanager_client
- .get_secret_value(&config.cloudfront_signer_private_key)
- .await
- .context("failed to get CloudFront signer private key from secrets manager")?
- .to_string(),
- };
+
let cloudfront_config = CloudFrontConfig {
- distribution_url: config.cloudfront_distribution_url.clone(),
- signer_public_key_id: config.cloudfront_signer_public_key_id.clone(),
- signer_private_key: cloudfront_private_key,
+ distribution_url: config
+ .document_storage_service_cloudfront_distribution_url
+ .to_string(),
+ signer_public_key_id: config
+ .document_storage_service_cloudfront_signer_public_key_id
+ .to_string(),
+ signer_private_key: config
+ .document_storage_service_cloudfront_signer_private_key
+ .as_ref()
+ .to_string(),
presigned_url_expiry_seconds: 3600,
browser_cache_expiry_seconds: 86400,
};
@@ -303,7 +308,7 @@ async fn main() -> anyhow::Result<()> {
entity_access_service.clone(),
),
static_file: static_file::inbound::attachment::StaticFileAttachmentService::new(Arc::new(
- static_file::outbound::CdnStaticFileRepo::new(config.static_file_service_url.clone()),
+ static_file::outbound::CdnStaticFileRepo::new(StaticFileServiceUrl::new()?.to_string()),
)),
};
let message_service = Arc::new(chat::domain::service::MessageServiceImpl::new(
@@ -434,7 +439,7 @@ async fn main() -> anyhow::Result<()> {
let ai_projection_worker = ai_projections::worker::AiProjectionWorker::new(
sqs_worker::SQSWorker::new(
aws_sdk_sqs::Client::new(&aws_config),
- config.ai_projection_queue.clone(),
+ config.ai_projection_queue.to_string(),
10,
10,
),
@@ -448,22 +453,15 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("initialized ai projections service");
- let mcp_credentials_key_b64 = match config.environment {
- Environment::Local => config.mcp_credentials_key_secret_name.clone(),
- _ => secretsmanager_client
- .get_secret_value(&config.mcp_credentials_key_secret_name)
- .await
- .context("failed to get MCP credentials key from secrets manager")?
- .to_string(),
- };
- let mcp_encryption_key =
- mcp_client::domain::models::AesKey::try_from(mcp_credentials_key_b64.as_str())
- .context("invalid MCP credentials encryption key")?;
+ let mcp_encryption_key = mcp_client::domain::models::AesKey::try_from(
+ config.mcp_credentials_key_secret_name.as_ref(),
+ )
+ .context("invalid MCP credentials encryption key")?;
let mcp_server_repo =
mcp_client::outbound::pg_server_repo::PgServerRepo::new(db.clone(), mcp_encryption_key);
let mcp_redirect_uri = format!(
"{}/mcp/servers/auth/callback",
- config.document_cognition_service_url
+ DocumentCognitionServiceUrl::new()?,
);
let mcp_oauth_state_store =
mcp_client::outbound::redis_state_store::RedisOAuthStateStore::new(redis_client.clone());