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(contacts_service): macro config (#4046)

Will Hutchinson3ef6e93eb371
diff --git a/.github/workspace-dep-closures.json b/.github/workspace-dep-closures.json
index 10c2e1e3a4..3b20748af8 100644
--- a/.github/workspace-dep-closures.json
+++ b/.github/workspace-dep-closures.json
@@ -765,6 +765,8 @@
"item_filters",
"macro_auth",
"macro_aws_config",
+ "macro_config",
+ "macro_config_derive",
"macro_cors",
"macro_db_client",
"macro_entrypoint",
diff --git a/infra/stacks/contacts-service/Pulumi.dev.yaml b/infra/stacks/contacts-service/Pulumi.dev.yaml
index 93f41cf814..4dfd806daa 100644
--- a/infra/stacks/contacts-service/Pulumi.dev.yaml
+++ b/infra/stacks/contacts-service/Pulumi.dev.yaml
@@ -5,5 +5,4 @@ config:
contacts-service:fusionauth_issuer: fusionauth-dev.macro.com
contacts-service:jwt_secret_key: fusionauth-jwt-secret-dev
contacts-service:internal_api_key: document-storage-service-auth-key-dev
- contacts-service:macro_cache_secret_key: macro-cache-dev
- contacts-service:macro_db_secret_key: macro-db-dev
+ contacts-service:doppler_secret_sync_key: /doppler/contacts-service/dev
diff --git a/infra/stacks/contacts-service/Pulumi.prod.yaml b/infra/stacks/contacts-service/Pulumi.prod.yaml
index 83cb27a4b1..3c762b4ace 100644
--- a/infra/stacks/contacts-service/Pulumi.prod.yaml
+++ b/infra/stacks/contacts-service/Pulumi.prod.yaml
@@ -5,5 +5,4 @@ config:
contacts-service:fusionauth_issuer: auth.macro.com
contacts-service:jwt_secret_key: fusionauth-jwt-secret-prod
contacts-service:internal_api_key: document-storage-service-auth-key-prod
- contacts-service:macro_cache_secret_key: macro-cache-prod
- contacts-service:macro_db_secret_key: macro-db-prod
+ contacts-service:doppler_secret_sync_key: /doppler/contacts-service/prod
diff --git a/infra/stacks/contacts-service/index.ts b/infra/stacks/contacts-service/index.ts
index 13cda09ce7..0892362712 100644
--- a/infra/stacks/contacts-service/index.ts
+++ b/infra/stacks/contacts-service/index.ts
@@ -1,13 +1,7 @@
import * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
import { Queue } from '../../packages/resources';
-import {
- config,
- getMacroApiToken,
- getServiceUrl,
- ServiceUrl,
- stack,
-} from '../../packages/shared';
+import { config, getMacroApiToken, stack } from '../../packages/shared';
import { get_coparse_api_vpc } from '../../packages/vpc';
import { ContactsService } from './service';
@@ -26,31 +20,17 @@ export const contactsQueueName = contactsQueue.queue.name;
export const coparse_api_vpc = get_coparse_api_vpc();
-const DATABASE_URL = aws.secretsmanager
+const dopplerSecretSyncArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({
- secretId: config.require(`macro_db_secret_key`),
+ secretId: config.require('doppler_secret_sync_key'),
})
- .apply((secret) => secret.secretString);
-
-const MACRO_CACHE = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: config.require(`macro_cache_secret_key`),
- })
- .apply((secret) => secret.secretString);
+ .apply((secret) => secret.arn);
const JWT_SECRET_KEY = config.require(`jwt_secret_key`);
const jwtSecretKeyArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: JWT_SECRET_KEY })
.apply((secret) => secret.arn);
-const fusionauthClientIdSecretKey = config.require(`fusionauth_client_id`);
-
-const AUDIENCE = aws.secretsmanager
- .getSecretVersionOutput({
- secretId: fusionauthClientIdSecretKey,
- })
- .apply((secret) => secret.secretString);
-const ISSUER = config.require(`fusionauth_issuer`);
const INTERNAL_API_SECRET_KEY = config.require(`internal_api_key`);
const internalApiKeyArn: pulumi.Output<string> = aws.secretsmanager
.getSecretVersionOutput({ secretId: INTERNAL_API_SECRET_KEY })
@@ -65,54 +45,11 @@ const secretKeyArns = [
];
let containerEnvVars = [
- {
- name: 'RUST_LOG',
- value: `warn,contacts_service=${stack === 'prod' ? 'info' : 'debug'},contacts=${stack === 'prod' ? 'info' : 'debug'},contacts_db_client=${stack === 'prod' ? 'info' : 'debug'},tower_http=info`,
- },
{
name: 'ENVIRONMENT',
value: stack,
},
- {
- name: 'DATABASE_URL',
- value: pulumi.interpolate`${DATABASE_URL}`,
- },
- {
- name: 'CONTACTS_QUEUE',
- value: pulumi.interpolate`${contactsQueueName}`,
- },
- {
- name: 'REDIS_URI',
- value: pulumi.interpolate`redis://${MACRO_CACHE}`,
- },
- {
- name: 'JWT_SECRET_KEY',
- value: pulumi.interpolate`${JWT_SECRET_KEY}`,
- },
- {
- name: 'AUDIENCE',
- value: pulumi.interpolate`${AUDIENCE}`,
- },
- {
- name: 'ISSUER',
- value: pulumi.interpolate`${ISSUER}`,
- },
- {
- name: 'INTERNAL_API_SECRET_KEY',
- value: pulumi.interpolate`${INTERNAL_API_SECRET_KEY}`,
- },
- {
- 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: ServiceUrl.CONNECTION_GATEWAY_URL,
- value: getServiceUrl(ServiceUrl.CONNECTION_GATEWAY_URL),
- },
+ { name: 'DOPPLER_PROJECT', value: 'contacts_service' },
// OpenTelemetry / Datadog tracing configuration
{
name: 'DD_SERVICE',
@@ -148,6 +85,12 @@ const contactsService = new ContactsService('contacts-service', {
ecsClusterArn: cloudStorageClusterArn,
cloudStorageClusterName,
secretKeyArns,
+ containerSecrets: [
+ {
+ name: 'APP_SECRETS_JSON',
+ valueFrom: pulumi.interpolate`${dopplerSecretSyncArn}`,
+ },
+ ],
});
export const contactsServiceUrl = pulumi.interpolate`${contactsService.domain}`;
diff --git a/infra/stacks/contacts-service/service.ts b/infra/stacks/contacts-service/service.ts
index 0c72130db2..9216eb9411 100644
--- a/infra/stacks/contacts-service/service.ts
+++ b/infra/stacks/contacts-service/service.ts
@@ -38,10 +38,15 @@ type CreateContactsServiceArgs = {
ecsClusterArn: pulumi.Output<string> | string;
cloudStorageClusterName: pulumi.Output<string> | string;
secretKeyArns: (pulumi.Output<string> | string)[];
+ containerSecrets: {
+ name: string;
+ valueFrom: pulumi.Output<string> | string;
+ }[];
};
export class ContactsService extends pulumi.ComponentResource {
public role: aws.iam.Role;
+ public executionRole: aws.iam.Role;
public ecr: awsx.ecr.Repository;
public serviceAlbSg: aws.ec2.SecurityGroup;
public serviceSg: aws.ec2.SecurityGroup;
@@ -67,6 +72,7 @@ export class ContactsService extends pulumi.ComponentResource {
containerEnvVars,
cloudStorageClusterName,
secretKeyArns,
+ containerSecrets,
}: CreateContactsServiceArgs,
opts?: pulumi.ComponentResourceOptions
) {
@@ -140,6 +146,42 @@ export class ContactsService extends pulumi.ComponentResource {
{ parent: this }
);
+ const executionSecretsPolicy = new aws.iam.Policy(
+ `${BASE_NAME}-execution-secrets-policy`,
+ {
+ policy: {
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Action: ['secretsmanager:GetSecretValue'],
+ Resource: containerSecrets.map((s) => s.valueFrom),
+ Effect: 'Allow',
+ },
+ ],
+ },
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ const ecsTaskAssumeRolePolicy = aws.iam.assumeRolePolicyForPrincipal({
+ Service: 'ecs-tasks.amazonaws.com',
+ });
+
+ this.executionRole = new aws.iam.Role(
+ `${BASE_NAME}-execution-role`,
+ {
+ name: `${BASE_NAME}-execution-role-${stack}`,
+ assumeRolePolicy: ecsTaskAssumeRolePolicy,
+ tags: this.tags,
+ managedPolicyArns: [
+ 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy',
+ executionSecretsPolicy.arn,
+ ],
+ },
+ { parent: this }
+ );
+
// ecr image
const image = new EcrImage(
`${BASE_NAME}-ecr-image-${stack}`,
@@ -200,6 +242,9 @@ export class ContactsService extends pulumi.ComponentResource {
taskRole: {
roleArn: this.role.arn,
},
+ executionRole: {
+ roleArn: this.executionRole.arn,
+ },
containers: {
log_router: fargateLogRouterSidecarContainer,
datadog_agent: datadogAgentContainer,
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index b43571912f..f45e140097 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2601,9 +2601,11 @@ dependencies = [
"http-body-util",
"macro_auth",
"macro_aws_config",
+ "macro_config",
"macro_cors",
"macro_entrypoint",
"macro_env",
+ "macro_env_var",
"macro_middleware",
"macro_service_urls",
"macro_user_id",
diff --git a/rust/cloud-storage/contacts_service/Cargo.toml b/rust/cloud-storage/contacts_service/Cargo.toml
index 29892d3f1a..bac2698c29 100644
--- a/rust/cloud-storage/contacts_service/Cargo.toml
+++ b/rust/cloud-storage/contacts_service/Cargo.toml
@@ -42,6 +42,8 @@ utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
macro_service_urls = { path = "../macro_service_urls" }
workspace-hack = { version = "0.1", path = "../workspace-hack" }
+macro_env_var = { path = "../macro_env_var" }
+macro_config = { path = "../macro_config" }
[features]
mock = []
diff --git a/rust/cloud-storage/contacts_service/src/config.rs b/rust/cloud-storage/contacts_service/src/config.rs
index e84b7086d2..a0b6371899 100644
--- a/rust/cloud-storage/contacts_service/src/config.rs
+++ b/rust/cloud-storage/contacts_service/src/config.rs
@@ -1,65 +1,44 @@
use anyhow::Context;
pub use macro_env::Environment;
-use macro_service_urls::ConnectionGatewayUrl;
+use macro_env_var::{env_vars, maybe_env_vars};
+env_vars! {
+ pub struct BaseUrl;
+ pub struct DatabaseUrl;
+ pub struct RedisUri;
+ pub struct ContactsQueue;
+}
+
+maybe_env_vars! {
+ pub struct ContactsQueueMaxMessages;
+ pub struct ContactsQueueWaitTimeSeconds;
+}
+
+#[derive(macro_config::MacroConfig)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct Config {
/// port number of service
+ #[macro_config_default(8080)]
pub port: usize,
/// The environment we are in
+ #[macro_config_default(Environment::new_or_prod())]
pub environment: Environment,
/// The connection URL for the Postgres database this application should use.
- pub database_url: String,
+ pub database_url: DatabaseUrl,
/// The Redis URI for rate limiting.
- pub redis_uri: String,
+ pub redis_uri: RedisUri,
/// SQS URL
- pub queue_url: String,
+ pub contacts_queue: ContactsQueue,
/// The notification queue max messages per poll
- pub queue_max_messages: i32,
+ pub contacts_queue_max_messages: ContactsQueueMaxMessages,
/// The notification queue wait time seconds
- pub queue_wait_time_seconds: i32,
- /// Connection gateway URL for sending real-time notifications
- pub connection_gateway_url: Option<String>,
+ pub contacts_queue_wait_time_seconds: ContactsQueueWaitTimeSeconds,
}
impl Config {
pub fn from_env() -> anyhow::Result<Self> {
- let port: usize = std::env::var("PORT")
- .unwrap_or("8080".to_string())
- .parse::<usize>()
- .unwrap();
-
- let database_url =
- std::env::var("DATABASE_URL").context("DATABASE_URL must be provided")?;
-
- let redis_uri = std::env::var("REDIS_URI").context("REDIS_URI must be provided")?;
-
- let queue_url =
- std::env::var("CONTACTS_QUEUE").context("CONTACTS_QUEUE must be provided")?;
-
- let queue_max_messages: i32 = std::env::var("CONTACTS_QUEUE_MAX_MESSAGES")
- .unwrap_or("10".to_string())
- .parse::<i32>()
- .unwrap();
-
- let queue_wait_time_seconds: i32 = std::env::var("CONTACTS_QUEUE_WAIT_TIME_SECONDS")
- .unwrap_or("5".to_string())
- .parse::<i32>()
- .unwrap();
-
- let connection_gateway_url = Some(ConnectionGatewayUrl::new()?.to_string());
-
- let environment = Environment::new_or_prod();
-
- Ok(Config {
- port,
- environment,
- database_url,
- redis_uri,
- queue_url,
- queue_wait_time_seconds,
- queue_max_messages,
- connection_gateway_url,
- })
+ macro_config::ConfigLoader::load::<Config>()
+ .context("failed to load contacts service config")
}
#[cfg(test)]
@@ -68,12 +47,11 @@ impl Config {
Config {
port: 0,
environment: Environment::Local,
- database_url: "".to_string(),
- redis_uri: "".to_string(),
- queue_url: "".to_string(),
- queue_max_messages: 0,
- queue_wait_time_seconds: 0,
- connection_gateway_url: None,
+ database_url: DatabaseUrl::new_testing(""),
+ redis_uri: RedisUri::new_testing(""),
+ contacts_queue: ContactsQueue::new_testing(""),
+ contacts_queue_max_messages: ContactsQueueMaxMessages::new_unset(),
+ contacts_queue_wait_time_seconds: ContactsQueueWaitTimeSeconds::new_unset(),
}
}
}
diff --git a/rust/cloud-storage/contacts_service/src/main.rs b/rust/cloud-storage/contacts_service/src/main.rs
index 20380916af..c6a5a0bf2d 100644
--- a/rust/cloud-storage/contacts_service/src/main.rs
+++ b/rust/cloud-storage/contacts_service/src/main.rs
@@ -12,6 +12,7 @@ use contacts::outbound::gateway::ConnectionGatewayNotifier;
use contacts::outbound::repository::DbContactsRepository;
use macro_entrypoint::MacroEntrypoint;
use macro_middleware::auth::internal_access::InternalApiSecretKey;
+use macro_service_urls::ConnectionGatewayUrl;
use rate_limit::{RateLimitServiceImpl, RedisRateLimitAdapter};
use secretsmanager_client::SecretManager;
use sqlx::postgres::PgPoolOptions;
@@ -38,15 +39,23 @@ async fn connect_to_database(config: &Config) -> anyhow::Result<sqlx::PgPool> {
}
async fn create_sqs_worker(config: &Config) -> SQSWorker {
- let queue_url = config.queue_url.clone();
+ let queue_url = config.contacts_queue.to_string().clone();
let aws_config = macro_aws_config::get_macro_aws_config().await;
let sqs_client = aws_sdk_sqs::Client::new(&aws_config);
sqs_worker::SQSWorker::new(
sqs_client,
queue_url,
- config.queue_max_messages,
- config.queue_wait_time_seconds,
+ config
+ .contacts_queue_max_messages
+ .value()
+ .map(|p| p.parse::<i32>().expect("valid number"))
+ .unwrap_or(10),
+ config
+ .contacts_queue_wait_time_seconds
+ .value()
+ .map(|p| p.parse::<i32>().expect("valid number"))
+ .unwrap_or(10),
)
}
@@ -63,17 +72,17 @@ async fn main() -> anyhow::Result<()> {
aws_sdk_secretsmanager::Client::new(&macro_aws_config::get_macro_aws_config().await),
);
- let notifier = if let Some(url) = config.connection_gateway_url.as_ref() {
- let internal_api_secret = secretsmanager_client
- .get_maybe_secret_value(config.environment, InternalApiSecretKey::new()?)
- .await?;
- Some(
- ConnectionGatewayNotifier::new(internal_api_secret.as_ref().to_string(), url.clone())
- .unwrap(),
+ let internal_api_secret = secretsmanager_client
+ .get_maybe_secret_value(config.environment, InternalApiSecretKey::new()?)
+ .await?;
+
+ let notifier = Some(
+ ConnectionGatewayNotifier::new(
+ internal_api_secret.as_ref().to_string(),
+ ConnectionGatewayUrl::new()?.to_string(),
)
- } else {
- None
- };
+ .unwrap(),
+ );
let repository = DbContactsRepository::new(db.clone());
let outbox_repo = DbContactsRepository::new(db.clone());
@@ -103,8 +112,8 @@ async fn main() -> anyhow::Result<()> {
)
.await?;
- let redis_client =
- redis::Client::open(config.redis_uri.as_str()).context("failed to create redis client")?;
+ let redis_client = redis::Client::open(config.redis_uri.to_string().as_str())
+ .context("failed to create redis client")?;
let rate_limit_service = RateLimitServiceImpl {
repo: RedisRateLimitAdapter {
diff --git a/rust/cloud-storage/deny.toml b/rust/cloud-storage/deny.toml
index 0a2cb0a402..5aa1fbdf32 100644
--- a/rust/cloud-storage/deny.toml
+++ b/rust/cloud-storage/deny.toml
@@ -85,6 +85,8 @@ ignore = [
{ id = "RUSTSEC-2026-0105", reason = "core2 yanked/unmaintained, transitive via pdfium-render deps" },
{ id = "RUSTSEC-2026-0173", reason = "proc-macro-error2 is unmaintained; transitive dependency pending upstream migration" },
{ id = "RUSTSEC-2026-0174", reason = "http-types unmaintained, transitive via async-stripe; no safe upgrade available" },
+ { id = "RUSTSEC-2026-0179", reason = "postgres-protocol 0.6.11 is transitive via pgvector; database connections are to trusted infrastructure" },
+ { id = "RUSTSEC-2026-0180", reason = "postgres-protocol 0.6.11 is transitive via pgvector; database connections are to trusted infrastructure" },
#{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
#"[email protected]", # you can also ignore yanked crate versions if you wish
#{ crate = "[email protected]", reason = "you can specify why you are ignoring the yanked crate" },