Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deploy-agent-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
PGPASSWORD=POSTGRES_PASSWORD:latest
CONTROL_PLANE_DB_CA_CERT=CONTROL_PLANE_DB_CA_CERT:latest
CONTROL_PLANE_JWT_SECRET=CONTROL_PLANE_JWT_SECRET:latest
STRIPE_API_KEY=STRIPE_API_KEY:latest

env_vars_update_strategy: overwrite
secrets_update_strategy: overwrite
7 changes: 7 additions & 0 deletions .github/workflows/platform-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ jobs:
- run: mise run build:flowctl-go
- run: mise run ci:nextest-build
- run: mise run ci:nextest-run

- name: Stripe integration test
env:
STRIPE_API_KEY: ${{ secrets.STRIPE_TESTMODE_API_KEY }}
if: env.STRIPE_API_KEY != ''
run: cargo nextest run --frozen --run-ignored ignored-only -E 'test(graphql_billing_live_stripe)'

- run: mise run ci:doctest
- run: mise run ci:gotest
- run: mise run ci:catalog-test
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ zeroize = { workspace = true }

[dev-dependencies]
assemble = { path = "../assemble" }
control-plane-api = { path = "../control-plane-api", features = ["test-support"] }
insta = { workspace = true }
md5 = { workspace = true }
tokio = { workspace = true }
Expand Down
34 changes: 2 additions & 32 deletions crates/agent/src/integration_tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,45 +541,14 @@ impl TestHarness {
/// storage_mappings, and tenants tables should all look just like they
/// would in production.
pub async fn setup_tenant(&self, tenant: &str) -> sqlx::types::Uuid {
let user_id = sqlx::types::Uuid::new_v4();
let email = format!("{tenant}@{}.test", self.test_name.replace(' ', "-"));

let meta = serde_json::json!({
"picture": format!("http://{tenant}.test/avatar"),
"full_name": format!("Full ({tenant}) Name"),
});

let mut txn = self.pool.begin().await.unwrap();
sqlx::query!(
r#"insert into auth.users(id, email, raw_user_meta_data) values ($1, $2, $3)"#,
user_id,
email.as_str(),
meta
)
.execute(&mut *txn)
.await
.expect("failed to create user");

control_plane_api::directives::beta_onboard::provision_tenant(
"support@estuary.dev",
Some(format!("for test: {}", self.test_name)),
tenant,
user_id,
&mut txn,
)
.await
.expect("failed to provision tenant");

// Remove the estuary_support/ role grant, which gets automatically
// added by a trigger whenever we create a new tenant. Removing it here
// ensures that things still work correctly without it.
sqlx::query!(r#"delete from role_grants where subject_role = 'estuary_support/';"#)
.execute(&mut *txn)
control_plane_api::test_support::provision_test_tenant(&self.pool, tenant, &email, meta)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to control_plane_api so it could be shared, rather than duplicating it.

.await
.expect("failed to remove estuary_support/ role");

txn.commit().await.expect("failed to commit transaction");
user_id
}

pub async fn add_role_grant(&mut self, subject: &str, object: &str, capability: Capability) {
Expand Down Expand Up @@ -1682,6 +1651,7 @@ impl TestHarness {

let app = Arc::new(control_plane_api::App::new(
id_gen,
None,
&jwt_secret,
self.pool.clone(),
self.publisher.clone(),
Expand Down
14 changes: 13 additions & 1 deletion crates/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ struct Args {
/// The port to listen on for API requests.
#[clap(long, default_value = "8080", env = "API_PORT")]
api_port: u16,
/// Stripe secret API key. When provided, the billing GraphQL queries and
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Option so that a Stripe API key is not required to run locally.

/// mutations that interact with Stripe are enabled. Without this, those
/// operations return an error indicating billing is not configured.
#[derivative(Debug = "ignore")]
#[clap(long = "stripe-api-key", env = "STRIPE_API_KEY")]
stripe_api_key: Option<String>,
/// Whether to serve job handlers within this agent instance.
#[clap(long = "serve-handlers", env = "SERVE_HANDLERS")]
serve_handlers: bool,
Expand Down Expand Up @@ -312,9 +318,15 @@ async fn async_main(args: Args) -> Result<(), anyhow::Error> {
args.controller_config,
);

// Wire up the agent's API Application and server.
let billing_provider: Option<Arc<dyn control_plane_api::billing::BillingProvider>> =
args.stripe_api_key.map(|api_key| {
Arc::new(control_plane_api::billing::StripeBillingProvider::new(
api_key,
)) as Arc<dyn control_plane_api::billing::BillingProvider>
});
let api_app = Arc::new(App::new(
agent::id_generator::with_random_shard(),
billing_provider,
jwt_secret.as_bytes(),
pg_pool.clone(),
publisher.clone(),
Expand Down
1 change: 1 addition & 0 deletions crates/billing-integrations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ license.workspace = true
[dependencies]
anyhow = { workspace = true }
async-stripe = { workspace = true }
billing-types = { path = "../billing-types" }
clap = { workspace = true }
chrono = { workspace = true }
comfy-table = { workspace = true }
Expand Down
Loading
Loading