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): sfs (#4238)

Will Hutchinson17366078172b
diff --git a/.github/workspace-dep-closures.json b/.github/workspace-dep-closures.json
index 55414bf316..742f6d01b8 100644
--- a/.github/workspace-dep-closures.json
+++ b/.github/workspace-dep-closures.json
@@ -3854,6 +3854,8 @@
"ip_extractor",
"macro_auth",
"macro_aws_config",
+ "macro_config",
+ "macro_config_derive",
"macro_cors",
"macro_db_client",
"macro_entrypoint",
diff --git a/infra/stacks/doppler-projects/index.ts b/infra/stacks/doppler-projects/index.ts
index d1543b0818..12ee6822cc 100644
--- a/infra/stacks/doppler-projects/index.ts
+++ b/infra/stacks/doppler-projects/index.ts
@@ -8,6 +8,7 @@ const SERVICE_NAMES = [
'cloud-storage-service',
'search-processing-service',
'unfurl-service',
+ 'static-file-service',
];
for (const service_name of SERVICE_NAMES) {
diff --git a/infra/stacks/static-file-service/index.ts b/infra/stacks/static-file-service/index.ts
index 78e163de88..c684090212 100644
--- a/infra/stacks/static-file-service/index.ts
+++ b/infra/stacks/static-file-service/index.ts
@@ -2,12 +2,7 @@ import * as aws from '@pulumi/aws';
import * as pulumi from '@pulumi/pulumi';
import { config, getMacroApiToken } from '../../packages/shared';
import { get_coparse_api_vpc } from '../../packages/vpc';
-import {
- SERVICE_NAME,
- SERVICE_URL,
- STATIC_FILE_BUCKET,
- StaticFileService,
-} from './static-file-service';
+import { SERVICE_NAME, StaticFileService } from './static-file-service';
const stack = pulumi.getStack();
@@ -41,15 +36,6 @@ const cloudStorageClusterName: pulumi.Output<string> = cloudStorageStack
.getOutput('cloudStorageClusterName')
.apply((arn) => arn as string);
-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 MACRO_API_TOKENS = getMacroApiToken();
const containerEnvVars = [
@@ -57,41 +43,6 @@ const containerEnvVars = [
name: 'ENVIRONMENT',
value: stack,
},
- {
- name: 'JWT_SECRET_KEY',
- value: pulumi.interpolate`${JWT_SECRET_KEY}`,
- },
- {
- name: 'AUDIENCE',
- value: pulumi.interpolate`${FUSIONAUTH_CLIENT_ID}`,
- },
-
- { name: 'ISSUER', value: pulumi.interpolate`${FUSIONAUTH_ISSUER}` },
-
- {
- name: 'STATIC_FILE_SERVICE_URL',
- value: pulumi.interpolate`${SERVICE_URL}`,
- },
- {
- name: 'STATIC_STORAGE_BUCKET',
- value: pulumi.interpolate`${STATIC_FILE_BUCKET}`,
- },
- {
- name: 'INTERNAL_API_SECRET_KEY',
- value: pulumi.interpolate`${INTERNAL_API_SECRET_KEY}`,
- },
- {
- name: 'RUST_LOG',
- value: `static_file_service=${stack === 'prod' ? 'error' : 'info'}`,
- },
- {
- 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}`,
- },
// OpenTelemetry / Datadog tracing configuration
{
name: 'DD_SERVICE',
diff --git a/infra/stacks/static-file-service/static-file-service.ts b/infra/stacks/static-file-service/static-file-service.ts
index a0f5e2a0f5..59251cb103 100644
--- a/infra/stacks/static-file-service/static-file-service.ts
+++ b/infra/stacks/static-file-service/static-file-service.ts
@@ -12,11 +12,16 @@ import {
serviceLoadBalancer,
} from '../../packages/resources';
import { EcrImage } from '../../packages/service';
-import { BASE_DOMAIN, MACRO_SUBDOMAIN_CERT } from '../../packages/shared';
+import {
+ BASE_DOMAIN,
+ MACRO_SUBDOMAIN_CERT,
+ DopplerEcsEnvironment,
+} from '../../packages/shared';
import { StaticFileCloudFront } from './distribution';
const stack = pulumi.getStack();
-export const SERVICE_NAME = 'static-file-service';
+export const BASE_NAME = pulumi.getProject();
+export const SERVICE_NAME = BASE_NAME;
export const SERVICE_DOMAIN_NAME = `static-file-service${stack === 'prod' ? '' : `-${stack}`}`;
export const SERVICE_URL = `https://${SERVICE_DOMAIN_NAME}.${BASE_DOMAIN}`;
export const STATIC_FILE_BUCKET = `static-file-storage-${stack}`;
@@ -526,6 +531,13 @@ export class StaticFileService extends pulumi.ComponentResource {
})
),
});
+
+ const dopplerEcsEnvironment = new DopplerEcsEnvironment(
+ BASE_NAME,
+ { tags: this.tags },
+ { parent: this }
+ );
+
// service
const service = new awsx.ecs.FargateService(
`${SERVICE_NAME}`,
@@ -544,6 +556,9 @@ export class StaticFileService extends pulumi.ComponentResource {
taskRole: {
roleArn: this.role.arn,
},
+ executionRole: {
+ roleArn: dopplerEcsEnvironment.executionRole.arn,
+ },
containers: {
log_router: fargateLogRouterSidecarContainer,
datadog_agent: datadogAgentContainer,
@@ -564,6 +579,7 @@ export class StaticFileService extends pulumi.ComponentResource {
},
...(args.containerEnvVars ?? []),
],
+ secrets: [...dopplerEcsEnvironment.containerSecrets],
logConfiguration: {
logDriver: 'awsfirelens',
options: {
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 1125d354ac..bf8aaa1764 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -11770,8 +11770,10 @@ dependencies = [
"aws-sdk-sqs",
"axum",
"chrono",
+ "doppler-config",
"macro_auth",
"macro_aws_config",
+ "macro_config",
"macro_cors",
"macro_entrypoint",
"macro_env",
diff --git a/rust/cloud-storage/static_file_service/Cargo.toml b/rust/cloud-storage/static_file_service/Cargo.toml
index e3b4f075fb..a304d7e982 100644
--- a/rust/cloud-storage/static_file_service/Cargo.toml
+++ b/rust/cloud-storage/static_file_service/Cargo.toml
@@ -12,6 +12,10 @@ path = "src/main.rs"
name = "static_file_service_openapi"
path = "src/openapi.rs"
+[[bin]]
+name = "static_file_service_doppler_config"
+path = "src/doppler_config.rs"
+
[features]
dynamodb_client_test = []
local_auth = []
@@ -25,9 +29,11 @@ aws-sdk-secretsmanager = { workspace = true }
aws-sdk-sqs.workspace = true
axum = { workspace = true, features = ["tower-log", "ws"] }
chrono = { workspace = true }
+doppler-config = { 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_entrypoint = { path = "../macro_entrypoint" }
macro_env = { path = "../macro_env" }
macro_env_var = { path = "../macro_env_var" }
diff --git a/rust/cloud-storage/static_file_service/src/api/event/poll.rs b/rust/cloud-storage/static_file_service/src/api/event/poll.rs
index 7c47e6b4ab..93bb2c6ba6 100644
--- a/rust/cloud-storage/static_file_service/src/api/event/poll.rs
+++ b/rust/cloud-storage/static_file_service/src/api/event/poll.rs
@@ -10,8 +10,15 @@ enum PollError {
// very important that long polling on the sqs queue is enabled
pub async fn poll_s3_events(context: AppState) {
loop {
- if let Err(PollError::PollingError) =
- poll(context.config.s3_event_queue_url.clone(), context.clone()).await
+ if let Err(PollError::PollingError) = poll(
+ context
+ .config
+ .static_file_service_s3_event_queue_url
+ .as_ref()
+ .to_owned(),
+ context.clone(),
+ )
+ .await
{
tokio::time::sleep(time::Duration::from_secs(20)).await;
}
diff --git a/rust/cloud-storage/static_file_service/src/api/file/put_presigned_url.rs b/rust/cloud-storage/static_file_service/src/api/file/put_presigned_url.rs
index f8a8b2f982..73c0f63b64 100644
--- a/rust/cloud-storage/static_file_service/src/api/file/put_presigned_url.rs
+++ b/rust/cloud-storage/static_file_service/src/api/file/put_presigned_url.rs
@@ -50,7 +50,7 @@ pub async fn put_presigned_url(
let id: String = Uuid::new_v4().to_string();
let static_file_key = s3_key::StaticFileKey::new(&id);
let s3_key = static_file_key.to_key();
- let permalink = format!("{}/{}", ctx.config.service_url, s3_key);
+ let permalink = format!("{}/{}", ctx.config.static_file_service_url, s3_key);
let owner_id = if !user.user_id.is_empty() {
user.user_id.clone()
diff --git a/rust/cloud-storage/static_file_service/src/api/mod.rs b/rust/cloud-storage/static_file_service/src/api/mod.rs
index 34aa1d2e74..f4a16b5754 100644
--- a/rust/cloud-storage/static_file_service/src/api/mod.rs
+++ b/rust/cloud-storage/static_file_service/src/api/mod.rs
@@ -31,11 +31,20 @@ pub async fn setup_and_serve(
let aws_config = macro_aws_config::get_macro_aws_config().await;
- let metadata_client = DynamodbClient::new(&aws_config, config.dynamodb_table.clone());
+ let metadata_client = DynamodbClient::new(
+ &aws_config,
+ config
+ .static_file_service_dynamodb_table_name
+ .as_ref()
+ .to_owned(),
+ );
let sqs_client = aws_sdk_sqs::Client::new(&aws_config);
let inner_client = macro_aws_config::s3_client().await;
- let storage_client = S3Client::new(inner_client, config.storage_bucket_name.clone());
+ let storage_client = S3Client::new(
+ inner_client,
+ config.static_storage_bucket.as_ref().to_owned(),
+ );
let state = AppState {
metadata_client,
diff --git a/rust/cloud-storage/static_file_service/src/config.rs b/rust/cloud-storage/static_file_service/src/config.rs
index 030f7ce669..651d1eb6fe 100644
--- a/rust/cloud-storage/static_file_service/src/config.rs
+++ b/rust/cloud-storage/static_file_service/src/config.rs
@@ -1,70 +1,41 @@
use anyhow::Context;
pub use macro_env::Environment;
-use macro_env_var::{env_vars, maybe_env_vars};
+use macro_env_var::env_vars;
+use macro_middleware::auth::internal_access::InternalApiSecretKey;
use macro_service_urls::StaticFileServiceUrl;
+use secretsmanager_client::LocalOrRemoteSecret;
env_vars! {
- struct StaticFileServiceDynamodbTableName;
- struct StaticStorageBucket;
- struct StaticFileServiceS3EventQueueUrl;
- struct InternalApiSecretKey;
+ pub struct StaticFileServiceDynamodbTableName;
+ pub struct StaticStorageBucket;
+ pub struct StaticFileServiceS3EventQueueUrl;
}
-maybe_env_vars! {
- struct Port;
-}
-
-#[derive(Debug, Clone)]
+#[derive(macro_config::MacroConfig)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct Config {
/// self explanatory
+ #[macro_config_default(Environment::new_or_prod())]
pub environment: Environment,
/// port (8080)
+ #[macro_config_default(8080)]
pub port: usize,
/// the tablename of the metadata table
- pub dynamodb_table: String,
+ pub static_file_service_dynamodb_table_name: StaticFileServiceDynamodbTableName,
/// s3 storage bucket
- pub storage_bucket_name: String,
+ pub static_storage_bucket: StaticStorageBucket,
/// service url
- pub service_url: String,
+ #[macro_config_default(StaticFileServiceUrl::unwrap_new().to_string())]
+ pub static_file_service_url: String,
/// s3 upload notification queue
- pub s3_event_queue_url: String,
+ pub static_file_service_s3_event_queue_url: StaticFileServiceS3EventQueueUrl,
/// Internal API secret key
- pub internal_api_secret_key: String,
+ pub internal_api_secret_key: LocalOrRemoteSecret<InternalApiSecretKey>,
}
impl Config {
pub fn from_env() -> anyhow::Result<Self> {
- let environment = Environment::new_or_prod();
- let port = Port::new()
- .map(|port| port.parse::<usize>().context("PORT must be a valid usize"))
- .transpose()?
- .unwrap_or(8080);
- let dynamodb_table = StaticFileServiceDynamodbTableName::new()
- .context("STATIC_FILE_SERVICE_DYNAMODB_TABLE_NAME must be provided")?
- .to_string();
-
- let storage_bucket_name = StaticStorageBucket::new()
- .context("STATIC_STORAGE_BUCKET must be provided")?
- .to_string();
-
- let service_url = StaticFileServiceUrl::new()?.to_string();
-
- let s3_event_queue_url = StaticFileServiceS3EventQueueUrl::new()
- .context("S3_EVENT_QUEUE_URL must be provided")?
- .to_string();
-
- let internal_api_secret_key = InternalApiSecretKey::new()
- .context("INTERNAL_API_SECRET_KEY must be provided")?
- .to_string();
-
- Ok(Config {
- environment,
- port,
- dynamodb_table,
- storage_bucket_name,
- service_url,
- s3_event_queue_url,
- internal_api_secret_key,
- })
+ macro_config::ConfigLoader::load::<Config>()
+ .context("failed to load static file service config")
}
}
diff --git a/rust/cloud-storage/static_file_service/src/doppler_config.rs b/rust/cloud-storage/static_file_service/src/doppler_config.rs
new file mode 100644
index 0000000000..07467760cf
--- /dev/null
+++ b/rust/cloud-storage/static_file_service/src/doppler_config.rs
@@ -0,0 +1,31 @@
+#![allow(unused)]
+#![recursion_limit = "256"]
+
+use macro_env::Environment;
+
+mod config;
+
+const DOPPLER_PROJECT: &str = "static-file-service";
+
+#[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/static_file_service/src/main.rs b/rust/cloud-storage/static_file_service/src/main.rs
index d8f39bfa62..7ed19e71bb 100644
--- a/rust/cloud-storage/static_file_service/src/main.rs
+++ b/rust/cloud-storage/static_file_service/src/main.rs
@@ -2,8 +2,6 @@
use anyhow::Context;
use macro_auth::middleware::decode_jwt::JwtValidationArgs;
use macro_entrypoint::MacroEntrypoint;
-use macro_middleware::auth::internal_access::InternalApiSecretKey;
-use secretsmanager_client::SecretManager;
mod api;
mod config;
@@ -21,9 +19,12 @@ async fn main() -> anyhow::Result<()> {
aws_sdk_secretsmanager::Client::new(&aws_config),
);
- let internal_api_secret = secretsmanager_client
- .get_maybe_secret_value(config.environment, InternalApiSecretKey::new()?)
- .await?;
+ let environment = config.environment;
+ let config = config
+ .resolve_remote_secrets(environment, &secretsmanager_client)
+ .await
+ .context("failed to resolve config secrets")?;
+ let internal_api_secret = config.internal_api_secret_key.clone();
let jwt_validation_args =
JwtValidationArgs::new_with_secret_manager(config.environment, &secretsmanager_client)