From 85e3676056c232e999aa4f07fb5310500079b6fe Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Tue, 30 Apr 2024 12:44:30 +0530 Subject: [PATCH 01/24] feat(multitenancy): add logical sepration of tenant using db schema --- .vscode/launch.json | 1103 +++++++++++++++++ config/development.toml | 3 + crates/analytics/src/api_event/core.rs | 4 +- crates/analytics/src/lib.rs | 2 +- crates/analytics/src/payments/core.rs | 2 +- crates/analytics/src/sdk_events/core.rs | 4 +- .../src/query/connector_response.rs | 6 +- .../src/query/process_tracker.rs | 14 +- crates/drainer/src/handler.rs | 4 +- crates/drainer/src/health_check.rs | 6 +- crates/drainer/src/stream.rs | 2 +- crates/redis_interface/src/commands.rs | 66 +- crates/router/src/bin/scheduler.rs | 95 +- .../src/compatibility/stripe/customers.rs | 12 +- .../compatibility/stripe/payment_intents.rs | 21 +- .../src/compatibility/stripe/refunds.rs | 8 +- .../src/compatibility/stripe/setup_intents.rs | 8 +- crates/router/src/compatibility/wrap.rs | 9 +- .../src/configs/secrets_transformers.rs | 1 + crates/router/src/configs/settings.rs | 6 + crates/router/src/connector/adyen.rs | 10 +- crates/router/src/connector/airwallex.rs | 2 +- crates/router/src/connector/nuvei.rs | 2 +- crates/router/src/connector/shift4.rs | 2 +- crates/router/src/connector/square.rs | 2 +- crates/router/src/connector/stripe.rs | 10 +- crates/router/src/connector/wise.rs | 12 +- crates/router/src/core/admin.rs | 41 +- crates/router/src/core/api_keys.rs | 28 +- crates/router/src/core/api_locking.rs | 13 +- crates/router/src/core/authentication.rs | 8 +- .../router/src/core/authentication/utils.rs | 8 +- crates/router/src/core/blocklist.rs | 10 +- .../router/src/core/blocklist/transformers.rs | 8 +- crates/router/src/core/blocklist/utils.rs | 20 +- crates/router/src/core/cache.rs | 4 +- crates/router/src/core/cards_info.rs | 4 +- crates/router/src/core/conditional_config.rs | 8 +- crates/router/src/core/configs.rs | 10 +- .../router/src/core/connector_onboarding.rs | 10 +- .../src/core/connector_onboarding/paypal.rs | 16 +- crates/router/src/core/currency.rs | 7 +- crates/router/src/core/customers.rs | 22 +- crates/router/src/core/disputes.rs | 26 +- .../router/src/core/disputes/transformers.rs | 8 +- crates/router/src/core/files.rs | 8 +- crates/router/src/core/files/helpers.rs | 12 +- crates/router/src/core/fraud_check.rs | 22 +- crates/router/src/core/fraud_check/flows.rs | 4 +- .../core/fraud_check/flows/checkout_flow.rs | 8 +- .../fraud_check/flows/fulfillment_flow.rs | 6 +- .../core/fraud_check/flows/record_return.rs | 8 +- .../src/core/fraud_check/flows/sale_flow.rs | 8 +- .../fraud_check/flows/transaction_flow.rs | 8 +- .../router/src/core/fraud_check/operation.rs | 10 +- .../fraud_check/operation/fraud_check_post.rs | 18 +- .../fraud_check/operation/fraud_check_pre.rs | 12 +- crates/router/src/core/gsm.rs | 18 +- crates/router/src/core/health_check.rs | 2 +- crates/router/src/core/locker_migration.rs | 8 +- crates/router/src/core/mandate.rs | 24 +- crates/router/src/core/mandate/helpers.rs | 4 +- crates/router/src/core/payment_link.rs | 10 +- crates/router/src/core/payment_methods.rs | 10 +- .../router/src/core/payment_methods/cards.rs | 88 +- .../surcharge_decision_configs.rs | 12 +- .../router/src/core/payment_methods/vault.rs | 37 +- crates/router/src/core/payments.rs | 80 +- .../router/src/core/payments/access_token.rs | 6 +- .../src/core/payments/conditional_configs.rs | 12 +- crates/router/src/core/payments/customers.rs | 10 +- crates/router/src/core/payments/flows.rs | 16 +- .../src/core/payments/flows/approve_flow.rs | 10 +- .../src/core/payments/flows/authorize_flow.rs | 18 +- .../src/core/payments/flows/cancel_flow.rs | 10 +- .../src/core/payments/flows/capture_flow.rs | 10 +- .../payments/flows/complete_authorize_flow.rs | 16 +- .../flows/incremental_authorization_flow.rs | 10 +- .../src/core/payments/flows/psync_flow.rs | 12 +- .../src/core/payments/flows/reject_flow.rs | 10 +- .../src/core/payments/flows/session_flow.rs | 19 +- .../core/payments/flows/setup_mandate_flow.rs | 18 +- crates/router/src/core/payments/helpers.rs | 80 +- crates/router/src/core/payments/operations.rs | 70 +- .../payments/operations/payment_approve.rs | 12 +- .../payments/operations/payment_cancel.rs | 12 +- .../payments/operations/payment_capture.rs | 12 +- .../operations/payment_complete_authorize.rs | 28 +- .../payments/operations/payment_confirm.rs | 36 +- .../payments/operations/payment_create.rs | 41 +- .../payments/operations/payment_reject.rs | 12 +- .../payments/operations/payment_response.rs | 28 +- .../payments/operations/payment_session.rs | 24 +- .../core/payments/operations/payment_start.rs | 24 +- .../payments/operations/payment_status.rs | 26 +- .../payments/operations/payment_update.rs | 28 +- .../payments_incremental_authorization.rs | 24 +- crates/router/src/core/payments/retry.rs | 28 +- crates/router/src/core/payments/routing.rs | 24 +- .../router/src/core/payments/tokenization.rs | 10 +- .../router/src/core/payments/transformers.rs | 10 +- crates/router/src/core/payments/types.rs | 10 +- crates/router/src/core/payouts.rs | 52 +- crates/router/src/core/payouts/helpers.rs | 16 +- crates/router/src/core/payouts/retry.rs | 26 +- crates/router/src/core/payouts/validator.rs | 6 +- crates/router/src/core/pm_auth.rs | 23 +- crates/router/src/core/refunds.rs | 58 +- crates/router/src/core/refunds/validator.rs | 8 +- crates/router/src/core/routing.rs | 24 +- .../src/core/surcharge_decision_config.rs | 8 +- crates/router/src/core/user.rs | 61 +- .../src/core/user/dashboard_metadata.rs | 14 +- crates/router/src/core/user/sample_data.rs | 6 +- crates/router/src/core/user_role.rs | 14 +- crates/router/src/core/user_role/role.rs | 18 +- crates/router/src/core/utils.rs | 34 +- crates/router/src/core/verification.rs | 11 +- crates/router/src/core/verification/utils.rs | 4 +- crates/router/src/core/verify_connector.rs | 4 +- crates/router/src/core/webhooks.rs | 50 +- .../src/core/webhooks/webhook_events.rs | 16 +- crates/router/src/db/address.rs | 28 +- crates/router/src/db/api_keys.rs | 12 +- crates/router/src/db/authentication.rs | 6 +- crates/router/src/db/authorization.rs | 6 +- crates/router/src/db/blocklist.rs | 22 +- crates/router/src/db/blocklist_fingerprint.rs | 8 +- crates/router/src/db/blocklist_lookup.rs | 14 +- crates/router/src/db/business_profile.rs | 12 +- crates/router/src/db/cache.rs | 12 +- crates/router/src/db/capture.rs | 14 +- crates/router/src/db/cards_info.rs | 4 +- crates/router/src/db/configs.rs | 16 +- crates/router/src/db/customers.rs | 26 +- crates/router/src/db/dashboard_metadata.rs | 12 +- crates/router/src/db/dispute.rs | 12 +- crates/router/src/db/ephemeral_key.rs | 4 +- crates/router/src/db/events.rs | 18 +- crates/router/src/db/file.rs | 8 +- crates/router/src/db/fraud_check.rs | 14 +- crates/router/src/db/gsm.rs | 10 +- crates/router/src/db/health_check.rs | 2 +- crates/router/src/db/locker_mock_up.rs | 6 +- crates/router/src/db/mandate.rs | 12 +- crates/router/src/db/merchant_account.rs | 16 +- .../src/db/merchant_connector_account.rs | 20 +- crates/router/src/db/merchant_key_store.rs | 8 +- crates/router/src/db/organization.rs | 6 +- crates/router/src/db/payment_link.rs | 6 +- crates/router/src/db/payment_method.rs | 28 +- crates/router/src/db/refund.rs | 40 +- crates/router/src/db/reverse_lookup.rs | 8 +- crates/router/src/db/role.rs | 12 +- crates/router/src/db/routing_algorithm.rs | 12 +- crates/router/src/db/user.rs | 14 +- crates/router/src/db/user_role.rs | 16 +- crates/router/src/lib.rs | 2 +- crates/router/src/routes.rs | 3 +- crates/router/src/routes/admin.rs | 34 +- crates/router/src/routes/api_keys.rs | 10 +- crates/router/src/routes/app.rs | 137 +- crates/router/src/routes/cache.rs | 2 +- crates/router/src/routes/cards_info.rs | 2 +- crates/router/src/routes/configs.rs | 8 +- crates/router/src/routes/customers.rs | 14 +- crates/router/src/routes/disputes.rs | 14 +- crates/router/src/routes/dummy_connector.rs | 12 +- .../router/src/routes/dummy_connector/core.rs | 14 +- .../src/routes/dummy_connector/utils.rs | 13 +- crates/router/src/routes/ephemeral_key.rs | 4 +- crates/router/src/routes/files.rs | 6 +- crates/router/src/routes/gsm.rs | 8 +- crates/router/src/routes/health.rs | 8 +- crates/router/src/routes/mandates.rs | 6 +- crates/router/src/routes/payment_link.rs | 4 +- crates/router/src/routes/payment_methods.rs | 56 +- crates/router/src/routes/payments.rs | 50 +- crates/router/src/routes/payouts.rs | 18 +- crates/router/src/routes/pm_auth.rs | 4 +- crates/router/src/routes/recon.rs | 10 +- crates/router/src/routes/refunds.rs | 12 +- crates/router/src/routes/routing.rs | 34 +- crates/router/src/routes/verification.rs | 4 +- crates/router/src/routes/verify_connector.rs | 2 +- crates/router/src/routes/webhook_events.rs | 6 +- crates/router/src/routes/webhooks.rs | 2 +- crates/router/src/services.rs | 31 +- crates/router/src/services/api.rs | 86 +- crates/router/src/services/api/client.rs | 8 +- crates/router/src/services/api/request.rs | 2 +- crates/router/src/services/authentication.rs | 93 +- .../src/services/authentication/blacklist.rs | 26 +- crates/router/src/services/authorization.rs | 12 +- .../src/services/authorization/roles.rs | 4 +- crates/router/src/services/email/types.rs | 4 +- crates/router/src/services/pm_auth.rs | 4 +- crates/router/src/types/api/mandates.rs | 6 +- .../router/src/types/api/verify_connector.rs | 6 +- .../src/types/api/verify_connector/paypal.rs | 4 +- crates/router/src/types/api/webhooks.rs | 2 +- crates/router/src/types/domain/types.rs | 12 +- crates/router/src/types/domain/user.rs | 37 +- .../src/types/storage/payment_attempt.rs | 27 +- crates/router/src/utils.rs | 2 +- .../router/src/utils/connector_onboarding.rs | 8 +- .../src/utils/connector_onboarding/paypal.rs | 4 +- crates/router/src/utils/currency.rs | 41 +- crates/router/src/utils/user.rs | 18 +- .../src/utils/user/dashboard_metadata.rs | 14 +- crates/router/src/utils/user/sample_data.rs | 4 +- crates/router/src/utils/user_role.rs | 10 +- crates/router/src/workflows/api_key_expiry.rs | 10 +- .../src/workflows/outgoing_webhook_retry.rs | 20 +- crates/router/src/workflows/payment_sync.rs | 12 +- crates/router/src/workflows/refund_router.rs | 8 +- crates/router/src/workflows/tokenized_data.rs | 8 +- crates/router/tests/connectors/aci.rs | 2 +- crates/router/tests/connectors/utils.rs | 3 +- .../tests/test_module/some_module.rs | 4 +- crates/scheduler/src/consumer.rs | 46 +- crates/scheduler/src/producer.rs | 31 +- crates/scheduler/src/scheduler.rs | 32 +- crates/scheduler/src/utils.rs | 2 +- crates/storage_impl/src/database/store.rs | 19 +- crates/storage_impl/src/lib.rs | 43 +- .../src/payments/payment_attempt.rs | 52 +- .../src/payments/payment_intent.rs | 20 +- .../src/payouts/payout_attempt.rs | 16 +- crates/storage_impl/src/payouts/payouts.rs | 28 +- 230 files changed, 3204 insertions(+), 1833 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000000..ca8e7b50cd9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,1103 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'analytics'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=analytics" + ], + "filter": { + "name": "analytics", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'analytics'", + "cargo": { + "args": [ + "build", + "--bin=analytics", + "--package=analytics" + ], + "filter": { + "name": "analytics", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'analytics'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=analytics", + "--package=analytics" + ], + "filter": { + "name": "analytics", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'api_models'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=api_models" + ], + "filter": { + "name": "api_models", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'cards'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=cards" + ], + "filter": { + "name": "cards", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'basic'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=basic", + "--package=cards" + ], + "filter": { + "name": "basic", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'common_utils'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=common_utils" + ], + "filter": { + "name": "common_utils", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'percentage'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=percentage", + "--package=common_utils" + ], + "filter": { + "name": "percentage", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'common_enums'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=common_enums" + ], + "filter": { + "name": "common_enums", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'masking'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=masking" + ], + "filter": { + "name": "masking", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'basic'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=basic", + "--package=masking" + ], + "filter": { + "name": "basic", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'router_env'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=router_env" + ], + "filter": { + "name": "router_env", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'logger'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=logger", + "--package=router_env" + ], + "filter": { + "name": "logger", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'env'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=env", + "--package=router_env" + ], + "filter": { + "name": "env", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'euclid'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=euclid" + ], + "filter": { + "name": "euclid", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug benchmark 'backends'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bench=backends", + "--package=euclid" + ], + "filter": { + "name": "backends", + "kind": "bench" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'diesel_models'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=diesel_models" + ], + "filter": { + "name": "diesel_models", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'external_services'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=external_services" + ], + "filter": { + "name": "external_services", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'hyperswitch_interfaces'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=hyperswitch_interfaces" + ], + "filter": { + "name": "hyperswitch_interfaces", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'storage_impl'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=storage_impl" + ], + "filter": { + "name": "storage_impl", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'data_models'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=data_models" + ], + "filter": { + "name": "data_models", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'redis_interface'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=redis_interface" + ], + "filter": { + "name": "redis_interface", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'config_importer'", + "cargo": { + "args": [ + "build", + "--bin=config_importer", + "--package=config_importer" + ], + "filter": { + "name": "config_importer", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'config_importer'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=config_importer", + "--package=config_importer" + ], + "filter": { + "name": "config_importer", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'connector_configs'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=connector_configs" + ], + "filter": { + "name": "connector_configs", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'currency_conversion'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=currency_conversion" + ], + "filter": { + "name": "currency_conversion", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'drainer'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=drainer" + ], + "filter": { + "name": "drainer", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'drainer'", + "cargo": { + "args": [ + "build", + "--bin=drainer", + "--package=drainer" + ], + "filter": { + "name": "drainer", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'drainer'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=drainer", + "--package=drainer" + ], + "filter": { + "name": "drainer", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'kgraph_utils'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=kgraph_utils" + ], + "filter": { + "name": "kgraph_utils", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug benchmark 'evaluation'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bench=evaluation", + "--package=kgraph_utils" + ], + "filter": { + "name": "evaluation", + "kind": "bench" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'events'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=events" + ], + "filter": { + "name": "events", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'openapi'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=openapi" + ], + "filter": { + "name": "openapi", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'openapi'", + "cargo": { + "args": [ + "build", + "--bin=openapi", + "--package=openapi" + ], + "filter": { + "name": "openapi", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'openapi'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=openapi", + "--package=openapi" + ], + "filter": { + "name": "openapi", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'pm_auth'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=pm_auth" + ], + "filter": { + "name": "pm_auth", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'router'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=router" + ], + "filter": { + "name": "router", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'router'", + "cargo": { + "args": [ + "build", + "--bin=router", + "--package=router" + ], + "filter": { + "name": "router", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'router'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=router", + "--package=router" + ], + "filter": { + "name": "router", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'scheduler'", + "cargo": { + "args": [ + "build", + "--bin=scheduler", + "--package=router" + ], + "filter": { + "name": "scheduler", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'scheduler'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=scheduler", + "--package=router" + ], + "filter": { + "name": "scheduler", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'connectors'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=connectors", + "--package=router" + ], + "filter": { + "name": "connectors", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'cache'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=cache", + "--package=router" + ], + "filter": { + "name": "cache", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'integration_demo'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=integration_demo", + "--package=router" + ], + "filter": { + "name": "integration_demo", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'refunds'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=refunds", + "--package=router" + ], + "filter": { + "name": "refunds", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'payouts'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=payouts", + "--package=router" + ], + "filter": { + "name": "payouts", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'payments'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=payments", + "--package=router" + ], + "filter": { + "name": "payments", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'services'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=services", + "--package=router" + ], + "filter": { + "name": "services", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'webhooks'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=webhooks", + "--package=router" + ], + "filter": { + "name": "webhooks", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'customers'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=customers", + "--package=router" + ], + "filter": { + "name": "customers", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'payments2'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=payments2", + "--package=router" + ], + "filter": { + "name": "payments2", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'health_check'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=health_check", + "--package=router" + ], + "filter": { + "name": "health_check", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'utils'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=utils", + "--package=router" + ], + "filter": { + "name": "utils", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'scheduler'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=scheduler" + ], + "filter": { + "name": "scheduler", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'test_utils'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=test_utils" + ], + "filter": { + "name": "test_utils", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'test_utils'", + "cargo": { + "args": [ + "build", + "--bin=test_utils", + "--package=test_utils" + ], + "filter": { + "name": "test_utils", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'test_utils'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=test_utils", + "--package=test_utils" + ], + "filter": { + "name": "test_utils", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug integration test 'connectors'", + "cargo": { + "args": [ + "test", + "--no-run", + "--test=connectors", + "--package=test_utils" + ], + "filter": { + "name": "connectors", + "kind": "test" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/config/development.toml b/config/development.toml index 5e9abe1974b..6246fb7fe7c 100644 --- a/config/development.toml +++ b/config/development.toml @@ -613,3 +613,6 @@ payment_attempts = "hyperswitch-payment-attempt-events" payment_intents = "hyperswitch-payment-intent-events" refunds = "hyperswitch-refund-events" disputes = "hyperswitch-dispute-events" + +[multitenancy] +tenants = ["public", "zurich"] \ No newline at end of file diff --git a/crates/analytics/src/api_event/core.rs b/crates/analytics/src/api_event/core.rs index 7225a6322d4..bce24219421 100644 --- a/crates/analytics/src/api_event/core.rs +++ b/crates/analytics/src/api_event/core.rs @@ -26,7 +26,7 @@ use crate::{ AnalyticsProvider, }; -#[instrument(skip_all)] +////#\[instrument\(skip_all)] pub async fn api_events_core( pool: &AnalyticsProvider, req: ApiLogsRequest, @@ -88,7 +88,7 @@ pub async fn get_filters( Ok(res) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_api_event_metrics( pool: &AnalyticsProvider, merchant_id: &str, diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rs index eb08d8549d1..caf8dc632a6 100644 --- a/crates/analytics/src/lib.rs +++ b/crates/analytics/src/lib.rs @@ -89,7 +89,7 @@ impl ToString for AnalyticsProvider { } impl AnalyticsProvider { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn get_payment_metrics( &self, metric: &PaymentMetrics, diff --git a/crates/analytics/src/payments/core.rs b/crates/analytics/src/payments/core.rs index debc03fc9d5..6ce0eede47d 100644 --- a/crates/analytics/src/payments/core.rs +++ b/crates/analytics/src/payments/core.rs @@ -41,7 +41,7 @@ pub enum TaskType { ), } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_metrics( pool: &AnalyticsProvider, merchant_id: &str, diff --git a/crates/analytics/src/sdk_events/core.rs b/crates/analytics/src/sdk_events/core.rs index 2ffc7f1aed6..d140f4fdb1a 100644 --- a/crates/analytics/src/sdk_events/core.rs +++ b/crates/analytics/src/sdk_events/core.rs @@ -22,7 +22,7 @@ use crate::{ AnalyticsProvider, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn sdk_events_core( pool: &AnalyticsProvider, req: SdkEventsRequest, @@ -42,7 +42,7 @@ pub async fn sdk_events_core( .switch() } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_metrics( pool: &AnalyticsProvider, publishable_key: Option<&String>, diff --git a/crates/diesel_models/src/query/connector_response.rs b/crates/diesel_models/src/query/connector_response.rs index 952db945ae3..1401ea39276 100644 --- a/crates/diesel_models/src/query/connector_response.rs +++ b/crates/diesel_models/src/query/connector_response.rs @@ -14,7 +14,7 @@ use crate::{ }; impl ConnectorResponseNew { - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn insert(self, conn: &PgPooledConn) -> StorageResult { let payment_attempt_update = PaymentAttemptUpdate::ConnectorResponse { authentication_data: self.authentication_data.clone(), @@ -51,7 +51,7 @@ impl ConnectorResponseNew { } impl ConnectorResponse { - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn update( self, conn: &PgPooledConn, @@ -131,7 +131,7 @@ impl ConnectorResponse { connector_response_result } - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn find_by_payment_id_merchant_id_attempt_id( conn: &PgPooledConn, payment_id: &str, diff --git a/crates/diesel_models/src/query/process_tracker.rs b/crates/diesel_models/src/query/process_tracker.rs index 74f23ac0bf7..d5cb2e488d1 100644 --- a/crates/diesel_models/src/query/process_tracker.rs +++ b/crates/diesel_models/src/query/process_tracker.rs @@ -13,14 +13,14 @@ use crate::{ }; impl ProcessTrackerNew { - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn insert_process(self, conn: &PgPooledConn) -> StorageResult { generics::generic_insert(conn, self).await } } impl ProcessTracker { - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn update( self, conn: &PgPooledConn, @@ -41,7 +41,7 @@ impl ProcessTracker { } } - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn update_process_status_by_ids( conn: &PgPooledConn, task_ids: Vec, @@ -55,7 +55,7 @@ impl ProcessTracker { .await } - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn find_process_by_id(conn: &PgPooledConn, id: &str) -> StorageResult> { generics::generic_find_by_id_optional::<::Table, _, _>( conn, @@ -64,7 +64,7 @@ impl ProcessTracker { .await } - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn find_processes_by_time_status( conn: &PgPooledConn, time_lower_limit: PrimitiveDateTime, @@ -89,7 +89,7 @@ impl ProcessTracker { .await } - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn find_processes_to_clean( conn: &PgPooledConn, time_lower_limit: PrimitiveDateTime, @@ -118,7 +118,7 @@ impl ProcessTracker { Ok(x) } - #[instrument(skip(conn))] + //#\[instrument\(skip(conn))] pub async fn reinitialize_limbo_processes( conn: &PgPooledConn, ids: Vec, diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs index 47b60db80d5..6c02cbaf951 100644 --- a/crates/drainer/src/handler.rs +++ b/crates/drainer/src/handler.rs @@ -145,7 +145,7 @@ pub async fn redis_error_receiver(rx: oneshot::Receiver<()>, shutdown_channel: m } } -#[router_env::instrument(skip_all)] +//#[router_env::instrument(skip_all)] async fn drainer_handler( store: Arc, stream_index: u8, @@ -179,7 +179,7 @@ async fn drainer_handler( }) } -#[instrument(skip_all, fields(global_id, request_id, session_id))] +//#\[instrument\(skip_all, fields(global_id, request_id, session_id))] async fn drainer( store: Arc, max_read_count: u64, diff --git a/crates/drainer/src/health_check.rs b/crates/drainer/src/health_check.rs index 443cb5b6f3f..a92c9fe3169 100644 --- a/crates/drainer/src/health_check.rs +++ b/crates/drainer/src/health_check.rs @@ -29,13 +29,13 @@ impl Health { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn health() -> impl actix_web::Responder { logger::info!("Drainer health was called"); actix_web::HttpResponse::Ok().body("Drainer health is good") } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn deep_health_check( conf: web::Data, store: web::Data>, @@ -53,7 +53,7 @@ pub async fn deep_health_check( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn deep_health_check_func( conf: web::Data, store: web::Data>, diff --git a/crates/drainer/src/stream.rs b/crates/drainer/src/stream.rs index 319fc2b0e1d..5e562a55177 100644 --- a/crates/drainer/src/stream.rs +++ b/crates/drainer/src/stream.rs @@ -25,7 +25,7 @@ impl Store { self.drainer_stream(format!("shard_{stream_index}").as_str()) } - #[router_env::instrument(skip_all)] + //#[router_env::instrument(skip_all)] pub async fn is_stream_available(&self, stream_index: u8) -> bool { let stream_key_flag = self.get_stream_key_flag(stream_index); diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index d9b7072ff8c..c191cf58d76 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -31,7 +31,7 @@ use crate::{ }; impl super::RedisConnectionPool { - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_key(&self, key: &str, value: V) -> CustomResult<(), errors::RedisError> where V: TryInto + Debug + Send + Sync, @@ -63,7 +63,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn serialize_and_set_key_if_not_exist( &self, key: &str, @@ -80,7 +80,7 @@ impl super::RedisConnectionPool { .await } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn serialize_and_set_key( &self, key: &str, @@ -96,7 +96,7 @@ impl super::RedisConnectionPool { self.set_key(key, serialized.as_slice()).await } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn serialize_and_set_key_with_expiry( &self, key: &str, @@ -122,7 +122,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetExFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn get_key(&self, key: &str) -> CustomResult where V: FromRedis + Unpin + Send + 'static, @@ -133,7 +133,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::GetFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn exists(&self, key: &str) -> CustomResult where V: Into + Unpin + Send + 'static, @@ -144,7 +144,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::GetFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn get_and_deserialize_key( &self, key: &str, @@ -162,7 +162,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::JsonDeserializationFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn delete_key(&self, key: &str) -> CustomResult { self.pool .del(key) @@ -170,7 +170,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::DeleteFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_key_with_expiry( &self, key: &str, @@ -187,7 +187,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetExFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_key_if_not_exists_with_expiry( &self, key: &str, @@ -212,7 +212,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_expiry( &self, key: &str, @@ -224,7 +224,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetExpiryFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_expire_at( &self, key: &str, @@ -236,7 +236,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetExpiryFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_hash_fields( &self, key: &str, @@ -260,7 +260,7 @@ impl super::RedisConnectionPool { .await } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn set_hash_field_if_not_exist( &self, key: &str, @@ -287,7 +287,7 @@ impl super::RedisConnectionPool { .await } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn serialize_and_set_hash_field_if_not_exist( &self, key: &str, @@ -306,7 +306,7 @@ impl super::RedisConnectionPool { .await } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn serialize_and_set_multiple_hash_field_if_not_exist( &self, kv: &[(&str, V)], @@ -326,7 +326,7 @@ impl super::RedisConnectionPool { Ok(hsetnx) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn hscan( &self, key: &str, @@ -357,7 +357,7 @@ impl super::RedisConnectionPool { .await) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn hscan_and_deserialize( &self, key: &str, @@ -377,7 +377,7 @@ impl super::RedisConnectionPool { .collect()) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn get_hash_field( &self, key: &str, @@ -392,7 +392,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::GetHashFieldFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn get_hash_field_and_deserialize( &self, key: &str, @@ -413,7 +413,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::JsonDeserializationFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn sadd( &self, key: &str, @@ -429,7 +429,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetAddMembersFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_append_entry( &self, stream: &str, @@ -446,7 +446,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::StreamAppendFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_delete_entries( &self, stream: &str, @@ -461,7 +461,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::StreamDeleteFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_trim_entries( &self, stream: &str, @@ -477,7 +477,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::StreamTrimFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_acknowledge_entries( &self, stream: &str, @@ -493,7 +493,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::StreamAcknowledgeFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_get_length(&self, stream: K) -> CustomResult where K: Into + Debug + Send + Sync, @@ -504,7 +504,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::GetLengthFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_read_entries( &self, streams: K, @@ -531,7 +531,7 @@ impl super::RedisConnectionPool { }) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn stream_read_with_options( &self, streams: K, @@ -562,7 +562,7 @@ impl super::RedisConnectionPool { // Consumer Group API - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn consumer_group_create( &self, stream: &str, @@ -583,7 +583,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::ConsumerGroupCreateFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn consumer_group_destroy( &self, stream: &str, @@ -596,7 +596,7 @@ impl super::RedisConnectionPool { } // the number of pending messages that the consumer had before it was deleted - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn consumer_group_delete_consumer( &self, stream: &str, @@ -609,7 +609,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::ConsumerGroupRemoveConsumerFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn consumer_group_set_last_id( &self, stream: &str, @@ -622,7 +622,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::ConsumerGroupSetIdFailed) } - #[instrument(level = "DEBUG", skip(self))] + //#\[instrument\(level = "DEBUG", skip(self))] pub async fn consumer_group_set_message_owner( &self, stream: &str, diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs index 1df37e9f6d1..b12f3bd0abf 100644 --- a/crates/router/src/bin/scheduler.rs +++ b/crates/router/src/bin/scheduler.rs @@ -1,5 +1,5 @@ #![recursion_limit = "256"] -use std::{str::FromStr, sync::Arc}; +use std::{collections::HashMap, str::FromStr, sync::Arc}; use actix_web::{dev::Server, web, Scope}; use api_models::health_check::SchedulerHealthCheckResponse; @@ -12,7 +12,8 @@ use router::{ errors::{self, CustomResult}, health_check::HealthCheckInterface, }, - logger, routes, + logger, + routes, services::{self, api}, workflows, }; @@ -75,21 +76,21 @@ async fn main() -> CustomResult<(), ProcessTrackerError> { [router_env::service_name!()], ); - #[allow(clippy::expect_used)] - let web_server = Box::pin(start_web_server( - state.clone(), - scheduler_flow_str.to_string(), - )) - .await - .expect("Failed to create the server"); - - let _task_handle = tokio::spawn( - async move { - let _ = web_server.await; - logger::error!("The health check probe stopped working!"); - } - .in_current_span(), - ); + // #[allow(clippy::expect_used)] + // let web_server = Box::pin(start_web_server( + // state.clone(), + // scheduler_flow_str.to_string(), + // )) + // .await + // .expect("Failed to create the server"); + + // let _task_handle = tokio::spawn( + // async move { + // let _ = web_server.await; + // logger::error!("The health check probe stopped working!"); + // } + // .in_current_span(), + // ); logger::debug!(startup_config=?state.conf); @@ -136,34 +137,53 @@ impl Health { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn health() -> impl actix_web::Responder { logger::info!("Scheduler health was called"); actix_web::HttpResponse::Ok().body("Scheduler health is good") } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn deep_health_check( state: web::Data, service: web::Data, ) -> impl actix_web::Responder { - let report = deep_health_check_func(state, service).await; - match report { - Ok(response) => services::http_response_json( - serde_json::to_string(&response) - .map_err(|err| { - logger::error!(serialization_error=?err); - }) - .unwrap_or_default(), - ), - Err(err) => api::log_and_return_error_response(err), + let mut checks = HashMap::new(); + let stores = state.stores.clone(); + let app_state = Arc::clone(&state.into_inner()); + let service_name = service.into_inner(); + for (tenant, _) in stores { + let session_state = routes::SessionState::from_app_state(app_state.clone(), &tenant); + let report = deep_health_check_func(session_state, &service_name).await; + match report { + Ok(response) => { + checks.insert( + tenant, + serde_json::to_string(&response) + .map_err(|err| { + logger::error!(serialization_error=?err); + }) + .unwrap_or_default(), + ); + } + Err(err) => { + return api::log_and_return_error_response(err); + } + } } + services::http_response_json( + serde_json::to_string(&checks) + .map_err(|err| { + logger::error!(serialization_error=?err); + }) + .unwrap_or_default(), + ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn deep_health_check_func( - state: web::Data, - service: web::Data, + state: routes::SessionState, + service: &str, ) -> errors::RouterResult { - logger::info!("{} deep health check was called", service.into_inner()); + logger::info!("{} deep health check was called", service); logger::debug!("Database health check begin"); @@ -215,10 +235,10 @@ pub async fn deep_health_check_func( pub struct WorkflowRunner; #[async_trait::async_trait] -impl ProcessTrackerWorkflows for WorkflowRunner { +impl ProcessTrackerWorkflows for WorkflowRunner { async fn trigger_workflow<'a>( &'a self, - state: &'a routes::AppState, + state: &'a routes::SessionState, process: storage::ProcessTracker, ) -> CustomResult<(), ProcessTrackerError> { let runner = process @@ -233,7 +253,7 @@ impl ProcessTrackerWorkflows for WorkflowRunner { .attach_printable("Failed to parse workflow runner name")?; let get_operation = |runner: storage::ProcessTrackerRunner| -> CustomResult< - Box>, + Box>, ProcessTrackerError, > { match runner { @@ -269,7 +289,7 @@ impl ProcessTrackerWorkflows for WorkflowRunner { let operation = get_operation(runner)?; let app_state = &state.clone(); - let output = operation.execute_workflow(app_state, process.clone()).await; + let output = operation.execute_workflow(state, process.clone()).await; match output { Ok(_) => operation.success_handler(app_state, process).await, Err(error) => match operation @@ -310,6 +330,7 @@ async fn start_scheduler( Arc::new(scheduler_settings), channel, WorkflowRunner {}, + |state, tenant| routes::SessionState::from_app_state(Arc::new(state.clone()), tenant), ) .await } diff --git a/crates/router/src/compatibility/stripe/customers.rs b/crates/router/src/compatibility/stripe/customers.rs index 3628c72a31c..4b8ddc6212f 100644 --- a/crates/router/src/compatibility/stripe/customers.rs +++ b/crates/router/src/compatibility/stripe/customers.rs @@ -11,7 +11,7 @@ use crate::{ types::api::{customers as customer_types, payment_methods}, }; -#[instrument(skip_all, fields(flow = ?Flow::CustomersCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersCreate))] pub async fn customer_create( state: web::Data, qs_config: web::Data, @@ -51,7 +51,7 @@ pub async fn customer_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersRetrieve))] pub async fn customer_retrieve( state: web::Data, req: HttpRequest, @@ -85,7 +85,7 @@ pub async fn customer_retrieve( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersUpdate))] pub async fn customer_update( state: web::Data, qs_config: web::Data, @@ -128,7 +128,7 @@ pub async fn customer_update( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersDelete))] pub async fn customer_delete( state: web::Data, req: HttpRequest, @@ -154,7 +154,7 @@ pub async fn customer_delete( state.into_inner(), &req, payload, - |state, auth, req, _| { + |state, auth: auth::AuthenticationData, req, _| { customers::delete_customer(state, auth.merchant_account, req, auth.key_store) }, &auth::ApiKeyAuth, @@ -162,7 +162,7 @@ pub async fn customer_delete( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] pub async fn list_customer_payment_method_api( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs index d67e10a96e5..d6f18dd11be 100644 --- a/crates/router/src/compatibility/stripe/payment_intents.rs +++ b/crates/router/src/compatibility/stripe/payment_intents.rs @@ -13,7 +13,7 @@ use crate::{ types::api as api_types, }; -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] pub async fn payment_intents_create( state: web::Data, qs_config: web::Data, @@ -69,6 +69,7 @@ pub async fn payment_intents_create( payments::CallConnectorAction::Trigger, eligible_connectors, api_types::HeaderPayload::default(), + ) }, &auth::ApiKeyAuth, @@ -76,7 +77,7 @@ pub async fn payment_intents_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] pub async fn payment_intents_retrieve( state: web::Data, req: HttpRequest, @@ -136,7 +137,7 @@ pub async fn payment_intents_retrieve( )) .await } -#[instrument(skip_all, fields(flow))] +//#\[instrument\(skip_all, fields(flow))] pub async fn payment_intents_retrieve_with_gateway_creds( state: web::Data, qs_config: web::Data, @@ -199,6 +200,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds( payments::CallConnectorAction::Trigger, None, api_types::HeaderPayload::default(), + ) }, &*auth_type, @@ -206,7 +208,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsUpdate))] pub async fn payment_intents_update( state: web::Data, qs_config: web::Data, @@ -265,6 +267,7 @@ pub async fn payment_intents_update( payments::CallConnectorAction::Trigger, eligible_connectors, api_types::HeaderPayload::default(), + ) }, &*auth_type, @@ -272,7 +275,7 @@ pub async fn payment_intents_update( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] pub async fn payment_intents_confirm( state: web::Data, qs_config: web::Data, @@ -337,6 +340,7 @@ pub async fn payment_intents_confirm( payments::CallConnectorAction::Trigger, eligible_connectors, api_types::HeaderPayload::default(), + ) }, &*auth_type, @@ -344,7 +348,7 @@ pub async fn payment_intents_confirm( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] pub async fn payment_intents_capture( state: web::Data, qs_config: web::Data, @@ -398,6 +402,7 @@ pub async fn payment_intents_capture( payments::CallConnectorAction::Trigger, None, api_types::HeaderPayload::default(), + ) }, &auth::ApiKeyAuth, @@ -405,7 +410,7 @@ pub async fn payment_intents_capture( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] pub async fn payment_intents_cancel( state: web::Data, qs_config: web::Data, @@ -470,7 +475,7 @@ pub async fn payment_intents_cancel( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn payment_intent_list( state: web::Data, diff --git a/crates/router/src/compatibility/stripe/refunds.rs b/crates/router/src/compatibility/stripe/refunds.rs index da68e79e422..bca03334019 100644 --- a/crates/router/src/compatibility/stripe/refunds.rs +++ b/crates/router/src/compatibility/stripe/refunds.rs @@ -11,7 +11,7 @@ use crate::{ types::api::refunds as refund_types, }; -#[instrument(skip_all, fields(flow = ?Flow::RefundsCreate, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsCreate, payment_id))] pub async fn refund_create( state: web::Data, qs_config: web::Data, @@ -56,7 +56,7 @@ pub async fn refund_create( )) .await } -#[instrument(skip_all, fields(flow))] +//#\[instrument\(skip_all, fields(flow))] pub async fn refund_retrieve_with_gateway_creds( state: web::Data, qs_config: web::Data, @@ -106,7 +106,7 @@ pub async fn refund_retrieve_with_gateway_creds( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieveForceSync))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsRetrieveForceSync))] pub async fn refund_retrieve( state: web::Data, req: HttpRequest, @@ -148,7 +148,7 @@ pub async fn refund_retrieve( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::RefundsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsUpdate))] pub async fn refund_update( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rs index 60627ee5642..79e268db031 100644 --- a/crates/router/src/compatibility/stripe/setup_intents.rs +++ b/crates/router/src/compatibility/stripe/setup_intents.rs @@ -15,7 +15,7 @@ use crate::{ types::api as api_types, }; -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCreate))] pub async fn setup_intents_create( state: web::Data, qs_config: web::Data, @@ -78,7 +78,7 @@ pub async fn setup_intents_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] pub async fn setup_intents_retrieve( state: web::Data, req: HttpRequest, @@ -138,7 +138,7 @@ pub async fn setup_intents_retrieve( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsUpdate))] pub async fn setup_intents_update( state: web::Data, qs_config: web::Data, @@ -211,7 +211,7 @@ pub async fn setup_intents_update( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsConfirm))] pub async fn setup_intents_confirm( state: web::Data, qs_config: web::Data, diff --git a/crates/router/src/compatibility/wrap.rs b/crates/router/src/compatibility/wrap.rs index 96163727da3..04db00b99f3 100644 --- a/crates/router/src/compatibility/wrap.rs +++ b/crates/router/src/compatibility/wrap.rs @@ -10,23 +10,23 @@ use crate::{ events::api_logs::ApiEventMetric, routes::{ app::{AppStateInfo, ReqState}, - metrics, AppState, + metrics, AppState, SessionState, }, services::{self, api, authentication as auth, logger}, }; -#[instrument(skip(request, payload, state, func, api_authentication))] +//#\[instrument\(skip(request, payload, state, func, api_authentication))] pub async fn compatibility_api_wrap<'a, 'b, U, T, Q, F, Fut, S, E, E2>( flow: impl router_env::types::FlowMetric, state: Arc, request: &'a HttpRequest, payload: T, func: F, - api_authentication: &dyn auth::AuthenticateAndFetch, + api_authentication: &dyn auth::AuthenticateAndFetch, lock_action: api_locking::LockAction, ) -> HttpResponse where - F: Fn(AppState, U, T, ReqState) -> Fut, + F: Fn(SessionState, U, T, ReqState) -> Fut, Fut: Future, E2>>, E2: ErrorSwitch + std::error::Error + Send + Sync + 'static, Q: Serialize + std::fmt::Debug + 'a + ApiEventMetric, @@ -49,6 +49,7 @@ where api::server_wrap_util( &flow, state.clone().into(), + request.headers(), req_state, request, payload, diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rs index 537f6666c5d..6a6efcc8698 100644 --- a/crates/router/src/configs/secrets_transformers.rs +++ b/crates/router/src/configs/secrets_transformers.rs @@ -365,5 +365,6 @@ pub(crate) async fn fetch_raw_secrets( connector_onboarding, cors: conf.cors, unmasked_headers: conf.unmasked_headers, + multitenancy: conf.multitenancy, } } diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index 74598f0a5cc..978e51a933b 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -119,6 +119,12 @@ pub struct Settings { #[cfg(feature = "olap")] pub connector_onboarding: SecretStateContainer, pub unmasked_headers: UnmaskedHeaders, + pub multitenancy: Multitenancy, +} + +#[derive(Debug, Deserialize, Clone, Default)] +pub struct Multitenancy { + pub tenants: Vec, } #[derive(Debug, Deserialize, Clone, Default)] diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs index 481eba0df70..05b6972328a 100644 --- a/crates/router/src/connector/adyen.rs +++ b/crates/router/src/connector/adyen.rs @@ -1146,7 +1146,7 @@ impl services::ConnectorIntegration, @@ -1251,7 +1251,7 @@ impl services::ConnectorIntegration, @@ -1361,7 +1361,7 @@ impl Ok(Some(request)) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn handle_response( &self, data: &types::PayoutsRouterData, @@ -1484,7 +1484,7 @@ impl services::ConnectorIntegration, @@ -1597,7 +1597,7 @@ impl services::ConnectorIntegration, diff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rs index 6a8f384e199..301883110c5 100644 --- a/crates/router/src/connector/airwallex.rs +++ b/crates/router/src/connector/airwallex.rs @@ -338,7 +338,7 @@ impl ConnectorIntegration CustomResult<(), errors::ConnectorError> { let integ: Box< &(dyn ConnectorIntegration< diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rs index 0e3ae84581a..a80eea7a6bb 100644 --- a/crates/router/src/connector/nuvei.rs +++ b/crates/router/src/connector/nuvei.rs @@ -516,7 +516,7 @@ impl ConnectorIntegration CustomResult<(), errors::ConnectorError> { let integ: Box< &(dyn ConnectorIntegration< diff --git a/crates/router/src/connector/shift4.rs b/crates/router/src/connector/shift4.rs index e11a79cb027..5e1ec587f8c 100644 --- a/crates/router/src/connector/shift4.rs +++ b/crates/router/src/connector/shift4.rs @@ -215,7 +215,7 @@ impl ConnectorIntegration CustomResult<(), errors::ConnectorError> { if router_data.auth_type == diesel_models::enums::AuthenticationType::ThreeDs && router_data.payment_method == diesel_models::enums::PaymentMethod::Card diff --git a/crates/router/src/connector/square.rs b/crates/router/src/connector/square.rs index 915a9a9ca11..5a007796567 100644 --- a/crates/router/src/connector/square.rs +++ b/crates/router/src/connector/square.rs @@ -195,7 +195,7 @@ impl async fn execute_pretasks( &self, router_data: &mut types::TokenizationRouterData, - app_state: &crate::routes::AppState, + app_state: &crate::routes::SessionState, ) -> CustomResult<(), errors::ConnectorError> { let integ: Box< &(dyn ConnectorIntegration< diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs index 70c08a31d73..fb156a7a5cf 100644 --- a/crates/router/src/connector/stripe.rs +++ b/crates/router/src/connector/stripe.rs @@ -1331,7 +1331,7 @@ impl services::ConnectorIntegration, @@ -1440,7 +1440,7 @@ impl services::ConnectorIntegration, @@ -1596,7 +1596,7 @@ impl )) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn handle_response( &self, data: &types::UploadFileRouterData, @@ -1706,7 +1706,7 @@ impl )) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn handle_response( &self, data: &types::RetrieveFileRouterData, @@ -1842,7 +1842,7 @@ impl Ok(Some(request)) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn handle_response( &self, data: &types::SubmitEvidenceRouterData, diff --git a/crates/router/src/connector/wise.rs b/crates/router/src/connector/wise.rs index 3a241fe4ed6..495b8f2d397 100644 --- a/crates/router/src/connector/wise.rs +++ b/crates/router/src/connector/wise.rs @@ -280,7 +280,7 @@ impl services::ConnectorIntegration, @@ -386,7 +386,7 @@ impl services::ConnectorIntegration, @@ -467,7 +467,7 @@ impl Ok(Some(request)) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn handle_response( &self, data: &types::PayoutsRouterData, @@ -506,7 +506,7 @@ impl services::ConnectorIntegration, - app_state: &routes::AppState, + app_state: &routes::SessionState, ) -> CustomResult<(), errors::ConnectorError> { // Create a quote let quote_router_data = @@ -584,7 +584,7 @@ impl services::ConnectorIntegration, @@ -697,7 +697,7 @@ impl services::ConnectorIntegration, diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index c7e1e4118b4..369b54bda55 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -26,7 +26,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services::{self, api as service_api}, types::{ self, api, @@ -50,7 +50,7 @@ pub fn create_merchant_publishable_key() -> String { } pub async fn create_merchant_account( - state: AppState, + state: SessionState, req: api::MerchantAccountCreate, ) -> RouterResponse { let db = state.store.as_ref(); @@ -287,7 +287,7 @@ pub async fn create_merchant_account( #[cfg(feature = "olap")] pub async fn list_merchant_account( - state: AppState, + state: SessionState, req: api_models::admin::MerchantAccountListRequest, ) -> RouterResponse> { let merchant_accounts = state @@ -311,7 +311,7 @@ pub async fn list_merchant_account( } pub async fn get_merchant_account( - state: AppState, + state: SessionState, req: api::MerchantId, ) -> RouterResponse { let db = state.store.as_ref(); @@ -399,7 +399,7 @@ pub async fn create_business_profile_from_business_labels( /// For backwards compatibility /// If any of the fields of merchant account are updated, then update these fields in business profiles pub async fn update_business_profile_cascade( - state: AppState, + state: SessionState, merchant_account_update: api::MerchantAccountUpdate, merchant_id: String, ) -> RouterResult<()> { @@ -460,7 +460,7 @@ pub async fn update_business_profile_cascade( } pub async fn merchant_account_update( - state: AppState, + state: SessionState, merchant_id: &String, req: api::MerchantAccountUpdate, ) -> RouterResponse { @@ -614,7 +614,7 @@ pub async fn merchant_account_update( } pub async fn merchant_account_delete( - state: AppState, + state: SessionState, merchant_id: String, ) -> RouterResponse { let mut is_deleted = false; @@ -730,7 +730,8 @@ fn validate_certificate_in_mca_metadata( } pub async fn create_payment_connector( - state: AppState, + state: SessionState, + req: api::MerchantConnectorCreate, merchant_id: &String, ) -> RouterResponse { @@ -1081,7 +1082,7 @@ async fn validate_pm_auth( } pub async fn retrieve_payment_connector( - state: AppState, + state: SessionState, merchant_id: String, merchant_connector_id: String, ) -> RouterResponse { @@ -1114,7 +1115,7 @@ pub async fn retrieve_payment_connector( } pub async fn list_payment_connectors( - state: AppState, + state: SessionState, merchant_id: String, ) -> RouterResponse> { let store = state.store.as_ref(); @@ -1151,7 +1152,7 @@ pub async fn list_payment_connectors( } pub async fn update_payment_connector( - state: AppState, + state: SessionState, merchant_id: &str, merchant_connector_id: &str, req: api_models::admin::MerchantConnectorUpdate, @@ -1313,7 +1314,7 @@ pub async fn update_payment_connector( } pub async fn delete_payment_connector( - state: AppState, + state: SessionState, merchant_id: String, merchant_connector_id: String, ) -> RouterResponse { @@ -1358,7 +1359,7 @@ pub async fn delete_payment_connector( } pub async fn kv_for_merchant( - state: AppState, + state: SessionState, merchant_id: String, enable: bool, ) -> RouterResponse { @@ -1418,7 +1419,7 @@ pub async fn kv_for_merchant( } pub async fn check_merchant_account_kv_status( - state: AppState, + state: SessionState, merchant_id: String, ) -> RouterResponse { let db = state.store.as_ref(); @@ -1490,7 +1491,7 @@ pub async fn create_and_insert_business_profile( } pub async fn create_business_profile( - state: AppState, + state: SessionState, request: api::BusinessProfileCreate, merchant_id: &str, ) -> RouterResponse { @@ -1537,7 +1538,7 @@ pub async fn create_business_profile( } pub async fn list_business_profile( - state: AppState, + state: SessionState, merchant_id: String, ) -> RouterResponse> { let db = state.store.as_ref(); @@ -1557,7 +1558,7 @@ pub async fn list_business_profile( } pub async fn retrieve_business_profile( - state: AppState, + state: SessionState, profile_id: String, ) -> RouterResponse { let db = state.store.as_ref(); @@ -1575,7 +1576,7 @@ pub async fn retrieve_business_profile( } pub async fn delete_business_profile( - state: AppState, + state: SessionState, profile_id: String, merchant_id: &str, ) -> RouterResponse { @@ -1591,7 +1592,7 @@ pub async fn delete_business_profile( } pub async fn update_business_profile( - state: AppState, + state: SessionState, profile_id: &str, merchant_id: &str, request: api::BusinessProfileUpdate, @@ -1941,7 +1942,7 @@ pub(crate) fn validate_auth_and_metadata_type( #[cfg(feature = "dummy_connector")] pub async fn validate_dummy_connector_enabled( - state: &AppState, + state: &SessionState, connector_name: &api_enums::Connector, ) -> Result<(), errors::ApiErrorResponse> { if !state.conf.dummy_connector.enabled diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs index f75ed011688..7953cc34bcb 100644 --- a/crates/router/src/core/api_keys.rs +++ b/crates/router/src/core/api_keys.rs @@ -9,7 +9,7 @@ use crate::{ configs::settings, consts, core::errors::{self, RouterResponse, StorageErrorExt}, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services::ApplicationResponse, types::{api, storage, transformers::ForeignInto}, utils, @@ -108,9 +108,9 @@ impl PlaintextApiKey { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn create_api_key( - state: AppState, + state: SessionState, api_key: api::CreateApiKeyRequest, merchant_id: String, ) -> RouterResponse { @@ -178,7 +178,7 @@ pub async fn create_api_key( // After first email has been sent, update the schedule_time based on retry_count in execute_workflow(). // A task is not scheduled if the time for the first email is in the past. #[cfg(feature = "email")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn add_api_key_expiry_task( store: &dyn crate::db::StorageInterface, api_key: &ApiKey, @@ -242,9 +242,9 @@ pub async fn add_api_key_expiry_task( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn retrieve_api_key( - state: AppState, + state: SessionState, merchant_id: &str, key_id: &str, ) -> RouterResponse { @@ -259,9 +259,9 @@ pub async fn retrieve_api_key( Ok(ApplicationResponse::Json(api_key.foreign_into())) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn update_api_key( - state: AppState, + state: SessionState, api_key: api::UpdateApiKeyRequest, ) -> RouterResponse { let merchant_id = api_key.merchant_id.clone(); @@ -335,7 +335,7 @@ pub async fn update_api_key( // Construct Update variant of ProcessTrackerUpdate with new tracking_data. // A task is not scheduled if the time for the first email is in the past. #[cfg(feature = "email")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn update_api_key_expiry_task( store: &dyn crate::db::StorageInterface, api_key: &ApiKey, @@ -393,9 +393,9 @@ pub async fn update_api_key_expiry_task( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn revoke_api_key( - state: AppState, + state: SessionState, merchant_id: &str, key_id: &str, ) -> RouterResponse { @@ -441,7 +441,7 @@ pub async fn revoke_api_key( // Function to revoke api_key_expiry task in the process_tracker table when API key is revoked. // Construct StatusUpdate variant of ProcessTrackerUpdate by setting status to 'finish'. #[cfg(feature = "email")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn revoke_api_key_expiry_task( store: &dyn crate::db::StorageInterface, key_id: &str, @@ -461,9 +461,9 @@ pub async fn revoke_api_key_expiry_task( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn list_api_keys( - state: AppState, + state: SessionState, merchant_id: String, limit: Option, offset: Option, diff --git a/crates/router/src/core/api_locking.rs b/crates/router/src/core/api_locking.rs index ec205f52427..51010b10cd9 100644 --- a/crates/router/src/core/api_locking.rs +++ b/crates/router/src/core/api_locking.rs @@ -6,7 +6,10 @@ use redis_interface as redis; use router_env::{instrument, logger, tracing}; use super::errors::{self, RouterResult}; -use crate::routes::{app::AppStateInfo, lock_utils}; +use crate::routes::{ + app::SessionStateInfo, + lock_utils, +}; pub const API_LOCK_PREFIX: &str = "API_LOCK"; @@ -47,10 +50,10 @@ impl LockingInput { } impl LockAction { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn perform_locking_action(self, state: &A, merchant_id: String) -> RouterResult<()> where - A: AppStateInfo, + A: SessionStateInfo, { match self { Self::Hold { input } => { @@ -108,10 +111,10 @@ impl LockAction { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn free_lock_action(self, state: &A, merchant_id: String) -> RouterResult<()> where - A: AppStateInfo, + A: SessionStateInfo, { match self { Self::Hold { input } => { diff --git a/crates/router/src/core/authentication.rs b/crates/router/src/core/authentication.rs index 09d8ccc8833..65974b699aa 100644 --- a/crates/router/src/core/authentication.rs +++ b/crates/router/src/core/authentication.rs @@ -12,14 +12,14 @@ use masking::PeekInterface; use super::errors; use crate::{ core::{errors::ApiErrorResponse, payments as payments_core}, - routes::AppState, + routes::SessionState, types::{self as core_types, api, authentication::AuthenticationResponseData, storage}, utils::OptionExt, }; #[allow(clippy::too_many_arguments)] pub async fn perform_authentication( - state: &AppState, + state: &SessionState, authentication_connector: String, payment_method_data: payments::PaymentMethodData, payment_method: common_enums::PaymentMethod, @@ -105,7 +105,7 @@ pub async fn perform_authentication( } pub async fn perform_post_authentication( - state: &AppState, + state: &SessionState, authentication_connector: String, business_profile: core_types::storage::BusinessProfile, merchant_connector_account: payments_core::helpers::MerchantConnectorAccountType, @@ -156,7 +156,7 @@ pub async fn perform_post_authentication( } pub async fn perform_pre_authentication( - state: &AppState, + state: &SessionState, authentication_connector_name: String, authentication_flow_input: types::PreAuthenthenticationFlowInput<'_, F>, business_profile: &core_types::storage::BusinessProfile, diff --git a/crates/router/src/core/authentication/utils.rs b/crates/router/src/core/authentication/utils.rs index 8d6efc4d685..a072aee48b1 100644 --- a/crates/router/src/core/authentication/utils.rs +++ b/crates/router/src/core/authentication/utils.rs @@ -7,7 +7,7 @@ use crate::{ payments, }, errors::RouterResult, - routes::AppState, + routes::SessionState, services::{self, execute_connector_processing_step}, types::{ api::{self, ConnectorCallType}, @@ -47,7 +47,7 @@ pub fn get_connector_name_if_separate_authn_supported( } pub async fn update_trackers( - state: &AppState, + state: &SessionState, router_data: RouterData, authentication: storage::Authentication, token: Option, @@ -141,7 +141,7 @@ impl ForeignFrom for common_enums::AttemptSt } pub async fn create_new_authentication( - state: &AppState, + state: &SessionState, merchant_id: String, authentication_connector: String, ) -> RouterResult { @@ -190,7 +190,7 @@ pub async fn create_new_authentication( } pub async fn do_auth_connector_call( - state: &AppState, + state: &SessionState, authentication_connector_name: String, router_data: RouterData, ) -> RouterResult> diff --git a/crates/router/src/core/blocklist.rs b/crates/router/src/core/blocklist.rs index 12a0802517c..947acc506df 100644 --- a/crates/router/src/core/blocklist.rs +++ b/crates/router/src/core/blocklist.rs @@ -5,13 +5,13 @@ use api_models::blocklist as api_blocklist; use crate::{ core::errors::{self, RouterResponse}, - routes::AppState, + routes::SessionState, services, types::domain, }; pub async fn add_entry_to_blocklist( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, body: api_blocklist::AddToBlocklistRequest, ) -> RouterResponse { @@ -21,7 +21,7 @@ pub async fn add_entry_to_blocklist( } pub async fn remove_entry_from_blocklist( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, body: api_blocklist::DeleteFromBlocklistRequest, ) -> RouterResponse { @@ -31,7 +31,7 @@ pub async fn remove_entry_from_blocklist( } pub async fn list_blocklist_entries( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, query: api_blocklist::ListBlocklistQuery, ) -> RouterResponse> { @@ -41,7 +41,7 @@ pub async fn list_blocklist_entries( } pub async fn toggle_blocklist_guard( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, query: api_blocklist::ToggleBlocklistQuery, ) -> RouterResponse { diff --git a/crates/router/src/core/blocklist/transformers.rs b/crates/router/src/core/blocklist/transformers.rs index a2583e5b604..72a24ac973e 100644 --- a/crates/router/src/core/blocklist/transformers.rs +++ b/crates/router/src/core/blocklist/transformers.rs @@ -109,9 +109,9 @@ async fn generate_jwe_payload_for_request( Ok(jwe_body) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn generate_fingerprint( - state: &routes::AppState, + state: &routes::SessionState, card_number: StrongSecret, hash_key: StrongSecret, locker_choice: api_enums::LockerChoice, @@ -127,9 +127,9 @@ pub async fn generate_fingerprint( Ok(generate_fingerprint_resp) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn call_to_locker_for_fingerprint( - state: &routes::AppState, + state: &routes::SessionState, payload: &blocklist::GenerateFingerprintRequest, locker_choice: api_enums::LockerChoice, ) -> CustomResult { diff --git a/crates/router/src/core/blocklist/utils.rs b/crates/router/src/core/blocklist/utils.rs index 7c01a9aca76..7baf323be38 100644 --- a/crates/router/src/core/blocklist/utils.rs +++ b/crates/router/src/core/blocklist/utils.rs @@ -5,7 +5,7 @@ use diesel_models::configs; use error_stack::ResultExt; use masking::StrongSecret; -use super::{errors, transformers::generate_fingerprint, AppState}; +use super::{errors, transformers::generate_fingerprint, SessionState}; use crate::{ consts, core::{ @@ -18,7 +18,7 @@ use crate::{ }; pub async fn delete_entry_from_blocklist( - state: &AppState, + state: &SessionState, merchant_id: String, request: api_blocklist::DeleteFromBlocklistRequest, ) -> RouterResult { @@ -44,7 +44,7 @@ pub async fn delete_entry_from_blocklist( } pub async fn toggle_blocklist_guard_for_merchant( - state: &AppState, + state: &SessionState, merchant_id: String, query: api_blocklist::ToggleBlocklistQuery, ) -> CustomResult { @@ -94,7 +94,7 @@ pub fn get_blocklist_guard_key(merchant_id: &str) -> String { } pub async fn list_blocklist_entries_for_merchant( - state: &AppState, + state: &SessionState, merchant_id: String, query: api_blocklist::ListBlocklistQuery, ) -> RouterResult> { @@ -138,7 +138,7 @@ fn validate_extended_card_bin(bin: &str) -> RouterResult<()> { } pub async fn insert_entry_into_blocklist( - state: &AppState, + state: &SessionState, merchant_id: String, to_block: api_blocklist::AddToBlocklistRequest, ) -> RouterResult { @@ -207,7 +207,7 @@ pub async fn insert_entry_into_blocklist( } pub async fn get_merchant_fingerprint_secret( - state: &AppState, + state: &SessionState, merchant_id: &str, ) -> RouterResult { let key = get_merchant_fingerprint_secret_key(merchant_id); @@ -246,7 +246,7 @@ fn get_merchant_fingerprint_secret_key(merchant_id: &str) -> String { async fn duplicate_check_insert_bin( bin: &str, - state: &AppState, + state: &SessionState, merchant_id: &str, data_kind: common_enums::BlocklistDataKind, ) -> RouterResult { @@ -287,7 +287,7 @@ async fn duplicate_check_insert_bin( } async fn delete_card_bin_blocklist_entry( - state: &AppState, + state: &SessionState, bin: &str, merchant_id: &str, ) -> RouterResult { @@ -301,7 +301,7 @@ async fn delete_card_bin_blocklist_entry( } pub async fn validate_data_for_blocklist( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut PaymentData, ) -> CustomResult @@ -452,7 +452,7 @@ where } pub async fn generate_payment_fingerprint( - state: &AppState, + state: &SessionState, merchant_id: String, payment_method_data: Option, ) -> CustomResult, errors::ApiErrorResponse> { diff --git a/crates/router/src/core/cache.rs b/crates/router/src/core/cache.rs index a8ca8395a67..f740bd42d30 100644 --- a/crates/router/src/core/cache.rs +++ b/crates/router/src/core/cache.rs @@ -3,10 +3,10 @@ use error_stack::{report, ResultExt}; use storage_impl::redis::cache::CacheKind; use super::errors; -use crate::{db::cache::publish_into_redact_channel, routes::AppState, services}; +use crate::{db::cache::publish_into_redact_channel, routes::SessionState, services}; pub async fn invalidate( - state: AppState, + state: SessionState, key: &str, ) -> CustomResult, errors::ApiErrorResponse> { let store = state.store.as_ref(); diff --git a/crates/router/src/core/cards_info.rs b/crates/router/src/core/cards_info.rs index 4352e1808c7..34308257ad8 100644 --- a/crates/router/src/core/cards_info.rs +++ b/crates/router/src/core/cards_info.rs @@ -19,9 +19,9 @@ fn verify_iin_length(card_iin: &str) -> Result<(), errors::ApiErrorResponse> { }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn retrieve_card_info( - state: routes::AppState, + state: routes::SessionState, merchant_account: domain::MerchantAccount, request: api_models::cards_info::CardsInfoRequest, ) -> RouterResponse { diff --git a/crates/router/src/core/conditional_config.rs b/crates/router/src/core/conditional_config.rs index c352e825052..a8bc8a797dc 100644 --- a/crates/router/src/core/conditional_config.rs +++ b/crates/router/src/core/conditional_config.rs @@ -12,14 +12,14 @@ use super::routing::helpers::{ }; use crate::{ core::errors::{self, RouterResponse}, - routes::AppState, + routes::SessionState, services::api as service_api, types::domain, utils::OptionExt, }; pub async fn upsert_conditional_config( - state: AppState, + state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, request: DecisionManager, @@ -149,7 +149,7 @@ pub async fn upsert_conditional_config( } pub async fn delete_conditional_config( - state: AppState, + state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, ) -> RouterResponse<()> { @@ -177,7 +177,7 @@ pub async fn delete_conditional_config( } pub async fn retrieve_conditional_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, ) -> RouterResponse { let db = state.store.as_ref(); diff --git a/crates/router/src/core/configs.rs b/crates/router/src/core/configs.rs index ba2303167d7..be8dfc83828 100644 --- a/crates/router/src/core/configs.rs +++ b/crates/router/src/core/configs.rs @@ -2,12 +2,12 @@ use error_stack::ResultExt; use crate::{ core::errors::{self, utils::StorageErrorExt, RouterResponse}, - routes::AppState, + routes::SessionState, services::ApplicationResponse, types::{api, transformers::ForeignInto}, }; -pub async fn set_config(state: AppState, config: api::Config) -> RouterResponse { +pub async fn set_config(state: SessionState, config: api::Config) -> RouterResponse { let store = state.store.as_ref(); let config = store .insert_config(diesel_models::configs::ConfigNew { @@ -21,7 +21,7 @@ pub async fn set_config(state: AppState, config: api::Config) -> RouterResponse< Ok(ApplicationResponse::Json(config.foreign_into())) } -pub async fn read_config(state: AppState, key: &str) -> RouterResponse { +pub async fn read_config(state: SessionState, key: &str) -> RouterResponse { let store = state.store.as_ref(); let config = store .find_config_by_key(key) @@ -31,7 +31,7 @@ pub async fn read_config(state: AppState, key: &str) -> RouterResponse RouterResponse { let store = state.store.as_ref(); @@ -42,7 +42,7 @@ pub async fn update_config( Ok(ApplicationResponse::Json(config.foreign_into())) } -pub async fn config_delete(state: AppState, key: String) -> RouterResponse { +pub async fn config_delete(state: SessionState, key: String) -> RouterResponse { let store = state.store.as_ref(); let config = store .delete_config_by_key(&key) diff --git a/crates/router/src/core/connector_onboarding.rs b/crates/router/src/core/connector_onboarding.rs index b69b2996a6a..d6c20cc2810 100644 --- a/crates/router/src/core/connector_onboarding.rs +++ b/crates/router/src/core/connector_onboarding.rs @@ -7,18 +7,18 @@ use crate::{ services::{authentication as auth, ApplicationResponse}, types as oss_types, utils::connector_onboarding as utils, - AppState, + SessionState, }; pub mod paypal; #[async_trait::async_trait] pub trait AccessToken { - async fn access_token(state: &AppState) -> RouterResult; + async fn access_token(state: &SessionState) -> RouterResult; } pub async fn get_action_url( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, request: api::ActionUrlRequest, _req_state: ReqState, @@ -53,7 +53,7 @@ pub async fn get_action_url( } pub async fn sync_onboarding_status( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, request: api::OnboardingSyncRequest, _req_state: ReqState, @@ -107,7 +107,7 @@ pub async fn sync_onboarding_status( } pub async fn reset_tracking_id( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, request: api::ResetTrackingIdRequest, _req_state: ReqState, diff --git a/crates/router/src/core/connector_onboarding/paypal.rs b/crates/router/src/core/connector_onboarding/paypal.rs index 616fcbdc8cc..6f28cfcbf8e 100644 --- a/crates/router/src/core/connector_onboarding/paypal.rs +++ b/crates/router/src/core/connector_onboarding/paypal.rs @@ -11,10 +11,10 @@ use crate::{ services::{send_request, ApplicationResponse, Request}, types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types}, utils::connector_onboarding as utils, - AppState, + SessionState, }; -fn build_referral_url(state: AppState) -> String { +fn build_referral_url(state: SessionState) -> String { format!( "{}v2/customer/partner-referrals", state.conf.connectors.paypal.base_url @@ -22,7 +22,7 @@ fn build_referral_url(state: AppState) -> String { } async fn build_referral_request( - state: AppState, + state: SessionState, tracking_id: String, return_url: String, ) -> RouterResult { @@ -37,7 +37,7 @@ async fn build_referral_request( } pub async fn get_action_url_from_paypal( - state: AppState, + state: SessionState, tracking_id: String, return_url: String, ) -> RouterResult { @@ -61,7 +61,7 @@ pub async fn get_action_url_from_paypal( parsed_response.extract_action_url() } -fn merchant_onboarding_status_url(state: AppState, tracking_id: String) -> String { +fn merchant_onboarding_status_url(state: SessionState, tracking_id: String) -> String { let partner_id = state .conf .connector_onboarding @@ -78,7 +78,7 @@ fn merchant_onboarding_status_url(state: AppState, tracking_id: String) -> Strin } pub async fn sync_merchant_onboarding_status( - state: AppState, + state: SessionState, tracking_id: String, ) -> RouterResult { let access_token = utils::paypal::generate_access_token(state.clone()).await?; @@ -113,7 +113,7 @@ pub async fn sync_merchant_onboarding_status( } async fn find_paypal_merchant_by_tracking_id( - state: AppState, + state: SessionState, tracking_id: String, access_token: &oss_types::AccessToken, ) -> RouterResult> { @@ -139,7 +139,7 @@ async fn find_paypal_merchant_by_tracking_id( } pub async fn update_mca( - state: &AppState, + state: &SessionState, merchant_id: String, connector_id: String, auth_details: oss_types::ConnectorAuthType, diff --git a/crates/router/src/core/currency.rs b/crates/router/src/core/currency.rs index f2791deb7b6..66f8cfba3a9 100644 --- a/crates/router/src/core/currency.rs +++ b/crates/router/src/core/currency.rs @@ -5,11 +5,11 @@ use crate::{ core::errors::ApiErrorResponse, services::ApplicationResponse, utils::currency::{self, convert_currency, get_forex_rates}, - AppState, + SessionState, }; pub async fn retrieve_forex( - state: AppState, + state: SessionState, ) -> CustomResult, ApiErrorResponse> { let forex_api = state.conf.forex_api.get_inner(); Ok(ApplicationResponse::Json( @@ -27,7 +27,8 @@ pub async fn retrieve_forex( } pub async fn convert_forex( - state: AppState, + state: SessionState, + amount: i64, to_currency: String, from_currency: String, diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs index c38167f07c4..d8e08c7768b 100644 --- a/crates/router/src/core/customers.rs +++ b/crates/router/src/core/customers.rs @@ -12,7 +12,7 @@ use crate::{ payment_methods::cards, }, pii::PeekInterface, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{ api::customers, @@ -27,9 +27,9 @@ use crate::{ pub const REDACTED: &str = "Redacted"; -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn create_customer( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, mut customer_data: customers::CustomerRequest, @@ -134,9 +134,9 @@ pub async fn create_customer( )) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn retrieve_customer( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: customers::CustomerId, @@ -164,9 +164,9 @@ pub async fn retrieve_customer( )) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn list_customers( - state: AppState, + state: SessionState, merchant_id: String, key_store: domain::MerchantKeyStore, ) -> errors::CustomerResponse> { @@ -185,9 +185,9 @@ pub async fn list_customers( Ok(services::ApplicationResponse::Json(customers)) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn delete_customer( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: customers::CustomerId, key_store: domain::MerchantKeyStore, @@ -339,9 +339,9 @@ pub async fn delete_customer( Ok(services::ApplicationResponse::Json(response)) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn update_customer( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, update_customer: customers::CustomerRequest, key_store: domain::MerchantKeyStore, diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs index 4928dc949dc..14613e89be5 100644 --- a/crates/router/src/core/disputes.rs +++ b/crates/router/src/core/disputes.rs @@ -10,7 +10,7 @@ use super::{ }; use crate::{ core::{files, payments, utils as core_utils}, - routes::AppState, + routes::SessionState, services, types::{ api::{self, disputes}, @@ -22,9 +22,9 @@ use crate::{ }, }; -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn retrieve_dispute( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: disputes::DisputeId, ) -> RouterResponse { @@ -39,9 +39,9 @@ pub async fn retrieve_dispute( Ok(services::ApplicationResponse::Json(dispute_response)) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn retrieve_disputes_list( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, constraints: api_models::disputes::DisputeListConstraints, ) -> RouterResponse> { @@ -58,9 +58,9 @@ pub async fn retrieve_disputes_list( Ok(services::ApplicationResponse::Json(disputes_list)) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn accept_dispute( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: disputes::DisputeId, @@ -159,9 +159,9 @@ pub async fn accept_dispute( Ok(services::ApplicationResponse::Json(dispute_response)) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn submit_evidence( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: dispute_models::SubmitEvidenceRequest, @@ -324,7 +324,7 @@ pub async fn submit_evidence( } pub async fn attach_evidence( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, attach_evidence_request: api::AttachEvidenceRequest, @@ -399,9 +399,9 @@ pub async fn attach_evidence( Ok(create_file_response) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn retrieve_dispute_evidence( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: disputes::DisputeId, ) -> RouterResponse> { @@ -424,7 +424,7 @@ pub async fn retrieve_dispute_evidence( } pub async fn delete_evidence( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, delete_evidence_request: dispute_models::DeleteEvidenceRequest, ) -> RouterResponse { diff --git a/crates/router/src/core/disputes/transformers.rs b/crates/router/src/core/disputes/transformers.rs index 936184fc993..d37410d5ef8 100644 --- a/crates/router/src/core/disputes/transformers.rs +++ b/crates/router/src/core/disputes/transformers.rs @@ -4,7 +4,7 @@ use error_stack::ResultExt; use crate::{ core::{errors, files::helpers::retrieve_file_and_provider_file_id_from_file_id}, - routes::AppState, + routes::SessionState, types::{ api::{self, DisputeEvidence}, domain, @@ -14,7 +14,7 @@ use crate::{ }; pub async fn get_evidence_request_data( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, evidence_request: api_models::disputes::SubmitEvidenceRequest, @@ -203,7 +203,7 @@ pub fn update_dispute_evidence( } pub async fn get_dispute_evidence_block( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, evidence_type: EvidenceType, file_id: String, @@ -271,7 +271,7 @@ pub fn delete_evidence_file( } pub async fn get_dispute_evidence_vec( - state: &AppState, + state: &SessionState, merchant_account: domain::MerchantAccount, dispute_evidence: DisputeEvidence, ) -> CustomResult, errors::ApiErrorResponse> { diff --git a/crates/router/src/core/files.rs b/crates/router/src/core/files.rs index e2ce5b42c3f..e65798ddb92 100644 --- a/crates/router/src/core/files.rs +++ b/crates/router/src/core/files.rs @@ -6,13 +6,13 @@ use error_stack::ResultExt; use super::errors::{self, RouterResponse}; use crate::{ consts, - routes::AppState, + routes::SessionState, services::{self, ApplicationResponse}, types::{api, domain}, }; pub async fn files_create_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, create_file_request: api::CreateFileRequest, @@ -78,7 +78,7 @@ pub async fn files_create_core( } pub async fn files_delete_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: api::FileId, ) -> RouterResponse { @@ -94,7 +94,7 @@ pub async fn files_delete_core( } pub async fn files_retrieve_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: api::FileId, diff --git a/crates/router/src/core/files/helpers.rs b/crates/router/src/core/files/helpers.rs index 0c6a88d8270..0be198377b8 100644 --- a/crates/router/src/core/files/helpers.rs +++ b/crates/router/src/core/files/helpers.rs @@ -8,7 +8,7 @@ use crate::{ errors::{self, StorageErrorExt}, payments, utils, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain, transformers::ForeignTryFrom}, }; @@ -31,7 +31,7 @@ pub async fn get_file_purpose(field: &mut Field) -> Option { } pub async fn validate_file_upload( - state: &AppState, + state: &SessionState, merchant_account: domain::MerchantAccount, create_file_request: api::CreateFileRequest, ) -> CustomResult<(), errors::ApiErrorResponse> { @@ -81,7 +81,7 @@ pub async fn validate_file_upload( } pub async fn delete_file_using_file_id( - state: &AppState, + state: &SessionState, file_key: String, merchant_account: &domain::MerchantAccount, ) -> CustomResult<(), errors::ApiErrorResponse> { @@ -113,7 +113,7 @@ pub async fn delete_file_using_file_id( } pub async fn retrieve_file_from_connector( - state: &AppState, + state: &SessionState, file_metadata: diesel_models::file::FileMetadata, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -171,7 +171,7 @@ pub async fn retrieve_file_from_connector( } pub async fn retrieve_file_and_provider_file_id_from_file_id( - state: &AppState, + state: &SessionState, file_id: Option, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -227,7 +227,7 @@ pub async fn retrieve_file_and_provider_file_id_from_file_id( //Upload file to connector if it supports / store it in S3 and return file_upload_provider, provider_file_id accordingly pub async fn upload_and_get_provider_provider_file_id_profile_id( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, create_file_request: &api::CreateFileRequest, diff --git a/crates/router/src/core/fraud_check.rs b/crates/router/src/core/fraud_check.rs index 0e3f67c051b..45d592177ea 100644 --- a/crates/router/src/core/fraud_check.rs +++ b/crates/router/src/core/fraud_check.rs @@ -26,7 +26,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::AppState, + routes::SessionState, services, types::{ self as oss_types, @@ -47,9 +47,9 @@ pub mod flows; pub mod operation; pub mod types; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn call_frm_service( - state: &AppState, + state: &SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, @@ -356,7 +356,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn make_frm_data_and_fraud_check_operation<'a, F>( _db: &dyn StorageInterface, - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: payments::PaymentData, frm_routing_algorithm: FrmRoutingAlgorithm, @@ -424,7 +424,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn pre_payment_frm_core<'a, F>( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut payments::PaymentData, frm_info: &mut FrmInfo, @@ -492,7 +492,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn post_payment_frm_core<'a, F>( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut payments::PaymentData, frm_info: &mut FrmInfo, @@ -578,7 +578,7 @@ pub async fn call_frm_before_connector_call<'a, F, Req, Ctx>( operation: &BoxedOperation<'_, F, Req, Ctx>, merchant_account: &domain::MerchantAccount, payment_data: &mut payments::PaymentData, - state: &AppState, + state: &SessionState, frm_info: &mut Option>, customer: &Option, should_continue_transaction: &mut bool, @@ -647,9 +647,9 @@ impl From for PaymentDetails { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn frm_fulfillment_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: frm_core_types::FrmFulfillmentRequest, @@ -706,12 +706,12 @@ pub async fn frm_fulfillment_core( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn make_fulfillment_api_call( db: &dyn StorageInterface, fraud_check: FraudCheck, payment_intent: PaymentIntent, - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: frm_core_types::FrmFulfillmentRequest, diff --git a/crates/router/src/core/fraud_check/flows.rs b/crates/router/src/core/fraud_check/flows.rs index 3d4916a372b..896d062bc14 100644 --- a/crates/router/src/core/fraud_check/flows.rs +++ b/crates/router/src/core/fraud_check/flows.rs @@ -11,7 +11,7 @@ use crate::{ errors::RouterResult, payments::{self, flows::ConstructFlowSpecificData}, }, - routes::AppState, + routes::SessionState, services, types::{ api::{Connector, FraudCheckConnectorData}, @@ -24,7 +24,7 @@ use crate::{ pub trait FeatureFrm { async fn decide_frm_flows<'a>( self, - state: &AppState, + state: &SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs index f17a1730088..99946443c0e 100644 --- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs +++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs @@ -19,7 +19,7 @@ use crate::{ storage::enums as storage_enums, BrowserInformation, ConnectorAuthType, ResponseId, RouterData, }, - AppState, + SessionState, }; #[async_trait] @@ -28,7 +28,7 @@ impl ConstructFlowSpecificData( &self, - _state: &AppState, + _state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, @@ -133,7 +133,7 @@ impl ConstructFlowSpecificData for FrmCheckoutRouterData { async fn decide_frm_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, merchant_account: &domain::MerchantAccount, @@ -151,7 +151,7 @@ impl FeatureFrm for FrmCheckoutRouter pub async fn decide_frm_flow<'a, 'b>( router_data: &'b mut FrmCheckoutRouterData, - state: &'a AppState, + state: &'a SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, _merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs index a76408b5d3d..1d0c8a33381 100644 --- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs +++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs @@ -15,12 +15,12 @@ use crate::{ fraud_check::{FraudCheckFulfillmentData, FrmFulfillmentRouterData}, storage, ConnectorAuthType, ErrorResponse, RouterData, }, - utils, AppState, + utils, SessionState, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_fulfillment_router_data<'a>( - state: &'a AppState, + state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs index cba19769d57..bd30a705b66 100644 --- a/crates/router/src/core/fraud_check/flows/record_return.rs +++ b/crates/router/src/core/fraud_check/flows/record_return.rs @@ -19,7 +19,7 @@ use crate::{ storage::enums as storage_enums, ConnectorAuthType, ResponseId, RouterData, }, - utils, AppState, + utils, SessionState, }; #[async_trait] @@ -28,7 +28,7 @@ impl ConstructFlowSpecificData( &self, - _state: &AppState, + _state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, @@ -111,7 +111,7 @@ impl ConstructFlowSpecificData for FrmRecordReturnRouterData { async fn decide_frm_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, merchant_account: &domain::MerchantAccount, @@ -129,7 +129,7 @@ impl FeatureFrm for FrmRecordReturnRou pub async fn decide_frm_flow<'a, 'b>( router_data: &'b mut FrmRecordReturnRouterData, - state: &'a AppState, + state: &'a SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, _merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs index c9f5e4dac0a..deca811b1b0 100644 --- a/crates/router/src/core/fraud_check/flows/sale_flow.rs +++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs @@ -16,7 +16,7 @@ use crate::{ storage::enums as storage_enums, ConnectorAuthType, ResponseId, RouterData, }, - AppState, + SessionState, }; #[async_trait] @@ -25,7 +25,7 @@ impl ConstructFlowSpecificData( &self, - _state: &AppState, + _state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, @@ -107,7 +107,7 @@ impl ConstructFlowSpecificData for FrmSaleRouterData { async fn decide_frm_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, merchant_account: &domain::MerchantAccount, @@ -125,7 +125,7 @@ impl FeatureFrm for FrmSaleRouterData { pub async fn decide_frm_flow<'a, 'b>( router_data: &'b mut FrmSaleRouterData, - state: &'a AppState, + state: &'a SessionState, connector: &FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, _merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs index dc385093f23..8cd9fd9112a 100644 --- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs +++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs @@ -18,7 +18,7 @@ use crate::{ storage::enums as storage_enums, ConnectorAuthType, ResponseId, RouterData, }, - AppState, + SessionState, }; #[async_trait] @@ -31,7 +31,7 @@ impl { async fn construct_router_data<'a>( &self, - _state: &AppState, + _state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, _key_store: &domain::MerchantKeyStore, @@ -123,7 +123,7 @@ impl impl FeatureFrm for FrmTransactionRouterData { async fn decide_frm_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &frm_api::FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, merchant_account: &domain::MerchantAccount, @@ -141,7 +141,7 @@ impl FeatureFrm for FrmTransact pub async fn decide_frm_flow<'a, 'b>( router_data: &'b mut FrmTransactionRouterData, - state: &'a AppState, + state: &'a SessionState, connector: &frm_api::FraudCheckConnectorData, call_connector_action: payments::CallConnectorAction, _merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/operation.rs b/crates/router/src/core/fraud_check/operation.rs index e7677dad6f3..9718082e67b 100644 --- a/crates/router/src/core/fraud_check/operation.rs +++ b/crates/router/src/core/fraud_check/operation.rs @@ -15,7 +15,7 @@ use crate::{ payments, }, db::StorageInterface, - routes::AppState, + routes::SessionState, types::{domain, fraud_check::FrmRouterData}, }; @@ -40,7 +40,7 @@ pub trait FraudCheckOperation: Send + std::fmt::Debug { pub trait GetTracker: Send { async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: D, frm_connector_details: ConnectorDetailsCore, ) -> RouterResult>; @@ -50,7 +50,7 @@ pub trait GetTracker: Send { pub trait Domain: Send + Sync { async fn post_payment_frm<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, @@ -62,7 +62,7 @@ pub trait Domain: Send + Sync { async fn pre_payment_frm<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, @@ -77,7 +77,7 @@ pub trait Domain: Send + Sync { #[allow(clippy::too_many_arguments)] async fn execute_post_tasks( &self, - _state: &AppState, + _state: &SessionState, frm_data: &mut FrmData, _merchant_account: &domain::MerchantAccount, _frm_configs: FrmConfigsObject, diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs index a6cd0976129..2d49081155d 100644 --- a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs +++ b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs @@ -36,7 +36,7 @@ use crate::{ }, ResponseId, }, - utils, AppState, + utils, SessionState, }; #[derive(Debug, Clone, Copy)] @@ -68,10 +68,10 @@ impl FraudCheckOperation for FraudCheckPost { #[async_trait] impl GetTracker for FraudCheckPost { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: PaymentToFrmData, frm_connector_details: ConnectorDetailsCore, ) -> RouterResult> { @@ -136,10 +136,10 @@ impl GetTracker for FraudCheckPost { #[async_trait] impl Domain for FraudCheckPost { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn post_payment_frm<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, @@ -173,10 +173,10 @@ impl Domain for FraudCheckPost { })) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn execute_post_tasks( &self, - state: &AppState, + state: &SessionState, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, frm_configs: FrmConfigsObject, @@ -231,10 +231,10 @@ impl Domain for FraudCheckPost { return Ok(Some(frm_data.to_owned())); } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn pre_payment_frm<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs index ed582574bf5..48804dc7b75 100644 --- a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs +++ b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs @@ -31,7 +31,7 @@ use crate::{ }, ResponseId, }, - AppState, + SessionState, }; #[derive(Debug, Clone, Copy)] @@ -63,10 +63,10 @@ impl FraudCheckOperation for FraudCheckPre { #[async_trait] impl GetTracker for FraudCheckPre { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: PaymentToFrmData, frm_connector_details: ConnectorDetailsCore, ) -> RouterResult> { @@ -134,10 +134,10 @@ impl GetTracker for FraudCheckPre { #[async_trait] impl Domain for FraudCheckPre { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn post_payment_frm<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, @@ -174,7 +174,7 @@ impl Domain for FraudCheckPre { async fn pre_payment_frm<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut payments::PaymentData, frm_data: &mut FrmData, merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/gsm.rs b/crates/router/src/core/gsm.rs index 668c1773e2c..a96227ec181 100644 --- a/crates/router/src/core/gsm.rs +++ b/crates/router/src/core/gsm.rs @@ -11,12 +11,12 @@ use crate::{ db::gsm::GsmInterface, services, types::transformers::ForeignInto, - AppState, + SessionState, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn create_gsm_rule( - state: AppState, + state: SessionState, gsm_rule: gsm_api_types::GsmCreateRequest, ) -> RouterResponse { let db = state.store.as_ref(); @@ -28,9 +28,9 @@ pub async fn create_gsm_rule( .map(|gsm| services::ApplicationResponse::Json(gsm.foreign_into())) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn retrieve_gsm_rule( - state: AppState, + state: SessionState, gsm_request: gsm_api_types::GsmRetrieveRequest, ) -> RouterResponse { let db = state.store.as_ref(); @@ -49,9 +49,9 @@ pub async fn retrieve_gsm_rule( .map(|gsm| services::ApplicationResponse::Json(gsm.foreign_into())) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn update_gsm_rule( - state: AppState, + state: SessionState, gsm_request: gsm_api_types::GsmUpdateRequest, ) -> RouterResponse { let db = state.store.as_ref(); @@ -92,9 +92,9 @@ pub async fn update_gsm_rule( .map(|gsm| services::ApplicationResponse::Json(gsm.foreign_into())) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn delete_gsm_rule( - state: AppState, + state: SessionState, gsm_request: gsm_api_types::GsmDeleteRequest, ) -> RouterResponse { let db = state.store.as_ref(); diff --git a/crates/router/src/core/health_check.rs b/crates/router/src/core/health_check.rs index 9997c6261fd..a0ada5de3ac 100644 --- a/crates/router/src/core/health_check.rs +++ b/crates/router/src/core/health_check.rs @@ -26,7 +26,7 @@ pub trait HealthCheckInterface { } #[async_trait::async_trait] -impl HealthCheckInterface for app::AppState { +impl HealthCheckInterface for app::SessionState { async fn health_check_db(&self) -> CustomResult { let db = &*self.store; db.health_check_db().await?; diff --git a/crates/router/src/core/locker_migration.rs b/crates/router/src/core/locker_migration.rs index 53f503e8711..d07b2310254 100644 --- a/crates/router/src/core/locker_migration.rs +++ b/crates/router/src/core/locker_migration.rs @@ -7,13 +7,13 @@ use futures::TryFutureExt; use super::{errors::StorageErrorExt, payment_methods::cards}; use crate::{ errors, - routes::AppState, + routes::SessionState, services::{self, logger}, types::{api, domain}, }; pub async fn rust_locker_migration( - state: AppState, + state: SessionState, merchant_id: &str, ) -> CustomResult, errors::ApiErrorResponse> { let db = state.store.as_ref(); @@ -75,7 +75,8 @@ pub async fn rust_locker_migration( } pub async fn call_to_locker( - state: &AppState, + state: &SessionState, + payment_methods: Vec, customer_id: &String, merchant_id: &str, @@ -138,6 +139,7 @@ pub async fn call_to_locker( merchant_account, api_enums::LockerChoice::HyperswitchCardVault, Some(pm.locker_id.as_ref().unwrap_or(&pm.payment_method_id)), + ) .await .change_context(errors::ApiErrorResponse::InternalServerError) diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs index 54fec6ab4a2..9adadba9d81 100644 --- a/crates/router/src/core/mandate.rs +++ b/crates/router/src/core/mandate.rs @@ -14,7 +14,7 @@ use crate::{ payments::CallConnectorAction, }, db::StorageInterface, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{ self, @@ -29,9 +29,9 @@ use crate::{ utils::OptionExt, }; -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn get_mandate( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: mandates::MandateId, @@ -53,9 +53,9 @@ pub async fn get_mandate( )) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn revoke_mandate( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: mandates::MandateId, @@ -155,7 +155,7 @@ pub async fn revoke_mandate( } } -#[instrument(skip(db))] +//#\[instrument\(skip(db))] pub async fn update_connector_mandate_id( db: &dyn StorageInterface, merchant_account: String, @@ -207,9 +207,9 @@ pub async fn update_connector_mandate_id( Ok(services::ApplicationResponse::StatusOk) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn get_customer_mandates( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: customers::CustomerId, @@ -257,7 +257,7 @@ where } } pub async fn update_mandate_procedure( - state: &AppState, + state: &SessionState, resp: types::RouterData, mandate: Mandate, merchant_id: &str, @@ -322,7 +322,7 @@ where Ok(resp) } pub async fn mandate_procedure( - state: &AppState, + state: &SessionState, mut resp: types::RouterData, maybe_customer: &Option, pm_id: Option, @@ -467,9 +467,9 @@ where Ok(resp) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn retrieve_mandates_list( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, constraints: api_models::mandates::MandateListConstraints, diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs index c15969fd1c8..1bc07d3be31 100644 --- a/crates/router/src/core/mandate/helpers.rs +++ b/crates/router/src/core/mandate/helpers.rs @@ -7,12 +7,12 @@ use error_stack::ResultExt; use crate::{ core::{errors, payments}, - routes::AppState, + routes::SessionState, types::{api, domain}, }; pub async fn get_profile_id_for_mandate( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, mandate: Mandate, ) -> CustomResult { diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs index 63a3e9a498b..c63242ad0fd 100644 --- a/crates/router/src/core/payment_link.rs +++ b/crates/router/src/core/payment_link.rs @@ -14,7 +14,7 @@ use time::PrimitiveDateTime; use super::errors::{self, RouterResult, StorageErrorExt}; use crate::{ errors::RouterResponse, - routes::AppState, + routes::SessionState, services, types::{ api::payment_link::PaymentLinkResponseExt, domain, storage::enums as storage_enums, @@ -23,7 +23,7 @@ use crate::{ }; pub async fn retrieve_payment_link( - state: AppState, + state: SessionState, payment_link_id: String, ) -> RouterResponse { let db = &*state.store; @@ -47,7 +47,7 @@ pub async fn retrieve_payment_link( } pub async fn initiate_payment_link_flow( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, merchant_id: String, payment_id: String, @@ -283,7 +283,7 @@ fn validate_sdk_requirements( } pub async fn list_payment_link( - state: AppState, + state: SessionState, merchant: domain::MerchantAccount, constraints: api_models::payments::PaymentLinkListConstraints, ) -> RouterResponse> { @@ -471,7 +471,7 @@ fn check_payment_link_invalid_conditions( } pub async fn get_payment_link_status( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, merchant_id: String, payment_id: String, diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 2b7577e1fb8..290a6cfdd58 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -12,7 +12,7 @@ use diesel_models::enums; use crate::{ core::{errors::RouterResult, payments::helpers, pm_auth as core_pm_auth}, - routes::AppState, + routes::SessionState, types::{ api::{self, payments}, domain, storage, @@ -25,14 +25,14 @@ pub struct Oss; pub trait PaymentMethodRetrieve { async fn retrieve_payment_method( pm_data: &Option, - state: &AppState, + state: &SessionState, payment_intent: &PaymentIntent, payment_attempt: &PaymentAttempt, merchant_key_store: &domain::MerchantKeyStore, ) -> RouterResult<(Option, Option)>; async fn retrieve_payment_method_with_token( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, token: &storage::PaymentTokenData, payment_intent: &PaymentIntent, @@ -46,7 +46,7 @@ pub trait PaymentMethodRetrieve { impl PaymentMethodRetrieve for Oss { async fn retrieve_payment_method( pm_data: &Option, - state: &AppState, + state: &SessionState, payment_intent: &PaymentIntent, payment_attempt: &PaymentAttempt, merchant_key_store: &domain::MerchantKeyStore, @@ -117,7 +117,7 @@ impl PaymentMethodRetrieve for Oss { } async fn retrieve_payment_method_with_token( - state: &AppState, + state: &SessionState, merchant_key_store: &domain::MerchantKeyStore, token_data: &storage::PaymentTokenData, payment_intent: &PaymentIntent, diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index c885a3bf227..1c45e711074 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -74,7 +74,7 @@ use crate::{ utils::{self, ConnectorResponseExt, OptionExt}, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_payment_method( db: &dyn db::StorageInterface, @@ -168,7 +168,7 @@ pub fn store_default_payment_method( (payment_method_response, None) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_or_insert_payment_method( db: &dyn db::StorageInterface, req: api::PaymentMethodCreate, @@ -236,9 +236,9 @@ pub async fn get_or_insert_payment_method( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn add_payment_method( - state: routes::AppState, + state: routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -464,9 +464,9 @@ pub async fn insert_payment_method( .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn update_customer_payment_method( - state: routes::AppState, + state: routes::SessionState, merchant_account: domain::MerchantAccount, req: api::PaymentMethodUpdate, payment_method_id: &str, @@ -519,7 +519,7 @@ pub async fn update_customer_payment_method( #[cfg(feature = "payouts")] pub async fn add_bank_to_locker( - state: &routes::AppState, + state: &routes::SessionState, req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -583,7 +583,7 @@ pub async fn add_bank_to_locker( /// The response will be the tuple of PaymentMethodResponse and the duplication check of payment_method pub async fn add_card_to_locker( - state: &routes::AppState, + state: &routes::SessionState, req: api::PaymentMethodCreate, card: &api::CardDetail, customer_id: &String, @@ -630,7 +630,7 @@ pub async fn add_card_to_locker( } pub async fn get_card_from_locker( - state: &routes::AppState, + state: &routes::SessionState, customer_id: &str, merchant_id: &str, card_reference: &str, @@ -671,7 +671,7 @@ pub async fn get_card_from_locker( } pub async fn delete_card_from_locker( - state: &routes::AppState, + state: &routes::SessionState, customer_id: &str, merchant_id: &str, card_reference: &str, @@ -693,9 +693,9 @@ pub async fn delete_card_from_locker( .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn add_card_hs( - state: &routes::AppState, + state: &routes::SessionState, req: api::PaymentMethodCreate, card: &api::CardDetail, customer_id: String, @@ -736,7 +736,7 @@ pub async fn add_card_hs( Ok((payment_method_resp, store_card_payload.duplication_check)) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn decode_and_decrypt_locker_data( key_store: &domain::MerchantKeyStore, enc_card_data: String, @@ -757,9 +757,9 @@ pub async fn decode_and_decrypt_locker_data( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_payment_method_from_hs_locker<'a>( - state: &'a routes::AppState, + state: &'a routes::SessionState, key_store: &domain::MerchantKeyStore, customer_id: &str, merchant_id: &str, @@ -819,9 +819,9 @@ pub async fn get_payment_method_from_hs_locker<'a>( Ok(payment_method_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn call_to_locker_hs<'a>( - state: &routes::AppState, + state: &routes::SessionState, payload: &payment_methods::StoreLockerReq<'a>, customer_id: &str, locker_choice: api_enums::LockerChoice, @@ -892,9 +892,9 @@ pub async fn update_payment_method_connector_mandate_details( .change_context(errors::VaultError::UpdateInPaymentMethodDataTableFailed)?; Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_card_from_hs_locker<'a>( - state: &'a routes::AppState, + state: &'a routes::SessionState, customer_id: &str, merchant_id: &str, card_reference: &'a str, @@ -945,9 +945,9 @@ pub async fn get_card_from_hs_locker<'a>( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn delete_card_from_hs_locker<'a>( - state: &routes::AppState, + state: &routes::SessionState, customer_id: &str, merchant_id: &str, card_reference: &'a str, @@ -1052,7 +1052,7 @@ pub async fn mock_call_to_locker_hs<'a>( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn mock_get_card<'a>( db: &dyn db::StorageInterface, card_id: &'a str, @@ -1088,7 +1088,7 @@ pub async fn mock_get_card<'a>( )) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn mock_get_payment_method<'a>( db: &dyn db::StorageInterface, key_store: &domain::MerchantKeyStore, @@ -1119,7 +1119,7 @@ pub async fn mock_get_payment_method<'a>( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn mock_delete_card_hs<'a>( db: &dyn db::StorageInterface, card_id: &'a str, @@ -1134,7 +1134,7 @@ pub async fn mock_delete_card_hs<'a>( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn mock_delete_card<'a>( db: &dyn db::StorageInterface, card_id: &'a str, @@ -1152,7 +1152,7 @@ pub async fn mock_delete_card<'a>( } //------------------------------------------------------------------------------ pub fn get_banks( - state: &routes::AppState, + state: &routes::SessionState, pm_type: common_enums::enums::PaymentMethodType, connectors: Vec, ) -> Result, errors::ApiErrorResponse> { @@ -1234,7 +1234,7 @@ fn get_val(str: String, val: &serde_json::Value) -> Option { } pub async fn list_payment_methods( - state: routes::AppState, + state: routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, mut req: api::PaymentMethodListRequest, @@ -2087,7 +2087,7 @@ pub async fn list_payment_methods( } pub async fn call_surcharge_decision_management( - state: routes::AppState, + state: routes::SessionState, merchant_account: &domain::MerchantAccount, business_profile: &BusinessProfile, payment_attempt: &storage::PaymentAttempt, @@ -2137,7 +2137,7 @@ pub async fn call_surcharge_decision_management( } pub async fn call_surcharge_decision_management_for_saved_card( - state: &routes::AppState, + state: &routes::SessionState, merchant_account: &domain::MerchantAccount, business_profile: &BusinessProfile, payment_attempt: &storage::PaymentAttempt, @@ -2720,7 +2720,7 @@ async fn filter_payment_mandate_based( } pub async fn do_list_customer_pm_fetch_customer_if_not_passed( - state: routes::AppState, + state: routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: Option, @@ -2776,7 +2776,7 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed( } pub async fn list_customer_payment_method( - state: &routes::AppState, + state: &routes::SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, payment_intent: Option, @@ -3078,7 +3078,7 @@ pub async fn list_customer_payment_method( pub async fn get_card_details_with_locker_fallback( pm: &payment_method::PaymentMethod, key: &[u8], - state: &routes::AppState, + state: &routes::SessionState, ) -> errors::RouterResult> { let card_decrypted = decrypt::(pm.payment_method_data.clone(), key) @@ -3109,7 +3109,7 @@ pub async fn get_card_details_with_locker_fallback( pub async fn get_card_details_without_locker_fallback( pm: &payment_method::PaymentMethod, key: &[u8], - state: &routes::AppState, + state: &routes::SessionState, ) -> errors::RouterResult { let card_decrypted = decrypt::(pm.payment_method_data.clone(), key) @@ -3134,7 +3134,7 @@ pub async fn get_card_details_without_locker_fallback( } pub async fn get_card_details_from_locker( - state: &routes::AppState, + state: &routes::SessionState, pm: &storage::PaymentMethod, ) -> errors::RouterResult { let card = get_card_from_locker( @@ -3153,7 +3153,7 @@ pub async fn get_card_details_from_locker( } pub async fn get_lookup_key_from_locker( - state: &routes::AppState, + state: &routes::SessionState, payment_token: &str, pm: &storage::PaymentMethod, merchant_key_store: &domain::MerchantKeyStore, @@ -3328,7 +3328,7 @@ pub async fn set_default_payment_method( pub async fn update_last_used_at( pm_id: &str, - state: &routes::AppState, + state: &routes::SessionState, storage_scheme: MerchantStorageScheme, ) -> errors::RouterResult<()> { let update_last_used = storage::PaymentMethodUpdate::LastUsedUpdate { @@ -3350,7 +3350,7 @@ pub async fn update_last_used_at( } #[cfg(feature = "payouts")] pub async fn get_bank_from_hs_locker( - state: &routes::AppState, + state: &routes::SessionState, key_store: &domain::MerchantKeyStore, temp_token: &str, customer_id: &str, @@ -3401,9 +3401,9 @@ pub async fn get_bank_from_hs_locker( pub struct TempLockerCardSupport; impl TempLockerCardSupport { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn create_payment_method_data_in_temp_locker( - state: &routes::AppState, + state: &routes::SessionState, payment_token: &str, card: api::CardDetailFromLocker, pm: &storage::PaymentMethod, @@ -3486,9 +3486,9 @@ impl TempLockerCardSupport { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn retrieve_payment_method( - state: routes::AppState, + state: routes::SessionState, pm: api::PaymentMethodId, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, @@ -3541,9 +3541,9 @@ pub async fn retrieve_payment_method( )) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn delete_payment_method( - state: routes::AppState, + state: routes::SessionState, merchant_account: domain::MerchantAccount, pm_id: api::PaymentMethodId, key_store: domain::MerchantKeyStore, @@ -3665,7 +3665,7 @@ pub async fn create_encrypted_payment_method_data( } pub async fn list_countries_currencies_for_connector_payment_method( - state: routes::AppState, + state: routes::SessionState, req: ListCountriesCurrenciesRequest, ) -> errors::RouterResponse { Ok(services::ApplicationResponse::Json( diff --git a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs index e89fb22e879..1971bc918d4 100644 --- a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs +++ b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs @@ -29,7 +29,7 @@ use crate::{ conditional_configs::ConditionalConfigResult, routing::make_dsl_input_for_surcharge, }, }, - AppState, + SessionState, }; struct VirInterpreterBackendCacheWrapper { @@ -96,7 +96,7 @@ impl SurchargeSource { } pub async fn perform_surcharge_decision_management_for_payment_method_list( - state: &AppState, + state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &oss_storage::PaymentAttempt, payment_intent: &oss_storage::PaymentIntent, @@ -216,7 +216,7 @@ pub async fn perform_surcharge_decision_management_for_payment_method_list( } pub async fn perform_surcharge_decision_management_for_session_flow( - state: &AppState, + state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_data: &mut PaymentData, payment_method_type_list: &Vec, @@ -277,7 +277,7 @@ where Ok(surcharge_metadata) } pub async fn perform_surcharge_decision_management_for_saved_cards( - state: &AppState, + state: &SessionState, algorithm_ref: routing::RoutingAlgorithmRef, payment_attempt: &oss_storage::PaymentAttempt, payment_intent: &oss_storage::PaymentIntent, @@ -385,7 +385,7 @@ fn get_surcharge_details_from_surcharge_output( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn ensure_algorithm_cached( store: &dyn StorageInterface, merchant_id: &str, @@ -408,7 +408,7 @@ pub async fn ensure_algorithm_cached( Ok(key) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn refresh_surcharge_algorithm_cache( store: &dyn StorageInterface, key: String, diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs index 1bfa4830291..6b3723a17c2 100644 --- a/crates/router/src/core/payment_methods/vault.rs +++ b/crates/router/src/core/payment_methods/vault.rs @@ -689,9 +689,9 @@ pub struct MockTokenizeDBValue { pub struct Vault; impl Vault { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn get_payment_method_data_from_locker( - state: &routes::AppState, + state: &routes::SessionState, lookup_key: &str, merchant_key_store: &domain::MerchantKeyStore, ) -> RouterResult<(Option, SupplementaryVaultData)> { @@ -705,9 +705,9 @@ impl Vault { Ok((Some(payment_method), customer_id)) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn store_payment_method_data_in_locker( - state: &routes::AppState, + state: &routes::SessionState, token_id: Option, payment_method: &api::PaymentMethodData, customer_id: Option, @@ -740,9 +740,9 @@ impl Vault { } #[cfg(feature = "payouts")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn get_payout_method_data_from_temporary_locker( - state: &routes::AppState, + state: &routes::SessionState, lookup_key: &str, merchant_key_store: &domain::MerchantKeyStore, ) -> RouterResult<(Option, SupplementaryVaultData)> { @@ -757,9 +757,9 @@ impl Vault { } #[cfg(feature = "payouts")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn store_payout_method_data_in_locker( - state: &routes::AppState, + state: &routes::SessionState, token_id: Option, payout_method: &api::PayoutMethodData, customer_id: Option, @@ -791,9 +791,9 @@ impl Vault { Ok(lookup_key) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn delete_locker_payment_method_by_lookup_key( - state: &routes::AppState, + state: &routes::SessionState, lookup_key: &Option, ) { if let Some(lookup_key) = lookup_key { @@ -813,9 +813,9 @@ fn get_redis_locker_key(lookup_key: &str) -> String { format!("{}_{}", consts::LOCKER_REDIS_PREFIX, lookup_key) } -#[instrument(skip(state, value1, value2))] +//#\[instrument\(skip(state, value1, value2))] pub async fn create_tokenize( - state: &routes::AppState, + state: &routes::SessionState, value1: String, value2: Option, lookup_key: String, @@ -878,9 +878,9 @@ pub async fn create_tokenize( } } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn get_tokenized_data( - state: &routes::AppState, + state: &routes::SessionState, lookup_key: &str, _should_get_value2: bool, encryption_key: &masking::Secret>, @@ -941,8 +941,11 @@ pub async fn get_tokenized_data( } } -#[instrument(skip(state))] -pub async fn delete_tokenized_data(state: &routes::AppState, lookup_key: &str) -> RouterResult<()> { +//#\[instrument\(skip(state))] +pub async fn delete_tokenized_data( + state: &routes::SessionState, + lookup_key: &str, +) -> RouterResult<()> { let redis_key = get_redis_locker_key(lookup_key); let func = || async { metrics::DELETED_TOKENIZED_CARD.add(&metrics::CONTEXT, 1, &[]); @@ -1026,7 +1029,7 @@ pub async fn add_delete_tokenized_data_task( } pub async fn start_tokenize_data_workflow( - state: &routes::AppState, + state: &routes::SessionState, tokenize_tracker: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { let db = &*state.store; diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 4c087671a29..d37b38403f9 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -62,7 +62,9 @@ use crate::{ }, db::StorageInterface, logger, - routes::{app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, AppState}, + routes::{ + app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, SessionState, + }, services::{self, api::Authenticate}, types::{ self as router_types, @@ -80,9 +82,9 @@ use crate::{ }; #[allow(clippy::too_many_arguments, clippy::type_complexity)] -#[instrument(skip_all, fields(payment_id, merchant_id))] +//#\[instrument\(skip_all, fields(payment_id, merchant_id))] pub async fn payments_operation_core( - state: &AppState, + state: &SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, @@ -507,9 +509,9 @@ where )) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn call_decision_manager( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut PaymentData, ) -> RouterResult<()> @@ -542,9 +544,9 @@ where Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn populate_surcharge_details( - state: &AppState, + state: &SessionState, payment_data: &mut PaymentData, ) -> RouterResult<()> where @@ -622,9 +624,9 @@ pub fn get_connector_data( .attach_printable("Connector not found in connectors iterator") } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn call_surcharge_decision_management_for_session_flow( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut PaymentData, session_connector_data: &[api::SessionConnectorData], @@ -679,7 +681,7 @@ where } #[allow(clippy::too_many_arguments)] pub async fn payments_core( - state: AppState, + state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, @@ -761,7 +763,7 @@ pub struct PaymentsRedirectResponseData { pub trait PaymentRedirectFlow: Sync { async fn call_payment_flow( &self, - state: &AppState, + state: &SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, merchant_key_store: domain::MerchantKeyStore, @@ -782,7 +784,7 @@ pub trait PaymentRedirectFlow: Sync { #[allow(clippy::too_many_arguments)] async fn handle_payments_redirect_response( &self, - state: AppState, + state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, @@ -872,7 +874,7 @@ pub struct PaymentRedirectCompleteAuthorize; impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize { async fn call_payment_flow( &self, - state: &AppState, + state: &SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, merchant_key_store: domain::MerchantKeyStore, @@ -977,7 +979,7 @@ pub struct PaymentRedirectSync; impl PaymentRedirectFlow for PaymentRedirectSync { async fn call_payment_flow( &self, - state: &AppState, + state: &SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, merchant_key_store: domain::MerchantKeyStore, @@ -1050,7 +1052,7 @@ pub struct PaymentAuthenticateCompleteAuthorize; impl PaymentRedirectFlow for PaymentAuthenticateCompleteAuthorize { async fn call_payment_flow( &self, - state: &AppState, + state: &SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, merchant_key_store: domain::MerchantKeyStore, @@ -1148,9 +1150,9 @@ impl PaymentRedirectFlow for PaymentAuthenticat } #[allow(clippy::too_many_arguments)] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn call_connector_service( - state: &AppState, + state: &SessionState, req_state: ReqState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -1384,7 +1386,7 @@ where } async fn blocklist_guard( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, operation: &BoxedOperation<'_, F, ApiRequest, Ctx>, payment_data: &mut PaymentData, @@ -1424,7 +1426,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn call_multiple_connectors_service( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, connectors: Vec, @@ -1544,7 +1546,7 @@ where } pub async fn call_create_connector_customer_if_required( - state: &AppState, + state: &SessionState, customer: &Option, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -1646,7 +1648,7 @@ where } async fn complete_preprocessing_steps_if_required( - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, payment_data: &PaymentData, mut router_data: router_types::RouterData, @@ -1773,9 +1775,9 @@ pub fn is_preprocessing_required_for_wallets(connector_name: String) -> bool { connector_name == *"trustpay" || connector_name == *"payme" } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_profile_id_and_get_mca<'a, F>( - state: &'a AppState, + state: &'a SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut PaymentData, connector_name: &str, @@ -1813,7 +1815,7 @@ where } fn is_payment_method_tokenization_enabled_for_connector( - state: &AppState, + state: &SessionState, connector_name: &str, payment_method: &storage::enums::PaymentMethod, payment_method_type: &Option, @@ -1934,7 +1936,7 @@ fn is_payment_method_type_allowed_for_connector( } async fn decide_payment_method_tokenize_action( - state: &AppState, + state: &SessionState, connector_name: &str, payment_method: &storage::enums::PaymentMethod, pm_parent_token: Option<&String>, @@ -2007,7 +2009,7 @@ pub enum TokenizationAction { #[allow(clippy::too_many_arguments)] pub async fn get_connector_tokenization_action_when_confirm_true( - state: &AppState, + state: &SessionState, operation: &BoxedOperation<'_, F, Req, Ctx>, payment_data: &mut PaymentData, validate_result: &operations::ValidateResult<'_>, @@ -2132,7 +2134,7 @@ where } pub async fn tokenize_in_router_when_confirm_false_or_external_authentication( - state: &AppState, + state: &SessionState, operation: &BoxedOperation<'_, F, Req, Ctx>, payment_data: &mut PaymentData, validate_result: &operations::ValidateResult<'_>, @@ -2465,7 +2467,7 @@ pub fn is_operation_complete_authorize(operation: &Op) -> bool { #[cfg(feature = "olap")] pub async fn list_payments( - state: AppState, + state: SessionState, merchant: domain::MerchantAccount, constraints: api::PaymentListConstraints, ) -> RouterResponse { @@ -2531,7 +2533,7 @@ pub async fn list_payments( } #[cfg(feature = "olap")] pub async fn apply_filters_on_payments( - state: AppState, + state: SessionState, merchant: domain::MerchantAccount, constraints: api::PaymentListFilterConstraints, ) -> RouterResponse { @@ -2583,7 +2585,7 @@ pub async fn apply_filters_on_payments( #[cfg(feature = "olap")] pub async fn get_filters_for_payments( - state: AppState, + state: SessionState, merchant: domain::MerchantAccount, time_range: api::TimeRange, ) -> RouterResponse { @@ -2696,7 +2698,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn get_connector_choice( operation: &BoxedOperation<'_, F, Req, Ctx>, - state: &AppState, + state: &SessionState, req: &Req, merchant_account: &domain::MerchantAccount, business_profile: &storage::business_profile::BusinessProfile, @@ -2776,7 +2778,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn connector_selection( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, business_profile: &storage::business_profile::BusinessProfile, key_store: &domain::MerchantKeyStore, @@ -2851,7 +2853,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn decide_connector( - state: AppState, + state: SessionState, merchant_account: &domain::MerchantAccount, business_profile: &storage::business_profile::BusinessProfile, key_store: &domain::MerchantKeyStore, @@ -3067,7 +3069,7 @@ where } pub async fn decide_multiplex_connector_for_normal_or_recurring_payment( - state: &AppState, + state: &SessionState, payment_data: &mut PaymentData, routing_data: &mut storage::RoutingData, connectors: Vec, @@ -3259,7 +3261,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment(payment_data: &PaymentData( - state: AppState, + state: SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, payment_data: &mut PaymentData, @@ -3400,7 +3402,7 @@ where #[allow(clippy::too_many_arguments)] pub async fn route_connector_v1( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, business_profile: &storage::business_profile::BusinessProfile, key_store: &domain::MerchantKeyStore, @@ -3521,9 +3523,9 @@ where } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn payment_external_authentication( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: api_models::payments::PaymentsExternalAuthenticationRequest, diff --git a/crates/router/src/core/payments/access_token.rs b/crates/router/src/core/payments/access_token.rs index 47f6b7e2ae4..6bc6386f454 100644 --- a/crates/router/src/core/payments/access_token.rs +++ b/crates/router/src/core/payments/access_token.rs @@ -9,7 +9,7 @@ use crate::{ errors::{self, RouterResult}, payments, }, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{self, api as api_types, domain}, }; @@ -53,7 +53,7 @@ pub async fn add_access_token< Req: Debug + Clone + 'static, Res: Debug + Clone + 'static, >( - state: &AppState, + state: &SessionState, connector: &api_types::ConnectorData, merchant_account: &domain::MerchantAccount, router_data: &types::RouterData, @@ -135,7 +135,7 @@ pub async fn add_access_token< } pub async fn refresh_connector_auth( - state: &AppState, + state: &SessionState, connector: &api_types::ConnectorData, _merchant_account: &domain::MerchantAccount, router_data: &types::RouterData< diff --git a/crates/router/src/core/payments/conditional_configs.rs b/crates/router/src/core/payments/conditional_configs.rs index 5dc78d42e5e..e511d45265d 100644 --- a/crates/router/src/core/payments/conditional_configs.rs +++ b/crates/router/src/core/payments/conditional_configs.rs @@ -19,9 +19,9 @@ static CONF_CACHE: StaticCache = errors::CustomResult; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn perform_decision_management( - state: &routes::AppState, + state: &routes::SessionState, algorithm_ref: routing::RoutingAlgorithmRef, merchant_id: &str, payment_data: &mut payments::PaymentData, @@ -49,9 +49,9 @@ pub async fn perform_decision_management( execute_dsl_and_get_conditional_config(backend_input, interpreter).await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn ensure_algorithm_cached( - state: &routes::AppState, + state: &routes::SessionState, merchant_id: &str, timestamp: i64, algorithm_id: &str, @@ -71,9 +71,9 @@ pub async fn ensure_algorithm_cached( Ok(key) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn refresh_routing_cache( - state: &routes::AppState, + state: &routes::SessionState, key: String, algorithm_id: &str, timestamp: i64, diff --git a/crates/router/src/core/payments/customers.rs b/crates/router/src/core/payments/customers.rs index ff56eaf46eb..2fdfe299ad1 100644 --- a/crates/router/src/core/payments/customers.rs +++ b/crates/router/src/core/payments/customers.rs @@ -6,14 +6,14 @@ use crate::{ payments, }, logger, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{self, api, domain, storage}, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn create_connector_customer( - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, router_data: &types::RouterData, customer_request_data: types::ConnectorCustomerData, @@ -88,7 +88,7 @@ pub fn get_connector_customer_details_if_present<'a>( } pub fn should_call_connector_create_customer<'a>( - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, customer: &'a Option, connector_label: &str, @@ -111,7 +111,7 @@ pub fn should_call_connector_create_customer<'a>( } } -#[instrument] +//#[instrument] pub async fn update_connector_customer_in_customers( connector_label: &str, customer: Option<&domain::Customer>, diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs index 3f8d56a3726..cb74edba5b7 100644 --- a/crates/router/src/core/payments/flows.rs +++ b/crates/router/src/core/payments/flows.rs @@ -19,7 +19,7 @@ use crate::{ errors::{ConnectorError, CustomResult, RouterResult}, payments::{self, helpers}, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain}, }; @@ -28,7 +28,7 @@ use crate::{ pub trait ConstructFlowSpecificData { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -42,7 +42,7 @@ pub trait ConstructFlowSpecificData { pub trait Feature { async fn decide_flows<'a>( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, maybe_customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -58,7 +58,7 @@ pub trait Feature { async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult @@ -69,7 +69,7 @@ pub trait Feature { async fn add_payment_method_token<'a>( &mut self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, _tokenization_action: &payments::TokenizationAction, ) -> RouterResult> @@ -83,7 +83,7 @@ pub trait Feature { async fn preprocessing_steps<'a>( self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, ) -> RouterResult where @@ -96,7 +96,7 @@ pub trait Feature { async fn create_connector_customer<'a>( &self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, ) -> RouterResult> where @@ -110,7 +110,7 @@ pub trait Feature { /// Returns the connector request and a bool which specifies whether to proceed with further async fn build_flow_specific_connector_request( &mut self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, _call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { diff --git a/crates/router/src/core/payments/flows/approve_flow.rs b/crates/router/src/core/payments/flows/approve_flow.rs index 43e36847eb9..f4ba187e7d2 100644 --- a/crates/router/src/core/payments/flows/approve_flow.rs +++ b/crates/router/src/core/payments/flows/approve_flow.rs @@ -6,7 +6,7 @@ use crate::{ errors::{api_error_response::NotImplementedMessage, ApiErrorResponse, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain}, }; @@ -18,7 +18,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -47,7 +47,7 @@ impl Feature { async fn decide_flows<'a>( self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, _customer: &Option, _call_connector_action: payments::CallConnectorAction, @@ -64,7 +64,7 @@ impl Feature async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -73,7 +73,7 @@ impl Feature async fn build_flow_specific_connector_request( &mut self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, _call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index cccfab5a74b..426bee6d0da 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -12,7 +12,7 @@ use crate::{ }, }, logger, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{self, api, domain}, }; @@ -27,7 +27,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -59,7 +59,7 @@ impl impl Feature for types::PaymentsAuthorizeRouterData { async fn decide_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, maybe_customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -187,7 +187,7 @@ impl Feature for types::PaymentsAu async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -196,7 +196,7 @@ impl Feature for types::PaymentsAu async fn add_payment_method_token<'a>( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, tokenization_action: &payments::TokenizationAction, ) -> RouterResult> { @@ -213,7 +213,7 @@ impl Feature for types::PaymentsAu async fn preprocessing_steps<'a>( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, ) -> RouterResult { authorize_preprocessing_steps(state, &self, true, connector).await @@ -221,7 +221,7 @@ impl Feature for types::PaymentsAu async fn create_connector_customer<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, ) -> RouterResult> { customers::create_connector_customer( @@ -235,7 +235,7 @@ impl Feature for types::PaymentsAu async fn build_flow_specific_connector_request( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { @@ -338,7 +338,7 @@ impl mandate::MandateBehaviour for types::PaymentsAuthorizeData { } pub async fn authorize_preprocessing_steps( - state: &AppState, + state: &SessionState, router_data: &types::RouterData, confirm: bool, connector: &api::ConnectorData, diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rs index 5814b1cafb1..41fd1307a33 100644 --- a/crates/router/src/core/payments/flows/cancel_flow.rs +++ b/crates/router/src/core/payments/flows/cancel_flow.rs @@ -6,7 +6,7 @@ use crate::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{self, api, domain}, }; @@ -17,7 +17,7 @@ impl ConstructFlowSpecificData( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -46,7 +46,7 @@ impl Feature { async fn decide_flows<'a>( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, _customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -86,7 +86,7 @@ impl Feature async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -95,7 +95,7 @@ impl Feature async fn build_flow_specific_connector_request( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rs index 5f64014bce7..dc055efa198 100644 --- a/crates/router/src/core/payments/flows/capture_flow.rs +++ b/crates/router/src/core/payments/flows/capture_flow.rs @@ -6,7 +6,7 @@ use crate::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain}, }; @@ -18,7 +18,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -47,7 +47,7 @@ impl Feature { async fn decide_flows<'a>( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, _customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -78,7 +78,7 @@ impl Feature async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -87,7 +87,7 @@ impl Feature async fn build_flow_specific_connector_request( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { diff --git a/crates/router/src/core/payments/flows/complete_authorize_flow.rs b/crates/router/src/core/payments/flows/complete_authorize_flow.rs index e64240387d2..a66798eb96e 100644 --- a/crates/router/src/core/payments/flows/complete_authorize_flow.rs +++ b/crates/router/src/core/payments/flows/complete_authorize_flow.rs @@ -6,7 +6,7 @@ use crate::{ errors::{self, ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{self, api, domain}, utils::OptionExt, @@ -22,7 +22,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -61,7 +61,7 @@ impl Feature { async fn decide_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, _customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -92,7 +92,7 @@ impl Feature async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -101,7 +101,7 @@ impl Feature async fn add_payment_method_token<'a>( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, _tokenization_action: &payments::TokenizationAction, ) -> RouterResult> { @@ -123,7 +123,7 @@ impl Feature async fn build_flow_specific_connector_request( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { @@ -148,7 +148,7 @@ impl Feature async fn preprocessing_steps<'a>( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, ) -> RouterResult { complete_authorize_preprocessing_steps(state, &self, true, connector).await @@ -156,7 +156,7 @@ impl Feature } pub async fn complete_authorize_preprocessing_steps( - state: &AppState, + state: &SessionState, router_data: &types::RouterData, confirm: bool, connector: &api::ConnectorData, diff --git a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs index 99f8e4831bb..63950ddb5d7 100644 --- a/crates/router/src/core/payments/flows/incremental_authorization_flow.rs +++ b/crates/router/src/core/payments/flows/incremental_authorization_flow.rs @@ -6,7 +6,7 @@ use crate::{ errors::{ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, Feature, PaymentData}, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain}, }; @@ -21,7 +21,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -54,7 +54,7 @@ impl Feature( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, _customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -85,7 +85,7 @@ impl Feature( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -94,7 +94,7 @@ impl Feature RouterResult<(Option, bool)> { diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs index 6463e87279b..7b7e66b391d 100644 --- a/crates/router/src/core/payments/flows/psync_flow.rs +++ b/crates/router/src/core/payments/flows/psync_flow.rs @@ -8,7 +8,7 @@ use crate::{ errors::{ApiErrorResponse, ConnectorErrorExt, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, - routes::AppState, + routes::SessionState, services::{self, logger}, types::{self, api, domain}, }; @@ -19,7 +19,7 @@ impl ConstructFlowSpecificData( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -50,7 +50,7 @@ impl Feature { async fn decide_flows<'a>( mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, _customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -104,7 +104,7 @@ impl Feature async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -113,7 +113,7 @@ impl Feature async fn build_flow_specific_connector_request( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { @@ -151,7 +151,7 @@ impl Feature impl types::RouterData { async fn execute_connector_processing_step_for_each_capture( mut self, - state: &AppState, + state: &SessionState, pending_connector_capture_id_list: Vec, call_connector_action: payments::CallConnectorAction, connector_integration: services::BoxedConnectorIntegration< diff --git a/crates/router/src/core/payments/flows/reject_flow.rs b/crates/router/src/core/payments/flows/reject_flow.rs index 4157edf8d0a..6c186fcffa4 100644 --- a/crates/router/src/core/payments/flows/reject_flow.rs +++ b/crates/router/src/core/payments/flows/reject_flow.rs @@ -6,7 +6,7 @@ use crate::{ errors::{api_error_response::NotImplementedMessage, ApiErrorResponse, RouterResult}, payments::{self, access_token, helpers, transformers, PaymentData}, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain}, }; @@ -17,7 +17,7 @@ impl ConstructFlowSpecificData( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -46,7 +46,7 @@ impl Feature { async fn decide_flows<'a>( self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, _customer: &Option, _call_connector_action: payments::CallConnectorAction, @@ -63,7 +63,7 @@ impl Feature async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -72,7 +72,7 @@ impl Feature async fn build_flow_specific_connector_request( &mut self, - _state: &AppState, + _state: &SessionState, _connector: &api::ConnectorData, _call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs index 7e15e2ed3f9..a32fa608f93 100644 --- a/crates/router/src/core/payments/flows/session_flow.rs +++ b/crates/router/src/core/payments/flows/session_flow.rs @@ -24,7 +24,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &routes::AppState, + state: &routes::SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -51,7 +51,7 @@ impl impl Feature for types::PaymentsSessionRouterData { async fn decide_flows<'a>( self, - state: &routes::AppState, + state: &routes::SessionState, connector: &api::ConnectorData, customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -80,7 +80,7 @@ impl Feature for types::PaymentsSessio async fn add_access_token<'a>( &self, - state: &routes::AppState, + state: &routes::SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -119,7 +119,7 @@ fn get_applepay_metadata( } fn build_apple_pay_session_request( - state: &routes::AppState, + state: &routes::SessionState, request: payment_types::ApplepaySessionRequest, apple_pay_merchant_cert: String, apple_pay_merchant_cert_key: String, @@ -143,7 +143,7 @@ fn build_apple_pay_session_request( } async fn create_applepay_session_token( - state: &routes::AppState, + state: &routes::SessionState, router_data: &types::PaymentsSessionRouterData, connector: &api::ConnectorData, ) -> RouterResult { @@ -418,7 +418,7 @@ fn create_apple_pay_session_response( } fn create_gpay_session_token( - state: &routes::AppState, + state: &routes::SessionState, router_data: &types::PaymentsSessionRouterData, connector: &api::ConnectorData, ) -> RouterResult { @@ -495,7 +495,10 @@ fn create_gpay_session_token( } } -fn is_session_response_delayed(state: &routes::AppState, connector: &api::ConnectorData) -> bool { +fn is_session_response_delayed( + state: &routes::SessionState, + connector: &api::ConnectorData, +) -> bool { let connectors_with_delayed_response = &state .conf .delayed_session_response @@ -519,7 +522,7 @@ fn log_session_response_if_error( impl types::PaymentsSessionRouterData { pub async fn decide_flow<'a, 'b>( &'b self, - state: &'a routes::AppState, + state: &'a routes::SessionState, connector: &api::ConnectorData, _customer: &Option, _confirm: Option, diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index d8acfe98f3b..ef3b615ec33 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -13,7 +13,7 @@ use crate::{ self, access_token, customers, helpers, tokenization, transformers, PaymentData, }, }, - routes::AppState, + routes::SessionState, services, types::{self, api, domain}, }; @@ -28,7 +28,7 @@ impl { async fn construct_router_data<'a>( &self, - state: &AppState, + state: &SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -55,7 +55,7 @@ impl impl Feature for types::SetupMandateRouterData { async fn decide_flows<'a>( self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, maybe_customer: &Option, call_connector_action: payments::CallConnectorAction, @@ -130,7 +130,7 @@ impl Feature for types::Setup async fn add_access_token<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, ) -> RouterResult { @@ -139,7 +139,7 @@ impl Feature for types::Setup async fn add_payment_method_token<'a>( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, tokenization_action: &payments::TokenizationAction, ) -> RouterResult> { @@ -156,7 +156,7 @@ impl Feature for types::Setup async fn create_connector_customer<'a>( &self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, ) -> RouterResult> { customers::create_connector_customer( @@ -170,7 +170,7 @@ impl Feature for types::Setup async fn build_flow_specific_connector_request( &mut self, - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, call_connector_action: payments::CallConnectorAction, ) -> RouterResult<(Option, bool)> { @@ -213,7 +213,7 @@ impl TryFrom for types::ConnectorCustomerData { impl types::SetupMandateRouterData { pub async fn decide_flow<'a, 'b>( &'b self, - state: &'a AppState, + state: &'a SessionState, connector: &api::ConnectorData, maybe_customer: &Option, confirm: Option, @@ -274,7 +274,7 @@ impl types::SetupMandateRouterData { async fn update_mandate_flow( self, - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, mandate_id: String, connector: &api::ConnectorData, diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 9851ec1edc2..b0185c9b507 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -43,7 +43,7 @@ use crate::{ pm_auth::retrieve_payment_method_from_auth_service, }, db::StorageInterface, - routes::{metrics, payment_methods, AppState}, + routes::{metrics, payment_methods, SessionState}, services, types::{ self as core_types, @@ -101,7 +101,7 @@ pub fn filter_mca_based_on_business_profile( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_or_update_address_for_payment_by_request( db: &dyn StorageInterface, @@ -261,7 +261,7 @@ pub async fn create_or_update_address_for_payment_by_request( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_or_find_address_for_payment_by_request( db: &dyn StorageInterface, @@ -412,7 +412,7 @@ pub async fn get_address_by_id( } pub async fn get_token_pm_type_mandate_details( - state: &AppState, + state: &SessionState, request: &api::PaymentsRequest, mandate_type: Option, merchant_account: &domain::MerchantAccount, @@ -551,7 +551,7 @@ pub async fn get_token_pm_type_mandate_details( } pub async fn get_token_for_recurring_mandate( - state: &AppState, + state: &SessionState, req: &api::PaymentsRequest, merchant_account: &domain::MerchantAccount, merchant_key_store: &domain::MerchantKeyStore, @@ -671,7 +671,7 @@ pub async fn get_token_for_recurring_mandate( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] /// Check weather the merchant id in the request /// and merchant id in the merchant account are same. pub fn validate_merchant_id( @@ -692,7 +692,7 @@ pub fn validate_merchant_id( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_request_amount_and_amount_to_capture( op_amount: Option, op_amount_to_capture: Option, @@ -731,7 +731,7 @@ pub fn validate_request_amount_and_amount_to_capture( } /// if capture method = automatic, amount_to_capture(if provided) must be equal to amount -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_amount_to_capture_and_capture_method( payment_attempt: Option<&PaymentAttempt>, request: &api_models::payments::PaymentsRequest, @@ -777,7 +777,7 @@ pub fn validate_amount_to_capture_and_capture_method( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_card_data( payment_method_data: Option, ) -> CustomResult<(), errors::ApiErrorResponse> { @@ -1127,7 +1127,7 @@ pub fn verify_mandate_details_for_recurring_payments( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn payment_attempt_status_fsm( payment_method_data: &Option, confirm: Option, @@ -1155,7 +1155,7 @@ pub fn payment_intent_status_fsm( } pub async fn add_domain_task_to_pt( operation: &Op, - state: &AppState, + state: &SessionState, payment_attempt: &PaymentAttempt, requeue: bool, schedule_time: Option, @@ -1212,7 +1212,7 @@ where Box::new(PaymentResponse) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) async fn get_payment_method_create_request( payment_method_data: Option<&domain::PaymentMethodData>, payment_method: Option, @@ -1379,7 +1379,7 @@ pub fn validate_customer_details_in_request( /// Get the customer details from customer field if present /// or from the individual fields in `PaymentsRequest` -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn get_customer_details_from_request( request: &api_models::payments::PaymentsRequest, ) -> CustomerDetails { @@ -1423,7 +1423,7 @@ pub fn get_customer_details_from_request( } pub async fn get_connector_default( - _state: &AppState, + _state: &SessionState, request_connector: Option, ) -> CustomResult { Ok(request_connector.map_or( @@ -1432,7 +1432,7 @@ pub async fn get_connector_default( )) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::type_complexity)] pub async fn create_customer_if_not_exist<'a, F: Clone, R, Ctx>( operation: BoxedOperation<'a, F, R, Ctx>, @@ -1604,7 +1604,7 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, Ctx>( } pub async fn retrieve_payment_method_with_temporary_token( - state: &AppState, + state: &SessionState, token: &str, payment_intent: &PaymentIntent, merchant_key_store: &domain::MerchantKeyStore, @@ -1701,7 +1701,7 @@ pub async fn retrieve_payment_method_with_temporary_token( } pub async fn retrieve_card_with_permanent_token( - state: &AppState, + state: &SessionState, locker_id: &str, payment_method_id: &str, payment_intent: &PaymentIntent, @@ -1758,7 +1758,7 @@ pub async fn retrieve_card_with_permanent_token( } pub async fn retrieve_payment_method_from_db_with_token_data( - state: &AppState, + state: &SessionState, token_data: &storage::PaymentTokenData, storage_scheme: storage::enums::MerchantStorageScheme, ) -> RouterResult> { @@ -1793,7 +1793,7 @@ pub async fn retrieve_payment_method_from_db_with_token_data( } pub async fn retrieve_payment_token_data( - state: &AppState, + state: &SessionState, token: String, payment_method: Option, ) -> RouterResult { @@ -1844,7 +1844,7 @@ pub async fn retrieve_payment_token_data( pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( operation: BoxedOperation<'a, F, R, Ctx>, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, merchant_key_store: &domain::MerchantKeyStore, customer: &Option, @@ -1941,7 +1941,7 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( } pub async fn store_in_vault_and_generate_ppmt( - state: &AppState, + state: &SessionState, payment_method_data: &api_models::payments::PaymentMethodData, payment_intent: &PaymentIntent, payment_attempt: &PaymentAttempt, @@ -1977,7 +1977,7 @@ pub async fn store_in_vault_and_generate_ppmt( } pub async fn store_payment_method_data_in_vault( - state: &AppState, + state: &SessionState, payment_attempt: &PaymentAttempt, payment_intent: &PaymentIntent, payment_method: enums::PaymentMethod, @@ -2021,7 +2021,7 @@ pub fn should_store_payment_method_data_in_vault( .unwrap_or(true) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) fn validate_capture_method( capture_method: storage_enums::CaptureMethod, ) -> RouterResult<()> { @@ -2038,7 +2038,7 @@ pub(crate) fn validate_capture_method( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) fn validate_status_with_capture_method( status: storage_enums::IntentStatus, capture_method: storage_enums::CaptureMethod, @@ -2069,7 +2069,7 @@ pub(crate) fn validate_status_with_capture_method( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) fn validate_amount_to_capture( amount: i64, amount_to_capture: Option, @@ -2084,7 +2084,7 @@ pub(crate) fn validate_amount_to_capture( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) fn validate_payment_method_fields_present( req: &api::PaymentsRequest, ) -> RouterResult<()> { @@ -2455,7 +2455,7 @@ pub fn make_merchant_url_with_response( } pub async fn make_ephemeral_key( - state: AppState, + state: SessionState, customer_id: String, merchant_id: String, ) -> errors::RouterResponse { @@ -2477,7 +2477,7 @@ pub async fn make_ephemeral_key( } pub async fn delete_ephemeral_key( - state: AppState, + state: SessionState, ek_id: String, ) -> errors::RouterResponse { let db = state.store.as_ref(); @@ -2713,7 +2713,7 @@ pub(crate) fn validate_payment_status_against_not_allowed_statuses( }) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) fn validate_pm_or_token_given( payment_method: &Option, payment_method_data: &Option, @@ -3012,7 +3012,7 @@ mod tests { } // This function will be removed after moving this functionality to server_wrap and using cache instead of config -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn insert_merchant_connector_creds_to_config( db: &dyn StorageInterface, merchant_id: &str, @@ -3099,9 +3099,9 @@ impl MerchantConnectorAccountType { /// Query for merchant connector account either by business label or profile id /// If profile_id is passed use it, or use connector_label to query merchant connector account -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_merchant_connector_account( - state: &AppState, + state: &SessionState, merchant_id: &str, creds_identifier: Option, key_store: &domain::MerchantKeyStore, @@ -3234,7 +3234,7 @@ pub fn router_data_type_conversion( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn get_attempt_type( payment_intent: &PaymentIntent, payment_attempt: &PaymentAttempt, @@ -3441,7 +3441,7 @@ impl AttemptType { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn modify_payment_intent_and_payment_attempt( &self, request: &api::PaymentsRequest, @@ -3581,7 +3581,7 @@ mod test { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_additional_payment_data( pm_data: &api_models::payments::PaymentMethodData, db: &dyn StorageInterface, @@ -3772,7 +3772,7 @@ impl ApplePayData { pub async fn decrypt( &self, - state: &AppState, + state: &SessionState, ) -> CustomResult { let merchant_id = self.merchant_id(state).await?; let shared_secret = self.shared_secret(state).await?; @@ -3785,7 +3785,7 @@ impl ApplePayData { pub async fn merchant_id( &self, - state: &AppState, + state: &SessionState, ) -> CustomResult { let cert_data = state .conf @@ -3830,7 +3830,7 @@ impl ApplePayData { pub async fn shared_secret( &self, - state: &AppState, + state: &SessionState, ) -> CustomResult, errors::ApplePayDecryptionError> { let public_ec_bytes = BASE64_ENGINE .decode(self.header.ephemeral_public_key.peek().as_bytes()) @@ -4004,7 +4004,7 @@ pub fn validate_payment_link_request( } pub async fn get_gsm_record( - state: &AppState, + state: &SessionState, error_code: Option, error_message: Option, connector_name: String, @@ -4141,7 +4141,7 @@ pub fn update_additional_payment_data_with_connector_response_pm_data( } pub async fn get_payment_method_details_from_payment_token( - state: &AppState, + state: &SessionState, payment_attempt: &PaymentAttempt, payment_intent: &PaymentIntent, key_store: &domain::MerchantKeyStore, diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs index 6b04c500dc1..3e86ffe5d4b 100644 --- a/crates/router/src/core/payments/operations.rs +++ b/crates/router/src/core/payments/operations.rs @@ -32,7 +32,7 @@ use crate::{ payment_methods::PaymentMethodRetrieve, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ self, @@ -105,7 +105,7 @@ pub trait GetTracker: Send { #[allow(clippy::too_many_arguments)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &R, merchant_account: &domain::MerchantAccount, @@ -130,7 +130,7 @@ pub trait Domain: Send + Sync { #[allow(clippy::too_many_arguments)] async fn make_pm_data<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -143,7 +143,7 @@ pub trait Domain: Send + Sync { async fn add_task_to_process_tracker<'a>( &'a self, - _db: &'a AppState, + _db: &'a SessionState, _payment_attempt: &storage::PaymentAttempt, _requeue: bool, _schedule_time: Option, @@ -154,7 +154,7 @@ pub trait Domain: Send + Sync { async fn get_connector<'a>( &'a self, merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &R, payment_intent: &storage::PaymentIntent, mechant_key_store: &domain::MerchantKeyStore, @@ -162,7 +162,7 @@ pub trait Domain: Send + Sync { async fn populate_payment_data<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _payment_data: &mut PaymentData, _merchant_account: &domain::MerchantAccount, ) -> CustomResult<(), errors::ApiErrorResponse> { @@ -171,7 +171,7 @@ pub trait Domain: Send + Sync { async fn call_external_three_ds_authentication_if_eligible<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _payment_data: &mut PaymentData, _should_continue_confirm_transaction: &mut bool, _connector_call_type: &ConnectorCallType, @@ -181,10 +181,10 @@ pub trait Domain: Send + Sync { Ok(()) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -197,7 +197,7 @@ pub trait Domain: Send + Sync { pub trait UpdateTracker: Send { async fn update_trackers<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, req_state: ReqState, payment_data: D, customer: Option, @@ -215,7 +215,7 @@ pub trait UpdateTracker: Send { pub trait PostUpdateTracker: Send { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, payment_data: D, response: types::RouterData, @@ -234,7 +234,7 @@ impl< where for<'a> &'a Op: Operation, { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -266,7 +266,7 @@ where async fn get_connector<'a>( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, _request: &api::PaymentsRetrieveRequest, _payment_intent: &storage::PaymentIntent, _merchant_key_store: &domain::MerchantKeyStore, @@ -274,10 +274,10 @@ where helpers::get_connector_default(state, None).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -298,10 +298,10 @@ where .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -318,7 +318,7 @@ impl< where for<'a> &'a Op: Operation, { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -346,10 +346,10 @@ where .await?, )) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_data: &mut PaymentData, _storage_scheme: enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, @@ -365,7 +365,7 @@ where async fn get_connector<'a>( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, _request: &api::PaymentsCaptureRequest, _payment_intent: &storage::PaymentIntent, _merchant_key_store: &domain::MerchantKeyStore, @@ -373,10 +373,10 @@ where helpers::get_connector_default(state, None).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -393,7 +393,7 @@ impl< where for<'a> &'a Op: Operation, { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -422,10 +422,10 @@ where )) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_data: &mut PaymentData, _storage_scheme: enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, @@ -441,7 +441,7 @@ where async fn get_connector<'a>( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, _request: &api::PaymentsCancelRequest, _payment_intent: &storage::PaymentIntent, _merchant_key_store: &domain::MerchantKeyStore, @@ -449,10 +449,10 @@ where helpers::get_connector_default(state, None).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -469,7 +469,7 @@ impl< where for<'a> &'a Op: Operation, { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, _db: &dyn StorageInterface, @@ -487,10 +487,10 @@ where Ok((Box::new(self), None)) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_data: &mut PaymentData, _storage_scheme: enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, @@ -506,7 +506,7 @@ where async fn get_connector<'a>( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, _request: &api::PaymentsRejectRequest, _payment_intent: &storage::PaymentIntent, _merchant_key_store: &domain::MerchantKeyStore, @@ -514,10 +514,10 @@ where helpers::get_connector_default(state, None).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs index be73d0836dd..855dbbe57bd 100644 --- a/crates/router/src/core/payments/operations/payment_approve.rs +++ b/crates/router/src/core/payments/operations/payment_approve.rs @@ -13,7 +13,7 @@ use crate::{ payment_methods::PaymentMethodRetrieve, payments::{helpers, operations, PaymentData}, }, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, PaymentIdTypeExt}, @@ -32,10 +32,10 @@ pub struct PaymentApprove; impl GetTracker, api::PaymentsCaptureRequest, Ctx> for PaymentApprove { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, _request: &api::PaymentsCaptureRequest, merchant_account: &domain::MerchantAccount, @@ -196,10 +196,10 @@ impl impl UpdateTracker, api::PaymentsCaptureRequest, Ctx> for PaymentApprove { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData, _customer: Option, @@ -236,7 +236,7 @@ impl impl ValidateRequest for PaymentApprove { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCaptureRequest, diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs index cb1b2fbd674..d3f927fe979 100644 --- a/crates/router/src/core/payments/operations/payment_cancel.rs +++ b/crates/router/src/core/payments/operations/payment_cancel.rs @@ -15,7 +15,7 @@ use crate::{ payments::{helpers, operations, PaymentData}, }, events::audit_events::{AuditEvent, AuditEventType}, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ self as core_types, @@ -34,10 +34,10 @@ pub struct PaymentCancel; impl GetTracker, api::PaymentsCancelRequest, Ctx> for PaymentCancel { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsCancelRequest, merchant_account: &domain::MerchantAccount, @@ -206,10 +206,10 @@ impl impl UpdateTracker, api::PaymentsCancelRequest, Ctx> for PaymentCancel { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, req_state: ReqState, mut payment_data: PaymentData, _customer: Option, @@ -276,7 +276,7 @@ impl impl ValidateRequest for PaymentCancel { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCancelRequest, diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index a20358cb95b..1566e43a049 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -13,7 +13,7 @@ use crate::{ payment_methods::PaymentMethodRetrieve, payments::{self, helpers, operations, types::MultipleCaptureData}, }, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ self as core_types, @@ -32,10 +32,10 @@ pub struct PaymentCapture; impl GetTracker, api::PaymentsCaptureRequest, Ctx> for PaymentCapture { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsCaptureRequest, merchant_account: &domain::MerchantAccount, @@ -250,10 +250,10 @@ impl UpdateTracker, api::PaymentsCaptureRequest, Ctx> for PaymentCapture { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, _req_state: ReqState, mut payment_data: payments::PaymentData, _customer: Option, @@ -300,7 +300,7 @@ impl impl ValidateRequest for PaymentCapture { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCaptureRequest, diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs index e9e0ec36a73..67c1c22c283 100644 --- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs +++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs @@ -16,7 +16,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, PaymentIdTypeExt}, @@ -34,10 +34,10 @@ pub struct CompleteAuthorize; impl GetTracker, api::PaymentsRequest, Ctx> for CompleteAuthorize { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsRequest, merchant_account: &domain::MerchantAccount, @@ -332,7 +332,7 @@ impl impl Domain for CompleteAuthorize { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -359,10 +359,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: storage_enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -384,10 +384,10 @@ impl Domain( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_attempt: &storage::PaymentAttempt, _requeue: bool, _schedule_time: Option, @@ -398,7 +398,7 @@ impl Domain( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &api::PaymentsRequest, _payment_intent: &storage::PaymentIntent, _key_store: &domain::MerchantKeyStore, @@ -408,10 +408,10 @@ impl Domain( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -423,10 +423,10 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for CompleteAuthorize { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - _state: &'b AppState, + _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData, _customer: Option, @@ -449,7 +449,7 @@ impl impl ValidateRequest for CompleteAuthorize { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 7af7e13b9fc..cb8d9d2196d 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -24,7 +24,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, ConnectorCallType, PaymentIdTypeExt}, @@ -41,10 +41,10 @@ pub struct PaymentConfirm; impl GetTracker, api::PaymentsRequest, Ctx> for PaymentConfirm { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsRequest, merchant_account: &domain::MerchantAccount, @@ -651,7 +651,7 @@ impl impl Domain for PaymentConfirm { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -678,10 +678,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: storage_enums::MerchantStorageScheme, key_store: &domain::MerchantKeyStore, @@ -708,10 +708,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_attempt: &storage::PaymentAttempt, requeue: bool, schedule_time: Option, @@ -726,7 +726,7 @@ impl Domain Domain( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &api::PaymentsRequest, _payment_intent: &storage::PaymentIntent, _key_store: &domain::MerchantKeyStore, @@ -752,10 +752,10 @@ impl Domain( &'a self, - state: &AppState, + state: &SessionState, payment_data: &mut PaymentData, _merchant_account: &domain::MerchantAccount, ) -> CustomResult<(), errors::ApiErrorResponse> { @@ -764,7 +764,7 @@ impl Domain( &'a self, - state: &AppState, + state: &SessionState, payment_data: &mut PaymentData, should_continue_confirm_transaction: &mut bool, connector_call_type: &ConnectorCallType, @@ -884,10 +884,10 @@ impl Domain( &'a self, - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_data: &mut PaymentData, ) -> CustomResult { @@ -899,10 +899,10 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for PaymentConfirm { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - state: &'b AppState, + state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData, customer: Option, @@ -1203,7 +1203,7 @@ impl impl ValidateRequest for PaymentConfirm { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 5c5eeb046f5..bd268ad85b5 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -28,7 +28,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ self, @@ -52,10 +52,10 @@ pub struct PaymentCreate; impl GetTracker, api::PaymentsRequest, Ctx> for PaymentCreate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsRequest, merchant_account: &domain::MerchantAccount, @@ -464,7 +464,7 @@ impl impl Domain for PaymentCreate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -491,10 +491,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -515,10 +515,10 @@ impl Domain( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_attempt: &PaymentAttempt, _requeue: bool, _schedule_time: Option, @@ -529,7 +529,7 @@ impl Domain( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &api::PaymentsRequest, _payment_intent: &storage::PaymentIntent, _merchant_key_store: &domain::MerchantKeyStore, @@ -537,10 +537,10 @@ impl Domain( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -552,10 +552,10 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for PaymentCreate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - state: &'b AppState, + state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData, _customer: Option, @@ -657,7 +657,7 @@ impl impl ValidateRequest for PaymentCreate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, @@ -752,7 +752,7 @@ impl ValidateRequest, request: &api::PaymentsRequest, browser_info: Option, - state: &AppState, + state: &SessionState, + payment_method_billing_address_id: Option, payment_method_info: &Option, key_store: &domain::MerchantKeyStore, @@ -927,7 +928,7 @@ impl PaymentCreate { )) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] async fn make_payment_intent( payment_id: &str, @@ -1022,10 +1023,10 @@ impl PaymentCreate { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn get_ephemeral_key( request: &api::PaymentsRequest, - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, ) -> Option { match request.customer_id.clone() { @@ -1048,7 +1049,7 @@ impl PaymentCreate { } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn payments_create_request_validation( req: &api::PaymentsRequest, ) -> RouterResult<(api::Amount, enums::Currency)> { diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs index 413a6fb4f0f..3920f44cd4f 100644 --- a/crates/router/src/core/payments/operations/payment_reject.rs +++ b/crates/router/src/core/payments/operations/payment_reject.rs @@ -13,7 +13,7 @@ use crate::{ payment_methods::PaymentMethodRetrieve, payments::{helpers, operations, PaymentAddress, PaymentData}, }, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, PaymentIdTypeExt}, @@ -31,10 +31,10 @@ pub struct PaymentReject; impl GetTracker, PaymentsCancelRequest, Ctx> for PaymentReject { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, _request: &PaymentsCancelRequest, merchant_account: &domain::MerchantAccount, @@ -192,10 +192,10 @@ impl impl UpdateTracker, PaymentsCancelRequest, Ctx> for PaymentReject { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - state: &'b AppState, + state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData, _customer: Option, @@ -260,7 +260,7 @@ impl impl ValidateRequest for PaymentReject { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &PaymentsCancelRequest, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 50c795be2b0..5f50433f074 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -29,7 +29,7 @@ use crate::{ }, utils as core_utils, }, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, types::{ self, api, storage::{self, enums}, @@ -52,7 +52,7 @@ impl PostUpdateTracker, types::PaymentsAuthorizeData { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData< @@ -88,7 +88,7 @@ impl PostUpdateTracker, types::PaymentsIncrementalAu { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, _payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData< @@ -216,7 +216,7 @@ impl PostUpdateTracker, types::PaymentsIncrementalAu impl PostUpdateTracker, types::PaymentsSyncData> for PaymentResponse { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, payment_data: PaymentData, router_data: types::RouterData, @@ -242,7 +242,7 @@ impl PostUpdateTracker, types::PaymentsSessionData> { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData, @@ -270,7 +270,7 @@ impl PostUpdateTracker, types::PaymentsCaptureData> { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData, @@ -296,7 +296,7 @@ impl PostUpdateTracker, types::PaymentsCaptureData> impl PostUpdateTracker, types::PaymentsCancelData> for PaymentResponse { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData, @@ -325,7 +325,7 @@ impl PostUpdateTracker, types::PaymentsApproveData> { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData, @@ -352,7 +352,7 @@ impl PostUpdateTracker, types::PaymentsApproveData> impl PostUpdateTracker, types::PaymentsRejectData> for PaymentResponse { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData, @@ -381,7 +381,7 @@ impl PostUpdateTracker, types::SetupMandateRequestDa { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData< @@ -419,7 +419,7 @@ impl PostUpdateTracker, types::CompleteAuthorizeData { async fn update_tracker<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, payment_id: &api::PaymentIdType, payment_data: PaymentData, response: types::RouterData, @@ -439,9 +439,9 @@ impl PostUpdateTracker, types::CompleteAuthorizeData } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn payment_response_update_tracker( - state: &AppState, + state: &SessionState, _payment_id: &api::PaymentIdType, mut payment_data: PaymentData, router_data: types::RouterData, @@ -962,7 +962,7 @@ async fn payment_response_update_tracker( } async fn update_payment_method_status_and_ntid( - state: &AppState, + state: &SessionState, payment_data: &mut PaymentData, attempt_status: common_enums::AttemptStatus, payment_response: Result, diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs index d963c6864b7..f8ba8d75f6f 100644 --- a/crates/router/src/core/payments/operations/payment_session.rs +++ b/crates/router/src/core/payments/operations/payment_session.rs @@ -15,7 +15,7 @@ use crate::{ payments::{self, helpers, operations, PaymentData}, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, PaymentIdTypeExt}, @@ -33,10 +33,10 @@ pub struct PaymentSession; impl GetTracker, api::PaymentsSessionRequest, Ctx> for PaymentSession { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsSessionRequest, merchant_account: &domain::MerchantAccount, @@ -217,10 +217,10 @@ impl impl UpdateTracker, api::PaymentsSessionRequest, Ctx> for PaymentSession { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - state: &'b AppState, + state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData, _customer: Option, @@ -260,7 +260,7 @@ impl impl ValidateRequest for PaymentSession { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsSessionRequest, @@ -293,7 +293,7 @@ impl< where for<'a> &'a Op: Operation, { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -320,10 +320,10 @@ where .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'b>( &'b self, - _state: &'b AppState, + _state: &'b SessionState, _payment_data: &mut PaymentData, _storage_scheme: storage_enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, @@ -349,7 +349,7 @@ where async fn get_connector<'a>( &'a self, merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &api::PaymentsSessionRequest, payment_intent: &storage::PaymentIntent, key_store: &domain::MerchantKeyStore, @@ -462,10 +462,10 @@ where )) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> errors::CustomResult { diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs index 70fb33851d9..b7a656eff13 100644 --- a/crates/router/src/core/payments/operations/payment_start.rs +++ b/crates/router/src/core/payments/operations/payment_start.rs @@ -14,7 +14,7 @@ use crate::{ payments::{helpers, operations, CustomerDetails, PaymentAddress, PaymentData}, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, PaymentIdTypeExt}, @@ -32,10 +32,10 @@ pub struct PaymentStart; impl GetTracker, api::PaymentsStartRequest, Ctx> for PaymentStart { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, _request: &api::PaymentsStartRequest, merchant_account: &domain::MerchantAccount, @@ -204,10 +204,10 @@ impl impl UpdateTracker, api::PaymentsStartRequest, Ctx> for PaymentStart { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - _state: &'b AppState, + _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData, _customer: Option, @@ -230,7 +230,7 @@ impl impl ValidateRequest for PaymentStart { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsStartRequest, @@ -269,7 +269,7 @@ impl< where for<'a> &'a Op: Operation, { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -296,10 +296,10 @@ where .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: storage_enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -333,7 +333,7 @@ where async fn get_connector<'a>( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, _request: &api::PaymentsStartRequest, _payment_intent: &storage::PaymentIntent, _mechant_key_store: &domain::MerchantKeyStore, @@ -341,10 +341,10 @@ where helpers::get_connector_default(state, None).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs index c079f93caae..707ec5280ae 100644 --- a/crates/router/src/core/payments/operations/payment_status.rs +++ b/crates/router/src/core/payments/operations/payment_status.rs @@ -18,7 +18,7 @@ use crate::{ }, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api, domain, @@ -64,7 +64,7 @@ impl Operation Domain for PaymentStatus { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -91,10 +91,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -115,10 +115,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_attempt: &storage::PaymentAttempt, requeue: bool, schedule_time: Option, @@ -129,7 +129,7 @@ impl Domain( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &api::PaymentsRequest, _payment_intent: &storage::PaymentIntent, _key_store: &domain::MerchantKeyStore, @@ -137,10 +137,10 @@ impl Domain( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -154,7 +154,7 @@ impl { async fn update_trackers<'b>( &'b self, - _state: &'b AppState, + _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData, _customer: Option, @@ -180,7 +180,7 @@ impl { async fn update_trackers<'b>( &'b self, - _state: &'b AppState, + _state: &'b SessionState, _req_state: ReqState, payment_data: PaymentData, _customer: Option, @@ -204,10 +204,10 @@ impl impl GetTracker, api::PaymentsRetrieveRequest, Ctx> for PaymentStatus { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsRetrieveRequest, merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index e722a05f767..ee5a63ed0d9 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -19,7 +19,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services, types::{ api::{self, PaymentIdTypeExt}, @@ -37,10 +37,10 @@ pub struct PaymentUpdate; impl GetTracker, api::PaymentsRequest, Ctx> for PaymentUpdate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &api::PaymentsRequest, merchant_account: &domain::MerchantAccount, @@ -470,7 +470,7 @@ impl impl Domain for PaymentUpdate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -497,10 +497,10 @@ impl Domain( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_data: &mut PaymentData, storage_scheme: storage_enums::MerchantStorageScheme, merchant_key_store: &domain::MerchantKeyStore, @@ -521,10 +521,10 @@ impl Domain( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_attempt: &storage::PaymentAttempt, _requeue: bool, _schedule_time: Option, @@ -535,7 +535,7 @@ impl Domain( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, request: &api::PaymentsRequest, _payment_intent: &storage::PaymentIntent, _key_store: &domain::MerchantKeyStore, @@ -543,10 +543,10 @@ impl Domain( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut PaymentData, ) -> CustomResult { @@ -558,10 +558,10 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for PaymentUpdate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - state: &'b AppState, + state: &'b SessionState, _req_state: ReqState, mut payment_data: PaymentData, customer: Option, @@ -729,7 +729,7 @@ impl impl ValidateRequest for PaymentUpdate { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs index 7f2311eb88a..eaf99862ddc 100644 --- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs +++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs @@ -19,7 +19,7 @@ use crate::{ }, routes::{ app::{ReqState, StorageInterface}, - AppState, + SessionState, }, services, types::{ @@ -39,10 +39,10 @@ impl GetTracker, PaymentsIncrementalAuthorizationRequest, Ctx> for PaymentIncrementalAuthorization { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_trackers<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, payment_id: &api::PaymentIdType, request: &PaymentsIncrementalAuthorizationRequest, merchant_account: &domain::MerchantAccount, @@ -174,10 +174,10 @@ impl UpdateTracker, PaymentsIncrementalAuthorizationRequest, Ctx> for PaymentIncrementalAuthorization { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_trackers<'b>( &'b self, - db: &'b AppState, + db: &'b SessionState, _req_state: ReqState, mut payment_data: payments::PaymentData, _customer: Option, @@ -265,7 +265,7 @@ impl ValidateRequest for PaymentIncrementalAuthorization { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &PaymentsIncrementalAuthorizationRequest, @@ -290,7 +290,7 @@ impl impl Domain for PaymentIncrementalAuthorization { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, _db: &dyn StorageInterface, @@ -308,10 +308,10 @@ impl Ok((Box::new(self), None)) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn make_pm_data<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, _payment_data: &mut payments::PaymentData, _storage_scheme: enums::MerchantStorageScheme, _merchant_key_store: &domain::MerchantKeyStore, @@ -327,7 +327,7 @@ impl async fn get_connector<'a>( &'a self, _merchant_account: &domain::MerchantAccount, - state: &AppState, + state: &SessionState, _request: &PaymentsIncrementalAuthorizationRequest, _payment_intent: &storage::PaymentIntent, _merchant_key_store: &domain::MerchantKeyStore, @@ -335,10 +335,10 @@ impl helpers::get_connector_default(state, None).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, - _state: &AppState, + _state: &SessionState, _merchant_account: &domain::MerchantAccount, _payment_data: &mut payments::PaymentData, ) -> CustomResult { diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 71cded04e1a..32dd004589b 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -29,10 +29,10 @@ use crate::{ utils, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn do_gsm_actions( - state: &app::AppState, + state: &app::SessionState, req_state: ReqState, payment_data: &mut payments::PaymentData, mut connectors: IntoIter, @@ -162,9 +162,9 @@ where Ok(router_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn is_step_up_enabled_for_merchant_connector( - state: &app::AppState, + state: &app::SessionState, merchant_id: &str, connector_name: types::Connector, ) -> bool { @@ -186,9 +186,9 @@ pub async fn is_step_up_enabled_for_merchant_connector( .unwrap_or(false) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_retries( - state: &app::AppState, + state: &app::SessionState, retries: Option, merchant_id: &str, ) -> Option { @@ -216,9 +216,9 @@ pub async fn get_retries( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_gsm( - state: &app::AppState, + state: &app::SessionState, router_data: &types::RouterData, ) -> RouterResult> { let error_response = router_data.response.as_ref().err(); @@ -232,7 +232,7 @@ pub async fn get_gsm( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn get_gsm_decision( option_gsm: Option, ) -> api_models::gsm::GsmDecision { @@ -266,9 +266,9 @@ fn get_flow_name() -> RouterResult { } #[allow(clippy::too_many_arguments)] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn do_retry( - state: &routes::AppState, + state: &routes::SessionState, req_state: ReqState, connector: api::ConnectorData, operation: &operations::BoxedOperation<'_, F, ApiRequest, Ctx>, @@ -322,9 +322,9 @@ where .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn modify_trackers( - state: &routes::AppState, + state: &routes::SessionState, connector: String, payment_data: &mut payments::PaymentData, storage_scheme: storage_enums::MerchantStorageScheme, @@ -466,7 +466,7 @@ where Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn make_new_payment_attempt( connector: String, old_payment_attempt: storage::PaymentAttempt, diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs index e2502e2ecb6..d71a1d84b1a 100644 --- a/crates/router/src/core/payments/routing.rs +++ b/crates/router/src/core/payments/routing.rs @@ -47,7 +47,7 @@ use crate::{ transformers::ForeignInto, }, utils::{OptionExt, ValueExt}, - AppState, + SessionState, }; pub(super) enum CachedAlgorithm { @@ -58,7 +58,7 @@ pub(super) enum CachedAlgorithm { } pub struct SessionFlowRoutingInput<'a> { - pub state: &'a AppState, + pub state: &'a SessionState, pub country: Option, pub key_store: &'a domain::MerchantKeyStore, pub merchant_account: &'a domain::MerchantAccount, @@ -68,7 +68,7 @@ pub struct SessionFlowRoutingInput<'a> { } pub struct SessionRoutingPmTypeInput<'a> { - state: &'a AppState, + state: &'a SessionState, key_store: &'a domain::MerchantKeyStore, merchant_last_modified: i64, attempt_id: &'a str, @@ -263,7 +263,7 @@ where } pub async fn perform_static_routing_v1( - state: &AppState, + state: &SessionState, merchant_id: &str, algorithm_ref: routing_types::RoutingAlgorithmRef, transaction_data: &routing::TransactionData<'_, F>, @@ -336,7 +336,7 @@ pub async fn perform_static_routing_v1( } async fn ensure_algorithm_cached_v1( - state: &AppState, + state: &SessionState, merchant_id: &str, timestamp: i64, algorithm_id: &str, @@ -440,7 +440,7 @@ fn execute_dsl_and_get_connector_v1( } pub async fn refresh_routing_cache_v1( - state: &AppState, + state: &SessionState, key: String, algorithm_id: &str, timestamp: i64, @@ -537,7 +537,7 @@ pub fn perform_volume_split( } pub async fn get_merchant_kgraph<'a>( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, merchant_last_modified: i64, #[cfg(feature = "business_profile_routing")] profile_id: Option, @@ -599,7 +599,7 @@ pub async fn get_merchant_kgraph<'a>( } pub async fn refresh_kgraph_cache( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, timestamp: i64, key: String, @@ -658,7 +658,7 @@ pub async fn refresh_kgraph_cache( #[allow(clippy::too_many_arguments)] async fn perform_kgraph_filtering( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, merchant_last_modified: i64, chosen: Vec, @@ -705,7 +705,7 @@ async fn perform_kgraph_filtering( } pub async fn perform_eligibility_analysis( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, merchant_last_modified: i64, chosen: Vec, @@ -734,7 +734,7 @@ pub async fn perform_eligibility_analysis( } pub async fn perform_fallback_routing( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, merchant_last_modified: i64, transaction_data: &routing::TransactionData<'_, F>, @@ -782,7 +782,7 @@ pub async fn perform_fallback_routing( } pub async fn perform_eligibility_analysis_with_fallback( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, merchant_last_modified: i64, chosen: Vec, diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index b2c8a3234a3..d27fde76689 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -18,7 +18,7 @@ use crate::{ mandate, payment_methods, payments, }, logger, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{ self, @@ -29,10 +29,10 @@ use crate::{ utils::{generate_id, OptionExt}, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn save_payment_method( - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, resp: types::RouterData, maybe_customer: &Option, @@ -628,7 +628,7 @@ async fn skip_saving_card_in_locker( } pub async fn save_in_locker( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, payment_method_request: api::PaymentMethodCreate, ) -> RouterResult<( @@ -699,7 +699,7 @@ pub fn create_payment_method_metadata( } pub async fn add_payment_method_token( - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, tokenization_action: &payments::TokenizationAction, router_data: &mut types::RouterData, diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 23b3f1f6931..cb6b1e7c449 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -19,7 +19,7 @@ use crate::{ payments::{self, helpers}, utils as core_utils, }, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services::{self, RedirectForm}, types::{ self, api, domain, @@ -30,9 +30,9 @@ use crate::{ utils::{OptionExt, ValueExt}, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_payment_router_data<'a, F, T>( - state: &'a AppState, + state: &'a SessionState, payment_data: PaymentData, connector_id: &str, merchant_account: &domain::MerchantAccount, @@ -343,7 +343,7 @@ where } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] // try to use router data here so that already validated things , we don't want to repeat the validations. // Add internal value not found and external value not found so that we can give 500 / Internal server error for internal value not found #[allow(clippy::too_many_arguments)] @@ -1057,7 +1057,7 @@ where router_base_url: String, connector_name: String, payment_data: PaymentData, - state: &'a AppState, + state: &'a SessionState, customer_data: &'a Option, } impl TryFrom> for types::PaymentsAuthorizeData { diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rs index 73825558068..db00c13d31a 100644 --- a/crates/router/src/core/payments/types.rs +++ b/crates/router/src/core/payments/types.rs @@ -16,7 +16,7 @@ use router_env::{instrument, tracing}; use crate::{ consts as router_consts, core::errors::{self, RouterResult}, - routes::AppState, + routes::SessionState, types::{ storage::{self, enums as storage_enums}, transformers::ForeignTryFrom, @@ -321,10 +321,10 @@ impl SurchargeMetadata { } } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn persist_individual_surcharge_details_in_redis( &self, - state: &AppState, + state: &SessionState, business_profile: &BusinessProfile, ) -> RouterResult<()> { if !self.is_empty_result() { @@ -357,9 +357,9 @@ impl SurchargeMetadata { Ok(()) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] pub async fn get_individual_surcharge_detail_from_redis( - state: &AppState, + state: &SessionState, surcharge_key: SurchargeKey, payment_attempt_id: &str, ) -> CustomResult { diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs index 47ea7ff3761..62eb70b13c2 100644 --- a/crates/router/src/core/payouts.rs +++ b/crates/router/src/core/payouts.rs @@ -27,7 +27,7 @@ use crate::{ payments::{self, helpers as payment_helpers}, utils as core_utils, }, - routes::AppState, + routes::SessionState, services, types::{ self, @@ -63,7 +63,7 @@ pub fn get_next_connector( #[cfg(feature = "payouts")] pub async fn get_connector_choice( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, connector: Option, @@ -143,9 +143,9 @@ pub async fn get_connector_choice( } #[cfg(feature = "payouts")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn make_connector_decision( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, @@ -253,9 +253,9 @@ pub async fn make_connector_decision( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn payouts_create_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutCreateRequest, @@ -307,7 +307,7 @@ pub async fn payouts_create_core( } pub async fn payouts_update_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutCreateRequest, @@ -456,9 +456,9 @@ pub async fn payouts_update_core( .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn payouts_retrieve_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutRetrieveRequest, @@ -480,9 +480,9 @@ pub async fn payouts_retrieve_core( .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn payouts_cancel_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutActionRequest, @@ -583,9 +583,9 @@ pub async fn payouts_cancel_core( .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn payouts_fulfill_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: payouts::PayoutActionRequest, @@ -678,7 +678,7 @@ pub async fn payouts_fulfill_core( #[cfg(feature = "olap")] pub async fn payouts_list_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, constraints: payouts::PayoutListConstraints, @@ -772,7 +772,7 @@ pub async fn payouts_list_core( #[cfg(feature = "olap")] pub async fn payouts_filtered_list_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, filters: payouts::PayoutListFilterConstraints, @@ -818,7 +818,7 @@ pub async fn payouts_filtered_list_core( #[cfg(feature = "olap")] pub async fn payouts_list_available_filters_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, time_range: api::TimeRange, ) -> RouterResponse { @@ -853,7 +853,7 @@ pub async fn payouts_list_available_filters_core( // ********************************************** HELPERS ********************************************** pub async fn call_connector_payout( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, @@ -999,7 +999,7 @@ pub async fn call_connector_payout( } pub async fn create_recipient( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, @@ -1085,7 +1085,7 @@ pub async fn create_recipient( } pub async fn check_payout_eligibility( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, @@ -1201,7 +1201,7 @@ pub async fn check_payout_eligibility( } pub async fn create_payout( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, @@ -1323,7 +1323,7 @@ pub async fn create_payout( } pub async fn cancel_payout( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutRequest, @@ -1431,7 +1431,7 @@ pub async fn cancel_payout( } pub async fn fulfill_payout( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutRequest, @@ -1563,7 +1563,7 @@ pub async fn fulfill_payout( } pub async fn response_handler( - _state: &AppState, + _state: &SessionState, merchant_account: &domain::MerchantAccount, _req: &payouts::PayoutRequest, payout_data: &PayoutData, @@ -1637,7 +1637,7 @@ pub async fn response_handler( // DB entries #[allow(clippy::too_many_arguments)] pub async fn payout_create_db_entries( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutCreateRequest, @@ -1791,7 +1791,7 @@ pub async fn payout_create_db_entries( } pub async fn make_payout_data( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, req: &payouts::PayoutRequest, @@ -1865,7 +1865,7 @@ pub async fn make_payout_data( } async fn validate_and_get_business_profile( - state: &AppState, + state: &SessionState, profile_id: &String, merchant_id: &str, ) -> RouterResult { diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs index df6e24122a2..99ce4853c7d 100644 --- a/crates/router/src/core/payouts/helpers.rs +++ b/crates/router/src/core/payouts/helpers.rs @@ -27,7 +27,7 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{ api::{self, enums as api_enums}, @@ -43,7 +43,7 @@ use crate::{ #[allow(clippy::too_many_arguments)] pub async fn make_payout_method_data<'a>( - state: &'a AppState, + state: &'a SessionState, payout_method_data: Option<&api::PayoutMethodData>, payout_token: Option<&str>, customer_id: &str, @@ -188,7 +188,7 @@ pub async fn make_payout_method_data<'a>( } pub async fn save_payout_data_to_locker( - state: &AppState, + state: &SessionState, payout_data: &mut PayoutData, payout_method_data: &api::PayoutMethodData, merchant_account: &domain::MerchantAccount, @@ -572,7 +572,7 @@ pub async fn save_payout_data_to_locker( } pub async fn get_or_create_customer_details( - state: &AppState, + state: &SessionState, customer_details: &CustomerDetails, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -632,7 +632,7 @@ pub async fn get_or_create_customer_details( } pub async fn decide_payout_connector( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, request_straight_through: Option, @@ -791,7 +791,7 @@ pub async fn decide_payout_connector( } pub async fn get_default_payout_connector( - _state: &AppState, + _state: &SessionState, request_connector: Option, ) -> CustomResult { Ok(request_connector.map_or( @@ -801,7 +801,7 @@ pub async fn get_default_payout_connector( } pub fn should_call_payout_connector_create_customer<'a>( - state: &AppState, + state: &SessionState, connector: &api::ConnectorData, customer: &'a Option, connector_label: &str, @@ -830,7 +830,7 @@ pub fn should_call_payout_connector_create_customer<'a>( } pub async fn get_gsm_record( - state: &AppState, + state: &SessionState, error_code: Option, error_message: Option, connector_name: Option, diff --git a/crates/router/src/core/payouts/retry.rs b/crates/router/src/core/payouts/retry.rs index 7c0b8265603..ff299550ebc 100644 --- a/crates/router/src/core/payouts/retry.rs +++ b/crates/router/src/core/payouts/retry.rs @@ -26,10 +26,10 @@ pub enum PayoutRetryType { MultiConnector, } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn do_gsm_multiple_connector_actions( - state: &app::AppState, + state: &app::SessionState, mut connectors: IntoIter, original_connector_data: api::ConnectorData, mut payout_data: PayoutData, @@ -95,10 +95,10 @@ pub async fn do_gsm_multiple_connector_actions( Ok(payout_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn do_gsm_single_connector_actions( - state: &app::AppState, + state: &app::SessionState, original_connector_data: api::ConnectorData, mut payout_data: PayoutData, merchant_account: &domain::MerchantAccount, @@ -161,9 +161,9 @@ pub async fn do_gsm_single_connector_actions( Ok(payout_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_retries( - state: &app::AppState, + state: &app::SessionState, retries: Option, merchant_id: &str, retry_type: PayoutRetryType, @@ -199,9 +199,9 @@ pub async fn get_retries( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_gsm( - state: &app::AppState, + state: &app::SessionState, original_connector_data: &api::ConnectorData, payout_data: &PayoutData, ) -> RouterResult> { @@ -216,7 +216,7 @@ pub async fn get_gsm( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn get_gsm_decision( option_gsm: Option, ) -> api_models::gsm::GsmDecision { @@ -239,9 +239,9 @@ pub fn get_gsm_decision( } #[allow(clippy::too_many_arguments)] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn do_retry( - state: &routes::AppState, + state: &routes::SessionState, connector: api::ConnectorData, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -263,9 +263,9 @@ pub async fn do_retry( .await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn modify_trackers( - state: &routes::AppState, + state: &routes::SessionState, connector: &api::ConnectorData, merchant_account: &domain::MerchantAccount, payout_data: &mut PayoutData, diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs index 02ba3066544..93c010bbcf4 100644 --- a/crates/router/src/core/payouts/validator.rs +++ b/crates/router/src/core/payouts/validator.rs @@ -11,12 +11,12 @@ use crate::{ utils as core_utils, }, db::StorageInterface, - routes::AppState, + routes::SessionState, types::{api::payouts, domain, storage}, utils, }; -#[instrument(skip(db))] +//#\[instrument\(skip(db))] pub async fn validate_uniqueness_of_payout_id_against_merchant_id( db: &dyn StorageInterface, payout_id: &str, @@ -45,7 +45,7 @@ pub async fn validate_uniqueness_of_payout_id_against_merchant_id( /// - payout_id is unique against merchant_id /// - payout_token provided is legitimate pub async fn validate_create_request( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, req: &payouts::PayoutCreateRequest, merchant_key_store: &domain::MerchantKeyStore, diff --git a/crates/router/src/core/pm_auth.rs b/crates/router/src/core/pm_auth.rs index 09b8ad9f868..b769b7c6e22 100644 --- a/crates/router/src/core/pm_auth.rs +++ b/crates/router/src/core/pm_auth.rs @@ -36,15 +36,12 @@ use crate::{ errors::{self, ApiErrorResponse, RouterResponse, RouterResult, StorageErrorExt}, payment_methods::cards, payments::helpers as oss_helpers, - pm_auth::helpers::{self as pm_auth_helpers}, + pm_auth::helpers as pm_auth_helpers, }, db::StorageInterface, logger, - routes::AppState, - services::{ - pm_auth::{self as pm_auth_services}, - ApplicationResponse, - }, + routes::SessionState, + services::{pm_auth as pm_auth_services, ApplicationResponse}, types::{ self, domain::{self, types::decrypt}, @@ -55,7 +52,7 @@ use crate::{ }; pub async fn create_link_token( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, payload: api_models::pm_auth::LinkTokenCreateRequest, @@ -160,7 +157,7 @@ pub async fn create_link_token( }; let connector_resp = pm_auth_services::execute_connector_processing_step( - state.as_ref(), + &state, connector_integration, &router_data, &connector.connector_name, @@ -205,7 +202,7 @@ impl ForeignTryFrom<&types::ConnectorAuthType> for PlaidAuthType { } pub async fn exchange_token_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, payload: api_models::pm_auth::ExchangeTokenCreateRequest, @@ -271,7 +268,7 @@ async fn store_bank_details_in_payment_methods( key_store: domain::MerchantKeyStore, payload: api_models::pm_auth::ExchangeTokenCreateRequest, merchant_account: domain::MerchantAccount, - state: AppState, + state: SessionState, bank_account_details_resp: pm_auth_types::BankAccountCredentialsResponse, connector_details: (&str, Secret), mca_id: String, @@ -504,7 +501,7 @@ pub async fn get_bank_account_creds( connector_name: &str, access_token: &Secret, auth_type: pm_auth_types::ConnectorAuthType, - state: &AppState, + state: &SessionState, bank_account_id: Option>, ) -> RouterResult { let connector_integration_bank_details: BoxedConnectorIntegration< @@ -559,7 +556,7 @@ async fn get_access_token_from_exchange_api( connector_name: &str, payload: &api_models::pm_auth::ExchangeTokenCreateRequest, auth_type: &pm_auth_types::ConnectorAuthType, - state: &AppState, + state: &SessionState, ) -> RouterResult> { let connector_integration: BoxedConnectorIntegration< '_, @@ -643,7 +640,7 @@ async fn get_selected_config_from_redis( } pub async fn retrieve_payment_method_from_auth_service( - state: &AppState, + state: &SessionState, key_store: &domain::MerchantKeyStore, auth_token: &payment_methods::BankAccountTokenData, payment_intent: &PaymentIntent, diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 2d6cac3f6e0..e9ed25cd15b 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -13,7 +13,7 @@ use crate::{ utils as core_utils, }, db, logger, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services, types::{ self, @@ -28,9 +28,9 @@ use crate::{ // ********************************************** REFUND EXECUTE ********************************************** -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn refund_create_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, req: refunds::RefundRequest, @@ -119,9 +119,9 @@ pub async fn refund_create_core( .map(services::ApplicationResponse::Json) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn trigger_refund_to_gateway( - state: &AppState, + state: &SessionState, refund: &storage::Refund, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -302,14 +302,14 @@ pub async fn trigger_refund_to_gateway( // ********************************************** REFUND SYNC ********************************************** pub async fn refund_response_wrapper<'a, F, Fut, T, Req>( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, request: Req, f: F, ) -> RouterResponse where - F: Fn(AppState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut, + F: Fn(SessionState, domain::MerchantAccount, domain::MerchantKeyStore, Req) -> Fut, Fut: futures::Future>, T: ForeignInto, { @@ -320,9 +320,9 @@ where )) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn refund_retrieve_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, request: refunds::RefundsRetrieveRequest, @@ -415,9 +415,9 @@ fn should_call_refund(refund: &diesel_models::refund::Refund, force_sync: bool) predicate1 && predicate2 } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn sync_refund_with_gateway( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, payment_attempt: &storage::PaymentAttempt, @@ -523,7 +523,7 @@ pub async fn sync_refund_with_gateway( // ********************************************** REFUND UPDATE ********************************************** pub async fn refund_update_core( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: refunds::RefundUpdateRequest, ) -> RouterResponse { @@ -558,10 +558,10 @@ pub async fn refund_update_core( // ********************************************** VALIDATIONS ********************************************** -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn validate_and_create_refund( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, payment_attempt: &storage::PaymentAttempt, @@ -702,10 +702,10 @@ pub async fn validate_and_create_refund( /// If payment-id is provided, lists all the refunds associated with that particular payment-id /// If payment-id is not provided, lists the refunds associated with that particular merchant - to the limit specified,if no limits given, it is 10 by default -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[cfg(feature = "olap")] pub async fn refund_list( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: api_models::refunds::RefundListRequest, ) -> RouterResponse { @@ -747,10 +747,10 @@ pub async fn refund_list( )) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[cfg(feature = "olap")] pub async fn refund_filter_list( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, req: api_models::payments::TimeRange, ) -> RouterResponse { @@ -791,10 +791,10 @@ impl ForeignFrom for api::RefundResponse { // ********************************************** PROCESS TRACKER ********************************************** -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn schedule_refund_execution( - state: &AppState, + state: &SessionState, refund: storage::Refund, refund_type: api_models::refunds::RefundType, merchant_account: &domain::MerchantAccount, @@ -869,9 +869,9 @@ pub async fn schedule_refund_execution( Ok(result) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn sync_refund_with_gateway_workflow( - state: &AppState, + state: &SessionState, refund_tracker: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { let refund_core = @@ -938,9 +938,9 @@ pub async fn sync_refund_with_gateway_workflow( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn start_refund_workflow( - state: &AppState, + state: &SessionState, refund_tracker: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { match refund_tracker.name.as_deref() { @@ -954,9 +954,9 @@ pub async fn start_refund_workflow( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn trigger_refund_execute_workflow( - state: &AppState, + state: &SessionState, refund_tracker: &storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { let db = &*state.store; @@ -1057,7 +1057,7 @@ pub async fn trigger_refund_execute_workflow( Ok(()) } -#[instrument] +//#[instrument] pub fn refund_to_refund_core_workflow_model( refund: &storage::Refund, ) -> storage::RefundCoreWorkflow { @@ -1069,7 +1069,7 @@ pub fn refund_to_refund_core_workflow_model( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn add_refund_sync_task( db: &dyn db::StorageInterface, refund: &storage::Refund, @@ -1110,7 +1110,7 @@ pub async fn add_refund_sync_task( Ok(response) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn add_refund_execute_task( db: &dyn db::StorageInterface, refund: &storage::Refund, diff --git a/crates/router/src/core/refunds/validator.rs b/crates/router/src/core/refunds/validator.rs index 43d44ebe41d..88c6f6ad3eb 100644 --- a/crates/router/src/core/refunds/validator.rs +++ b/crates/router/src/core/refunds/validator.rs @@ -27,7 +27,7 @@ pub enum RefundValidationError { DuplicateRefund, } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_success_transaction( transaction: &storage::PaymentAttempt, ) -> CustomResult<(), RefundValidationError> { @@ -38,7 +38,7 @@ pub fn validate_success_transaction( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_refund_amount( amount_captured: i64, all_refunds: &[storage::Refund], @@ -67,7 +67,7 @@ pub fn validate_refund_amount( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_payment_order_age( created_at: &PrimitiveDateTime, refund_max_age: i64, @@ -80,7 +80,7 @@ pub fn validate_payment_order_age( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub fn validate_maximum_refund_against_payment_attempt( all_refunds: &[storage::Refund], refund_max_attempts: usize, diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs index bec90c51e9c..77e3f7de01e 100644 --- a/crates/router/src/core/routing.rs +++ b/crates/router/src/core/routing.rs @@ -26,7 +26,7 @@ use crate::{ errors::{RouterResponse, StorageErrorExt}, metrics, utils as core_utils, }, - routes::AppState, + routes::SessionState, types::domain, utils::{self, OptionExt, ValueExt}, }; @@ -45,7 +45,7 @@ where } pub async fn retrieve_merchant_routing_dictionary( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, #[cfg(feature = "business_profile_routing")] query_params: RoutingRetrieveQuery, #[cfg(feature = "business_profile_routing")] transaction_type: &enums::TransactionType, @@ -92,7 +92,7 @@ pub async fn retrieve_merchant_routing_dictionary( } pub async fn create_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, request: routing_types::RoutingConfigRequest, @@ -247,7 +247,7 @@ pub async fn create_routing_config( } pub async fn link_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, #[cfg(not(feature = "business_profile_routing"))] key_store: domain::MerchantKeyStore, algorithm_id: String, @@ -370,7 +370,7 @@ pub async fn link_routing_config( } pub async fn retrieve_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, algorithm_id: RoutingAlgorithmId, ) -> RouterResponse { @@ -444,7 +444,7 @@ pub async fn retrieve_routing_config( } } pub async fn unlink_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, #[cfg(not(feature = "business_profile_routing"))] key_store: domain::MerchantKeyStore, #[cfg(feature = "business_profile_routing")] request: routing_types::RoutingConfigRequest, @@ -629,7 +629,7 @@ pub async fn unlink_routing_config( } pub async fn update_default_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, updated_config: Vec, transaction_type: &enums::TransactionType, @@ -678,7 +678,7 @@ pub async fn update_default_routing_config( } pub async fn retrieve_default_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, transaction_type: &enums::TransactionType, ) -> RouterResponse> { @@ -698,7 +698,7 @@ pub async fn retrieve_default_routing_config( } pub async fn retrieve_linked_routing_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, #[cfg(feature = "business_profile_routing")] query_params: RoutingRetrieveLinkQuery, #[cfg(feature = "business_profile_routing")] transaction_type: &enums::TransactionType, @@ -807,7 +807,7 @@ pub async fn retrieve_linked_routing_config( } pub async fn upsert_connector_agnostic_mandate_config( - state: AppState, + state: SessionState, business_profile_id: &str, mandate_config: routing_types::DetailedConnectorChoice, ) -> RouterResponse { @@ -838,7 +838,7 @@ pub async fn upsert_connector_agnostic_mandate_config( } pub async fn retrieve_default_routing_config_for_profiles( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, transaction_type: &enums::TransactionType, ) -> RouterResponse> { @@ -877,7 +877,7 @@ pub async fn retrieve_default_routing_config_for_profiles( } pub async fn update_default_routing_config_for_profile( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, updated_config: Vec, profile_id: String, diff --git a/crates/router/src/core/surcharge_decision_config.rs b/crates/router/src/core/surcharge_decision_config.rs index b489b92cdf1..7f451e6008f 100644 --- a/crates/router/src/core/surcharge_decision_config.rs +++ b/crates/router/src/core/surcharge_decision_config.rs @@ -15,14 +15,14 @@ use super::routing::helpers::{ }; use crate::{ core::errors::{self, RouterResponse}, - routes::AppState, + routes::SessionState, services::api as service_api, types::domain, utils::OptionExt, }; pub async fn upsert_surcharge_decision_config( - state: AppState, + state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, request: SurchargeDecisionConfigReq, @@ -139,7 +139,7 @@ pub async fn upsert_surcharge_decision_config( } pub async fn delete_surcharge_decision_config( - state: AppState, + state: SessionState, key_store: domain::MerchantKeyStore, merchant_account: domain::MerchantAccount, ) -> RouterResponse<()> { @@ -167,7 +167,7 @@ pub async fn delete_surcharge_decision_config( } pub async fn retrieve_surcharge_decision_config( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, ) -> RouterResponse { let db = state.store.as_ref(); diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs index 364af0f83dd..a2b5c3b83fc 100644 --- a/crates/router/src/core/user.rs +++ b/crates/router/src/core/user.rs @@ -15,7 +15,7 @@ use super::errors::{StorageErrorExt, UserErrors, UserResponse, UserResult}; use crate::services::email::types as email_types; use crate::{ consts, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services::{authentication as auth, authorization::roles, ApplicationResponse}, types::{domain, transformers::ForeignInto}, utils, @@ -26,7 +26,7 @@ pub mod sample_data; #[cfg(feature = "email")] pub async fn signup_with_merchant_id( - state: AppState, + state: SessionState, request: user_api::SignUpWithMerchantIdRequest, ) -> UserResponse { let new_user = domain::NewUser::try_from(request.clone())?; @@ -72,7 +72,7 @@ pub async fn signup_with_merchant_id( } pub async fn signup( - state: AppState, + state: SessionState, request: user_api::SignUpRequest, ) -> UserResponse { let new_user = domain::NewUser::try_from(request)?; @@ -101,7 +101,7 @@ pub async fn signup( } pub async fn signin_without_invite_checks( - state: AppState, + state: SessionState, request: user_api::SignInRequest, ) -> UserResponse { let user_from_db: domain::UserFromStorage = state @@ -129,7 +129,7 @@ pub async fn signin_without_invite_checks( } pub async fn signin( - state: AppState, + state: SessionState, request: user_api::SignInRequest, ) -> UserResponse { let user_from_db: domain::UserFromStorage = state @@ -174,7 +174,7 @@ pub async fn signin( #[cfg(feature = "email")] pub async fn connect_account( - state: AppState, + state: SessionState, request: user_api::ConnectAccountRequest, ) -> UserResponse { let find_user = state @@ -268,13 +268,16 @@ pub async fn connect_account( } } -pub async fn signout(state: AppState, user_from_token: auth::UserFromToken) -> UserResponse<()> { +pub async fn signout( + state: SessionState, + user_from_token: auth::UserFromToken, +) -> UserResponse<()> { auth::blacklist::insert_user_in_blacklist(&state, &user_from_token.user_id).await?; auth::cookies::remove_cookie_response() } pub async fn change_password( - state: AppState, + state: SessionState, request: user_api::ChangePasswordRequest, user_from_token: auth::UserFromToken, ) -> UserResponse<()> { @@ -333,7 +336,7 @@ pub async fn change_password( #[cfg(feature = "email")] pub async fn forgot_password( - state: AppState, + state: SessionState, request: user_api::ForgotPasswordRequest, ) -> UserResponse<()> { let user_email = domain::UserEmail::from_pii_email(request.email)?; @@ -372,7 +375,7 @@ pub async fn forgot_password( #[cfg(feature = "email")] pub async fn reset_password( - state: AppState, + state: SessionState, request: user_api::ResetPasswordRequest, ) -> UserResponse<()> { let token = request.token.expose(); @@ -426,7 +429,7 @@ pub async fn reset_password( } pub async fn invite_user( - state: AppState, + state: SessionState, request: user_api::InviteUserRequest, user_from_token: auth::UserFromToken, req_state: ReqState, @@ -626,7 +629,7 @@ pub async fn invite_user( } pub async fn invite_multiple_user( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, requests: Vec, req_state: ReqState, @@ -653,7 +656,7 @@ pub async fn invite_multiple_user( } async fn handle_invitation( - state: &AppState, + state: &SessionState, user_from_token: &auth::UserFromToken, request: &user_api::InviteUserRequest, req_state: &ReqState, @@ -703,7 +706,7 @@ async fn handle_invitation( //TODO: send email async fn handle_existing_user_invitation( - state: &AppState, + state: &SessionState, user_from_token: &auth::UserFromToken, request: &user_api::InviteUserRequest, invitee_user_from_db: domain::UserFromStorage, @@ -774,7 +777,7 @@ async fn handle_existing_user_invitation( } async fn handle_new_user_invitation( - state: &AppState, + state: &SessionState, user_from_token: &auth::UserFromToken, request: &user_api::InviteUserRequest, req_state: ReqState, @@ -874,7 +877,7 @@ async fn handle_new_user_invitation( #[cfg(feature = "email")] pub async fn resend_invite( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, request: user_api::ReInviteUserRequest, _req_state: ReqState, @@ -936,7 +939,7 @@ pub async fn resend_invite( #[cfg(feature = "email")] pub async fn accept_invite_from_email( - state: AppState, + state: SessionState, request: user_api::AcceptInviteFromEmailRequest, ) -> UserResponse { let token = request.token.expose(); @@ -998,7 +1001,7 @@ pub async fn accept_invite_from_email( } pub async fn create_internal_user( - state: AppState, + state: SessionState, request: user_api::CreateInternalUserRequest, ) -> UserResponse<()> { let new_user = domain::NewUser::try_from(request)?; @@ -1061,7 +1064,7 @@ pub async fn create_internal_user( } pub async fn switch_merchant_id( - state: AppState, + state: SessionState, request: user_api::SwitchMerchantIdRequest, user_from_token: auth::UserFromToken, ) -> UserResponse { @@ -1160,7 +1163,7 @@ pub async fn switch_merchant_id( } pub async fn create_merchant_account( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, req: user_api::UserMerchantCreate, ) -> UserResponse<()> { @@ -1191,7 +1194,7 @@ pub async fn create_merchant_account( } pub async fn list_merchants_for_user( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, ) -> UserResponse> { let user_roles = state @@ -1224,7 +1227,7 @@ pub async fn list_merchants_for_user( } pub async fn get_user_details_in_merchant_account( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, request: user_api::GetUserDetailsRequest, _req_state: ReqState, @@ -1268,7 +1271,7 @@ pub async fn get_user_details_in_merchant_account( } pub async fn list_users_for_merchant_account( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, ) -> UserResponse { let users_and_user_roles = state @@ -1316,7 +1319,7 @@ pub async fn list_users_for_merchant_account( #[cfg(feature = "email")] pub async fn verify_email_without_invite_checks( - state: AppState, + state: SessionState, req: user_api::VerifyEmailRequest, ) -> UserResponse { let token = req.token.clone().expose(); @@ -1340,7 +1343,7 @@ pub async fn verify_email_without_invite_checks( .await .map_err(|e| logger::error!(?e)); let token = utils::user::generate_jwt_auth_token(&state, &user_from_db, &user_role).await?; - utils::user_role::set_role_permissions_in_cache_by_user_role(&state, &user_role).await; + utils::user_role::set_role_permissions_in_cache_by_user_role(&state, &user_role, &state).await; let response = utils::user::get_dashboard_entry_response(&state, user_from_db, user_role, token.clone())?; @@ -1350,7 +1353,7 @@ pub async fn verify_email_without_invite_checks( #[cfg(feature = "email")] pub async fn verify_email( - state: AppState, + state: SessionState, req: user_api::VerifyEmailRequest, ) -> UserResponse { let token = req.token.clone().expose(); @@ -1405,7 +1408,7 @@ pub async fn verify_email( #[cfg(feature = "email")] pub async fn send_verification_mail( - state: AppState, + state: SessionState, req: user_api::SendVerifyEmailRequest, ) -> UserResponse<()> { let user_email = domain::UserEmail::try_from(req.email)?; @@ -1445,7 +1448,7 @@ pub async fn send_verification_mail( #[cfg(feature = "recon")] pub async fn verify_token( - state: AppState, + state: SessionState, req: auth::ReconUser, ) -> UserResponse { let user = state @@ -1473,7 +1476,7 @@ pub async fn verify_token( } pub async fn update_user_details( - state: AppState, + state: SessionState, user_token: auth::UserFromToken, req: user_api::UpdateUserAccountDetailsRequest, _req_state: ReqState, diff --git a/crates/router/src/core/user/dashboard_metadata.rs b/crates/router/src/core/user/dashboard_metadata.rs index bd4b2c3a10d..16e13c165fa 100644 --- a/crates/router/src/core/user/dashboard_metadata.rs +++ b/crates/router/src/core/user/dashboard_metadata.rs @@ -10,7 +10,7 @@ use router_env::logger; use crate::{ core::errors::{UserErrors, UserResponse, UserResult}, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services::{authentication::UserFromToken, ApplicationResponse}, types::domain::{user::dashboard_metadata as types, MerchantKeyStore}, utils::user::dashboard_metadata as utils, @@ -19,7 +19,7 @@ use crate::{ use crate::{services::email::types as email_types, types::domain}; pub async fn set_metadata( - state: AppState, + state: SessionState, user: UserFromToken, request: api::SetMetaDataRequest, _req_state: ReqState, @@ -33,7 +33,7 @@ pub async fn set_metadata( } pub async fn get_multiple_metadata( - state: AppState, + state: SessionState, user: UserFromToken, request: GetMultipleMetaDataPayload, _req_state: ReqState, @@ -222,7 +222,7 @@ fn into_response( } async fn insert_metadata( - state: &AppState, + state: &SessionState, user: UserFromToken, metadata_key: DBEnum, metadata_value: types::MetaData, @@ -552,7 +552,7 @@ async fn insert_metadata( } async fn fetch_metadata( - state: &AppState, + state: &SessionState, user: &UserFromToken, metadata_keys: Vec, ) -> UserResult> { @@ -587,7 +587,7 @@ async fn fetch_metadata( } pub async fn backfill_metadata( - state: &AppState, + state: &SessionState, user: &UserFromToken, key: &DBEnum, ) -> UserResult> { @@ -686,7 +686,7 @@ pub async fn backfill_metadata( } pub async fn get_merchant_connector_account_by_name( - state: &AppState, + state: &SessionState, merchant_id: &str, connector_name: &str, key_store: &MerchantKeyStore, diff --git a/crates/router/src/core/user/sample_data.rs b/crates/router/src/core/user/sample_data.rs index f95f48f19e7..483bcc6cd0d 100644 --- a/crates/router/src/core/user/sample_data.rs +++ b/crates/router/src/core/user/sample_data.rs @@ -7,13 +7,13 @@ pub type SampleDataApiResponse = SampleDataResult>; use crate::{ core::errors::sample_data::SampleDataResult, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services::{authentication::UserFromToken, ApplicationResponse}, utils::user::sample_data::generate_sample_data, }; pub async fn generate_sample_data_for_user( - state: AppState, + state: SessionState, user_from_token: UserFromToken, req: SampleDataRequest, _req_state: ReqState, @@ -57,7 +57,7 @@ pub async fn generate_sample_data_for_user( } pub async fn delete_sample_data_for_user( - state: AppState, + state: SessionState, user_from_token: UserFromToken, _req: SampleDataRequest, _req_state: ReqState, diff --git a/crates/router/src/core/user_role.rs b/crates/router/src/core/user_role.rs index 6ddab570aed..1b900c68861 100644 --- a/crates/router/src/core/user_role.rs +++ b/crates/router/src/core/user_role.rs @@ -7,7 +7,7 @@ use router_env::logger; use crate::{ consts, core::errors::{StorageErrorExt, UserErrors, UserResponse}, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services::{ authentication as auth, authorization::{info, roles}, @@ -21,7 +21,7 @@ pub mod role; // TODO: To be deprecated once groups are stable pub async fn get_authorization_info_with_modules( - _state: AppState, + _state: SessionState, ) -> UserResponse { Ok(ApplicationResponse::Json( user_role_api::AuthorizationInfoResponse( @@ -34,7 +34,7 @@ pub async fn get_authorization_info_with_modules( } pub async fn get_authorization_info_with_groups( - _state: AppState, + _state: SessionState, ) -> UserResponse { Ok(ApplicationResponse::Json( user_role_api::AuthorizationInfoResponse( @@ -47,7 +47,7 @@ pub async fn get_authorization_info_with_groups( } pub async fn update_user_role( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, req: user_role_api::UpdateUserRoleRequest, _req_state: ReqState, @@ -118,7 +118,7 @@ pub async fn update_user_role( } pub async fn transfer_org_ownership( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, req: user_role_api::TransferOrgOwnershipRequest, _req_state: ReqState, @@ -170,7 +170,7 @@ pub async fn transfer_org_ownership( } pub async fn accept_invitation( - state: AppState, + state: SessionState, user_token: auth::UserWithoutMerchantFromToken, req: user_role_api::AcceptInvitationRequest, _req_state: ReqState, @@ -223,7 +223,7 @@ pub async fn accept_invitation( } pub async fn delete_user_role( - state: AppState, + state: SessionState, user_from_token: auth::UserFromToken, request: user_role_api::DeleteUserRoleRequest, _req_state: ReqState, diff --git a/crates/router/src/core/user_role/role.rs b/crates/router/src/core/user_role/role.rs index 504d5dd632b..386156f58e7 100644 --- a/crates/router/src/core/user_role/role.rs +++ b/crates/router/src/core/user_role/role.rs @@ -7,7 +7,7 @@ use error_stack::{report, ResultExt}; use crate::{ consts, core::errors::{StorageErrorExt, UserErrors, UserResponse}, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, services::{ authentication::{blacklist, UserFromToken}, authorization::roles::{self, predefined_roles::PREDEFINED_ROLES}, @@ -18,7 +18,7 @@ use crate::{ }; pub async fn get_role_from_token_with_permissions( - state: AppState, + state: SessionState, user_from_token: UserFromToken, ) -> UserResponse { let role_info = user_from_token @@ -38,7 +38,7 @@ pub async fn get_role_from_token_with_permissions( } pub async fn get_role_from_token_with_groups( - state: AppState, + state: SessionState, user_from_token: UserFromToken, ) -> UserResponse { let role_info = user_from_token @@ -54,7 +54,7 @@ pub async fn get_role_from_token_with_groups( } pub async fn create_role( - state: AppState, + state: SessionState, user_from_token: UserFromToken, req: role_api::CreateRoleRequest, _req_state: ReqState, @@ -107,7 +107,7 @@ pub async fn create_role( // TODO: To be deprecated once groups are stable pub async fn list_invitable_roles_with_permissions( - state: AppState, + state: SessionState, user_from_token: UserFromToken, ) -> UserResponse { let predefined_roles_map = PREDEFINED_ROLES @@ -156,7 +156,7 @@ pub async fn list_invitable_roles_with_permissions( } pub async fn list_invitable_roles_with_groups( - state: AppState, + state: SessionState, user_from_token: UserFromToken, ) -> UserResponse { let predefined_roles_map = PREDEFINED_ROLES @@ -198,7 +198,7 @@ pub async fn list_invitable_roles_with_groups( // TODO: To be deprecated once groups are stable pub async fn get_role_with_permissions( - state: AppState, + state: SessionState, user_from_token: UserFromToken, role: role_api::GetRoleRequest, ) -> UserResponse { @@ -232,7 +232,7 @@ pub async fn get_role_with_permissions( } pub async fn get_role_with_groups( - state: AppState, + state: SessionState, user_from_token: UserFromToken, role: role_api::GetRoleRequest, ) -> UserResponse { @@ -260,7 +260,7 @@ pub async fn get_role_with_groups( } pub async fn update_role( - state: AppState, + state: SessionState, user_from_token: UserFromToken, req: role_api::UpdateRoleRequest, role_id: &str, diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 3423ace6e5b..4b66b47a462 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -19,7 +19,7 @@ use crate::{ consts, core::errors::{self, RouterResult, StorageErrorExt}, db::StorageInterface, - routes::AppState, + routes::SessionState, types::{ self, domain, storage::{self, enums}, @@ -34,9 +34,9 @@ const IRRELEVANT_PAYMENT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_payment_id_in_di const IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_attempt_id_in_dispute_flow"; #[cfg(feature = "payouts")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_mca_for_payout<'a>( - state: &'a AppState, + state: &'a SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -61,9 +61,9 @@ pub async fn get_mca_for_payout<'a>( } #[cfg(feature = "payouts")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_payout_router_data<'a, F>( - state: &'a AppState, + state: &'a SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -192,10 +192,10 @@ pub async fn construct_payout_router_data<'a, F>( Ok(router_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn construct_refund_router_data<'a, F>( - state: &'a AppState, + state: &'a SessionState, connector_id: &str, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, @@ -487,9 +487,9 @@ pub fn validate_dispute_stage_and_dispute_status( ) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_accept_dispute_router_data<'a>( - state: &'a AppState, + state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, @@ -580,9 +580,9 @@ pub async fn construct_accept_dispute_router_data<'a>( Ok(router_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_submit_evidence_router_data<'a>( - state: &'a AppState, + state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, @@ -672,10 +672,10 @@ pub async fn construct_submit_evidence_router_data<'a>( Ok(router_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn construct_upload_file_router_data<'a>( - state: &'a AppState, + state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, @@ -770,9 +770,9 @@ pub async fn construct_upload_file_router_data<'a>( Ok(router_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_defend_dispute_router_data<'a>( - state: &'a AppState, + state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, payment_attempt: &storage::PaymentAttempt, merchant_account: &domain::MerchantAccount, @@ -865,9 +865,9 @@ pub async fn construct_defend_dispute_router_data<'a>( Ok(router_data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn construct_retrieve_file_router_data<'a>( - state: &'a AppState, + state: &'a SessionState, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, file_metadata: &diesel_models::file::FileMetadata, diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs index 3f738df5920..d84e3ef7932 100644 --- a/crates/router/src/core/verification.rs +++ b/crates/router/src/core/verification.rs @@ -4,12 +4,17 @@ use common_utils::{errors::CustomResult, request::RequestContent}; use error_stack::ResultExt; use masking::ExposeInterface; -use crate::{core::errors::api_error_response, headers, logger, routes::AppState, services}; +use crate::{ + core::errors::api_error_response, + headers, logger, + routes::SessionState, + services, +}; const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant"; pub async fn verify_merchant_creds_for_applepay( - state: AppState, + state: SessionState, body: verifications::ApplepayMerchantVerificationRequest, merchant_id: String, ) -> CustomResult< @@ -85,7 +90,7 @@ pub async fn verify_merchant_creds_for_applepay( } pub async fn get_verified_apple_domains_with_mid_mca_id( - state: AppState, + state: SessionState, merchant_id: String, merchant_connector_id: String, ) -> CustomResult< diff --git a/crates/router/src/core/verification/utils.rs b/crates/router/src/core/verification/utils.rs index 56960d3cb48..7518091ee87 100644 --- a/crates/router/src/core/verification/utils.rs +++ b/crates/router/src/core/verification/utils.rs @@ -4,13 +4,13 @@ use error_stack::{Report, ResultExt}; use crate::{ core::errors::{self, utils::StorageErrorExt}, logger, - routes::AppState, + routes::SessionState, types, types::storage, }; pub async fn check_existence_and_add_domain_to_db( - state: &AppState, + state: &SessionState, merchant_id: String, merchant_connector_id: String, domain_from_req: Vec, diff --git a/crates/router/src/core/verify_connector.rs b/crates/router/src/core/verify_connector.rs index 17cedd1e2d0..8574fdb22d3 100644 --- a/crates/router/src/core/verify_connector.rs +++ b/crates/router/src/core/verify_connector.rs @@ -10,11 +10,11 @@ use crate::{ api::verify_connector::{self as types, VerifyConnector}, }, utils::verify_connector as utils, - AppState, + SessionState, }; pub async fn verify_connector_credentials( - state: AppState, + state: SessionState, req: VerifyConnectorRequest, ) -> errors::RouterResponse<()> { let boxed_connector = api::ConnectorData::get_connector_by_name( diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs index 278ac8f970e..769ee4ec370 100644 --- a/crates/router/src/core/webhooks.rs +++ b/crates/router/src/core/webhooks.rs @@ -40,10 +40,10 @@ use crate::{ }, logger, routes::{ - app::{AppStateInfo, ReqState}, + app::{ReqState, SessionStateInfo}, lock_utils, metrics::request::add_attributes, - AppState, + SessionState, }, services::{self, authentication as auth}, types::{ @@ -60,7 +60,7 @@ const OUTGOING_WEBHOOK_TIMEOUT_SECS: u64 = 5; const MERCHANT_ID: &str = "merchant_id"; pub async fn payments_incoming_webhook_flow( - state: AppState, + state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, business_profile: diesel_models::business_profile::BusinessProfile, @@ -203,10 +203,10 @@ pub async fn payments_incoming_webhook_flow( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn refunds_incoming_webhook_flow( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, business_profile: diesel_models::business_profile::BusinessProfile, key_store: domain::MerchantKeyStore, @@ -304,7 +304,7 @@ pub async fn refunds_incoming_webhook_flow( } pub async fn get_payment_attempt_from_object_reference_id( - state: &AppState, + state: &SessionState, object_reference_id: api_models::webhooks::ObjectReferenceId, merchant_account: &domain::MerchantAccount, ) -> CustomResult @@ -342,7 +342,7 @@ pub async fn get_payment_attempt_from_object_reference_id( #[allow(clippy::too_many_arguments)] pub async fn get_or_update_dispute_object( - state: AppState, + state: SessionState, option_dispute: Option, dispute_details: api::disputes::DisputePayload, merchant_id: &str, @@ -417,7 +417,7 @@ pub async fn get_or_update_dispute_object( } pub async fn mandates_incoming_webhook_flow( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, business_profile: diesel_models::business_profile::BusinessProfile, key_store: domain::MerchantKeyStore, @@ -498,9 +498,9 @@ pub async fn mandates_incoming_webhook_flow( } #[allow(clippy::too_many_arguments)] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn disputes_incoming_webhook_flow( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, business_profile: diesel_models::business_profile::BusinessProfile, key_store: domain::MerchantKeyStore, @@ -570,7 +570,7 @@ pub async fn disputes_incoming_webhook_flow( } async fn bank_transfer_webhook_flow( - state: AppState, + state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, business_profile: diesel_models::business_profile::BusinessProfile, @@ -658,9 +658,9 @@ async fn bank_transfer_webhook_flow( } #[allow(clippy::too_many_arguments)] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) async fn create_event_and_trigger_outgoing_webhook( - state: AppState, + state: SessionState, merchant_account: domain::MerchantAccount, business_profile: diesel_models::business_profile::BusinessProfile, merchant_key_store: &domain::MerchantKeyStore, @@ -798,9 +798,9 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook( } #[allow(clippy::too_many_arguments)] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) async fn trigger_webhook_and_raise_event( - state: AppState, + state: SessionState, business_profile: diesel_models::business_profile::BusinessProfile, merchant_key_store: &domain::MerchantKeyStore, event: domain::Event, @@ -832,7 +832,7 @@ pub(crate) async fn trigger_webhook_and_raise_event( } async fn trigger_webhook_to_merchant( - state: AppState, + state: SessionState, business_profile: diesel_models::business_profile::BusinessProfile, merchant_key_store: &domain::MerchantKeyStore, event: domain::Event, @@ -898,7 +898,7 @@ async fn trigger_webhook_to_merchant( logger::debug!(outgoing_webhook_response=?response); let update_event_if_client_error = - |state: AppState, + |state: SessionState, merchant_key_store: domain::MerchantKeyStore, merchant_id: String, event_id: String, @@ -943,7 +943,7 @@ async fn trigger_webhook_to_merchant( }; let api_client_error_handler = - |state: AppState, + |state: SessionState, merchant_key_store: domain::MerchantKeyStore, merchant_id: String, event_id: String, @@ -970,7 +970,7 @@ async fn trigger_webhook_to_merchant( Ok::<_, error_stack::Report>(()) }; - let update_event_in_storage = |state: AppState, + let update_event_in_storage = |state: SessionState, merchant_key_store: domain::MerchantKeyStore, merchant_id: String, event_id: String, @@ -1048,7 +1048,7 @@ async fn trigger_webhook_to_merchant( ) }; let success_response_handler = - |state: AppState, + |state: SessionState, merchant_id: String, process_tracker: Option, business_status: &'static str| async move { @@ -1230,7 +1230,7 @@ async fn trigger_webhook_to_merchant( } fn raise_webhooks_analytics_event( - state: AppState, + state: SessionState, trigger_webhook_result: CustomResult<(), errors::WebhooksFlowError>, content: Option, merchant_id: String, @@ -1267,7 +1267,7 @@ fn raise_webhooks_analytics_event( #[allow(clippy::too_many_arguments)] pub async fn webhooks_wrapper( flow: &impl router_env::types::FlowMetric, - state: AppState, + state: SessionState, req_state: ReqState, req: &actix_web::HttpRequest, merchant_account: domain::MerchantAccount, @@ -1327,9 +1327,9 @@ pub async fn webhooks_wrapper( - state: AppState, + state: SessionState, req_state: ReqState, req: &actix_web::HttpRequest, merchant_account: domain::MerchantAccount, @@ -1702,7 +1702,7 @@ pub async fn get_payment_id( /// This function fetches the merchant connector account ( if the url used is /{merchant_connector_id}) /// if merchant connector id is not passed in the request, then this will return None for mca async fn fetch_optional_mca_and_connector( - state: &AppState, + state: &SessionState, merchant_account: &domain::MerchantAccount, connector_name_or_mca_id: &str, key_store: &domain::MerchantKeyStore, diff --git a/crates/router/src/core/webhooks/webhook_events.rs b/crates/router/src/core/webhooks/webhook_events.rs index 6db214c2b05..356c7637cc4 100644 --- a/crates/router/src/core/webhooks/webhook_events.rs +++ b/crates/router/src/core/webhooks/webhook_events.rs @@ -4,7 +4,7 @@ use router_env::{instrument, tracing}; use crate::{ core::errors::{self, RouterResponse, StorageErrorExt}, - routes::AppState, + routes::SessionState, services::ApplicationResponse, types::{api, domain, storage, transformers::ForeignTryFrom}, utils::{OptionExt, StringExt}, @@ -18,9 +18,9 @@ enum MerchantAccountOrBusinessProfile { BusinessProfile(storage::BusinessProfile), } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn list_initial_delivery_attempts( - state: AppState, + state: SessionState, merchant_id_or_profile_id: String, constraints: api::webhook_events::EventListConstraints, ) -> RouterResponse> { @@ -106,9 +106,9 @@ pub async fn list_initial_delivery_attempts( )) } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn list_delivery_attempts( - state: AppState, + state: SessionState, merchant_id_or_profile_id: String, initial_attempt_id: String, ) -> RouterResponse> { @@ -155,9 +155,9 @@ pub async fn list_delivery_attempts( } } -#[instrument(skip(state))] +//#\[instrument\(skip(state))] pub async fn retry_delivery_attempt( - state: AppState, + state: SessionState, merchant_id_or_profile_id: String, event_id: String, ) -> RouterResponse { @@ -254,7 +254,7 @@ pub async fn retry_delivery_attempt( } async fn determine_identifier_and_get_key_store( - state: AppState, + state: SessionState, merchant_id_or_profile_id: String, ) -> errors::RouterResult<(MerchantAccountOrBusinessProfile, domain::MerchantKeyStore)> { let store = state.store.as_ref(); diff --git a/crates/router/src/db/address.rs b/crates/router/src/db/address.rs index 8eb281184f6..54dad91b72a 100644 --- a/crates/router/src/db/address.rs +++ b/crates/router/src/db/address.rs @@ -94,7 +94,7 @@ mod storage { }; #[async_trait::async_trait] impl AddressInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_address_by_address_id( &self, address_id: &str, @@ -113,7 +113,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_address_by_merchant_id_payment_id_address_id( &self, merchant_id: &str, @@ -140,7 +140,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_address( &self, address_id: String, @@ -160,7 +160,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_address_for_payments( &self, this: domain::Address, @@ -186,7 +186,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_address_for_payments( &self, _payment_id: &str, @@ -211,7 +211,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_address_for_customers( &self, address: domain::Address, @@ -234,7 +234,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_address_by_merchant_id_customer_id( &self, customer_id: &str, @@ -293,7 +293,7 @@ mod storage { }; #[async_trait::async_trait] impl AddressInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_address_by_address_id( &self, address_id: &str, @@ -312,7 +312,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_address_by_merchant_id_payment_id_address_id( &self, merchant_id: &str, @@ -361,7 +361,7 @@ mod storage { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_address( &self, address_id: String, @@ -381,7 +381,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_address_for_payments( &self, this: domain::Address, @@ -452,7 +452,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_address_for_payments( &self, payment_id: &str, @@ -544,7 +544,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_address_for_customers( &self, address: domain::Address, @@ -567,7 +567,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_address_by_merchant_id_customer_id( &self, customer_id: &str, diff --git a/crates/router/src/db/api_keys.rs b/crates/router/src/db/api_keys.rs index a23b3f0f7af..cbfd602a847 100644 --- a/crates/router/src/db/api_keys.rs +++ b/crates/router/src/db/api_keys.rs @@ -53,7 +53,7 @@ pub trait ApiKeyInterface { #[async_trait::async_trait] impl ApiKeyInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_api_key( &self, api_key: storage::ApiKeyNew, @@ -65,7 +65,7 @@ impl ApiKeyInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_api_key( &self, merchant_id: String, @@ -113,7 +113,7 @@ impl ApiKeyInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn revoke_api_key( &self, merchant_id: &str, @@ -155,7 +155,7 @@ impl ApiKeyInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_api_key_by_merchant_id_key_id_optional( &self, merchant_id: &str, @@ -167,7 +167,7 @@ impl ApiKeyInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_api_key_by_hash_optional( &self, hashed_api_key: storage::HashedApiKey, @@ -197,7 +197,7 @@ impl ApiKeyInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_api_keys_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/authentication.rs b/crates/router/src/db/authentication.rs index a2c7f050052..b6a48a54d4d 100644 --- a/crates/router/src/db/authentication.rs +++ b/crates/router/src/db/authentication.rs @@ -31,7 +31,7 @@ pub trait AuthenticationInterface { #[async_trait::async_trait] impl AuthenticationInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_authentication( &self, authentication: storage::AuthenticationNew, @@ -43,7 +43,7 @@ impl AuthenticationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_authentication_by_merchant_id_authentication_id( &self, merchant_id: String, @@ -59,7 +59,7 @@ impl AuthenticationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_authentication_by_merchant_id_authentication_id( &self, previous_state: storage::Authentication, diff --git a/crates/router/src/db/authorization.rs b/crates/router/src/db/authorization.rs index 7b7802d64e5..05d69b77944 100644 --- a/crates/router/src/db/authorization.rs +++ b/crates/router/src/db/authorization.rs @@ -32,7 +32,7 @@ pub trait AuthorizationInterface { #[async_trait::async_trait] impl AuthorizationInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_authorization( &self, authorization: storage::AuthorizationNew, @@ -44,7 +44,7 @@ impl AuthorizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_all_authorizations_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -56,7 +56,7 @@ impl AuthorizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_authorization_by_merchant_id_authorization_id( &self, merchant_id: String, diff --git a/crates/router/src/db/blocklist.rs b/crates/router/src/db/blocklist.rs index 4a7236c95a7..f68b0708131 100644 --- a/crates/router/src/db/blocklist.rs +++ b/crates/router/src/db/blocklist.rs @@ -45,7 +45,7 @@ pub trait BlocklistInterface { #[async_trait::async_trait] impl BlocklistInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_entry( &self, pm_blocklist: storage::BlocklistNew, @@ -57,7 +57,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -69,7 +69,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_blocklist_entries_by_merchant_id( &self, merchant_id: &str, @@ -80,7 +80,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_blocklist_entries_by_merchant_id_data_kind( &self, merchant_id: &str, @@ -100,7 +100,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -115,7 +115,7 @@ impl BlocklistInterface for Store { #[async_trait::async_trait] impl BlocklistInterface for MockDb { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_entry( &self, _pm_blocklist: storage::BlocklistNew, @@ -159,7 +159,7 @@ impl BlocklistInterface for MockDb { #[async_trait::async_trait] impl BlocklistInterface for KafkaStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_entry( &self, pm_blocklist: storage::BlocklistNew, @@ -167,7 +167,7 @@ impl BlocklistInterface for KafkaStore { self.diesel_store.insert_blocklist_entry(pm_blocklist).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -178,7 +178,7 @@ impl BlocklistInterface for KafkaStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -189,7 +189,7 @@ impl BlocklistInterface for KafkaStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_blocklist_entries_by_merchant_id_data_kind( &self, merchant_id: &str, @@ -202,7 +202,7 @@ impl BlocklistInterface for KafkaStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_blocklist_entries_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/blocklist_fingerprint.rs b/crates/router/src/db/blocklist_fingerprint.rs index 65671555c7f..7d7f8648725 100644 --- a/crates/router/src/db/blocklist_fingerprint.rs +++ b/crates/router/src/db/blocklist_fingerprint.rs @@ -26,7 +26,7 @@ pub trait BlocklistFingerprintInterface { #[async_trait::async_trait] impl BlocklistFingerprintInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_fingerprint_entry( &self, pm_fingerprint_new: storage::BlocklistFingerprintNew, @@ -38,7 +38,7 @@ impl BlocklistFingerprintInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_blocklist_fingerprint_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -75,7 +75,7 @@ impl BlocklistFingerprintInterface for MockDb { #[async_trait::async_trait] impl BlocklistFingerprintInterface for KafkaStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_fingerprint_entry( &self, pm_fingerprint_new: storage::BlocklistFingerprintNew, @@ -85,7 +85,7 @@ impl BlocklistFingerprintInterface for KafkaStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_blocklist_fingerprint_by_merchant_id_fingerprint_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/blocklist_lookup.rs b/crates/router/src/db/blocklist_lookup.rs index 0f796946beb..cfd7cde6134 100644 --- a/crates/router/src/db/blocklist_lookup.rs +++ b/crates/router/src/db/blocklist_lookup.rs @@ -32,7 +32,7 @@ pub trait BlocklistLookupInterface { #[async_trait::async_trait] impl BlocklistLookupInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_lookup_entry( &self, blocklist_lookup_entry: storage::BlocklistLookupNew, @@ -44,7 +44,7 @@ impl BlocklistLookupInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, @@ -56,7 +56,7 @@ impl BlocklistLookupInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, @@ -71,7 +71,7 @@ impl BlocklistLookupInterface for Store { #[async_trait::async_trait] impl BlocklistLookupInterface for MockDb { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_lookup_entry( &self, _blocklist_lookup_entry: storage::BlocklistLookupNew, @@ -98,7 +98,7 @@ impl BlocklistLookupInterface for MockDb { #[async_trait::async_trait] impl BlocklistLookupInterface for KafkaStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_blocklist_lookup_entry( &self, blocklist_lookup_entry: storage::BlocklistLookupNew, @@ -108,7 +108,7 @@ impl BlocklistLookupInterface for KafkaStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, @@ -119,7 +119,7 @@ impl BlocklistLookupInterface for KafkaStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, diff --git a/crates/router/src/db/business_profile.rs b/crates/router/src/db/business_profile.rs index 4d5a94b370a..c76a5056657 100644 --- a/crates/router/src/db/business_profile.rs +++ b/crates/router/src/db/business_profile.rs @@ -47,7 +47,7 @@ pub trait BusinessProfileInterface { #[async_trait::async_trait] impl BusinessProfileInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_business_profile( &self, business_profile: business_profile::BusinessProfileNew, @@ -59,7 +59,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_business_profile_by_profile_id( &self, profile_id: &str, @@ -70,7 +70,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_business_profile_by_profile_name_merchant_id( &self, profile_name: &str, @@ -86,7 +86,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_business_profile_by_profile_id( &self, current_state: business_profile::BusinessProfile, @@ -102,7 +102,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_business_profile_by_profile_id_merchant_id( &self, profile_id: &str, @@ -118,7 +118,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_business_profile_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/cache.rs b/crates/router/src/db/cache.rs index 7f2462b3fc8..592648494cb 100644 --- a/crates/router/src/db/cache.rs +++ b/crates/router/src/db/cache.rs @@ -13,7 +13,7 @@ use crate::{ core::errors::{self, CustomResult}, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_or_populate_redis( store: &dyn StorageInterface, key: impl AsRef, @@ -54,7 +54,7 @@ where } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn get_or_populate_in_memory( store: &dyn StorageInterface, key: &str, @@ -76,7 +76,7 @@ where } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn redact_cache( store: &dyn StorageInterface, key: &str, @@ -104,7 +104,7 @@ where Ok(data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn publish_into_redact_channel<'a, K: IntoIterator> + Send>( store: &dyn StorageInterface, keys: K, @@ -130,7 +130,7 @@ pub async fn publish_into_redact_channel<'a, K: IntoIterator()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn publish_and_redact<'a, T, F, Fut>( store: &dyn StorageInterface, key: CacheKind<'a>, @@ -145,7 +145,7 @@ where Ok(data) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn publish_and_redact_multiple<'a, T, F, Fut, K>( store: &dyn StorageInterface, keys: K, diff --git a/crates/router/src/db/capture.rs b/crates/router/src/db/capture.rs index 48aad6a9e3f..1c9c8d02b20 100644 --- a/crates/router/src/db/capture.rs +++ b/crates/router/src/db/capture.rs @@ -45,7 +45,7 @@ mod storage { #[async_trait::async_trait] impl CaptureInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_capture( &self, capture: CaptureNew, @@ -61,7 +61,7 @@ mod storage { db_call().await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_capture_with_capture_id( &self, this: Capture, @@ -77,7 +77,7 @@ mod storage { db_call().await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_all_captures_by_merchant_id_payment_id_authorized_attempt_id( &self, merchant_id: &str, @@ -116,7 +116,7 @@ mod storage { #[async_trait::async_trait] impl CaptureInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_capture( &self, capture: CaptureNew, @@ -132,7 +132,7 @@ mod storage { db_call().await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_capture_with_capture_id( &self, this: Capture, @@ -148,7 +148,7 @@ mod storage { db_call().await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_all_captures_by_merchant_id_payment_id_authorized_attempt_id( &self, merchant_id: &str, @@ -203,7 +203,7 @@ impl CaptureInterface for MockDb { Ok(capture) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_capture_with_capture_id( &self, _this: types::Capture, diff --git a/crates/router/src/db/cards_info.rs b/crates/router/src/db/cards_info.rs index 68bd90946b6..2ccb1946e2f 100644 --- a/crates/router/src/db/cards_info.rs +++ b/crates/router/src/db/cards_info.rs @@ -19,7 +19,7 @@ pub trait CardsInfoInterface { #[async_trait::async_trait] impl CardsInfoInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_card_info( &self, card_iin: &str, @@ -33,7 +33,7 @@ impl CardsInfoInterface for Store { #[async_trait::async_trait] impl CardsInfoInterface for MockDb { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_card_info( &self, card_iin: &str, diff --git a/crates/router/src/db/configs.rs b/crates/router/src/db/configs.rs index 8deb4bdf6f6..9cce2b447ff 100644 --- a/crates/router/src/db/configs.rs +++ b/crates/router/src/db/configs.rs @@ -59,7 +59,7 @@ pub trait ConfigInterface { #[async_trait::async_trait] impl ConfigInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_config( &self, config: storage::ConfigNew, @@ -71,7 +71,7 @@ impl ConfigInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_config_in_database( &self, key: &str, @@ -84,7 +84,7 @@ impl ConfigInterface for Store { } //update in DB and remove in redis and cache - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_config_by_key( &self, key: &str, @@ -96,7 +96,7 @@ impl ConfigInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_config_by_key_from_db( &self, key: &str, @@ -108,7 +108,7 @@ impl ConfigInterface for Store { } //check in cache, then redis then finally DB, and on the way back populate redis and cache - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_config_by_key( &self, key: &str, @@ -122,7 +122,7 @@ impl ConfigInterface for Store { cache::get_or_populate_in_memory(self, key, find_config_by_key_from_db, &CONFIG_CACHE).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_config_by_key_unwrap_or( &self, key: &str, @@ -160,7 +160,7 @@ impl ConfigInterface for Store { cache::get_or_populate_in_memory(self, key, find_else_unwrap_or, &CONFIG_CACHE).await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_config_by_key( &self, key: &str, @@ -182,7 +182,7 @@ impl ConfigInterface for Store { #[async_trait::async_trait] impl ConfigInterface for MockDb { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_config( &self, config: storage::ConfigNew, diff --git a/crates/router/src/db/customers.rs b/crates/router/src/db/customers.rs index 00fb7e4a08f..ae0b5825952 100644 --- a/crates/router/src/db/customers.rs +++ b/crates/router/src/db/customers.rs @@ -97,7 +97,7 @@ mod storage { #[async_trait::async_trait] impl CustomerInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] // check customer not found in kv and fallback to db async fn find_customer_optional_by_customer_id_merchant_id( &self, @@ -160,7 +160,7 @@ mod storage { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_customer_by_customer_id_merchant_id( &self, customer_id: String, @@ -232,7 +232,7 @@ mod storage { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -289,7 +289,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_customers_by_merchant_id( &self, merchant_id: &str, @@ -315,7 +315,7 @@ mod storage { Ok(customers) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_customer( &self, customer_data: domain::Customer, @@ -382,7 +382,7 @@ mod storage { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -427,7 +427,7 @@ mod storage { #[async_trait::async_trait] impl CustomerInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_customer_optional_by_customer_id_merchant_id( &self, customer_id: &str, @@ -463,7 +463,7 @@ mod storage { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_customer_by_customer_id_merchant_id( &self, customer_id: String, @@ -490,7 +490,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -521,7 +521,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_customers_by_merchant_id( &self, merchant_id: &str, @@ -547,7 +547,7 @@ mod storage { Ok(customers) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_customer( &self, customer_data: domain::Customer, @@ -570,7 +570,7 @@ mod storage { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -639,7 +639,7 @@ impl CustomerInterface for MockDb { Ok(customers) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_customer_by_customer_id_merchant_id( &self, _customer_id: String, diff --git a/crates/router/src/db/dashboard_metadata.rs b/crates/router/src/db/dashboard_metadata.rs index 5267985e1ac..509da09b853 100644 --- a/crates/router/src/db/dashboard_metadata.rs +++ b/crates/router/src/db/dashboard_metadata.rs @@ -56,7 +56,7 @@ pub trait DashboardMetadataInterface { #[async_trait::async_trait] impl DashboardMetadataInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_metadata( &self, metadata: storage::DashboardMetadataNew, @@ -68,7 +68,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_metadata( &self, user_id: Option, @@ -90,7 +90,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_user_scoped_dashboard_metadata( &self, user_id: &str, @@ -110,7 +110,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_scoped_dashboard_metadata( &self, merchant_id: &str, @@ -128,7 +128,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_all_user_scoped_dashboard_metadata_by_merchant_id( &self, user_id: &str, @@ -144,7 +144,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_user_scoped_dashboard_metadata_by_merchant_id_data_key( &self, user_id: &str, diff --git a/crates/router/src/db/dispute.rs b/crates/router/src/db/dispute.rs index 0fe5f3d7666..26106ff3156 100644 --- a/crates/router/src/db/dispute.rs +++ b/crates/router/src/db/dispute.rs @@ -49,7 +49,7 @@ pub trait DisputeInterface { #[async_trait::async_trait] impl DisputeInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_dispute( &self, dispute: storage::DisputeNew, @@ -61,7 +61,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_by_merchant_id_payment_id_connector_dispute_id( &self, merchant_id: &str, @@ -79,7 +79,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_dispute_by_merchant_id_dispute_id( &self, merchant_id: &str, @@ -91,7 +91,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_disputes_by_merchant_id( &self, merchant_id: &str, @@ -103,7 +103,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_disputes_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -115,7 +115,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_dispute( &self, this: storage::Dispute, diff --git a/crates/router/src/db/ephemeral_key.rs b/crates/router/src/db/ephemeral_key.rs index a1d43e83b87..79d137f22c7 100644 --- a/crates/router/src/db/ephemeral_key.rs +++ b/crates/router/src/db/ephemeral_key.rs @@ -40,7 +40,7 @@ mod storage { #[async_trait::async_trait] impl EphemeralKeyInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn create_ephemeral_key( &self, new: EphemeralKeyNew, @@ -94,7 +94,7 @@ mod storage { Err(er) => Err(er).change_context(errors::StorageError::KVError), } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_ephemeral_key( &self, key: &str, diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs index 53480ed431b..bf753dcfe68 100644 --- a/crates/router/src/db/events.rs +++ b/crates/router/src/db/events.rs @@ -93,7 +93,7 @@ where #[async_trait::async_trait] impl EventInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_event( &self, event: domain::Event, @@ -112,7 +112,7 @@ impl EventInterface for Store { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_event_by_merchant_id_event_id( &self, merchant_id: &str, @@ -128,7 +128,7 @@ impl EventInterface for Store { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_initial_events_by_merchant_id_primary_object_id( &self, merchant_id: &str, @@ -158,7 +158,7 @@ impl EventInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_initial_events_by_merchant_id_constraints( &self, merchant_id: &str, @@ -194,7 +194,7 @@ impl EventInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_events_by_merchant_id_initial_attempt_id( &self, merchant_id: &str, @@ -224,7 +224,7 @@ impl EventInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_initial_events_by_profile_id_primary_object_id( &self, profile_id: &str, @@ -254,7 +254,7 @@ impl EventInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_initial_events_by_profile_id_constraints( &self, profile_id: &str, @@ -290,7 +290,7 @@ impl EventInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_events_by_profile_id_initial_attempt_id( &self, profile_id: &str, @@ -316,7 +316,7 @@ impl EventInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_event_by_merchant_id_event_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/file.rs b/crates/router/src/db/file.rs index da28404971d..29f4199d6fd 100644 --- a/crates/router/src/db/file.rs +++ b/crates/router/src/db/file.rs @@ -36,7 +36,7 @@ pub trait FileMetadataInterface { #[async_trait::async_trait] impl FileMetadataInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_file_metadata( &self, file: storage::FileMetadataNew, @@ -47,7 +47,7 @@ impl FileMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_file_metadata_by_merchant_id_file_id( &self, merchant_id: &str, @@ -59,7 +59,7 @@ impl FileMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_file_metadata_by_merchant_id_file_id( &self, merchant_id: &str, @@ -71,7 +71,7 @@ impl FileMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_file_metadata( &self, this: storage::FileMetadata, diff --git a/crates/router/src/db/fraud_check.rs b/crates/router/src/db/fraud_check.rs index 34818260364..f2a32bbf4f7 100644 --- a/crates/router/src/db/fraud_check.rs +++ b/crates/router/src/db/fraud_check.rs @@ -37,7 +37,7 @@ pub trait FraudCheckInterface { #[async_trait::async_trait] impl FraudCheckInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_fraud_check_response( &self, new: storage::FraudCheckNew, @@ -48,7 +48,7 @@ impl FraudCheckInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_fraud_check_response_with_attempt_id( &self, this: FraudCheck, @@ -60,7 +60,7 @@ impl FraudCheckInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_fraud_check_by_payment_id( &self, payment_id: String, @@ -72,7 +72,7 @@ impl FraudCheckInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_fraud_check_by_payment_id_if_present( &self, payment_id: String, @@ -120,7 +120,7 @@ impl FraudCheckInterface for MockDb { #[cfg(feature = "kafka_events")] #[async_trait::async_trait] impl FraudCheckInterface for super::KafkaStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_fraud_check_response( &self, _new: storage::FraudCheckNew, @@ -128,7 +128,7 @@ impl FraudCheckInterface for super::KafkaStore { Err(errors::StorageError::MockDbError)? } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_fraud_check_response_with_attempt_id( &self, _this: FraudCheck, @@ -137,7 +137,7 @@ impl FraudCheckInterface for super::KafkaStore { Err(errors::StorageError::MockDbError)? } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_fraud_check_by_payment_id( &self, _payment_id: String, diff --git a/crates/router/src/db/gsm.rs b/crates/router/src/db/gsm.rs index 1aa96e14c18..2718e6d702f 100644 --- a/crates/router/src/db/gsm.rs +++ b/crates/router/src/db/gsm.rs @@ -53,7 +53,7 @@ pub trait GsmInterface { #[async_trait::async_trait] impl GsmInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn add_gsm_rule( &self, rule: storage::GatewayStatusMappingNew, @@ -64,7 +64,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_gsm_decision( &self, connector: String, @@ -81,7 +81,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_gsm_rule( &self, connector: String, @@ -96,7 +96,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_gsm_rule( &self, connector: String, @@ -112,7 +112,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_gsm_rule( &self, connector: String, diff --git a/crates/router/src/db/health_check.rs b/crates/router/src/db/health_check.rs index 5423fef9557..3f10b96fe29 100644 --- a/crates/router/src/db/health_check.rs +++ b/crates/router/src/db/health_check.rs @@ -17,7 +17,7 @@ pub trait HealthCheckDbInterface { #[async_trait::async_trait] impl HealthCheckDbInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> { let conn = connection::pg_connection_write(self) .await diff --git a/crates/router/src/db/locker_mock_up.rs b/crates/router/src/db/locker_mock_up.rs index ea0e70c5bb9..00c92b2b2f2 100644 --- a/crates/router/src/db/locker_mock_up.rs +++ b/crates/router/src/db/locker_mock_up.rs @@ -28,7 +28,7 @@ pub trait LockerMockUpInterface { #[async_trait::async_trait] impl LockerMockUpInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_locker_by_card_id( &self, card_id: &str, @@ -39,7 +39,7 @@ impl LockerMockUpInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_locker_mock_up( &self, new: storage::LockerMockUpNew, @@ -50,7 +50,7 @@ impl LockerMockUpInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_locker_mock_up( &self, card_id: &str, diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs index 273d34a68af..bef7ed784ff 100644 --- a/crates/router/src/db/mandate.rs +++ b/crates/router/src/db/mandate.rs @@ -49,7 +49,7 @@ pub trait MandateInterface { #[async_trait::async_trait] impl MandateInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_mandate_by_merchant_id_mandate_id( &self, merchant_id: &str, @@ -61,7 +61,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_mandate_by_merchant_id_connector_mandate_id( &self, merchant_id: &str, @@ -77,7 +77,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_mandate_by_merchant_id_customer_id( &self, merchant_id: &str, @@ -89,7 +89,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_mandate_by_merchant_id_mandate_id( &self, merchant_id: &str, @@ -102,7 +102,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_mandates_by_merchant_id( &self, merchant_id: &str, @@ -114,7 +114,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_mandate( &self, mandate: storage::MandateNew, diff --git a/crates/router/src/db/merchant_account.rs b/crates/router/src/db/merchant_account.rs index 08d0c279047..7a2c3a5acff 100644 --- a/crates/router/src/db/merchant_account.rs +++ b/crates/router/src/db/merchant_account.rs @@ -79,7 +79,7 @@ where #[async_trait::async_trait] impl MerchantAccountInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_merchant( &self, merchant_account: domain::MerchantAccount, @@ -98,7 +98,7 @@ impl MerchantAccountInterface for Store { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_account_by_merchant_id( &self, merchant_id: &str, @@ -130,7 +130,7 @@ impl MerchantAccountInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_merchant( &self, this: domain::MerchantAccount, @@ -156,7 +156,7 @@ impl MerchantAccountInterface for Store { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_specific_fields_in_merchant( &self, merchant_id: &str, @@ -182,7 +182,7 @@ impl MerchantAccountInterface for Store { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_account_by_publishable_key( &self, publishable_key: &str, @@ -229,7 +229,7 @@ impl MerchantAccountInterface for Store { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_merchant_accounts_by_organization_id( &self, organization_id: &str, @@ -269,7 +269,7 @@ impl MerchantAccountInterface for Store { Ok(merchant_accounts) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_merchant_account_by_merchant_id( &self, merchant_id: &str, @@ -305,7 +305,7 @@ impl MerchantAccountInterface for Store { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_multiple_merchant_accounts( &self, merchant_ids: Vec, diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index b7c85560804..0f83b823abb 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -37,7 +37,7 @@ pub trait ConnectorAccessToken { #[async_trait::async_trait] impl ConnectorAccessToken for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_access_token( &self, merchant_id: &str, @@ -64,7 +64,7 @@ impl ConnectorAccessToken for Store { Ok(access_token) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn set_access_token( &self, merchant_id: &str, @@ -168,7 +168,7 @@ where #[async_trait::async_trait] impl MerchantConnectorAccountInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_connector_account_by_merchant_id_connector_label( &self, merchant_id: &str, @@ -213,7 +213,7 @@ impl MerchantConnectorAccountInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_connector_account_by_profile_id_connector_name( &self, profile_id: &str, @@ -258,7 +258,7 @@ impl MerchantConnectorAccountInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_connector_account_by_merchant_id_connector_name( &self, merchant_id: &str, @@ -287,7 +287,7 @@ impl MerchantConnectorAccountInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id( &self, merchant_id: &str, @@ -329,7 +329,7 @@ impl MerchantConnectorAccountInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_merchant_connector_account( &self, t: domain::MerchantConnectorAccount, @@ -350,7 +350,7 @@ impl MerchantConnectorAccountInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_merchant_connector_account_by_merchant_id_and_disabled_list( &self, merchant_id: &str, @@ -375,7 +375,7 @@ impl MerchantConnectorAccountInterface for Store { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_merchant_connector_account( &self, this: domain::MerchantConnectorAccount, @@ -433,7 +433,7 @@ impl MerchantConnectorAccountInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/merchant_key_store.rs b/crates/router/src/db/merchant_key_store.rs index f857ab9d61e..58ae04b54c2 100644 --- a/crates/router/src/db/merchant_key_store.rs +++ b/crates/router/src/db/merchant_key_store.rs @@ -44,7 +44,7 @@ pub trait MerchantKeyStoreInterface { #[async_trait::async_trait] impl MerchantKeyStoreInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_merchant_key_store( &self, merchant_key_store: domain::MerchantKeyStore, @@ -63,7 +63,7 @@ impl MerchantKeyStoreInterface for Store { .change_context(errors::StorageError::DecryptionError) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_merchant_key_store_by_merchant_id( &self, merchant_id: &str, @@ -105,7 +105,7 @@ impl MerchantKeyStoreInterface for Store { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_merchant_key_store_by_merchant_id( &self, merchant_id: &str, @@ -138,7 +138,7 @@ impl MerchantKeyStoreInterface for Store { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_multiple_key_stores( &self, merchant_ids: Vec, diff --git a/crates/router/src/db/organization.rs b/crates/router/src/db/organization.rs index 0fe9ea9a180..fe14df236e4 100644 --- a/crates/router/src/db/organization.rs +++ b/crates/router/src/db/organization.rs @@ -26,7 +26,7 @@ pub trait OrganizationInterface { #[async_trait::async_trait] impl OrganizationInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_organization( &self, organization: storage::OrganizationNew, @@ -38,7 +38,7 @@ impl OrganizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_organization_by_org_id( &self, org_id: &str, @@ -49,7 +49,7 @@ impl OrganizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_organization_by_org_id( &self, org_id: &str, diff --git a/crates/router/src/db/payment_link.rs b/crates/router/src/db/payment_link.rs index c3f78767931..a8cb5da4197 100644 --- a/crates/router/src/db/payment_link.rs +++ b/crates/router/src/db/payment_link.rs @@ -30,7 +30,7 @@ pub trait PaymentLinkInterface { #[async_trait::async_trait] impl PaymentLinkInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_link_by_payment_link_id( &self, payment_link_id: &str, @@ -41,7 +41,7 @@ impl PaymentLinkInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payment_link( &self, payment_link_config: storage::PaymentLinkNew, @@ -53,7 +53,7 @@ impl PaymentLinkInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_payment_link_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/payment_method.rs b/crates/router/src/db/payment_method.rs index 50a70ec58ab..3b8c404d7ee 100644 --- a/crates/router/src/db/payment_method.rs +++ b/crates/router/src/db/payment_method.rs @@ -84,7 +84,7 @@ pub trait PaymentMethodInterface { // #[async_trait::async_trait] // impl PaymentMethodInterface for Store { -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn find_payment_method( // &self, // payment_method_id: &str, @@ -128,7 +128,7 @@ pub trait PaymentMethodInterface { // } // } -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn find_payment_method_by_locker_id( // &self, // locker_id: &str, @@ -172,7 +172,7 @@ pub trait PaymentMethodInterface { // } // } // // not supported in kv -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn get_payment_method_count_by_customer_id_merchant_id_status( // &self, // customer_id: &str, @@ -190,7 +190,7 @@ pub trait PaymentMethodInterface { // .map_err(|error| report!(errors::StorageError::from(error))) // } -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn insert_payment_method( // &self, // payment_method_new: storage_types::PaymentMethodNew, @@ -270,7 +270,7 @@ pub trait PaymentMethodInterface { // } // } -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn update_payment_method( // &self, // payment_method: storage_types::PaymentMethod, @@ -331,7 +331,7 @@ pub trait PaymentMethodInterface { // } // } -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn find_payment_method_by_customer_id_merchant_id_list( // &self, // customer_id: &str, @@ -349,7 +349,7 @@ pub trait PaymentMethodInterface { // .map_err(|error| report!(errors::StorageError::from(error))) // } -// #[instrument(skip_all)] +// //#\[instrument\(skip_all)] // async fn find_payment_method_by_customer_id_merchant_id_status( // &self, // customer_id: &str, @@ -399,7 +399,7 @@ mod storage { }; #[async_trait::async_trait] impl PaymentMethodInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_method( &self, payment_method_id: &str, @@ -411,7 +411,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_method_by_locker_id( &self, locker_id: &str, @@ -423,7 +423,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_payment_method_count_by_customer_id_merchant_id_status( &self, customer_id: &str, @@ -441,7 +441,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payment_method( &self, payment_method_new: storage_types::PaymentMethodNew, @@ -454,7 +454,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payment_method( &self, payment_method: storage_types::PaymentMethod, @@ -468,7 +468,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_method_by_customer_id_merchant_id_list( &self, customer_id: &str, @@ -486,7 +486,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_method_by_customer_id_merchant_id_status( &self, customer_id: &str, diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs index ca3921d6199..106143ccfb9 100644 --- a/crates/router/src/db/refund.rs +++ b/crates/router/src/db/refund.rs @@ -106,7 +106,7 @@ mod storage { #[async_trait::async_trait] impl RefundInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_internal_reference_id_merchant_id( &self, internal_reference_id: &str, @@ -123,7 +123,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_refund( &self, new: storage_types::RefundNew, @@ -135,7 +135,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_merchant_id_connector_transaction_id( &self, merchant_id: &str, @@ -152,7 +152,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_refund( &self, this: storage_types::Refund, @@ -165,7 +165,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_merchant_id_refund_id( &self, merchant_id: &str, @@ -178,7 +178,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_merchant_id_connector_refund_id_connector( &self, merchant_id: &str, @@ -197,7 +197,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_payment_id_merchant_id( &self, payment_id: &str, @@ -211,7 +211,7 @@ mod storage { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_refund_by_constraints( &self, merchant_id: &str, @@ -233,7 +233,7 @@ mod storage { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_refund_by_meta_constraints( &self, merchant_id: &str, @@ -250,7 +250,7 @@ mod storage { .map_err(|error|report!(errors::StorageError::from(error))) } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_total_count_of_refunds( &self, merchant_id: &str, @@ -288,7 +288,7 @@ mod storage { }; #[async_trait::async_trait] impl RefundInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_internal_reference_id_merchant_id( &self, internal_reference_id: &str, @@ -335,7 +335,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_refund( &self, new: storage_types::RefundNew, @@ -468,7 +468,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_merchant_id_connector_transaction_id( &self, merchant_id: &str, @@ -519,7 +519,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_refund( &self, this: storage_types::Refund, @@ -575,7 +575,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_merchant_id_refund_id( &self, merchant_id: &str, @@ -618,7 +618,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_merchant_id_connector_refund_id_connector( &self, merchant_id: &str, @@ -668,7 +668,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_refund_by_payment_id_merchant_id( &self, payment_id: &str, @@ -710,7 +710,7 @@ mod storage { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_refund_by_constraints( &self, merchant_id: &str, @@ -732,7 +732,7 @@ mod storage { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_refund_by_meta_constraints( &self, merchant_id: &str, @@ -746,7 +746,7 @@ mod storage { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_total_count_of_refunds( &self, merchant_id: &str, diff --git a/crates/router/src/db/reverse_lookup.rs b/crates/router/src/db/reverse_lookup.rs index 121ec06ec1f..7311d7996e8 100644 --- a/crates/router/src/db/reverse_lookup.rs +++ b/crates/router/src/db/reverse_lookup.rs @@ -38,7 +38,7 @@ mod storage { #[async_trait::async_trait] impl ReverseLookupInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_reverse_lookup( &self, new: ReverseLookupNew, @@ -50,7 +50,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_lookup_by_lookup_id( &self, id: &str, @@ -85,7 +85,7 @@ mod storage { #[async_trait::async_trait] impl ReverseLookupInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_reverse_lookup( &self, new: ReverseLookupNew, @@ -138,7 +138,7 @@ mod storage { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_lookup_by_lookup_id( &self, id: &str, diff --git a/crates/router/src/db/role.rs b/crates/router/src/db/role.rs index 54b7f6e38d4..5dbb1847082 100644 --- a/crates/router/src/db/role.rs +++ b/crates/router/src/db/role.rs @@ -49,7 +49,7 @@ pub trait RoleInterface { #[async_trait::async_trait] impl RoleInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_role( &self, role: storage::RoleNew, @@ -60,7 +60,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_role_by_role_id( &self, role_id: &str, @@ -71,7 +71,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_role_by_role_id_in_merchant_scope( &self, role_id: &str, @@ -84,7 +84,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_role_by_role_id( &self, role_id: &str, @@ -96,7 +96,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_role_by_role_id( &self, role_id: &str, @@ -107,7 +107,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_all_roles( &self, merchant_id: &str, diff --git a/crates/router/src/db/routing_algorithm.rs b/crates/router/src/db/routing_algorithm.rs index f65933d8982..a9370842895 100644 --- a/crates/router/src/db/routing_algorithm.rs +++ b/crates/router/src/db/routing_algorithm.rs @@ -61,7 +61,7 @@ pub trait RoutingAlgorithmInterface { #[async_trait::async_trait] impl RoutingAlgorithmInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_routing_algorithm( &self, routing_algorithm: routing_storage::RoutingAlgorithm, @@ -73,7 +73,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_routing_algorithm_by_profile_id_algorithm_id( &self, profile_id: &str, @@ -89,7 +89,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_routing_algorithm_by_algorithm_id_merchant_id( &self, algorithm_id: &str, @@ -105,7 +105,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id( &self, algorithm_id: &str, @@ -121,7 +121,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_routing_algorithm_metadata_by_profile_id( &self, profile_id: &str, @@ -136,7 +136,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_routing_algorithm_metadata_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/user.rs b/crates/router/src/db/user.rs index a96829a756e..822c37625c1 100644 --- a/crates/router/src/db/user.rs +++ b/crates/router/src/db/user.rs @@ -53,7 +53,7 @@ pub trait UserInterface { #[async_trait::async_trait] impl UserInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_user( &self, user_data: storage::UserNew, @@ -65,7 +65,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_user_by_email( &self, user_email: &str, @@ -76,7 +76,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_user_by_id( &self, user_id: &str, @@ -87,7 +87,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_user_by_user_id( &self, user_id: &str, @@ -99,7 +99,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_user_by_email( &self, user_email: &str, @@ -111,7 +111,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_user_by_user_id( &self, user_id: &str, @@ -122,7 +122,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_users_and_roles_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/user_role.rs b/crates/router/src/db/user_role.rs index 2f61f70b2a8..84522a18d50 100644 --- a/crates/router/src/db/user_role.rs +++ b/crates/router/src/db/user_role.rs @@ -65,7 +65,7 @@ pub trait UserRoleInterface { #[async_trait::async_trait] impl UserRoleInterface for Store { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_user_role( &self, user_role: storage::UserRoleNew, @@ -77,7 +77,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_user_role_by_user_id( &self, user_id: &str, @@ -88,7 +88,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_user_role_by_user_id_merchant_id( &self, user_id: &str, @@ -104,7 +104,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_user_role_by_user_id_merchant_id( &self, user_id: &str, @@ -122,7 +122,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_user_roles_by_user_id_org_id( &self, user_id: &str, @@ -140,7 +140,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn delete_user_role_by_user_id_merchant_id( &self, user_id: &str, @@ -156,7 +156,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn list_user_roles_by_user_id( &self, user_id: &str, @@ -167,7 +167,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn transfer_org_ownership_between_users( &self, from_user_id: &str, diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs index a8d6e792f3c..9865b5f214c 100644 --- a/crates/router/src/lib.rs +++ b/crates/router/src/lib.rs @@ -32,7 +32,7 @@ use actix_web::{ use http::StatusCode; use hyperswitch_interfaces::secrets_interface::secret_state::SecuredSecret; use router_env::tracing::Instrument; -use routes::AppState; +use routes::{AppState, SessionState}; use storage_impl::errors::ApplicationResult; use tokio::sync::{mpsc, oneshot}; diff --git a/crates/router/src/routes.rs b/crates/router/src/routes.rs index bf335a5e718..b98c9a0786f 100644 --- a/crates/router/src/routes.rs +++ b/crates/router/src/routes.rs @@ -59,7 +59,8 @@ pub use self::app::Recon; pub use self::app::{ ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers, Disputes, EphemeralKey, Files, Gsm, Health, Mandates, MerchantAccount, - MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Refunds, User, Webhooks, + MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Refunds, SessionState, User, + Webhooks, }; #[cfg(feature = "olap")] pub use self::app::{Blocklist, Routing, Verify, WebhookEvents}; diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs index bc534dde390..91cf21c7075 100644 --- a/crates/router/src/routes/admin.rs +++ b/crates/router/src/routes/admin.rs @@ -23,7 +23,7 @@ use crate::{ operation_id = "Create a Merchant Account", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountCreate))] pub async fn merchant_account_create( state: web::Data, req: HttpRequest, @@ -56,7 +56,7 @@ pub async fn merchant_account_create( operation_id = "Retrieve a Merchant Account", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountRetrieve))] pub async fn retrieve_merchant_account( state: web::Data, req: HttpRequest, @@ -89,7 +89,7 @@ pub async fn retrieve_merchant_account( } #[cfg(feature = "olap")] -#[instrument(skip_all, fields(flow = ?Flow::MerchantAccountList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantAccountList))] pub async fn merchant_account_list( state: web::Data, req: HttpRequest, @@ -125,7 +125,7 @@ pub async fn merchant_account_list( operation_id = "Update a Merchant Account", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountUpdate))] pub async fn update_merchant_account( state: web::Data, req: HttpRequest, @@ -168,7 +168,7 @@ pub async fn update_merchant_account( operation_id = "Delete a Merchant Account", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountDelete))] // #[delete("/{id}")] pub async fn delete_merchant_account( state: web::Data, @@ -205,7 +205,7 @@ pub async fn delete_merchant_account( operation_id = "Create a Merchant Connector", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsCreate))] pub async fn payment_connector_create( state: web::Data, req: HttpRequest, @@ -251,7 +251,7 @@ pub async fn payment_connector_create( operation_id = "Retrieve a Merchant Connector", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsRetrieve))] pub async fn payment_connector_retrieve( state: web::Data, req: HttpRequest, @@ -303,7 +303,7 @@ pub async fn payment_connector_retrieve( operation_id = "List all Merchant Connectors", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsList))] pub async fn payment_connector_list( state: web::Data, req: HttpRequest, @@ -350,7 +350,7 @@ pub async fn payment_connector_list( operation_id = "Update a Merchant Connector", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsUpdate))] pub async fn payment_connector_update( state: web::Data, req: HttpRequest, @@ -399,7 +399,7 @@ pub async fn payment_connector_update( operation_id = "Delete a Merchant Connector", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsDelete))] pub async fn payment_connector_delete( state: web::Data, req: HttpRequest, @@ -436,7 +436,7 @@ pub async fn payment_connector_delete( /// Merchant Account - Toggle KV /// /// Toggle KV mode for the Merchant Account -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn merchant_account_toggle_kv( state: web::Data, req: HttpRequest, @@ -458,7 +458,7 @@ pub async fn merchant_account_toggle_kv( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileCreate))] pub async fn business_profile_create( state: web::Data, req: HttpRequest, @@ -487,7 +487,7 @@ pub async fn business_profile_create( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileRetrieve))] pub async fn business_profile_retrieve( state: web::Data, req: HttpRequest, @@ -514,7 +514,7 @@ pub async fn business_profile_retrieve( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileUpdate))] pub async fn business_profile_update( state: web::Data, req: HttpRequest, @@ -542,7 +542,7 @@ pub async fn business_profile_update( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileDelete))] pub async fn business_profile_delete( state: web::Data, req: HttpRequest, @@ -562,7 +562,7 @@ pub async fn business_profile_delete( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileList))] pub async fn business_profiles_list( state: web::Data, req: HttpRequest, @@ -592,7 +592,7 @@ pub async fn business_profiles_list( /// Merchant Account - KV Status /// /// Toggle KV mode for the Merchant Account -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn merchant_account_kv_status( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/api_keys.rs b/crates/router/src/routes/api_keys.rs index 55959589152..1a5dbbf92cb 100644 --- a/crates/router/src/routes/api_keys.rs +++ b/crates/router/src/routes/api_keys.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Create an API Key", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::ApiKeyCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyCreate))] pub async fn api_key_create( state: web::Data, req: HttpRequest, @@ -74,7 +74,7 @@ pub async fn api_key_create( operation_id = "Retrieve an API Key", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::ApiKeyRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyRetrieve))] pub async fn api_key_retrieve( state: web::Data, req: HttpRequest, @@ -120,7 +120,7 @@ pub async fn api_key_retrieve( operation_id = "Update an API Key", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::ApiKeyUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyUpdate))] pub async fn api_key_update( state: web::Data, req: HttpRequest, @@ -170,7 +170,7 @@ pub async fn api_key_update( operation_id = "Revoke an API Key", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::ApiKeyRevoke))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyRevoke))] pub async fn api_key_revoke( state: web::Data, req: HttpRequest, @@ -215,7 +215,7 @@ pub async fn api_key_revoke( operation_id = "List all API Keys associated with a merchant account", security(("admin_api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::ApiKeyList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyList))] pub async fn api_key_list( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 74bb8bbc242..af29f817f30 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; use actix_web::{web, Scope}; #[cfg(all(feature = "business_profile_routing", feature = "olap"))] @@ -54,7 +54,7 @@ pub use crate::{ db::{StorageImpl, StorageInterface}, events::EventsHandler, routes::cards_info::card_iin_info, - services::get_store, + services::{get_cache_store, get_store}, }; #[derive(Clone)] @@ -62,10 +62,76 @@ pub struct ReqState { pub event_context: events::EventContext, } +#[derive(Clone)] +pub struct SessionState { + pub store: Box, + pub conf: Arc>, + pub api_client: Box, + pub event_handler: EventsHandler, + #[cfg(feature = "olap")] + pub pool: crate::analytics::AnalyticsProvider, + pub file_storage_client: Box, + pub request_id: Option, +} +impl scheduler::SchedulerAppState for SessionState { + fn get_db(&self) -> Box { + self.store.get_scheduler_db() + } + + fn get_tenants(&self) -> Vec { + self.conf.multitenancy.tenants.clone() + } +} +impl SessionState { + pub fn get_req_state(&self) -> ReqState { + ReqState { + event_context: events::EventContext::new(self.event_handler.clone()), + } + } + pub fn from_app_state(state: Arc, tenant: &str) -> Self { + Self { + store: state.stores.get(tenant).unwrap().clone(), + conf: Arc::clone(&state.conf), + api_client: state.api_client.clone(), + event_handler: state.event_handler.clone(), + pool: state.pool.clone(), + file_storage_client: state.file_storage_client.clone(), + request_id: state.request_id.clone(), + } + } +} + +pub trait SessionStateInfo { + fn conf(&self) -> settings::Settings; + fn store(&self) -> Box; + fn event_handler(&self) -> EventsHandler; + fn get_request_id(&self) -> Option; + fn add_request_id(&mut self, request_id: RequestId); +} + +impl SessionStateInfo for SessionState { + fn store(&self) -> Box { + self.store.to_owned() + } + fn conf(&self) -> settings::Settings { + self.conf.as_ref().to_owned() + } + fn event_handler(&self) -> EventsHandler { + self.event_handler.clone() + } + fn get_request_id(&self) -> Option { + self.api_client.get_request_id() + } + fn add_request_id(&mut self, request_id: RequestId) { + self.api_client.add_request_id(request_id); + self.store.add_request_id(request_id.to_string()); + self.request_id.replace(request_id); + } +} #[derive(Clone)] pub struct AppState { pub flow_name: String, - pub store: Box, + pub stores: HashMap>, pub conf: Arc>, pub event_handler: EventsHandler, #[cfg(feature = "email")] @@ -77,16 +143,17 @@ pub struct AppState { pub file_storage_client: Box, pub encryption_client: Box, } - impl scheduler::SchedulerAppState for AppState { fn get_db(&self) -> Box { - self.store.get_scheduler_db() + todo!() + } + fn get_tenants(&self) -> Vec { + self.conf.multitenancy.tenants.clone() } } - pub trait AppStateInfo { fn conf(&self) -> settings::Settings; - fn store(&self) -> Box; + // fn store(&self) -> Box; fn event_handler(&self) -> EventsHandler; #[cfg(feature = "email")] fn email_client(&self) -> Arc; @@ -100,9 +167,6 @@ impl AppStateInfo for AppState { fn conf(&self) -> settings::Settings { self.conf.as_ref().to_owned() } - fn store(&self) -> Box { - self.store.to_owned() - } #[cfg(feature = "email")] fn email_client(&self) -> Arc { self.email_client.to_owned() @@ -112,7 +176,6 @@ impl AppStateInfo for AppState { } fn add_request_id(&mut self, request_id: RequestId) { self.api_client.add_request_id(request_id); - self.store.add_request_id(request_id.to_string()); self.request_id.replace(request_id); } @@ -176,33 +239,39 @@ impl AppState { .get_event_handler() .await .expect("Failed to create event handler"); - - let store: Box = match storage_impl { - StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match &event_handler { - EventsHandler::Kafka(kafka_client) => Box::new( - crate::db::KafkaStore::new( + let mut stores = HashMap::new(); + let cache_store = get_cache_store(&conf.clone(), shut_down_signal, testable) + .await + .expect("Failed to create store"); + for tenant in conf.clone().multitenancy.tenants { + let store: Box = match storage_impl { + StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match &event_handler { + EventsHandler::Kafka(kafka_client) => Box::new( + crate::db::KafkaStore::new( + #[allow(clippy::expect_used)] + get_store(&conf.clone(), tenant.as_str(), Arc::clone(&cache_store), testable) + .await + .expect("Failed to create store"), + kafka_client.clone(), + ) + .await, + ), + EventsHandler::Logs(_) => Box::new( #[allow(clippy::expect_used)] - get_store(&conf.clone(), shut_down_signal, testable) + get_store(&conf, tenant.as_str(), Arc::clone(&cache_store), testable) .await .expect("Failed to create store"), - kafka_client.clone(), - ) - .await, - ), - EventsHandler::Logs(_) => Box::new( - #[allow(clippy::expect_used)] - get_store(&conf, shut_down_signal, testable) + ), + }, + #[allow(clippy::expect_used)] + StorageImpl::Mock => Box::new( + MockDb::new(&conf.redis) .await - .expect("Failed to create store"), + .expect("Failed to create mock store"), ), - }, - #[allow(clippy::expect_used)] - StorageImpl::Mock => Box::new( - MockDb::new(&conf.redis) - .await - .expect("Failed to create mock store"), - ), - }; + }; + stores.insert(tenant, store); + } #[cfg(feature = "olap")] let pool = @@ -215,7 +284,7 @@ impl AppState { Self { flow_name: String::from("default"), - store, + stores, conf: Arc::new(conf), #[cfg(feature = "email")] email_client, diff --git a/crates/router/src/routes/cache.rs b/crates/router/src/routes/cache.rs index e7742d2d18c..347351d864a 100644 --- a/crates/router/src/routes/cache.rs +++ b/crates/router/src/routes/cache.rs @@ -7,7 +7,7 @@ use crate::{ services::{api, authentication as auth}, }; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn invalidate( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/cards_info.rs b/crates/router/src/routes/cards_info.rs index 4d65fc72036..3afa7ca6b04 100644 --- a/crates/router/src/routes/cards_info.rs +++ b/crates/router/src/routes/cards_info.rs @@ -21,7 +21,7 @@ use crate::{ operation_id = "Retrieve card information", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::CardsInfo))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CardsInfo))] pub async fn card_iin_info( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/configs.rs b/crates/router/src/routes/configs.rs index 74b9cd73b1e..a93387ee4f4 100644 --- a/crates/router/src/routes/configs.rs +++ b/crates/router/src/routes/configs.rs @@ -8,7 +8,7 @@ use crate::{ types::api as api_types, }; -#[instrument(skip_all, fields(flow = ?Flow::CreateConfigKey))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CreateConfigKey))] pub async fn config_key_create( state: web::Data, req: HttpRequest, @@ -28,7 +28,7 @@ pub async fn config_key_create( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyFetch))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ConfigKeyFetch))] pub async fn config_key_retrieve( state: web::Data, req: HttpRequest, @@ -48,7 +48,7 @@ pub async fn config_key_retrieve( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ConfigKeyUpdate))] pub async fn config_key_update( state: web::Data, req: HttpRequest, @@ -72,7 +72,7 @@ pub async fn config_key_update( .await } -#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ConfigKeyDelete))] pub async fn config_key_delete( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rs index 64fa8e83d49..415f3bd6ab3 100644 --- a/crates/router/src/routes/customers.rs +++ b/crates/router/src/routes/customers.rs @@ -8,7 +8,7 @@ use crate::{ types::api::customers, }; -#[instrument(skip_all, fields(flow = ?Flow::CustomersCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersCreate))] pub async fn customers_create( state: web::Data, req: HttpRequest, @@ -31,7 +31,7 @@ pub async fn customers_create( .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersRetrieve))] pub async fn customers_retrieve( state: web::Data, req: HttpRequest, @@ -46,7 +46,7 @@ pub async fn customers_retrieve( let auth = if auth::is_jwt_auth(req.headers()) { Box::new(auth::JWTAuth(Permission::CustomerRead)) } else { - match auth::is_ephemeral_auth(req.headers(), &*state.store, &payload.customer_id).await { + match auth::is_ephemeral_auth(req.headers(), &payload.customer_id) { Ok(auth) => auth, Err(err) => return api::log_and_return_error_response(err), } @@ -64,7 +64,7 @@ pub async fn customers_retrieve( .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersList))] pub async fn customers_list(state: web::Data, req: HttpRequest) -> HttpResponse { let flow = Flow::CustomersList; @@ -86,7 +86,7 @@ pub async fn customers_list(state: web::Data, req: HttpRequest) -> Htt .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersUpdate))] pub async fn customers_update( state: web::Data, req: HttpRequest, @@ -112,7 +112,7 @@ pub async fn customers_update( .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersDelete))] pub async fn customers_delete( state: web::Data, req: HttpRequest, @@ -138,7 +138,7 @@ pub async fn customers_delete( )) .await } -#[instrument(skip_all, fields(flow = ?Flow::CustomersGetMandates))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersGetMandates))] pub async fn get_customer_mandates( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/disputes.rs b/crates/router/src/routes/disputes.rs index a4a6c7507a4..d898ac5d9c4 100644 --- a/crates/router/src/routes/disputes.rs +++ b/crates/router/src/routes/disputes.rs @@ -28,7 +28,7 @@ use crate::{ operation_id = "Retrieve a Dispute", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::DisputesRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesRetrieve))] pub async fn retrieve_dispute( state: web::Data, req: HttpRequest, @@ -77,7 +77,7 @@ pub async fn retrieve_dispute( operation_id = "List Disputes", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::DisputesList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesList))] pub async fn retrieve_disputes_list( state: web::Data, req: HttpRequest, @@ -115,7 +115,7 @@ pub async fn retrieve_disputes_list( operation_id = "Accept a Dispute", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::DisputesRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesRetrieve))] pub async fn accept_dispute( state: web::Data, req: HttpRequest, @@ -155,7 +155,7 @@ pub async fn accept_dispute( operation_id = "Submit Dispute Evidence", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::DisputesEvidenceSubmit))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesEvidenceSubmit))] pub async fn submit_dispute_evidence( state: web::Data, req: HttpRequest, @@ -194,7 +194,7 @@ pub async fn submit_dispute_evidence( operation_id = "Attach Evidence to Dispute", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::AttachDisputeEvidence))] +//#\[instrument\(skip_all, fields(flow = ?Flow::AttachDisputeEvidence))] pub async fn attach_dispute_evidence( state: web::Data, req: HttpRequest, @@ -240,7 +240,7 @@ pub async fn attach_dispute_evidence( operation_id = "Retrieve a Dispute Evidence", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RetrieveDisputeEvidence))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RetrieveDisputeEvidence))] pub async fn retrieve_dispute_evidence( state: web::Data, req: HttpRequest, @@ -283,7 +283,7 @@ pub async fn retrieve_dispute_evidence( operation_id = "Delete Evidence attached to a Dispute", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::DeleteDisputeEvidence))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DeleteDisputeEvidence))] pub async fn delete_dispute_evidence( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/dummy_connector.rs b/crates/router/src/routes/dummy_connector.rs index 79338fc620c..41c4ecb2992 100644 --- a/crates/router/src/routes/dummy_connector.rs +++ b/crates/router/src/routes/dummy_connector.rs @@ -13,7 +13,7 @@ mod errors; pub mod types; mod utils; -#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] +//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] pub async fn dummy_connector_authorize_payment( state: web::Data, req: actix_web::HttpRequest, @@ -33,7 +33,7 @@ pub async fn dummy_connector_authorize_payment( ) .await } -#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] +//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] pub async fn dummy_connector_complete_payment( state: web::Data, req: actix_web::HttpRequest, @@ -57,7 +57,7 @@ pub async fn dummy_connector_complete_payment( ) .await } -#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] +//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] pub async fn dummy_connector_payment( state: web::Data, req: actix_web::HttpRequest, @@ -76,7 +76,7 @@ pub async fn dummy_connector_payment( ) .await } -#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentRetrieve))] pub async fn dummy_connector_payment_data( state: web::Data, req: actix_web::HttpRequest, @@ -96,7 +96,7 @@ pub async fn dummy_connector_payment_data( ) .await } -#[instrument(skip_all, fields(flow = ?types::Flow::DummyRefundCreate))] +//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyRefundCreate))] pub async fn dummy_connector_refund( state: web::Data, req: actix_web::HttpRequest, @@ -117,7 +117,7 @@ pub async fn dummy_connector_refund( ) .await } -#[instrument(skip_all, fields(flow = ?types::Flow::DummyRefundRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyRefundRetrieve))] pub async fn dummy_connector_refund_data( state: web::Data, req: actix_web::HttpRequest, diff --git a/crates/router/src/routes/dummy_connector/core.rs b/crates/router/src/routes/dummy_connector/core.rs index e8f84b3047e..1c82f893653 100644 --- a/crates/router/src/routes/dummy_connector/core.rs +++ b/crates/router/src/routes/dummy_connector/core.rs @@ -1,4 +1,4 @@ -use app::AppState; +use app::SessionState; use common_utils::generate_id_with_default_len; use error_stack::ResultExt; @@ -10,7 +10,7 @@ use crate::{ }; pub async fn payment( - state: AppState, + state: SessionState, req: types::DummyConnectorPaymentRequest, ) -> types::DummyConnectorResponse { utils::tokio_mock_sleep( @@ -41,7 +41,7 @@ pub async fn payment( } pub async fn payment_data( - state: AppState, + state: SessionState, req: types::DummyConnectorPaymentRetrieveRequest, ) -> types::DummyConnectorResponse { utils::tokio_mock_sleep( @@ -55,7 +55,7 @@ pub async fn payment_data( } pub async fn payment_authorize( - state: AppState, + state: SessionState, req: types::DummyConnectorPaymentConfirmRequest, ) -> types::DummyConnectorResponse { let payment_data = utils::get_payment_data_by_attempt_id(&state, req.attempt_id.clone()).await; @@ -83,7 +83,7 @@ pub async fn payment_authorize( } pub async fn payment_complete( - state: AppState, + state: SessionState, req: types::DummyConnectorPaymentCompleteRequest, ) -> types::DummyConnectorResponse<()> { utils::tokio_mock_sleep( @@ -145,7 +145,7 @@ pub async fn payment_complete( } pub async fn refund_payment( - state: AppState, + state: SessionState, req: types::DummyConnectorRefundRequest, ) -> types::DummyConnectorResponse { utils::tokio_mock_sleep( @@ -197,7 +197,7 @@ pub async fn refund_payment( } pub async fn refund_data( - state: AppState, + state: SessionState, req: types::DummyConnectorRefundRetrieveRequest, ) -> types::DummyConnectorResponse { let refund_id = req.refund_id; diff --git a/crates/router/src/routes/dummy_connector/utils.rs b/crates/router/src/routes/dummy_connector/utils.rs index 8bba182ad0a..ceb2e267e70 100644 --- a/crates/router/src/routes/dummy_connector/utils.rs +++ b/crates/router/src/routes/dummy_connector/utils.rs @@ -11,7 +11,10 @@ use super::{ consts, errors, types::{self, GetPaymentMethodDetails}, }; -use crate::{configs::settings, routes::AppState}; +use crate::{ + configs::settings, + routes::SessionState, +}; pub async fn tokio_mock_sleep(delay: u64, tolerance: u64) { let mut rng = rand::thread_rng(); @@ -26,7 +29,7 @@ pub async fn tokio_mock_sleep(delay: u64, tolerance: u64) { } pub async fn store_data_in_redis( - state: &AppState, + state: &SessionState, key: String, data: impl serde::Serialize + Debug, ttl: i64, @@ -46,7 +49,7 @@ pub async fn store_data_in_redis( } pub async fn get_payment_data_from_payment_id( - state: &AppState, + state: &SessionState, payment_id: String, ) -> types::DummyConnectorResult { let redis_conn = state @@ -65,7 +68,7 @@ pub async fn get_payment_data_from_payment_id( } pub async fn get_payment_data_by_attempt_id( - state: &AppState, + state: &SessionState, attempt_id: String, ) -> types::DummyConnectorResult { let redis_conn = state @@ -336,7 +339,7 @@ impl ProcessPaymentAttempt for types::DummyConnectorPaymentMethodData { impl types::DummyConnectorPaymentData { pub fn process_payment_attempt( - state: &AppState, + state: &SessionState, payment_attempt: types::DummyConnectorPaymentAttempt, ) -> types::DummyConnectorResult { let redirect_url = format!( diff --git a/crates/router/src/routes/ephemeral_key.rs b/crates/router/src/routes/ephemeral_key.rs index bfe7c353c28..505fea41211 100644 --- a/crates/router/src/routes/ephemeral_key.rs +++ b/crates/router/src/routes/ephemeral_key.rs @@ -8,7 +8,7 @@ use crate::{ types::api::customers, }; -#[instrument(skip_all, fields(flow = ?Flow::EphemeralKeyCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::EphemeralKeyCreate))] pub async fn ephemeral_key_create( state: web::Data, req: HttpRequest, @@ -29,7 +29,7 @@ pub async fn ephemeral_key_create( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::EphemeralKeyDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::EphemeralKeyDelete))] pub async fn ephemeral_key_delete( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/files.rs b/crates/router/src/routes/files.rs index 92be12b2bc9..f1ebd2d3424 100644 --- a/crates/router/src/routes/files.rs +++ b/crates/router/src/routes/files.rs @@ -27,7 +27,7 @@ use crate::{ operation_id = "Create a File", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::CreateFile))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CreateFile))] pub async fn files_create( state: web::Data, req: HttpRequest, @@ -71,7 +71,7 @@ pub async fn files_create( operation_id = "Delete a File", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::DeleteFile))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DeleteFile))] pub async fn files_delete( state: web::Data, req: HttpRequest, @@ -113,7 +113,7 @@ pub async fn files_delete( operation_id = "Retrieve a File", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RetrieveFile))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RetrieveFile))] pub async fn files_retrieve( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/gsm.rs b/crates/router/src/routes/gsm.rs index 77a0cb0a645..02272d4ccb1 100644 --- a/crates/router/src/routes/gsm.rs +++ b/crates/router/src/routes/gsm.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Create Gsm Rule", security(("admin_api_key" = [])), )] -#[instrument(skip_all, fields(flow = ?Flow::GsmRuleCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleCreate))] pub async fn create_gsm_rule( state: web::Data, req: HttpRequest, @@ -63,7 +63,7 @@ pub async fn create_gsm_rule( operation_id = "Retrieve Gsm Rule", security(("admin_api_key" = [])), )] -#[instrument(skip_all, fields(flow = ?Flow::GsmRuleRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleRetrieve))] pub async fn get_gsm_rule( state: web::Data, req: HttpRequest, @@ -100,7 +100,7 @@ pub async fn get_gsm_rule( operation_id = "Update Gsm Rule", security(("admin_api_key" = [])), )] -#[instrument(skip_all, fields(flow = ?Flow::GsmRuleUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleUpdate))] pub async fn update_gsm_rule( state: web::Data, req: HttpRequest, @@ -138,7 +138,7 @@ pub async fn update_gsm_rule( operation_id = "Delete Gsm Rule", security(("admin_api_key" = [])), )] -#[instrument(skip_all, fields(flow = ?Flow::GsmRuleDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleDelete))] pub async fn delete_gsm_rule( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/health.rs b/crates/router/src/routes/health.rs index fbfcd893a63..67302dbc5d9 100644 --- a/crates/router/src/routes/health.rs +++ b/crates/router/src/routes/health.rs @@ -11,7 +11,7 @@ use crate::{ }; /// . // #[logger::instrument(skip_all, name = "name1", level = "warn", fields( key1 = "val1" ))] -#[instrument(skip_all, fields(flow = ?Flow::HealthCheck))] +//#\[instrument\(skip_all, fields(flow = ?Flow::HealthCheck))] // #[actix_web::get("/health")] pub async fn health() -> impl actix_web::Responder { metrics::HEALTH_METRIC.add(&metrics::CONTEXT, 1, &[]); @@ -19,7 +19,7 @@ pub async fn health() -> impl actix_web::Responder { actix_web::HttpResponse::Ok().body("health is good") } -#[instrument(skip_all, fields(flow = ?Flow::DeepHealthCheck))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DeepHealthCheck))] pub async fn deep_health_check( state: web::Data, request: HttpRequest, @@ -40,7 +40,9 @@ pub async fn deep_health_check( .await } -async fn deep_health_check_func(state: app::AppState) -> RouterResponse { +async fn deep_health_check_func( + state: app::SessionState, +) -> RouterResponse { logger::info!("Deep health check was called"); logger::debug!("Database health check begin"); diff --git a/crates/router/src/routes/mandates.rs b/crates/router/src/routes/mandates.rs index 365f9a43248..6fc187ab288 100644 --- a/crates/router/src/routes/mandates.rs +++ b/crates/router/src/routes/mandates.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Retrieve a Mandate", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MandatesRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MandatesRetrieve))] // #[get("/{id}")] pub async fn get_mandate( state: web::Data, @@ -66,7 +66,7 @@ pub async fn get_mandate( operation_id = "Revoke a Mandate", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MandatesRevoke))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MandatesRevoke))] // #[post("/revoke/{id}")] pub async fn revoke_mandate( state: web::Data, @@ -113,7 +113,7 @@ pub async fn revoke_mandate( operation_id = "List Mandates", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::MandatesList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::MandatesList))] pub async fn retrieve_mandates_list( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/payment_link.rs b/crates/router/src/routes/payment_link.rs index 7742f6c1c0e..0318336b46d 100644 --- a/crates/router/src/routes/payment_link.rs +++ b/crates/router/src/routes/payment_link.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Retrieve a Payment Link", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip(state, req), fields(flow = ?Flow::PaymentLinkRetrieve))] +//#\[instrument\(skip(state, req), fields(flow = ?Flow::PaymentLinkRetrieve))] pub async fn payment_link_retrieve( state: web::Data, @@ -104,7 +104,7 @@ pub async fn initiate_payment_link( operation_id = "List all Payment links", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentLinkList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentLinkList))] pub async fn payments_link_list( state: web::Data, req: actix_web::HttpRequest, diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index 6c3d51f6592..de56b574214 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -5,7 +5,7 @@ use error_stack::ResultExt; use router_env::{instrument, logger, tracing, Flow}; use time::PrimitiveDateTime; -use super::app::AppState; +use super::app::{AppState, SessionState}; use crate::{ core::{api_locking, errors, payment_methods::cards}, services::{api, authentication as auth, authorization::permissions::Permission}, @@ -16,7 +16,7 @@ use crate::{ utils::Encode, }; -#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsCreate))] pub async fn create_payment_method_api( state: web::Data, req: HttpRequest, @@ -43,7 +43,7 @@ pub async fn create_payment_method_api( .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsList))] pub async fn list_payment_method_api( state: web::Data, req: HttpRequest, @@ -92,7 +92,7 @@ pub async fn list_payment_method_api( operation_id = "List all Payment Methods for a Customer", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] pub async fn list_customer_payment_method_api( state: web::Data, customer_id: web::Path<(String,)>, @@ -103,11 +103,10 @@ pub async fn list_customer_payment_method_api( let payload = query_payload.into_inner(); let customer_id = customer_id.into_inner().0; - let ephemeral_auth = - match auth::is_ephemeral_auth(req.headers(), &*state.store, &customer_id).await { - Ok(auth) => auth, - Err(err) => return api::log_and_return_error_response(err), - }; + let ephemeral_auth = match auth::is_ephemeral_auth(req.headers(), &customer_id) { + Ok(auth) => auth, + Err(err) => return api::log_and_return_error_response(err), + }; Box::pin(api::server_wrap( flow, state, @@ -151,7 +150,7 @@ pub async fn list_customer_payment_method_api( operation_id = "List all Payment Methods for a Customer", security(("publishable_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] pub async fn list_customer_payment_method_api_client( state: web::Data, req: HttpRequest, @@ -184,7 +183,7 @@ pub async fn list_customer_payment_method_api_client( .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsRetrieve))] pub async fn payment_method_retrieve_api( state: web::Data, req: HttpRequest, @@ -210,7 +209,7 @@ pub async fn payment_method_retrieve_api( .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsUpdate))] pub async fn payment_method_update_api( state: web::Data, req: HttpRequest, @@ -240,7 +239,7 @@ pub async fn payment_method_update_api( .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsDelete))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsDelete))] pub async fn payment_method_delete_api( state: web::Data, req: HttpRequest, @@ -264,7 +263,7 @@ pub async fn payment_method_delete_api( .await } -#[instrument(skip_all, fields(flow = ?Flow::ListCountriesCurrencies))] +//#\[instrument\(skip_all, fields(flow = ?Flow::ListCountriesCurrencies))] pub async fn list_countries_currencies_for_connector_payment_method( state: web::Data, req: HttpRequest, @@ -293,7 +292,7 @@ pub async fn list_countries_currencies_for_connector_payment_method( .await } -#[instrument(skip_all, fields(flow = ?Flow::DefaultPaymentMethodsSet))] +//#\[instrument\(skip_all, fields(flow = ?Flow::DefaultPaymentMethodsSet))] pub async fn default_payment_method_set_api( state: web::Data, req: HttpRequest, @@ -301,28 +300,29 @@ pub async fn default_payment_method_set_api( ) -> HttpResponse { let flow = Flow::DefaultPaymentMethodsSet; let payload = path.into_inner(); - let customer_id = payload.clone().customer_id; + let pc = payload.clone(); + let customer_id = pc.customer_id.as_str(); - let ephemeral_auth = - match auth::is_ephemeral_auth(req.headers(), &*state.store, &customer_id).await { - Ok(auth) => auth, - Err(err) => return api::log_and_return_error_response(err), - }; - let db = &*state.store.clone(); + let ephemeral_auth = match auth::is_ephemeral_auth(req.headers(), customer_id) { + Ok(auth) => auth, + Err(err) => return api::log_and_return_error_response(err), + }; Box::pin(api::server_wrap( flow, state, &req, payload, - |_state, auth: auth::AuthenticationData, default_payment_method, _| { - cards::set_default_payment_method( - db, + |state, auth: auth::AuthenticationData, default_payment_method, _| async move { + let res = cards::set_default_payment_method( + &*state.clone().store, auth.merchant_account.merchant_id, auth.key_store, - &customer_id, + customer_id, default_payment_method.payment_method_id, auth.merchant_account.storage_scheme, ) + .await; + res }, &*ephemeral_auth, api_locking::LockAction::NotApplicable, @@ -374,7 +374,7 @@ impl ParentPaymentMethodToken { &self, intent_created_at: Option, token: PaymentTokenData, - state: &AppState, + state: &SessionState, ) -> CustomResult<(), errors::ApiErrorResponse> { let token_json_str = token .encode_to_string_of_json() @@ -410,7 +410,7 @@ impl ParentPaymentMethodToken { .contains(&status) } - pub async fn delete(&self, state: &AppState) -> CustomResult<(), errors::ApiErrorResponse> { + pub async fn delete(&self, state: &SessionState) -> CustomResult<(), errors::ApiErrorResponse> { let redis_conn = state .store .get_redis_conn() diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index ac45228f90d..e7491a2ba69 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -89,7 +89,7 @@ use crate::{ operation_id = "Create a Payment", security(("api_key" = [])), )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] pub async fn payments_create( state: web::Data, req: actix_web::HttpRequest, @@ -166,7 +166,7 @@ pub async fn payments_create( // tag = "Payments", // operation_id = "Start a Redirection Payment" // )] -#[instrument(skip(state, req), fields(flow = ?Flow::PaymentsStart, payment_id))] +//#\[instrument\(skip(state, req), fields(flow = ?Flow::PaymentsStart, payment_id))] pub async fn payments_start( state: web::Data, req: actix_web::HttpRequest, @@ -232,7 +232,7 @@ pub async fn payments_start( operation_id = "Retrieve a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip(state, req), fields(flow, payment_id))] +//#\[instrument\(skip(state, req), fields(flow, payment_id))] // #[get("/{payment_id}")] pub async fn payments_retrieve( state: web::Data, @@ -282,6 +282,7 @@ pub async fn payments_retrieve( payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), + ) }, auth::auth_type( @@ -308,7 +309,7 @@ pub async fn payments_retrieve( operation_id = "Retrieve a Payment", security(("api_key" = [])) )] -#[instrument(skip(state, req), fields(flow, payment_id))] +//#\[instrument\(skip(state, req), fields(flow, payment_id))] // #[post("/sync")] pub async fn payments_retrieve_with_gateway_creds( state: web::Data, @@ -355,6 +356,7 @@ pub async fn payments_retrieve_with_gateway_creds( payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), + ) }, &*auth_type, @@ -380,7 +382,7 @@ pub async fn payments_retrieve_with_gateway_creds( operation_id = "Update a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsUpdate, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsUpdate, payment_id))] // #[post("/{payment_id}")] pub async fn payments_update( state: web::Data, @@ -448,7 +450,7 @@ pub async fn payments_update( operation_id = "Confirm a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] // #[post("/{payment_id}/confirm")] pub async fn payments_confirm( state: web::Data, @@ -526,7 +528,7 @@ pub async fn payments_confirm( operation_id = "Capture a Payment", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] // #[post("/{payment_id}/capture")] pub async fn payments_capture( state: web::Data, @@ -591,7 +593,7 @@ pub async fn payments_capture( operation_id = "Create Session tokens for a Payment", security(("publishable_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsSessionToken, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsSessionToken, payment_id))] pub async fn payments_connector_session( state: web::Data, req: actix_web::HttpRequest, @@ -653,7 +655,7 @@ pub async fn payments_connector_session( // tag = "Payments", // operation_id = "Get Redirect Response for a Payment" // )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] pub async fn payments_redirect_response( state: web::Data, req: actix_web::HttpRequest, @@ -689,6 +691,7 @@ pub async fn payments_redirect_response( auth.merchant_account, auth.key_store, req, + ) }, &auth::MerchantIdAuth(merchant_id), @@ -715,7 +718,7 @@ pub async fn payments_redirect_response( // tag = "Payments", // operation_id = "Get Redirect Response for a Payment" // )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] pub async fn payments_redirect_response_with_creds_identifier( state: web::Data, req: actix_web::HttpRequest, @@ -750,6 +753,7 @@ pub async fn payments_redirect_response_with_creds_identifier( auth.merchant_account, auth.key_store, req, + ) }, &auth::MerchantIdAuth(merchant_id), @@ -757,7 +761,7 @@ pub async fn payments_redirect_response_with_creds_identifier( ) .await } -#[instrument(skip_all, fields(flow =? Flow::PaymentsRedirect, payment_id))] +//#\[instrument\(skip_all, fields(flow =? Flow::PaymentsRedirect, payment_id))] pub async fn payments_complete_authorize( state: web::Data, req: actix_web::HttpRequest, @@ -794,6 +798,7 @@ pub async fn payments_complete_authorize( auth.merchant_account, auth.key_store, req, + ) }, &auth::MerchantIdAuth(merchant_id), @@ -819,7 +824,7 @@ pub async fn payments_complete_authorize( operation_id = "Cancel a Payment", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] // #[post("/{payment_id}/cancel")] pub async fn payments_cancel( state: web::Data, @@ -852,6 +857,7 @@ pub async fn payments_cancel( payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), + ) }, &auth::ApiKeyAuth, @@ -884,7 +890,7 @@ pub async fn payments_cancel( operation_id = "List all Payments", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn payments_list( state: web::Data, @@ -908,7 +914,7 @@ pub async fn payments_list( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn payments_list_by_filter( state: web::Data, @@ -934,7 +940,7 @@ pub async fn payments_list_by_filter( ) .await } -#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn get_filters_for_payments( state: web::Data, @@ -960,7 +966,7 @@ pub async fn get_filters_for_payments( } #[cfg(feature = "oltp")] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsApprove, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsApprove, payment_id))] // #[post("/{payment_id}/approve")] pub async fn payments_approve( state: web::Data, @@ -1021,7 +1027,7 @@ pub async fn payments_approve( } #[cfg(feature = "oltp")] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsReject, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsReject, payment_id))] // #[post("/{payment_id}/reject")] pub async fn payments_reject( state: web::Data, @@ -1067,6 +1073,7 @@ pub async fn payments_reject( payments::CallConnectorAction::Trigger, None, payment_types::HeaderPayload::default(), + ) }, match env::which() { @@ -1085,7 +1092,7 @@ pub async fn payments_reject( #[allow(clippy::too_many_arguments)] async fn authorize_verify_select( operation: Op, - state: app::AppState, + state: app::SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, @@ -1183,7 +1190,7 @@ where operation_id = "Increment authorized amount for a Payment", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsIncrementalAuthorization, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsIncrementalAuthorization, payment_id))] pub async fn payments_incremental_authorization( state: web::Data, req: actix_web::HttpRequest, @@ -1248,7 +1255,7 @@ pub async fn payments_incremental_authorization( operation_id = "Initiate external authentication for a Payment", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsExternalAuthentication, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsExternalAuthentication, payment_id))] pub async fn payments_external_authentication( state: web::Data, req: actix_web::HttpRequest, @@ -1297,7 +1304,7 @@ pub async fn payments_external_authentication( operation_id = "Authorize a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PaymentsAuthorize, payment_id))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsAuthorize, payment_id))] pub async fn post_3ds_payments_authorize( state: web::Data, req: actix_web::HttpRequest, @@ -1334,6 +1341,7 @@ pub async fn post_3ds_payments_authorize( auth.merchant_account, auth.key_store, req, + ) }, &auth::MerchantIdAuth(merchant_id), diff --git a/crates/router/src/routes/payouts.rs b/crates/router/src/routes/payouts.rs index f3b6a7cd477..5d6cdf8071b 100644 --- a/crates/router/src/routes/payouts.rs +++ b/crates/router/src/routes/payouts.rs @@ -26,7 +26,7 @@ use crate::{ operation_id = "Create a Payout", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsCreate))] pub async fn payouts_create( state: web::Data, req: HttpRequest, @@ -61,7 +61,7 @@ pub async fn payouts_create( operation_id = "Retrieve a Payout", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsRetrieve))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsRetrieve))] pub async fn payouts_retrieve( state: web::Data, req: HttpRequest, @@ -106,7 +106,7 @@ pub async fn payouts_retrieve( operation_id = "Update a Payout", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsUpdate))] pub async fn payouts_update( state: web::Data, req: HttpRequest, @@ -146,7 +146,7 @@ pub async fn payouts_update( operation_id = "Cancel a Payout", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsCancel))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsCancel))] pub async fn payouts_cancel( state: web::Data, req: HttpRequest, @@ -186,7 +186,7 @@ pub async fn payouts_cancel( operation_id = "Fulfill a Payout", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsFulfill))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsFulfill))] pub async fn payouts_fulfill( state: web::Data, req: HttpRequest, @@ -224,7 +224,7 @@ pub async fn payouts_fulfill( operation_id = "List payouts", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsList))] pub async fn payouts_list( state: web::Data, req: HttpRequest, @@ -262,7 +262,7 @@ pub async fn payouts_list( operation_id = "Filter payouts", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsList))] pub async fn payouts_list_by_filter( state: web::Data, req: HttpRequest, @@ -302,7 +302,7 @@ pub async fn payouts_list_by_filter( operation_id = "Filter payouts", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::PayoutsFilter))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsFilter))] pub async fn payouts_list_available_filters( state: web::Data, req: HttpRequest, @@ -329,7 +329,7 @@ pub async fn payouts_list_available_filters( .await } -#[instrument(skip_all, fields(flow = ?Flow::PayoutsAccounts))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsAccounts))] // #[get("/accounts")] pub async fn payouts_accounts() -> impl Responder { let _flow = Flow::PayoutsAccounts; diff --git a/crates/router/src/routes/pm_auth.rs b/crates/router/src/routes/pm_auth.rs index e0cce9c515c..9d0ef364fae 100644 --- a/crates/router/src/routes/pm_auth.rs +++ b/crates/router/src/routes/pm_auth.rs @@ -4,7 +4,7 @@ use router_env::{instrument, tracing, types::Flow}; use crate::{core::api_locking, routes::AppState, services::api as oss_api}; -#[instrument(skip_all, fields(flow = ?Flow::PmAuthLinkTokenCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PmAuthLinkTokenCreate))] pub async fn link_token_create( state: web::Data, req: HttpRequest, @@ -38,7 +38,7 @@ pub async fn link_token_create( .await } -#[instrument(skip_all, fields(flow = ?Flow::PmAuthExchangeToken))] +//#\[instrument\(skip_all, fields(flow = ?Flow::PmAuthExchangeToken))] pub async fn exchange_token( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/recon.rs b/crates/router/src/routes/recon.rs index 7845f52c924..7da563949eb 100644 --- a/crates/router/src/routes/recon.rs +++ b/crates/router/src/routes/recon.rs @@ -5,7 +5,7 @@ use error_stack::ResultExt; use masking::{ExposeInterface, PeekInterface, Secret}; use router_env::Flow; -use super::AppState; +use super::{AppState,SessionState}; use crate::{ core::{ api_locking, @@ -71,7 +71,7 @@ pub async fn get_recon_token(state: web::Data, req: HttpRequest) -> Ht } pub async fn send_recon_request( - state: AppState, + state: SessionState, user: UserFromToken, ) -> RouterResponse { let db = &*state.store; @@ -151,7 +151,7 @@ pub async fn send_recon_request( } pub async fn recon_merchant_account_update( - state: AppState, + state: SessionState, req: recon_api::ReconUpdateMerchantRequest, ) -> RouterResponse { let merchant_id = &req.merchant_id.clone(); @@ -218,7 +218,7 @@ pub async fn recon_merchant_account_update( } pub async fn generate_recon_token( - state: AppState, + state: SessionState, req: ReconUser, ) -> RouterResponse { let db = &*state.store; @@ -244,7 +244,7 @@ pub async fn generate_recon_token( pub async fn get_recon_auth_token( user: UserFromStorage, - state: AppState, + state: SessionState, ) -> RouterResult> { ReconToken::new_token(user.0.user_id.clone(), &state.conf).await } diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index d68c7138213..1a848d64e30 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -23,7 +23,7 @@ use crate::{ operation_id = "Create a Refund", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RefundsCreate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsCreate))] // #[post("")] pub async fn refunds_create( state: web::Data, @@ -63,7 +63,7 @@ pub async fn refunds_create( operation_id = "Retrieve a Refund", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow))] +//#\[instrument\(skip_all, fields(flow))] // #[get("/{id}")] pub async fn refunds_retrieve( state: web::Data, @@ -120,7 +120,7 @@ pub async fn refunds_retrieve( operation_id = "Retrieve a Refund", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow))] +//#\[instrument\(skip_all, fields(flow))] // #[post("/sync")] pub async fn refunds_retrieve_with_body( state: web::Data, @@ -171,7 +171,7 @@ pub async fn refunds_retrieve_with_body( operation_id = "Update a Refund", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RefundsUpdate))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsUpdate))] // #[post("/{id}")] pub async fn refunds_update( state: web::Data, @@ -207,7 +207,7 @@ pub async fn refunds_update( operation_id = "List all Refunds", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RefundsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsList))] #[cfg(feature = "olap")] pub async fn refunds_list( state: web::Data, @@ -244,7 +244,7 @@ pub async fn refunds_list( operation_id = "List all filters for Refunds", security(("api_key" = [])) )] -#[instrument(skip_all, fields(flow = ?Flow::RefundsList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsList))] #[cfg(feature = "olap")] pub async fn refunds_filter_list( state: web::Data, diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs index 8438424546c..5969ce49e1a 100644 --- a/crates/router/src/routes/routing.rs +++ b/crates/router/src/routes/routing.rs @@ -18,7 +18,7 @@ use crate::{ }; #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_create_config( state: web::Data, req: HttpRequest, @@ -54,7 +54,7 @@ pub async fn routing_create_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_link_config( state: web::Data, req: HttpRequest, @@ -91,7 +91,7 @@ pub async fn routing_link_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_retrieve_config( state: web::Data, req: HttpRequest, @@ -121,7 +121,7 @@ pub async fn routing_retrieve_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn list_routing_configs( state: web::Data, req: HttpRequest, @@ -183,7 +183,7 @@ pub async fn list_routing_configs( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_unlink_config( state: web::Data, req: HttpRequest, @@ -252,7 +252,7 @@ pub async fn routing_unlink_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_update_default_config( state: web::Data, req: HttpRequest, @@ -286,7 +286,7 @@ pub async fn routing_update_default_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_retrieve_default_config( state: web::Data, req: HttpRequest, @@ -314,7 +314,7 @@ pub async fn routing_retrieve_default_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn upsert_surcharge_decision_manager_config( state: web::Data, req: HttpRequest, @@ -347,7 +347,7 @@ pub async fn upsert_surcharge_decision_manager_config( .await } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn delete_surcharge_decision_manager_config( state: web::Data, req: HttpRequest, @@ -379,7 +379,7 @@ pub async fn delete_surcharge_decision_manager_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn retrieve_surcharge_decision_manager_config( state: web::Data, req: HttpRequest, @@ -410,7 +410,7 @@ pub async fn retrieve_surcharge_decision_manager_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn upsert_decision_manager_config( state: web::Data, req: HttpRequest, @@ -444,7 +444,7 @@ pub async fn upsert_decision_manager_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn delete_decision_manager_config( state: web::Data, req: HttpRequest, @@ -476,7 +476,7 @@ pub async fn delete_decision_manager_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn retrieve_decision_manager_config( state: web::Data, req: HttpRequest, @@ -504,7 +504,7 @@ pub async fn retrieve_decision_manager_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_retrieve_linked_config( state: web::Data, req: HttpRequest, @@ -567,7 +567,7 @@ pub async fn routing_retrieve_linked_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn upsert_connector_agnostic_mandate_config( state: web::Data, req: HttpRequest, @@ -602,7 +602,7 @@ pub async fn upsert_connector_agnostic_mandate_config( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_retrieve_default_config_for_profiles( state: web::Data, req: HttpRequest, @@ -638,7 +638,7 @@ pub async fn routing_retrieve_default_config_for_profiles( } #[cfg(feature = "olap")] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn routing_update_default_config_for_profile( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/verification.rs b/crates/router/src/routes/verification.rs index 00662663113..059b1d96ac4 100644 --- a/crates/router/src/routes/verification.rs +++ b/crates/router/src/routes/verification.rs @@ -8,7 +8,7 @@ use crate::{ services::{api, authentication as auth, authorization::permissions::Permission}, }; -#[instrument(skip_all, fields(flow = ?Flow::Verification))] +//#\[instrument\(skip_all, fields(flow = ?Flow::Verification))] pub async fn apple_pay_merchant_registration( state: web::Data, req: HttpRequest, @@ -39,7 +39,7 @@ pub async fn apple_pay_merchant_registration( .await } -#[instrument(skip_all, fields(flow = ?Flow::Verification))] +//#\[instrument\(skip_all, fields(flow = ?Flow::Verification))] pub async fn retrieve_apple_pay_verified_domains( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/verify_connector.rs b/crates/router/src/routes/verify_connector.rs index c045b3a8e6a..a5e41fb7f80 100644 --- a/crates/router/src/routes/verify_connector.rs +++ b/crates/router/src/routes/verify_connector.rs @@ -8,7 +8,7 @@ use crate::{ services::{self, authentication as auth, authorization::permissions::Permission}, }; -#[instrument(skip_all, fields(flow = ?Flow::VerifyPaymentConnector))] +//#\[instrument\(skip_all, fields(flow = ?Flow::VerifyPaymentConnector))] pub async fn payment_connector_verify( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/webhook_events.rs b/crates/router/src/routes/webhook_events.rs index ef1d64f54e9..4fead5c4ee1 100644 --- a/crates/router/src/routes/webhook_events.rs +++ b/crates/router/src/routes/webhook_events.rs @@ -11,7 +11,7 @@ use crate::{ }, }; -#[instrument(skip_all, fields(flow = ?Flow::WebhookEventInitialDeliveryAttemptList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::WebhookEventInitialDeliveryAttemptList))] pub async fn list_initial_webhook_delivery_attempts( state: web::Data, req: HttpRequest, @@ -52,7 +52,7 @@ pub async fn list_initial_webhook_delivery_attempts( .await } -#[instrument(skip_all, fields(flow = ?Flow::WebhookEventDeliveryAttemptList))] +//#\[instrument\(skip_all, fields(flow = ?Flow::WebhookEventDeliveryAttemptList))] pub async fn list_webhook_delivery_attempts( state: web::Data, req: HttpRequest, @@ -91,7 +91,7 @@ pub async fn list_webhook_delivery_attempts( .await } -#[instrument(skip_all, fields(flow = ?Flow::WebhookEventDeliveryRetry))] +//#\[instrument\(skip_all, fields(flow = ?Flow::WebhookEventDeliveryRetry))] pub async fn retry_webhook_delivery_attempt( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/webhooks.rs b/crates/router/src/routes/webhooks.rs index 03fe6a1d758..df6d15124dc 100644 --- a/crates/router/src/routes/webhooks.rs +++ b/crates/router/src/routes/webhooks.rs @@ -11,7 +11,7 @@ use crate::{ services::{api, authentication as auth}, }; -#[instrument(skip_all, fields(flow = ?Flow::IncomingWebhookReceive))] +//#\[instrument\(skip_all, fields(flow = ?Flow::IncomingWebhookReceive))] pub async fn receive_incoming_webhook( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index 6b604498c71..ffb65ff7a54 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -13,12 +13,17 @@ pub mod recon; #[cfg(feature = "email")] pub mod email; +use std::sync::Arc; + use data_models::errors::StorageResult; use error_stack::ResultExt; use masking::{ExposeInterface, StrongSecret}; #[cfg(feature = "kv_store")] use storage_impl::KVRouterStore; -use storage_impl::RouterStore; +use storage_impl::{ + redis::RedisStore, + RouterStore, +}; use tokio::sync::oneshot; pub use self::{api::*, encryption::*}; @@ -40,7 +45,8 @@ pub type Store = KVRouterStore; #[allow(clippy::expect_used)] pub async fn get_store( config: &Settings, - shut_down_signal: oneshot::Sender<()>, + schema: &str, + cache_store: Arc, test_transaction: bool, ) -> StorageResult { let master_config = config.master_database.clone().into_inner(); @@ -61,16 +67,9 @@ pub async fn get_store( let conf = (master_config.into(), replica_config.into()); let store: RouterStore = if test_transaction { - RouterStore::test_store(conf, &config.redis, master_enc_key).await? + RouterStore::test_store(conf, schema, &config.redis, master_enc_key).await? } else { - RouterStore::from_config( - conf, - &config.redis, - master_enc_key, - shut_down_signal, - consts::PUB_SUB_CHANNEL, - ) - .await? + RouterStore::from_config(conf, schema, master_enc_key, cache_store).await? }; #[cfg(feature = "kv_store")] @@ -84,6 +83,16 @@ pub async fn get_store( Ok(store) } +#[allow(clippy::expect_used)] +pub async fn get_cache_store( + config: &Settings, + shut_down_signal: oneshot::Sender<()>, + _test_transaction: bool, +) -> StorageResult> { + RouterStore::::cache_store(&config.redis, shut_down_signal, consts::PUB_SUB_CHANNEL) + .await +} + #[inline] pub fn generate_aes256_key() -> errors::CustomResult<[u8; 32], common_utils::errors::CryptoError> { use ring::rand::SecureRandom; diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 1a6246d559e..fd0eb74eff7 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -6,9 +6,11 @@ use std::{ fmt::Debug, future::Future, str, + sync::Arc, time::{Duration, Instant}, }; +use actix_http::header::HeaderMap; use actix_web::{ body, http::header::HeaderValue, web, FromRequest, HttpRequest, HttpResponse, Responder, ResponseError, @@ -45,9 +47,9 @@ use crate::{ }, logger, routes::{ - app::{AppStateInfo, ReqState}, + app::{AppStateInfo, ReqState, SessionStateInfo}, metrics::{self, request as metrics_request}, - AppState, + AppState, SessionState, }, types::{ self, @@ -154,7 +156,7 @@ pub trait ConnectorIntegration: ConnectorIntegrationAny, - _app_state: &AppState, + _app_state: &SessionState, ) -> CustomResult<(), errors::ConnectorError> { Ok(()) } @@ -164,7 +166,7 @@ pub trait ConnectorIntegration: ConnectorIntegrationAny, - _app_state: &AppState, + _app_state: &SessionState, ) -> CustomResult<(), errors::ConnectorError> { Ok(()) } @@ -269,7 +271,7 @@ pub enum CaptureSyncMethod { /// Handle the flow by interacting with connector module /// `connector_request` is applicable only in case if the `CallConnectorAction` is `Trigger` /// In other cases, It will be created if required, even if it is not passed -#[instrument(skip_all, fields(connector_name, payment_method))] +//#\[instrument\(skip_all, fields(connector_name, payment_method))] pub async fn execute_connector_processing_step< 'b, 'a, @@ -277,7 +279,7 @@ pub async fn execute_connector_processing_step< Req: Debug + Clone + 'static, Resp: Debug + Clone + 'static, >( - state: &'b AppState, + state: &'b SessionState, connector_integration: BoxedConnectorIntegration<'a, T, Req, Resp>, req: &'b types::RouterData, call_connector_action: payments::CallConnectorAction, @@ -534,9 +536,9 @@ where } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn call_connector_api( - state: &AppState, + state: &SessionState, request: Request, flow_name: &str, ) -> CustomResult, errors::ApiClientError> { @@ -570,9 +572,9 @@ pub async fn call_connector_api( handle_response(response).await } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn send_request( - state: &AppState, + state: &SessionState, request: Request, option_timeout_secs: Option, ) -> CustomResult { @@ -750,7 +752,7 @@ fn is_connection_closed_before_message_could_complete(error: &reqwest::Error) -> false } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn handle_response( response: CustomResult, ) -> CustomResult, errors::ApiClientError> { @@ -944,22 +946,23 @@ pub enum AuthFlow { } #[allow(clippy::too_many_arguments)] -#[instrument( - skip(request, payload, state, func, api_auth, request_state), - fields(merchant_id) -)] +//#\[instrument\( +// skip(request, payload, state, func, api_auth, request_state), +// fields(merchant_id) +// )] pub async fn server_wrap_util<'a, 'b, U, T, Q, F, Fut, E, OErr>( flow: &'a impl router_env::types::FlowMetric, state: web::Data, + incoming_request_header: &HeaderMap, mut request_state: ReqState, request: &'a HttpRequest, payload: T, func: F, - api_auth: &dyn AuthenticateAndFetch, + api_auth: &dyn AuthenticateAndFetch, lock_action: api_locking::LockAction, ) -> CustomResult, OErr> where - F: Fn(AppState, U, T, ReqState) -> Fut, + F: Fn(SessionState, U, T, ReqState) -> Fut, 'b: 'a, Fut: Future, E>>, Q: Serialize + Debug + 'a + ApiEventMetric, @@ -981,7 +984,6 @@ where let mut app_state = state.get_ref().clone(); - app_state.add_request_id(request_id); let start_instant = Instant::now(); let serialized_request = masking::masked_serialize(&payload) .attach_printable("Failed to serialize json request") @@ -989,9 +991,36 @@ where let mut event_type = payload.get_api_event_type(); + // let tenant_id = incoming_request_header + // .get("x-tenant-id") + // .and_then(|value| value.to_str().ok()) + // .ok_or_else(|| { + // errors::ApiErrorResponse::InvalidRequestData { message: "Missing tenant Id".to_string() } + // .switch() + // }).map(|tenant_id| if !state.conf.multitenancy.tenants.contains(&tenant_id.to_string()) { + // Err(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid tenant Id".to_string() } + // .switch()) + // } else { + // Ok(tenant_id) + // } )??; + let tenant_id = "public"; + let mut session_state = SessionState { + store: state.stores.get(tenant_id).ok_or_else(|| { + errors::ApiErrorResponse::InternalServerError + .switch() + })?.clone(), + conf: Arc::clone(&state.conf), + api_client: state.api_client.clone(), + event_handler: state.event_handler.clone(), + pool: state.pool.clone(), + file_storage_client: state.file_storage_client.clone(), + request_id: state.request_id.clone(), + }; + session_state.add_request_id(request_id); + // Currently auth failures are not recorded as API events let (auth_out, auth_type) = api_auth - .authenticate_and_fetch(request.headers(), &app_state) + .authenticate_and_fetch(request.headers(), &session_state) .await .switch()?; @@ -1011,14 +1040,14 @@ where let output = { lock_action .clone() - .perform_locking_action(&app_state, merchant_id.to_owned()) + .perform_locking_action(&session_state, merchant_id.to_owned()) .await .switch()?; - let res = func(app_state.clone(), auth_out, payload, request_state) + let res = func(session_state.clone(), auth_out, payload, request_state) .await .switch(); lock_action - .free_lock_action(&app_state, merchant_id.to_owned()) + .free_lock_action(&session_state, merchant_id.to_owned()) .await .switch()?; res @@ -1090,21 +1119,21 @@ where output } -#[instrument( - skip(request, state, func, api_auth, payload), - fields(request_method, request_url_path, status_code) -)] +//#\[instrument\( +// skip(request, state, func, api_auth, payload), +// fields(request_method, request_url_path, status_code) +// )] pub async fn server_wrap<'a, T, U, Q, F, Fut, E>( flow: impl router_env::types::FlowMetric, state: web::Data, request: &'a HttpRequest, payload: T, func: F, - api_auth: &dyn AuthenticateAndFetch, + api_auth: &dyn AuthenticateAndFetch, lock_action: api_locking::LockAction, ) -> HttpResponse where - F: Fn(AppState, U, T, ReqState) -> Fut, + F: Fn(SessionState, U, T, ReqState) -> Fut, Fut: Future, E>>, Q: Serialize + Debug + ApiEventMetric + 'a, T: Debug + Serialize + ApiEventMetric, @@ -1148,6 +1177,7 @@ where server_wrap_util( &flow, state.clone(), + incoming_request_header, req_state, request, payload, diff --git a/crates/router/src/services/api/client.rs b/crates/router/src/services/api/client.rs index 816269c086f..e7f19fa5da5 100644 --- a/crates/router/src/services/api/client.rs +++ b/crates/router/src/services/api/client.rs @@ -15,7 +15,7 @@ use crate::{ errors::{ApiClientError, CustomResult}, payments, }, - routes::AppState, + routes::SessionState, }; static NON_PROXIED_CLIENT: OnceCell = OnceCell::new(); @@ -160,7 +160,7 @@ where async fn send_request( &self, - state: &AppState, + state: &SessionState, request: Request, option_timeout_secs: Option, forward_to_kafka: bool, @@ -335,7 +335,7 @@ impl ApiClient for ProxyClient { } async fn send_request( &self, - state: &AppState, + state: &SessionState, request: Request, option_timeout_secs: Option, _forward_to_kafka: bool, @@ -387,7 +387,7 @@ impl ApiClient for MockApiClient { async fn send_request( &self, - _state: &AppState, + _state: &SessionState, _request: Request, _option_timeout_secs: Option, _forward_to_kafka: bool, diff --git a/crates/router/src/services/api/request.rs b/crates/router/src/services/api/request.rs index ed53da0d971..1635c826667 100644 --- a/crates/router/src/services/api/request.rs +++ b/crates/router/src/services/api/request.rs @@ -40,7 +40,7 @@ pub(super) trait RequestBuilderExt { } impl RequestBuilderExt for reqwest::RequestBuilder { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] fn add_headers(mut self, headers: reqwest::header::HeaderMap) -> Self { self = self.headers(headers); self diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs index 748b6753f56..885475a0374 100644 --- a/crates/router/src/services/authentication.rs +++ b/crates/router/src/services/authentication.rs @@ -21,14 +21,14 @@ use crate::consts; #[cfg(feature = "olap")] use crate::core::errors::UserResult; #[cfg(feature = "recon")] -use crate::routes::AppState; +use crate::routes::{AppState, SessionState}; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, db::StorageInterface, - routes::app::AppStateInfo, + routes::app::SessionStateInfo, services::api, types::domain, utils::OptionExt, @@ -182,7 +182,7 @@ impl AuthInfo for AuthenticationData { #[async_trait] pub trait AuthenticateAndFetch where - A: AppStateInfo, + A: SessionStateInfo, { async fn authenticate_and_fetch( &self, @@ -199,7 +199,7 @@ pub struct NoAuth; #[async_trait] impl AuthenticateAndFetch<(), A> for NoAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -213,7 +213,7 @@ where #[async_trait] impl AuthenticateAndFetch for ApiKeyAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -290,7 +290,7 @@ pub struct UserWithoutMerchantJWTAuth; #[async_trait] impl AuthenticateAndFetch for UserWithoutMerchantJWTAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -319,7 +319,7 @@ pub struct AdminApiAuth; #[async_trait] impl AuthenticateAndFetch<(), A> for AdminApiAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -341,13 +341,42 @@ where } } +#[derive(Debug)] +pub struct EphemeralKeyAuth(pub String); + +#[async_trait] +impl AuthenticateAndFetch for EphemeralKeyAuth +where + A: SessionStateInfo + Sync, +{ + async fn authenticate_and_fetch( + &self, + request_headers: &HeaderMap, + state: &A, + ) -> RouterResult<(AuthenticationData, AuthenticationType)> { + let api_key = + get_api_key(request_headers).change_context(errors::ApiErrorResponse::Unauthorized)?; + let ephemeral_key = state + .store() + .get_ephemeral_key(api_key) + .await + .change_context(errors::ApiErrorResponse::Unauthorized)?; + + if ephemeral_key.customer_id.ne(self.0.as_str()) { + return Err(report!(errors::ApiErrorResponse::InvalidEphemeralKey)); + } + MerchantIdAuth(ephemeral_key.merchant_id) + .authenticate_and_fetch(request_headers, state) + .await + } +} #[derive(Debug)] pub struct MerchantIdAuth(pub String); #[async_trait] impl AuthenticateAndFetch for MerchantIdAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -401,7 +430,7 @@ pub struct PublishableKeyAuth; #[async_trait] impl AuthenticateAndFetch for PublishableKeyAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -445,7 +474,7 @@ struct JwtAuthPayloadFetchUnit { #[async_trait] impl AuthenticateAndFetch<(), A> for JWTAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -474,7 +503,7 @@ where #[async_trait] impl AuthenticateAndFetch for JWTAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -512,7 +541,7 @@ pub struct JWTAuthMerchantFromRoute { #[async_trait] impl AuthenticateAndFetch<(), A> for JWTAuthMerchantFromRoute where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -549,7 +578,7 @@ pub struct JWTAuthMerchantOrProfileFromRoute { #[async_trait] impl AuthenticateAndFetch<(), A> for JWTAuthMerchantOrProfileFromRoute where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -606,7 +635,7 @@ where pub async fn parse_jwt_payload(headers: &HeaderMap, state: &A) -> RouterResult where T: serde::de::DeserializeOwned, - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { let token = get_jwt_from_authorization_header(headers)?; if let Some(token_from_cookies) = get_cookie_from_header(headers) @@ -626,7 +655,7 @@ where #[async_trait] impl AuthenticateAndFetch for JWTAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -676,7 +705,7 @@ pub type AuthenticationDataWithUserId = (AuthenticationData, String); #[async_trait] impl AuthenticateAndFetch for JWTAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -727,7 +756,7 @@ pub struct DashboardNoPermissionAuth; #[async_trait] impl AuthenticateAndFetch for DashboardNoPermissionAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -758,7 +787,7 @@ where #[async_trait] impl AuthenticateAndFetch<(), A> for DashboardNoPermissionAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -777,7 +806,7 @@ where #[async_trait] impl AuthenticateAndFetch for DashboardNoPermissionAuth where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -862,7 +891,7 @@ impl ClientSecretFetch for api_models::pm_auth::ExchangeTokenCreateRequest { } } -pub fn get_auth_type_and_flow( +pub fn get_auth_type_and_flow( headers: &HeaderMap, ) -> RouterResult<( Box>, @@ -884,7 +913,7 @@ pub fn check_client_secret_and_get_auth( api::AuthFlow, )> where - T: AppStateInfo, + T: SessionStateInfo, ApiKeyAuth: AuthenticateAndFetch, PublishableKeyAuth: AuthenticateAndFetch, { @@ -909,34 +938,24 @@ where Ok((Box::new(ApiKeyAuth), api::AuthFlow::Merchant)) } -pub async fn is_ephemeral_auth( +pub fn is_ephemeral_auth( headers: &HeaderMap, - db: &dyn StorageInterface, customer_id: &str, ) -> RouterResult>> { let api_key = get_api_key(headers)?; if !api_key.starts_with("epk") { return Ok(Box::new(ApiKeyAuth)); + } else { + return Ok(Box::new(EphemeralKeyAuth(customer_id.to_owned()))); } - - let ephemeral_key = db - .get_ephemeral_key(api_key) - .await - .change_context(errors::ApiErrorResponse::Unauthorized)?; - - if ephemeral_key.customer_id.ne(customer_id) { - return Err(report!(errors::ApiErrorResponse::InvalidEphemeralKey)); - } - - Ok(Box::new(MerchantIdAuth(ephemeral_key.merchant_id))) } pub fn is_jwt_auth(headers: &HeaderMap) -> bool { headers.get(crate::headers::AUTHORIZATION).is_some() } -pub async fn decode_jwt(token: &str, state: &impl AppStateInfo) -> RouterResult +pub async fn decode_jwt(token: &str, state: &impl SessionStateInfo) -> RouterResult where T: serde::de::DeserializeOwned, { @@ -1012,7 +1031,7 @@ pub struct ReconAdmin; #[cfg(feature = "recon")] impl AuthenticateAndFetch<(), A> for ReconAdmin where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { async fn authenticate_and_fetch( &self, @@ -1052,7 +1071,7 @@ impl AuthenticateAndFetch for ReconJWT { async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, - state: &AppState, + state: &SessionState, ) -> RouterResult<(ReconUser, AuthenticationType)> { let payload = parse_jwt_payload::(request_headers, state).await?; diff --git a/crates/router/src/services/authentication/blacklist.rs b/crates/router/src/services/authentication/blacklist.rs index 7c1cbf27e10..ba91d8f9c75 100644 --- a/crates/router/src/services/authentication/blacklist.rs +++ b/crates/router/src/services/authentication/blacklist.rs @@ -11,17 +11,17 @@ use crate::consts::{EMAIL_TOKEN_BLACKLIST_PREFIX, EMAIL_TOKEN_TIME_IN_SECS}; use crate::{ consts::{JWT_TOKEN_TIME_IN_SECS, ROLE_BLACKLIST_PREFIX, USER_BLACKLIST_PREFIX}, core::errors::{ApiErrorResponse, RouterResult}, - routes::app::AppStateInfo, + routes::app::SessionStateInfo, }; #[cfg(feature = "olap")] use crate::{ core::errors::{UserErrors, UserResult}, - routes::AppState, + routes::SessionState, services::authorization as authz, }; #[cfg(feature = "olap")] -pub async fn insert_user_in_blacklist(state: &AppState, user_id: &str) -> UserResult<()> { +pub async fn insert_user_in_blacklist(state: &SessionState, user_id: &str) -> UserResult<()> { let user_blacklist_key = format!("{}{}", USER_BLACKLIST_PREFIX, user_id); let expiry = expiry_to_i64(JWT_TOKEN_TIME_IN_SECS).change_context(UserErrors::InternalServerError)?; @@ -37,7 +37,7 @@ pub async fn insert_user_in_blacklist(state: &AppState, user_id: &str) -> UserRe } #[cfg(feature = "olap")] -pub async fn insert_role_in_blacklist(state: &AppState, role_id: &str) -> UserResult<()> { +pub async fn insert_role_in_blacklist(state: &SessionState, role_id: &str) -> UserResult<()> { let role_blacklist_key = format!("{}{}", ROLE_BLACKLIST_PREFIX, role_id); let expiry = expiry_to_i64(JWT_TOKEN_TIME_IN_SECS).change_context(UserErrors::InternalServerError)?; @@ -56,7 +56,7 @@ pub async fn insert_role_in_blacklist(state: &AppState, role_id: &str) -> UserRe } #[cfg(feature = "olap")] -async fn invalidate_role_cache(state: &AppState, role_id: &str) -> RouterResult<()> { +async fn invalidate_role_cache(state: &SessionState, role_id: &str) -> RouterResult<()> { let redis_conn = get_redis_connection(state)?; redis_conn .delete_key(authz::get_cache_key_from_role_id(role_id).as_str()) @@ -65,7 +65,7 @@ async fn invalidate_role_cache(state: &AppState, role_id: &str) -> RouterResult< .change_context(ApiErrorResponse::InternalServerError) } -pub async fn check_user_in_blacklist( +pub async fn check_user_in_blacklist( state: &A, user_id: &str, token_expiry: u64, @@ -80,7 +80,7 @@ pub async fn check_user_in_blacklist( .map(|timestamp| timestamp.map_or(false, |timestamp| timestamp > token_issued_at)) } -pub async fn check_role_in_blacklist( +pub async fn check_role_in_blacklist( state: &A, role_id: &str, token_expiry: u64, @@ -96,7 +96,7 @@ pub async fn check_role_in_blacklist( } #[cfg(feature = "email")] -pub async fn insert_email_token_in_blacklist(state: &AppState, token: &str) -> UserResult<()> { +pub async fn insert_email_token_in_blacklist(state: &SessionState, token: &str) -> UserResult<()> { let redis_conn = get_redis_connection(state).change_context(UserErrors::InternalServerError)?; let blacklist_key = format!("{}{token}", EMAIL_TOKEN_BLACKLIST_PREFIX); let expiry = @@ -108,7 +108,7 @@ pub async fn insert_email_token_in_blacklist(state: &AppState, token: &str) -> U } #[cfg(feature = "email")] -pub async fn check_email_token_in_blacklist(state: &AppState, token: &str) -> UserResult<()> { +pub async fn check_email_token_in_blacklist(state: &SessionState, token: &str) -> UserResult<()> { let redis_conn = get_redis_connection(state).change_context(UserErrors::InternalServerError)?; let blacklist_key = format!("{}{token}", EMAIL_TOKEN_BLACKLIST_PREFIX); let key_exists = redis_conn @@ -122,7 +122,7 @@ pub async fn check_email_token_in_blacklist(state: &AppState, token: &str) -> Us Ok(()) } -fn get_redis_connection(state: &A) -> RouterResult> { +fn get_redis_connection(state: &A) -> RouterResult> { state .store() .get_redis_conn() @@ -138,14 +138,14 @@ fn expiry_to_i64(expiry: u64) -> RouterResult { pub trait BlackList { async fn check_in_blacklist(&self, state: &A) -> RouterResult where - A: AppStateInfo + Sync; + A: SessionStateInfo + Sync; } #[async_trait::async_trait] impl BlackList for AuthToken { async fn check_in_blacklist(&self, state: &A) -> RouterResult where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { Ok( check_user_in_blacklist(state, &self.user_id, self.exp).await? @@ -158,7 +158,7 @@ impl BlackList for AuthToken { impl BlackList for UserAuthToken { async fn check_in_blacklist(&self, state: &A) -> RouterResult where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { check_user_in_blacklist(state, &self.user_id, self.exp).await } diff --git a/crates/router/src/services/authorization.rs b/crates/router/src/services/authorization.rs index 33edb173255..768c57a36d0 100644 --- a/crates/router/src/services/authorization.rs +++ b/crates/router/src/services/authorization.rs @@ -9,7 +9,7 @@ use super::authentication::AuthToken; use crate::{ consts, core::errors::{ApiErrorResponse, RouterResult, StorageErrorExt}, - routes::app::AppStateInfo, + routes::app::SessionStateInfo, }; #[cfg(feature = "olap")] @@ -23,7 +23,7 @@ pub async fn get_permissions( token: &AuthToken, ) -> RouterResult> where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { if let Some(permissions) = get_permissions_from_predefined_roles(&token.role_id) { return Ok(permissions); @@ -55,7 +55,7 @@ async fn get_permissions_from_cache( role_id: &str, ) -> RouterResult> where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { let redis_conn = get_redis_connection(state)?; @@ -82,7 +82,7 @@ async fn get_permissions_from_db( org_id: &str, ) -> RouterResult> where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { state .store() @@ -99,7 +99,7 @@ pub async fn set_permissions_in_cache( expiry: i64, ) -> RouterResult<()> where - A: AppStateInfo + Sync, + A: SessionStateInfo + Sync, { let redis_conn = get_redis_connection(state)?; @@ -139,7 +139,7 @@ pub fn check_authorization( ) } -fn get_redis_connection(state: &A) -> RouterResult> { +fn get_redis_connection(state: &A) -> RouterResult> { state .store() .get_redis_conn() diff --git a/crates/router/src/services/authorization/roles.rs b/crates/router/src/services/authorization/roles.rs index f99892c565d..8e5cb6fbeaa 100644 --- a/crates/router/src/services/authorization/roles.rs +++ b/crates/router/src/services/authorization/roles.rs @@ -4,7 +4,7 @@ use common_enums::{PermissionGroup, RoleScope}; use common_utils::errors::CustomResult; use super::{permission_groups::get_permissions_vec, permissions::Permission}; -use crate::{core::errors, routes::AppState}; +use crate::{core::errors, routes::SessionState}; pub mod predefined_roles; @@ -67,7 +67,7 @@ impl RoleInfo { } pub async fn from_role_id( - state: &AppState, + state: &SessionState, role_id: &str, merchant_id: &str, org_id: &str, diff --git a/crates/router/src/services/email/types.rs b/crates/router/src/services/email/types.rs index 2fbe7d606e5..b6996a8f58f 100644 --- a/crates/router/src/services/email/types.rs +++ b/crates/router/src/services/email/types.rs @@ -4,7 +4,7 @@ use error_stack::ResultExt; use external_services::email::{EmailContents, EmailData, EmailError}; use masking::{ExposeInterface, PeekInterface, Secret}; -use crate::{configs, consts, routes::AppState}; +use crate::{configs, consts, routes::SessionState}; #[cfg(feature = "olap")] use crate::{ core::errors::{UserErrors, UserResult}, @@ -378,7 +378,7 @@ pub struct BizEmailProd { } impl BizEmailProd { - pub fn new(state: &AppState, data: ProdIntent) -> UserResult { + pub fn new(state: &SessionState, data: ProdIntent) -> UserResult { Ok(Self { recipient_email: (domain::UserEmail::new( consts::user::BUSINESS_EMAIL.to_string().into(), diff --git a/crates/router/src/services/pm_auth.rs b/crates/router/src/services/pm_auth.rs index 91b752aaf13..84c91e15e0b 100644 --- a/crates/router/src/services/pm_auth.rs +++ b/crates/router/src/services/pm_auth.rs @@ -7,7 +7,7 @@ use pm_auth::{ use crate::{ core::errors::{self}, logger, - routes::AppState, + routes::SessionState, services::{self}, }; @@ -18,7 +18,7 @@ pub async fn execute_connector_processing_step< Req: Clone + 'static, Resp: Clone + 'static, >( - state: &'b AppState, + state: &'b SessionState, connector_integration: BoxedConnectorIntegration<'a, T, Req, Resp>, req: &'b PaymentAuthRouterData, connector: &pm_auth_types::PaymentMethodAuthConnectors, diff --git a/crates/router/src/types/api/mandates.rs b/crates/router/src/types/api/mandates.rs index dda6dc0cfcc..9d3b9e57532 100644 --- a/crates/router/src/types/api/mandates.rs +++ b/crates/router/src/types/api/mandates.rs @@ -10,7 +10,7 @@ use crate::{ payment_methods, }, newtype, - routes::AppState, + routes::SessionState, types::{ api, domain, storage::{self, enums as storage_enums}, @@ -25,7 +25,7 @@ newtype!( #[async_trait::async_trait] pub(crate) trait MandateResponseExt: Sized { async fn from_db_mandate( - state: &AppState, + state: &SessionState, key_store: domain::MerchantKeyStore, mandate: storage::Mandate, storage_scheme: storage_enums::MerchantStorageScheme, @@ -35,7 +35,7 @@ pub(crate) trait MandateResponseExt: Sized { #[async_trait::async_trait] impl MandateResponseExt for MandateResponse { async fn from_db_mandate( - state: &AppState, + state: &SessionState, key_store: domain::MerchantKeyStore, mandate: storage::Mandate, storage_scheme: storage_enums::MerchantStorageScheme, diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index 55dc4a2bf04..f433b6ea240 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -9,7 +9,7 @@ use crate::{ services, services::ConnectorIntegration, types::{self, api, domain, storage::enums as storage_enums}, - AppState, + SessionState, }; #[derive(Clone, Debug)] @@ -113,7 +113,7 @@ impl VerifyConnectorData { #[async_trait::async_trait] pub trait VerifyConnector { async fn verify( - state: &AppState, + state: &SessionState, connector_data: VerifyConnectorData, ) -> errors::RouterResponse<()> { let authorize_data = connector_data.get_payment_authorize_data(); @@ -147,7 +147,7 @@ pub trait VerifyConnector { } async fn get_access_token( - _state: &AppState, + _state: &SessionState, _connector_data: VerifyConnectorData, ) -> errors::CustomResult, errors::ApiErrorResponse> { // AccessToken is None for the connectors without the AccessToken Flow. diff --git a/crates/router/src/types/api/verify_connector/paypal.rs b/crates/router/src/types/api/verify_connector/paypal.rs index 2cb2a8061d1..99b7feb6616 100644 --- a/crates/router/src/types/api/verify_connector/paypal.rs +++ b/crates/router/src/types/api/verify_connector/paypal.rs @@ -4,7 +4,7 @@ use super::{VerifyConnector, VerifyConnectorData}; use crate::{ connector, core::errors, - routes::AppState, + routes::SessionState, services, types::{self, api}, }; @@ -12,7 +12,7 @@ use crate::{ #[async_trait::async_trait] impl VerifyConnector for connector::Paypal { async fn get_access_token( - state: &AppState, + state: &SessionState, connector_data: VerifyConnectorData, ) -> errors::CustomResult, errors::ApiErrorResponse> { let token_data: types::AccessTokenRequestData = diff --git a/crates/router/src/types/api/webhooks.rs b/crates/router/src/types/api/webhooks.rs index 52f5300d9be..61132221730 100644 --- a/crates/router/src/types/api/webhooks.rs +++ b/crates/router/src/types/api/webhooks.rs @@ -146,7 +146,7 @@ pub trait IncomingWebhook: ConnectorCommon + Sync { async fn verify_webhook_source_verification_call( &self, - state: &crate::routes::AppState, + state: &crate::routes::SessionState, merchant_account: &domain::MerchantAccount, merchant_connector_account: domain::MerchantConnectorAccount, connector_name: &str, diff --git a/crates/router/src/types/domain/types.rs b/crates/router/src/types/domain/types.rs index 0ef4e8579d3..a97cbc81101 100644 --- a/crates/router/src/types/domain/types.rs +++ b/crates/router/src/types/domain/types.rs @@ -37,7 +37,7 @@ impl< S: masking::Strategy + Send, > TypeEncryption for crypto::Encryptable> { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn encrypt( masked_data: Secret, key: &[u8], @@ -48,7 +48,7 @@ impl< Ok(Self::new(masked_data, encrypted_data.into())) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn decrypt( encrypted_data: Encryption, key: &[u8], @@ -72,7 +72,7 @@ impl< > TypeEncryption for crypto::Encryptable> { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn encrypt( masked_data: Secret, key: &[u8], @@ -85,7 +85,7 @@ impl< Ok(Self::new(masked_data, encrypted_data.into())) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn decrypt( encrypted_data: Encryption, key: &[u8], @@ -107,7 +107,7 @@ impl< S: masking::Strategy> + Send, > TypeEncryption, V, S> for crypto::Encryptable, S>> { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn encrypt( masked_data: Secret, S>, key: &[u8], @@ -118,7 +118,7 @@ impl< Ok(Self::new(masked_data, encrypted_data.into())) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn decrypt( encrypted_data: Encryption, key: &[u8], diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rs index bc06ffbad7b..ae5afef76ca 100644 --- a/crates/router/src/types/domain/user.rs +++ b/crates/router/src/types/domain/user.rs @@ -24,7 +24,7 @@ use crate::{ errors::{self, UserErrors, UserResult}, }, db::StorageInterface, - routes::AppState, + routes::SessionState, services::{authentication as auth, authentication::UserFromToken, authorization::info}, types::transformers::ForeignFrom, utils::{self, user::password}, @@ -196,7 +196,7 @@ impl UserCompanyName { pub struct NewUserOrganization(diesel_org::OrganizationNew); impl NewUserOrganization { - pub async fn insert_org_in_db(self, state: AppState) -> UserResult { + pub async fn insert_org_in_db(self, state: SessionState) -> UserResult { state .store .insert_organization(self.0) @@ -310,7 +310,7 @@ impl NewUserMerchant { self.new_organization.clone() } - pub async fn check_if_already_exists_in_db(&self, state: AppState) -> UserResult<()> { + pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> { if state .store .get_merchant_key_store_by_merchant_id( @@ -329,7 +329,10 @@ impl NewUserMerchant { Ok(()) } - pub async fn create_new_merchant_and_insert_in_db(&self, state: AppState) -> UserResult<()> { + pub async fn create_new_merchant_and_insert_in_db( + &self, + state: SessionState, + ) -> UserResult<()> { self.check_if_already_exists_in_db(state.clone()).await?; Box::pin(admin::create_merchant_account( state.clone(), @@ -512,7 +515,7 @@ impl NewUser { .attach_printable("Error while inserting user") } - pub async fn check_if_already_exists_in_db(&self, state: AppState) -> UserResult<()> { + pub async fn check_if_already_exists_in_db(&self, state: SessionState) -> UserResult<()> { if state .store .find_user_by_email(self.get_email().into_inner().expose().expose().as_str()) @@ -526,7 +529,7 @@ impl NewUser { pub async fn insert_user_and_merchant_in_db( &self, - state: AppState, + state: SessionState, ) -> UserResult { self.check_if_already_exists_in_db(state.clone()).await?; let db = state.store.as_ref(); @@ -543,7 +546,7 @@ impl NewUser { pub async fn insert_user_role_in_db( self, - state: AppState, + state: SessionState, role_id: String, user_status: UserStatus, ) -> UserResult { @@ -732,7 +735,7 @@ impl UserFromStorage { self.0.email.clone() } - pub async fn get_role_from_db(&self, state: AppState) -> UserResult { + pub async fn get_role_from_db(&self, state: SessionState) -> UserResult { state .store .find_user_role_by_user_id(&self.0.user_id) @@ -740,7 +743,7 @@ impl UserFromStorage { .change_context(UserErrors::InternalServerError) } - pub async fn get_roles_from_db(&self, state: &AppState) -> UserResult> { + pub async fn get_roles_from_db(&self, state: &SessionState) -> UserResult> { state .store .list_user_roles_by_user_id(&self.0.user_id) @@ -749,7 +752,7 @@ impl UserFromStorage { } #[cfg(feature = "email")] - pub fn get_verification_days_left(&self, state: &AppState) -> UserResult> { + pub fn get_verification_days_left(&self, state: &SessionState) -> UserResult> { if self.0.is_verified { return Ok(None); } @@ -777,7 +780,7 @@ impl UserFromStorage { pub async fn get_role_from_db_by_merchant_id( &self, - state: &AppState, + state: &SessionState, merchant_id: &str, ) -> CustomResult { state @@ -849,7 +852,7 @@ impl SignInWithRoleStrategyType { pub async fn get_signin_response( self, - state: &AppState, + state: &SessionState, ) -> UserResult { match self { Self::SingleRole(strategy) => strategy.get_signin_response(state).await, @@ -864,7 +867,10 @@ pub struct SignInWithSingleRoleStrategy { } impl SignInWithSingleRoleStrategy { - async fn get_signin_response(self, state: &AppState) -> UserResult { + async fn get_signin_response( + self, + state: &SessionState, + ) -> UserResult { let token = utils::user::generate_jwt_auth_token(state, &self.user, &self.user_role).await?; utils::user_role::set_role_permissions_in_cache_by_user_role(state, &self.user_role).await; @@ -884,7 +890,10 @@ pub struct SignInWithMultipleRolesStrategy { } impl SignInWithMultipleRolesStrategy { - async fn get_signin_response(self, state: &AppState) -> UserResult { + async fn get_signin_response( + self, + state: &SessionState, + ) -> UserResult { let merchant_accounts = state .store .list_multiple_merchant_accounts( diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index 0d840326f9b..cfd5e4a1e31 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -121,8 +121,11 @@ mod tests { ..PaymentAttemptNew::default() }; - let response = state - .store + let store = state + .stores + .get(state.conf.multitenancy.tenants.get(0).unwrap()) + .unwrap(); + let response = store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) .await .unwrap(); @@ -162,14 +165,16 @@ mod tests { attempt_id: attempt_id.clone(), ..PaymentAttemptNew::default() }; - state - .store + let store = state + .stores + .get(state.conf.multitenancy.tenants.get(0).unwrap()) + .unwrap(); + store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) .await .unwrap(); - let response = state - .store + let response = store .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &payment_id, &merchant_id, @@ -215,14 +220,16 @@ mod tests { attempt_id: uuid.clone(), ..PaymentAttemptNew::default() }; - state - .store + let store = state + .stores + .get(state.conf.multitenancy.tenants.get(0).unwrap()) + .unwrap(); + store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) .await .unwrap(); - let response = state - .store + let response = store .find_payment_attempt_by_payment_id_merchant_id_attempt_id( &uuid, "1", diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs index 398ff7f30d9..ea2a626c18d 100644 --- a/crates/router/src/utils.rs +++ b/crates/router/src/utils.rs @@ -742,7 +742,7 @@ pub async fn trigger_payments_webhook( key_store: &domain::MerchantKeyStore, payment_data: crate::core::payments::PaymentData, customer: Option, - state: &crate::routes::AppState, + state: &crate::routes::SessionState, operation: Op, ) -> RouterResult<()> where diff --git a/crates/router/src/utils/connector_onboarding.rs b/crates/router/src/utils/connector_onboarding.rs index 03735e61cc7..dc61a4a5f1b 100644 --- a/crates/router/src/utils/connector_onboarding.rs +++ b/crates/router/src/utils/connector_onboarding.rs @@ -5,7 +5,7 @@ use super::errors::StorageErrorExt; use crate::{ consts, core::errors::{api_error_response::NotImplementedMessage, ApiErrorResponse, RouterResult}, - routes::{app::settings, AppState}, + routes::{app::settings, SessionState}, types::{self, api::enums}, }; @@ -41,7 +41,7 @@ pub fn is_enabled( } pub async fn check_if_connector_exists( - state: &AppState, + state: &SessionState, connector_id: &str, merchant_id: &str, ) -> RouterResult<()> { @@ -70,7 +70,7 @@ pub async fn check_if_connector_exists( } pub async fn set_tracking_id_in_configs( - state: &AppState, + state: &SessionState, connector_id: &str, connector: enums::Connector, ) -> RouterResult<()> { @@ -115,7 +115,7 @@ pub async fn set_tracking_id_in_configs( } pub async fn get_tracking_id_from_configs( - state: &AppState, + state: &SessionState, connector_id: &str, connector: enums::Connector, ) -> RouterResult { diff --git a/crates/router/src/utils/connector_onboarding/paypal.rs b/crates/router/src/utils/connector_onboarding/paypal.rs index 708763a4440..9827a4b0937 100644 --- a/crates/router/src/utils/connector_onboarding/paypal.rs +++ b/crates/router/src/utils/connector_onboarding/paypal.rs @@ -5,7 +5,7 @@ use http::header; use crate::{ connector, core::errors::{ApiErrorResponse, RouterResult}, - routes::AppState, + routes::SessionState, types, types::api::{ enums, @@ -14,7 +14,7 @@ use crate::{ utils::verify_connector as verify_connector_utils, }; -pub async fn generate_access_token(state: AppState) -> RouterResult { +pub async fn generate_access_token(state: SessionState) -> RouterResult { let connector = enums::Connector::Paypal; let boxed_connector = types::api::ConnectorData::convert_connector( &state.conf.connectors, diff --git a/crates/router/src/utils/currency.rs b/crates/router/src/utils/currency.rs index 912f8fce94c..8d5eb5bb76d 100644 --- a/crates/router/src/utils/currency.rs +++ b/crates/router/src/utils/currency.rs @@ -14,7 +14,7 @@ use tokio::{sync::RwLock, time::sleep}; use crate::{ logger, routes::app::settings::{Conversion, DefaultExchangeRates}, - services, AppState, + services, SessionState, }; const REDIX_FOREX_CACHE_KEY: &str = "{forex_cache}_lock"; const REDIX_FOREX_CACHE_DATA: &str = "{forex_cache}_data"; @@ -121,7 +121,8 @@ async fn save_forex_to_local( // Alternative handler for handling the case, When no data in local as well as redis #[allow(dead_code)] async fn waited_fetch_and_update_caches( - state: &AppState, + state: &SessionState, + local_fetch_retry_delay: u64, local_fetch_retry_count: u64, ) -> CustomResult { @@ -171,7 +172,8 @@ impl From for CurrencyFactors { } } pub async fn get_forex_rates( - state: &AppState, + state: &SessionState, + call_delay: i64, local_fetch_retry_delay: u64, local_fetch_retry_count: u64, @@ -197,7 +199,8 @@ pub async fn get_forex_rates( } async fn handler_local_no_data( - state: &AppState, + state: &SessionState, + call_delay: i64, _local_fetch_retry_delay: u64, _local_fetch_retry_count: u64, @@ -216,7 +219,8 @@ async fn handler_local_no_data( } async fn successive_fetch_and_save_forex( - state: &AppState, + state: &SessionState, + stale_redis_data: Option, ) -> CustomResult { match acquire_redis_lock(state).await { @@ -249,7 +253,7 @@ async fn successive_fetch_and_save_forex( } async fn successive_save_data_to_redis_local( - state: &AppState, + state: &SessionState, forex: FxExchangeRatesCacheEntry, ) -> CustomResult { Ok(save_forex_to_redis(state, &forex) @@ -268,7 +272,8 @@ async fn successive_save_data_to_redis_local( } async fn fallback_forex_redis_check( - state: &AppState, + state: &SessionState, + redis_data: FxExchangeRatesCacheEntry, call_delay: i64, ) -> CustomResult { @@ -287,7 +292,8 @@ async fn fallback_forex_redis_check( } async fn handler_local_expired( - state: &AppState, + state: &SessionState, + call_delay: i64, local_rates: FxExchangeRatesCacheEntry, ) -> CustomResult { @@ -316,7 +322,7 @@ async fn handler_local_expired( } async fn fetch_forex_rates( - state: &AppState, + state: &SessionState, ) -> Result> { let forex_api_key = state.conf.forex_api.get_inner().api_key.peek(); @@ -371,7 +377,7 @@ async fn fetch_forex_rates( } pub async fn fallback_fetch_forex_rates( - state: &AppState, + state: &SessionState, ) -> CustomResult { let fallback_forex_api_key = state.conf.forex_api.get_inner().fallback_api_key.peek(); @@ -438,7 +444,7 @@ pub async fn fallback_fetch_forex_rates( } async fn release_redis_lock( - state: &AppState, + state: &SessionState, ) -> Result> { state .store @@ -449,9 +455,9 @@ async fn release_redis_lock( .change_context(ForexCacheError::RedisLockReleaseFailed) } -async fn acquire_redis_lock(app_state: &AppState) -> CustomResult { - let forex_api = app_state.conf.forex_api.get_inner(); - app_state +async fn acquire_redis_lock(state: &SessionState) -> CustomResult { + let forex_api = state.conf.forex_api.get_inner(); + state .store .get_redis_conn() .change_context(ForexCacheError::RedisConnectionError)? @@ -472,7 +478,7 @@ async fn acquire_redis_lock(app_state: &AppState) -> CustomResult CustomResult<(), ForexCacheError> { app_state @@ -485,7 +491,7 @@ async fn save_forex_to_redis( } async fn retrieve_forex_from_redis( - app_state: &AppState, + app_state: &SessionState, ) -> CustomResult, ForexCacheError> { app_state .store @@ -510,7 +516,8 @@ async fn is_redis_expired( } pub async fn convert_currency( - state: AppState, + state: SessionState, + amount: i64, to_currency: String, from_currency: String, diff --git a/crates/router/src/utils/user.rs b/crates/router/src/utils/user.rs index 60b2ac48286..8d6018d0c90 100644 --- a/crates/router/src/utils/user.rs +++ b/crates/router/src/utils/user.rs @@ -8,7 +8,7 @@ use masking::{ExposeInterface, Secret}; use crate::{ core::errors::{StorageError, UserErrors, UserResult}, - routes::AppState, + routes::SessionState, services::{ authentication::{AuthToken, UserFromToken}, authorization::roles::{self, RoleInfo}, @@ -24,7 +24,7 @@ pub mod sample_data; impl UserFromToken { pub async fn get_merchant_account_from_db( &self, - state: AppState, + state: SessionState, ) -> UserResult { let key_store = state .store @@ -54,7 +54,7 @@ impl UserFromToken { Ok(merchant_account) } - pub async fn get_user_from_db(&self, state: &AppState) -> UserResult { + pub async fn get_user_from_db(&self, state: &SessionState) -> UserResult { let user = state .store .find_user_by_id(&self.user_id) @@ -63,7 +63,7 @@ impl UserFromToken { Ok(user.into()) } - pub async fn get_role_info_from_db(&self, state: &AppState) -> UserResult { + pub async fn get_role_info_from_db(&self, state: &SessionState) -> UserResult { roles::RoleInfo::from_role_id(state, &self.role_id, &self.merchant_id, &self.org_id) .await .change_context(UserErrors::InternalServerError) @@ -71,7 +71,7 @@ impl UserFromToken { } pub async fn generate_jwt_auth_token( - state: &AppState, + state: &SessionState, user: &UserFromStorage, user_role: &UserRole, ) -> UserResult> { @@ -87,7 +87,7 @@ pub async fn generate_jwt_auth_token( } pub async fn generate_jwt_auth_token_with_custom_role_attributes( - state: &AppState, + state: &SessionState, user: &UserFromStorage, merchant_id: String, org_id: String, @@ -105,7 +105,7 @@ pub async fn generate_jwt_auth_token_with_custom_role_attributes( } pub fn get_dashboard_entry_response( - state: &AppState, + state: &SessionState, user: UserFromStorage, user_role: UserRole, token: Secret, @@ -125,7 +125,7 @@ pub fn get_dashboard_entry_response( #[allow(unused_variables)] pub fn get_verification_days_left( - state: &AppState, + state: &SessionState, user: &UserFromStorage, ) -> UserResult> { #[cfg(feature = "email")] @@ -175,7 +175,7 @@ pub fn get_multiple_merchant_details_with_status( } pub async fn get_user_from_db_by_email( - state: &AppState, + state: &SessionState, email: domain::UserEmail, ) -> CustomResult { state diff --git a/crates/router/src/utils/user/dashboard_metadata.rs b/crates/router/src/utils/user/dashboard_metadata.rs index e18a6401173..4fa4c06a32f 100644 --- a/crates/router/src/utils/user/dashboard_metadata.rs +++ b/crates/router/src/utils/user/dashboard_metadata.rs @@ -13,11 +13,11 @@ use masking::Secret; use crate::{ core::errors::{UserErrors, UserResult}, - headers, AppState, + headers, SessionState, }; pub async fn insert_merchant_scoped_metadata_to_db( - state: &AppState, + state: &SessionState, user_id: String, merchant_id: String, org_id: String, @@ -50,7 +50,7 @@ pub async fn insert_merchant_scoped_metadata_to_db( }) } pub async fn insert_user_scoped_metadata_to_db( - state: &AppState, + state: &SessionState, user_id: String, merchant_id: String, org_id: String, @@ -84,7 +84,7 @@ pub async fn insert_user_scoped_metadata_to_db( } pub async fn get_merchant_scoped_metadata_from_db( - state: &AppState, + state: &SessionState, merchant_id: String, org_id: String, metadata_keys: Vec, @@ -97,7 +97,7 @@ pub async fn get_merchant_scoped_metadata_from_db( .attach_printable("DB Error Fetching DashboardMetaData") } pub async fn get_user_scoped_metadata_from_db( - state: &AppState, + state: &SessionState, user_id: String, merchant_id: String, org_id: String, @@ -121,7 +121,7 @@ pub async fn get_user_scoped_metadata_from_db( } pub async fn update_merchant_scoped_metadata( - state: &AppState, + state: &SessionState, user_id: String, merchant_id: String, org_id: String, @@ -149,7 +149,7 @@ pub async fn update_merchant_scoped_metadata( .change_context(UserErrors::InternalServerError) } pub async fn update_user_scoped_metadata( - state: &AppState, + state: &SessionState, user_id: String, merchant_id: String, org_id: String, diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs index 8469bf770d2..9fbd9c2c245 100644 --- a/crates/router/src/utils/user/sample_data.rs +++ b/crates/router/src/utils/user/sample_data.rs @@ -11,12 +11,12 @@ use time::OffsetDateTime; use crate::{ consts, core::errors::sample_data::{SampleDataError, SampleDataResult}, - AppState, + SessionState, }; #[allow(clippy::type_complexity)] pub async fn generate_sample_data( - state: &AppState, + state: &SessionState, req: SampleDataRequest, merchant_id: &str, ) -> SampleDataResult)>> { diff --git a/crates/router/src/utils/user_role.rs b/crates/router/src/utils/user_role.rs index ba4c2878667..d0ad08848ca 100644 --- a/crates/router/src/utils/user_role.rs +++ b/crates/router/src/utils/user_role.rs @@ -9,7 +9,7 @@ use router_env::logger; use crate::{ consts, core::errors::{StorageErrorExt, UserErrors, UserResult}, - routes::AppState, + routes::SessionState, services::authorization::{self as authz, permissions::Permission, roles}, types::domain, }; @@ -73,7 +73,7 @@ pub fn validate_role_groups(groups: &[PermissionGroup]) -> UserResult<()> { } pub async fn validate_role_name( - state: &AppState, + state: &SessionState, role_name: &domain::RoleName, merchant_id: &str, org_id: &str, @@ -101,7 +101,7 @@ pub async fn validate_role_name( } pub async fn set_role_permissions_in_cache_by_user_role( - state: &AppState, + state: &SessionState, user_role: &UserRole, ) -> bool { set_role_permissions_in_cache_if_required( @@ -116,7 +116,7 @@ pub async fn set_role_permissions_in_cache_by_user_role( } pub async fn set_role_permissions_in_cache_if_required( - state: &AppState, + state: &SessionState, role_id: &str, merchant_id: &str, org_id: &str, @@ -143,7 +143,7 @@ pub async fn set_role_permissions_in_cache_if_required( } pub async fn get_multiple_role_info_for_user_roles( - state: &AppState, + state: &SessionState, user_roles: &[UserRole], ) -> UserResult> { futures::future::try_join_all(user_roles.iter().map(|user_role| async { diff --git a/crates/router/src/workflows/api_key_expiry.rs b/crates/router/src/workflows/api_key_expiry.rs index c5914810108..fe12056a3e0 100644 --- a/crates/router/src/workflows/api_key_expiry.rs +++ b/crates/router/src/workflows/api_key_expiry.rs @@ -1,12 +1,12 @@ use common_utils::{errors::ValidationError, ext_traits::ValueExt}; use diesel_models::{enums as storage_enums, ApiKeyExpiryTrackingData}; use router_env::logger; -use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerAppState}; +use scheduler::{workflows::ProcessTrackerWorkflow}; use crate::{ errors, logger::error, - routes::{metrics, AppState}, + routes::{metrics, SessionState}, services::email::types::ApiKeyExpiryReminder, types::{api, domain::UserEmail, storage}, utils::OptionExt, @@ -15,10 +15,10 @@ use crate::{ pub struct ApiKeyExpiryWorkflow; #[async_trait::async_trait] -impl ProcessTrackerWorkflow for ApiKeyExpiryWorkflow { +impl ProcessTrackerWorkflow for ApiKeyExpiryWorkflow { async fn execute_workflow<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { let db = &*state.store; @@ -137,7 +137,7 @@ impl ProcessTrackerWorkflow for ApiKeyExpiryWorkflow { async fn error_handler<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, process: storage::ProcessTracker, _error: errors::ProcessTrackerError, ) -> errors::CustomResult<(), errors::ProcessTrackerError> { diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rs index 760993decb4..0681b689043 100644 --- a/crates/router/src/workflows/outgoing_webhook_retry.rs +++ b/crates/router/src/workflows/outgoing_webhook_retry.rs @@ -17,18 +17,18 @@ use crate::{ core::webhooks::{self as webhooks_core, types::OutgoingWebhookTrackingData}, db::StorageInterface, errors, logger, - routes::{app::ReqState, AppState}, + routes::{app::ReqState, SessionState}, types::{domain, storage}, }; pub struct OutgoingWebhookRetryWorkflow; #[async_trait::async_trait] -impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { - #[instrument(skip_all)] +impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { + //#\[instrument\(skip_all)] async fn execute_workflow<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { let delivery_attempt = storage::enums::WebhookDeliveryAttempt::AutomaticRetry; @@ -204,10 +204,10 @@ impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { Ok(()) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn error_handler<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, error: errors::ProcessTrackerError, ) -> errors::CustomResult<(), errors::ProcessTrackerError> { @@ -243,7 +243,7 @@ impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { /// seconds between them by default. /// - `custom_merchant_mapping.merchant_id1`: Merchant-specific retry configuration for merchant /// with merchant ID `merchant_id1`. -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) async fn get_webhook_delivery_retry_schedule_time( db: &dyn StorageInterface, merchant_id: &str, @@ -288,7 +288,7 @@ pub(crate) async fn get_webhook_delivery_retry_schedule_time( } /// Schedule the webhook delivery task for retry -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub(crate) async fn retry_webhook_delivery_task( db: &dyn StorageInterface, merchant_id: &str, @@ -311,9 +311,9 @@ pub(crate) async fn retry_webhook_delivery_task( } } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn get_outgoing_webhook_content_and_event_type( - state: AppState, + state: SessionState, req_state: ReqState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs index 4b35e4d73b7..1abd6fe849d 100644 --- a/crates/router/src/workflows/payment_sync.rs +++ b/crates/router/src/workflows/payment_sync.rs @@ -3,7 +3,7 @@ use error_stack::ResultExt; use router_env::logger; use scheduler::{ consumer::{self, types::process_data, workflows::ProcessTrackerWorkflow}, - errors as sch_errors, utils as scheduler_utils, SchedulerAppState, + errors as sch_errors, utils as scheduler_utils, }; use crate::{ @@ -15,7 +15,7 @@ use crate::{ }, db::StorageInterface, errors, - routes::AppState, + routes::SessionState, services, types::{ api, @@ -27,10 +27,10 @@ use crate::{ pub struct PaymentsSyncWorkflow; #[async_trait::async_trait] -impl ProcessTrackerWorkflow for PaymentsSyncWorkflow { +impl ProcessTrackerWorkflow for PaymentsSyncWorkflow { async fn execute_workflow<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), sch_errors::ProcessTrackerError> { let db: &dyn StorageInterface = &*state.store; @@ -93,7 +93,7 @@ impl ProcessTrackerWorkflow for PaymentsSyncWorkflow { match &payment_data.payment_attempt.status { status if terminal_status.contains(status) => { state - .get_db() + .store .as_scheduler() .finish_process_with_business_status(process, "COMPLETED_BY_PT".to_string()) .await? @@ -198,7 +198,7 @@ impl ProcessTrackerWorkflow for PaymentsSyncWorkflow { async fn error_handler<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, error: sch_errors::ProcessTrackerError, ) -> errors::CustomResult<(), sch_errors::ProcessTrackerError> { diff --git a/crates/router/src/workflows/refund_router.rs b/crates/router/src/workflows/refund_router.rs index 934c208f911..515e34c0689 100644 --- a/crates/router/src/workflows/refund_router.rs +++ b/crates/router/src/workflows/refund_router.rs @@ -1,16 +1,16 @@ use scheduler::consumer::workflows::ProcessTrackerWorkflow; use crate::{ - core::refunds as refund_flow, errors, logger::error, routes::AppState, types::storage, + core::refunds as refund_flow, errors, logger::error, routes::SessionState, types::storage, }; pub struct RefundWorkflowRouter; #[async_trait::async_trait] -impl ProcessTrackerWorkflow for RefundWorkflowRouter { +impl ProcessTrackerWorkflow for RefundWorkflowRouter { async fn execute_workflow<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { Ok(Box::pin(refund_flow::start_refund_workflow(state, &process)).await?) @@ -18,7 +18,7 @@ impl ProcessTrackerWorkflow for RefundWorkflowRouter { async fn error_handler<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, process: storage::ProcessTracker, _error: errors::ProcessTrackerError, ) -> errors::CustomResult<(), errors::ProcessTrackerError> { diff --git a/crates/router/src/workflows/tokenized_data.rs b/crates/router/src/workflows/tokenized_data.rs index 0674982f92f..bc1842205ae 100644 --- a/crates/router/src/workflows/tokenized_data.rs +++ b/crates/router/src/workflows/tokenized_data.rs @@ -1,16 +1,16 @@ use scheduler::consumer::workflows::ProcessTrackerWorkflow; use crate::{ - core::payment_methods::vault, errors, logger::error, routes::AppState, types::storage, + core::payment_methods::vault, errors, logger::error, routes::SessionState, types::storage, }; pub struct DeleteTokenizeDataWorkflow; #[async_trait::async_trait] -impl ProcessTrackerWorkflow for DeleteTokenizeDataWorkflow { +impl ProcessTrackerWorkflow for DeleteTokenizeDataWorkflow { async fn execute_workflow<'a>( &'a self, - state: &'a AppState, + state: &'a SessionState, process: storage::ProcessTracker, ) -> Result<(), errors::ProcessTrackerError> { Ok(vault::start_tokenize_data_workflow(state, &process).await?) @@ -18,7 +18,7 @@ impl ProcessTrackerWorkflow for DeleteTokenizeDataWorkflow { async fn error_handler<'a>( &'a self, - _state: &'a AppState, + _state: &'a SessionState, process: storage::ProcessTracker, _error: errors::ProcessTrackerError, ) -> errors::CustomResult<(), errors::ProcessTrackerError> { diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index 52f86f67b31..50d3b1a1d32 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -186,7 +186,7 @@ async fn payments_create_success() { let conf = Settings::new().unwrap(); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let state = Box::pin(routes::SessionState::with_storage( conf, StorageImpl::PostgresqlTest, tx, diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 47ec71cc94e..804c54ddfd0 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -126,7 +126,8 @@ pub trait ConnectorActions: Connector { Box::new(services::MockApiClient), )) .await; - integration.execute_pretasks(&mut request, &state).await?; + let state: &SessionState = &state.stores.get("public").unwrap().clone(); + integration.execute_pretasks(&mut request, session_state).await?; Box::pin(call_connector(request, integration)).await } diff --git a/crates/router_env/tests/test_module/some_module.rs b/crates/router_env/tests/test_module/some_module.rs index 8c9dda2c08e..436decca716 100644 --- a/crates/router_env/tests/test_module/some_module.rs +++ b/crates/router_env/tests/test_module/some_module.rs @@ -1,7 +1,7 @@ use logger::instrument; use router_env as logger; -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn fn_with_colon(val: i32) { let a = 13; let b = 31; @@ -23,7 +23,7 @@ pub async fn fn_with_colon(val: i32) { fn_without_colon(131).await; } -#[instrument(fields(val3 = "abc"), skip_all)] +//#\[instrument\(fields(val3 = "abc"), skip_all)] pub async fn fn_without_colon(val: i32) { let a = 13; let b = 31; diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs index a95ac493247..528023e8f02 100644 --- a/crates/scheduler/src/consumer.rs +++ b/crates/scheduler/src/consumer.rs @@ -30,13 +30,17 @@ pub fn valid_business_statuses() -> Vec<&'static str> { vec!["Pending"] } -#[instrument(skip_all)] -pub async fn start_consumer( +//#\[instrument\(skip_all)] +pub async fn start_consumer( state: &T, settings: sync::Arc, - workflow_selector: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, + workflow_selector: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, (tx, mut rx): (mpsc::Sender<()>, mpsc::Receiver<()>), -) -> CustomResult<(), errors::ProcessTrackerError> { + app_state_to_session_state: F, +) -> CustomResult<(), errors::ProcessTrackerError> +where + F: Fn(&T, &str) -> U, +{ use std::time::Duration; use rand::distributions::{Distribution, Uniform}; @@ -77,17 +81,20 @@ pub async fn start_consumer( if settings.consumer.disabled { continue; } - - pt_utils::consumer_operation_handler( - state.clone(), - settings.clone(), - |error| { - logger::error!(?error, "Failed to perform consumer operation"); - }, - sync::Arc::clone(&consumer_operation_counter), - workflow_selector, - ) - .await; + let tenants = state.get_tenants(); + for tenant in tenants { + let session_state = app_state_to_session_state(state, tenant.as_str()); + pt_utils::consumer_operation_handler( + session_state.clone(), + settings.clone(), + |error| { + logger::error!(?error, "Failed to perform consumer operation"); + }, + sync::Arc::clone(&consumer_operation_counter), + workflow_selector, + ) + .await; + } } Ok(()) | Err(mpsc::error::TryRecvError::Disconnected) => { logger::debug!("Awaiting shutdown!"); @@ -115,7 +122,7 @@ pub async fn start_consumer( Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn consumer_operations( state: &T, settings: &SchedulerSettings, @@ -161,7 +168,7 @@ pub async fn consumer_operations( Ok(()) } -#[instrument(skip(db, redis_conn))] +//#\[instrument\(skip(db, redis_conn))] pub async fn fetch_consumer_tasks( db: &dyn ProcessTrackerInterface, redis_conn: &RedisConnectionPool, @@ -208,7 +215,7 @@ pub async fn fetch_consumer_tasks( } // Accept flow_options if required -#[instrument(skip(state), fields(workflow_id))] +//#\[instrument\(skip(state), fields(workflow_id))] pub async fn start_workflow( state: T, process: storage::ProcessTracker, @@ -220,7 +227,6 @@ where { tracing::Span::current().record("workflow_id", Uuid::new_v4().to_string()); logger::info!(pt.name=?process.name, pt.id=%process.id); - let res = workflow_selector .trigger_workflow(&state.clone(), process.clone()) .await @@ -232,7 +238,7 @@ where res } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn consumer_error_handler( state: &(dyn SchedulerInterface + 'static), process: storage::ProcessTracker, diff --git a/crates/scheduler/src/producer.rs b/crates/scheduler/src/producer.rs index fd2b9b654a4..a470e7e6bfb 100644 --- a/crates/scheduler/src/producer.rs +++ b/crates/scheduler/src/producer.rs @@ -19,14 +19,17 @@ use crate::{ scheduler::SchedulerInterface, utils::*, SchedulerAppState, }; -#[instrument(skip_all)] -pub async fn start_producer( +//#\[instrument\(skip_all)] +pub async fn start_producer( state: &T, scheduler_settings: Arc, (tx, mut rx): (mpsc::Sender<()>, mpsc::Receiver<()>), + app_state_to_session_state: F, ) -> CustomResult<(), errors::ProcessTrackerError> where + F: Fn(&T, &str) -> U, T: SchedulerAppState, + U: SchedulerAppState, { use std::time::Duration; @@ -65,13 +68,17 @@ where match rx.try_recv() { Err(mpsc::error::TryRecvError::Empty) => { interval.tick().await; - match run_producer_flow(state, &scheduler_settings).await { - Ok(_) => (), - Err(error) => { - // Intentionally not propagating error to caller. - // Any errors that occur in the producer flow must be handled here only, as - // this is the topmost level function which is concerned with the producer flow. - error!(%error); + let tenants = state.get_tenants(); + for tenant in tenants { + let session_state = app_state_to_session_state(state, tenant.as_str()); + match run_producer_flow(&session_state, &scheduler_settings).await { + Ok(_) => (), + Err(error) => { + // Intentionally not propagating error to caller. + // Any errors that occur in the producer flow must be handled here only, as + // this is the topmost level function which is concerned with the producer flow. + error!(%error); + } } } } @@ -79,7 +86,7 @@ where logger::debug!("Awaiting shutdown!"); rx.close(); shutdown_interval.tick().await; - logger::info!("Terminating consumer"); + logger::info!("Terminating producer"); break; } } @@ -92,7 +99,7 @@ where Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn run_producer_flow( state: &T, settings: &SchedulerSettings, @@ -121,7 +128,7 @@ where Ok(()) } -#[instrument(skip_all)] +//#\[instrument\(skip_all)] pub async fn fetch_producer_tasks( db: &dyn SchedulerInterface, conf: &SchedulerSettings, diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs index 273f10819f8..1ccfaa49a66 100644 --- a/crates/scheduler/src/scheduler.rs +++ b/crates/scheduler/src/scheduler.rs @@ -53,21 +53,43 @@ impl SchedulerInterface for MockDb {} #[async_trait::async_trait] pub trait SchedulerAppState: Send + Sync + Clone { fn get_db(&self) -> Box; + fn get_tenants(&self) -> Vec; } -pub async fn start_process_tracker( +pub async fn start_process_tracker< + T: SchedulerAppState + 'static, + U: SchedulerAppState + 'static, + F, +>( state: &T, scheduler_flow: SchedulerFlow, scheduler_settings: Arc, channel: (mpsc::Sender<()>, mpsc::Receiver<()>), - runner_from_task: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, -) -> CustomResult<(), errors::ProcessTrackerError> { + runner_from_task: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, + app_state_to_session_state: F, +) -> CustomResult<(), errors::ProcessTrackerError> +where + F: Fn(&T, &str) -> U, +{ match scheduler_flow { SchedulerFlow::Producer => { - producer::start_producer(state, scheduler_settings, channel).await? + producer::start_producer( + state, + scheduler_settings, + channel, + app_state_to_session_state, + ) + .await? } SchedulerFlow::Consumer => { - consumer::start_consumer(state, scheduler_settings, runner_from_task, channel).await? + consumer::start_consumer( + state, + scheduler_settings, + runner_from_task, + channel, + app_state_to_session_state, + ) + .await? } SchedulerFlow::Cleaner => { error!("This flow has not been implemented yet!"); diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs index 48d02f7fced..555472d3c7e 100644 --- a/crates/scheduler/src/utils.rs +++ b/crates/scheduler/src/utils.rs @@ -253,7 +253,7 @@ pub fn get_time_from_delta(delta: Option) -> Option( state: T, settings: sync::Arc, diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rs index 92ba8910bfb..7f5722b20f6 100644 --- a/crates/storage_impl/src/database/store.rs +++ b/crates/storage_impl/src/database/store.rs @@ -13,7 +13,7 @@ pub type PgPooledConn = async_bb8_diesel::Connection; #[async_trait::async_trait] pub trait DatabaseStore: Clone + Send + Sync { type Config: Send; - async fn new(config: Self::Config, test_transaction: bool) -> StorageResult; + async fn new(config: Self::Config, schema: &str, test_transaction: bool) -> StorageResult; fn get_master_pool(&self) -> &PgPool; fn get_replica_pool(&self) -> &PgPool; } @@ -26,9 +26,9 @@ pub struct Store { #[async_trait::async_trait] impl DatabaseStore for Store { type Config = Database; - async fn new(config: Database, test_transaction: bool) -> StorageResult { + async fn new(config: Database, schema: &str, test_transaction: bool) -> StorageResult { Ok(Self { - master_pool: diesel_make_pg_pool(&config, test_transaction).await?, + master_pool: diesel_make_pg_pool(&config, schema, test_transaction).await?, }) } @@ -50,12 +50,12 @@ pub struct ReplicaStore { #[async_trait::async_trait] impl DatabaseStore for ReplicaStore { type Config = (Database, Database); - async fn new(config: (Database, Database), test_transaction: bool) -> StorageResult { + async fn new(config: (Database, Database), schema: &str, test_transaction: bool) -> StorageResult { let (master_config, replica_config) = config; - let master_pool = diesel_make_pg_pool(&master_config, test_transaction) + let master_pool = diesel_make_pg_pool(&master_config, schema, test_transaction) .await .attach_printable("failed to create master pool")?; - let replica_pool = diesel_make_pg_pool(&replica_config, test_transaction) + let replica_pool = diesel_make_pg_pool(&replica_config, schema, test_transaction) .await .attach_printable("failed to create replica pool")?; Ok(Self { @@ -75,15 +75,18 @@ impl DatabaseStore for ReplicaStore { pub async fn diesel_make_pg_pool( database: &Database, + schema: &str, test_transaction: bool, ) -> StorageResult { let database_url = format!( - "postgres://{}:{}@{}:{}/{}", + "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", database.username, database.password.peek(), database.host, database.port, - database.dbname + database.dbname, + schema, + schema, ); let manager = async_bb8_diesel::ConnectionManager::::new(database_url); let mut pool = bb8::Pool::builder() diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 91e308888be..236fd2626ef 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -37,7 +37,7 @@ pub use crate::database::store::Store; #[derive(Debug, Clone)] pub struct RouterStore { db_store: T, - cache_store: RedisStore, + cache_store: Arc, master_encryption_key: StrongSecret>, pub request_id: Option, } @@ -54,20 +54,19 @@ where tokio::sync::oneshot::Sender<()>, &'static str, ); - async fn new(config: Self::Config, test_transaction: bool) -> StorageResult { + async fn new(config: Self::Config, schema: &str, test_transaction: bool) -> StorageResult { let (db_conf, cache_conf, encryption_key, cache_error_signal, inmemory_cache_stream) = config; if test_transaction { - Self::test_store(db_conf, &cache_conf, encryption_key) + Self::test_store(db_conf, schema, &cache_conf, encryption_key) .await .attach_printable("failed to create test router store") } else { Self::from_config( db_conf, - &cache_conf, + schema, encryption_key, - cache_error_signal, - inmemory_cache_stream, + Self::cache_store(&cache_conf, cache_error_signal, inmemory_cache_stream).await?, ) .await .attach_printable("failed to create store") @@ -92,12 +91,24 @@ impl RedisConnInterface for RouterStore { impl RouterStore { pub async fn from_config( db_conf: T::Config, - cache_conf: &redis_interface::RedisSettings, + schema: &str, encryption_key: StrongSecret>, + cache_store: Arc, + ) -> StorageResult { + let db_store = T::new(db_conf, schema, false).await?; + Ok(Self { + db_store, + cache_store, + master_encryption_key: encryption_key, + request_id: None, + }) + } + + pub async fn cache_store( + cache_conf: &redis_interface::RedisSettings, cache_error_signal: tokio::sync::oneshot::Sender<()>, inmemory_cache_stream: &str, - ) -> StorageResult { - let db_store = T::new(db_conf, false).await?; + ) -> StorageResult> { let cache_store = RedisStore::new(cache_conf) .await .change_context(StorageError::InitializationError) @@ -108,12 +119,7 @@ impl RouterStore { .await .change_context(StorageError::InitializationError) .attach_printable("Failed to subscribe to inmemory cache stream")?; - Ok(Self { - db_store, - cache_store, - master_encryption_key: encryption_key, - request_id: None, - }) + Ok(Arc::new(cache_store)) } pub fn master_key(&self) -> &StrongSecret> { @@ -125,18 +131,19 @@ impl RouterStore { /// Will panic if `CONNECTOR_AUTH_FILE_PATH` is not set pub async fn test_store( db_conf: T::Config, + schema: &str, cache_conf: &redis_interface::RedisSettings, encryption_key: StrongSecret>, ) -> StorageResult { // TODO: create an error enum and return proper error here - let db_store = T::new(db_conf, true).await?; + let db_store = T::new(db_conf, schema, true).await?; let cache_store = RedisStore::new(cache_conf) .await .change_context(StorageError::InitializationError) .attach_printable("failed to create redis cache")?; Ok(Self { db_store, - cache_store, + cache_store: Arc::new(cache_store), master_encryption_key: encryption_key, request_id: None, }) @@ -159,7 +166,7 @@ where T: DatabaseStore, { type Config = (RouterStore, String, u8, u32); - async fn new(config: Self::Config, _test_transaction: bool) -> StorageResult { + async fn new(config: Self::Config, schema:&str ,_test_transaction: bool) -> StorageResult { let (router_store, drainer_stream_name, drainer_num_partitions, ttl_for_kv) = config; Ok(Self::from_store( router_store, diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 138f3658aa0..8e88a46852b 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -38,7 +38,7 @@ use crate::{ #[async_trait::async_trait] impl PaymentAttemptInterface for RouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payment_attempt( &self, payment_attempt: PaymentAttemptNew, @@ -56,7 +56,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payment_attempt_with_attempt_id( &self, this: PaymentAttempt, @@ -74,7 +74,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id( &self, connector_transaction_id: &str, @@ -97,7 +97,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -118,7 +118,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -139,7 +139,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_merchant_id_connector_txn_id( &self, merchant_id: &str, @@ -160,7 +160,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id( &self, payment_id: &str, @@ -184,7 +184,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_filters_for_payments( &self, pi: &[PaymentIntent], @@ -222,7 +222,7 @@ impl PaymentAttemptInterface for RouterStore { ) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_preprocessing_id_merchant_id( &self, preprocessing_id: &str, @@ -244,7 +244,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_attempts_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -265,7 +265,7 @@ impl PaymentAttemptInterface for RouterStore { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_attempt_id_merchant_id( &self, attempt_id: &str, @@ -283,7 +283,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_total_count_of_filtered_payment_attempts( &self, merchant_id: &str, @@ -325,7 +325,7 @@ impl PaymentAttemptInterface for RouterStore { #[async_trait::async_trait] impl PaymentAttemptInterface for KVRouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payment_attempt( &self, payment_attempt: PaymentAttemptNew, @@ -459,7 +459,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payment_attempt_with_attempt_id( &self, this: PaymentAttempt, @@ -576,7 +576,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id( &self, connector_transaction_id: &str, @@ -626,7 +626,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -678,7 +678,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -733,7 +733,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_merchant_id_connector_txn_id( &self, merchant_id: &str, @@ -792,7 +792,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id( &self, payment_id: &str, @@ -839,7 +839,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_attempt_id_merchant_id( &self, attempt_id: &str, @@ -898,7 +898,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_attempt_by_preprocessing_id_merchant_id( &self, preprocessing_id: &str, @@ -957,7 +957,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_attempts_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -1000,7 +1000,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_filters_for_payments( &self, pi: &[PaymentIntent], @@ -1012,7 +1012,7 @@ impl PaymentAttemptInterface for KVRouterStore { .await } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_total_count_of_filtered_payment_attempts( &self, merchant_id: &str, @@ -1977,7 +1977,7 @@ impl DataModelExt for PaymentAttemptUpdate { } #[inline] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn add_connector_txn_id_to_reverse_lookup( store: &KVRouterStore, key: &str, @@ -2000,7 +2000,7 @@ async fn add_connector_txn_id_to_reverse_lookup( } #[inline] -#[instrument(skip_all)] +//#\[instrument\(skip_all)] async fn add_preprocessing_id_to_reverse_lookup( store: &KVRouterStore, key: &str, diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs index 8934b3ba2c6..eadb071ee78 100644 --- a/crates/storage_impl/src/payments/payment_intent.rs +++ b/crates/storage_impl/src/payments/payment_intent.rs @@ -143,7 +143,7 @@ impl PaymentIntentInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payment_intent( &self, this: PaymentIntent, @@ -204,7 +204,7 @@ impl PaymentIntentInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_intent_by_payment_id_merchant_id( &self, payment_id: &str, @@ -333,7 +333,7 @@ impl PaymentIntentInterface for KVRouterStore { #[async_trait::async_trait] impl PaymentIntentInterface for crate::RouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payment_intent( &self, new: PaymentIntentNew, @@ -350,7 +350,7 @@ impl PaymentIntentInterface for crate::RouterStore { .map(PaymentIntent::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payment_intent( &self, this: PaymentIntent, @@ -368,7 +368,7 @@ impl PaymentIntentInterface for crate::RouterStore { .map(PaymentIntent::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payment_intent_by_payment_id_merchant_id( &self, payment_id: &str, @@ -385,7 +385,7 @@ impl PaymentIntentInterface for crate::RouterStore { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_active_payment_attempt( &self, payment: &mut PaymentIntent, @@ -414,7 +414,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payment_intent_by_constraints( &self, merchant_id: &str, @@ -528,7 +528,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payment_intents_by_time_range_constraints( &self, merchant_id: &str, @@ -542,7 +542,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_filtered_payment_intents_attempt( &self, merchant_id: &str, @@ -683,7 +683,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_filtered_active_attempt_ids_for_total_count( &self, merchant_id: &str, diff --git a/crates/storage_impl/src/payouts/payout_attempt.rs b/crates/storage_impl/src/payouts/payout_attempt.rs index 50334442e63..9f1772a4466 100644 --- a/crates/storage_impl/src/payouts/payout_attempt.rs +++ b/crates/storage_impl/src/payouts/payout_attempt.rs @@ -36,7 +36,7 @@ use crate::{ #[async_trait::async_trait] impl PayoutAttemptInterface for KVRouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payout_attempt( &self, new_payout_attempt: PayoutAttemptNew, @@ -128,7 +128,7 @@ impl PayoutAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payout_attempt( &self, this: &PayoutAttempt, @@ -188,7 +188,7 @@ impl PayoutAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payout_attempt_by_merchant_id_payout_attempt_id( &self, merchant_id: &str, @@ -246,7 +246,7 @@ impl PayoutAttemptInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_filters_for_payouts( &self, payouts: &[Payouts], @@ -261,7 +261,7 @@ impl PayoutAttemptInterface for KVRouterStore { #[async_trait::async_trait] impl PayoutAttemptInterface for crate::RouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payout_attempt( &self, new: PayoutAttemptNew, @@ -279,7 +279,7 @@ impl PayoutAttemptInterface for crate::RouterStore { .map(PayoutAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payout_attempt( &self, this: &PayoutAttempt, @@ -299,7 +299,7 @@ impl PayoutAttemptInterface for crate::RouterStore { .map(PayoutAttempt::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payout_attempt_by_merchant_id_payout_attempt_id( &self, merchant_id: &str, @@ -320,7 +320,7 @@ impl PayoutAttemptInterface for crate::RouterStore { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn get_filters_for_payouts( &self, payouts: &[Payouts], diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs index 0f72aa592bf..8561cfdbd5d 100644 --- a/crates/storage_impl/src/payouts/payouts.rs +++ b/crates/storage_impl/src/payouts/payouts.rs @@ -45,7 +45,7 @@ use crate::{ #[async_trait::async_trait] impl PayoutsInterface for KVRouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payout( &self, new: PayoutsNew, @@ -119,7 +119,7 @@ impl PayoutsInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payout( &self, this: &Payouts, @@ -177,7 +177,7 @@ impl PayoutsInterface for KVRouterStore { } } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -219,7 +219,7 @@ impl PayoutsInterface for KVRouterStore { .map(Payouts::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_optional_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -272,7 +272,7 @@ impl PayoutsInterface for KVRouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payouts_by_constraints( &self, merchant_id: &str, @@ -285,7 +285,7 @@ impl PayoutsInterface for KVRouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payouts_and_attempts( &self, merchant_id: &str, @@ -299,7 +299,7 @@ impl PayoutsInterface for KVRouterStore { } #[cfg(feature = "olap")] - #[instrument[skip_all]] + //#[instrument[skip_all]] async fn filter_payouts_by_time_range_constraints( &self, merchant_id: &str, @@ -314,7 +314,7 @@ impl PayoutsInterface for KVRouterStore { #[async_trait::async_trait] impl PayoutsInterface for crate::RouterStore { - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn insert_payout( &self, new: PayoutsNew, @@ -331,7 +331,7 @@ impl PayoutsInterface for crate::RouterStore { .map(Payouts::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn update_payout( &self, this: &Payouts, @@ -351,7 +351,7 @@ impl PayoutsInterface for crate::RouterStore { .map(Payouts::from_storage_model) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -368,7 +368,7 @@ impl PayoutsInterface for crate::RouterStore { }) } - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn find_optional_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -386,7 +386,7 @@ impl PayoutsInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payouts_by_constraints( &self, merchant_id: &str, @@ -502,7 +502,7 @@ impl PayoutsInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payouts_and_attempts( &self, merchant_id: &str, @@ -636,7 +636,7 @@ impl PayoutsInterface for crate::RouterStore { } #[cfg(feature = "olap")] - #[instrument(skip_all)] + //#\[instrument\(skip_all)] async fn filter_payouts_by_time_range_constraints( &self, merchant_id: &str, From 2265882623371f7a66fa043bf8c69894d082e049 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Mon, 13 May 2024 15:58:54 +0530 Subject: [PATCH 02/24] feat(multitenancy): add base_url for redirection and pay start --- config/development.toml | 5 +- crates/analytics/src/api_event/core.rs | 4 +- crates/analytics/src/lib.rs | 10 +- crates/analytics/src/payments/core.rs | 2 +- crates/analytics/src/sdk_events/core.rs | 4 +- crates/analytics/src/sqlx.rs | 6 +- .../src/query/connector_response.rs | 6 +- .../src/query/process_tracker.rs | 14 +- crates/drainer/src/connection.rs | 12 +- crates/drainer/src/handler.rs | 78 +++++--- crates/drainer/src/health_check.rs | 54 +++--- crates/drainer/src/lib.rs | 13 +- crates/drainer/src/main.rs | 19 +- crates/drainer/src/secrets_transformers.rs | 1 + crates/drainer/src/services.rs | 16 +- crates/drainer/src/settings.rs | 29 ++- crates/drainer/src/stream.rs | 2 +- crates/redis_interface/src/commands.rs | 166 +++++++++++------- crates/redis_interface/src/lib.rs | 31 ++-- crates/router/src/bin/scheduler.rs | 59 ++++--- .../src/compatibility/stripe/customers.rs | 10 +- .../router/src/compatibility/stripe/errors.rs | 6 +- .../compatibility/stripe/payment_intents.rs | 16 +- .../src/compatibility/stripe/refunds.rs | 8 +- .../src/compatibility/stripe/setup_intents.rs | 8 +- crates/router/src/compatibility/wrap.rs | 2 +- crates/router/src/configs/defaults.rs | 2 +- crates/router/src/configs/settings.rs | 26 ++- crates/router/src/connector/adyen.rs | 10 +- crates/router/src/connector/stripe.rs | 10 +- crates/router/src/connector/wise.rs | 10 +- crates/router/src/core/api_keys.rs | 16 +- crates/router/src/core/api_locking.rs | 9 +- .../router/src/core/blocklist/transformers.rs | 4 +- crates/router/src/core/cards_info.rs | 2 +- crates/router/src/core/customers.rs | 10 +- crates/router/src/core/disputes.rs | 10 +- .../src/core/errors/api_error_response.rs | 2 + crates/router/src/core/errors/transformers.rs | 3 + crates/router/src/core/fraud_check.rs | 6 +- .../fraud_check/flows/fulfillment_flow.rs | 2 +- .../fraud_check/operation/fraud_check_post.rs | 8 +- .../fraud_check/operation/fraud_check_pre.rs | 4 +- crates/router/src/core/gsm.rs | 8 +- crates/router/src/core/mandate.rs | 10 +- .../router/src/core/payment_methods/cards.rs | 34 ++-- .../surcharge_decision_configs.rs | 4 +- .../router/src/core/payment_methods/vault.rs | 16 +- crates/router/src/core/payments.rs | 22 ++- .../src/core/payments/conditional_configs.rs | 6 +- crates/router/src/core/payments/customers.rs | 2 +- crates/router/src/core/payments/helpers.rs | 49 +++--- crates/router/src/core/payments/operations.rs | 26 +-- .../payments/operations/payment_approve.rs | 6 +- .../payments/operations/payment_cancel.rs | 6 +- .../payments/operations/payment_capture.rs | 6 +- .../operations/payment_complete_authorize.rs | 14 +- .../payments/operations/payment_confirm.rs | 16 +- .../payments/operations/payment_create.rs | 24 +-- .../payments/operations/payment_reject.rs | 6 +- .../payments/operations/payment_response.rs | 2 +- .../payments/operations/payment_session.rs | 12 +- .../core/payments/operations/payment_start.rs | 12 +- .../payments/operations/payment_status.rs | 10 +- .../payments/operations/payment_update.rs | 14 +- .../payments_incremental_authorization.rs | 12 +- crates/router/src/core/payments/retry.rs | 16 +- .../router/src/core/payments/tokenization.rs | 2 +- .../router/src/core/payments/transformers.rs | 26 +-- crates/router/src/core/payments/types.rs | 4 +- crates/router/src/core/payouts.rs | 10 +- crates/router/src/core/payouts/retry.rs | 14 +- crates/router/src/core/payouts/validator.rs | 2 +- crates/router/src/core/refunds.rs | 26 +-- crates/router/src/core/refunds/validator.rs | 8 +- crates/router/src/core/user.rs | 2 +- crates/router/src/core/utils.rs | 18 +- crates/router/src/core/verification.rs | 7 +- crates/router/src/core/webhooks.rs | 10 +- .../src/core/webhooks/webhook_events.rs | 6 +- crates/router/src/db/address.rs | 28 +-- crates/router/src/db/api_keys.rs | 12 +- crates/router/src/db/authentication.rs | 6 +- crates/router/src/db/authorization.rs | 6 +- crates/router/src/db/blocklist.rs | 22 +-- crates/router/src/db/blocklist_fingerprint.rs | 8 +- crates/router/src/db/blocklist_lookup.rs | 14 +- crates/router/src/db/business_profile.rs | 12 +- crates/router/src/db/cache.rs | 12 +- crates/router/src/db/capture.rs | 14 +- crates/router/src/db/cards_info.rs | 4 +- crates/router/src/db/configs.rs | 16 +- crates/router/src/db/customers.rs | 26 +-- crates/router/src/db/dashboard_metadata.rs | 12 +- crates/router/src/db/dispute.rs | 12 +- crates/router/src/db/ephemeral_key.rs | 4 +- crates/router/src/db/events.rs | 18 +- crates/router/src/db/file.rs | 8 +- crates/router/src/db/fraud_check.rs | 14 +- crates/router/src/db/gsm.rs | 10 +- crates/router/src/db/health_check.rs | 2 +- crates/router/src/db/kafka_store.rs | 7 +- crates/router/src/db/locker_mock_up.rs | 6 +- crates/router/src/db/mandate.rs | 12 +- crates/router/src/db/merchant_account.rs | 16 +- .../src/db/merchant_connector_account.rs | 20 +-- crates/router/src/db/merchant_key_store.rs | 8 +- crates/router/src/db/organization.rs | 6 +- crates/router/src/db/payment_link.rs | 6 +- crates/router/src/db/payment_method.rs | 28 +-- crates/router/src/db/refund.rs | 40 ++--- crates/router/src/db/reverse_lookup.rs | 8 +- crates/router/src/db/role.rs | 12 +- crates/router/src/db/routing_algorithm.rs | 12 +- crates/router/src/db/user.rs | 14 +- crates/router/src/db/user_role.rs | 16 +- crates/router/src/routes/admin.rs | 34 ++-- crates/router/src/routes/api_keys.rs | 10 +- crates/router/src/routes/app.rs | 63 +++++-- crates/router/src/routes/cache.rs | 2 +- crates/router/src/routes/cards_info.rs | 2 +- crates/router/src/routes/configs.rs | 8 +- crates/router/src/routes/customers.rs | 12 +- crates/router/src/routes/disputes.rs | 14 +- crates/router/src/routes/dummy_connector.rs | 12 +- .../router/src/routes/dummy_connector/core.rs | 2 +- .../src/routes/dummy_connector/utils.rs | 7 +- crates/router/src/routes/ephemeral_key.rs | 4 +- crates/router/src/routes/files.rs | 6 +- crates/router/src/routes/gsm.rs | 8 +- crates/router/src/routes/health.rs | 4 +- crates/router/src/routes/mandates.rs | 6 +- crates/router/src/routes/payment_link.rs | 4 +- crates/router/src/routes/payment_methods.rs | 18 +- crates/router/src/routes/payments.rs | 40 ++--- crates/router/src/routes/payouts.rs | 18 +- crates/router/src/routes/pm_auth.rs | 4 +- crates/router/src/routes/recon.rs | 2 +- crates/router/src/routes/refunds.rs | 12 +- crates/router/src/routes/routing.rs | 34 ++-- crates/router/src/routes/verification.rs | 4 +- crates/router/src/routes/verify_connector.rs | 2 +- crates/router/src/routes/webhook_events.rs | 6 +- crates/router/src/routes/webhooks.rs | 2 +- crates/router/src/services.rs | 5 +- crates/router/src/services/api.rs | 62 ++++--- crates/router/src/services/api/request.rs | 2 +- crates/router/src/services/authentication.rs | 7 +- crates/router/src/types/domain/types.rs | 12 +- .../src/types/storage/payment_attempt.rs | 6 +- crates/router/src/utils.rs | 2 +- crates/router/src/workflows/api_key_expiry.rs | 2 +- .../src/workflows/outgoing_webhook_retry.rs | 10 +- crates/router/tests/cache.rs | 6 +- crates/router/tests/connectors/aci.rs | 15 +- crates/router/tests/connectors/utils.rs | 44 +++-- crates/router/tests/payments.rs | 8 +- crates/router/tests/payments2.rs | 8 +- crates/router/tests/services.rs | 8 +- .../tests/test_module/some_module.rs | 4 +- crates/scheduler/src/consumer.rs | 39 ++-- crates/scheduler/src/errors.rs | 2 + crates/scheduler/src/producer.rs | 10 +- crates/scheduler/src/scheduler.rs | 2 +- crates/scheduler/src/utils.rs | 17 +- crates/storage_impl/src/database/store.rs | 9 +- crates/storage_impl/src/lib.rs | 33 ++-- .../src/payments/payment_attempt.rs | 52 +++--- .../src/payments/payment_intent.rs | 20 +-- .../src/payouts/payout_attempt.rs | 16 +- crates/storage_impl/src/payouts/payouts.rs | 26 +-- 171 files changed, 1336 insertions(+), 1085 deletions(-) diff --git a/config/development.toml b/config/development.toml index 6246fb7fe7c..42c294e337a 100644 --- a/config/development.toml +++ b/config/development.toml @@ -614,5 +614,6 @@ payment_intents = "hyperswitch-payment-intent-events" refunds = "hyperswitch-refund-events" disputes = "hyperswitch-dispute-events" -[multitenancy] -tenants = ["public", "zurich"] \ No newline at end of file +[multitenancy.tenants] +public = { name = "hyperswitch", base_url = "http://localhost:8080"} +zurich = { name = "zurich", base_url = "http://localhost:9090"} \ No newline at end of file diff --git a/crates/analytics/src/api_event/core.rs b/crates/analytics/src/api_event/core.rs index bce24219421..a3185fc056b 100644 --- a/crates/analytics/src/api_event/core.rs +++ b/crates/analytics/src/api_event/core.rs @@ -26,7 +26,7 @@ use crate::{ AnalyticsProvider, }; -////#\[instrument\(skip_all)] +//#[instrument(skip_all)] pub async fn api_events_core( pool: &AnalyticsProvider, req: ApiLogsRequest, @@ -88,7 +88,7 @@ pub async fn get_filters( Ok(res) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_api_event_metrics( pool: &AnalyticsProvider, merchant_id: &str, diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rs index caf8dc632a6..16bec491a4d 100644 --- a/crates/analytics/src/lib.rs +++ b/crates/analytics/src/lib.rs @@ -89,7 +89,7 @@ impl ToString for AnalyticsProvider { } impl AnalyticsProvider { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn get_payment_metrics( &self, metric: &PaymentMetrics, @@ -565,20 +565,20 @@ impl AnalyticsProvider { } } - pub async fn from_conf(config: &AnalyticsConfig) -> Self { + pub async fn from_conf(config: &AnalyticsConfig, tenant: &str) -> Self { match config { - AnalyticsConfig::Sqlx { sqlx } => Self::Sqlx(SqlxClient::from_conf(sqlx).await), + AnalyticsConfig::Sqlx { sqlx } => Self::Sqlx(SqlxClient::from_conf(sqlx, tenant).await), AnalyticsConfig::Clickhouse { clickhouse } => Self::Clickhouse(ClickhouseClient { config: Arc::new(clickhouse.clone()), }), AnalyticsConfig::CombinedCkh { sqlx, clickhouse } => Self::CombinedCkh( - SqlxClient::from_conf(sqlx).await, + SqlxClient::from_conf(sqlx, tenant).await, ClickhouseClient { config: Arc::new(clickhouse.clone()), }, ), AnalyticsConfig::CombinedSqlx { sqlx, clickhouse } => Self::CombinedSqlx( - SqlxClient::from_conf(sqlx).await, + SqlxClient::from_conf(sqlx, tenant).await, ClickhouseClient { config: Arc::new(clickhouse.clone()), }, diff --git a/crates/analytics/src/payments/core.rs b/crates/analytics/src/payments/core.rs index 6ce0eede47d..debc03fc9d5 100644 --- a/crates/analytics/src/payments/core.rs +++ b/crates/analytics/src/payments/core.rs @@ -41,7 +41,7 @@ pub enum TaskType { ), } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_metrics( pool: &AnalyticsProvider, merchant_id: &str, diff --git a/crates/analytics/src/sdk_events/core.rs b/crates/analytics/src/sdk_events/core.rs index d140f4fdb1a..2ffc7f1aed6 100644 --- a/crates/analytics/src/sdk_events/core.rs +++ b/crates/analytics/src/sdk_events/core.rs @@ -22,7 +22,7 @@ use crate::{ AnalyticsProvider, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn sdk_events_core( pool: &AnalyticsProvider, req: SdkEventsRequest, @@ -42,7 +42,7 @@ pub async fn sdk_events_core( .switch() } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_metrics( pool: &AnalyticsProvider, publishable_key: Option<&String>, diff --git a/crates/analytics/src/sqlx.rs b/crates/analytics/src/sqlx.rs index 86782c5f750..9e1c8c40c07 100644 --- a/crates/analytics/src/sqlx.rs +++ b/crates/analytics/src/sqlx.rs @@ -49,11 +49,11 @@ impl Default for SqlxClient { } impl SqlxClient { - pub async fn from_conf(conf: &Database) -> Self { + pub async fn from_conf(conf: &Database, schema: &str) -> Self { let password = &conf.password.peek(); let database_url = format!( - "postgres://{}:{}@{}:{}/{}", - conf.username, password, conf.host, conf.port, conf.dbname + "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", + conf.username, password, conf.host, conf.port, conf.dbname, schema, schema ); #[allow(clippy::expect_used)] let pool = PgPoolOptions::new() diff --git a/crates/diesel_models/src/query/connector_response.rs b/crates/diesel_models/src/query/connector_response.rs index 1401ea39276..952db945ae3 100644 --- a/crates/diesel_models/src/query/connector_response.rs +++ b/crates/diesel_models/src/query/connector_response.rs @@ -14,7 +14,7 @@ use crate::{ }; impl ConnectorResponseNew { - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn insert(self, conn: &PgPooledConn) -> StorageResult { let payment_attempt_update = PaymentAttemptUpdate::ConnectorResponse { authentication_data: self.authentication_data.clone(), @@ -51,7 +51,7 @@ impl ConnectorResponseNew { } impl ConnectorResponse { - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn update( self, conn: &PgPooledConn, @@ -131,7 +131,7 @@ impl ConnectorResponse { connector_response_result } - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn find_by_payment_id_merchant_id_attempt_id( conn: &PgPooledConn, payment_id: &str, diff --git a/crates/diesel_models/src/query/process_tracker.rs b/crates/diesel_models/src/query/process_tracker.rs index d5cb2e488d1..74f23ac0bf7 100644 --- a/crates/diesel_models/src/query/process_tracker.rs +++ b/crates/diesel_models/src/query/process_tracker.rs @@ -13,14 +13,14 @@ use crate::{ }; impl ProcessTrackerNew { - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn insert_process(self, conn: &PgPooledConn) -> StorageResult { generics::generic_insert(conn, self).await } } impl ProcessTracker { - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn update( self, conn: &PgPooledConn, @@ -41,7 +41,7 @@ impl ProcessTracker { } } - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn update_process_status_by_ids( conn: &PgPooledConn, task_ids: Vec, @@ -55,7 +55,7 @@ impl ProcessTracker { .await } - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn find_process_by_id(conn: &PgPooledConn, id: &str) -> StorageResult> { generics::generic_find_by_id_optional::<::Table, _, _>( conn, @@ -64,7 +64,7 @@ impl ProcessTracker { .await } - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn find_processes_by_time_status( conn: &PgPooledConn, time_lower_limit: PrimitiveDateTime, @@ -89,7 +89,7 @@ impl ProcessTracker { .await } - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn find_processes_to_clean( conn: &PgPooledConn, time_lower_limit: PrimitiveDateTime, @@ -118,7 +118,7 @@ impl ProcessTracker { Ok(x) } - //#\[instrument\(skip(conn))] + #[instrument(skip(conn))] pub async fn reinitialize_limbo_processes( conn: &PgPooledConn, ids: Vec, diff --git a/crates/drainer/src/connection.rs b/crates/drainer/src/connection.rs index c539e9a734c..fdc7595d4a8 100644 --- a/crates/drainer/src/connection.rs +++ b/crates/drainer/src/connection.rs @@ -18,14 +18,20 @@ pub async fn redis_connection(conf: &Settings) -> redis_interface::RedisConnecti /// /// Will panic if could not create a db pool #[allow(clippy::expect_used)] -pub async fn diesel_make_pg_pool(database: &Database, _test_transaction: bool) -> PgPool { +pub async fn diesel_make_pg_pool( + database: &Database, + _test_transaction: bool, + schema: &str, +) -> PgPool { let database_url = format!( - "postgres://{}:{}@{}:{}/{}", + "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", database.username, database.password.peek(), database.host, database.port, - database.dbname + database.dbname, + schema, + schema ); let manager = async_bb8_diesel::ConnectionManager::::new(database_url); let pool = bb8::Pool::builder() diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs index 6c02cbaf951..856c13e8fdf 100644 --- a/crates/drainer/src/handler.rs +++ b/crates/drainer/src/handler.rs @@ -1,4 +1,7 @@ -use std::sync::{atomic, Arc}; +use std::{ + collections::HashMap, + sync::{atomic, Arc}, +}; use router_env::tracing::Instrument; use tokio::{ @@ -31,12 +34,12 @@ pub struct HandlerInner { loop_interval: Duration, active_tasks: Arc, conf: DrainerSettings, - store: Arc, + stores: HashMap>, running: Arc, } impl Handler { - pub fn from_conf(conf: DrainerSettings, store: Arc) -> Self { + pub fn from_conf(conf: DrainerSettings, stores: HashMap>) -> Self { let shutdown_interval = Duration::from_millis(conf.shutdown_interval.into()); let loop_interval = Duration::from_millis(conf.loop_interval.into()); @@ -49,7 +52,7 @@ impl Handler { loop_interval, active_tasks, conf, - store, + stores, running, }; @@ -68,21 +71,23 @@ impl Handler { while self.running.load(atomic::Ordering::SeqCst) { metrics::DRAINER_HEALTH.add(&metrics::CONTEXT, 1, &[]); - if self.store.is_stream_available(stream_index).await { - let _task_handle = tokio::spawn( - drainer_handler( - self.store.clone(), - stream_index, - self.conf.max_read_count, - self.active_tasks.clone(), - jobs_picked.clone(), - ) - .in_current_span(), - ); + for store in self.stores.values() { + if store.is_stream_available(stream_index).await { + let _task_handle = tokio::spawn( + drainer_handler( + store.clone(), + stream_index, + self.conf.max_read_count, + self.active_tasks.clone(), + jobs_picked.clone(), + ) + .in_current_span(), + ); + } } stream_index = utils::increment_stream_index( (stream_index, jobs_picked.clone()), - self.store.config.drainer_num_partitions, + self.conf.num_partitions, ) .await; time::sleep(self.loop_interval).await; @@ -116,18 +121,32 @@ impl Handler { pub fn spawn_error_handlers(&self, tx: mpsc::Sender<()>) -> errors::DrainerResult<()> { let (redis_error_tx, redis_error_rx) = oneshot::channel(); + let mut redis_conn_clone = None; + for store in self.stores.values() { + redis_conn_clone = Some(store.redis_conn.clone()); + } + match redis_conn_clone { + None => { + logger::error!("No redis connection found"); + return Err(errors::DrainerError::UnexpectedError( + "No redis connection found".to_string(), + ) + .into()); + } + Some(redis_conn_clone) => { + // Spawn a task to monitor if redis is down or not + let _task_handle = tokio::spawn( + async move { redis_conn_clone.on_error(redis_error_tx).await } + .in_current_span(), + ); - let redis_conn_clone = self.store.redis_conn.clone(); - - // Spawn a task to monitor if redis is down or not - let _task_handle = tokio::spawn( - async move { redis_conn_clone.on_error(redis_error_tx).await }.in_current_span(), - ); - - //Spawns a task to send shutdown signal if redis goes down - let _task_handle = tokio::spawn(redis_error_receiver(redis_error_rx, tx).in_current_span()); + //Spawns a task to send shutdown signal if redis goes down + let _task_handle = + tokio::spawn(redis_error_receiver(redis_error_rx, tx).in_current_span()); - Ok(()) + Ok(()) + } + } } } @@ -179,7 +198,7 @@ async fn drainer_handler( }) } -//#\[instrument\(skip_all, fields(global_id, request_id, session_id))] +#[instrument(skip_all, fields(global_id, request_id, session_id))] async fn drainer( store: Arc, max_read_count: u64, @@ -208,7 +227,10 @@ async fn drainer( }; // parse_stream_entries returns error if no entries is found, handle it - let entries = utils::parse_stream_entries(&stream_read, stream_name)?; + let entries = utils::parse_stream_entries( + &stream_read, + store.redis_conn.get_tenant_key(stream_name).as_str(), + )?; let read_count = entries.len(); metrics::JOBS_PICKED_PER_STREAM.add( diff --git a/crates/drainer/src/health_check.rs b/crates/drainer/src/health_check.rs index a92c9fe3169..558f3847a95 100644 --- a/crates/drainer/src/health_check.rs +++ b/crates/drainer/src/health_check.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; use actix_web::{web, Scope}; use async_bb8_diesel::{AsyncConnection, AsyncRunQueryDsl}; @@ -8,9 +8,9 @@ use error_stack::ResultExt; use router_env::{instrument, logger, tracing}; use crate::{ - connection::{pg_connection, redis_connection}, + connection::pg_connection, errors::HealthCheckError, - services::{self, Store}, + services::{self, log_and_return_error_response, Store}, Settings, }; @@ -20,43 +20,53 @@ pub const TEST_STREAM_DATA: &[(&str, &str)] = &[("data", "sample_data")]; pub struct Health; impl Health { - pub fn server(conf: Settings, store: Arc) -> Scope { + pub fn server(conf: Settings, stores: HashMap>) -> Scope { web::scope("health") .app_data(web::Data::new(conf)) - .app_data(web::Data::new(store)) + .app_data(web::Data::new(stores)) .service(web::resource("").route(web::get().to(health))) .service(web::resource("/ready").route(web::get().to(deep_health_check))) } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn health() -> impl actix_web::Responder { logger::info!("Drainer health was called"); actix_web::HttpResponse::Ok().body("Drainer health is good") } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn deep_health_check( conf: web::Data, - store: web::Data>, + stores: web::Data>>, ) -> impl actix_web::Responder { - match deep_health_check_func(conf, store).await { - Ok(response) => services::http_response_json( - serde_json::to_string(&response) + let mut deep_health_res = HashMap::new(); + for (tenant, store) in stores.iter() { + logger::info!("Tenant: {:?}", tenant); + + let response = match deep_health_check_func(conf.clone(), store).await { + Ok(response) => serde_json::to_string(&response) .map_err(|err| { logger::error!(serialization_error=?err); }) .unwrap_or_default(), - ), - - Err(err) => services::log_and_return_error_response(err), + Err(err) => return log_and_return_error_response(err), + }; + deep_health_res.insert(tenant.clone(), response); } + services::http_response_json( + serde_json::to_string(&deep_health_res) + .map_err(|err| { + logger::error!(serialization_error=?err); + }) + .unwrap_or_default(), + ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn deep_health_check_func( conf: web::Data, - store: web::Data>, + store: &Arc, ) -> Result> { logger::info!("Deep health check was called"); @@ -146,8 +156,11 @@ impl HealthCheckInterface for Store { Ok(()) } - async fn health_check_redis(&self, conf: &Settings) -> CustomResult<(), HealthCheckRedisError> { - let redis_conn = redis_connection(conf).await; + async fn health_check_redis( + &self, + _conf: &Settings, + ) -> CustomResult<(), HealthCheckRedisError> { + let redis_conn = self.redis_conn.clone(); redis_conn .serialize_and_set_key_with_expiry("test_key", "test_value", 30) @@ -181,15 +194,14 @@ impl HealthCheckInterface for Store { logger::debug!("Stream append succeeded"); - let output = self - .redis_conn + let output = redis_conn .stream_read_entries(TEST_STREAM_NAME, "0-0", Some(10)) .await .change_context(HealthCheckRedisError::StreamReadFailed)?; logger::debug!("Stream read succeeded"); let (_, id_to_trim) = output - .get(TEST_STREAM_NAME) + .get(&redis_conn.get_tenant_key(TEST_STREAM_NAME)) .and_then(|entries| { entries .last() diff --git a/crates/drainer/src/lib.rs b/crates/drainer/src/lib.rs index 56f2db0907e..c72981ad12c 100644 --- a/crates/drainer/src/lib.rs +++ b/crates/drainer/src/lib.rs @@ -10,7 +10,7 @@ pub mod settings; mod stream; mod types; mod utils; -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; mod secrets_transformers; use actix_web::dev::Server; @@ -30,8 +30,11 @@ use crate::{ connection::pg_connection, services::Store, settings::DrainerSettings, types::StreamData, }; -pub async fn start_drainer(store: Arc, conf: DrainerSettings) -> errors::DrainerResult<()> { - let drainer_handler = handler::Handler::from_conf(conf, store); +pub async fn start_drainer( + stores: HashMap>, + conf: DrainerSettings, +) -> errors::DrainerResult<()> { + let drainer_handler = handler::Handler::from_conf(conf, stores); let (tx, rx) = mpsc::channel::<()>(1); @@ -59,11 +62,11 @@ pub async fn start_drainer(store: Arc, conf: DrainerSettings) -> errors:: pub async fn start_web_server( conf: Settings, - store: Arc, + stores: HashMap>, ) -> Result { let server = conf.server.clone(); let web_server = actix_web::HttpServer::new(move || { - actix_web::App::new().service(health_check::Health::server(conf.clone(), store.clone())) + actix_web::App::new().service(health_check::Health::server(conf.clone(), stores.clone())) }) .bind((server.host.as_str(), server.port))? .run(); diff --git a/crates/drainer/src/main.rs b/crates/drainer/src/main.rs index 64e66619d74..030b8209116 100644 --- a/crates/drainer/src/main.rs +++ b/crates/drainer/src/main.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use drainer::{ errors::DrainerResult, logger::logger, services, settings, start_drainer, start_web_server, }; @@ -17,7 +19,11 @@ async fn main() -> DrainerResult<()> { let state = settings::AppState::new(conf.clone()).await; - let store = std::sync::Arc::new(services::Store::new(&state.conf, false).await); + let mut stores = HashMap::new(); + for tenant in conf.multitenancy.get_tenant_names() { + let store = std::sync::Arc::new(services::Store::new(&state.conf, false, &tenant).await); + stores.insert(tenant.clone(), store); + } #[cfg(feature = "vergen")] println!("Starting drainer (Version: {})", router_env::git_tag!()); @@ -29,9 +35,12 @@ async fn main() -> DrainerResult<()> { ); #[allow(clippy::expect_used)] - let web_server = Box::pin(start_web_server(state.conf.as_ref().clone(), store.clone())) - .await - .expect("Failed to create the server"); + let web_server = Box::pin(start_web_server( + state.conf.as_ref().clone(), + stores.clone(), + )) + .await + .expect("Failed to create the server"); tokio::spawn( async move { @@ -44,7 +53,7 @@ async fn main() -> DrainerResult<()> { logger::debug!(startup_config=?conf); logger::info!("Drainer started [{:?}] [{:?}]", conf.drainer, conf.log); - start_drainer(store.clone(), conf.drainer).await?; + start_drainer(stores.clone(), conf.drainer).await?; Ok(()) } diff --git a/crates/drainer/src/secrets_transformers.rs b/crates/drainer/src/secrets_transformers.rs index 4ffb584a152..0582ccd798b 100644 --- a/crates/drainer/src/secrets_transformers.rs +++ b/crates/drainer/src/secrets_transformers.rs @@ -45,5 +45,6 @@ pub async fn fetch_raw_secrets( drainer: conf.drainer, encryption_management: conf.encryption_management, secrets_management: conf.secrets_management, + multitenancy: conf.multitenancy, } } diff --git a/crates/drainer/src/services.rs b/crates/drainer/src/services.rs index 9e0165548a0..2cfd2d14fed 100644 --- a/crates/drainer/src/services.rs +++ b/crates/drainer/src/services.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use actix_web::{body, HttpResponse, ResponseError}; use error_stack::Report; +use redis_interface::RedisConnectionPool; use crate::{ connection::{diesel_make_pg_pool, PgPool}, @@ -11,7 +12,7 @@ use crate::{ #[derive(Clone)] pub struct Store { pub master_pool: PgPool, - pub redis_conn: Arc, + pub redis_conn: Arc, pub config: StoreConfig, pub request_id: Option, } @@ -28,11 +29,16 @@ impl Store { /// Panics if there is a failure while obtaining the HashiCorp client using the provided configuration. /// This panic indicates a critical failure in setting up external services, and the application cannot proceed without a valid HashiCorp client. /// - pub async fn new(config: &crate::Settings, test_transaction: bool) -> Self { + pub async fn new(config: &crate::Settings, test_transaction: bool, tenant: &str) -> Self { + let redis_conn = crate::connection::redis_connection(config).await; Self { - master_pool: diesel_make_pg_pool(config.master_database.get_inner(), test_transaction) - .await, - redis_conn: Arc::new(crate::connection::redis_connection(config).await), + master_pool: diesel_make_pg_pool( + config.master_database.get_inner(), + test_transaction, + tenant, + ) + .await, + redis_conn: Arc::new(RedisConnectionPool::clone(&redis_conn, tenant)), config: StoreConfig { drainer_stream_name: config.drainer.stream_name.clone(), drainer_num_partitions: config.drainer.num_partitions, diff --git a/crates/drainer/src/settings.rs b/crates/drainer/src/settings.rs index e68ede9e8b2..ffafb6c0b80 100644 --- a/crates/drainer/src/settings.rs +++ b/crates/drainer/src/settings.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, sync::Arc}; +use std::{collections::HashMap, path::PathBuf, sync::Arc}; use common_utils::ext_traits::ConfigExt; use config::{Environment, File}; @@ -73,6 +73,7 @@ pub struct Settings { pub drainer: DrainerSettings, pub encryption_management: EncryptionManagementConfig, pub secrets_management: SecretsManagementConfig, + pub multitenancy: Multitenancy, } #[derive(Debug, Deserialize, Clone)] @@ -97,6 +98,32 @@ pub struct DrainerSettings { pub loop_interval: u32, // in milliseconds } +#[derive(Debug, Deserialize, Clone, Default)] +pub struct Multitenancy { + pub tenants: TenantConfig, +} +impl Multitenancy { + pub fn get_tenants(&self) -> HashMap { + self.tenants.0.clone() + } + pub fn get_tenant_names(&self) -> Vec { + self.tenants.0.keys().cloned().collect() + } + pub fn get_tenant(&self, tenant_id: &str) -> Option<&Tenant> { + self.tenants.0.get(tenant_id) + } +} + +#[derive(Debug, Deserialize, Clone, Default)] +#[serde(transparent)] +pub struct TenantConfig(pub HashMap); + +#[derive(Debug, Deserialize, Clone, Default)] +pub struct Tenant { + pub name: String, + pub base_url: String, +} + #[derive(Debug, Deserialize, Clone)] #[serde(default)] pub struct Server { diff --git a/crates/drainer/src/stream.rs b/crates/drainer/src/stream.rs index 5e562a55177..98aa7d7307d 100644 --- a/crates/drainer/src/stream.rs +++ b/crates/drainer/src/stream.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use redis_interface as redis; -use router_env::{logger, tracing}; +use router_env::logger; use crate::{errors, metrics, Store}; diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index c191cf58d76..516a9e5117a 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -31,7 +31,14 @@ use crate::{ }; impl super::RedisConnectionPool { - //#\[instrument\(level = "DEBUG", skip(self))] + pub fn get_tenant_key(&self, key: &str) -> String { + if self.tenant.is_empty() { + key.to_string() + } else { + format!("{}:{}", self.tenant, key) + } + } + #[instrument(level = "DEBUG", skip(self))] pub async fn set_key(&self, key: &str, value: V) -> CustomResult<(), errors::RedisError> where V: TryInto + Debug + Send + Sync, @@ -39,7 +46,7 @@ impl super::RedisConnectionPool { { self.pool .set( - key, + self.get_tenant_key(key), value, Some(Expiration::EX(self.config.default_ttl.into())), None, @@ -63,7 +70,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn serialize_and_set_key_if_not_exist( &self, key: &str, @@ -80,7 +87,7 @@ impl super::RedisConnectionPool { .await } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn serialize_and_set_key( &self, key: &str, @@ -96,7 +103,7 @@ impl super::RedisConnectionPool { self.set_key(key, serialized.as_slice()).await } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn serialize_and_set_key_with_expiry( &self, key: &str, @@ -112,7 +119,7 @@ impl super::RedisConnectionPool { self.pool .set( - key, + self.get_tenant_key(key), serialized.as_slice(), Some(Expiration::EX(seconds)), None, @@ -122,29 +129,29 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetExFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn get_key(&self, key: &str) -> CustomResult where V: FromRedis + Unpin + Send + 'static, { self.pool - .get(key) + .get(self.get_tenant_key(key)) .await .change_context(errors::RedisError::GetFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn exists(&self, key: &str) -> CustomResult where V: Into + Unpin + Send + 'static, { self.pool - .exists(key) + .exists(self.get_tenant_key(key)) .await .change_context(errors::RedisError::GetFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn get_and_deserialize_key( &self, key: &str, @@ -162,15 +169,15 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::JsonDeserializationFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn delete_key(&self, key: &str) -> CustomResult { self.pool - .del(key) + .del(self.get_tenant_key(key)) .await .change_context(errors::RedisError::DeleteFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn set_key_with_expiry( &self, key: &str, @@ -182,12 +189,18 @@ impl super::RedisConnectionPool { V::Error: Into + Send + Sync, { self.pool - .set(key, value, Some(Expiration::EX(seconds)), None, false) + .set( + self.get_tenant_key(key), + value, + Some(Expiration::EX(seconds)), + None, + false, + ) .await .change_context(errors::RedisError::SetExFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn set_key_if_not_exists_with_expiry( &self, key: &str, @@ -200,7 +213,7 @@ impl super::RedisConnectionPool { { self.pool .set( - key, + self.get_tenant_key(key), value, Some(Expiration::EX( seconds.unwrap_or(self.config.default_ttl.into()), @@ -212,31 +225,31 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::SetFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn set_expiry( &self, key: &str, seconds: i64, ) -> CustomResult<(), errors::RedisError> { self.pool - .expire(key, seconds) + .expire(self.get_tenant_key(key), seconds) .await .change_context(errors::RedisError::SetExpiryFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn set_expire_at( &self, key: &str, timestamp: i64, ) -> CustomResult<(), errors::RedisError> { self.pool - .expire_at(key, timestamp) + .expire_at(self.get_tenant_key(key), timestamp) .await .change_context(errors::RedisError::SetExpiryFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn set_hash_fields( &self, key: &str, @@ -249,7 +262,7 @@ impl super::RedisConnectionPool { { let output: Result<(), _> = self .pool - .hset(key, values) + .hset(self.get_tenant_key(key), values) .await .change_context(errors::RedisError::SetHashFailed); // setting expiry for the key @@ -260,7 +273,7 @@ impl super::RedisConnectionPool { .await } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn set_hash_field_if_not_exist( &self, key: &str, @@ -274,7 +287,7 @@ impl super::RedisConnectionPool { { let output: Result = self .pool - .hsetnx(key, field, value) + .hsetnx(self.get_tenant_key(key), field, value) .await .change_context(errors::RedisError::SetHashFieldFailed); @@ -287,7 +300,7 @@ impl super::RedisConnectionPool { .await } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn serialize_and_set_hash_field_if_not_exist( &self, key: &str, @@ -306,7 +319,7 @@ impl super::RedisConnectionPool { .await } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn serialize_and_set_multiple_hash_field_if_not_exist( &self, kv: &[(&str, V)], @@ -326,7 +339,7 @@ impl super::RedisConnectionPool { Ok(hsetnx) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn hscan( &self, key: &str, @@ -336,7 +349,7 @@ impl super::RedisConnectionPool { Ok(self .pool .next() - .hscan::<&str, &str>(key, pattern, count) + .hscan::<&str, &str>(&self.get_tenant_key(key), pattern, count) .filter_map(|value| async move { match value { Ok(mut v) => { @@ -357,7 +370,7 @@ impl super::RedisConnectionPool { .await) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn hscan_and_deserialize( &self, key: &str, @@ -377,7 +390,7 @@ impl super::RedisConnectionPool { .collect()) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn get_hash_field( &self, key: &str, @@ -387,12 +400,12 @@ impl super::RedisConnectionPool { V: FromRedis + Unpin + Send + 'static, { self.pool - .hget(key, field) + .hget(self.get_tenant_key(key), field) .await .change_context(errors::RedisError::GetHashFieldFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn get_hash_field_and_deserialize( &self, key: &str, @@ -413,7 +426,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::JsonDeserializationFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn sadd( &self, key: &str, @@ -424,12 +437,12 @@ impl super::RedisConnectionPool { V::Error: Into + Send, { self.pool - .sadd(key, members) + .sadd(self.get_tenant_key(key), members) .await .change_context(errors::RedisError::SetAddMembersFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn stream_append_entry( &self, stream: &str, @@ -441,12 +454,12 @@ impl super::RedisConnectionPool { F::Error: Into + Send + Sync, { self.pool - .xadd(stream, false, None, entry_id, fields) + .xadd(self.get_tenant_key(stream), false, None, entry_id, fields) .await .change_context(errors::RedisError::StreamAppendFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn stream_delete_entries( &self, stream: &str, @@ -456,12 +469,12 @@ impl super::RedisConnectionPool { Ids: Into + Debug + Send + Sync, { self.pool - .xdel(stream, ids) + .xdel(self.get_tenant_key(stream), ids) .await .change_context(errors::RedisError::StreamDeleteFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn stream_trim_entries( &self, stream: &str, @@ -472,12 +485,12 @@ impl super::RedisConnectionPool { C::Error: Into + Send + Sync, { self.pool - .xtrim(stream, xcap) + .xtrim(self.get_tenant_key(stream), xcap) .await .change_context(errors::RedisError::StreamTrimFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn stream_acknowledge_entries( &self, stream: &str, @@ -488,23 +501,35 @@ impl super::RedisConnectionPool { Ids: Into + Debug + Send + Sync, { self.pool - .xack(stream, group, ids) + .xack(self.get_tenant_key(stream), group, ids) .await .change_context(errors::RedisError::StreamAcknowledgeFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] - pub async fn stream_get_length(&self, stream: K) -> CustomResult - where - K: Into + Debug + Send + Sync, - { + #[instrument(level = "DEBUG", skip(self))] + pub async fn stream_get_length(&self, stream: &str) -> CustomResult { self.pool - .xlen(stream) + .xlen(self.get_tenant_key(stream)) .await .change_context(errors::RedisError::GetLengthFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + pub fn get_tenant_keys(&self, keys: K) -> MultipleKeys + where + K: Into + Debug + Send + Sync, + { + let multiple_keys: MultipleKeys = keys.into(); + let res = multiple_keys + .inner() + .iter() + .filter_map(|key| key.as_str()) + .map(|k| self.get_tenant_key(k)) + .map(|i| RedisKey::from(i)) + .collect::>(); + MultipleKeys::from(res) + } + + #[instrument(level = "DEBUG", skip(self))] pub async fn stream_read_entries( &self, streams: K, @@ -515,11 +540,12 @@ impl super::RedisConnectionPool { K: Into + Debug + Send + Sync, Ids: Into + Debug + Send + Sync, { + let strms = self.get_tenant_keys(streams); self.pool .xread_map( Some(read_count.unwrap_or(self.config.default_stream_read_count)), None, - streams, + strms, ids, ) .await @@ -531,7 +557,7 @@ impl super::RedisConnectionPool { }) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn stream_read_with_options( &self, streams: K, @@ -547,10 +573,22 @@ impl super::RedisConnectionPool { match group { Some((group_name, consumer_name)) => { self.pool - .xreadgroup_map(group_name, consumer_name, count, block, false, streams, ids) + .xreadgroup_map( + group_name, + consumer_name, + count, + block, + false, + self.get_tenant_keys(streams), + ids, + ) + .await + } + None => { + self.pool + .xread_map(count, block, self.get_tenant_keys(streams), ids) .await } - None => self.pool.xread_map(count, block, streams, ids).await, } .map_err(|err| match err.kind() { RedisErrorKind::NotFound | RedisErrorKind::Parse => { @@ -562,7 +600,7 @@ impl super::RedisConnectionPool { // Consumer Group API - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn consumer_group_create( &self, stream: &str, @@ -578,25 +616,25 @@ impl super::RedisConnectionPool { } self.pool - .xgroup_create(stream, group, id, true) + .xgroup_create(self.get_tenant_key(stream), group, id, true) .await .change_context(errors::RedisError::ConsumerGroupCreateFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn consumer_group_destroy( &self, stream: &str, group: &str, ) -> CustomResult { self.pool - .xgroup_destroy(stream, group) + .xgroup_destroy(self.get_tenant_key(stream), group) .await .change_context(errors::RedisError::ConsumerGroupDestroyFailed) } // the number of pending messages that the consumer had before it was deleted - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn consumer_group_delete_consumer( &self, stream: &str, @@ -604,12 +642,12 @@ impl super::RedisConnectionPool { consumer: &str, ) -> CustomResult { self.pool - .xgroup_delconsumer(stream, group, consumer) + .xgroup_delconsumer(self.get_tenant_key(stream), group, consumer) .await .change_context(errors::RedisError::ConsumerGroupRemoveConsumerFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn consumer_group_set_last_id( &self, stream: &str, @@ -617,12 +655,12 @@ impl super::RedisConnectionPool { id: &RedisEntryId, ) -> CustomResult { self.pool - .xgroup_setid(stream, group, id) + .xgroup_setid(self.get_tenant_key(stream), group, id) .await .change_context(errors::RedisError::ConsumerGroupSetIdFailed) } - //#\[instrument\(level = "DEBUG", skip(self))] + #[instrument(level = "DEBUG", skip(self))] pub async fn consumer_group_set_message_owner( &self, stream: &str, @@ -637,7 +675,7 @@ impl super::RedisConnectionPool { { self.pool .xclaim( - stream, + self.get_tenant_key(stream), group, consumer, min_idle_time, diff --git a/crates/redis_interface/src/lib.rs b/crates/redis_interface/src/lib.rs index 0ab1ea394c9..fb3c4cd6082 100644 --- a/crates/redis_interface/src/lib.rs +++ b/crates/redis_interface/src/lib.rs @@ -31,10 +31,11 @@ use router_env::logger; pub use self::types::*; pub struct RedisConnectionPool { - pub pool: fred::prelude::RedisPool, - config: RedisConfig, - pub subscriber: SubscriberClient, - pub publisher: RedisClient, + pub pool: Arc, + pub tenant: String, + pub config: Arc, + pub subscriber: Arc, + pub publisher: Arc, pub is_redis_available: Arc, } @@ -167,14 +168,24 @@ impl RedisConnectionPool { let config = RedisConfig::from(conf); Ok(Self { - pool, - config, + pool: Arc::new(pool), + config: Arc::new(config), is_redis_available: Arc::new(atomic::AtomicBool::new(true)), - subscriber, - publisher, + subscriber: Arc::new(subscriber), + publisher: Arc::new(publisher), + tenant: String::default(), }) } - + pub fn clone(&self, tenant: &str) -> Self { + Self { + pool: Arc::clone(&self.pool), + tenant: tenant.to_string(), + config: Arc::clone(&self.config), + subscriber: Arc::clone(&self.subscriber), + publisher: Arc::clone(&self.publisher), + is_redis_available: Arc::clone(&self.is_redis_available), + } + } pub async fn on_error(&self, tx: tokio::sync::oneshot::Sender<()>) { use futures::StreamExt; use tokio_stream::wrappers::BroadcastStream; @@ -212,7 +223,7 @@ impl RedisConnectionPool { } } -struct RedisConfig { +pub struct RedisConfig { default_ttl: u32, default_stream_read_count: u64, default_hash_ttl: u32, diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs index b12f3bd0abf..eefe3513b14 100644 --- a/crates/router/src/bin/scheduler.rs +++ b/crates/router/src/bin/scheduler.rs @@ -12,8 +12,7 @@ use router::{ errors::{self, CustomResult}, health_check::HealthCheckInterface, }, - logger, - routes, + logger, routes, services::{self, api}, workflows, }; @@ -76,21 +75,21 @@ async fn main() -> CustomResult<(), ProcessTrackerError> { [router_env::service_name!()], ); - // #[allow(clippy::expect_used)] - // let web_server = Box::pin(start_web_server( - // state.clone(), - // scheduler_flow_str.to_string(), - // )) - // .await - // .expect("Failed to create the server"); - - // let _task_handle = tokio::spawn( - // async move { - // let _ = web_server.await; - // logger::error!("The health check probe stopped working!"); - // } - // .in_current_span(), - // ); + #[allow(clippy::expect_used)] + let web_server = Box::pin(start_web_server( + state.clone(), + scheduler_flow_str.to_string(), + )) + .await + .expect("Failed to create the server"); + + let _task_handle = tokio::spawn( + async move { + let _ = web_server.await; + logger::error!("The health check probe stopped working!"); + } + .in_current_span(), + ); logger::debug!(startup_config=?state.conf); @@ -137,12 +136,12 @@ impl Health { } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn health() -> impl actix_web::Responder { logger::info!("Scheduler health was called"); actix_web::HttpResponse::Ok().body("Scheduler health is good") } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn deep_health_check( state: web::Data, service: web::Data, @@ -152,7 +151,19 @@ pub async fn deep_health_check( let app_state = Arc::clone(&state.into_inner()); let service_name = service.into_inner(); for (tenant, _) in stores { - let session_state = routes::SessionState::from_app_state(app_state.clone(), &tenant); + let session_state_res = + routes::SessionState::from_app_state(app_state.clone(), &tenant, || { + errors::ApiErrorResponse::MissingRequiredField { + field_name: "tenant_id", + } + .into() + }); + let session_state = match session_state_res { + Ok(state) => state, + Err(err) => { + return api::log_and_return_error_response(err); + } + }; let report = deep_health_check_func(session_state, &service_name).await; match report { Ok(response) => { @@ -178,7 +189,7 @@ pub async fn deep_health_check( .unwrap_or_default(), ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn deep_health_check_func( state: routes::SessionState, service: &str, @@ -330,7 +341,11 @@ async fn start_scheduler( Arc::new(scheduler_settings), channel, WorkflowRunner {}, - |state, tenant| routes::SessionState::from_app_state(Arc::new(state.clone()), tenant), + |state, tenant| { + routes::SessionState::from_app_state(Arc::new(state.clone()), tenant, || { + errors::ProcessTrackerError::TenantNotFound.into() + }) + }, ) .await } diff --git a/crates/router/src/compatibility/stripe/customers.rs b/crates/router/src/compatibility/stripe/customers.rs index 4b8ddc6212f..e7b194fb35c 100644 --- a/crates/router/src/compatibility/stripe/customers.rs +++ b/crates/router/src/compatibility/stripe/customers.rs @@ -11,7 +11,7 @@ use crate::{ types::api::{customers as customer_types, payment_methods}, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersCreate))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersCreate))] pub async fn customer_create( state: web::Data, qs_config: web::Data, @@ -51,7 +51,7 @@ pub async fn customer_create( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieve))] pub async fn customer_retrieve( state: web::Data, req: HttpRequest, @@ -85,7 +85,7 @@ pub async fn customer_retrieve( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersUpdate))] pub async fn customer_update( state: web::Data, qs_config: web::Data, @@ -128,7 +128,7 @@ pub async fn customer_update( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersDelete))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersDelete))] pub async fn customer_delete( state: web::Data, req: HttpRequest, @@ -162,7 +162,7 @@ pub async fn customer_delete( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] +#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] pub async fn list_customer_payment_method_api( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs index a7c54ef8f34..4ef1001bb07 100644 --- a/crates/router/src/compatibility/stripe/errors.rs +++ b/crates/router/src/compatibility/stripe/errors.rs @@ -262,6 +262,8 @@ pub enum StripeErrorCode { CurrencyConversionFailed, #[error(error_type = StripeErrorType::InvalidRequestError, code = "IR_25", message = "Cannot delete the default payment method")] PaymentMethodDeleteFailed, + #[error(error_type = StripeErrorType::InvalidRequestError, code = "IR_27", message = "Invalid tenant")] + InvalidTenant, // [#216]: https://github.com/juspay/hyperswitch/issues/216 // Implement the remaining stripe error codes @@ -635,6 +637,7 @@ impl From for StripeErrorCode { errors::ApiErrorResponse::InvalidWalletToken { wallet_name } => { Self::InvalidWalletToken { wallet_name } } + errors::ApiErrorResponse::InvalidTenant { tenant_id } => Self::InvalidTenant, } } } @@ -706,7 +709,8 @@ impl actix_web::ResponseError for StripeErrorCode { | Self::PaymentMethodUnactivated | Self::InvalidConnectorConfiguration { .. } | Self::CurrencyConversionFailed - | Self::PaymentMethodDeleteFailed => StatusCode::BAD_REQUEST, + | Self::PaymentMethodDeleteFailed + | Self::InvalidTenant => StatusCode::BAD_REQUEST, Self::RefundFailed | Self::PayoutFailed | Self::PaymentLinkNotFound diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs index d6f18dd11be..25fe8e98aa2 100644 --- a/crates/router/src/compatibility/stripe/payment_intents.rs +++ b/crates/router/src/compatibility/stripe/payment_intents.rs @@ -13,7 +13,7 @@ use crate::{ types::api as api_types, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] pub async fn payment_intents_create( state: web::Data, qs_config: web::Data, @@ -77,7 +77,7 @@ pub async fn payment_intents_create( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] pub async fn payment_intents_retrieve( state: web::Data, req: HttpRequest, @@ -137,7 +137,7 @@ pub async fn payment_intents_retrieve( )) .await } -//#\[instrument\(skip_all, fields(flow))] +#[instrument(skip_all, fields(flow))] pub async fn payment_intents_retrieve_with_gateway_creds( state: web::Data, qs_config: web::Data, @@ -208,7 +208,7 @@ pub async fn payment_intents_retrieve_with_gateway_creds( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsUpdate))] pub async fn payment_intents_update( state: web::Data, qs_config: web::Data, @@ -275,7 +275,7 @@ pub async fn payment_intents_update( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] pub async fn payment_intents_confirm( state: web::Data, qs_config: web::Data, @@ -348,7 +348,7 @@ pub async fn payment_intents_confirm( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] pub async fn payment_intents_capture( state: web::Data, qs_config: web::Data, @@ -410,7 +410,7 @@ pub async fn payment_intents_capture( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] pub async fn payment_intents_cancel( state: web::Data, qs_config: web::Data, @@ -475,7 +475,7 @@ pub async fn payment_intents_cancel( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn payment_intent_list( state: web::Data, diff --git a/crates/router/src/compatibility/stripe/refunds.rs b/crates/router/src/compatibility/stripe/refunds.rs index bca03334019..da68e79e422 100644 --- a/crates/router/src/compatibility/stripe/refunds.rs +++ b/crates/router/src/compatibility/stripe/refunds.rs @@ -11,7 +11,7 @@ use crate::{ types::api::refunds as refund_types, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsCreate, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsCreate, payment_id))] pub async fn refund_create( state: web::Data, qs_config: web::Data, @@ -56,7 +56,7 @@ pub async fn refund_create( )) .await } -//#\[instrument\(skip_all, fields(flow))] +#[instrument(skip_all, fields(flow))] pub async fn refund_retrieve_with_gateway_creds( state: web::Data, qs_config: web::Data, @@ -106,7 +106,7 @@ pub async fn refund_retrieve_with_gateway_creds( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsRetrieveForceSync))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsRetrieveForceSync))] pub async fn refund_retrieve( state: web::Data, req: HttpRequest, @@ -148,7 +148,7 @@ pub async fn refund_retrieve( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsUpdate))] pub async fn refund_update( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rs index 79e268db031..60627ee5642 100644 --- a/crates/router/src/compatibility/stripe/setup_intents.rs +++ b/crates/router/src/compatibility/stripe/setup_intents.rs @@ -15,7 +15,7 @@ use crate::{ types::api as api_types, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCreate))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate))] pub async fn setup_intents_create( state: web::Data, qs_config: web::Data, @@ -78,7 +78,7 @@ pub async fn setup_intents_create( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsRetrieveForceSync))] pub async fn setup_intents_retrieve( state: web::Data, req: HttpRequest, @@ -138,7 +138,7 @@ pub async fn setup_intents_retrieve( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsUpdate))] pub async fn setup_intents_update( state: web::Data, qs_config: web::Data, @@ -211,7 +211,7 @@ pub async fn setup_intents_update( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsConfirm))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm))] pub async fn setup_intents_confirm( state: web::Data, qs_config: web::Data, diff --git a/crates/router/src/compatibility/wrap.rs b/crates/router/src/compatibility/wrap.rs index 04db00b99f3..b6012c425a5 100644 --- a/crates/router/src/compatibility/wrap.rs +++ b/crates/router/src/compatibility/wrap.rs @@ -15,7 +15,7 @@ use crate::{ services::{self, api, authentication as auth, logger}, }; -//#\[instrument\(skip(request, payload, state, func, api_authentication))] +#[instrument(skip(request, payload, state, func, api_authentication))] pub async fn compatibility_api_wrap<'a, 'b, U, T, Q, F, Fut, S, E, E2>( flow: impl router_env::types::FlowMetric, state: Arc, diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs index 7ade016856c..9d8be21724c 100644 --- a/crates/router/src/configs/defaults.rs +++ b/crates/router/src/configs/defaults.rs @@ -11,7 +11,7 @@ impl Default for super::settings::Server { workers: num_cpus::get_physical(), host: "localhost".into(), request_body_limit: 16 * 1024, // POST request body is limited to 16KiB - base_url: "http://localhost:8080".into(), + // base_url: "http://localhost:8080".into(), shutdown_timeout: 30, } } diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index 978e51a933b..b37d2c02f20 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -124,7 +124,29 @@ pub struct Settings { #[derive(Debug, Deserialize, Clone, Default)] pub struct Multitenancy { - pub tenants: Vec, + pub tenants: TenantConfig, +} + +impl Multitenancy { + pub fn get_tenants(&self) -> HashMap { + self.tenants.0.clone() + } + pub fn get_tenant_names(&self) -> Vec { + self.tenants.0.keys().cloned().collect() + } + pub fn get_tenant(&self, tenant_id: &str) -> Option<&Tenant> { + self.tenants.0.get(tenant_id) + } +} + +#[derive(Debug, Deserialize, Clone, Default)] +#[serde(transparent)] +pub struct TenantConfig(pub HashMap); + +#[derive(Debug, Deserialize, Clone, Default)] +pub struct Tenant { + pub name: String, + pub base_url: String, } #[derive(Debug, Deserialize, Clone, Default)] @@ -438,7 +460,7 @@ pub struct Server { pub workers: usize, pub host: String, pub request_body_limit: usize, - pub base_url: String, + // pub base_url: String, pub shutdown_timeout: u64, } diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs index 05b6972328a..481eba0df70 100644 --- a/crates/router/src/connector/adyen.rs +++ b/crates/router/src/connector/adyen.rs @@ -1146,7 +1146,7 @@ impl services::ConnectorIntegration, @@ -1251,7 +1251,7 @@ impl services::ConnectorIntegration, @@ -1361,7 +1361,7 @@ impl Ok(Some(request)) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn handle_response( &self, data: &types::PayoutsRouterData, @@ -1484,7 +1484,7 @@ impl services::ConnectorIntegration, @@ -1597,7 +1597,7 @@ impl services::ConnectorIntegration, diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs index fb156a7a5cf..70c08a31d73 100644 --- a/crates/router/src/connector/stripe.rs +++ b/crates/router/src/connector/stripe.rs @@ -1331,7 +1331,7 @@ impl services::ConnectorIntegration, @@ -1440,7 +1440,7 @@ impl services::ConnectorIntegration, @@ -1596,7 +1596,7 @@ impl )) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn handle_response( &self, data: &types::UploadFileRouterData, @@ -1706,7 +1706,7 @@ impl )) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn handle_response( &self, data: &types::RetrieveFileRouterData, @@ -1842,7 +1842,7 @@ impl Ok(Some(request)) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn handle_response( &self, data: &types::SubmitEvidenceRouterData, diff --git a/crates/router/src/connector/wise.rs b/crates/router/src/connector/wise.rs index 495b8f2d397..d3fc4d8991d 100644 --- a/crates/router/src/connector/wise.rs +++ b/crates/router/src/connector/wise.rs @@ -280,7 +280,7 @@ impl services::ConnectorIntegration, @@ -386,7 +386,7 @@ impl services::ConnectorIntegration, @@ -467,7 +467,7 @@ impl Ok(Some(request)) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn handle_response( &self, data: &types::PayoutsRouterData, @@ -584,7 +584,7 @@ impl services::ConnectorIntegration, @@ -697,7 +697,7 @@ impl services::ConnectorIntegration, diff --git a/crates/router/src/core/api_keys.rs b/crates/router/src/core/api_keys.rs index 7953cc34bcb..64dc791a849 100644 --- a/crates/router/src/core/api_keys.rs +++ b/crates/router/src/core/api_keys.rs @@ -108,7 +108,7 @@ impl PlaintextApiKey { } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn create_api_key( state: SessionState, api_key: api::CreateApiKeyRequest, @@ -178,7 +178,7 @@ pub async fn create_api_key( // After first email has been sent, update the schedule_time based on retry_count in execute_workflow(). // A task is not scheduled if the time for the first email is in the past. #[cfg(feature = "email")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn add_api_key_expiry_task( store: &dyn crate::db::StorageInterface, api_key: &ApiKey, @@ -242,7 +242,7 @@ pub async fn add_api_key_expiry_task( Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn retrieve_api_key( state: SessionState, merchant_id: &str, @@ -259,7 +259,7 @@ pub async fn retrieve_api_key( Ok(ApplicationResponse::Json(api_key.foreign_into())) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn update_api_key( state: SessionState, api_key: api::UpdateApiKeyRequest, @@ -335,7 +335,7 @@ pub async fn update_api_key( // Construct Update variant of ProcessTrackerUpdate with new tracking_data. // A task is not scheduled if the time for the first email is in the past. #[cfg(feature = "email")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn update_api_key_expiry_task( store: &dyn crate::db::StorageInterface, api_key: &ApiKey, @@ -393,7 +393,7 @@ pub async fn update_api_key_expiry_task( Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn revoke_api_key( state: SessionState, merchant_id: &str, @@ -441,7 +441,7 @@ pub async fn revoke_api_key( // Function to revoke api_key_expiry task in the process_tracker table when API key is revoked. // Construct StatusUpdate variant of ProcessTrackerUpdate by setting status to 'finish'. #[cfg(feature = "email")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn revoke_api_key_expiry_task( store: &dyn crate::db::StorageInterface, key_id: &str, @@ -461,7 +461,7 @@ pub async fn revoke_api_key_expiry_task( Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn list_api_keys( state: SessionState, merchant_id: String, diff --git a/crates/router/src/core/api_locking.rs b/crates/router/src/core/api_locking.rs index 51010b10cd9..8723c5fc141 100644 --- a/crates/router/src/core/api_locking.rs +++ b/crates/router/src/core/api_locking.rs @@ -6,10 +6,7 @@ use redis_interface as redis; use router_env::{instrument, logger, tracing}; use super::errors::{self, RouterResult}; -use crate::routes::{ - app::SessionStateInfo, - lock_utils, -}; +use crate::routes::{app::SessionStateInfo, lock_utils}; pub const API_LOCK_PREFIX: &str = "API_LOCK"; @@ -50,7 +47,7 @@ impl LockingInput { } impl LockAction { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn perform_locking_action(self, state: &A, merchant_id: String) -> RouterResult<()> where A: SessionStateInfo, @@ -111,7 +108,7 @@ impl LockAction { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn free_lock_action(self, state: &A, merchant_id: String) -> RouterResult<()> where A: SessionStateInfo, diff --git a/crates/router/src/core/blocklist/transformers.rs b/crates/router/src/core/blocklist/transformers.rs index 72a24ac973e..c3499445602 100644 --- a/crates/router/src/core/blocklist/transformers.rs +++ b/crates/router/src/core/blocklist/transformers.rs @@ -109,7 +109,7 @@ async fn generate_jwe_payload_for_request( Ok(jwe_body) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn generate_fingerprint( state: &routes::SessionState, card_number: StrongSecret, @@ -127,7 +127,7 @@ pub async fn generate_fingerprint( Ok(generate_fingerprint_resp) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn call_to_locker_for_fingerprint( state: &routes::SessionState, payload: &blocklist::GenerateFingerprintRequest, diff --git a/crates/router/src/core/cards_info.rs b/crates/router/src/core/cards_info.rs index 34308257ad8..bc01a786d15 100644 --- a/crates/router/src/core/cards_info.rs +++ b/crates/router/src/core/cards_info.rs @@ -19,7 +19,7 @@ fn verify_iin_length(card_iin: &str) -> Result<(), errors::ApiErrorResponse> { }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn retrieve_card_info( state: routes::SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rs index d8e08c7768b..81bfafd8f6f 100644 --- a/crates/router/src/core/customers.rs +++ b/crates/router/src/core/customers.rs @@ -27,7 +27,7 @@ use crate::{ pub const REDACTED: &str = "Redacted"; -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn create_customer( state: SessionState, merchant_account: domain::MerchantAccount, @@ -134,7 +134,7 @@ pub async fn create_customer( )) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn retrieve_customer( state: SessionState, merchant_account: domain::MerchantAccount, @@ -164,7 +164,7 @@ pub async fn retrieve_customer( )) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn list_customers( state: SessionState, merchant_id: String, @@ -185,7 +185,7 @@ pub async fn list_customers( Ok(services::ApplicationResponse::Json(customers)) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn delete_customer( state: SessionState, merchant_account: domain::MerchantAccount, @@ -339,7 +339,7 @@ pub async fn delete_customer( Ok(services::ApplicationResponse::Json(response)) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn update_customer( state: SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs index 14613e89be5..d24e0524996 100644 --- a/crates/router/src/core/disputes.rs +++ b/crates/router/src/core/disputes.rs @@ -22,7 +22,7 @@ use crate::{ }, }; -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn retrieve_dispute( state: SessionState, merchant_account: domain::MerchantAccount, @@ -39,7 +39,7 @@ pub async fn retrieve_dispute( Ok(services::ApplicationResponse::Json(dispute_response)) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn retrieve_disputes_list( state: SessionState, merchant_account: domain::MerchantAccount, @@ -58,7 +58,7 @@ pub async fn retrieve_disputes_list( Ok(services::ApplicationResponse::Json(disputes_list)) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn accept_dispute( state: SessionState, merchant_account: domain::MerchantAccount, @@ -159,7 +159,7 @@ pub async fn accept_dispute( Ok(services::ApplicationResponse::Json(dispute_response)) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn submit_evidence( state: SessionState, merchant_account: domain::MerchantAccount, @@ -399,7 +399,7 @@ pub async fn attach_evidence( Ok(create_file_response) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn retrieve_dispute_evidence( state: SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs index dc3e19cb725..442f13ff690 100644 --- a/crates/router/src/core/errors/api_error_response.rs +++ b/crates/router/src/core/errors/api_error_response.rs @@ -265,6 +265,8 @@ pub enum ApiErrorResponse { message = "Invalid Cookie" )] InvalidCookie, + #[error(error_type = ErrorType::InvalidRequestError, code = "IR_27", message = "Invalid tenant id: {tenant_id}")] + InvalidTenant { tenant_id: String }, } impl PTError for ApiErrorResponse { diff --git a/crates/router/src/core/errors/transformers.rs b/crates/router/src/core/errors/transformers.rs index 7c06fc92c99..30dc11e751f 100644 --- a/crates/router/src/core/errors/transformers.rs +++ b/crates/router/src/core/errors/transformers.rs @@ -295,6 +295,9 @@ impl ErrorSwitch for ApiErrorRespon Self::InvalidCookie => { AER::BadRequest(ApiError::new("IR", 26, "Invalid Cookie", None)) } + Self::InvalidTenant { tenant_id } => { + AER::BadRequest(ApiError::new("IR", 27, format!("Invalid Tenant {tenant_id}"), None)) + } } } } diff --git a/crates/router/src/core/fraud_check.rs b/crates/router/src/core/fraud_check.rs index 45d592177ea..a483f241d7f 100644 --- a/crates/router/src/core/fraud_check.rs +++ b/crates/router/src/core/fraud_check.rs @@ -47,7 +47,7 @@ pub mod flows; pub mod operation; pub mod types; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn call_frm_service( state: &SessionState, payment_data: &mut payments::PaymentData, @@ -647,7 +647,7 @@ impl From for PaymentDetails { } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn frm_fulfillment_core( state: SessionState, merchant_account: domain::MerchantAccount, @@ -706,7 +706,7 @@ pub async fn frm_fulfillment_core( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn make_fulfillment_api_call( db: &dyn StorageInterface, fraud_check: FraudCheck, diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs index 1d0c8a33381..c9184d03ab6 100644 --- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs +++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs @@ -18,7 +18,7 @@ use crate::{ utils, SessionState, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_fulfillment_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs index 2d49081155d..77f37f07bc8 100644 --- a/crates/router/src/core/fraud_check/operation/fraud_check_post.rs +++ b/crates/router/src/core/fraud_check/operation/fraud_check_post.rs @@ -68,7 +68,7 @@ impl FraudCheckOperation for FraudCheckPost { #[async_trait] impl GetTracker for FraudCheckPost { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -136,7 +136,7 @@ impl GetTracker for FraudCheckPost { #[async_trait] impl Domain for FraudCheckPost { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn post_payment_frm<'a>( &'a self, state: &'a SessionState, @@ -173,7 +173,7 @@ impl Domain for FraudCheckPost { })) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn execute_post_tasks( &self, state: &SessionState, @@ -231,7 +231,7 @@ impl Domain for FraudCheckPost { return Ok(Some(frm_data.to_owned())); } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn pre_payment_frm<'a>( &'a self, state: &'a SessionState, diff --git a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs index 48804dc7b75..719a6530230 100644 --- a/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs +++ b/crates/router/src/core/fraud_check/operation/fraud_check_pre.rs @@ -63,7 +63,7 @@ impl FraudCheckOperation for FraudCheckPre { #[async_trait] impl GetTracker for FraudCheckPre { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -134,7 +134,7 @@ impl GetTracker for FraudCheckPre { #[async_trait] impl Domain for FraudCheckPre { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn post_payment_frm<'a>( &'a self, state: &'a SessionState, diff --git a/crates/router/src/core/gsm.rs b/crates/router/src/core/gsm.rs index a96227ec181..4a678a5c408 100644 --- a/crates/router/src/core/gsm.rs +++ b/crates/router/src/core/gsm.rs @@ -14,7 +14,7 @@ use crate::{ SessionState, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn create_gsm_rule( state: SessionState, gsm_rule: gsm_api_types::GsmCreateRequest, @@ -28,7 +28,7 @@ pub async fn create_gsm_rule( .map(|gsm| services::ApplicationResponse::Json(gsm.foreign_into())) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn retrieve_gsm_rule( state: SessionState, gsm_request: gsm_api_types::GsmRetrieveRequest, @@ -49,7 +49,7 @@ pub async fn retrieve_gsm_rule( .map(|gsm| services::ApplicationResponse::Json(gsm.foreign_into())) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn update_gsm_rule( state: SessionState, gsm_request: gsm_api_types::GsmUpdateRequest, @@ -92,7 +92,7 @@ pub async fn update_gsm_rule( .map(|gsm| services::ApplicationResponse::Json(gsm.foreign_into())) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn delete_gsm_rule( state: SessionState, gsm_request: gsm_api_types::GsmDeleteRequest, diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs index 9adadba9d81..a3e7d18153e 100644 --- a/crates/router/src/core/mandate.rs +++ b/crates/router/src/core/mandate.rs @@ -29,7 +29,7 @@ use crate::{ utils::OptionExt, }; -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn get_mandate( state: SessionState, merchant_account: domain::MerchantAccount, @@ -53,7 +53,7 @@ pub async fn get_mandate( )) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn revoke_mandate( state: SessionState, merchant_account: domain::MerchantAccount, @@ -155,7 +155,7 @@ pub async fn revoke_mandate( } } -//#\[instrument\(skip(db))] +#[instrument(skip(db))] pub async fn update_connector_mandate_id( db: &dyn StorageInterface, merchant_account: String, @@ -207,7 +207,7 @@ pub async fn update_connector_mandate_id( Ok(services::ApplicationResponse::StatusOk) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn get_customer_mandates( state: SessionState, merchant_account: domain::MerchantAccount, @@ -467,7 +467,7 @@ where Ok(resp) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn retrieve_mandates_list( state: SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 1c45e711074..1cdb0e2f6f1 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -74,7 +74,7 @@ use crate::{ utils::{self, ConnectorResponseExt, OptionExt}, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_payment_method( db: &dyn db::StorageInterface, @@ -168,7 +168,7 @@ pub fn store_default_payment_method( (payment_method_response, None) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_or_insert_payment_method( db: &dyn db::StorageInterface, req: api::PaymentMethodCreate, @@ -236,7 +236,7 @@ pub async fn get_or_insert_payment_method( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn add_payment_method( state: routes::SessionState, req: api::PaymentMethodCreate, @@ -464,7 +464,7 @@ pub async fn insert_payment_method( .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn update_customer_payment_method( state: routes::SessionState, merchant_account: domain::MerchantAccount, @@ -693,7 +693,7 @@ pub async fn delete_card_from_locker( .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn add_card_hs( state: &routes::SessionState, req: api::PaymentMethodCreate, @@ -736,7 +736,7 @@ pub async fn add_card_hs( Ok((payment_method_resp, store_card_payload.duplication_check)) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn decode_and_decrypt_locker_data( key_store: &domain::MerchantKeyStore, enc_card_data: String, @@ -757,7 +757,7 @@ pub async fn decode_and_decrypt_locker_data( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_payment_method_from_hs_locker<'a>( state: &'a routes::SessionState, key_store: &domain::MerchantKeyStore, @@ -819,7 +819,7 @@ pub async fn get_payment_method_from_hs_locker<'a>( Ok(payment_method_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn call_to_locker_hs<'a>( state: &routes::SessionState, payload: &payment_methods::StoreLockerReq<'a>, @@ -892,7 +892,7 @@ pub async fn update_payment_method_connector_mandate_details( .change_context(errors::VaultError::UpdateInPaymentMethodDataTableFailed)?; Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_card_from_hs_locker<'a>( state: &'a routes::SessionState, customer_id: &str, @@ -945,7 +945,7 @@ pub async fn get_card_from_hs_locker<'a>( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn delete_card_from_hs_locker<'a>( state: &routes::SessionState, customer_id: &str, @@ -1052,7 +1052,7 @@ pub async fn mock_call_to_locker_hs<'a>( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn mock_get_card<'a>( db: &dyn db::StorageInterface, card_id: &'a str, @@ -1088,7 +1088,7 @@ pub async fn mock_get_card<'a>( )) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn mock_get_payment_method<'a>( db: &dyn db::StorageInterface, key_store: &domain::MerchantKeyStore, @@ -1119,7 +1119,7 @@ pub async fn mock_get_payment_method<'a>( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn mock_delete_card_hs<'a>( db: &dyn db::StorageInterface, card_id: &'a str, @@ -1134,7 +1134,7 @@ pub async fn mock_delete_card_hs<'a>( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn mock_delete_card<'a>( db: &dyn db::StorageInterface, card_id: &'a str, @@ -3401,7 +3401,7 @@ pub async fn get_bank_from_hs_locker( pub struct TempLockerCardSupport; impl TempLockerCardSupport { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn create_payment_method_data_in_temp_locker( state: &routes::SessionState, payment_token: &str, @@ -3486,7 +3486,7 @@ impl TempLockerCardSupport { } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn retrieve_payment_method( state: routes::SessionState, pm: api::PaymentMethodId, @@ -3541,7 +3541,7 @@ pub async fn retrieve_payment_method( )) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn delete_payment_method( state: routes::SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs index 1971bc918d4..1cd9513cd4a 100644 --- a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs +++ b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs @@ -385,7 +385,7 @@ fn get_surcharge_details_from_surcharge_output( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn ensure_algorithm_cached( store: &dyn StorageInterface, merchant_id: &str, @@ -408,7 +408,7 @@ pub async fn ensure_algorithm_cached( Ok(key) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn refresh_surcharge_algorithm_cache( store: &dyn StorageInterface, key: String, diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs index 6b3723a17c2..98b9a2e8513 100644 --- a/crates/router/src/core/payment_methods/vault.rs +++ b/crates/router/src/core/payment_methods/vault.rs @@ -689,7 +689,7 @@ pub struct MockTokenizeDBValue { pub struct Vault; impl Vault { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn get_payment_method_data_from_locker( state: &routes::SessionState, lookup_key: &str, @@ -705,7 +705,7 @@ impl Vault { Ok((Some(payment_method), customer_id)) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn store_payment_method_data_in_locker( state: &routes::SessionState, token_id: Option, @@ -740,7 +740,7 @@ impl Vault { } #[cfg(feature = "payouts")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn get_payout_method_data_from_temporary_locker( state: &routes::SessionState, lookup_key: &str, @@ -757,7 +757,7 @@ impl Vault { } #[cfg(feature = "payouts")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn store_payout_method_data_in_locker( state: &routes::SessionState, token_id: Option, @@ -791,7 +791,7 @@ impl Vault { Ok(lookup_key) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn delete_locker_payment_method_by_lookup_key( state: &routes::SessionState, lookup_key: &Option, @@ -813,7 +813,7 @@ fn get_redis_locker_key(lookup_key: &str) -> String { format!("{}_{}", consts::LOCKER_REDIS_PREFIX, lookup_key) } -//#\[instrument\(skip(state, value1, value2))] +#[instrument(skip(state, value1, value2))] pub async fn create_tokenize( state: &routes::SessionState, value1: String, @@ -878,7 +878,7 @@ pub async fn create_tokenize( } } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn get_tokenized_data( state: &routes::SessionState, lookup_key: &str, @@ -941,7 +941,7 @@ pub async fn get_tokenized_data( } } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn delete_tokenized_data( state: &routes::SessionState, lookup_key: &str, diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index d37b38403f9..a252589af2d 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -62,9 +62,7 @@ use crate::{ }, db::StorageInterface, logger, - routes::{ - app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, SessionState, - }, + routes::{app::ReqState, metrics, payment_methods::ParentPaymentMethodToken, SessionState}, services::{self, api::Authenticate}, types::{ self as router_types, @@ -82,7 +80,7 @@ use crate::{ }; #[allow(clippy::too_many_arguments, clippy::type_complexity)] -//#\[instrument\(skip_all, fields(payment_id, merchant_id))] +#[instrument(skip_all, fields(payment_id, merchant_id))] pub async fn payments_operation_core( state: &SessionState, req_state: ReqState, @@ -509,7 +507,7 @@ where )) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn call_decision_manager( state: &SessionState, merchant_account: &domain::MerchantAccount, @@ -544,7 +542,7 @@ where Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn populate_surcharge_details( state: &SessionState, payment_data: &mut PaymentData, @@ -624,7 +622,7 @@ pub fn get_connector_data( .attach_printable("Connector not found in connectors iterator") } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn call_surcharge_decision_management_for_session_flow( state: &SessionState, merchant_account: &domain::MerchantAccount, @@ -735,7 +733,7 @@ where payment_data, customer, auth_flow, - &state.conf.server, + &state.base_url, operation, &state.conf.connector_request_reference_id_config, connector_http_status_code, @@ -1150,7 +1148,7 @@ impl PaymentRedirectFlow for PaymentAuthenticat } #[allow(clippy::too_many_arguments)] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn call_connector_service( state: &SessionState, req_state: ReqState, @@ -1775,7 +1773,7 @@ pub fn is_preprocessing_required_for_wallets(connector_name: String) -> bool { connector_name == *"trustpay" || connector_name == *"payme" } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_profile_id_and_get_mca<'a, F>( state: &'a SessionState, merchant_account: &domain::MerchantAccount, @@ -3523,7 +3521,7 @@ where } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn payment_external_authentication( state: SessionState, merchant_account: domain::MerchantAccount, @@ -3658,7 +3656,7 @@ pub async fn payment_external_authentication( .ok_or(errors::ApiErrorResponse::InternalServerError) .attach_printable("missing connector in payment_attempt")?; let return_url = Some(helpers::create_authorize_url( - &state.conf.server.base_url, + &state.base_url, &payment_attempt.clone(), payment_connector_name, )); diff --git a/crates/router/src/core/payments/conditional_configs.rs b/crates/router/src/core/payments/conditional_configs.rs index e511d45265d..c73fa3659b7 100644 --- a/crates/router/src/core/payments/conditional_configs.rs +++ b/crates/router/src/core/payments/conditional_configs.rs @@ -19,7 +19,7 @@ static CONF_CACHE: StaticCache = errors::CustomResult; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn perform_decision_management( state: &routes::SessionState, algorithm_ref: routing::RoutingAlgorithmRef, @@ -49,7 +49,7 @@ pub async fn perform_decision_management( execute_dsl_and_get_conditional_config(backend_input, interpreter).await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn ensure_algorithm_cached( state: &routes::SessionState, merchant_id: &str, @@ -71,7 +71,7 @@ pub async fn ensure_algorithm_cached( Ok(key) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn refresh_routing_cache( state: &routes::SessionState, key: String, diff --git a/crates/router/src/core/payments/customers.rs b/crates/router/src/core/payments/customers.rs index 2fdfe299ad1..163a93c1e92 100644 --- a/crates/router/src/core/payments/customers.rs +++ b/crates/router/src/core/payments/customers.rs @@ -11,7 +11,7 @@ use crate::{ types::{self, api, domain, storage}, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn create_connector_customer( state: &SessionState, connector: &api::ConnectorData, diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index b0185c9b507..e07cc244338 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -32,7 +32,7 @@ use super::{ CustomerDetails, PaymentData, }; use crate::{ - configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerEnableConfig}, + configs::settings::{ConnectorRequestReferenceIdConfig, TempLockerEnableConfig}, connector, consts::{self, BASE64_ENGINE}, core::{ @@ -101,7 +101,7 @@ pub fn filter_mca_based_on_business_profile( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_or_update_address_for_payment_by_request( db: &dyn StorageInterface, @@ -261,7 +261,7 @@ pub async fn create_or_update_address_for_payment_by_request( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn create_or_find_address_for_payment_by_request( db: &dyn StorageInterface, @@ -671,7 +671,7 @@ pub async fn get_token_for_recurring_mandate( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] /// Check weather the merchant id in the request /// and merchant id in the merchant account are same. pub fn validate_merchant_id( @@ -692,7 +692,7 @@ pub fn validate_merchant_id( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_request_amount_and_amount_to_capture( op_amount: Option, op_amount_to_capture: Option, @@ -731,7 +731,7 @@ pub fn validate_request_amount_and_amount_to_capture( } /// if capture method = automatic, amount_to_capture(if provided) must be equal to amount -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_amount_to_capture_and_capture_method( payment_attempt: Option<&PaymentAttempt>, request: &api_models::payments::PaymentsRequest, @@ -777,7 +777,7 @@ pub fn validate_amount_to_capture_and_capture_method( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_card_data( payment_method_data: Option, ) -> CustomResult<(), errors::ApiErrorResponse> { @@ -974,16 +974,13 @@ pub fn validate_customer_id_mandatory_cases( } pub fn create_startpay_url( - server: &Server, + base_url: &String, payment_attempt: &PaymentAttempt, payment_intent: &PaymentIntent, ) -> String { format!( "{}/payments/redirect/{}/{}/{}", - server.base_url, - payment_intent.payment_id, - payment_intent.merchant_id, - payment_attempt.attempt_id + base_url, payment_intent.payment_id, payment_intent.merchant_id, payment_attempt.attempt_id ) } @@ -1127,7 +1124,7 @@ pub fn verify_mandate_details_for_recurring_payments( Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn payment_attempt_status_fsm( payment_method_data: &Option, confirm: Option, @@ -1212,7 +1209,7 @@ where Box::new(PaymentResponse) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) async fn get_payment_method_create_request( payment_method_data: Option<&domain::PaymentMethodData>, payment_method: Option, @@ -1379,7 +1376,7 @@ pub fn validate_customer_details_in_request( /// Get the customer details from customer field if present /// or from the individual fields in `PaymentsRequest` -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn get_customer_details_from_request( request: &api_models::payments::PaymentsRequest, ) -> CustomerDetails { @@ -1432,7 +1429,7 @@ pub async fn get_connector_default( )) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::type_complexity)] pub async fn create_customer_if_not_exist<'a, F: Clone, R, Ctx>( operation: BoxedOperation<'a, F, R, Ctx>, @@ -2021,7 +2018,7 @@ pub fn should_store_payment_method_data_in_vault( .unwrap_or(true) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) fn validate_capture_method( capture_method: storage_enums::CaptureMethod, ) -> RouterResult<()> { @@ -2038,7 +2035,7 @@ pub(crate) fn validate_capture_method( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) fn validate_status_with_capture_method( status: storage_enums::IntentStatus, capture_method: storage_enums::CaptureMethod, @@ -2069,7 +2066,7 @@ pub(crate) fn validate_status_with_capture_method( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) fn validate_amount_to_capture( amount: i64, amount_to_capture: Option, @@ -2084,7 +2081,7 @@ pub(crate) fn validate_amount_to_capture( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) fn validate_payment_method_fields_present( req: &api::PaymentsRequest, ) -> RouterResult<()> { @@ -2713,7 +2710,7 @@ pub(crate) fn validate_payment_status_against_not_allowed_statuses( }) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) fn validate_pm_or_token_given( payment_method: &Option, payment_method_data: &Option, @@ -3012,7 +3009,7 @@ mod tests { } // This function will be removed after moving this functionality to server_wrap and using cache instead of config -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn insert_merchant_connector_creds_to_config( db: &dyn StorageInterface, merchant_id: &str, @@ -3099,7 +3096,7 @@ impl MerchantConnectorAccountType { /// Query for merchant connector account either by business label or profile id /// If profile_id is passed use it, or use connector_label to query merchant connector account -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_merchant_connector_account( state: &SessionState, merchant_id: &str, @@ -3234,7 +3231,7 @@ pub fn router_data_type_conversion( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn get_attempt_type( payment_intent: &PaymentIntent, payment_attempt: &PaymentAttempt, @@ -3441,7 +3438,7 @@ impl AttemptType { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn modify_payment_intent_and_payment_attempt( &self, request: &api::PaymentsRequest, @@ -3581,7 +3578,7 @@ mod test { } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_additional_payment_data( pm_data: &api_models::payments::PaymentMethodData, db: &dyn StorageInterface, diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs index 3e86ffe5d4b..72a49d33ead 100644 --- a/crates/router/src/core/payments/operations.rs +++ b/crates/router/src/core/payments/operations.rs @@ -181,7 +181,7 @@ pub trait Domain: Send + Sync { Ok(()) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, @@ -234,7 +234,7 @@ impl< where for<'a> &'a Op: Operation, { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -274,7 +274,7 @@ where helpers::get_connector_default(state, None).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'a>( &'a self, state: &'a SessionState, @@ -298,7 +298,7 @@ where .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, @@ -318,7 +318,7 @@ impl< where for<'a> &'a Op: Operation, { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -346,7 +346,7 @@ where .await?, )) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, @@ -373,7 +373,7 @@ where helpers::get_connector_default(state, None).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, @@ -393,7 +393,7 @@ impl< where for<'a> &'a Op: Operation, { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -422,7 +422,7 @@ where )) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, @@ -449,7 +449,7 @@ where helpers::get_connector_default(state, None).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, @@ -469,7 +469,7 @@ impl< where for<'a> &'a Op: Operation, { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, _db: &dyn StorageInterface, @@ -487,7 +487,7 @@ where Ok((Box::new(self), None)) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, @@ -514,7 +514,7 @@ where helpers::get_connector_default(state, None).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs index 855dbbe57bd..2c24835cd4d 100644 --- a/crates/router/src/core/payments/operations/payment_approve.rs +++ b/crates/router/src/core/payments/operations/payment_approve.rs @@ -32,7 +32,7 @@ pub struct PaymentApprove; impl GetTracker, api::PaymentsCaptureRequest, Ctx> for PaymentApprove { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -196,7 +196,7 @@ impl impl UpdateTracker, api::PaymentsCaptureRequest, Ctx> for PaymentApprove { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, db: &'b SessionState, @@ -236,7 +236,7 @@ impl impl ValidateRequest for PaymentApprove { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCaptureRequest, diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs index d3f927fe979..14b6f858129 100644 --- a/crates/router/src/core/payments/operations/payment_cancel.rs +++ b/crates/router/src/core/payments/operations/payment_cancel.rs @@ -34,7 +34,7 @@ pub struct PaymentCancel; impl GetTracker, api::PaymentsCancelRequest, Ctx> for PaymentCancel { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -206,7 +206,7 @@ impl impl UpdateTracker, api::PaymentsCancelRequest, Ctx> for PaymentCancel { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, db: &'b SessionState, @@ -276,7 +276,7 @@ impl impl ValidateRequest for PaymentCancel { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCancelRequest, diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 1566e43a049..ffb15288741 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -32,7 +32,7 @@ pub struct PaymentCapture; impl GetTracker, api::PaymentsCaptureRequest, Ctx> for PaymentCapture { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -250,7 +250,7 @@ impl UpdateTracker, api::PaymentsCaptureRequest, Ctx> for PaymentCapture { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, db: &'b SessionState, @@ -300,7 +300,7 @@ impl impl ValidateRequest for PaymentCapture { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsCaptureRequest, diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs index 67c1c22c283..a573ec0a46d 100644 --- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs +++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs @@ -34,7 +34,7 @@ pub struct CompleteAuthorize; impl GetTracker, api::PaymentsRequest, Ctx> for CompleteAuthorize { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -332,7 +332,7 @@ impl impl Domain for CompleteAuthorize { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -359,7 +359,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -384,7 +384,7 @@ impl Domain( &'a self, _state: &'a SessionState, @@ -408,7 +408,7 @@ impl Domain( &'a self, _state: &SessionState, @@ -423,7 +423,7 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for CompleteAuthorize { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, _state: &'b SessionState, @@ -449,7 +449,7 @@ impl impl ValidateRequest for CompleteAuthorize { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index cb8d9d2196d..95a9a1ae27e 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -41,7 +41,7 @@ pub struct PaymentConfirm; impl GetTracker, api::PaymentsRequest, Ctx> for PaymentConfirm { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -651,7 +651,7 @@ impl impl Domain for PaymentConfirm { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -678,7 +678,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -708,7 +708,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -752,7 +752,7 @@ impl Domain( &'a self, state: &SessionState, @@ -884,7 +884,7 @@ impl Domain( &'a self, state: &SessionState, @@ -899,7 +899,7 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for PaymentConfirm { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, state: &'b SessionState, @@ -1203,7 +1203,7 @@ impl impl ValidateRequest for PaymentConfirm { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index bd268ad85b5..b2927cfcad3 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -52,7 +52,7 @@ pub struct PaymentCreate; impl GetTracker, api::PaymentsRequest, Ctx> for PaymentCreate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -215,7 +215,7 @@ impl .map(|merchant_name| merchant_name.into_inner().peek().to_owned()) .unwrap_or_default(); - let default_domain_name = state.conf.server.base_url.clone(); + let default_domain_name = state.base_url.clone(); let (payment_link_config, domain_name) = payment_link::get_payment_link_config_based_on_priority( @@ -464,7 +464,7 @@ impl impl Domain for PaymentCreate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -491,7 +491,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -515,7 +515,7 @@ impl Domain( &'a self, _state: &'a SessionState, @@ -537,7 +537,7 @@ impl Domain( &'a self, _state: &SessionState, @@ -552,7 +552,7 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for PaymentCreate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, state: &'b SessionState, @@ -657,7 +657,7 @@ impl impl ValidateRequest for PaymentCreate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, @@ -752,7 +752,7 @@ impl ValidateRequest RouterResult<(api::Amount, enums::Currency)> { diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs index 3920f44cd4f..779491a04a0 100644 --- a/crates/router/src/core/payments/operations/payment_reject.rs +++ b/crates/router/src/core/payments/operations/payment_reject.rs @@ -31,7 +31,7 @@ pub struct PaymentReject; impl GetTracker, PaymentsCancelRequest, Ctx> for PaymentReject { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -192,7 +192,7 @@ impl impl UpdateTracker, PaymentsCancelRequest, Ctx> for PaymentReject { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, state: &'b SessionState, @@ -260,7 +260,7 @@ impl impl ValidateRequest for PaymentReject { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &PaymentsCancelRequest, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 5f50433f074..cca5ed0d05f 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -439,7 +439,7 @@ impl PostUpdateTracker, types::CompleteAuthorizeData } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn payment_response_update_tracker( state: &SessionState, _payment_id: &api::PaymentIdType, diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs index f8ba8d75f6f..984edb1086c 100644 --- a/crates/router/src/core/payments/operations/payment_session.rs +++ b/crates/router/src/core/payments/operations/payment_session.rs @@ -33,7 +33,7 @@ pub struct PaymentSession; impl GetTracker, api::PaymentsSessionRequest, Ctx> for PaymentSession { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -217,7 +217,7 @@ impl impl UpdateTracker, api::PaymentsSessionRequest, Ctx> for PaymentSession { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, state: &'b SessionState, @@ -260,7 +260,7 @@ impl impl ValidateRequest for PaymentSession { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsSessionRequest, @@ -293,7 +293,7 @@ impl< where for<'a> &'a Op: Operation, { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -320,7 +320,7 @@ where .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'b>( &'b self, _state: &'b SessionState, @@ -462,7 +462,7 @@ where )) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs index b7a656eff13..6ca11f3a3a3 100644 --- a/crates/router/src/core/payments/operations/payment_start.rs +++ b/crates/router/src/core/payments/operations/payment_start.rs @@ -32,7 +32,7 @@ pub struct PaymentStart; impl GetTracker, api::PaymentsStartRequest, Ctx> for PaymentStart { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -204,7 +204,7 @@ impl impl UpdateTracker, api::PaymentsStartRequest, Ctx> for PaymentStart { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, _state: &'b SessionState, @@ -230,7 +230,7 @@ impl impl ValidateRequest for PaymentStart { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsStartRequest, @@ -269,7 +269,7 @@ impl< where for<'a> &'a Op: Operation, { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -296,7 +296,7 @@ where .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'a>( &'a self, state: &'a SessionState, @@ -341,7 +341,7 @@ where helpers::get_connector_default(state, None).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs index 707ec5280ae..614edf42999 100644 --- a/crates/router/src/core/payments/operations/payment_status.rs +++ b/crates/router/src/core/payments/operations/payment_status.rs @@ -64,7 +64,7 @@ impl Operation Domain for PaymentStatus { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -91,7 +91,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -115,7 +115,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -137,7 +137,7 @@ impl Domain( &'a self, _state: &SessionState, @@ -204,7 +204,7 @@ impl impl GetTracker, api::PaymentsRetrieveRequest, Ctx> for PaymentStatus { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index ee5a63ed0d9..d0a31c2e81a 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -37,7 +37,7 @@ pub struct PaymentUpdate; impl GetTracker, api::PaymentsRequest, Ctx> for PaymentUpdate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -470,7 +470,7 @@ impl impl Domain for PaymentUpdate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, db: &dyn StorageInterface, @@ -497,7 +497,7 @@ impl Domain( &'a self, state: &'a SessionState, @@ -521,7 +521,7 @@ impl Domain( &'a self, _state: &'a SessionState, @@ -543,7 +543,7 @@ impl Domain( &'a self, _state: &SessionState, @@ -558,7 +558,7 @@ impl Domain UpdateTracker, api::PaymentsRequest, Ctx> for PaymentUpdate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, state: &'b SessionState, @@ -729,7 +729,7 @@ impl impl ValidateRequest for PaymentUpdate { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &api::PaymentsRequest, diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs index eaf99862ddc..e1a6dd2feaa 100644 --- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs +++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs @@ -39,7 +39,7 @@ impl GetTracker, PaymentsIncrementalAuthorizationRequest, Ctx> for PaymentIncrementalAuthorization { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_trackers<'a>( &'a self, state: &'a SessionState, @@ -174,7 +174,7 @@ impl UpdateTracker, PaymentsIncrementalAuthorizationRequest, Ctx> for PaymentIncrementalAuthorization { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_trackers<'b>( &'b self, db: &'b SessionState, @@ -265,7 +265,7 @@ impl ValidateRequest for PaymentIncrementalAuthorization { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn validate_request<'a, 'b>( &'b self, request: &PaymentsIncrementalAuthorizationRequest, @@ -290,7 +290,7 @@ impl impl Domain for PaymentIncrementalAuthorization { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_or_create_customer_details<'a>( &'a self, _db: &dyn StorageInterface, @@ -308,7 +308,7 @@ impl Ok((Box::new(self), None)) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn make_pm_data<'a>( &'a self, _state: &'a SessionState, @@ -335,7 +335,7 @@ impl helpers::get_connector_default(state, None).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn guard_payment_against_blocklist<'a>( &'a self, _state: &SessionState, diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 32dd004589b..6384466dc34 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -29,7 +29,7 @@ use crate::{ utils, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn do_gsm_actions( state: &app::SessionState, @@ -162,7 +162,7 @@ where Ok(router_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn is_step_up_enabled_for_merchant_connector( state: &app::SessionState, merchant_id: &str, @@ -186,7 +186,7 @@ pub async fn is_step_up_enabled_for_merchant_connector( .unwrap_or(false) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_retries( state: &app::SessionState, retries: Option, @@ -216,7 +216,7 @@ pub async fn get_retries( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_gsm( state: &app::SessionState, router_data: &types::RouterData, @@ -232,7 +232,7 @@ pub async fn get_gsm( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn get_gsm_decision( option_gsm: Option, ) -> api_models::gsm::GsmDecision { @@ -266,7 +266,7 @@ fn get_flow_name() -> RouterResult { } #[allow(clippy::too_many_arguments)] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn do_retry( state: &routes::SessionState, req_state: ReqState, @@ -322,7 +322,7 @@ where .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn modify_trackers( state: &routes::SessionState, connector: String, @@ -466,7 +466,7 @@ where Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn make_new_payment_attempt( connector: String, old_payment_attempt: storage::PaymentAttempt, diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index d27fde76689..60a23bb7d6d 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -29,7 +29,7 @@ use crate::{ utils::{generate_id, OptionExt}, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn save_payment_method( state: &SessionState, diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index cb6b1e7c449..15a7322a859 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -12,7 +12,7 @@ use router_env::{instrument, tracing}; use super::{flows::Feature, types::AuthenticationData, PaymentData}; use crate::{ - configs::settings::{ConnectorRequestReferenceIdConfig, Server}, + configs::settings::ConnectorRequestReferenceIdConfig, connector::{Helcim, Nexinets}, core::{ errors::{self, RouterResponse, RouterResult}, @@ -30,7 +30,7 @@ use crate::{ utils::{OptionExt, ValueExt}, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_payment_router_data<'a, F, T>( state: &'a SessionState, payment_data: PaymentData, @@ -88,7 +88,7 @@ where }); let additional_data = PaymentAdditionalData { - router_base_url: state.conf.server.base_url.clone(), + router_base_url: state.base_url.clone(), connector_name: connector_id.to_string(), payment_data: payment_data.clone(), state, @@ -195,7 +195,7 @@ where data: D, customer: Option, auth_flow: services::AuthFlow, - server: &Server, + base_url: &String, operation: Op, connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, connector_http_status_code: Option, @@ -214,7 +214,7 @@ where payment_data: PaymentData, customer: Option, auth_flow: services::AuthFlow, - server: &Server, + base_url: &String, operation: Op, connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, connector_http_status_code: Option, @@ -244,7 +244,7 @@ where captures, customer, auth_flow, - server, + base_url, &operation, connector_request_reference_id_config, connector_http_status_code, @@ -264,7 +264,7 @@ where payment_data: PaymentData, _customer: Option, _auth_flow: services::AuthFlow, - _server: &Server, + _base_url: &String, _operation: Op, _connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, _connector_http_status_code: Option, @@ -296,7 +296,7 @@ where data: PaymentData, customer: Option, _auth_flow: services::AuthFlow, - _server: &Server, + _base_url: &String, _operation: Op, _connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, _connector_http_status_code: Option, @@ -343,7 +343,7 @@ where } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] // try to use router data here so that already validated things , we don't want to repeat the validations. // Add internal value not found and external value not found so that we can give 500 / Internal server error for internal value not found #[allow(clippy::too_many_arguments)] @@ -352,7 +352,7 @@ pub fn payments_to_payments_response( captures: Option>, customer: Option, auth_flow: services::AuthFlow, - server: &Server, + base_url: &String, operation: &Op, connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, connector_http_status_code: Option, @@ -560,7 +560,7 @@ where .or(payment_attempt.authentication_data.as_ref().map(|_| { api_models::payments::NextActionData::RedirectToUrl { redirect_to_url: helpers::create_startpay_url( - server, + base_url, &payment_attempt, &payment_intent, ), @@ -575,9 +575,9 @@ where .get_required_value("connector")?; Some(api_models::payments::NextActionData::ThreeDsInvoke { three_ds_data: api_models::payments::ThreeDsData { - three_ds_authentication_url: helpers::create_authentication_url(&server.base_url, &payment_attempt), + three_ds_authentication_url: helpers::create_authentication_url(base_url, &payment_attempt), three_ds_authorize_url: helpers::create_authorize_url( - &server.base_url, + base_url, &payment_attempt, payment_connector_name, ), diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rs index db00c13d31a..c25a1fe9971 100644 --- a/crates/router/src/core/payments/types.rs +++ b/crates/router/src/core/payments/types.rs @@ -321,7 +321,7 @@ impl SurchargeMetadata { } } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn persist_individual_surcharge_details_in_redis( &self, state: &SessionState, @@ -357,7 +357,7 @@ impl SurchargeMetadata { Ok(()) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] pub async fn get_individual_surcharge_detail_from_redis( state: &SessionState, surcharge_key: SurchargeKey, diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs index 62eb70b13c2..3d913e11363 100644 --- a/crates/router/src/core/payouts.rs +++ b/crates/router/src/core/payouts.rs @@ -143,7 +143,7 @@ pub async fn get_connector_choice( } #[cfg(feature = "payouts")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn make_connector_decision( state: &SessionState, merchant_account: &domain::MerchantAccount, @@ -253,7 +253,7 @@ pub async fn make_connector_decision( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn payouts_create_core( state: SessionState, merchant_account: domain::MerchantAccount, @@ -456,7 +456,7 @@ pub async fn payouts_update_core( .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn payouts_retrieve_core( state: SessionState, merchant_account: domain::MerchantAccount, @@ -480,7 +480,7 @@ pub async fn payouts_retrieve_core( .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn payouts_cancel_core( state: SessionState, merchant_account: domain::MerchantAccount, @@ -583,7 +583,7 @@ pub async fn payouts_cancel_core( .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn payouts_fulfill_core( state: SessionState, merchant_account: domain::MerchantAccount, diff --git a/crates/router/src/core/payouts/retry.rs b/crates/router/src/core/payouts/retry.rs index ff299550ebc..18bfd43b00d 100644 --- a/crates/router/src/core/payouts/retry.rs +++ b/crates/router/src/core/payouts/retry.rs @@ -26,7 +26,7 @@ pub enum PayoutRetryType { MultiConnector, } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn do_gsm_multiple_connector_actions( state: &app::SessionState, @@ -95,7 +95,7 @@ pub async fn do_gsm_multiple_connector_actions( Ok(payout_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn do_gsm_single_connector_actions( state: &app::SessionState, @@ -161,7 +161,7 @@ pub async fn do_gsm_single_connector_actions( Ok(payout_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_retries( state: &app::SessionState, retries: Option, @@ -199,7 +199,7 @@ pub async fn get_retries( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_gsm( state: &app::SessionState, original_connector_data: &api::ConnectorData, @@ -216,7 +216,7 @@ pub async fn get_gsm( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn get_gsm_decision( option_gsm: Option, ) -> api_models::gsm::GsmDecision { @@ -239,7 +239,7 @@ pub fn get_gsm_decision( } #[allow(clippy::too_many_arguments)] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn do_retry( state: &routes::SessionState, connector: api::ConnectorData, @@ -263,7 +263,7 @@ pub async fn do_retry( .await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn modify_trackers( state: &routes::SessionState, connector: &api::ConnectorData, diff --git a/crates/router/src/core/payouts/validator.rs b/crates/router/src/core/payouts/validator.rs index 93c010bbcf4..061b0199293 100644 --- a/crates/router/src/core/payouts/validator.rs +++ b/crates/router/src/core/payouts/validator.rs @@ -16,7 +16,7 @@ use crate::{ utils, }; -//#\[instrument\(skip(db))] +#[instrument(skip(db))] pub async fn validate_uniqueness_of_payout_id_against_merchant_id( db: &dyn StorageInterface, payout_id: &str, diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index e9ed25cd15b..524fcd57a8c 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -28,7 +28,7 @@ use crate::{ // ********************************************** REFUND EXECUTE ********************************************** -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn refund_create_core( state: SessionState, merchant_account: domain::MerchantAccount, @@ -119,7 +119,7 @@ pub async fn refund_create_core( .map(services::ApplicationResponse::Json) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn trigger_refund_to_gateway( state: &SessionState, refund: &storage::Refund, @@ -320,7 +320,7 @@ where )) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn refund_retrieve_core( state: SessionState, merchant_account: domain::MerchantAccount, @@ -415,7 +415,7 @@ fn should_call_refund(refund: &diesel_models::refund::Refund, force_sync: bool) predicate1 && predicate2 } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn sync_refund_with_gateway( state: &SessionState, merchant_account: &domain::MerchantAccount, @@ -558,7 +558,7 @@ pub async fn refund_update_core( // ********************************************** VALIDATIONS ********************************************** -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn validate_and_create_refund( state: &SessionState, @@ -702,7 +702,7 @@ pub async fn validate_and_create_refund( /// If payment-id is provided, lists all the refunds associated with that particular payment-id /// If payment-id is not provided, lists the refunds associated with that particular merchant - to the limit specified,if no limits given, it is 10 by default -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[cfg(feature = "olap")] pub async fn refund_list( state: SessionState, @@ -747,7 +747,7 @@ pub async fn refund_list( )) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[cfg(feature = "olap")] pub async fn refund_filter_list( state: SessionState, @@ -791,7 +791,7 @@ impl ForeignFrom for api::RefundResponse { // ********************************************** PROCESS TRACKER ********************************************** -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn schedule_refund_execution( state: &SessionState, @@ -869,7 +869,7 @@ pub async fn schedule_refund_execution( Ok(result) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn sync_refund_with_gateway_workflow( state: &SessionState, refund_tracker: &storage::ProcessTracker, @@ -938,7 +938,7 @@ pub async fn sync_refund_with_gateway_workflow( Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn start_refund_workflow( state: &SessionState, refund_tracker: &storage::ProcessTracker, @@ -954,7 +954,7 @@ pub async fn start_refund_workflow( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn trigger_refund_execute_workflow( state: &SessionState, refund_tracker: &storage::ProcessTracker, @@ -1069,7 +1069,7 @@ pub fn refund_to_refund_core_workflow_model( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn add_refund_sync_task( db: &dyn db::StorageInterface, refund: &storage::Refund, @@ -1110,7 +1110,7 @@ pub async fn add_refund_sync_task( Ok(response) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn add_refund_execute_task( db: &dyn db::StorageInterface, refund: &storage::Refund, diff --git a/crates/router/src/core/refunds/validator.rs b/crates/router/src/core/refunds/validator.rs index 88c6f6ad3eb..43d44ebe41d 100644 --- a/crates/router/src/core/refunds/validator.rs +++ b/crates/router/src/core/refunds/validator.rs @@ -27,7 +27,7 @@ pub enum RefundValidationError { DuplicateRefund, } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_success_transaction( transaction: &storage::PaymentAttempt, ) -> CustomResult<(), RefundValidationError> { @@ -38,7 +38,7 @@ pub fn validate_success_transaction( Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_refund_amount( amount_captured: i64, all_refunds: &[storage::Refund], @@ -67,7 +67,7 @@ pub fn validate_refund_amount( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_payment_order_age( created_at: &PrimitiveDateTime, refund_max_age: i64, @@ -80,7 +80,7 @@ pub fn validate_payment_order_age( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub fn validate_maximum_refund_against_payment_attempt( all_refunds: &[storage::Refund], refund_max_attempts: usize, diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs index a2b5c3b83fc..9888ceef594 100644 --- a/crates/router/src/core/user.rs +++ b/crates/router/src/core/user.rs @@ -1343,7 +1343,7 @@ pub async fn verify_email_without_invite_checks( .await .map_err(|e| logger::error!(?e)); let token = utils::user::generate_jwt_auth_token(&state, &user_from_db, &user_role).await?; - utils::user_role::set_role_permissions_in_cache_by_user_role(&state, &user_role, &state).await; + utils::user_role::set_role_permissions_in_cache_by_user_role(&state, &user_role).await; let response = utils::user::get_dashboard_entry_response(&state, user_from_db, user_role, token.clone())?; diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 4b66b47a462..3fb26d2ce57 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -34,7 +34,7 @@ const IRRELEVANT_PAYMENT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_payment_id_in_di const IRRELEVANT_ATTEMPT_ID_IN_DISPUTE_FLOW: &str = "irrelevant_attempt_id_in_dispute_flow"; #[cfg(feature = "payouts")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_mca_for_payout<'a>( state: &'a SessionState, connector_id: &str, @@ -61,7 +61,7 @@ pub async fn get_mca_for_payout<'a>( } #[cfg(feature = "payouts")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_payout_router_data<'a, F>( state: &'a SessionState, connector_id: &str, @@ -192,7 +192,7 @@ pub async fn construct_payout_router_data<'a, F>( Ok(router_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn construct_refund_router_data<'a, F>( state: &'a SessionState, @@ -243,7 +243,7 @@ pub async fn construct_refund_router_data<'a, F>( .change_context(errors::ApiErrorResponse::InternalServerError)?; let webhook_url = Some(helpers::create_webhook_url( - &state.conf.server.base_url.clone(), + &state.base_url.clone(), &merchant_account.merchant_id, &connector_id.to_string(), )); @@ -487,7 +487,7 @@ pub fn validate_dispute_stage_and_dispute_status( ) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_accept_dispute_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, @@ -580,7 +580,7 @@ pub async fn construct_accept_dispute_router_data<'a>( Ok(router_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_submit_evidence_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, @@ -672,7 +672,7 @@ pub async fn construct_submit_evidence_router_data<'a>( Ok(router_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn construct_upload_file_router_data<'a>( state: &'a SessionState, @@ -770,7 +770,7 @@ pub async fn construct_upload_file_router_data<'a>( Ok(router_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_defend_dispute_router_data<'a>( state: &'a SessionState, payment_intent: &'a storage::PaymentIntent, @@ -865,7 +865,7 @@ pub async fn construct_defend_dispute_router_data<'a>( Ok(router_data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn construct_retrieve_file_router_data<'a>( state: &'a SessionState, merchant_account: &domain::MerchantAccount, diff --git a/crates/router/src/core/verification.rs b/crates/router/src/core/verification.rs index d84e3ef7932..1880d80e8a9 100644 --- a/crates/router/src/core/verification.rs +++ b/crates/router/src/core/verification.rs @@ -4,12 +4,7 @@ use common_utils::{errors::CustomResult, request::RequestContent}; use error_stack::ResultExt; use masking::ExposeInterface; -use crate::{ - core::errors::api_error_response, - headers, logger, - routes::SessionState, - services, -}; +use crate::{core::errors::api_error_response, headers, logger, routes::SessionState, services}; const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant"; diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs index 769ee4ec370..ef57388e78f 100644 --- a/crates/router/src/core/webhooks.rs +++ b/crates/router/src/core/webhooks.rs @@ -203,7 +203,7 @@ pub async fn payments_incoming_webhook_flow( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] #[allow(clippy::too_many_arguments)] pub async fn refunds_incoming_webhook_flow( state: SessionState, @@ -498,7 +498,7 @@ pub async fn mandates_incoming_webhook_flow( } #[allow(clippy::too_many_arguments)] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn disputes_incoming_webhook_flow( state: SessionState, merchant_account: domain::MerchantAccount, @@ -658,7 +658,7 @@ async fn bank_transfer_webhook_flow( } #[allow(clippy::too_many_arguments)] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) async fn create_event_and_trigger_outgoing_webhook( state: SessionState, merchant_account: domain::MerchantAccount, @@ -798,7 +798,7 @@ pub(crate) async fn create_event_and_trigger_outgoing_webhook( } #[allow(clippy::too_many_arguments)] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) async fn trigger_webhook_and_raise_event( state: SessionState, business_profile: diesel_models::business_profile::BusinessProfile, @@ -1327,7 +1327,7 @@ pub async fn webhooks_wrapper( state: SessionState, req_state: ReqState, diff --git a/crates/router/src/core/webhooks/webhook_events.rs b/crates/router/src/core/webhooks/webhook_events.rs index 356c7637cc4..0db347c8198 100644 --- a/crates/router/src/core/webhooks/webhook_events.rs +++ b/crates/router/src/core/webhooks/webhook_events.rs @@ -18,7 +18,7 @@ enum MerchantAccountOrBusinessProfile { BusinessProfile(storage::BusinessProfile), } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn list_initial_delivery_attempts( state: SessionState, merchant_id_or_profile_id: String, @@ -106,7 +106,7 @@ pub async fn list_initial_delivery_attempts( )) } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn list_delivery_attempts( state: SessionState, merchant_id_or_profile_id: String, @@ -155,7 +155,7 @@ pub async fn list_delivery_attempts( } } -//#\[instrument\(skip(state))] +#[instrument(skip(state))] pub async fn retry_delivery_attempt( state: SessionState, merchant_id_or_profile_id: String, diff --git a/crates/router/src/db/address.rs b/crates/router/src/db/address.rs index 54dad91b72a..8eb281184f6 100644 --- a/crates/router/src/db/address.rs +++ b/crates/router/src/db/address.rs @@ -94,7 +94,7 @@ mod storage { }; #[async_trait::async_trait] impl AddressInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_address_by_address_id( &self, address_id: &str, @@ -113,7 +113,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_address_by_merchant_id_payment_id_address_id( &self, merchant_id: &str, @@ -140,7 +140,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_address( &self, address_id: String, @@ -160,7 +160,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_address_for_payments( &self, this: domain::Address, @@ -186,7 +186,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_address_for_payments( &self, _payment_id: &str, @@ -211,7 +211,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_address_for_customers( &self, address: domain::Address, @@ -234,7 +234,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_address_by_merchant_id_customer_id( &self, customer_id: &str, @@ -293,7 +293,7 @@ mod storage { }; #[async_trait::async_trait] impl AddressInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_address_by_address_id( &self, address_id: &str, @@ -312,7 +312,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_address_by_merchant_id_payment_id_address_id( &self, merchant_id: &str, @@ -361,7 +361,7 @@ mod storage { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_address( &self, address_id: String, @@ -381,7 +381,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_address_for_payments( &self, this: domain::Address, @@ -452,7 +452,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_address_for_payments( &self, payment_id: &str, @@ -544,7 +544,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_address_for_customers( &self, address: domain::Address, @@ -567,7 +567,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_address_by_merchant_id_customer_id( &self, customer_id: &str, diff --git a/crates/router/src/db/api_keys.rs b/crates/router/src/db/api_keys.rs index cbfd602a847..a23b3f0f7af 100644 --- a/crates/router/src/db/api_keys.rs +++ b/crates/router/src/db/api_keys.rs @@ -53,7 +53,7 @@ pub trait ApiKeyInterface { #[async_trait::async_trait] impl ApiKeyInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_api_key( &self, api_key: storage::ApiKeyNew, @@ -65,7 +65,7 @@ impl ApiKeyInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_api_key( &self, merchant_id: String, @@ -113,7 +113,7 @@ impl ApiKeyInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn revoke_api_key( &self, merchant_id: &str, @@ -155,7 +155,7 @@ impl ApiKeyInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_api_key_by_merchant_id_key_id_optional( &self, merchant_id: &str, @@ -167,7 +167,7 @@ impl ApiKeyInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_api_key_by_hash_optional( &self, hashed_api_key: storage::HashedApiKey, @@ -197,7 +197,7 @@ impl ApiKeyInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_api_keys_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/authentication.rs b/crates/router/src/db/authentication.rs index b6a48a54d4d..a2c7f050052 100644 --- a/crates/router/src/db/authentication.rs +++ b/crates/router/src/db/authentication.rs @@ -31,7 +31,7 @@ pub trait AuthenticationInterface { #[async_trait::async_trait] impl AuthenticationInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_authentication( &self, authentication: storage::AuthenticationNew, @@ -43,7 +43,7 @@ impl AuthenticationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_authentication_by_merchant_id_authentication_id( &self, merchant_id: String, @@ -59,7 +59,7 @@ impl AuthenticationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_authentication_by_merchant_id_authentication_id( &self, previous_state: storage::Authentication, diff --git a/crates/router/src/db/authorization.rs b/crates/router/src/db/authorization.rs index 05d69b77944..7b7802d64e5 100644 --- a/crates/router/src/db/authorization.rs +++ b/crates/router/src/db/authorization.rs @@ -32,7 +32,7 @@ pub trait AuthorizationInterface { #[async_trait::async_trait] impl AuthorizationInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_authorization( &self, authorization: storage::AuthorizationNew, @@ -44,7 +44,7 @@ impl AuthorizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_all_authorizations_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -56,7 +56,7 @@ impl AuthorizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_authorization_by_merchant_id_authorization_id( &self, merchant_id: String, diff --git a/crates/router/src/db/blocklist.rs b/crates/router/src/db/blocklist.rs index f68b0708131..4a7236c95a7 100644 --- a/crates/router/src/db/blocklist.rs +++ b/crates/router/src/db/blocklist.rs @@ -45,7 +45,7 @@ pub trait BlocklistInterface { #[async_trait::async_trait] impl BlocklistInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_entry( &self, pm_blocklist: storage::BlocklistNew, @@ -57,7 +57,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -69,7 +69,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_blocklist_entries_by_merchant_id( &self, merchant_id: &str, @@ -80,7 +80,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_blocklist_entries_by_merchant_id_data_kind( &self, merchant_id: &str, @@ -100,7 +100,7 @@ impl BlocklistInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -115,7 +115,7 @@ impl BlocklistInterface for Store { #[async_trait::async_trait] impl BlocklistInterface for MockDb { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_entry( &self, _pm_blocklist: storage::BlocklistNew, @@ -159,7 +159,7 @@ impl BlocklistInterface for MockDb { #[async_trait::async_trait] impl BlocklistInterface for KafkaStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_entry( &self, pm_blocklist: storage::BlocklistNew, @@ -167,7 +167,7 @@ impl BlocklistInterface for KafkaStore { self.diesel_store.insert_blocklist_entry(pm_blocklist).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -178,7 +178,7 @@ impl BlocklistInterface for KafkaStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_blocklist_entry_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -189,7 +189,7 @@ impl BlocklistInterface for KafkaStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_blocklist_entries_by_merchant_id_data_kind( &self, merchant_id: &str, @@ -202,7 +202,7 @@ impl BlocklistInterface for KafkaStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_blocklist_entries_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/blocklist_fingerprint.rs b/crates/router/src/db/blocklist_fingerprint.rs index 7d7f8648725..65671555c7f 100644 --- a/crates/router/src/db/blocklist_fingerprint.rs +++ b/crates/router/src/db/blocklist_fingerprint.rs @@ -26,7 +26,7 @@ pub trait BlocklistFingerprintInterface { #[async_trait::async_trait] impl BlocklistFingerprintInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_fingerprint_entry( &self, pm_fingerprint_new: storage::BlocklistFingerprintNew, @@ -38,7 +38,7 @@ impl BlocklistFingerprintInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_blocklist_fingerprint_by_merchant_id_fingerprint_id( &self, merchant_id: &str, @@ -75,7 +75,7 @@ impl BlocklistFingerprintInterface for MockDb { #[async_trait::async_trait] impl BlocklistFingerprintInterface for KafkaStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_fingerprint_entry( &self, pm_fingerprint_new: storage::BlocklistFingerprintNew, @@ -85,7 +85,7 @@ impl BlocklistFingerprintInterface for KafkaStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_blocklist_fingerprint_by_merchant_id_fingerprint_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/blocklist_lookup.rs b/crates/router/src/db/blocklist_lookup.rs index cfd7cde6134..0f796946beb 100644 --- a/crates/router/src/db/blocklist_lookup.rs +++ b/crates/router/src/db/blocklist_lookup.rs @@ -32,7 +32,7 @@ pub trait BlocklistLookupInterface { #[async_trait::async_trait] impl BlocklistLookupInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_lookup_entry( &self, blocklist_lookup_entry: storage::BlocklistLookupNew, @@ -44,7 +44,7 @@ impl BlocklistLookupInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, @@ -56,7 +56,7 @@ impl BlocklistLookupInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, @@ -71,7 +71,7 @@ impl BlocklistLookupInterface for Store { #[async_trait::async_trait] impl BlocklistLookupInterface for MockDb { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_lookup_entry( &self, _blocklist_lookup_entry: storage::BlocklistLookupNew, @@ -98,7 +98,7 @@ impl BlocklistLookupInterface for MockDb { #[async_trait::async_trait] impl BlocklistLookupInterface for KafkaStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_blocklist_lookup_entry( &self, blocklist_lookup_entry: storage::BlocklistLookupNew, @@ -108,7 +108,7 @@ impl BlocklistLookupInterface for KafkaStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, @@ -119,7 +119,7 @@ impl BlocklistLookupInterface for KafkaStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint( &self, merchant_id: &str, diff --git a/crates/router/src/db/business_profile.rs b/crates/router/src/db/business_profile.rs index c76a5056657..4d5a94b370a 100644 --- a/crates/router/src/db/business_profile.rs +++ b/crates/router/src/db/business_profile.rs @@ -47,7 +47,7 @@ pub trait BusinessProfileInterface { #[async_trait::async_trait] impl BusinessProfileInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_business_profile( &self, business_profile: business_profile::BusinessProfileNew, @@ -59,7 +59,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_business_profile_by_profile_id( &self, profile_id: &str, @@ -70,7 +70,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_business_profile_by_profile_name_merchant_id( &self, profile_name: &str, @@ -86,7 +86,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_business_profile_by_profile_id( &self, current_state: business_profile::BusinessProfile, @@ -102,7 +102,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_business_profile_by_profile_id_merchant_id( &self, profile_id: &str, @@ -118,7 +118,7 @@ impl BusinessProfileInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_business_profile_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/cache.rs b/crates/router/src/db/cache.rs index 592648494cb..7f2462b3fc8 100644 --- a/crates/router/src/db/cache.rs +++ b/crates/router/src/db/cache.rs @@ -13,7 +13,7 @@ use crate::{ core::errors::{self, CustomResult}, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_or_populate_redis( store: &dyn StorageInterface, key: impl AsRef, @@ -54,7 +54,7 @@ where } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn get_or_populate_in_memory( store: &dyn StorageInterface, key: &str, @@ -76,7 +76,7 @@ where } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn redact_cache( store: &dyn StorageInterface, key: &str, @@ -104,7 +104,7 @@ where Ok(data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn publish_into_redact_channel<'a, K: IntoIterator> + Send>( store: &dyn StorageInterface, keys: K, @@ -130,7 +130,7 @@ pub async fn publish_into_redact_channel<'a, K: IntoIterator()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn publish_and_redact<'a, T, F, Fut>( store: &dyn StorageInterface, key: CacheKind<'a>, @@ -145,7 +145,7 @@ where Ok(data) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn publish_and_redact_multiple<'a, T, F, Fut, K>( store: &dyn StorageInterface, keys: K, diff --git a/crates/router/src/db/capture.rs b/crates/router/src/db/capture.rs index 1c9c8d02b20..48aad6a9e3f 100644 --- a/crates/router/src/db/capture.rs +++ b/crates/router/src/db/capture.rs @@ -45,7 +45,7 @@ mod storage { #[async_trait::async_trait] impl CaptureInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_capture( &self, capture: CaptureNew, @@ -61,7 +61,7 @@ mod storage { db_call().await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_capture_with_capture_id( &self, this: Capture, @@ -77,7 +77,7 @@ mod storage { db_call().await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_all_captures_by_merchant_id_payment_id_authorized_attempt_id( &self, merchant_id: &str, @@ -116,7 +116,7 @@ mod storage { #[async_trait::async_trait] impl CaptureInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_capture( &self, capture: CaptureNew, @@ -132,7 +132,7 @@ mod storage { db_call().await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_capture_with_capture_id( &self, this: Capture, @@ -148,7 +148,7 @@ mod storage { db_call().await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_all_captures_by_merchant_id_payment_id_authorized_attempt_id( &self, merchant_id: &str, @@ -203,7 +203,7 @@ impl CaptureInterface for MockDb { Ok(capture) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_capture_with_capture_id( &self, _this: types::Capture, diff --git a/crates/router/src/db/cards_info.rs b/crates/router/src/db/cards_info.rs index 2ccb1946e2f..68bd90946b6 100644 --- a/crates/router/src/db/cards_info.rs +++ b/crates/router/src/db/cards_info.rs @@ -19,7 +19,7 @@ pub trait CardsInfoInterface { #[async_trait::async_trait] impl CardsInfoInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_card_info( &self, card_iin: &str, @@ -33,7 +33,7 @@ impl CardsInfoInterface for Store { #[async_trait::async_trait] impl CardsInfoInterface for MockDb { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_card_info( &self, card_iin: &str, diff --git a/crates/router/src/db/configs.rs b/crates/router/src/db/configs.rs index 9cce2b447ff..8deb4bdf6f6 100644 --- a/crates/router/src/db/configs.rs +++ b/crates/router/src/db/configs.rs @@ -59,7 +59,7 @@ pub trait ConfigInterface { #[async_trait::async_trait] impl ConfigInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_config( &self, config: storage::ConfigNew, @@ -71,7 +71,7 @@ impl ConfigInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_config_in_database( &self, key: &str, @@ -84,7 +84,7 @@ impl ConfigInterface for Store { } //update in DB and remove in redis and cache - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_config_by_key( &self, key: &str, @@ -96,7 +96,7 @@ impl ConfigInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_config_by_key_from_db( &self, key: &str, @@ -108,7 +108,7 @@ impl ConfigInterface for Store { } //check in cache, then redis then finally DB, and on the way back populate redis and cache - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_config_by_key( &self, key: &str, @@ -122,7 +122,7 @@ impl ConfigInterface for Store { cache::get_or_populate_in_memory(self, key, find_config_by_key_from_db, &CONFIG_CACHE).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_config_by_key_unwrap_or( &self, key: &str, @@ -160,7 +160,7 @@ impl ConfigInterface for Store { cache::get_or_populate_in_memory(self, key, find_else_unwrap_or, &CONFIG_CACHE).await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_config_by_key( &self, key: &str, @@ -182,7 +182,7 @@ impl ConfigInterface for Store { #[async_trait::async_trait] impl ConfigInterface for MockDb { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_config( &self, config: storage::ConfigNew, diff --git a/crates/router/src/db/customers.rs b/crates/router/src/db/customers.rs index ae0b5825952..00fb7e4a08f 100644 --- a/crates/router/src/db/customers.rs +++ b/crates/router/src/db/customers.rs @@ -97,7 +97,7 @@ mod storage { #[async_trait::async_trait] impl CustomerInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] // check customer not found in kv and fallback to db async fn find_customer_optional_by_customer_id_merchant_id( &self, @@ -160,7 +160,7 @@ mod storage { }) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_customer_by_customer_id_merchant_id( &self, customer_id: String, @@ -232,7 +232,7 @@ mod storage { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -289,7 +289,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_customers_by_merchant_id( &self, merchant_id: &str, @@ -315,7 +315,7 @@ mod storage { Ok(customers) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_customer( &self, customer_data: domain::Customer, @@ -382,7 +382,7 @@ mod storage { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -427,7 +427,7 @@ mod storage { #[async_trait::async_trait] impl CustomerInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_customer_optional_by_customer_id_merchant_id( &self, customer_id: &str, @@ -463,7 +463,7 @@ mod storage { }) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_customer_by_customer_id_merchant_id( &self, customer_id: String, @@ -490,7 +490,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -521,7 +521,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_customers_by_merchant_id( &self, merchant_id: &str, @@ -547,7 +547,7 @@ mod storage { Ok(customers) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_customer( &self, customer_data: domain::Customer, @@ -570,7 +570,7 @@ mod storage { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_customer_by_customer_id_merchant_id( &self, customer_id: &str, @@ -639,7 +639,7 @@ impl CustomerInterface for MockDb { Ok(customers) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_customer_by_customer_id_merchant_id( &self, _customer_id: String, diff --git a/crates/router/src/db/dashboard_metadata.rs b/crates/router/src/db/dashboard_metadata.rs index 509da09b853..5267985e1ac 100644 --- a/crates/router/src/db/dashboard_metadata.rs +++ b/crates/router/src/db/dashboard_metadata.rs @@ -56,7 +56,7 @@ pub trait DashboardMetadataInterface { #[async_trait::async_trait] impl DashboardMetadataInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_metadata( &self, metadata: storage::DashboardMetadataNew, @@ -68,7 +68,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_metadata( &self, user_id: Option, @@ -90,7 +90,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_user_scoped_dashboard_metadata( &self, user_id: &str, @@ -110,7 +110,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_scoped_dashboard_metadata( &self, merchant_id: &str, @@ -128,7 +128,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_all_user_scoped_dashboard_metadata_by_merchant_id( &self, user_id: &str, @@ -144,7 +144,7 @@ impl DashboardMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_user_scoped_dashboard_metadata_by_merchant_id_data_key( &self, user_id: &str, diff --git a/crates/router/src/db/dispute.rs b/crates/router/src/db/dispute.rs index 26106ff3156..0fe5f3d7666 100644 --- a/crates/router/src/db/dispute.rs +++ b/crates/router/src/db/dispute.rs @@ -49,7 +49,7 @@ pub trait DisputeInterface { #[async_trait::async_trait] impl DisputeInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_dispute( &self, dispute: storage::DisputeNew, @@ -61,7 +61,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_by_merchant_id_payment_id_connector_dispute_id( &self, merchant_id: &str, @@ -79,7 +79,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_dispute_by_merchant_id_dispute_id( &self, merchant_id: &str, @@ -91,7 +91,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_disputes_by_merchant_id( &self, merchant_id: &str, @@ -103,7 +103,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_disputes_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -115,7 +115,7 @@ impl DisputeInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_dispute( &self, this: storage::Dispute, diff --git a/crates/router/src/db/ephemeral_key.rs b/crates/router/src/db/ephemeral_key.rs index 79d137f22c7..a1d43e83b87 100644 --- a/crates/router/src/db/ephemeral_key.rs +++ b/crates/router/src/db/ephemeral_key.rs @@ -40,7 +40,7 @@ mod storage { #[async_trait::async_trait] impl EphemeralKeyInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn create_ephemeral_key( &self, new: EphemeralKeyNew, @@ -94,7 +94,7 @@ mod storage { Err(er) => Err(er).change_context(errors::StorageError::KVError), } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_ephemeral_key( &self, key: &str, diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs index bf753dcfe68..53480ed431b 100644 --- a/crates/router/src/db/events.rs +++ b/crates/router/src/db/events.rs @@ -93,7 +93,7 @@ where #[async_trait::async_trait] impl EventInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_event( &self, event: domain::Event, @@ -112,7 +112,7 @@ impl EventInterface for Store { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_event_by_merchant_id_event_id( &self, merchant_id: &str, @@ -128,7 +128,7 @@ impl EventInterface for Store { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_initial_events_by_merchant_id_primary_object_id( &self, merchant_id: &str, @@ -158,7 +158,7 @@ impl EventInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_initial_events_by_merchant_id_constraints( &self, merchant_id: &str, @@ -194,7 +194,7 @@ impl EventInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_events_by_merchant_id_initial_attempt_id( &self, merchant_id: &str, @@ -224,7 +224,7 @@ impl EventInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_initial_events_by_profile_id_primary_object_id( &self, profile_id: &str, @@ -254,7 +254,7 @@ impl EventInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_initial_events_by_profile_id_constraints( &self, profile_id: &str, @@ -290,7 +290,7 @@ impl EventInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_events_by_profile_id_initial_attempt_id( &self, profile_id: &str, @@ -316,7 +316,7 @@ impl EventInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_event_by_merchant_id_event_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/file.rs b/crates/router/src/db/file.rs index 29f4199d6fd..da28404971d 100644 --- a/crates/router/src/db/file.rs +++ b/crates/router/src/db/file.rs @@ -36,7 +36,7 @@ pub trait FileMetadataInterface { #[async_trait::async_trait] impl FileMetadataInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_file_metadata( &self, file: storage::FileMetadataNew, @@ -47,7 +47,7 @@ impl FileMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_file_metadata_by_merchant_id_file_id( &self, merchant_id: &str, @@ -59,7 +59,7 @@ impl FileMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_file_metadata_by_merchant_id_file_id( &self, merchant_id: &str, @@ -71,7 +71,7 @@ impl FileMetadataInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_file_metadata( &self, this: storage::FileMetadata, diff --git a/crates/router/src/db/fraud_check.rs b/crates/router/src/db/fraud_check.rs index f2a32bbf4f7..34818260364 100644 --- a/crates/router/src/db/fraud_check.rs +++ b/crates/router/src/db/fraud_check.rs @@ -37,7 +37,7 @@ pub trait FraudCheckInterface { #[async_trait::async_trait] impl FraudCheckInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_fraud_check_response( &self, new: storage::FraudCheckNew, @@ -48,7 +48,7 @@ impl FraudCheckInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_fraud_check_response_with_attempt_id( &self, this: FraudCheck, @@ -60,7 +60,7 @@ impl FraudCheckInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_fraud_check_by_payment_id( &self, payment_id: String, @@ -72,7 +72,7 @@ impl FraudCheckInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_fraud_check_by_payment_id_if_present( &self, payment_id: String, @@ -120,7 +120,7 @@ impl FraudCheckInterface for MockDb { #[cfg(feature = "kafka_events")] #[async_trait::async_trait] impl FraudCheckInterface for super::KafkaStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_fraud_check_response( &self, _new: storage::FraudCheckNew, @@ -128,7 +128,7 @@ impl FraudCheckInterface for super::KafkaStore { Err(errors::StorageError::MockDbError)? } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_fraud_check_response_with_attempt_id( &self, _this: FraudCheck, @@ -137,7 +137,7 @@ impl FraudCheckInterface for super::KafkaStore { Err(errors::StorageError::MockDbError)? } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_fraud_check_by_payment_id( &self, _payment_id: String, diff --git a/crates/router/src/db/gsm.rs b/crates/router/src/db/gsm.rs index 2718e6d702f..1aa96e14c18 100644 --- a/crates/router/src/db/gsm.rs +++ b/crates/router/src/db/gsm.rs @@ -53,7 +53,7 @@ pub trait GsmInterface { #[async_trait::async_trait] impl GsmInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn add_gsm_rule( &self, rule: storage::GatewayStatusMappingNew, @@ -64,7 +64,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_gsm_decision( &self, connector: String, @@ -81,7 +81,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_gsm_rule( &self, connector: String, @@ -96,7 +96,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_gsm_rule( &self, connector: String, @@ -112,7 +112,7 @@ impl GsmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_gsm_rule( &self, connector: String, diff --git a/crates/router/src/db/health_check.rs b/crates/router/src/db/health_check.rs index 3f10b96fe29..5423fef9557 100644 --- a/crates/router/src/db/health_check.rs +++ b/crates/router/src/db/health_check.rs @@ -17,7 +17,7 @@ pub trait HealthCheckDbInterface { #[async_trait::async_trait] impl HealthCheckDbInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> { let conn = connection::pg_connection_write(self) .await diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 095c26e05ad..93e8116e1ac 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -74,15 +74,17 @@ use crate::{ #[derive(Clone)] pub struct KafkaStore { + tenant_id: String, kafka_producer: KafkaProducer, pub diesel_store: Store, } impl KafkaStore { - pub async fn new(store: Store, kafka_producer: KafkaProducer) -> Self { + pub async fn new(store: Store, kafka_producer: KafkaProducer, tenant_id: String) -> Self { Self { kafka_producer, diesel_store: store, + tenant_id, } } } @@ -1059,8 +1061,9 @@ impl QueueInterface for KafkaStore { entry_id: &RedisEntryId, fields: Vec<(&str, String)>, ) -> CustomResult<(), RedisError> { + let stream_name = format!("{}_{}", &self.tenant_id, stream); self.diesel_store - .stream_append_entry(stream, entry_id, fields) + .stream_append_entry(&stream_name, entry_id, fields) .await } diff --git a/crates/router/src/db/locker_mock_up.rs b/crates/router/src/db/locker_mock_up.rs index 00c92b2b2f2..ea0e70c5bb9 100644 --- a/crates/router/src/db/locker_mock_up.rs +++ b/crates/router/src/db/locker_mock_up.rs @@ -28,7 +28,7 @@ pub trait LockerMockUpInterface { #[async_trait::async_trait] impl LockerMockUpInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_locker_by_card_id( &self, card_id: &str, @@ -39,7 +39,7 @@ impl LockerMockUpInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_locker_mock_up( &self, new: storage::LockerMockUpNew, @@ -50,7 +50,7 @@ impl LockerMockUpInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_locker_mock_up( &self, card_id: &str, diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs index bef7ed784ff..273d34a68af 100644 --- a/crates/router/src/db/mandate.rs +++ b/crates/router/src/db/mandate.rs @@ -49,7 +49,7 @@ pub trait MandateInterface { #[async_trait::async_trait] impl MandateInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_mandate_by_merchant_id_mandate_id( &self, merchant_id: &str, @@ -61,7 +61,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_mandate_by_merchant_id_connector_mandate_id( &self, merchant_id: &str, @@ -77,7 +77,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_mandate_by_merchant_id_customer_id( &self, merchant_id: &str, @@ -89,7 +89,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_mandate_by_merchant_id_mandate_id( &self, merchant_id: &str, @@ -102,7 +102,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_mandates_by_merchant_id( &self, merchant_id: &str, @@ -114,7 +114,7 @@ impl MandateInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_mandate( &self, mandate: storage::MandateNew, diff --git a/crates/router/src/db/merchant_account.rs b/crates/router/src/db/merchant_account.rs index 7a2c3a5acff..08d0c279047 100644 --- a/crates/router/src/db/merchant_account.rs +++ b/crates/router/src/db/merchant_account.rs @@ -79,7 +79,7 @@ where #[async_trait::async_trait] impl MerchantAccountInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_merchant( &self, merchant_account: domain::MerchantAccount, @@ -98,7 +98,7 @@ impl MerchantAccountInterface for Store { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_account_by_merchant_id( &self, merchant_id: &str, @@ -130,7 +130,7 @@ impl MerchantAccountInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_merchant( &self, this: domain::MerchantAccount, @@ -156,7 +156,7 @@ impl MerchantAccountInterface for Store { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_specific_fields_in_merchant( &self, merchant_id: &str, @@ -182,7 +182,7 @@ impl MerchantAccountInterface for Store { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_account_by_publishable_key( &self, publishable_key: &str, @@ -229,7 +229,7 @@ impl MerchantAccountInterface for Store { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_merchant_accounts_by_organization_id( &self, organization_id: &str, @@ -269,7 +269,7 @@ impl MerchantAccountInterface for Store { Ok(merchant_accounts) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_merchant_account_by_merchant_id( &self, merchant_id: &str, @@ -305,7 +305,7 @@ impl MerchantAccountInterface for Store { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_multiple_merchant_accounts( &self, merchant_ids: Vec, diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index 0f83b823abb..b7c85560804 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -37,7 +37,7 @@ pub trait ConnectorAccessToken { #[async_trait::async_trait] impl ConnectorAccessToken for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_access_token( &self, merchant_id: &str, @@ -64,7 +64,7 @@ impl ConnectorAccessToken for Store { Ok(access_token) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn set_access_token( &self, merchant_id: &str, @@ -168,7 +168,7 @@ where #[async_trait::async_trait] impl MerchantConnectorAccountInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_connector_account_by_merchant_id_connector_label( &self, merchant_id: &str, @@ -213,7 +213,7 @@ impl MerchantConnectorAccountInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_connector_account_by_profile_id_connector_name( &self, profile_id: &str, @@ -258,7 +258,7 @@ impl MerchantConnectorAccountInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_connector_account_by_merchant_id_connector_name( &self, merchant_id: &str, @@ -287,7 +287,7 @@ impl MerchantConnectorAccountInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id( &self, merchant_id: &str, @@ -329,7 +329,7 @@ impl MerchantConnectorAccountInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_merchant_connector_account( &self, t: domain::MerchantConnectorAccount, @@ -350,7 +350,7 @@ impl MerchantConnectorAccountInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_merchant_connector_account_by_merchant_id_and_disabled_list( &self, merchant_id: &str, @@ -375,7 +375,7 @@ impl MerchantConnectorAccountInterface for Store { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_merchant_connector_account( &self, this: domain::MerchantConnectorAccount, @@ -433,7 +433,7 @@ impl MerchantConnectorAccountInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_merchant_connector_account_by_merchant_id_merchant_connector_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/merchant_key_store.rs b/crates/router/src/db/merchant_key_store.rs index 58ae04b54c2..f857ab9d61e 100644 --- a/crates/router/src/db/merchant_key_store.rs +++ b/crates/router/src/db/merchant_key_store.rs @@ -44,7 +44,7 @@ pub trait MerchantKeyStoreInterface { #[async_trait::async_trait] impl MerchantKeyStoreInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_merchant_key_store( &self, merchant_key_store: domain::MerchantKeyStore, @@ -63,7 +63,7 @@ impl MerchantKeyStoreInterface for Store { .change_context(errors::StorageError::DecryptionError) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_merchant_key_store_by_merchant_id( &self, merchant_id: &str, @@ -105,7 +105,7 @@ impl MerchantKeyStoreInterface for Store { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_merchant_key_store_by_merchant_id( &self, merchant_id: &str, @@ -138,7 +138,7 @@ impl MerchantKeyStoreInterface for Store { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_multiple_key_stores( &self, merchant_ids: Vec, diff --git a/crates/router/src/db/organization.rs b/crates/router/src/db/organization.rs index fe14df236e4..0fe9ea9a180 100644 --- a/crates/router/src/db/organization.rs +++ b/crates/router/src/db/organization.rs @@ -26,7 +26,7 @@ pub trait OrganizationInterface { #[async_trait::async_trait] impl OrganizationInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_organization( &self, organization: storage::OrganizationNew, @@ -38,7 +38,7 @@ impl OrganizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_organization_by_org_id( &self, org_id: &str, @@ -49,7 +49,7 @@ impl OrganizationInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_organization_by_org_id( &self, org_id: &str, diff --git a/crates/router/src/db/payment_link.rs b/crates/router/src/db/payment_link.rs index a8cb5da4197..c3f78767931 100644 --- a/crates/router/src/db/payment_link.rs +++ b/crates/router/src/db/payment_link.rs @@ -30,7 +30,7 @@ pub trait PaymentLinkInterface { #[async_trait::async_trait] impl PaymentLinkInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_link_by_payment_link_id( &self, payment_link_id: &str, @@ -41,7 +41,7 @@ impl PaymentLinkInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payment_link( &self, payment_link_config: storage::PaymentLinkNew, @@ -53,7 +53,7 @@ impl PaymentLinkInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_payment_link_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/payment_method.rs b/crates/router/src/db/payment_method.rs index 3b8c404d7ee..50a70ec58ab 100644 --- a/crates/router/src/db/payment_method.rs +++ b/crates/router/src/db/payment_method.rs @@ -84,7 +84,7 @@ pub trait PaymentMethodInterface { // #[async_trait::async_trait] // impl PaymentMethodInterface for Store { -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn find_payment_method( // &self, // payment_method_id: &str, @@ -128,7 +128,7 @@ pub trait PaymentMethodInterface { // } // } -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn find_payment_method_by_locker_id( // &self, // locker_id: &str, @@ -172,7 +172,7 @@ pub trait PaymentMethodInterface { // } // } // // not supported in kv -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn get_payment_method_count_by_customer_id_merchant_id_status( // &self, // customer_id: &str, @@ -190,7 +190,7 @@ pub trait PaymentMethodInterface { // .map_err(|error| report!(errors::StorageError::from(error))) // } -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn insert_payment_method( // &self, // payment_method_new: storage_types::PaymentMethodNew, @@ -270,7 +270,7 @@ pub trait PaymentMethodInterface { // } // } -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn update_payment_method( // &self, // payment_method: storage_types::PaymentMethod, @@ -331,7 +331,7 @@ pub trait PaymentMethodInterface { // } // } -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn find_payment_method_by_customer_id_merchant_id_list( // &self, // customer_id: &str, @@ -349,7 +349,7 @@ pub trait PaymentMethodInterface { // .map_err(|error| report!(errors::StorageError::from(error))) // } -// //#\[instrument\(skip_all)] +// #[instrument(skip_all)] // async fn find_payment_method_by_customer_id_merchant_id_status( // &self, // customer_id: &str, @@ -399,7 +399,7 @@ mod storage { }; #[async_trait::async_trait] impl PaymentMethodInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_method( &self, payment_method_id: &str, @@ -411,7 +411,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_method_by_locker_id( &self, locker_id: &str, @@ -423,7 +423,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_payment_method_count_by_customer_id_merchant_id_status( &self, customer_id: &str, @@ -441,7 +441,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payment_method( &self, payment_method_new: storage_types::PaymentMethodNew, @@ -454,7 +454,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payment_method( &self, payment_method: storage_types::PaymentMethod, @@ -468,7 +468,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_method_by_customer_id_merchant_id_list( &self, customer_id: &str, @@ -486,7 +486,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_method_by_customer_id_merchant_id_status( &self, customer_id: &str, diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs index 106143ccfb9..ca3921d6199 100644 --- a/crates/router/src/db/refund.rs +++ b/crates/router/src/db/refund.rs @@ -106,7 +106,7 @@ mod storage { #[async_trait::async_trait] impl RefundInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_internal_reference_id_merchant_id( &self, internal_reference_id: &str, @@ -123,7 +123,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_refund( &self, new: storage_types::RefundNew, @@ -135,7 +135,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_merchant_id_connector_transaction_id( &self, merchant_id: &str, @@ -152,7 +152,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_refund( &self, this: storage_types::Refund, @@ -165,7 +165,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_merchant_id_refund_id( &self, merchant_id: &str, @@ -178,7 +178,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_merchant_id_connector_refund_id_connector( &self, merchant_id: &str, @@ -197,7 +197,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_payment_id_merchant_id( &self, payment_id: &str, @@ -211,7 +211,7 @@ mod storage { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_refund_by_constraints( &self, merchant_id: &str, @@ -233,7 +233,7 @@ mod storage { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_refund_by_meta_constraints( &self, merchant_id: &str, @@ -250,7 +250,7 @@ mod storage { .map_err(|error|report!(errors::StorageError::from(error))) } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_total_count_of_refunds( &self, merchant_id: &str, @@ -288,7 +288,7 @@ mod storage { }; #[async_trait::async_trait] impl RefundInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_internal_reference_id_merchant_id( &self, internal_reference_id: &str, @@ -335,7 +335,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_refund( &self, new: storage_types::RefundNew, @@ -468,7 +468,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_merchant_id_connector_transaction_id( &self, merchant_id: &str, @@ -519,7 +519,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_refund( &self, this: storage_types::Refund, @@ -575,7 +575,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_merchant_id_refund_id( &self, merchant_id: &str, @@ -618,7 +618,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_merchant_id_connector_refund_id_connector( &self, merchant_id: &str, @@ -668,7 +668,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_refund_by_payment_id_merchant_id( &self, payment_id: &str, @@ -710,7 +710,7 @@ mod storage { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_refund_by_constraints( &self, merchant_id: &str, @@ -732,7 +732,7 @@ mod storage { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_refund_by_meta_constraints( &self, merchant_id: &str, @@ -746,7 +746,7 @@ mod storage { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_total_count_of_refunds( &self, merchant_id: &str, diff --git a/crates/router/src/db/reverse_lookup.rs b/crates/router/src/db/reverse_lookup.rs index 7311d7996e8..121ec06ec1f 100644 --- a/crates/router/src/db/reverse_lookup.rs +++ b/crates/router/src/db/reverse_lookup.rs @@ -38,7 +38,7 @@ mod storage { #[async_trait::async_trait] impl ReverseLookupInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_reverse_lookup( &self, new: ReverseLookupNew, @@ -50,7 +50,7 @@ mod storage { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_lookup_by_lookup_id( &self, id: &str, @@ -85,7 +85,7 @@ mod storage { #[async_trait::async_trait] impl ReverseLookupInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_reverse_lookup( &self, new: ReverseLookupNew, @@ -138,7 +138,7 @@ mod storage { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_lookup_by_lookup_id( &self, id: &str, diff --git a/crates/router/src/db/role.rs b/crates/router/src/db/role.rs index 5dbb1847082..54b7f6e38d4 100644 --- a/crates/router/src/db/role.rs +++ b/crates/router/src/db/role.rs @@ -49,7 +49,7 @@ pub trait RoleInterface { #[async_trait::async_trait] impl RoleInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_role( &self, role: storage::RoleNew, @@ -60,7 +60,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_role_by_role_id( &self, role_id: &str, @@ -71,7 +71,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_role_by_role_id_in_merchant_scope( &self, role_id: &str, @@ -84,7 +84,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_role_by_role_id( &self, role_id: &str, @@ -96,7 +96,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_role_by_role_id( &self, role_id: &str, @@ -107,7 +107,7 @@ impl RoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_all_roles( &self, merchant_id: &str, diff --git a/crates/router/src/db/routing_algorithm.rs b/crates/router/src/db/routing_algorithm.rs index a9370842895..f65933d8982 100644 --- a/crates/router/src/db/routing_algorithm.rs +++ b/crates/router/src/db/routing_algorithm.rs @@ -61,7 +61,7 @@ pub trait RoutingAlgorithmInterface { #[async_trait::async_trait] impl RoutingAlgorithmInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_routing_algorithm( &self, routing_algorithm: routing_storage::RoutingAlgorithm, @@ -73,7 +73,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_routing_algorithm_by_profile_id_algorithm_id( &self, profile_id: &str, @@ -89,7 +89,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_routing_algorithm_by_algorithm_id_merchant_id( &self, algorithm_id: &str, @@ -105,7 +105,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_routing_algorithm_metadata_by_algorithm_id_profile_id( &self, algorithm_id: &str, @@ -121,7 +121,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_routing_algorithm_metadata_by_profile_id( &self, profile_id: &str, @@ -136,7 +136,7 @@ impl RoutingAlgorithmInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_routing_algorithm_metadata_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/user.rs b/crates/router/src/db/user.rs index 822c37625c1..a96829a756e 100644 --- a/crates/router/src/db/user.rs +++ b/crates/router/src/db/user.rs @@ -53,7 +53,7 @@ pub trait UserInterface { #[async_trait::async_trait] impl UserInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_user( &self, user_data: storage::UserNew, @@ -65,7 +65,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_user_by_email( &self, user_email: &str, @@ -76,7 +76,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_user_by_id( &self, user_id: &str, @@ -87,7 +87,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_user_by_user_id( &self, user_id: &str, @@ -99,7 +99,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_user_by_email( &self, user_email: &str, @@ -111,7 +111,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_user_by_user_id( &self, user_id: &str, @@ -122,7 +122,7 @@ impl UserInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_users_and_roles_by_merchant_id( &self, merchant_id: &str, diff --git a/crates/router/src/db/user_role.rs b/crates/router/src/db/user_role.rs index 84522a18d50..2f61f70b2a8 100644 --- a/crates/router/src/db/user_role.rs +++ b/crates/router/src/db/user_role.rs @@ -65,7 +65,7 @@ pub trait UserRoleInterface { #[async_trait::async_trait] impl UserRoleInterface for Store { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_user_role( &self, user_role: storage::UserRoleNew, @@ -77,7 +77,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_user_role_by_user_id( &self, user_id: &str, @@ -88,7 +88,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_user_role_by_user_id_merchant_id( &self, user_id: &str, @@ -104,7 +104,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_user_role_by_user_id_merchant_id( &self, user_id: &str, @@ -122,7 +122,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_user_roles_by_user_id_org_id( &self, user_id: &str, @@ -140,7 +140,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn delete_user_role_by_user_id_merchant_id( &self, user_id: &str, @@ -156,7 +156,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn list_user_roles_by_user_id( &self, user_id: &str, @@ -167,7 +167,7 @@ impl UserRoleInterface for Store { .map_err(|error| report!(errors::StorageError::from(error))) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn transfer_org_ownership_between_users( &self, from_user_id: &str, diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rs index 91cf21c7075..bc534dde390 100644 --- a/crates/router/src/routes/admin.rs +++ b/crates/router/src/routes/admin.rs @@ -23,7 +23,7 @@ use crate::{ operation_id = "Create a Merchant Account", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountCreate))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountCreate))] pub async fn merchant_account_create( state: web::Data, req: HttpRequest, @@ -56,7 +56,7 @@ pub async fn merchant_account_create( operation_id = "Retrieve a Merchant Account", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountRetrieve))] pub async fn retrieve_merchant_account( state: web::Data, req: HttpRequest, @@ -89,7 +89,7 @@ pub async fn retrieve_merchant_account( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantAccountList))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantAccountList))] pub async fn merchant_account_list( state: web::Data, req: HttpRequest, @@ -125,7 +125,7 @@ pub async fn merchant_account_list( operation_id = "Update a Merchant Account", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountUpdate))] pub async fn update_merchant_account( state: web::Data, req: HttpRequest, @@ -168,7 +168,7 @@ pub async fn update_merchant_account( operation_id = "Delete a Merchant Account", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantsAccountDelete))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountDelete))] // #[delete("/{id}")] pub async fn delete_merchant_account( state: web::Data, @@ -205,7 +205,7 @@ pub async fn delete_merchant_account( operation_id = "Create a Merchant Connector", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsCreate))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsCreate))] pub async fn payment_connector_create( state: web::Data, req: HttpRequest, @@ -251,7 +251,7 @@ pub async fn payment_connector_create( operation_id = "Retrieve a Merchant Connector", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsRetrieve))] pub async fn payment_connector_retrieve( state: web::Data, req: HttpRequest, @@ -303,7 +303,7 @@ pub async fn payment_connector_retrieve( operation_id = "List all Merchant Connectors", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsList))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsList))] pub async fn payment_connector_list( state: web::Data, req: HttpRequest, @@ -350,7 +350,7 @@ pub async fn payment_connector_list( operation_id = "Update a Merchant Connector", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsUpdate))] pub async fn payment_connector_update( state: web::Data, req: HttpRequest, @@ -399,7 +399,7 @@ pub async fn payment_connector_update( operation_id = "Delete a Merchant Connector", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MerchantConnectorsDelete))] +#[instrument(skip_all, fields(flow = ?Flow::MerchantConnectorsDelete))] pub async fn payment_connector_delete( state: web::Data, req: HttpRequest, @@ -436,7 +436,7 @@ pub async fn payment_connector_delete( /// Merchant Account - Toggle KV /// /// Toggle KV mode for the Merchant Account -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn merchant_account_toggle_kv( state: web::Data, req: HttpRequest, @@ -458,7 +458,7 @@ pub async fn merchant_account_toggle_kv( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileCreate))] +#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileCreate))] pub async fn business_profile_create( state: web::Data, req: HttpRequest, @@ -487,7 +487,7 @@ pub async fn business_profile_create( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileRetrieve))] pub async fn business_profile_retrieve( state: web::Data, req: HttpRequest, @@ -514,7 +514,7 @@ pub async fn business_profile_retrieve( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileUpdate))] pub async fn business_profile_update( state: web::Data, req: HttpRequest, @@ -542,7 +542,7 @@ pub async fn business_profile_update( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileDelete))] +#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileDelete))] pub async fn business_profile_delete( state: web::Data, req: HttpRequest, @@ -562,7 +562,7 @@ pub async fn business_profile_delete( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::BusinessProfileList))] +#[instrument(skip_all, fields(flow = ?Flow::BusinessProfileList))] pub async fn business_profiles_list( state: web::Data, req: HttpRequest, @@ -592,7 +592,7 @@ pub async fn business_profiles_list( /// Merchant Account - KV Status /// /// Toggle KV mode for the Merchant Account -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn merchant_account_kv_status( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/api_keys.rs b/crates/router/src/routes/api_keys.rs index 1a5dbbf92cb..55959589152 100644 --- a/crates/router/src/routes/api_keys.rs +++ b/crates/router/src/routes/api_keys.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Create an API Key", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyCreate))] +#[instrument(skip_all, fields(flow = ?Flow::ApiKeyCreate))] pub async fn api_key_create( state: web::Data, req: HttpRequest, @@ -74,7 +74,7 @@ pub async fn api_key_create( operation_id = "Retrieve an API Key", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::ApiKeyRetrieve))] pub async fn api_key_retrieve( state: web::Data, req: HttpRequest, @@ -120,7 +120,7 @@ pub async fn api_key_retrieve( operation_id = "Update an API Key", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::ApiKeyUpdate))] pub async fn api_key_update( state: web::Data, req: HttpRequest, @@ -170,7 +170,7 @@ pub async fn api_key_update( operation_id = "Revoke an API Key", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyRevoke))] +#[instrument(skip_all, fields(flow = ?Flow::ApiKeyRevoke))] pub async fn api_key_revoke( state: web::Data, req: HttpRequest, @@ -215,7 +215,7 @@ pub async fn api_key_revoke( operation_id = "List all API Keys associated with a merchant account", security(("admin_api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::ApiKeyList))] +#[instrument(skip_all, fields(flow = ?Flow::ApiKeyList))] pub async fn api_key_list( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index af29f817f30..7ddbaf8832d 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -68,10 +68,13 @@ pub struct SessionState { pub conf: Arc>, pub api_client: Box, pub event_handler: EventsHandler, + #[cfg(feature = "email")] + pub email_client: Arc, #[cfg(feature = "olap")] pub pool: crate::analytics::AnalyticsProvider, pub file_storage_client: Box, pub request_id: Option, + pub base_url: String, } impl scheduler::SchedulerAppState for SessionState { fn get_db(&self) -> Box { @@ -79,7 +82,7 @@ impl scheduler::SchedulerAppState for SessionState { } fn get_tenants(&self) -> Vec { - self.conf.multitenancy.tenants.clone() + self.conf.multitenancy.get_tenant_names().clone() } } impl SessionState { @@ -88,16 +91,29 @@ impl SessionState { event_context: events::EventContext::new(self.event_handler.clone()), } } - pub fn from_app_state(state: Arc, tenant: &str) -> Self { - Self { - store: state.stores.get(tenant).unwrap().clone(), + pub fn from_app_state(state: Arc, tenant: &str, err: F) -> Result + where + F: FnOnce() -> E + Copy, + { + Ok(Self { + store: state.stores.get(tenant).ok_or_else(err)?.clone(), conf: Arc::clone(&state.conf), api_client: state.api_client.clone(), event_handler: state.event_handler.clone(), - pool: state.pool.clone(), + pool: state.pools.get(tenant).ok_or_else(err)?.clone(), file_storage_client: state.file_storage_client.clone(), request_id: state.request_id.clone(), - } + base_url: state + .conf + .multitenancy + .get_tenant(tenant) + .ok_or_else(err)? + .clone() + .base_url + .clone(), + #[cfg(feature = "email")] + email_client: Arc::clone(&state.email_client), + }) } } @@ -138,7 +154,7 @@ pub struct AppState { pub email_client: Arc, pub api_client: Box, #[cfg(feature = "olap")] - pub pool: crate::analytics::AnalyticsProvider, + pub pools: HashMap, pub request_id: Option, pub file_storage_client: Box, pub encryption_client: Box, @@ -148,7 +164,7 @@ impl scheduler::SchedulerAppState for AppState { todo!() } fn get_tenants(&self) -> Vec { - self.conf.multitenancy.tenants.clone() + self.conf.multitenancy.get_tenant_names().clone() } } pub trait AppStateInfo { @@ -240,19 +256,26 @@ impl AppState { .await .expect("Failed to create event handler"); let mut stores = HashMap::new(); + let mut pools = HashMap::new(); let cache_store = get_cache_store(&conf.clone(), shut_down_signal, testable) .await .expect("Failed to create store"); - for tenant in conf.clone().multitenancy.tenants { + for tenant in conf.clone().multitenancy.get_tenant_names() { let store: Box = match storage_impl { StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match &event_handler { EventsHandler::Kafka(kafka_client) => Box::new( crate::db::KafkaStore::new( #[allow(clippy::expect_used)] - get_store(&conf.clone(), tenant.as_str(), Arc::clone(&cache_store), testable) - .await - .expect("Failed to create store"), + get_store( + &conf.clone(), + tenant.as_str(), + Arc::clone(&cache_store), + testable, + ) + .await + .expect("Failed to create store"), kafka_client.clone(), + tenant.clone(), ) .await, ), @@ -270,13 +293,17 @@ impl AppState { .expect("Failed to create mock store"), ), }; - stores.insert(tenant, store); + stores.insert(tenant.clone(), store); + #[cfg(feature = "olap")] + let pool = crate::analytics::AnalyticsProvider::from_conf( + conf.analytics.get_inner(), + tenant.as_str(), + ) + .await; + #[cfg(feature = "olap")] + pools.insert(tenant.clone(), pool); } - #[cfg(feature = "olap")] - let pool = - crate::analytics::AnalyticsProvider::from_conf(conf.analytics.get_inner()).await; - #[cfg(feature = "email")] let email_client = Arc::new(create_email_client(&conf).await); @@ -291,7 +318,7 @@ impl AppState { api_client, event_handler, #[cfg(feature = "olap")] - pool, + pools, request_id: None, file_storage_client, encryption_client, diff --git a/crates/router/src/routes/cache.rs b/crates/router/src/routes/cache.rs index 347351d864a..e7742d2d18c 100644 --- a/crates/router/src/routes/cache.rs +++ b/crates/router/src/routes/cache.rs @@ -7,7 +7,7 @@ use crate::{ services::{api, authentication as auth}, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn invalidate( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/cards_info.rs b/crates/router/src/routes/cards_info.rs index 3afa7ca6b04..4d65fc72036 100644 --- a/crates/router/src/routes/cards_info.rs +++ b/crates/router/src/routes/cards_info.rs @@ -21,7 +21,7 @@ use crate::{ operation_id = "Retrieve card information", security(("api_key" = []), ("publishable_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::CardsInfo))] +#[instrument(skip_all, fields(flow = ?Flow::CardsInfo))] pub async fn card_iin_info( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/configs.rs b/crates/router/src/routes/configs.rs index a93387ee4f4..74b9cd73b1e 100644 --- a/crates/router/src/routes/configs.rs +++ b/crates/router/src/routes/configs.rs @@ -8,7 +8,7 @@ use crate::{ types::api as api_types, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::CreateConfigKey))] +#[instrument(skip_all, fields(flow = ?Flow::CreateConfigKey))] pub async fn config_key_create( state: web::Data, req: HttpRequest, @@ -28,7 +28,7 @@ pub async fn config_key_create( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::ConfigKeyFetch))] +#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyFetch))] pub async fn config_key_retrieve( state: web::Data, req: HttpRequest, @@ -48,7 +48,7 @@ pub async fn config_key_retrieve( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::ConfigKeyUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyUpdate))] pub async fn config_key_update( state: web::Data, req: HttpRequest, @@ -72,7 +72,7 @@ pub async fn config_key_update( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::ConfigKeyDelete))] +#[instrument(skip_all, fields(flow = ?Flow::ConfigKeyDelete))] pub async fn config_key_delete( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rs index 415f3bd6ab3..05052462685 100644 --- a/crates/router/src/routes/customers.rs +++ b/crates/router/src/routes/customers.rs @@ -8,7 +8,7 @@ use crate::{ types::api::customers, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersCreate))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersCreate))] pub async fn customers_create( state: web::Data, req: HttpRequest, @@ -31,7 +31,7 @@ pub async fn customers_create( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersRetrieve))] pub async fn customers_retrieve( state: web::Data, req: HttpRequest, @@ -64,7 +64,7 @@ pub async fn customers_retrieve( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersList))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersList))] pub async fn customers_list(state: web::Data, req: HttpRequest) -> HttpResponse { let flow = Flow::CustomersList; @@ -86,7 +86,7 @@ pub async fn customers_list(state: web::Data, req: HttpRequest) -> Htt .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersUpdate))] pub async fn customers_update( state: web::Data, req: HttpRequest, @@ -112,7 +112,7 @@ pub async fn customers_update( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersDelete))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersDelete))] pub async fn customers_delete( state: web::Data, req: HttpRequest, @@ -138,7 +138,7 @@ pub async fn customers_delete( )) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomersGetMandates))] +#[instrument(skip_all, fields(flow = ?Flow::CustomersGetMandates))] pub async fn get_customer_mandates( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/disputes.rs b/crates/router/src/routes/disputes.rs index d898ac5d9c4..a4a6c7507a4 100644 --- a/crates/router/src/routes/disputes.rs +++ b/crates/router/src/routes/disputes.rs @@ -28,7 +28,7 @@ use crate::{ operation_id = "Retrieve a Dispute", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::DisputesRetrieve))] pub async fn retrieve_dispute( state: web::Data, req: HttpRequest, @@ -77,7 +77,7 @@ pub async fn retrieve_dispute( operation_id = "List Disputes", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesList))] +#[instrument(skip_all, fields(flow = ?Flow::DisputesList))] pub async fn retrieve_disputes_list( state: web::Data, req: HttpRequest, @@ -115,7 +115,7 @@ pub async fn retrieve_disputes_list( operation_id = "Accept a Dispute", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::DisputesRetrieve))] pub async fn accept_dispute( state: web::Data, req: HttpRequest, @@ -155,7 +155,7 @@ pub async fn accept_dispute( operation_id = "Submit Dispute Evidence", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::DisputesEvidenceSubmit))] +#[instrument(skip_all, fields(flow = ?Flow::DisputesEvidenceSubmit))] pub async fn submit_dispute_evidence( state: web::Data, req: HttpRequest, @@ -194,7 +194,7 @@ pub async fn submit_dispute_evidence( operation_id = "Attach Evidence to Dispute", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::AttachDisputeEvidence))] +#[instrument(skip_all, fields(flow = ?Flow::AttachDisputeEvidence))] pub async fn attach_dispute_evidence( state: web::Data, req: HttpRequest, @@ -240,7 +240,7 @@ pub async fn attach_dispute_evidence( operation_id = "Retrieve a Dispute Evidence", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::RetrieveDisputeEvidence))] +#[instrument(skip_all, fields(flow = ?Flow::RetrieveDisputeEvidence))] pub async fn retrieve_dispute_evidence( state: web::Data, req: HttpRequest, @@ -283,7 +283,7 @@ pub async fn retrieve_dispute_evidence( operation_id = "Delete Evidence attached to a Dispute", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::DeleteDisputeEvidence))] +#[instrument(skip_all, fields(flow = ?Flow::DeleteDisputeEvidence))] pub async fn delete_dispute_evidence( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/dummy_connector.rs b/crates/router/src/routes/dummy_connector.rs index 41c4ecb2992..79338fc620c 100644 --- a/crates/router/src/routes/dummy_connector.rs +++ b/crates/router/src/routes/dummy_connector.rs @@ -13,7 +13,7 @@ mod errors; pub mod types; mod utils; -//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] +#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] pub async fn dummy_connector_authorize_payment( state: web::Data, req: actix_web::HttpRequest, @@ -33,7 +33,7 @@ pub async fn dummy_connector_authorize_payment( ) .await } -//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] +#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] pub async fn dummy_connector_complete_payment( state: web::Data, req: actix_web::HttpRequest, @@ -57,7 +57,7 @@ pub async fn dummy_connector_complete_payment( ) .await } -//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] +#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentCreate))] pub async fn dummy_connector_payment( state: web::Data, req: actix_web::HttpRequest, @@ -76,7 +76,7 @@ pub async fn dummy_connector_payment( ) .await } -//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyPaymentRetrieve))] +#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentRetrieve))] pub async fn dummy_connector_payment_data( state: web::Data, req: actix_web::HttpRequest, @@ -96,7 +96,7 @@ pub async fn dummy_connector_payment_data( ) .await } -//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyRefundCreate))] +#[instrument(skip_all, fields(flow = ?types::Flow::DummyRefundCreate))] pub async fn dummy_connector_refund( state: web::Data, req: actix_web::HttpRequest, @@ -117,7 +117,7 @@ pub async fn dummy_connector_refund( ) .await } -//#\[instrument\(skip_all, fields(flow = ?types::Flow::DummyRefundRetrieve))] +#[instrument(skip_all, fields(flow = ?types::Flow::DummyRefundRetrieve))] pub async fn dummy_connector_refund_data( state: web::Data, req: actix_web::HttpRequest, diff --git a/crates/router/src/routes/dummy_connector/core.rs b/crates/router/src/routes/dummy_connector/core.rs index 1c82f893653..513a586d193 100644 --- a/crates/router/src/routes/dummy_connector/core.rs +++ b/crates/router/src/routes/dummy_connector/core.rs @@ -64,7 +64,7 @@ pub async fn payment_authorize( if let Ok(payment_data_inner) = payment_data { let return_url = format!( "{}/dummy-connector/complete/{}", - state.conf.server.base_url, req.attempt_id + state.base_url, req.attempt_id ); Ok(api::ApplicationResponse::FileData(( utils::get_authorize_page(payment_data_inner, return_url, dummy_connector_conf) diff --git a/crates/router/src/routes/dummy_connector/utils.rs b/crates/router/src/routes/dummy_connector/utils.rs index ceb2e267e70..6211c3abf80 100644 --- a/crates/router/src/routes/dummy_connector/utils.rs +++ b/crates/router/src/routes/dummy_connector/utils.rs @@ -11,10 +11,7 @@ use super::{ consts, errors, types::{self, GetPaymentMethodDetails}, }; -use crate::{ - configs::settings, - routes::SessionState, -}; +use crate::{configs::settings, routes::SessionState}; pub async fn tokio_mock_sleep(delay: u64, tolerance: u64) { let mut rng = rand::thread_rng(); @@ -344,7 +341,7 @@ impl types::DummyConnectorPaymentData { ) -> types::DummyConnectorResult { let redirect_url = format!( "{}/dummy-connector/authorize/{}", - state.conf.server.base_url, payment_attempt.attempt_id + state.base_url, payment_attempt.attempt_id ); payment_attempt .clone() diff --git a/crates/router/src/routes/ephemeral_key.rs b/crates/router/src/routes/ephemeral_key.rs index 505fea41211..bfe7c353c28 100644 --- a/crates/router/src/routes/ephemeral_key.rs +++ b/crates/router/src/routes/ephemeral_key.rs @@ -8,7 +8,7 @@ use crate::{ types::api::customers, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::EphemeralKeyCreate))] +#[instrument(skip_all, fields(flow = ?Flow::EphemeralKeyCreate))] pub async fn ephemeral_key_create( state: web::Data, req: HttpRequest, @@ -29,7 +29,7 @@ pub async fn ephemeral_key_create( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::EphemeralKeyDelete))] +#[instrument(skip_all, fields(flow = ?Flow::EphemeralKeyDelete))] pub async fn ephemeral_key_delete( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/files.rs b/crates/router/src/routes/files.rs index f1ebd2d3424..92be12b2bc9 100644 --- a/crates/router/src/routes/files.rs +++ b/crates/router/src/routes/files.rs @@ -27,7 +27,7 @@ use crate::{ operation_id = "Create a File", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::CreateFile))] +#[instrument(skip_all, fields(flow = ?Flow::CreateFile))] pub async fn files_create( state: web::Data, req: HttpRequest, @@ -71,7 +71,7 @@ pub async fn files_create( operation_id = "Delete a File", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::DeleteFile))] +#[instrument(skip_all, fields(flow = ?Flow::DeleteFile))] pub async fn files_delete( state: web::Data, req: HttpRequest, @@ -113,7 +113,7 @@ pub async fn files_delete( operation_id = "Retrieve a File", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::RetrieveFile))] +#[instrument(skip_all, fields(flow = ?Flow::RetrieveFile))] pub async fn files_retrieve( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/gsm.rs b/crates/router/src/routes/gsm.rs index 02272d4ccb1..77a0cb0a645 100644 --- a/crates/router/src/routes/gsm.rs +++ b/crates/router/src/routes/gsm.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Create Gsm Rule", security(("admin_api_key" = [])), )] -//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleCreate))] +#[instrument(skip_all, fields(flow = ?Flow::GsmRuleCreate))] pub async fn create_gsm_rule( state: web::Data, req: HttpRequest, @@ -63,7 +63,7 @@ pub async fn create_gsm_rule( operation_id = "Retrieve Gsm Rule", security(("admin_api_key" = [])), )] -//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::GsmRuleRetrieve))] pub async fn get_gsm_rule( state: web::Data, req: HttpRequest, @@ -100,7 +100,7 @@ pub async fn get_gsm_rule( operation_id = "Update Gsm Rule", security(("admin_api_key" = [])), )] -//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::GsmRuleUpdate))] pub async fn update_gsm_rule( state: web::Data, req: HttpRequest, @@ -138,7 +138,7 @@ pub async fn update_gsm_rule( operation_id = "Delete Gsm Rule", security(("admin_api_key" = [])), )] -//#\[instrument\(skip_all, fields(flow = ?Flow::GsmRuleDelete))] +#[instrument(skip_all, fields(flow = ?Flow::GsmRuleDelete))] pub async fn delete_gsm_rule( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/health.rs b/crates/router/src/routes/health.rs index 67302dbc5d9..511a2203b4c 100644 --- a/crates/router/src/routes/health.rs +++ b/crates/router/src/routes/health.rs @@ -11,7 +11,7 @@ use crate::{ }; /// . // #[logger::instrument(skip_all, name = "name1", level = "warn", fields( key1 = "val1" ))] -//#\[instrument\(skip_all, fields(flow = ?Flow::HealthCheck))] +#[instrument(skip_all, fields(flow = ?Flow::HealthCheck))] // #[actix_web::get("/health")] pub async fn health() -> impl actix_web::Responder { metrics::HEALTH_METRIC.add(&metrics::CONTEXT, 1, &[]); @@ -19,7 +19,7 @@ pub async fn health() -> impl actix_web::Responder { actix_web::HttpResponse::Ok().body("health is good") } -//#\[instrument\(skip_all, fields(flow = ?Flow::DeepHealthCheck))] +#[instrument(skip_all, fields(flow = ?Flow::DeepHealthCheck))] pub async fn deep_health_check( state: web::Data, request: HttpRequest, diff --git a/crates/router/src/routes/mandates.rs b/crates/router/src/routes/mandates.rs index 6fc187ab288..365f9a43248 100644 --- a/crates/router/src/routes/mandates.rs +++ b/crates/router/src/routes/mandates.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Retrieve a Mandate", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MandatesRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::MandatesRetrieve))] // #[get("/{id}")] pub async fn get_mandate( state: web::Data, @@ -66,7 +66,7 @@ pub async fn get_mandate( operation_id = "Revoke a Mandate", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MandatesRevoke))] +#[instrument(skip_all, fields(flow = ?Flow::MandatesRevoke))] // #[post("/revoke/{id}")] pub async fn revoke_mandate( state: web::Data, @@ -113,7 +113,7 @@ pub async fn revoke_mandate( operation_id = "List Mandates", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::MandatesList))] +#[instrument(skip_all, fields(flow = ?Flow::MandatesList))] pub async fn retrieve_mandates_list( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/payment_link.rs b/crates/router/src/routes/payment_link.rs index 0318336b46d..7742f6c1c0e 100644 --- a/crates/router/src/routes/payment_link.rs +++ b/crates/router/src/routes/payment_link.rs @@ -25,7 +25,7 @@ use crate::{ operation_id = "Retrieve a Payment Link", security(("api_key" = []), ("publishable_key" = [])) )] -//#\[instrument\(skip(state, req), fields(flow = ?Flow::PaymentLinkRetrieve))] +#[instrument(skip(state, req), fields(flow = ?Flow::PaymentLinkRetrieve))] pub async fn payment_link_retrieve( state: web::Data, @@ -104,7 +104,7 @@ pub async fn initiate_payment_link( operation_id = "List all Payment links", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentLinkList))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentLinkList))] pub async fn payments_link_list( state: web::Data, req: actix_web::HttpRequest, diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index de56b574214..181cd94424f 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -16,7 +16,7 @@ use crate::{ utils::Encode, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsCreate))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsCreate))] pub async fn create_payment_method_api( state: web::Data, req: HttpRequest, @@ -43,7 +43,7 @@ pub async fn create_payment_method_api( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsList))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsList))] pub async fn list_payment_method_api( state: web::Data, req: HttpRequest, @@ -92,7 +92,7 @@ pub async fn list_payment_method_api( operation_id = "List all Payment Methods for a Customer", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] +#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] pub async fn list_customer_payment_method_api( state: web::Data, customer_id: web::Path<(String,)>, @@ -150,7 +150,7 @@ pub async fn list_customer_payment_method_api( operation_id = "List all Payment Methods for a Customer", security(("publishable_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] +#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))] pub async fn list_customer_payment_method_api_client( state: web::Data, req: HttpRequest, @@ -183,7 +183,7 @@ pub async fn list_customer_payment_method_api_client( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsRetrieve))] pub async fn payment_method_retrieve_api( state: web::Data, req: HttpRequest, @@ -209,7 +209,7 @@ pub async fn payment_method_retrieve_api( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsUpdate))] pub async fn payment_method_update_api( state: web::Data, req: HttpRequest, @@ -239,7 +239,7 @@ pub async fn payment_method_update_api( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentMethodsDelete))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodsDelete))] pub async fn payment_method_delete_api( state: web::Data, req: HttpRequest, @@ -263,7 +263,7 @@ pub async fn payment_method_delete_api( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::ListCountriesCurrencies))] +#[instrument(skip_all, fields(flow = ?Flow::ListCountriesCurrencies))] pub async fn list_countries_currencies_for_connector_payment_method( state: web::Data, req: HttpRequest, @@ -292,7 +292,7 @@ pub async fn list_countries_currencies_for_connector_payment_method( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::DefaultPaymentMethodsSet))] +#[instrument(skip_all, fields(flow = ?Flow::DefaultPaymentMethodsSet))] pub async fn default_payment_method_set_api( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index e7491a2ba69..22ada3be6cc 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -89,7 +89,7 @@ use crate::{ operation_id = "Create a Payment", security(("api_key" = [])), )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCreate, payment_id))] pub async fn payments_create( state: web::Data, req: actix_web::HttpRequest, @@ -166,7 +166,7 @@ pub async fn payments_create( // tag = "Payments", // operation_id = "Start a Redirection Payment" // )] -//#\[instrument\(skip(state, req), fields(flow = ?Flow::PaymentsStart, payment_id))] +#[instrument(skip(state, req), fields(flow = ?Flow::PaymentsStart, payment_id))] pub async fn payments_start( state: web::Data, req: actix_web::HttpRequest, @@ -232,7 +232,7 @@ pub async fn payments_start( operation_id = "Retrieve a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -//#\[instrument\(skip(state, req), fields(flow, payment_id))] +#[instrument(skip(state, req), fields(flow, payment_id))] // #[get("/{payment_id}")] pub async fn payments_retrieve( state: web::Data, @@ -309,7 +309,7 @@ pub async fn payments_retrieve( operation_id = "Retrieve a Payment", security(("api_key" = [])) )] -//#\[instrument\(skip(state, req), fields(flow, payment_id))] +#[instrument(skip(state, req), fields(flow, payment_id))] // #[post("/sync")] pub async fn payments_retrieve_with_gateway_creds( state: web::Data, @@ -382,7 +382,7 @@ pub async fn payments_retrieve_with_gateway_creds( operation_id = "Update a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsUpdate, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsUpdate, payment_id))] // #[post("/{payment_id}")] pub async fn payments_update( state: web::Data, @@ -450,7 +450,7 @@ pub async fn payments_update( operation_id = "Confirm a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsConfirm, payment_id))] // #[post("/{payment_id}/confirm")] pub async fn payments_confirm( state: web::Data, @@ -528,7 +528,7 @@ pub async fn payments_confirm( operation_id = "Capture a Payment", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCapture, payment_id))] // #[post("/{payment_id}/capture")] pub async fn payments_capture( state: web::Data, @@ -593,7 +593,7 @@ pub async fn payments_capture( operation_id = "Create Session tokens for a Payment", security(("publishable_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsSessionToken, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsSessionToken, payment_id))] pub async fn payments_connector_session( state: web::Data, req: actix_web::HttpRequest, @@ -655,7 +655,7 @@ pub async fn payments_connector_session( // tag = "Payments", // operation_id = "Get Redirect Response for a Payment" // )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] pub async fn payments_redirect_response( state: web::Data, req: actix_web::HttpRequest, @@ -718,7 +718,7 @@ pub async fn payments_redirect_response( // tag = "Payments", // operation_id = "Get Redirect Response for a Payment" // )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsRedirect, payment_id))] pub async fn payments_redirect_response_with_creds_identifier( state: web::Data, req: actix_web::HttpRequest, @@ -761,7 +761,7 @@ pub async fn payments_redirect_response_with_creds_identifier( ) .await } -//#\[instrument\(skip_all, fields(flow =? Flow::PaymentsRedirect, payment_id))] +#[instrument(skip_all, fields(flow =? Flow::PaymentsRedirect, payment_id))] pub async fn payments_complete_authorize( state: web::Data, req: actix_web::HttpRequest, @@ -824,7 +824,7 @@ pub async fn payments_complete_authorize( operation_id = "Cancel a Payment", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsCancel, payment_id))] // #[post("/{payment_id}/cancel")] pub async fn payments_cancel( state: web::Data, @@ -890,7 +890,7 @@ pub async fn payments_cancel( operation_id = "List all Payments", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn payments_list( state: web::Data, @@ -914,7 +914,7 @@ pub async fn payments_list( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn payments_list_by_filter( state: web::Data, @@ -940,7 +940,7 @@ pub async fn payments_list_by_filter( ) .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsList))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsList))] #[cfg(feature = "olap")] pub async fn get_filters_for_payments( state: web::Data, @@ -966,7 +966,7 @@ pub async fn get_filters_for_payments( } #[cfg(feature = "oltp")] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsApprove, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsApprove, payment_id))] // #[post("/{payment_id}/approve")] pub async fn payments_approve( state: web::Data, @@ -1027,7 +1027,7 @@ pub async fn payments_approve( } #[cfg(feature = "oltp")] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsReject, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsReject, payment_id))] // #[post("/{payment_id}/reject")] pub async fn payments_reject( state: web::Data, @@ -1190,7 +1190,7 @@ where operation_id = "Increment authorized amount for a Payment", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsIncrementalAuthorization, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsIncrementalAuthorization, payment_id))] pub async fn payments_incremental_authorization( state: web::Data, req: actix_web::HttpRequest, @@ -1255,7 +1255,7 @@ pub async fn payments_incremental_authorization( operation_id = "Initiate external authentication for a Payment", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsExternalAuthentication, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsExternalAuthentication, payment_id))] pub async fn payments_external_authentication( state: web::Data, req: actix_web::HttpRequest, @@ -1304,7 +1304,7 @@ pub async fn payments_external_authentication( operation_id = "Authorize a Payment", security(("api_key" = []), ("publishable_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PaymentsAuthorize, payment_id))] +#[instrument(skip_all, fields(flow = ?Flow::PaymentsAuthorize, payment_id))] pub async fn post_3ds_payments_authorize( state: web::Data, req: actix_web::HttpRequest, diff --git a/crates/router/src/routes/payouts.rs b/crates/router/src/routes/payouts.rs index 5d6cdf8071b..f3b6a7cd477 100644 --- a/crates/router/src/routes/payouts.rs +++ b/crates/router/src/routes/payouts.rs @@ -26,7 +26,7 @@ use crate::{ operation_id = "Create a Payout", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsCreate))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsCreate))] pub async fn payouts_create( state: web::Data, req: HttpRequest, @@ -61,7 +61,7 @@ pub async fn payouts_create( operation_id = "Retrieve a Payout", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsRetrieve))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsRetrieve))] pub async fn payouts_retrieve( state: web::Data, req: HttpRequest, @@ -106,7 +106,7 @@ pub async fn payouts_retrieve( operation_id = "Update a Payout", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsUpdate))] pub async fn payouts_update( state: web::Data, req: HttpRequest, @@ -146,7 +146,7 @@ pub async fn payouts_update( operation_id = "Cancel a Payout", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsCancel))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsCancel))] pub async fn payouts_cancel( state: web::Data, req: HttpRequest, @@ -186,7 +186,7 @@ pub async fn payouts_cancel( operation_id = "Fulfill a Payout", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsFulfill))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsFulfill))] pub async fn payouts_fulfill( state: web::Data, req: HttpRequest, @@ -224,7 +224,7 @@ pub async fn payouts_fulfill( operation_id = "List payouts", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsList))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsList))] pub async fn payouts_list( state: web::Data, req: HttpRequest, @@ -262,7 +262,7 @@ pub async fn payouts_list( operation_id = "Filter payouts", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsList))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsList))] pub async fn payouts_list_by_filter( state: web::Data, req: HttpRequest, @@ -302,7 +302,7 @@ pub async fn payouts_list_by_filter( operation_id = "Filter payouts", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsFilter))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsFilter))] pub async fn payouts_list_available_filters( state: web::Data, req: HttpRequest, @@ -329,7 +329,7 @@ pub async fn payouts_list_available_filters( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PayoutsAccounts))] +#[instrument(skip_all, fields(flow = ?Flow::PayoutsAccounts))] // #[get("/accounts")] pub async fn payouts_accounts() -> impl Responder { let _flow = Flow::PayoutsAccounts; diff --git a/crates/router/src/routes/pm_auth.rs b/crates/router/src/routes/pm_auth.rs index 9d0ef364fae..e0cce9c515c 100644 --- a/crates/router/src/routes/pm_auth.rs +++ b/crates/router/src/routes/pm_auth.rs @@ -4,7 +4,7 @@ use router_env::{instrument, tracing, types::Flow}; use crate::{core::api_locking, routes::AppState, services::api as oss_api}; -//#\[instrument\(skip_all, fields(flow = ?Flow::PmAuthLinkTokenCreate))] +#[instrument(skip_all, fields(flow = ?Flow::PmAuthLinkTokenCreate))] pub async fn link_token_create( state: web::Data, req: HttpRequest, @@ -38,7 +38,7 @@ pub async fn link_token_create( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::PmAuthExchangeToken))] +#[instrument(skip_all, fields(flow = ?Flow::PmAuthExchangeToken))] pub async fn exchange_token( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/recon.rs b/crates/router/src/routes/recon.rs index 7da563949eb..28ed93282cb 100644 --- a/crates/router/src/routes/recon.rs +++ b/crates/router/src/routes/recon.rs @@ -5,7 +5,7 @@ use error_stack::ResultExt; use masking::{ExposeInterface, PeekInterface, Secret}; use router_env::Flow; -use super::{AppState,SessionState}; +use super::{AppState, SessionState}; use crate::{ core::{ api_locking, diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs index 1a848d64e30..d68c7138213 100644 --- a/crates/router/src/routes/refunds.rs +++ b/crates/router/src/routes/refunds.rs @@ -23,7 +23,7 @@ use crate::{ operation_id = "Create a Refund", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsCreate))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsCreate))] // #[post("")] pub async fn refunds_create( state: web::Data, @@ -63,7 +63,7 @@ pub async fn refunds_create( operation_id = "Retrieve a Refund", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow))] +#[instrument(skip_all, fields(flow))] // #[get("/{id}")] pub async fn refunds_retrieve( state: web::Data, @@ -120,7 +120,7 @@ pub async fn refunds_retrieve( operation_id = "Retrieve a Refund", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow))] +#[instrument(skip_all, fields(flow))] // #[post("/sync")] pub async fn refunds_retrieve_with_body( state: web::Data, @@ -171,7 +171,7 @@ pub async fn refunds_retrieve_with_body( operation_id = "Update a Refund", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsUpdate))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsUpdate))] // #[post("/{id}")] pub async fn refunds_update( state: web::Data, @@ -207,7 +207,7 @@ pub async fn refunds_update( operation_id = "List all Refunds", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsList))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsList))] #[cfg(feature = "olap")] pub async fn refunds_list( state: web::Data, @@ -244,7 +244,7 @@ pub async fn refunds_list( operation_id = "List all filters for Refunds", security(("api_key" = [])) )] -//#\[instrument\(skip_all, fields(flow = ?Flow::RefundsList))] +#[instrument(skip_all, fields(flow = ?Flow::RefundsList))] #[cfg(feature = "olap")] pub async fn refunds_filter_list( state: web::Data, diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs index 5969ce49e1a..8438424546c 100644 --- a/crates/router/src/routes/routing.rs +++ b/crates/router/src/routes/routing.rs @@ -18,7 +18,7 @@ use crate::{ }; #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_create_config( state: web::Data, req: HttpRequest, @@ -54,7 +54,7 @@ pub async fn routing_create_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_link_config( state: web::Data, req: HttpRequest, @@ -91,7 +91,7 @@ pub async fn routing_link_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_retrieve_config( state: web::Data, req: HttpRequest, @@ -121,7 +121,7 @@ pub async fn routing_retrieve_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn list_routing_configs( state: web::Data, req: HttpRequest, @@ -183,7 +183,7 @@ pub async fn list_routing_configs( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_unlink_config( state: web::Data, req: HttpRequest, @@ -252,7 +252,7 @@ pub async fn routing_unlink_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_update_default_config( state: web::Data, req: HttpRequest, @@ -286,7 +286,7 @@ pub async fn routing_update_default_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_retrieve_default_config( state: web::Data, req: HttpRequest, @@ -314,7 +314,7 @@ pub async fn routing_retrieve_default_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn upsert_surcharge_decision_manager_config( state: web::Data, req: HttpRequest, @@ -347,7 +347,7 @@ pub async fn upsert_surcharge_decision_manager_config( .await } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn delete_surcharge_decision_manager_config( state: web::Data, req: HttpRequest, @@ -379,7 +379,7 @@ pub async fn delete_surcharge_decision_manager_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn retrieve_surcharge_decision_manager_config( state: web::Data, req: HttpRequest, @@ -410,7 +410,7 @@ pub async fn retrieve_surcharge_decision_manager_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn upsert_decision_manager_config( state: web::Data, req: HttpRequest, @@ -444,7 +444,7 @@ pub async fn upsert_decision_manager_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn delete_decision_manager_config( state: web::Data, req: HttpRequest, @@ -476,7 +476,7 @@ pub async fn delete_decision_manager_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn retrieve_decision_manager_config( state: web::Data, req: HttpRequest, @@ -504,7 +504,7 @@ pub async fn retrieve_decision_manager_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_retrieve_linked_config( state: web::Data, req: HttpRequest, @@ -567,7 +567,7 @@ pub async fn routing_retrieve_linked_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn upsert_connector_agnostic_mandate_config( state: web::Data, req: HttpRequest, @@ -602,7 +602,7 @@ pub async fn upsert_connector_agnostic_mandate_config( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_retrieve_default_config_for_profiles( state: web::Data, req: HttpRequest, @@ -638,7 +638,7 @@ pub async fn routing_retrieve_default_config_for_profiles( } #[cfg(feature = "olap")] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn routing_update_default_config_for_profile( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/verification.rs b/crates/router/src/routes/verification.rs index 059b1d96ac4..00662663113 100644 --- a/crates/router/src/routes/verification.rs +++ b/crates/router/src/routes/verification.rs @@ -8,7 +8,7 @@ use crate::{ services::{api, authentication as auth, authorization::permissions::Permission}, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::Verification))] +#[instrument(skip_all, fields(flow = ?Flow::Verification))] pub async fn apple_pay_merchant_registration( state: web::Data, req: HttpRequest, @@ -39,7 +39,7 @@ pub async fn apple_pay_merchant_registration( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::Verification))] +#[instrument(skip_all, fields(flow = ?Flow::Verification))] pub async fn retrieve_apple_pay_verified_domains( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/verify_connector.rs b/crates/router/src/routes/verify_connector.rs index a5e41fb7f80..c045b3a8e6a 100644 --- a/crates/router/src/routes/verify_connector.rs +++ b/crates/router/src/routes/verify_connector.rs @@ -8,7 +8,7 @@ use crate::{ services::{self, authentication as auth, authorization::permissions::Permission}, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::VerifyPaymentConnector))] +#[instrument(skip_all, fields(flow = ?Flow::VerifyPaymentConnector))] pub async fn payment_connector_verify( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/webhook_events.rs b/crates/router/src/routes/webhook_events.rs index 4fead5c4ee1..ef1d64f54e9 100644 --- a/crates/router/src/routes/webhook_events.rs +++ b/crates/router/src/routes/webhook_events.rs @@ -11,7 +11,7 @@ use crate::{ }, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::WebhookEventInitialDeliveryAttemptList))] +#[instrument(skip_all, fields(flow = ?Flow::WebhookEventInitialDeliveryAttemptList))] pub async fn list_initial_webhook_delivery_attempts( state: web::Data, req: HttpRequest, @@ -52,7 +52,7 @@ pub async fn list_initial_webhook_delivery_attempts( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::WebhookEventDeliveryAttemptList))] +#[instrument(skip_all, fields(flow = ?Flow::WebhookEventDeliveryAttemptList))] pub async fn list_webhook_delivery_attempts( state: web::Data, req: HttpRequest, @@ -91,7 +91,7 @@ pub async fn list_webhook_delivery_attempts( .await } -//#\[instrument\(skip_all, fields(flow = ?Flow::WebhookEventDeliveryRetry))] +#[instrument(skip_all, fields(flow = ?Flow::WebhookEventDeliveryRetry))] pub async fn retry_webhook_delivery_attempt( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/routes/webhooks.rs b/crates/router/src/routes/webhooks.rs index df6d15124dc..03fe6a1d758 100644 --- a/crates/router/src/routes/webhooks.rs +++ b/crates/router/src/routes/webhooks.rs @@ -11,7 +11,7 @@ use crate::{ services::{api, authentication as auth}, }; -//#\[instrument\(skip_all, fields(flow = ?Flow::IncomingWebhookReceive))] +#[instrument(skip_all, fields(flow = ?Flow::IncomingWebhookReceive))] pub async fn receive_incoming_webhook( state: web::Data, req: HttpRequest, diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index ffb65ff7a54..be4641023f2 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -20,10 +20,7 @@ use error_stack::ResultExt; use masking::{ExposeInterface, StrongSecret}; #[cfg(feature = "kv_store")] use storage_impl::KVRouterStore; -use storage_impl::{ - redis::RedisStore, - RouterStore, -}; +use storage_impl::{redis::RedisStore, RouterStore}; use tokio::sync::oneshot; pub use self::{api::*, encryption::*}; diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index fd0eb74eff7..aebaaa008f3 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -271,7 +271,7 @@ pub enum CaptureSyncMethod { /// Handle the flow by interacting with connector module /// `connector_request` is applicable only in case if the `CallConnectorAction` is `Trigger` /// In other cases, It will be created if required, even if it is not passed -//#\[instrument\(skip_all, fields(connector_name, payment_method))] +#[instrument(skip_all, fields(connector_name, payment_method))] pub async fn execute_connector_processing_step< 'b, 'a, @@ -536,7 +536,7 @@ where } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn call_connector_api( state: &SessionState, request: Request, @@ -572,7 +572,7 @@ pub async fn call_connector_api( handle_response(response).await } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn send_request( state: &SessionState, request: Request, @@ -752,7 +752,7 @@ fn is_connection_closed_before_message_could_complete(error: &reqwest::Error) -> false } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn handle_response( response: CustomResult, ) -> CustomResult, errors::ApiClientError> { @@ -946,10 +946,10 @@ pub enum AuthFlow { } #[allow(clippy::too_many_arguments)] -//#\[instrument\( -// skip(request, payload, state, func, api_auth, request_state), -// fields(merchant_id) -// )] +#[instrument( + skip(request, payload, state, func, api_auth, request_state), + fields(merchant_id) +)] pub async fn server_wrap_util<'a, 'b, U, T, Q, F, Fut, E, OErr>( flow: &'a impl router_env::types::FlowMetric, state: web::Data, @@ -997,25 +997,35 @@ where // .ok_or_else(|| { // errors::ApiErrorResponse::InvalidRequestData { message: "Missing tenant Id".to_string() } // .switch() - // }).map(|tenant_id| if !state.conf.multitenancy.tenants.contains(&tenant_id.to_string()) { - // Err(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid tenant Id".to_string() } + // }).map(|tenant_id| if !state.conf.multitenancy.get_tenant_names().contains(&tenant_id.to_string()) { + // Err(errors::ApiErrorResponse::InvalidTenant { tenant_id: tenant_id.to_string() } // .switch()) // } else { // Ok(tenant_id) // } )??; let tenant_id = "public"; - let mut session_state = SessionState { - store: state.stores.get(tenant_id).ok_or_else(|| { - errors::ApiErrorResponse::InternalServerError - .switch() - })?.clone(), - conf: Arc::clone(&state.conf), - api_client: state.api_client.clone(), - event_handler: state.event_handler.clone(), - pool: state.pool.clone(), - file_storage_client: state.file_storage_client.clone(), - request_id: state.request_id.clone(), - }; + let mut session_state = + SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id, || { + errors::ApiErrorResponse::InvalidTenant { + tenant_id: tenant_id.to_string(), + } + .switch() + })?; + // { + // store: state.stores.get(tenant_id).ok_or_else(|| { + // errors::ApiErrorResponse::InternalServerError + // .switch() + // })?.clone(), + // conf: Arc::clone(&state.conf), + // api_client: state.api_client.clone(), + // event_handler: state.event_handler.clone(), + // pool: state.pools.get(tenant_id).ok_or_else(|| { + // errors::ApiErrorResponse::InternalServerError + // .switch() + // })?.clone(), + // file_storage_client: state.file_storage_client.clone(), + // request_id: state.request_id.clone(), + // }; session_state.add_request_id(request_id); // Currently auth failures are not recorded as API events @@ -1119,10 +1129,10 @@ where output } -//#\[instrument\( -// skip(request, state, func, api_auth, payload), -// fields(request_method, request_url_path, status_code) -// )] +#[instrument( + skip(request, state, func, api_auth, payload), + fields(request_method, request_url_path, status_code) +)] pub async fn server_wrap<'a, T, U, Q, F, Fut, E>( flow: impl router_env::types::FlowMetric, state: web::Data, diff --git a/crates/router/src/services/api/request.rs b/crates/router/src/services/api/request.rs index 1635c826667..ed53da0d971 100644 --- a/crates/router/src/services/api/request.rs +++ b/crates/router/src/services/api/request.rs @@ -40,7 +40,7 @@ pub(super) trait RequestBuilderExt { } impl RequestBuilderExt for reqwest::RequestBuilder { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] fn add_headers(mut self, headers: reqwest::header::HeaderMap) -> Self { self = self.headers(headers); self diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs index 885475a0374..58a6dd38f46 100644 --- a/crates/router/src/services/authentication.rs +++ b/crates/router/src/services/authentication.rs @@ -21,13 +21,12 @@ use crate::consts; #[cfg(feature = "olap")] use crate::core::errors::UserResult; #[cfg(feature = "recon")] -use crate::routes::{AppState, SessionState}; +use crate::routes::SessionState; use crate::{ core::{ api_keys, errors::{self, utils::StorageErrorExt, RouterResult}, }, - db::StorageInterface, routes::app::SessionStateInfo, services::api, types::domain, @@ -1067,13 +1066,13 @@ impl AuthInfo for ReconUser { } #[cfg(all(feature = "olap", feature = "recon"))] #[async_trait] -impl AuthenticateAndFetch for ReconJWT { +impl AuthenticateAndFetch for ReconJWT { async fn authenticate_and_fetch( &self, request_headers: &HeaderMap, state: &SessionState, ) -> RouterResult<(ReconUser, AuthenticationType)> { - let payload = parse_jwt_payload::(request_headers, state).await?; + let payload = parse_jwt_payload::(request_headers, state).await?; Ok(( ReconUser { diff --git a/crates/router/src/types/domain/types.rs b/crates/router/src/types/domain/types.rs index a97cbc81101..0ef4e8579d3 100644 --- a/crates/router/src/types/domain/types.rs +++ b/crates/router/src/types/domain/types.rs @@ -37,7 +37,7 @@ impl< S: masking::Strategy + Send, > TypeEncryption for crypto::Encryptable> { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn encrypt( masked_data: Secret, key: &[u8], @@ -48,7 +48,7 @@ impl< Ok(Self::new(masked_data, encrypted_data.into())) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn decrypt( encrypted_data: Encryption, key: &[u8], @@ -72,7 +72,7 @@ impl< > TypeEncryption for crypto::Encryptable> { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn encrypt( masked_data: Secret, key: &[u8], @@ -85,7 +85,7 @@ impl< Ok(Self::new(masked_data, encrypted_data.into())) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn decrypt( encrypted_data: Encryption, key: &[u8], @@ -107,7 +107,7 @@ impl< S: masking::Strategy> + Send, > TypeEncryption, V, S> for crypto::Encryptable, S>> { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn encrypt( masked_data: Secret, S>, key: &[u8], @@ -118,7 +118,7 @@ impl< Ok(Self::new(masked_data, encrypted_data.into())) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn decrypt( encrypted_data: Encryption, key: &[u8], diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index cfd5e4a1e31..1df3d85d6b4 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -123,7 +123,7 @@ mod tests { let store = state .stores - .get(state.conf.multitenancy.tenants.get(0).unwrap()) + .get(state.conf.multitenancy.get_tenant_names().get(0).unwrap()) .unwrap(); let response = store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) @@ -167,7 +167,7 @@ mod tests { }; let store = state .stores - .get(state.conf.multitenancy.tenants.get(0).unwrap()) + .get(state.conf.multitenancy.get_tenant_names().get(0).unwrap()) .unwrap(); store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) @@ -222,7 +222,7 @@ mod tests { }; let store = state .stores - .get(state.conf.multitenancy.tenants.get(0).unwrap()) + .get(state.conf.multitenancy.get_tenant_names().get(0).unwrap()) .unwrap(); store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs index ea2a626c18d..96eaf42e623 100644 --- a/crates/router/src/utils.rs +++ b/crates/router/src/utils.rs @@ -773,7 +773,7 @@ where captures, customer, services::AuthFlow::Merchant, - &state.conf.server, + &state.base_url, &operation, &state.conf.connector_request_reference_id_config, None, diff --git a/crates/router/src/workflows/api_key_expiry.rs b/crates/router/src/workflows/api_key_expiry.rs index fe12056a3e0..5c1762ead6a 100644 --- a/crates/router/src/workflows/api_key_expiry.rs +++ b/crates/router/src/workflows/api_key_expiry.rs @@ -1,7 +1,7 @@ use common_utils::{errors::ValidationError, ext_traits::ValueExt}; use diesel_models::{enums as storage_enums, ApiKeyExpiryTrackingData}; use router_env::logger; -use scheduler::{workflows::ProcessTrackerWorkflow}; +use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerAppState}; use crate::{ errors, diff --git a/crates/router/src/workflows/outgoing_webhook_retry.rs b/crates/router/src/workflows/outgoing_webhook_retry.rs index 0681b689043..30586e8575d 100644 --- a/crates/router/src/workflows/outgoing_webhook_retry.rs +++ b/crates/router/src/workflows/outgoing_webhook_retry.rs @@ -25,7 +25,7 @@ pub struct OutgoingWebhookRetryWorkflow; #[async_trait::async_trait] impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn execute_workflow<'a>( &'a self, state: &'a SessionState, @@ -204,7 +204,7 @@ impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { Ok(()) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn error_handler<'a>( &'a self, state: &'a SessionState, @@ -243,7 +243,7 @@ impl ProcessTrackerWorkflow for OutgoingWebhookRetryWorkflow { /// seconds between them by default. /// - `custom_merchant_mapping.merchant_id1`: Merchant-specific retry configuration for merchant /// with merchant ID `merchant_id1`. -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) async fn get_webhook_delivery_retry_schedule_time( db: &dyn StorageInterface, merchant_id: &str, @@ -288,7 +288,7 @@ pub(crate) async fn get_webhook_delivery_retry_schedule_time( } /// Schedule the webhook delivery task for retry -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub(crate) async fn retry_webhook_delivery_task( db: &dyn StorageInterface, merchant_id: &str, @@ -311,7 +311,7 @@ pub(crate) async fn retry_webhook_delivery_task( } } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn get_outgoing_webhook_content_and_event_type( state: SessionState, req_state: ReqState, diff --git a/crates/router/tests/cache.rs b/crates/router/tests/cache.rs index 040e0dddf97..94353ab60d3 100644 --- a/crates/router/tests/cache.rs +++ b/crates/router/tests/cache.rs @@ -1,4 +1,6 @@ #![allow(clippy::unwrap_used)] +use std::sync::Arc; + use router::{configs::settings::Settings, routes, services}; use storage_impl::redis::cache; @@ -9,13 +11,13 @@ async fn invalidate_existing_cache_success() { // Arrange Box::pin(utils::setup()).await; let (tx, _) = tokio::sync::oneshot::channel(); - let state = Box::pin(routes::AppState::new( + let app_state = Box::pin(routes::AppState::new( Settings::default(), tx, Box::new(services::MockApiClient), )) .await; - + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let cache_key = "cacheKey".to_string(); let cache_key_value = "val".to_string(); let _ = state diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index 50d3b1a1d32..049ec165fb1 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -1,4 +1,4 @@ -use std::{marker::PhantomData, str::FromStr}; +use std::{marker::PhantomData, str::FromStr, sync::Arc}; use api_models::payments::{Address, AddressDetails}; use masking::Secret; @@ -186,13 +186,14 @@ async fn payments_create_success() { let conf = Settings::new().unwrap(); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::SessionState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); static CV: aci::Aci = aci::Aci; let connector = types::api::ConnectorData { @@ -231,13 +232,15 @@ async fn payments_create_failure() { static CV: aci::Aci = aci::Aci; let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let connector = types::api::ConnectorData { connector: Box::new(&CV), connector_name: types::Connector::Aci, @@ -292,13 +295,14 @@ async fn refund_for_successful_payments() { }; let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let connector_integration: services::BoxedConnectorIntegration< '_, types::api::Authorize, @@ -361,13 +365,14 @@ async fn refunds_create_failure() { }; let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let connector_integration: services::BoxedConnectorIntegration< '_, types::api::Execute, diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 804c54ddfd0..2ea635b6148 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -1,4 +1,4 @@ -use std::{fmt::Debug, marker::PhantomData, str::FromStr, time::Duration}; +use std::{fmt::Debug, marker::PhantomData, str::FromStr, sync::Arc, time::Duration}; use async_trait::async_trait; use common_utils::pii::Email; @@ -94,13 +94,15 @@ pub trait ConnectorActions: Connector { payment_info, ); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -119,15 +121,16 @@ pub trait ConnectorActions: Connector { ); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; - let state: &SessionState = &state.stores.get("public").unwrap().clone(); - integration.execute_pretasks(&mut request, session_state).await?; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -145,13 +148,15 @@ pub trait ConnectorActions: Connector { ); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -174,13 +179,15 @@ pub trait ConnectorActions: Connector { ); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -594,13 +601,15 @@ pub trait ConnectorActions: Connector { let mut request = self.get_payout_request(None, payout_type, payment_info); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -635,13 +644,15 @@ pub trait ConnectorActions: Connector { let mut request = self.get_payout_request(connector_payout_id, payout_type, payment_info); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -677,13 +688,15 @@ pub trait ConnectorActions: Connector { request.connector_customer = connector_customer; let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -719,13 +732,15 @@ pub trait ConnectorActions: Connector { self.get_payout_request(Some(connector_payout_id), payout_type, payment_info); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -807,13 +822,15 @@ pub trait ConnectorActions: Connector { let mut request = self.get_payout_request(None, payout_type, payment_info); let tx = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( Settings::new().unwrap(), StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = + routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -840,13 +857,14 @@ async fn call_connector< let conf = Settings::new().unwrap(); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); services::api::execute_connector_processing_step( &state, integration, diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index 7a990464da5..d2575fac75c 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -2,6 +2,8 @@ mod utils; +use std::sync::Arc; + use router::{ configs, core::{payment_methods::Oss, payments}, @@ -275,13 +277,14 @@ async fn payments_create_core() { use configs::settings::Settings; let conf = Settings::new().expect("invalid settings"); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let key_store = state .store @@ -457,13 +460,14 @@ async fn payments_create_core_adyen_no_redirect() { use crate::configs::settings::Settings; let conf = Settings::new().expect("invalid settings"); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let customer_id = format!("cust_{}", Uuid::new_v4()); let merchant_id = "arunraj".to_string(); diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index cce589fb038..4b9c4bfe17b 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -2,6 +2,8 @@ mod utils; +use std::sync::Arc; + use router::{ core::{payment_methods::Oss, payments}, db::StorageImpl, @@ -35,13 +37,14 @@ async fn payments_create_core() { use router::configs::settings::Settings; let conf = Settings::new().expect("invalid settings"); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let key_store = state .store @@ -224,13 +227,14 @@ async fn payments_create_core_adyen_no_redirect() { let conf = Settings::new().expect("invalid settings"); let tx: oneshot::Sender<()> = oneshot::channel().0; - let state = Box::pin(routes::AppState::with_storage( + let app_state = Box::pin(routes::AppState::with_storage( conf, StorageImpl::PostgresqlTest, tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let customer_id = format!("cust_{}", Uuid::new_v4()); let merchant_id = "arunraj".to_string(); diff --git a/crates/router/tests/services.rs b/crates/router/tests/services.rs index eff7fe7f873..f00e1257286 100644 --- a/crates/router/tests/services.rs +++ b/crates/router/tests/services.rs @@ -1,4 +1,4 @@ -use std::sync::atomic; +use std::sync::{atomic, Arc}; use router::{configs::settings::Settings, routes, services}; @@ -10,12 +10,13 @@ async fn get_redis_conn_failure() { // Arrange utils::setup().await; let (tx, _) = tokio::sync::oneshot::channel(); - let state = Box::pin(routes::AppState::new( + let app_state = Box::pin(routes::AppState::new( Settings::default(), tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); let _ = state.store.get_redis_conn().map(|conn| { conn.is_redis_available @@ -34,12 +35,13 @@ async fn get_redis_conn_success() { // Arrange Box::pin(utils::setup()).await; let (tx, _) = tokio::sync::oneshot::channel(); - let state = Box::pin(routes::AppState::new( + let app_state = Box::pin(routes::AppState::new( Settings::default(), tx, Box::new(services::MockApiClient), )) .await; + let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); // Act let result = state.store.get_redis_conn(); diff --git a/crates/router_env/tests/test_module/some_module.rs b/crates/router_env/tests/test_module/some_module.rs index 436decca716..8c9dda2c08e 100644 --- a/crates/router_env/tests/test_module/some_module.rs +++ b/crates/router_env/tests/test_module/some_module.rs @@ -1,7 +1,7 @@ use logger::instrument; use router_env as logger; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn fn_with_colon(val: i32) { let a = 13; let b = 31; @@ -23,7 +23,7 @@ pub async fn fn_with_colon(val: i32) { fn_without_colon(131).await; } -//#\[instrument\(fields(val3 = "abc"), skip_all)] +#[instrument(fields(val3 = "abc"), skip_all)] pub async fn fn_without_colon(val: i32) { let a = 13; let b = 31; diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs index 528023e8f02..5c5b821803b 100644 --- a/crates/scheduler/src/consumer.rs +++ b/crates/scheduler/src/consumer.rs @@ -1,6 +1,9 @@ // TODO: Figure out what to log -use std::sync::{self, atomic}; +use std::{ + sync::{self, atomic}, + time as std_time, +}; pub mod types; pub mod workflows; @@ -30,7 +33,7 @@ pub fn valid_business_statuses() -> Vec<&'static str> { vec!["Pending"] } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn start_consumer( state: &T, settings: sync::Arc, @@ -39,7 +42,7 @@ pub async fn start_consumer CustomResult<(), errors::ProcessTrackerError> where - F: Fn(&T, &str) -> U, + F: Fn(&T, &str) -> CustomResult, { use std::time::Duration; @@ -81,20 +84,29 @@ where if settings.consumer.disabled { continue; } + consumer_operation_counter.fetch_add(1, atomic::Ordering::SeqCst); + let start_time = std_time::Instant::now(); let tenants = state.get_tenants(); for tenant in tenants { - let session_state = app_state_to_session_state(state, tenant.as_str()); + let session_state = app_state_to_session_state(state, tenant.as_str())?; pt_utils::consumer_operation_handler( session_state.clone(), settings.clone(), |error| { logger::error!(?error, "Failed to perform consumer operation"); }, - sync::Arc::clone(&consumer_operation_counter), workflow_selector, ) .await; } + + let end_time = std_time::Instant::now(); + let duration = end_time.saturating_duration_since(start_time).as_secs_f64(); + logger::debug!("Time taken to execute consumer_operation: {}s", duration); + + let current_count = + consumer_operation_counter.fetch_sub(1, atomic::Ordering::SeqCst); + logger::info!("Current tasks being executed: {}", current_count); } Ok(()) | Err(mpsc::error::TryRecvError::Disconnected) => { logger::debug!("Awaiting shutdown!"); @@ -122,7 +134,7 @@ where Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn consumer_operations( state: &T, settings: &SchedulerSettings, @@ -132,13 +144,10 @@ pub async fn consumer_operations( let group_name = settings.consumer.consumer_group.clone(); let consumer_name = format!("consumer_{}", Uuid::new_v4()); - let group_created = &mut state + let _group_created = &mut state .get_db() .consumer_group_create(&stream_name, &group_name, &RedisEntryId::AfterLastID) .await; - if group_created.is_err() { - logger::info!("Consumer group {group_name} already exists"); - } let mut tasks = state .get_db() @@ -146,7 +155,9 @@ pub async fn consumer_operations( .fetch_consumer_tasks(&stream_name, &group_name, &consumer_name) .await?; - logger::info!("{} picked {} tasks", consumer_name, tasks.len()); + if tasks.len() > 0 { + logger::info!("{} picked {} tasks", consumer_name, tasks.len()); + } let mut handler = vec![]; for task in tasks.iter_mut() { @@ -168,7 +179,7 @@ pub async fn consumer_operations( Ok(()) } -//#\[instrument\(skip(db, redis_conn))] +#[instrument(skip(db, redis_conn))] pub async fn fetch_consumer_tasks( db: &dyn ProcessTrackerInterface, redis_conn: &RedisConnectionPool, @@ -215,7 +226,7 @@ pub async fn fetch_consumer_tasks( } // Accept flow_options if required -//#\[instrument\(skip(state), fields(workflow_id))] +#[instrument(skip(state), fields(workflow_id))] pub async fn start_workflow( state: T, process: storage::ProcessTracker, @@ -238,7 +249,7 @@ where res } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn consumer_error_handler( state: &(dyn SchedulerInterface + 'static), process: storage::ProcessTracker, diff --git a/crates/scheduler/src/errors.rs b/crates/scheduler/src/errors.rs index e4fd56ba8d2..39f3cd6e860 100644 --- a/crates/scheduler/src/errors.rs +++ b/crates/scheduler/src/errors.rs @@ -58,6 +58,8 @@ pub enum ProcessTrackerError { EEmailError(error_stack::Report), #[error("Type Conversion error")] TypeConversionError, + #[error("Tenant not found")] + TenantNotFound, } #[macro_export] diff --git a/crates/scheduler/src/producer.rs b/crates/scheduler/src/producer.rs index a470e7e6bfb..d0c0403dac0 100644 --- a/crates/scheduler/src/producer.rs +++ b/crates/scheduler/src/producer.rs @@ -19,7 +19,7 @@ use crate::{ scheduler::SchedulerInterface, utils::*, SchedulerAppState, }; -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn start_producer( state: &T, scheduler_settings: Arc, @@ -27,7 +27,7 @@ pub async fn start_producer( app_state_to_session_state: F, ) -> CustomResult<(), errors::ProcessTrackerError> where - F: Fn(&T, &str) -> U, + F: Fn(&T, &str) -> CustomResult, T: SchedulerAppState, U: SchedulerAppState, { @@ -70,7 +70,7 @@ where interval.tick().await; let tenants = state.get_tenants(); for tenant in tenants { - let session_state = app_state_to_session_state(state, tenant.as_str()); + let session_state = app_state_to_session_state(state, tenant.as_str())?; match run_producer_flow(&session_state, &scheduler_settings).await { Ok(_) => (), Err(error) => { @@ -99,7 +99,7 @@ where Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn run_producer_flow( state: &T, settings: &SchedulerSettings, @@ -128,7 +128,7 @@ where Ok(()) } -//#\[instrument\(skip_all)] +#[instrument(skip_all)] pub async fn fetch_producer_tasks( db: &dyn SchedulerInterface, conf: &SchedulerSettings, diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs index 1ccfaa49a66..bc2d7cb47d7 100644 --- a/crates/scheduler/src/scheduler.rs +++ b/crates/scheduler/src/scheduler.rs @@ -69,7 +69,7 @@ pub async fn start_process_tracker< app_state_to_session_state: F, ) -> CustomResult<(), errors::ProcessTrackerError> where - F: Fn(&T, &str) -> U, + F: Fn(&T, &str) -> CustomResult, { match scheduler_flow { SchedulerFlow::Producer => { diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs index 555472d3c7e..d51d6a6b338 100644 --- a/crates/scheduler/src/utils.rs +++ b/crates/scheduler/src/utils.rs @@ -1,7 +1,4 @@ -use std::{ - sync::{self, atomic}, - time as std_time, -}; +use std::sync; use common_utils::errors::CustomResult; use diesel_models::enums::{self, ProcessTrackerStatus}; @@ -253,31 +250,21 @@ pub fn get_time_from_delta(delta: Option) -> Option( state: T, settings: sync::Arc, error_handler_fun: E, - consumer_operation_counter: sync::Arc, workflow_selector: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, ) where // Error handler function E: FnOnce(error_stack::Report), T: SchedulerAppState, { - consumer_operation_counter.fetch_add(1, atomic::Ordering::SeqCst); - let start_time = std_time::Instant::now(); - match consumer::consumer_operations(&state, &settings, workflow_selector).await { Ok(_) => (), Err(err) => error_handler_fun(err), } - let end_time = std_time::Instant::now(); - let duration = end_time.saturating_duration_since(start_time).as_secs_f64(); - logger::debug!("Time taken to execute consumer_operation: {}s", duration); - - let current_count = consumer_operation_counter.fetch_sub(1, atomic::Ordering::SeqCst); - logger::info!("Current tasks being executed: {}", current_count); } pub fn add_histogram_metrics( diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rs index 7f5722b20f6..27a47b7d054 100644 --- a/crates/storage_impl/src/database/store.rs +++ b/crates/storage_impl/src/database/store.rs @@ -13,7 +13,8 @@ pub type PgPooledConn = async_bb8_diesel::Connection; #[async_trait::async_trait] pub trait DatabaseStore: Clone + Send + Sync { type Config: Send; - async fn new(config: Self::Config, schema: &str, test_transaction: bool) -> StorageResult; + async fn new(config: Self::Config, schema: &str, test_transaction: bool) + -> StorageResult; fn get_master_pool(&self) -> &PgPool; fn get_replica_pool(&self) -> &PgPool; } @@ -50,7 +51,11 @@ pub struct ReplicaStore { #[async_trait::async_trait] impl DatabaseStore for ReplicaStore { type Config = (Database, Database); - async fn new(config: (Database, Database), schema: &str, test_transaction: bool) -> StorageResult { + async fn new( + config: (Database, Database), + schema: &str, + test_transaction: bool, + ) -> StorageResult { let (master_config, replica_config) = config; let master_pool = diesel_make_pg_pool(&master_config, schema, test_transaction) .await diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 236fd2626ef..fc9fc3937d5 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -28,7 +28,7 @@ use common_utils::errors::CustomResult; use data_models::{PayoutAttemptInterface, PayoutsInterface}; use database::store::PgPool; pub use mock_db::MockDb; -use redis_interface::{errors::RedisError, SaddReply}; +use redis_interface::{errors::RedisError, RedisConnectionPool, SaddReply}; pub use crate::database::store::DatabaseStore; #[cfg(not(feature = "payouts"))] @@ -54,7 +54,11 @@ where tokio::sync::oneshot::Sender<()>, &'static str, ); - async fn new(config: Self::Config, schema: &str, test_transaction: bool) -> StorageResult { + async fn new( + config: Self::Config, + schema: &str, + test_transaction: bool, + ) -> StorageResult { let (db_conf, cache_conf, encryption_key, cache_error_signal, inmemory_cache_stream) = config; if test_transaction { @@ -81,9 +85,7 @@ where } impl RedisConnInterface for RouterStore { - fn get_redis_conn( - &self, - ) -> error_stack::Result, RedisError> { + fn get_redis_conn(&self) -> error_stack::Result, RedisError> { self.cache_store.get_redis_conn() } } @@ -96,9 +98,13 @@ impl RouterStore { cache_store: Arc, ) -> StorageResult { let db_store = T::new(db_conf, schema, false).await?; + let redis_conn = cache_store.redis_conn.clone(); + Ok(Self { db_store, - cache_store, + cache_store: Arc::new(RedisStore { + redis_conn: Arc::new(RedisConnectionPool::clone(&redis_conn, schema)), + }), master_encryption_key: encryption_key, request_id: None, }) @@ -166,8 +172,13 @@ where T: DatabaseStore, { type Config = (RouterStore, String, u8, u32); - async fn new(config: Self::Config, schema:&str ,_test_transaction: bool) -> StorageResult { - let (router_store, drainer_stream_name, drainer_num_partitions, ttl_for_kv) = config; + async fn new( + config: Self::Config, + schema: &str, + _test_transaction: bool, + ) -> StorageResult { + let (router_store, _, drainer_num_partitions, ttl_for_kv) = config; + let drainer_stream_name = format!("{}_{}", schema, config.1); Ok(Self::from_store( router_store, drainer_stream_name, @@ -184,9 +195,7 @@ where } impl RedisConnInterface for KVRouterStore { - fn get_redis_conn( - &self, - ) -> error_stack::Result, RedisError> { + fn get_redis_conn(&self) -> error_stack::Result, RedisError> { self.router_store.get_redis_conn() } } @@ -282,7 +291,7 @@ pub trait UniqueConstraints { fn table_name(&self) -> &str; async fn check_for_constraints( &self, - redis_conn: &Arc, + redis_conn: &Arc, ) -> CustomResult<(), RedisError> { let constraints = self.unique_constraints(); let sadd_result = redis_conn diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 8e88a46852b..138f3658aa0 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -38,7 +38,7 @@ use crate::{ #[async_trait::async_trait] impl PaymentAttemptInterface for RouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payment_attempt( &self, payment_attempt: PaymentAttemptNew, @@ -56,7 +56,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payment_attempt_with_attempt_id( &self, this: PaymentAttempt, @@ -74,7 +74,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id( &self, connector_transaction_id: &str, @@ -97,7 +97,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -118,7 +118,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -139,7 +139,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_merchant_id_connector_txn_id( &self, merchant_id: &str, @@ -160,7 +160,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id( &self, payment_id: &str, @@ -184,7 +184,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_filters_for_payments( &self, pi: &[PaymentIntent], @@ -222,7 +222,7 @@ impl PaymentAttemptInterface for RouterStore { ) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_preprocessing_id_merchant_id( &self, preprocessing_id: &str, @@ -244,7 +244,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_attempts_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -265,7 +265,7 @@ impl PaymentAttemptInterface for RouterStore { }) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_attempt_id_merchant_id( &self, attempt_id: &str, @@ -283,7 +283,7 @@ impl PaymentAttemptInterface for RouterStore { .map(PaymentAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_total_count_of_filtered_payment_attempts( &self, merchant_id: &str, @@ -325,7 +325,7 @@ impl PaymentAttemptInterface for RouterStore { #[async_trait::async_trait] impl PaymentAttemptInterface for KVRouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payment_attempt( &self, payment_attempt: PaymentAttemptNew, @@ -459,7 +459,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payment_attempt_with_attempt_id( &self, this: PaymentAttempt, @@ -576,7 +576,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id( &self, connector_transaction_id: &str, @@ -626,7 +626,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -678,7 +678,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_last_successful_or_partially_captured_attempt_by_payment_id_merchant_id( &self, payment_id: &str, @@ -733,7 +733,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_merchant_id_connector_txn_id( &self, merchant_id: &str, @@ -792,7 +792,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id( &self, payment_id: &str, @@ -839,7 +839,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_attempt_id_merchant_id( &self, attempt_id: &str, @@ -898,7 +898,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_attempt_by_preprocessing_id_merchant_id( &self, preprocessing_id: &str, @@ -957,7 +957,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_attempts_by_merchant_id_payment_id( &self, merchant_id: &str, @@ -1000,7 +1000,7 @@ impl PaymentAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_filters_for_payments( &self, pi: &[PaymentIntent], @@ -1012,7 +1012,7 @@ impl PaymentAttemptInterface for KVRouterStore { .await } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_total_count_of_filtered_payment_attempts( &self, merchant_id: &str, @@ -1977,7 +1977,7 @@ impl DataModelExt for PaymentAttemptUpdate { } #[inline] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn add_connector_txn_id_to_reverse_lookup( store: &KVRouterStore, key: &str, @@ -2000,7 +2000,7 @@ async fn add_connector_txn_id_to_reverse_lookup( } #[inline] -//#\[instrument\(skip_all)] +#[instrument(skip_all)] async fn add_preprocessing_id_to_reverse_lookup( store: &KVRouterStore, key: &str, diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs index eadb071ee78..8934b3ba2c6 100644 --- a/crates/storage_impl/src/payments/payment_intent.rs +++ b/crates/storage_impl/src/payments/payment_intent.rs @@ -143,7 +143,7 @@ impl PaymentIntentInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payment_intent( &self, this: PaymentIntent, @@ -204,7 +204,7 @@ impl PaymentIntentInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_intent_by_payment_id_merchant_id( &self, payment_id: &str, @@ -333,7 +333,7 @@ impl PaymentIntentInterface for KVRouterStore { #[async_trait::async_trait] impl PaymentIntentInterface for crate::RouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payment_intent( &self, new: PaymentIntentNew, @@ -350,7 +350,7 @@ impl PaymentIntentInterface for crate::RouterStore { .map(PaymentIntent::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payment_intent( &self, this: PaymentIntent, @@ -368,7 +368,7 @@ impl PaymentIntentInterface for crate::RouterStore { .map(PaymentIntent::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payment_intent_by_payment_id_merchant_id( &self, payment_id: &str, @@ -385,7 +385,7 @@ impl PaymentIntentInterface for crate::RouterStore { }) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_active_payment_attempt( &self, payment: &mut PaymentIntent, @@ -414,7 +414,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payment_intent_by_constraints( &self, merchant_id: &str, @@ -528,7 +528,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payment_intents_by_time_range_constraints( &self, merchant_id: &str, @@ -542,7 +542,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_filtered_payment_intents_attempt( &self, merchant_id: &str, @@ -683,7 +683,7 @@ impl PaymentIntentInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_filtered_active_attempt_ids_for_total_count( &self, merchant_id: &str, diff --git a/crates/storage_impl/src/payouts/payout_attempt.rs b/crates/storage_impl/src/payouts/payout_attempt.rs index 9f1772a4466..50334442e63 100644 --- a/crates/storage_impl/src/payouts/payout_attempt.rs +++ b/crates/storage_impl/src/payouts/payout_attempt.rs @@ -36,7 +36,7 @@ use crate::{ #[async_trait::async_trait] impl PayoutAttemptInterface for KVRouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payout_attempt( &self, new_payout_attempt: PayoutAttemptNew, @@ -128,7 +128,7 @@ impl PayoutAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payout_attempt( &self, this: &PayoutAttempt, @@ -188,7 +188,7 @@ impl PayoutAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payout_attempt_by_merchant_id_payout_attempt_id( &self, merchant_id: &str, @@ -246,7 +246,7 @@ impl PayoutAttemptInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_filters_for_payouts( &self, payouts: &[Payouts], @@ -261,7 +261,7 @@ impl PayoutAttemptInterface for KVRouterStore { #[async_trait::async_trait] impl PayoutAttemptInterface for crate::RouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payout_attempt( &self, new: PayoutAttemptNew, @@ -279,7 +279,7 @@ impl PayoutAttemptInterface for crate::RouterStore { .map(PayoutAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payout_attempt( &self, this: &PayoutAttempt, @@ -299,7 +299,7 @@ impl PayoutAttemptInterface for crate::RouterStore { .map(PayoutAttempt::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payout_attempt_by_merchant_id_payout_attempt_id( &self, merchant_id: &str, @@ -320,7 +320,7 @@ impl PayoutAttemptInterface for crate::RouterStore { }) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn get_filters_for_payouts( &self, payouts: &[Payouts], diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs index 8561cfdbd5d..24f4ee841f0 100644 --- a/crates/storage_impl/src/payouts/payouts.rs +++ b/crates/storage_impl/src/payouts/payouts.rs @@ -45,7 +45,7 @@ use crate::{ #[async_trait::async_trait] impl PayoutsInterface for KVRouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payout( &self, new: PayoutsNew, @@ -119,7 +119,7 @@ impl PayoutsInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payout( &self, this: &Payouts, @@ -177,7 +177,7 @@ impl PayoutsInterface for KVRouterStore { } } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -219,7 +219,7 @@ impl PayoutsInterface for KVRouterStore { .map(Payouts::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_optional_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -272,7 +272,7 @@ impl PayoutsInterface for KVRouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payouts_by_constraints( &self, merchant_id: &str, @@ -285,7 +285,7 @@ impl PayoutsInterface for KVRouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payouts_and_attempts( &self, merchant_id: &str, @@ -314,7 +314,7 @@ impl PayoutsInterface for KVRouterStore { #[async_trait::async_trait] impl PayoutsInterface for crate::RouterStore { - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn insert_payout( &self, new: PayoutsNew, @@ -331,7 +331,7 @@ impl PayoutsInterface for crate::RouterStore { .map(Payouts::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn update_payout( &self, this: &Payouts, @@ -351,7 +351,7 @@ impl PayoutsInterface for crate::RouterStore { .map(Payouts::from_storage_model) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -368,7 +368,7 @@ impl PayoutsInterface for crate::RouterStore { }) } - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn find_optional_payout_by_merchant_id_payout_id( &self, merchant_id: &str, @@ -386,7 +386,7 @@ impl PayoutsInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payouts_by_constraints( &self, merchant_id: &str, @@ -502,7 +502,7 @@ impl PayoutsInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payouts_and_attempts( &self, merchant_id: &str, @@ -636,7 +636,7 @@ impl PayoutsInterface for crate::RouterStore { } #[cfg(feature = "olap")] - //#\[instrument\(skip_all)] + #[instrument(skip_all)] async fn filter_payouts_by_time_range_constraints( &self, merchant_id: &str, From 50559b7c49f89b7d6ca8a25fb8b8bcabbd47e63f Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Mon, 13 May 2024 16:54:00 +0530 Subject: [PATCH 03/24] feat(multitenancy): format code and remove unused deps --- crates/analytics/src/api_event/core.rs | 2 +- crates/drainer/src/handler.rs | 2 +- crates/drainer/src/stream.rs | 4 +- .../compatibility/stripe/payment_intents.rs | 5 --- crates/router/src/core/admin.rs | 1 - crates/router/src/core/currency.rs | 1 - crates/router/src/core/locker_migration.rs | 1 - crates/router/src/core/payments/customers.rs | 2 +- .../payments/operations/payment_create.rs | 1 - crates/router/src/core/refunds.rs | 2 +- crates/router/src/routes/payments.rs | 5 --- crates/router/src/services/api.rs | 41 ++++++------------- crates/router/src/utils/currency.rs | 7 ---- crates/storage_impl/src/payouts/payouts.rs | 2 +- 14 files changed, 20 insertions(+), 56 deletions(-) diff --git a/crates/analytics/src/api_event/core.rs b/crates/analytics/src/api_event/core.rs index a3185fc056b..7225a6322d4 100644 --- a/crates/analytics/src/api_event/core.rs +++ b/crates/analytics/src/api_event/core.rs @@ -26,7 +26,7 @@ use crate::{ AnalyticsProvider, }; -//#[instrument(skip_all)] +#[instrument(skip_all)] pub async fn api_events_core( pool: &AnalyticsProvider, req: ApiLogsRequest, diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs index 856c13e8fdf..80e59a049c6 100644 --- a/crates/drainer/src/handler.rs +++ b/crates/drainer/src/handler.rs @@ -164,7 +164,7 @@ pub async fn redis_error_receiver(rx: oneshot::Receiver<()>, shutdown_channel: m } } -//#[router_env::instrument(skip_all)] +#[router_env::instrument(skip_all)] async fn drainer_handler( store: Arc, stream_index: u8, diff --git a/crates/drainer/src/stream.rs b/crates/drainer/src/stream.rs index 98aa7d7307d..319fc2b0e1d 100644 --- a/crates/drainer/src/stream.rs +++ b/crates/drainer/src/stream.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use redis_interface as redis; -use router_env::logger; +use router_env::{logger, tracing}; use crate::{errors, metrics, Store}; @@ -25,7 +25,7 @@ impl Store { self.drainer_stream(format!("shard_{stream_index}").as_str()) } - //#[router_env::instrument(skip_all)] + #[router_env::instrument(skip_all)] pub async fn is_stream_available(&self, stream_index: u8) -> bool { let stream_key_flag = self.get_stream_key_flag(stream_index); diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs index 25fe8e98aa2..d67e10a96e5 100644 --- a/crates/router/src/compatibility/stripe/payment_intents.rs +++ b/crates/router/src/compatibility/stripe/payment_intents.rs @@ -69,7 +69,6 @@ pub async fn payment_intents_create( payments::CallConnectorAction::Trigger, eligible_connectors, api_types::HeaderPayload::default(), - ) }, &auth::ApiKeyAuth, @@ -200,7 +199,6 @@ pub async fn payment_intents_retrieve_with_gateway_creds( payments::CallConnectorAction::Trigger, None, api_types::HeaderPayload::default(), - ) }, &*auth_type, @@ -267,7 +265,6 @@ pub async fn payment_intents_update( payments::CallConnectorAction::Trigger, eligible_connectors, api_types::HeaderPayload::default(), - ) }, &*auth_type, @@ -340,7 +337,6 @@ pub async fn payment_intents_confirm( payments::CallConnectorAction::Trigger, eligible_connectors, api_types::HeaderPayload::default(), - ) }, &*auth_type, @@ -402,7 +398,6 @@ pub async fn payment_intents_capture( payments::CallConnectorAction::Trigger, None, api_types::HeaderPayload::default(), - ) }, &auth::ApiKeyAuth, diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 369b54bda55..43977db3c58 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -731,7 +731,6 @@ fn validate_certificate_in_mca_metadata( pub async fn create_payment_connector( state: SessionState, - req: api::MerchantConnectorCreate, merchant_id: &String, ) -> RouterResponse { diff --git a/crates/router/src/core/currency.rs b/crates/router/src/core/currency.rs index 66f8cfba3a9..96d75098271 100644 --- a/crates/router/src/core/currency.rs +++ b/crates/router/src/core/currency.rs @@ -28,7 +28,6 @@ pub async fn retrieve_forex( pub async fn convert_forex( state: SessionState, - amount: i64, to_currency: String, from_currency: String, diff --git a/crates/router/src/core/locker_migration.rs b/crates/router/src/core/locker_migration.rs index d07b2310254..385b2166437 100644 --- a/crates/router/src/core/locker_migration.rs +++ b/crates/router/src/core/locker_migration.rs @@ -76,7 +76,6 @@ pub async fn rust_locker_migration( pub async fn call_to_locker( state: &SessionState, - payment_methods: Vec, customer_id: &String, merchant_id: &str, diff --git a/crates/router/src/core/payments/customers.rs b/crates/router/src/core/payments/customers.rs index 163a93c1e92..448e5fedb8b 100644 --- a/crates/router/src/core/payments/customers.rs +++ b/crates/router/src/core/payments/customers.rs @@ -111,7 +111,7 @@ pub fn should_call_connector_create_customer<'a>( } } -//#[instrument] +#[instrument] pub async fn update_connector_customer_in_customers( connector_label: &str, customer: Option<&domain::Customer>, diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index b2927cfcad3..e561f70af12 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -763,7 +763,6 @@ impl PaymentCreate { request: &api::PaymentsRequest, browser_info: Option, state: &SessionState, - payment_method_billing_address_id: Option, payment_method_info: &Option, key_store: &domain::MerchantKeyStore, diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 524fcd57a8c..9fc8a9132eb 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -1057,7 +1057,7 @@ pub async fn trigger_refund_execute_workflow( Ok(()) } -//#[instrument] +#[instrument] pub fn refund_to_refund_core_workflow_model( refund: &storage::Refund, ) -> storage::RefundCoreWorkflow { diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs index 22ada3be6cc..ee4e5ccd96b 100644 --- a/crates/router/src/routes/payments.rs +++ b/crates/router/src/routes/payments.rs @@ -282,7 +282,6 @@ pub async fn payments_retrieve( payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), - ) }, auth::auth_type( @@ -356,7 +355,6 @@ pub async fn payments_retrieve_with_gateway_creds( payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), - ) }, &*auth_type, @@ -857,7 +855,6 @@ pub async fn payments_cancel( payments::CallConnectorAction::Trigger, None, HeaderPayload::default(), - ) }, &auth::ApiKeyAuth, @@ -1073,7 +1070,6 @@ pub async fn payments_reject( payments::CallConnectorAction::Trigger, None, payment_types::HeaderPayload::default(), - ) }, match env::which() { @@ -1341,7 +1337,6 @@ pub async fn post_3ds_payments_authorize( auth.merchant_account, auth.key_store, req, - ) }, &auth::MerchantIdAuth(merchant_id), diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index aebaaa008f3..2b0055efa58 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -991,19 +991,19 @@ where let mut event_type = payload.get_api_event_type(); - // let tenant_id = incoming_request_header - // .get("x-tenant-id") - // .and_then(|value| value.to_str().ok()) - // .ok_or_else(|| { - // errors::ApiErrorResponse::InvalidRequestData { message: "Missing tenant Id".to_string() } - // .switch() - // }).map(|tenant_id| if !state.conf.multitenancy.get_tenant_names().contains(&tenant_id.to_string()) { - // Err(errors::ApiErrorResponse::InvalidTenant { tenant_id: tenant_id.to_string() } - // .switch()) - // } else { - // Ok(tenant_id) - // } )??; - let tenant_id = "public"; + let tenant_id = incoming_request_header + .get("x-tenant-id") + .and_then(|value| value.to_str().ok()) + .ok_or_else(|| { + errors::ApiErrorResponse::InvalidRequestData { message: "Missing tenant Id".to_string() } + .switch() + }).map(|tenant_id| if !state.conf.multitenancy.get_tenant_names().contains(&tenant_id.to_string()) { + Err(errors::ApiErrorResponse::InvalidTenant { tenant_id: tenant_id.to_string() } + .switch()) + } else { + Ok(tenant_id) + } )??; + // let tenant_id = "public"; let mut session_state = SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id, || { errors::ApiErrorResponse::InvalidTenant { @@ -1011,21 +1011,6 @@ where } .switch() })?; - // { - // store: state.stores.get(tenant_id).ok_or_else(|| { - // errors::ApiErrorResponse::InternalServerError - // .switch() - // })?.clone(), - // conf: Arc::clone(&state.conf), - // api_client: state.api_client.clone(), - // event_handler: state.event_handler.clone(), - // pool: state.pools.get(tenant_id).ok_or_else(|| { - // errors::ApiErrorResponse::InternalServerError - // .switch() - // })?.clone(), - // file_storage_client: state.file_storage_client.clone(), - // request_id: state.request_id.clone(), - // }; session_state.add_request_id(request_id); // Currently auth failures are not recorded as API events diff --git a/crates/router/src/utils/currency.rs b/crates/router/src/utils/currency.rs index 8d5eb5bb76d..0bdcb23224d 100644 --- a/crates/router/src/utils/currency.rs +++ b/crates/router/src/utils/currency.rs @@ -122,7 +122,6 @@ async fn save_forex_to_local( #[allow(dead_code)] async fn waited_fetch_and_update_caches( state: &SessionState, - local_fetch_retry_delay: u64, local_fetch_retry_count: u64, ) -> CustomResult { @@ -173,7 +172,6 @@ impl From for CurrencyFactors { } pub async fn get_forex_rates( state: &SessionState, - call_delay: i64, local_fetch_retry_delay: u64, local_fetch_retry_count: u64, @@ -200,7 +198,6 @@ pub async fn get_forex_rates( async fn handler_local_no_data( state: &SessionState, - call_delay: i64, _local_fetch_retry_delay: u64, _local_fetch_retry_count: u64, @@ -220,7 +217,6 @@ async fn handler_local_no_data( async fn successive_fetch_and_save_forex( state: &SessionState, - stale_redis_data: Option, ) -> CustomResult { match acquire_redis_lock(state).await { @@ -273,7 +269,6 @@ async fn successive_save_data_to_redis_local( async fn fallback_forex_redis_check( state: &SessionState, - redis_data: FxExchangeRatesCacheEntry, call_delay: i64, ) -> CustomResult { @@ -293,7 +288,6 @@ async fn fallback_forex_redis_check( async fn handler_local_expired( state: &SessionState, - call_delay: i64, local_rates: FxExchangeRatesCacheEntry, ) -> CustomResult { @@ -517,7 +511,6 @@ async fn is_redis_expired( pub async fn convert_currency( state: SessionState, - amount: i64, to_currency: String, from_currency: String, diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs index 24f4ee841f0..0f72aa592bf 100644 --- a/crates/storage_impl/src/payouts/payouts.rs +++ b/crates/storage_impl/src/payouts/payouts.rs @@ -299,7 +299,7 @@ impl PayoutsInterface for KVRouterStore { } #[cfg(feature = "olap")] - //#[instrument[skip_all]] + #[instrument[skip_all]] async fn filter_payouts_by_time_range_constraints( &self, merchant_id: &str, From 54c1aee9ecc18b6afa899646a475ce3319fde7fc Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Mon, 13 May 2024 17:12:07 +0530 Subject: [PATCH 04/24] feat(multitenancy): create sessionstate for scheduler --- .vscode/launch.json | 1103 -------------------- crates/router/src/bin/scheduler.rs | 2 +- crates/router/src/routes/app.rs | 9 +- crates/scheduler/src/consumer.rs | 8 +- crates/scheduler/src/consumer/workflows.rs | 4 +- crates/scheduler/src/producer.rs | 6 +- crates/scheduler/src/scheduler.rs | 8 +- crates/scheduler/src/utils.rs | 4 +- 8 files changed, 18 insertions(+), 1126 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index ca8e7b50cd9..00000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,1103 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'analytics'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=analytics" - ], - "filter": { - "name": "analytics", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'analytics'", - "cargo": { - "args": [ - "build", - "--bin=analytics", - "--package=analytics" - ], - "filter": { - "name": "analytics", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'analytics'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=analytics", - "--package=analytics" - ], - "filter": { - "name": "analytics", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'api_models'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=api_models" - ], - "filter": { - "name": "api_models", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'cards'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=cards" - ], - "filter": { - "name": "cards", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'basic'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=basic", - "--package=cards" - ], - "filter": { - "name": "basic", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'common_utils'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=common_utils" - ], - "filter": { - "name": "common_utils", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'percentage'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=percentage", - "--package=common_utils" - ], - "filter": { - "name": "percentage", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'common_enums'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=common_enums" - ], - "filter": { - "name": "common_enums", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'masking'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=masking" - ], - "filter": { - "name": "masking", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'basic'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=basic", - "--package=masking" - ], - "filter": { - "name": "basic", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'router_env'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=router_env" - ], - "filter": { - "name": "router_env", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'logger'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=logger", - "--package=router_env" - ], - "filter": { - "name": "logger", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'env'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=env", - "--package=router_env" - ], - "filter": { - "name": "env", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'euclid'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=euclid" - ], - "filter": { - "name": "euclid", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug benchmark 'backends'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bench=backends", - "--package=euclid" - ], - "filter": { - "name": "backends", - "kind": "bench" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'diesel_models'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=diesel_models" - ], - "filter": { - "name": "diesel_models", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'external_services'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=external_services" - ], - "filter": { - "name": "external_services", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'hyperswitch_interfaces'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=hyperswitch_interfaces" - ], - "filter": { - "name": "hyperswitch_interfaces", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'storage_impl'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=storage_impl" - ], - "filter": { - "name": "storage_impl", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'data_models'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=data_models" - ], - "filter": { - "name": "data_models", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'redis_interface'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=redis_interface" - ], - "filter": { - "name": "redis_interface", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'config_importer'", - "cargo": { - "args": [ - "build", - "--bin=config_importer", - "--package=config_importer" - ], - "filter": { - "name": "config_importer", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'config_importer'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=config_importer", - "--package=config_importer" - ], - "filter": { - "name": "config_importer", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'connector_configs'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=connector_configs" - ], - "filter": { - "name": "connector_configs", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'currency_conversion'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=currency_conversion" - ], - "filter": { - "name": "currency_conversion", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'drainer'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=drainer" - ], - "filter": { - "name": "drainer", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'drainer'", - "cargo": { - "args": [ - "build", - "--bin=drainer", - "--package=drainer" - ], - "filter": { - "name": "drainer", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'drainer'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=drainer", - "--package=drainer" - ], - "filter": { - "name": "drainer", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'kgraph_utils'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=kgraph_utils" - ], - "filter": { - "name": "kgraph_utils", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug benchmark 'evaluation'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bench=evaluation", - "--package=kgraph_utils" - ], - "filter": { - "name": "evaluation", - "kind": "bench" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'events'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=events" - ], - "filter": { - "name": "events", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'openapi'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=openapi" - ], - "filter": { - "name": "openapi", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'openapi'", - "cargo": { - "args": [ - "build", - "--bin=openapi", - "--package=openapi" - ], - "filter": { - "name": "openapi", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'openapi'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=openapi", - "--package=openapi" - ], - "filter": { - "name": "openapi", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'pm_auth'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=pm_auth" - ], - "filter": { - "name": "pm_auth", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'router'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=router" - ], - "filter": { - "name": "router", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'router'", - "cargo": { - "args": [ - "build", - "--bin=router", - "--package=router" - ], - "filter": { - "name": "router", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'router'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=router", - "--package=router" - ], - "filter": { - "name": "router", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'scheduler'", - "cargo": { - "args": [ - "build", - "--bin=scheduler", - "--package=router" - ], - "filter": { - "name": "scheduler", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'scheduler'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=scheduler", - "--package=router" - ], - "filter": { - "name": "scheduler", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'connectors'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=connectors", - "--package=router" - ], - "filter": { - "name": "connectors", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'cache'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=cache", - "--package=router" - ], - "filter": { - "name": "cache", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'integration_demo'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=integration_demo", - "--package=router" - ], - "filter": { - "name": "integration_demo", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'refunds'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=refunds", - "--package=router" - ], - "filter": { - "name": "refunds", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'payouts'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=payouts", - "--package=router" - ], - "filter": { - "name": "payouts", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'payments'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=payments", - "--package=router" - ], - "filter": { - "name": "payments", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'services'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=services", - "--package=router" - ], - "filter": { - "name": "services", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'webhooks'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=webhooks", - "--package=router" - ], - "filter": { - "name": "webhooks", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'customers'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=customers", - "--package=router" - ], - "filter": { - "name": "customers", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'payments2'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=payments2", - "--package=router" - ], - "filter": { - "name": "payments2", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'health_check'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=health_check", - "--package=router" - ], - "filter": { - "name": "health_check", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'utils'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=utils", - "--package=router" - ], - "filter": { - "name": "utils", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'scheduler'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=scheduler" - ], - "filter": { - "name": "scheduler", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'test_utils'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=test_utils" - ], - "filter": { - "name": "test_utils", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'test_utils'", - "cargo": { - "args": [ - "build", - "--bin=test_utils", - "--package=test_utils" - ], - "filter": { - "name": "test_utils", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'test_utils'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=test_utils", - "--package=test_utils" - ], - "filter": { - "name": "test_utils", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug integration test 'connectors'", - "cargo": { - "args": [ - "test", - "--no-run", - "--test=connectors", - "--package=test_utils" - ], - "filter": { - "name": "connectors", - "kind": "test" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - } - ] -} \ No newline at end of file diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs index eefe3513b14..85d7043bc28 100644 --- a/crates/router/src/bin/scheduler.rs +++ b/crates/router/src/bin/scheduler.rs @@ -22,7 +22,7 @@ use router_env::{ }; use scheduler::{ consumer::workflows::ProcessTrackerWorkflow, errors::ProcessTrackerError, - workflows::ProcessTrackerWorkflows, SchedulerAppState, + workflows::ProcessTrackerWorkflows, SchedulerSessionState, }; use storage_impl::errors::ApplicationError; use tokio::sync::{mpsc, oneshot}; diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 7ddbaf8832d..540c44ca65d 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -76,14 +76,10 @@ pub struct SessionState { pub request_id: Option, pub base_url: String, } -impl scheduler::SchedulerAppState for SessionState { +impl scheduler::SchedulerSessionState for SessionState { fn get_db(&self) -> Box { self.store.get_scheduler_db() } - - fn get_tenants(&self) -> Vec { - self.conf.multitenancy.get_tenant_names().clone() - } } impl SessionState { pub fn get_req_state(&self) -> ReqState { @@ -160,9 +156,6 @@ pub struct AppState { pub encryption_client: Box, } impl scheduler::SchedulerAppState for AppState { - fn get_db(&self) -> Box { - todo!() - } fn get_tenants(&self) -> Vec { self.conf.multitenancy.get_tenant_names().clone() } diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs index 5c5b821803b..6d3eba64e6a 100644 --- a/crates/scheduler/src/consumer.rs +++ b/crates/scheduler/src/consumer.rs @@ -25,7 +25,7 @@ use super::env::logger; pub use super::workflows::ProcessTrackerWorkflow; use crate::{ configs::settings::SchedulerSettings, db::process_tracker::ProcessTrackerInterface, errors, - metrics, utils as pt_utils, SchedulerAppState, SchedulerInterface, + metrics, utils as pt_utils, SchedulerAppState, SchedulerSessionState, SchedulerInterface, }; // Valid consumer business statuses @@ -34,7 +34,7 @@ pub fn valid_business_statuses() -> Vec<&'static str> { } #[instrument(skip_all)] -pub async fn start_consumer( +pub async fn start_consumer( state: &T, settings: sync::Arc, workflow_selector: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, @@ -135,7 +135,7 @@ where } #[instrument(skip_all)] -pub async fn consumer_operations( +pub async fn consumer_operations( state: &T, settings: &SchedulerSettings, workflow_selector: impl workflows::ProcessTrackerWorkflows + 'static + Copy + std::fmt::Debug, @@ -234,7 +234,7 @@ pub async fn start_workflow( workflow_selector: impl workflows::ProcessTrackerWorkflows + 'static + std::fmt::Debug, ) -> CustomResult<(), errors::ProcessTrackerError> where - T: SchedulerAppState, + T: SchedulerSessionState, { tracing::Span::current().record("workflow_id", Uuid::new_v4().to_string()); logger::info!(pt.name=?process.name, pt.id=%process.id); diff --git a/crates/scheduler/src/consumer/workflows.rs b/crates/scheduler/src/consumer/workflows.rs index 3e8a4c8e502..bbece87f309 100644 --- a/crates/scheduler/src/consumer/workflows.rs +++ b/crates/scheduler/src/consumer/workflows.rs @@ -3,7 +3,7 @@ use common_utils::errors::CustomResult; pub use diesel_models::process_tracker as storage; use router_env::logger; -use crate::{errors, SchedulerAppState}; +use crate::{errors, SchedulerSessionState}; pub type WorkflowSelectorFn = fn(&storage::ProcessTracker) -> Result<(), errors::ProcessTrackerError>; @@ -26,7 +26,7 @@ pub trait ProcessTrackerWorkflows: Send + Sync { process: storage::ProcessTracker, ) -> CustomResult<(), errors::ProcessTrackerError> where - T: SchedulerAppState, + T: SchedulerSessionState, { let app_state = &state.clone(); let output = operation.execute_workflow(app_state, process.clone()).await; diff --git a/crates/scheduler/src/producer.rs b/crates/scheduler/src/producer.rs index d0c0403dac0..563a55a701f 100644 --- a/crates/scheduler/src/producer.rs +++ b/crates/scheduler/src/producer.rs @@ -16,7 +16,7 @@ use super::{ }; use crate::{ configs::settings::SchedulerSettings, errors, flow::SchedulerFlow, - scheduler::SchedulerInterface, utils::*, SchedulerAppState, + scheduler::SchedulerInterface, utils::*, SchedulerAppState, SchedulerSessionState, }; #[instrument(skip_all)] @@ -29,7 +29,7 @@ pub async fn start_producer( where F: Fn(&T, &str) -> CustomResult, T: SchedulerAppState, - U: SchedulerAppState, + U: SchedulerSessionState, { use std::time::Duration; @@ -105,7 +105,7 @@ pub async fn run_producer_flow( settings: &SchedulerSettings, ) -> CustomResult<(), errors::ProcessTrackerError> where - T: SchedulerAppState, + T: SchedulerSessionState, { lock_acquire_release::<_, _, _>(state.get_db().as_scheduler(), settings, move || async { let tasks = fetch_producer_tasks(state.get_db().as_scheduler(), settings).await?; diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs index bc2d7cb47d7..39a45d02ba9 100644 --- a/crates/scheduler/src/scheduler.rs +++ b/crates/scheduler/src/scheduler.rs @@ -52,13 +52,15 @@ impl SchedulerInterface for MockDb {} #[async_trait::async_trait] pub trait SchedulerAppState: Send + Sync + Clone { - fn get_db(&self) -> Box; fn get_tenants(&self) -> Vec; } - +#[async_trait::async_trait] +pub trait SchedulerSessionState: Send + Sync + Clone { + fn get_db(&self) -> Box; +} pub async fn start_process_tracker< T: SchedulerAppState + 'static, - U: SchedulerAppState + 'static, + U: SchedulerSessionState + 'static, F, >( state: &T, diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs index d51d6a6b338..54025f2f972 100644 --- a/crates/scheduler/src/utils.rs +++ b/crates/scheduler/src/utils.rs @@ -14,7 +14,7 @@ use super::{ }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, - flow::SchedulerFlow, metrics, SchedulerAppState, SchedulerInterface, + flow::SchedulerFlow, metrics, SchedulerSessionState, SchedulerInterface, }; pub async fn divide_and_append_tasks( @@ -259,7 +259,7 @@ pub async fn consumer_operation_handler( ) where // Error handler function E: FnOnce(error_stack::Report), - T: SchedulerAppState, + T: SchedulerSessionState, { match consumer::consumer_operations(&state, &settings, workflow_selector).await { Ok(_) => (), From 7d35c89d42c45f7c210bc5a1594aa21707e08d71 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 08:41:05 +0000 Subject: [PATCH 05/24] chore: run formatter --- crates/router/src/core/payments.rs | 7 ++--- crates/router/src/core/poll.rs | 4 ++- crates/router/src/routes.rs | 3 ++- crates/router/src/routes/app.rs | 13 +++++----- crates/router/src/services.rs | 1 + crates/router/src/services/api.rs | 26 ++++++++++++++----- .../src/types/domain/user/decision_manager.rs | 6 ++++- crates/scheduler/src/consumer.rs | 2 +- crates/scheduler/src/utils.rs | 2 +- crates/storage_impl/src/lib.rs | 1 + 10 files changed, 42 insertions(+), 23 deletions(-) diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 643f93ae610..d1981593638 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -3987,11 +3987,8 @@ pub async fn payment_external_authentication( &payment_attempt.clone(), payment_connector_name, )); - let webhook_url = helpers::create_webhook_url( - &state.base_url, - merchant_id, - &authentication_connector, - ); + let webhook_url = + helpers::create_webhook_url(&state.base_url, merchant_id, &authentication_connector); let business_profile = state .store diff --git a/crates/router/src/core/poll.rs b/crates/router/src/core/poll.rs index fd214ad13bd..53b4b02e610 100644 --- a/crates/router/src/core/poll.rs +++ b/crates/router/src/core/poll.rs @@ -4,7 +4,9 @@ use error_stack::ResultExt; use router_env::{instrument, tracing}; use super::errors; -use crate::{core::errors::RouterResponse, services::ApplicationResponse, types::domain, SessionState}; +use crate::{ + core::errors::RouterResponse, services::ApplicationResponse, types::domain, SessionState, +}; #[instrument(skip_all)] pub async fn retrieve_poll_status( diff --git a/crates/router/src/routes.rs b/crates/router/src/routes.rs index d5d8fb89120..9f13635ca90 100644 --- a/crates/router/src/routes.rs +++ b/crates/router/src/routes.rs @@ -60,7 +60,8 @@ pub use self::app::Recon; pub use self::app::{ ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers, Disputes, EphemeralKey, Files, Gsm, Health, Mandates, MerchantAccount, - MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Poll, Refunds, SessionState, User, Webhooks, + MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Poll, Refunds, SessionState, + User, Webhooks, }; #[cfg(feature = "olap")] pub use self::app::{Blocklist, Routing, Verify, WebhookEvents}; diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 885e1f9701b..87e9a50cd17 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -114,7 +114,7 @@ impl SessionState { #[cfg(feature = "email")] email_client: Arc::clone(&state.email_client), #[cfg(feature = "olap")] - opensearch_client: Arc::clone(&state.opensearch_client) + opensearch_client: Arc::clone(&state.opensearch_client), }) } } @@ -259,11 +259,12 @@ impl AppState { #[allow(clippy::expect_used)] #[cfg(feature = "olap")] - let opensearch_client = Arc::new(conf - .opensearch - .get_opensearch_client() - .await - .expect("Failed to create opensearch client")); + let opensearch_client = Arc::new( + conf.opensearch + .get_opensearch_client() + .await + .expect("Failed to create opensearch client"), + ); let mut pools = HashMap::new(); let mut stores = HashMap::new(); diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index 46230847cf4..1c8e40fdc9c 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -14,6 +14,7 @@ pub mod recon; pub mod email; use std::sync::Arc; + use error_stack::ResultExt; use hyperswitch_domain_models::errors::StorageResult; use masking::{ExposeInterface, StrongSecret}; diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 8c489324777..a31374b3b89 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1015,14 +1015,26 @@ where .get("x-tenant-id") .and_then(|value| value.to_str().ok()) .ok_or_else(|| { - errors::ApiErrorResponse::InvalidRequestData { message: "Missing tenant Id".to_string() } + errors::ApiErrorResponse::InvalidRequestData { + message: "Missing tenant Id".to_string(), + } .switch() - }).map(|tenant_id| if !state.conf.multitenancy.get_tenant_names().contains(&tenant_id.to_string()) { - Err(errors::ApiErrorResponse::InvalidTenant { tenant_id: tenant_id.to_string() } - .switch()) - } else { - Ok(tenant_id) - } )??; + }) + .map(|tenant_id| { + if !state + .conf + .multitenancy + .get_tenant_names() + .contains(&tenant_id.to_string()) + { + Err(errors::ApiErrorResponse::InvalidTenant { + tenant_id: tenant_id.to_string(), + } + .switch()) + } else { + Ok(tenant_id) + } + })??; // let tenant_id = "public"; let mut session_state = SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id, || { diff --git a/crates/router/src/types/domain/user/decision_manager.rs b/crates/router/src/types/domain/user/decision_manager.rs index a33bd7ffe4e..41ae12350fb 100644 --- a/crates/router/src/types/domain/user/decision_manager.rs +++ b/crates/router/src/types/domain/user/decision_manager.rs @@ -74,7 +74,11 @@ pub enum JWTFlow { } impl JWTFlow { - async fn is_required(&self, _user: &UserFromStorage, _state: &SessionState) -> UserResult { + async fn is_required( + &self, + _user: &UserFromStorage, + _state: &SessionState, + ) -> UserResult { Ok(true) } diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs index 6d3eba64e6a..986aed370fe 100644 --- a/crates/scheduler/src/consumer.rs +++ b/crates/scheduler/src/consumer.rs @@ -25,7 +25,7 @@ use super::env::logger; pub use super::workflows::ProcessTrackerWorkflow; use crate::{ configs::settings::SchedulerSettings, db::process_tracker::ProcessTrackerInterface, errors, - metrics, utils as pt_utils, SchedulerAppState, SchedulerSessionState, SchedulerInterface, + metrics, utils as pt_utils, SchedulerAppState, SchedulerInterface, SchedulerSessionState, }; // Valid consumer business statuses diff --git a/crates/scheduler/src/utils.rs b/crates/scheduler/src/utils.rs index f2cc4d656c0..7f073a8e10b 100644 --- a/crates/scheduler/src/utils.rs +++ b/crates/scheduler/src/utils.rs @@ -14,7 +14,7 @@ use super::{ }; use crate::{ configs::settings::SchedulerSettings, consumer::types::ProcessTrackerBatch, errors, - flow::SchedulerFlow, metrics, SchedulerSessionState, SchedulerInterface, + flow::SchedulerFlow, metrics, SchedulerInterface, SchedulerSessionState, }; pub async fn divide_and_append_tasks( diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index d9f0e1e6730..99305712c59 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -30,6 +30,7 @@ use database::store::PgPool; use hyperswitch_domain_models::{PayoutAttemptInterface, PayoutsInterface}; pub use mock_db::MockDb; use redis_interface::{errors::RedisError, RedisConnectionPool, SaddReply}; + pub use crate::database::store::DatabaseStore; #[cfg(not(feature = "payouts"))] pub use crate::database::store::Store; From b2b05c3cd8f0d100c552a22e1e50cc377ec34c2f Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Tue, 14 May 2024 14:11:37 +0530 Subject: [PATCH 06/24] feat(multitenancy): update tenants --- config/development.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/development.toml b/config/development.toml index 6984964b05b..833829c7647 100644 --- a/config/development.toml +++ b/config/development.toml @@ -629,5 +629,4 @@ disputes = "hyperswitch-dispute-events" sdk_eligible_payment_methods = "card" [multitenancy.tenants] -public = { name = "hyperswitch", base_url = "http://localhost:8080"} -zurich = { name = "zurich", base_url = "http://localhost:9090"} \ No newline at end of file +public = { name = "hyperswitch", base_url = "http://localhost:8080"} \ No newline at end of file From e60f9b53fdda5a097d044fcac453bf4880926979 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Wed, 15 May 2024 12:44:27 +0530 Subject: [PATCH 07/24] feat(multitenancy): fix clippy warnings --- crates/drainer/src/handler.rs | 4 ++-- crates/redis_interface/src/commands.rs | 2 +- crates/router/src/core/payments/helpers.rs | 6 +++--- crates/router/src/core/payments/transformers.rs | 10 +++++----- crates/router/src/core/user.rs | 8 ++++---- crates/router/src/routes/app.rs | 3 ++- crates/router/src/routes/payment_methods.rs | 5 ++--- crates/router/src/services/api.rs | 6 +++--- crates/router/src/services/authentication.rs | 4 ++-- crates/router/src/types/storage/payment_attempt.rs | 6 +++--- crates/router/src/workflows/api_key_expiry.rs | 2 +- crates/router/tests/services.rs | 2 ++ crates/scheduler/src/consumer.rs | 2 +- 13 files changed, 31 insertions(+), 29 deletions(-) diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs index 04270faf113..d891d1158ed 100644 --- a/crates/drainer/src/handler.rs +++ b/crates/drainer/src/handler.rs @@ -128,10 +128,10 @@ impl Handler { match redis_conn_clone { None => { logger::error!("No redis connection found"); - return Err(errors::DrainerError::UnexpectedError( + Err(errors::DrainerError::UnexpectedError( "No redis connection found".to_string(), ) - .into()); + .into()) } Some(redis_conn_clone) => { // Spawn a task to monitor if redis is down or not diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index ffad706d558..d0e865f0a48 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -556,7 +556,7 @@ impl super::RedisConnectionPool { .iter() .filter_map(|key| key.as_str()) .map(|k| self.get_tenant_key(k)) - .map(|i| RedisKey::from(i)) + .map(RedisKey::from) .collect::>(); MultipleKeys::from(res) } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index a62b9f62c1e..16fc6b3afba 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1004,7 +1004,7 @@ pub fn validate_customer_id_mandatory_cases( } pub fn create_startpay_url( - base_url: &String, + base_url: &str, payment_attempt: &PaymentAttempt, payment_intent: &PaymentIntent, ) -> String { @@ -1028,7 +1028,7 @@ pub fn create_redirect_url( } pub fn create_authentication_url( - router_base_url: &String, + router_base_url: &str, payment_attempt: &PaymentAttempt, ) -> String { format!( @@ -1038,7 +1038,7 @@ pub fn create_authentication_url( } pub fn create_authorize_url( - router_base_url: &String, + router_base_url: &str, payment_attempt: &PaymentAttempt, connector_name: &String, ) -> String { diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 24bed6f283b..81d39b3f602 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -194,7 +194,7 @@ where data: D, customer: Option, auth_flow: services::AuthFlow, - base_url: &String, + base_url: &str, operation: Op, connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, connector_http_status_code: Option, @@ -213,7 +213,7 @@ where payment_data: PaymentData, customer: Option, auth_flow: services::AuthFlow, - base_url: &String, + base_url: &str, operation: Op, connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, connector_http_status_code: Option, @@ -263,7 +263,7 @@ where payment_data: PaymentData, _customer: Option, _auth_flow: services::AuthFlow, - _base_url: &String, + _base_url: &str, _operation: Op, _connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, _connector_http_status_code: Option, @@ -295,7 +295,7 @@ where data: PaymentData, customer: Option, _auth_flow: services::AuthFlow, - _base_url: &String, + _base_url: &str, _operation: Op, _connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, _connector_http_status_code: Option, @@ -351,7 +351,7 @@ pub fn payments_to_payments_response( captures: Option>, customer: Option, auth_flow: services::AuthFlow, - base_url: &String, + base_url: &str, operation: &Op, connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig, connector_http_status_code: Option, diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rs index bcd8a770896..ef887dbe6c1 100644 --- a/crates/router/src/core/user.rs +++ b/crates/router/src/core/user.rs @@ -465,7 +465,7 @@ pub async fn rotate_password( #[cfg(feature = "email")] pub async fn reset_password_token_only_flow( - state: AppState, + state: SessionState, user_token: auth::UserFromSinglePurposeToken, request: user_api::ResetPasswordRequest, ) -> UserResponse<()> { @@ -970,7 +970,7 @@ pub async fn accept_invite_from_email( #[cfg(feature = "email")] pub async fn accept_invite_from_email_token_only_flow( - state: AppState, + state: SessionState, user_token: auth::UserFromSinglePurposeToken, request: user_api::AcceptInviteFromEmailRequest, ) -> UserResponse> { @@ -1413,7 +1413,7 @@ pub async fn verify_email( #[cfg(feature = "email")] pub async fn verify_email_token_only_flow( - state: AppState, + state: SessionState, user_token: auth::UserFromSinglePurposeToken, req: user_api::VerifyEmailRequest, ) -> UserResponse> { @@ -1584,7 +1584,7 @@ pub async fn update_user_details( #[cfg(feature = "email")] pub async fn user_from_email( - state: AppState, + state: SessionState, req: user_api::UserFromEmailRequest, ) -> UserResponse { let token = req.token.expose(); diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 87e9a50cd17..6f0f0d5a989 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -102,7 +102,7 @@ impl SessionState { event_handler: state.event_handler.clone(), pool: state.pools.get(tenant).ok_or_else(err)?.clone(), file_storage_client: state.file_storage_client.clone(), - request_id: state.request_id.clone(), + request_id: state.request_id, base_url: state .conf .multitenancy @@ -268,6 +268,7 @@ impl AppState { let mut pools = HashMap::new(); let mut stores = HashMap::new(); + #[allow(clippy::expect_used)] let cache_store = get_cache_store(&conf.clone(), shut_down_signal, testable) .await .expect("Failed to create store"); diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index 58df43159d3..a484a9ca1e7 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -355,7 +355,7 @@ pub async fn default_payment_method_set_api( &req, payload, |state, auth: auth::AuthenticationData, default_payment_method, _| async move { - let res = cards::set_default_payment_method( + cards::set_default_payment_method( &*state.clone().store, auth.merchant_account.merchant_id, auth.key_store, @@ -363,8 +363,7 @@ pub async fn default_payment_method_set_api( default_payment_method.payment_method_id, auth.merchant_account.storage_scheme, ) - .await; - res + .await }, &*ephemeral_auth, api_locking::LockAction::NotApplicable, diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index a31374b3b89..6d77ebdb460 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1032,14 +1032,14 @@ where } .switch()) } else { - Ok(tenant_id) + Ok(tenant_id.to_string()) } })??; // let tenant_id = "public"; let mut session_state = - SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id, || { + SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id.as_str(), || { errors::ApiErrorResponse::InvalidTenant { - tenant_id: tenant_id.to_string(), + tenant_id: tenant_id.clone(), } .switch() })?; diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rs index 58da1b05d76..7e49952b73b 100644 --- a/crates/router/src/services/authentication.rs +++ b/crates/router/src/services/authentication.rs @@ -1069,9 +1069,9 @@ pub fn is_ephemeral_auth( let api_key = get_api_key(headers)?; if !api_key.starts_with("epk") { - return Ok(Box::new(ApiKeyAuth)); + Ok(Box::new(ApiKeyAuth)) } else { - return Ok(Box::new(EphemeralKeyAuth(customer_id.to_owned()))); + Ok(Box::new(EphemeralKeyAuth(customer_id.to_owned()))) } } diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index 0801c5b4810..0752e295f2a 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -123,7 +123,7 @@ mod tests { let store = state .stores - .get(state.conf.multitenancy.get_tenant_names().get(0).unwrap()) + .get(state.conf.multitenancy.get_tenant_names().first().unwrap()) .unwrap(); let response = store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) @@ -167,7 +167,7 @@ mod tests { }; let store = state .stores - .get(state.conf.multitenancy.get_tenant_names().get(0).unwrap()) + .get(state.conf.multitenancy.get_tenant_names().first().unwrap()) .unwrap(); store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) @@ -222,7 +222,7 @@ mod tests { }; let store = state .stores - .get(state.conf.multitenancy.get_tenant_names().get(0).unwrap()) + .get(state.conf.multitenancy.get_tenant_names().first().unwrap()) .unwrap(); store .insert_payment_attempt(payment_attempt, enums::MerchantStorageScheme::PostgresOnly) diff --git a/crates/router/src/workflows/api_key_expiry.rs b/crates/router/src/workflows/api_key_expiry.rs index 5c1762ead6a..dff7905a262 100644 --- a/crates/router/src/workflows/api_key_expiry.rs +++ b/crates/router/src/workflows/api_key_expiry.rs @@ -1,7 +1,7 @@ use common_utils::{errors::ValidationError, ext_traits::ValueExt}; use diesel_models::{enums as storage_enums, ApiKeyExpiryTrackingData}; use router_env::logger; -use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerAppState}; +use scheduler::{workflows::ProcessTrackerWorkflow, SchedulerSessionState}; use crate::{ errors, diff --git a/crates/router/tests/services.rs b/crates/router/tests/services.rs index f00e1257286..771933e7552 100644 --- a/crates/router/tests/services.rs +++ b/crates/router/tests/services.rs @@ -6,6 +6,7 @@ mod utils; #[tokio::test] #[should_panic] +#[allow(clippy::unwrap_used)] async fn get_redis_conn_failure() { // Arrange utils::setup().await; @@ -31,6 +32,7 @@ async fn get_redis_conn_failure() { } #[tokio::test] +#[allow(clippy::unwrap_used)] async fn get_redis_conn_success() { // Arrange Box::pin(utils::setup()).await; diff --git a/crates/scheduler/src/consumer.rs b/crates/scheduler/src/consumer.rs index 986aed370fe..3e15a7cde0f 100644 --- a/crates/scheduler/src/consumer.rs +++ b/crates/scheduler/src/consumer.rs @@ -155,7 +155,7 @@ pub async fn consumer_operations( .fetch_consumer_tasks(&stream_name, &group_name, &consumer_name) .await?; - if tasks.len() > 0 { + if !tasks.is_empty() { logger::info!("{} picked {} tasks", consumer_name, tasks.len()); } let mut handler = vec![]; From c9405db2bf2cdcead675d08a6a5307ee83f60691 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Fri, 17 May 2024 17:05:22 +0530 Subject: [PATCH 08/24] feat(multitenancy): fix clippy warnings --- crates/router/src/routes/app.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index c3726f496e0..bea47758eac 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -16,6 +16,8 @@ use router_env::tracing_actix_web::RequestId; use scheduler::SchedulerInterface; use storage_impl::MockDb; use tokio::sync::oneshot; +#[cfg(feature = "olap")] +use crate::analytics::AnalyticsProvider; #[cfg(feature = "olap")] use super::blocklist; @@ -73,7 +75,7 @@ pub struct SessionState { #[cfg(feature = "email")] pub email_client: Arc, #[cfg(feature = "olap")] - pub pool: crate::analytics::AnalyticsProvider, + pub pool: AnalyticsProvider, pub file_storage_client: Box, pub request_id: Option, pub base_url: String, @@ -100,6 +102,7 @@ impl SessionState { conf: Arc::clone(&state.conf), api_client: state.api_client.clone(), event_handler: state.event_handler.clone(), + #[cfg(feature = "olap")] pool: state.pools.get(tenant).ok_or_else(err)?.clone(), file_storage_client: state.file_storage_client.clone(), request_id: state.request_id, @@ -156,7 +159,7 @@ pub struct AppState { pub email_client: Arc, pub api_client: Box, #[cfg(feature = "olap")] - pub pools: HashMap, + pub pools: HashMap, #[cfg(feature = "olap")] pub opensearch_client: Arc, pub request_id: Option, @@ -266,7 +269,8 @@ impl AppState { .expect("Failed to create opensearch client"), ); - let mut pools = HashMap::new(); + #[cfg(feature = "olap")] + let mut pools: HashMap = HashMap::new(); let mut stores = HashMap::new(); #[allow(clippy::expect_used)] let cache_store = get_cache_store(&conf.clone(), shut_down_signal, testable) @@ -307,7 +311,7 @@ impl AppState { }; stores.insert(tenant.clone(), store); #[cfg(feature = "olap")] - let pool = crate::analytics::AnalyticsProvider::from_conf( + let pool = AnalyticsProvider::from_conf( conf.analytics.get_inner(), tenant.as_str(), ) From c376ffc6710f91522987455c7710accc827987f5 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 17 May 2024 11:48:06 +0000 Subject: [PATCH 09/24] chore: run formatter --- crates/router/src/routes/app.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index bea47758eac..d2043e73501 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -16,8 +16,6 @@ use router_env::tracing_actix_web::RequestId; use scheduler::SchedulerInterface; use storage_impl::MockDb; use tokio::sync::oneshot; -#[cfg(feature = "olap")] -use crate::analytics::AnalyticsProvider; #[cfg(feature = "olap")] use super::blocklist; @@ -45,6 +43,8 @@ use super::{ephemeral_key::*, webhooks::*}; use super::{pm_auth, poll::retrieve_poll_status}; #[cfg(feature = "olap")] pub use crate::analytics::opensearch::OpenSearchClient; +#[cfg(feature = "olap")] +use crate::analytics::AnalyticsProvider; use crate::configs::secrets_transformers; #[cfg(all(feature = "frm", feature = "oltp"))] use crate::routes::fraud_check as frm_routes; @@ -311,11 +311,8 @@ impl AppState { }; stores.insert(tenant.clone(), store); #[cfg(feature = "olap")] - let pool = AnalyticsProvider::from_conf( - conf.analytics.get_inner(), - tenant.as_str(), - ) - .await; + let pool = + AnalyticsProvider::from_conf(conf.analytics.get_inner(), tenant.as_str()).await; #[cfg(feature = "olap")] pools.insert(tenant.clone(), pool); } From c78729e6b1e37dc88b8f3aa2b3080b9503b0f2a5 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Fri, 17 May 2024 18:04:27 +0530 Subject: [PATCH 10/24] feat(multitenancy): add support to enable/disable multitenancy support --- config/development.toml | 3 ++ crates/common_utils/src/consts.rs | 3 ++ crates/drainer/src/settings.rs | 1 + crates/router/src/bin/scheduler.rs | 2 +- crates/router/src/configs/settings.rs | 1 + crates/router/src/routes/app.rs | 11 +++--- crates/router/src/services/api.rs | 50 +++++++++++++++------------ 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/config/development.toml b/config/development.toml index 833829c7647..812b44d154f 100644 --- a/config/development.toml +++ b/config/development.toml @@ -628,5 +628,8 @@ disputes = "hyperswitch-dispute-events" [saved_payment_methods] sdk_eligible_payment_methods = "card" +[multitenancy] +enabled = false + [multitenancy.tenants] public = { name = "hyperswitch", base_url = "http://localhost:8080"} \ No newline at end of file diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs index 94b53766db0..114e2f92b6c 100644 --- a/crates/common_utils/src/consts.rs +++ b/crates/common_utils/src/consts.rs @@ -83,3 +83,6 @@ pub const DEFAULT_TTL_FOR_EXTENDED_CARD_INFO: u16 = 15 * 60; /// Max ttl for Extended card info in redis (in seconds) pub const MAX_TTL_FOR_EXTENDED_CARD_INFO: u16 = 60 * 60 * 2; + +/// Default tenant to be used when multitenancy is disabled +pub const DEFAULT_TENANT: &str = "public"; diff --git a/crates/drainer/src/settings.rs b/crates/drainer/src/settings.rs index ffafb6c0b80..ead91f4468e 100644 --- a/crates/drainer/src/settings.rs +++ b/crates/drainer/src/settings.rs @@ -100,6 +100,7 @@ pub struct DrainerSettings { #[derive(Debug, Deserialize, Clone, Default)] pub struct Multitenancy { + pub enabled: bool, pub tenants: TenantConfig, } impl Multitenancy { diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs index 701eb31f7d9..a59fdfe120b 100644 --- a/crates/router/src/bin/scheduler.rs +++ b/crates/router/src/bin/scheduler.rs @@ -360,7 +360,7 @@ async fn start_scheduler( WorkflowRunner {}, |state, tenant| { routes::SessionState::from_app_state(Arc::new(state.clone()), tenant, || { - errors::ProcessTrackerError::TenantNotFound.into() + ProcessTrackerError::TenantNotFound.into() }) }, ) diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index b10cd4eaa22..c0e44c0e23f 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -127,6 +127,7 @@ pub struct Settings { #[derive(Debug, Deserialize, Clone, Default)] pub struct Multitenancy { pub tenants: TenantConfig, + pub enabled: bool, } impl Multitenancy { diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index bea47758eac..d2043e73501 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -16,8 +16,6 @@ use router_env::tracing_actix_web::RequestId; use scheduler::SchedulerInterface; use storage_impl::MockDb; use tokio::sync::oneshot; -#[cfg(feature = "olap")] -use crate::analytics::AnalyticsProvider; #[cfg(feature = "olap")] use super::blocklist; @@ -45,6 +43,8 @@ use super::{ephemeral_key::*, webhooks::*}; use super::{pm_auth, poll::retrieve_poll_status}; #[cfg(feature = "olap")] pub use crate::analytics::opensearch::OpenSearchClient; +#[cfg(feature = "olap")] +use crate::analytics::AnalyticsProvider; use crate::configs::secrets_transformers; #[cfg(all(feature = "frm", feature = "oltp"))] use crate::routes::fraud_check as frm_routes; @@ -311,11 +311,8 @@ impl AppState { }; stores.insert(tenant.clone(), store); #[cfg(feature = "olap")] - let pool = AnalyticsProvider::from_conf( - conf.analytics.get_inner(), - tenant.as_str(), - ) - .await; + let pool = + AnalyticsProvider::from_conf(conf.analytics.get_inner(), tenant.as_str()).await; #[cfg(feature = "olap")] pools.insert(tenant.clone(), pool); } diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 6d77ebdb460..3712928abf4 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1011,30 +1011,34 @@ where let mut event_type = payload.get_api_event_type(); - let tenant_id = incoming_request_header - .get("x-tenant-id") - .and_then(|value| value.to_str().ok()) - .ok_or_else(|| { - errors::ApiErrorResponse::InvalidRequestData { - message: "Missing tenant Id".to_string(), - } - .switch() - }) - .map(|tenant_id| { - if !state - .conf - .multitenancy - .get_tenant_names() - .contains(&tenant_id.to_string()) - { - Err(errors::ApiErrorResponse::InvalidTenant { - tenant_id: tenant_id.to_string(), + let tenant_id = if !state.conf.multitenancy.enabled { + common_utils::consts::DEFAULT_TENANT.to_string() + } else { + incoming_request_header + .get("x-tenant-id") + .and_then(|value| value.to_str().ok()) + .ok_or_else(|| { + errors::ApiErrorResponse::InvalidRequestData { + message: "Missing tenant Id".to_string(), } - .switch()) - } else { - Ok(tenant_id.to_string()) - } - })??; + .switch() + }) + .map(|tenant_id| { + if !state + .conf + .multitenancy + .get_tenant_names() + .contains(&tenant_id.to_string()) + { + Err(errors::ApiErrorResponse::InvalidTenant { + tenant_id: tenant_id.to_string(), + } + .switch()) + } else { + Ok(tenant_id.to_string()) + } + })?? + }; // let tenant_id = "public"; let mut session_state = SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id.as_str(), || { From f103acc4f08df012f41497211eeb0383797c73af Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Tue, 21 May 2024 18:36:26 +0530 Subject: [PATCH 11/24] fix: clear redis entry on update operation --- crates/router/src/services.rs | 4 ++-- crates/storage_impl/src/lib.rs | 22 ++++++++++++---------- crates/storage_impl/src/redis/pub_sub.rs | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index 1c8e40fdc9c..161ad9c9814 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -66,7 +66,7 @@ pub async fn get_store( let store: RouterStore = if test_transaction { RouterStore::test_store(conf, schema, &config.redis, master_enc_key).await? } else { - RouterStore::from_config(conf, schema, master_enc_key, cache_store).await? + RouterStore::from_config(conf, schema, master_enc_key, cache_store, consts::PUB_SUB_CHANNEL).await? }; #[cfg(feature = "kv_store")] @@ -86,7 +86,7 @@ pub async fn get_cache_store( shut_down_signal: oneshot::Sender<()>, _test_transaction: bool, ) -> StorageResult> { - RouterStore::::cache_store(&config.redis, shut_down_signal, consts::PUB_SUB_CHANNEL) + RouterStore::::cache_store(&config.redis, shut_down_signal) .await } diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 99305712c59..cddcba5f190 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -71,7 +71,8 @@ where db_conf, schema, encryption_key, - Self::cache_store(&cache_conf, cache_error_signal, inmemory_cache_stream).await?, + Self::cache_store(&cache_conf, cache_error_signal).await?, + inmemory_cache_stream, ) .await .attach_printable("failed to create store") @@ -97,15 +98,22 @@ impl RouterStore { schema: &str, encryption_key: StrongSecret>, cache_store: Arc, + inmemory_cache_stream: &str, ) -> StorageResult { let db_store = T::new(db_conf, schema, false).await?; let redis_conn = cache_store.redis_conn.clone(); + let cache_store = Arc::new(RedisStore { + redis_conn: Arc::new(RedisConnectionPool::clone(&redis_conn, schema)), + }); + cache_store + .subscribe_to_channel(inmemory_cache_stream) + .await + .change_context(StorageError::InitializationError) + .attach_printable("Failed to subscribe to inmemory cache stream")?; Ok(Self { db_store, - cache_store: Arc::new(RedisStore { - redis_conn: Arc::new(RedisConnectionPool::clone(&redis_conn, schema)), - }), + cache_store, master_encryption_key: encryption_key, request_id: None, }) @@ -114,18 +122,12 @@ impl RouterStore { pub async fn cache_store( cache_conf: &redis_interface::RedisSettings, cache_error_signal: tokio::sync::oneshot::Sender<()>, - inmemory_cache_stream: &str, ) -> StorageResult> { let cache_store = RedisStore::new(cache_conf) .await .change_context(StorageError::InitializationError) .attach_printable("Failed to create cache store")?; cache_store.set_error_callback(cache_error_signal); - cache_store - .subscribe_to_channel(inmemory_cache_stream) - .await - .change_context(StorageError::InitializationError) - .attach_printable("Failed to subscribe to inmemory cache stream")?; Ok(Arc::new(cache_store)) } diff --git a/crates/storage_impl/src/redis/pub_sub.rs b/crates/storage_impl/src/redis/pub_sub.rs index 349d1872d2a..1f31fe92eed 100644 --- a/crates/storage_impl/src/redis/pub_sub.rs +++ b/crates/storage_impl/src/redis/pub_sub.rs @@ -44,7 +44,7 @@ impl PubSubInterface for redis_interface::RedisConnectionPool { #[inline] async fn on_message(&self) -> error_stack::Result<(), redis_errors::RedisError> { - logger::debug!("Started on message"); + logger::debug!("Started on message: {:?}", self.tenant); let mut rx = self.subscriber.on_message(); while let Ok(message) = rx.recv().await { logger::debug!("Invalidating {message:?}"); From 4e941d6aa31427692e587e6ea5f7d7b691c0ae77 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 13:16:06 +0000 Subject: [PATCH 12/24] chore: run formatter --- crates/router/src/services.rs | 12 +++++++++--- crates/router/tests/payments.rs | 1 + crates/router/tests/payments2.rs | 1 + crates/storage_impl/src/lib.rs | 9 ++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index e583b143b2a..38e5f11eff5 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -66,7 +66,14 @@ pub async fn get_store( let store: RouterStore = if test_transaction { RouterStore::test_store(conf, schema, &config.redis, master_enc_key).await? } else { - RouterStore::from_config(conf, schema, master_enc_key, cache_store, consts::PUB_SUB_CHANNEL).await? + RouterStore::from_config( + conf, + schema, + master_enc_key, + cache_store, + consts::PUB_SUB_CHANNEL, + ) + .await? }; #[cfg(feature = "kv_store")] @@ -87,8 +94,7 @@ pub async fn get_cache_store( shut_down_signal: oneshot::Sender<()>, _test_transaction: bool, ) -> StorageResult> { - RouterStore::::cache_store(&config.redis, shut_down_signal) - .await + RouterStore::::cache_store(&config.redis, shut_down_signal).await } #[inline] diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index b4907074a81..7ef2fadabe3 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -3,6 +3,7 @@ mod utils; use std::sync::Arc; + use common_utils::types::MinorUnit; use router::{ configs, diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index cea958cbbe6..aba73b7780a 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -3,6 +3,7 @@ mod utils; use std::sync::Arc; + use common_utils::types::MinorUnit; use router::{ core::payments, diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 03b20810fef..16a272db0c1 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -176,9 +176,12 @@ where T: DatabaseStore, { type Config = (RouterStore, String, u8, u32, Option); - async fn new(config: Self::Config, schema: &str, _test_transaction: bool) -> StorageResult { - let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = - config; + async fn new( + config: Self::Config, + schema: &str, + _test_transaction: bool, + ) -> StorageResult { + let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = config; let drainer_stream_name = format!("{}_{}", schema, config.1); Ok(Self::from_store( router_store, From f852184560e8bb911c87c81f1f0c4a902d8b22e5 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Thu, 23 May 2024 13:58:37 +0530 Subject: [PATCH 13/24] feat: add tenant support in in-memory cache --- crates/drainer/src/handler.rs | 2 +- crates/drainer/src/health_check.rs | 2 +- crates/redis_interface/src/commands.rs | 56 +++---- crates/redis_interface/src/lib.rs | 8 +- crates/router/src/db/api_keys.rs | 19 +-- crates/router/src/db/cache.rs | 47 ++++-- .../src/db/merchant_connector_account.rs | 10 +- crates/router/src/services.rs | 12 +- crates/router/tests/cache.rs | 22 ++- crates/storage_impl/src/lib.rs | 9 +- crates/storage_impl/src/redis/cache.rs | 143 ++++++++++++++---- crates/storage_impl/src/redis/pub_sub.rs | 32 +++- 12 files changed, 250 insertions(+), 112 deletions(-) diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs index 4a809bf1b0d..b9667327791 100644 --- a/crates/drainer/src/handler.rs +++ b/crates/drainer/src/handler.rs @@ -229,7 +229,7 @@ async fn drainer( // parse_stream_entries returns error if no entries is found, handle it let entries = utils::parse_stream_entries( &stream_read, - store.redis_conn.get_tenant_key(stream_name).as_str(), + store.redis_conn.add_prefix(stream_name).as_str(), )?; let read_count = entries.len(); diff --git a/crates/drainer/src/health_check.rs b/crates/drainer/src/health_check.rs index 558f3847a95..10514108991 100644 --- a/crates/drainer/src/health_check.rs +++ b/crates/drainer/src/health_check.rs @@ -201,7 +201,7 @@ impl HealthCheckInterface for Store { logger::debug!("Stream read succeeded"); let (_, id_to_trim) = output - .get(&redis_conn.get_tenant_key(TEST_STREAM_NAME)) + .get(&redis_conn.add_prefix(TEST_STREAM_NAME)) .and_then(|entries| { entries .last() diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index d0e865f0a48..e0f7ffb8095 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -31,11 +31,11 @@ use crate::{ }; impl super::RedisConnectionPool { - pub fn get_tenant_key(&self, key: &str) -> String { - if self.tenant.is_empty() { + pub fn add_prefix(&self, key: &str) -> String { + if self.key_prefix.is_empty() { key.to_string() } else { - format!("{}:{}", self.tenant, key) + format!("{}:{}", self.key_prefix, key) } } #[instrument(level = "DEBUG", skip(self))] @@ -46,7 +46,7 @@ impl super::RedisConnectionPool { { self.pool .set( - self.get_tenant_key(key), + self.add_prefix(key), value, Some(Expiration::EX(self.config.default_ttl.into())), None, @@ -151,7 +151,7 @@ impl super::RedisConnectionPool { self.pool .set( - self.get_tenant_key(key), + self.add_prefix(key), serialized.as_slice(), Some(Expiration::EX(seconds)), None, @@ -167,7 +167,7 @@ impl super::RedisConnectionPool { V: FromRedis + Unpin + Send + 'static, { self.pool - .get(self.get_tenant_key(key)) + .get(self.add_prefix(key)) .await .change_context(errors::RedisError::GetFailed) } @@ -178,7 +178,7 @@ impl super::RedisConnectionPool { V: Into + Unpin + Send + 'static, { self.pool - .exists(self.get_tenant_key(key)) + .exists(self.add_prefix(key)) .await .change_context(errors::RedisError::GetFailed) } @@ -204,7 +204,7 @@ impl super::RedisConnectionPool { #[instrument(level = "DEBUG", skip(self))] pub async fn delete_key(&self, key: &str) -> CustomResult { self.pool - .del(self.get_tenant_key(key)) + .del(self.add_prefix(key)) .await .change_context(errors::RedisError::DeleteFailed) } @@ -222,7 +222,7 @@ impl super::RedisConnectionPool { { self.pool .set( - self.get_tenant_key(key), + self.add_prefix(key), value, Some(Expiration::EX(seconds)), None, @@ -245,7 +245,7 @@ impl super::RedisConnectionPool { { self.pool .set( - self.get_tenant_key(key), + self.add_prefix(key), value, Some(Expiration::EX( seconds.unwrap_or(self.config.default_ttl.into()), @@ -264,7 +264,7 @@ impl super::RedisConnectionPool { seconds: i64, ) -> CustomResult<(), errors::RedisError> { self.pool - .expire(self.get_tenant_key(key), seconds) + .expire(self.add_prefix(key), seconds) .await .change_context(errors::RedisError::SetExpiryFailed) } @@ -276,7 +276,7 @@ impl super::RedisConnectionPool { timestamp: i64, ) -> CustomResult<(), errors::RedisError> { self.pool - .expire_at(self.get_tenant_key(key), timestamp) + .expire_at(self.add_prefix(key), timestamp) .await .change_context(errors::RedisError::SetExpiryFailed) } @@ -294,7 +294,7 @@ impl super::RedisConnectionPool { { let output: Result<(), _> = self .pool - .hset(self.get_tenant_key(key), values) + .hset(self.add_prefix(key), values) .await .change_context(errors::RedisError::SetHashFailed); // setting expiry for the key @@ -319,7 +319,7 @@ impl super::RedisConnectionPool { { let output: Result = self .pool - .hsetnx(self.get_tenant_key(key), field, value) + .hsetnx(self.add_prefix(key), field, value) .await .change_context(errors::RedisError::SetHashFieldFailed); @@ -381,7 +381,7 @@ impl super::RedisConnectionPool { Ok(self .pool .next() - .hscan::<&str, &str>(&self.get_tenant_key(key), pattern, count) + .hscan::<&str, &str>(&self.add_prefix(key), pattern, count) .filter_map(|value| async move { match value { Ok(mut v) => { @@ -432,7 +432,7 @@ impl super::RedisConnectionPool { V: FromRedis + Unpin + Send + 'static, { self.pool - .hget(self.get_tenant_key(key), field) + .hget(self.add_prefix(key), field) .await .change_context(errors::RedisError::GetHashFieldFailed) } @@ -469,7 +469,7 @@ impl super::RedisConnectionPool { V::Error: Into + Send, { self.pool - .sadd(self.get_tenant_key(key), members) + .sadd(self.add_prefix(key), members) .await .change_context(errors::RedisError::SetAddMembersFailed) } @@ -486,7 +486,7 @@ impl super::RedisConnectionPool { F::Error: Into + Send + Sync, { self.pool - .xadd(self.get_tenant_key(stream), false, None, entry_id, fields) + .xadd(self.add_prefix(stream), false, None, entry_id, fields) .await .change_context(errors::RedisError::StreamAppendFailed) } @@ -501,7 +501,7 @@ impl super::RedisConnectionPool { Ids: Into + Debug + Send + Sync, { self.pool - .xdel(self.get_tenant_key(stream), ids) + .xdel(self.add_prefix(stream), ids) .await .change_context(errors::RedisError::StreamDeleteFailed) } @@ -517,7 +517,7 @@ impl super::RedisConnectionPool { C::Error: Into + Send + Sync, { self.pool - .xtrim(self.get_tenant_key(stream), xcap) + .xtrim(self.add_prefix(stream), xcap) .await .change_context(errors::RedisError::StreamTrimFailed) } @@ -533,7 +533,7 @@ impl super::RedisConnectionPool { Ids: Into + Debug + Send + Sync, { self.pool - .xack(self.get_tenant_key(stream), group, ids) + .xack(self.add_prefix(stream), group, ids) .await .change_context(errors::RedisError::StreamAcknowledgeFailed) } @@ -541,7 +541,7 @@ impl super::RedisConnectionPool { #[instrument(level = "DEBUG", skip(self))] pub async fn stream_get_length(&self, stream: &str) -> CustomResult { self.pool - .xlen(self.get_tenant_key(stream)) + .xlen(self.add_prefix(stream)) .await .change_context(errors::RedisError::GetLengthFailed) } @@ -555,7 +555,7 @@ impl super::RedisConnectionPool { .inner() .iter() .filter_map(|key| key.as_str()) - .map(|k| self.get_tenant_key(k)) + .map(|k| self.add_prefix(k)) .map(RedisKey::from) .collect::>(); MultipleKeys::from(res) @@ -648,7 +648,7 @@ impl super::RedisConnectionPool { } self.pool - .xgroup_create(self.get_tenant_key(stream), group, id, true) + .xgroup_create(self.add_prefix(stream), group, id, true) .await .change_context(errors::RedisError::ConsumerGroupCreateFailed) } @@ -660,7 +660,7 @@ impl super::RedisConnectionPool { group: &str, ) -> CustomResult { self.pool - .xgroup_destroy(self.get_tenant_key(stream), group) + .xgroup_destroy(self.add_prefix(stream), group) .await .change_context(errors::RedisError::ConsumerGroupDestroyFailed) } @@ -674,7 +674,7 @@ impl super::RedisConnectionPool { consumer: &str, ) -> CustomResult { self.pool - .xgroup_delconsumer(self.get_tenant_key(stream), group, consumer) + .xgroup_delconsumer(self.add_prefix(stream), group, consumer) .await .change_context(errors::RedisError::ConsumerGroupRemoveConsumerFailed) } @@ -687,7 +687,7 @@ impl super::RedisConnectionPool { id: &RedisEntryId, ) -> CustomResult { self.pool - .xgroup_setid(self.get_tenant_key(stream), group, id) + .xgroup_setid(self.add_prefix(stream), group, id) .await .change_context(errors::RedisError::ConsumerGroupSetIdFailed) } @@ -707,7 +707,7 @@ impl super::RedisConnectionPool { { self.pool .xclaim( - self.get_tenant_key(stream), + self.add_prefix(stream), group, consumer, min_idle_time, diff --git a/crates/redis_interface/src/lib.rs b/crates/redis_interface/src/lib.rs index fb3c4cd6082..9eec3eb662a 100644 --- a/crates/redis_interface/src/lib.rs +++ b/crates/redis_interface/src/lib.rs @@ -32,7 +32,7 @@ pub use self::types::*; pub struct RedisConnectionPool { pub pool: Arc, - pub tenant: String, + pub key_prefix: String, pub config: Arc, pub subscriber: Arc, pub publisher: Arc, @@ -173,13 +173,13 @@ impl RedisConnectionPool { is_redis_available: Arc::new(atomic::AtomicBool::new(true)), subscriber: Arc::new(subscriber), publisher: Arc::new(publisher), - tenant: String::default(), + key_prefix: String::default(), }) } - pub fn clone(&self, tenant: &str) -> Self { + pub fn clone(&self, key_prefix: &str) -> Self { Self { pool: Arc::clone(&self.pool), - tenant: tenant.to_string(), + key_prefix: key_prefix.to_string(), config: Arc::clone(&self.config), subscriber: Arc::clone(&self.subscriber), publisher: Arc::clone(&self.publisher), diff --git a/crates/router/src/db/api_keys.rs b/crates/router/src/db/api_keys.rs index a23b3f0f7af..06ae0a2ec9d 100644 --- a/crates/router/src/db/api_keys.rs +++ b/crates/router/src/db/api_keys.rs @@ -375,7 +375,7 @@ impl ApiKeyInterface for MockDb { #[cfg(test)] mod tests { use storage_impl::redis::{ - cache::{CacheKind, ACCOUNTS_CACHE}, + cache::{CacheKind, CacheKey, ACCOUNTS_CACHE}, kv_store::RedisConnInterface, pub_sub::PubSubInterface, }; @@ -527,15 +527,12 @@ mod tests { .await .unwrap(); - assert!( - ACCOUNTS_CACHE - .get_val::(&format!( - "{}_{}", - merchant_id, - hashed_api_key.into_inner() - ),) - .await - .is_none() - ) + assert!(ACCOUNTS_CACHE + .get_val::(CacheKey { + key: format!("{}_{}", merchant_id, hashed_api_key.into_inner()), + prefix: String::default(), + },) + .await + .is_none()) } } diff --git a/crates/router/src/db/cache.rs b/crates/router/src/db/cache.rs index ba0aae55e89..539edcdfe2c 100644 --- a/crates/router/src/db/cache.rs +++ b/crates/router/src/db/cache.rs @@ -1,9 +1,11 @@ +use std::sync::Arc; + use common_utils::ext_traits::AsyncExt; use error_stack::ResultExt; use redis_interface::errors::RedisError; use router_env::{instrument, tracing}; use storage_impl::redis::{ - cache::{Cache, CacheKind, Cacheable}, + cache::{Cache, CacheKind, Cacheable, CacheKey}, pub_sub::PubSubInterface, }; @@ -15,7 +17,7 @@ use crate::{ #[instrument(skip_all)] pub async fn get_or_populate_redis( - store: &dyn StorageInterface, + redis: &Arc, key: impl AsRef, fun: F, ) -> CustomResult @@ -26,12 +28,6 @@ where { let type_name = std::any::type_name::(); let key = key.as_ref(); - let redis = &store - .get_redis_conn() - .change_context(errors::StorageError::RedisError( - RedisError::RedisConnectionError.into(), - )) - .attach_printable("Failed to get redis connection")?; let redis_val = redis.get_and_deserialize_key::(key, type_name).await; let get_data_set_redis = || async { let data = fun().await?; @@ -66,12 +62,31 @@ where F: FnOnce() -> Fut + Send, Fut: futures::Future> + Send, { - let cache_val = cache.get_val::(key).await; + let redis = &store + .get_redis_conn() + .change_context(errors::StorageError::RedisError( + RedisError::RedisConnectionError.into(), + )) + .attach_printable("Failed to get redis connection")?; + let cache_val = cache + .get_val::(CacheKey { + key: key.to_string(), + prefix: redis.key_prefix.clone(), + }) + .await; if let Some(val) = cache_val { Ok(val) } else { - let val = get_or_populate_redis(store, key, fun).await?; - cache.push(key.to_string(), val.clone()).await; + let val = get_or_populate_redis(redis, key, fun).await?; + cache + .push( + CacheKey { + key: key.to_string(), + prefix: redis.key_prefix.clone(), + }, + val.clone(), + ) + .await; Ok(val) } } @@ -88,7 +103,6 @@ where Fut: futures::Future> + Send, { let data = fun().await?; - in_memory.async_map(|cache| cache.remove(key)).await; let redis_conn = store .get_redis_conn() @@ -97,6 +111,15 @@ where )) .attach_printable("Failed to get redis connection")?; + in_memory + .async_map(|cache| { + cache.remove(CacheKey { + key: key.to_string(), + prefix: redis_conn.key_prefix.clone(), + }) + }) + .await; + redis_conn .delete_key(key) .await diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index 8f50f5f5426..d5e0ae9057b 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -758,7 +758,7 @@ mod merchant_connector_account_cache_tests { use error_stack::ResultExt; use masking::PeekInterface; use storage_impl::redis::{ - cache::{CacheKind, ACCOUNTS_CACHE}, + cache::{CacheKind, CacheKey, ACCOUNTS_CACHE}, kv_store::RedisConnInterface, pub_sub::PubSubInterface, }; @@ -891,10 +891,10 @@ mod merchant_connector_account_cache_tests { .unwrap(); assert!(ACCOUNTS_CACHE - .get_val::(&format!( - "{}_{}", - merchant_id, connector_label - ),) + .get_val::(CacheKey { + key: format!("{}_{}", merchant_id, connector_label), + prefix: String::default(), + },) .await .is_none()) } diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index e583b143b2a..38e5f11eff5 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -66,7 +66,14 @@ pub async fn get_store( let store: RouterStore = if test_transaction { RouterStore::test_store(conf, schema, &config.redis, master_enc_key).await? } else { - RouterStore::from_config(conf, schema, master_enc_key, cache_store, consts::PUB_SUB_CHANNEL).await? + RouterStore::from_config( + conf, + schema, + master_enc_key, + cache_store, + consts::PUB_SUB_CHANNEL, + ) + .await? }; #[cfg(feature = "kv_store")] @@ -87,8 +94,7 @@ pub async fn get_cache_store( shut_down_signal: oneshot::Sender<()>, _test_transaction: bool, ) -> StorageResult> { - RouterStore::::cache_store(&config.redis, shut_down_signal) - .await + RouterStore::::cache_store(&config.redis, shut_down_signal).await } #[inline] diff --git a/crates/router/tests/cache.rs b/crates/router/tests/cache.rs index 34d09f11262..f3472e6b8b3 100644 --- a/crates/router/tests/cache.rs +++ b/crates/router/tests/cache.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use router::{configs::settings::Settings, routes, services}; -use storage_impl::redis::cache; +use storage_impl::redis::cache::{self, CacheKey}; mod utils; @@ -31,11 +31,23 @@ async fn invalidate_existing_cache_success() { let client = awc::Client::default(); cache::CONFIG_CACHE - .push(cache_key.clone(), cache_key_value.clone()) + .push( + CacheKey { + key: cache_key.clone(), + prefix: String::default(), + }, + cache_key_value.clone(), + ) .await; cache::ACCOUNTS_CACHE - .push(cache_key.clone(), cache_key_value.clone()) + .push( + CacheKey { + key: cache_key.clone(), + prefix: String::default(), + }, + cache_key_value.clone(), + ) .await; // Act @@ -53,11 +65,11 @@ async fn invalidate_existing_cache_success() { println!("invalidate Cache: {response:?} : {response_body:?}"); assert_eq!(response.status(), awc::http::StatusCode::OK); assert!(cache::CONFIG_CACHE - .get_val::(&cache_key) + .get_val::(CacheKey { key: cache_key.clone(), prefix: String::default()}) .await .is_none()); assert!(cache::ACCOUNTS_CACHE - .get_val::(&cache_key) + .get_val::(CacheKey { key: cache_key, prefix: String::default()}) .await .is_none()); } diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 03b20810fef..16a272db0c1 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -176,9 +176,12 @@ where T: DatabaseStore, { type Config = (RouterStore, String, u8, u32, Option); - async fn new(config: Self::Config, schema: &str, _test_transaction: bool) -> StorageResult { - let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = - config; + async fn new( + config: Self::Config, + schema: &str, + _test_transaction: bool, + ) -> StorageResult { + let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = config; let drainer_stream_name = format!("{}_{}", schema, config.1); Ok(Self::from_store( router_store, diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs index 4cd2fc0c504..61958630e9e 100644 --- a/crates/storage_impl/src/redis/cache.rs +++ b/crates/storage_impl/src/redis/cache.rs @@ -1,4 +1,4 @@ -use std::{any::Any, borrow::Cow, sync::Arc}; +use std::{any::Any, borrow::Cow, fmt::Debug, sync::Arc}; use common_utils::{ errors::{self, CustomResult}, @@ -9,7 +9,7 @@ use error_stack::{Report, ResultExt}; use hyperswitch_domain_models::errors::StorageError; use moka::future::Cache as MokaCache; use once_cell::sync::Lazy; -use redis_interface::{errors::RedisError, RedisValue}; +use redis_interface::{errors::RedisError, RedisConnectionPool, RedisValue}; use super::{kv_store::RedisConnInterface, pub_sub::PubSubInterface}; @@ -94,6 +94,22 @@ pub struct Cache { inner: MokaCache>, } +#[derive(Debug, Clone)] +pub struct CacheKey { + pub key: String, + pub prefix: String, +} + +impl Into for CacheKey { + fn into(self) -> String { + if self.prefix.is_empty() { + self.key + } else { + format!("{}:{}", self.prefix.clone(), self.key.clone()) + } + } +} + impl Cache { /// With given `time_to_live` and `time_to_idle` creates a moka cache. /// @@ -114,39 +130,32 @@ impl Cache { } } - pub async fn push(&self, key: String, val: T) { - self.inner.insert(key, Arc::new(val)).await; + pub async fn push(&self, key: CacheKey, val: T) { + self.inner.insert(key.into(), Arc::new(val)).await; } - pub async fn get_val(&self, key: &str) -> Option { - let val = self.inner.get(key).await?; + pub async fn get_val(&self, key: CacheKey) -> Option { + let val = self.inner.get::(&key.into()).await?; (*val).as_any().downcast_ref::().cloned() } - pub async fn remove(&self, key: &str) { - self.inner.invalidate(key).await; + pub async fn remove(&self, key: CacheKey) { + self.inner.invalidate::(&key.into()).await; } } pub async fn get_or_populate_redis( - store: &(dyn RedisConnInterface + Send + Sync), + redis: &Arc, key: impl AsRef, fun: F, ) -> CustomResult where - T: serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug, + T: serde::Serialize + serde::de::DeserializeOwned + Debug, F: FnOnce() -> Fut + Send, Fut: futures::Future> + Send, { let type_name = std::any::type_name::(); let key = key.as_ref(); - let redis = &store - .get_redis_conn() - .map_err(|er| { - let error = format!("{}", er); - er.change_context(StorageError::RedisError(error)) - }) - .attach_printable("Failed to get redis connection")?; let redis_val = redis.get_and_deserialize_key::(key, type_name).await; let get_data_set_redis = || async { let data = fun().await?; @@ -171,28 +180,48 @@ where pub async fn get_or_populate_in_memory( store: &(dyn RedisConnInterface + Send + Sync), - key: &str, + key: &'static str, fun: F, cache: &Cache, ) -> CustomResult where - T: Cacheable + serde::Serialize + serde::de::DeserializeOwned + std::fmt::Debug + Clone, + T: Cacheable + serde::Serialize + serde::de::DeserializeOwned + Debug + Clone, F: FnOnce() -> Fut + Send, Fut: futures::Future> + Send, { - let cache_val = cache.get_val::(key).await; + let redis = &store + .get_redis_conn() + .map_err(|er| { + let error = format!("{}", er); + er.change_context(StorageError::RedisError(error)) + }) + .attach_printable("Failed to get redis connection")?; + let cache_val = cache + .get_val::(CacheKey { + key: key.to_string(), + prefix: redis.key_prefix.clone(), + }) + .await; if let Some(val) = cache_val { Ok(val) } else { - let val = get_or_populate_redis(store, key, fun).await?; - cache.push(key.to_string(), val.clone()).await; + let val = get_or_populate_redis(redis, key, fun).await?; + cache + .push( + CacheKey { + key: key.to_string(), + prefix: redis.key_prefix.clone(), + }, + val.clone(), + ) + .await; Ok(val) } } pub async fn redact_cache( store: &dyn RedisConnInterface, - key: &str, + key: &'static str, fun: F, in_memory: Option<&Cache>, ) -> CustomResult @@ -201,7 +230,6 @@ where Fut: futures::Future> + Send, { let data = fun().await?; - in_memory.async_map(|cache| cache.remove(key)).await; let redis_conn = store .get_redis_conn() @@ -210,6 +238,11 @@ where er.change_context(StorageError::RedisError(error)) }) .attach_printable("Failed to get redis connection")?; + let tenant_key = CacheKey { + key: key.to_string(), + prefix: redis_conn.key_prefix.clone(), + }; + in_memory.async_map(|cache| cache.remove(tenant_key)).await; redis_conn .delete_key(key) @@ -257,9 +290,17 @@ mod cache_tests { #[tokio::test] async fn construct_and_get_cache() { let cache = Cache::new(1800, 1800, None); - cache.push("key".to_string(), "val".to_string()).await; + cache.push(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }, "val".to_string()).await; assert_eq!( - cache.get_val::("key").await, + cache + .get_val::(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }) + .await, Some(String::from("val")) ); } @@ -267,25 +308,61 @@ mod cache_tests { #[tokio::test] async fn eviction_on_size_test() { let cache = Cache::new(2, 2, Some(0)); - cache.push("key".to_string(), "val".to_string()).await; - assert_eq!(cache.get_val::("key").await, None); + cache.push(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }, "val".to_string()).await; + assert_eq!( + cache + .get_val::(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }) + .await, + None + ); } #[tokio::test] async fn invalidate_cache_for_key() { let cache = Cache::new(1800, 1800, None); - cache.push("key".to_string(), "val".to_string()).await; + cache.push(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }, "val".to_string()).await; - cache.remove("key").await; + cache.remove(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }).await; - assert_eq!(cache.get_val::("key").await, None); + assert_eq!( + cache + .get_val::(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }) + .await, + None + ); } #[tokio::test] async fn eviction_on_time_test() { let cache = Cache::new(2, 2, None); - cache.push("key".to_string(), "val".to_string()).await; + cache.push(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }, "val".to_string()).await; tokio::time::sleep(std::time::Duration::from_secs(3)).await; - assert_eq!(cache.get_val::("key").await, None); + assert_eq!( + cache + .get_val::(CacheKey { + key: "key".to_string(), + prefix: "prefix".to_string() + }) + .await, + None + ); } } diff --git a/crates/storage_impl/src/redis/pub_sub.rs b/crates/storage_impl/src/redis/pub_sub.rs index a386057ff80..a903b4be22e 100644 --- a/crates/storage_impl/src/redis/pub_sub.rs +++ b/crates/storage_impl/src/redis/pub_sub.rs @@ -2,7 +2,7 @@ use error_stack::ResultExt; use redis_interface::{errors as redis_errors, PubsubInterface, RedisValue}; use router_env::logger; -use crate::redis::cache::{CacheKind, ACCOUNTS_CACHE, CONFIG_CACHE}; +use crate::redis::cache::{CacheKind, CacheKey, ACCOUNTS_CACHE, CONFIG_CACHE}; #[async_trait::async_trait] pub trait PubSubInterface { @@ -44,7 +44,7 @@ impl PubSubInterface for redis_interface::RedisConnectionPool { #[inline] async fn on_message(&self) -> error_stack::Result<(), redis_errors::RedisError> { - logger::debug!("Started on message: {:?}", self.tenant); + logger::debug!("Started on message: {:?}", self.key_prefix); let mut rx = self.subscriber.on_message(); while let Ok(message) = rx.recv().await { logger::debug!("Invalidating {message:?}"); @@ -60,16 +60,36 @@ impl PubSubInterface for redis_interface::RedisConnectionPool { let key = match key { CacheKind::Config(key) => { - CONFIG_CACHE.remove(key.as_ref()).await; + CONFIG_CACHE + .remove(CacheKey { + key: key.to_string(), + prefix: self.key_prefix.clone(), + }) + .await; key } CacheKind::Accounts(key) => { - ACCOUNTS_CACHE.remove(key.as_ref()).await; + ACCOUNTS_CACHE + .remove(CacheKey { + key: key.to_string(), + prefix: self.key_prefix.clone(), + }) + .await; key } CacheKind::All(key) => { - CONFIG_CACHE.remove(key.as_ref()).await; - ACCOUNTS_CACHE.remove(key.as_ref()).await; + CONFIG_CACHE + .remove(CacheKey { + key: key.to_string(), + prefix: self.key_prefix.clone(), + }) + .await; + ACCOUNTS_CACHE + .remove(CacheKey { + key: key.to_string(), + prefix: self.key_prefix.clone(), + }) + .await; key } }; From e0cb6f043b105779ab5fca590be355e3485161f5 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Thu, 23 May 2024 15:42:21 +0530 Subject: [PATCH 14/24] feat: add tenant support in in-memory cache --- crates/storage_impl/src/redis/cache.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs index f794122cc36..55b44601131 100644 --- a/crates/storage_impl/src/redis/cache.rs +++ b/crates/storage_impl/src/redis/cache.rs @@ -120,12 +120,12 @@ pub struct CacheKey { pub prefix: String, } -impl Into for CacheKey { - fn into(self) -> String { - if self.prefix.is_empty() { - self.key +impl From for String { + fn from(val: CacheKey) -> Self { + if val.prefix.is_empty() { + val.key } else { - format!("{}:{}", self.prefix.clone(), self.key.clone()) + format!("{}:{}", val.prefix.clone(), val.key.clone()) } } } From a6d1936afd69cff1dc6d027e55a4b113775a2c10 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Mon, 27 May 2024 17:51:28 +0530 Subject: [PATCH 15/24] feat: address PR comments --- crates/analytics/src/sqlx.rs | 8 +-- crates/common_utils/src/lib.rs | 24 +++++++++ crates/drainer/src/connection.rs | 13 +---- crates/drainer/src/settings.rs | 23 ++++++++- crates/router/src/bin/scheduler.rs | 4 +- crates/router/src/configs/defaults.rs | 1 - crates/router/src/configs/settings.rs | 5 +- crates/router/src/routes/app.rs | 61 ++++++++++++----------- crates/router/src/services/api.rs | 20 +++----- crates/router/tests/cache.rs | 2 +- crates/router/tests/connectors/aci.rs | 8 +-- crates/router/tests/connectors/utils.rs | 20 ++++---- crates/router/tests/payments.rs | 4 +- crates/router/tests/payments2.rs | 4 +- crates/router/tests/services.rs | 4 +- crates/storage_impl/src/config.rs | 19 +++++++ crates/storage_impl/src/database/store.rs | 14 +----- crates/storage_impl/src/redis/cache.rs | 2 +- 18 files changed, 136 insertions(+), 100 deletions(-) diff --git a/crates/analytics/src/sqlx.rs b/crates/analytics/src/sqlx.rs index 9422ff72a5d..77210be498c 100644 --- a/crates/analytics/src/sqlx.rs +++ b/crates/analytics/src/sqlx.rs @@ -4,12 +4,12 @@ use api_models::{ analytics::refunds::RefundType, enums::{DisputeStage, DisputeStatus}, }; +use common_utils::DbConnectionParams; use common_utils::errors::{CustomResult, ParsingError}; use diesel_models::enums::{ AttemptStatus, AuthenticationType, Currency, PaymentMethod, RefundStatus, }; use error_stack::ResultExt; -use masking::PeekInterface; use sqlx::{ postgres::{PgArgumentBuffer, PgPoolOptions, PgRow, PgTypeInfo, PgValueRef}, Decode, Encode, @@ -50,11 +50,7 @@ impl Default for SqlxClient { impl SqlxClient { pub async fn from_conf(conf: &Database, schema: &str) -> Self { - let password = &conf.password.peek(); - let database_url = format!( - "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", - conf.username, password, conf.host, conf.port, conf.dbname, schema, schema - ); + let database_url = conf.get_database_url(schema); #[allow(clippy::expect_used)] let pool = PgPoolOptions::new() .max_connections(conf.pool_size) diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs index f24b67fde1b..119b54c5070 100644 --- a/crates/common_utils/src/lib.rs +++ b/crates/common_utils/src/lib.rs @@ -2,6 +2,9 @@ #![warn(missing_docs, missing_debug_implementations)] #![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR" ), "/", "README.md"))] +use masking::Secret; +use masking::PeekInterface; + pub mod access_token; pub mod consts; pub mod crypto; @@ -205,3 +208,24 @@ pub fn generate_id_with_default_len(prefix: &str) -> String { pub fn generate_time_ordered_id(prefix: &str) -> String { format!("{prefix}_{}", uuid::Uuid::now_v7().as_simple()) } + +#[allow(missing_docs)] +pub trait DbConnectionParams { + fn get_username(&self) -> &str; + fn get_password(&self) -> Secret; + fn get_host(&self) -> &str; + fn get_port(&self) -> u16; + fn get_dbname(&self) -> &str; + fn get_database_url(&self, schema: &str) -> String { + format!( + "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", + self.get_username(), + self.get_password().peek(), + self.get_host(), + self.get_port(), + self.get_dbname(), + schema, + schema, + ) + } +} diff --git a/crates/drainer/src/connection.rs b/crates/drainer/src/connection.rs index fdc7595d4a8..0afe2b79668 100644 --- a/crates/drainer/src/connection.rs +++ b/crates/drainer/src/connection.rs @@ -1,6 +1,6 @@ use bb8::PooledConnection; use diesel::PgConnection; -use masking::PeekInterface; +use common_utils::DbConnectionParams; use crate::{settings::Database, Settings}; @@ -23,16 +23,7 @@ pub async fn diesel_make_pg_pool( _test_transaction: bool, schema: &str, ) -> PgPool { - let database_url = format!( - "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", - database.username, - database.password.peek(), - database.host, - database.port, - database.dbname, - schema, - schema - ); + let database_url = database.get_database_url(schema); let manager = async_bb8_diesel::ConnectionManager::::new(database_url); let pool = bb8::Pool::builder() .max_size(database.pool_size) diff --git a/crates/drainer/src/settings.rs b/crates/drainer/src/settings.rs index ead91f4468e..128a0e7c428 100644 --- a/crates/drainer/src/settings.rs +++ b/crates/drainer/src/settings.rs @@ -5,6 +5,7 @@ use config::{Environment, File}; use external_services::managers::{ encryption_management::EncryptionManagementConfig, secrets_management::SecretsManagementConfig, }; +use common_utils::DbConnectionParams; use hyperswitch_interfaces::{ encryption_interface::EncryptionManagementInterface, secrets_interface::secret_state::{ @@ -88,6 +89,24 @@ pub struct Database { pub connection_timeout: u64, } +impl DbConnectionParams for Database { + fn get_username(&self) -> &str { + &self.username + } + fn get_password(&self) -> Secret { + self.password.clone() + } + fn get_host(&self) -> &str { + &self.host + } + fn get_port(&self) -> u16 { + self.port + } + fn get_dbname(&self) -> &str { + &self.dbname + } +} + #[derive(Debug, Clone, Deserialize)] #[serde(default)] pub struct DrainerSettings { @@ -104,8 +123,8 @@ pub struct Multitenancy { pub tenants: TenantConfig, } impl Multitenancy { - pub fn get_tenants(&self) -> HashMap { - self.tenants.0.clone() + pub fn get_tenants(&self) -> &HashMap { + &self.tenants.0 } pub fn get_tenant_names(&self) -> Vec { self.tenants.0.keys().cloned().collect() diff --git a/crates/router/src/bin/scheduler.rs b/crates/router/src/bin/scheduler.rs index a59fdfe120b..6c5c3a4b2a3 100644 --- a/crates/router/src/bin/scheduler.rs +++ b/crates/router/src/bin/scheduler.rs @@ -152,7 +152,7 @@ pub async fn deep_health_check( let service_name = service.into_inner(); for (tenant, _) in stores { let session_state_res = - routes::SessionState::from_app_state(app_state.clone(), &tenant, || { + app_state.clone().get_session_state( &tenant, || { errors::ApiErrorResponse::MissingRequiredField { field_name: "tenant_id", } @@ -359,7 +359,7 @@ async fn start_scheduler( channel, WorkflowRunner {}, |state, tenant| { - routes::SessionState::from_app_state(Arc::new(state.clone()), tenant, || { + Arc::new(state.clone()).get_session_state( tenant, || { ProcessTrackerError::TenantNotFound.into() }) }, diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs index 5bafcfb8de1..eb386cb04c1 100644 --- a/crates/router/src/configs/defaults.rs +++ b/crates/router/src/configs/defaults.rs @@ -11,7 +11,6 @@ impl Default for super::settings::Server { workers: num_cpus::get_physical(), host: "localhost".into(), request_body_limit: 16 * 1024, // POST request body is limited to 16KiB - // base_url: "http://localhost:8080".into(), shutdown_timeout: 30, } } diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index c591a224188..94ca3af9800 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -131,8 +131,8 @@ pub struct Multitenancy { } impl Multitenancy { - pub fn get_tenants(&self) -> HashMap { - self.tenants.0.clone() + pub fn get_tenants(&self) -> &HashMap { + &self.tenants.0 } pub fn get_tenant_names(&self) -> Vec { self.tenants.0.keys().cloned().collect() @@ -474,7 +474,6 @@ pub struct Server { pub workers: usize, pub host: String, pub request_body_limit: usize, - // pub base_url: String, pub shutdown_timeout: u64, } diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index aa259619884..b9617d56e8b 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -5,6 +5,7 @@ use actix_web::{web, Scope}; use api_models::routing::RoutingRetrieveQuery; #[cfg(feature = "olap")] use common_enums::TransactionType; +use common_utils::consts::{DEFAULT_TENANT, GLOBAL_TENANT}; #[cfg(feature = "email")] use external_services::email::{ses::AwsSes, EmailService}; use external_services::file_storage::FileStorageInterface; @@ -69,6 +70,8 @@ pub struct ReqState { #[derive(Clone)] pub struct SessionState { pub store: Box, + /// Global store is used for global schema operations in tables like Users and Tenants + pub global_store: Box, pub conf: Arc>, pub api_client: Box, pub event_handler: EventsHandler, @@ -94,34 +97,6 @@ impl SessionState { event_context: events::EventContext::new(self.event_handler.clone()), } } - pub fn from_app_state(state: Arc, tenant: &str, err: F) -> Result - where - F: FnOnce() -> E + Copy, - { - Ok(Self { - store: state.stores.get(tenant).ok_or_else(err)?.clone(), - conf: Arc::clone(&state.conf), - api_client: state.api_client.clone(), - event_handler: state.event_handler.clone(), - #[cfg(feature = "olap")] - pool: state.pools.get(tenant).ok_or_else(err)?.clone(), - file_storage_client: state.file_storage_client.clone(), - request_id: state.request_id, - base_url: state - .conf - .multitenancy - .get_tenant(tenant) - .ok_or_else(err)? - .clone() - .base_url - .clone(), - tenant: tenant.to_string().clone(), - #[cfg(feature = "email")] - email_client: Arc::clone(&state.email_client), - #[cfg(feature = "olap")] - opensearch_client: Arc::clone(&state.opensearch_client), - }) - } } pub trait SessionStateInfo { @@ -170,7 +145,7 @@ pub struct AppState { } impl scheduler::SchedulerAppState for AppState { fn get_tenants(&self) -> Vec { - self.conf.multitenancy.get_tenant_names().clone() + self.conf.multitenancy.get_tenant_names() } } pub trait AppStateInfo { @@ -363,6 +338,34 @@ impl AppState { event_context: events::EventContext::new(self.event_handler.clone()), } } + pub fn get_session_state(self: Arc, tenant: &str, err: F) -> Result where + F: FnOnce() -> E + Copy,{ + let global_tenant = if self.conf.multitenancy.enabled { GLOBAL_TENANT } else { DEFAULT_TENANT }; + Ok(SessionState { + store: self.stores.get(tenant).ok_or_else(err)?.clone(), + global_store: self.stores.get(global_tenant).ok_or_else(err)?.clone(), + conf: Arc::clone(&self.conf), + api_client: self.api_client.clone(), + event_handler: self.event_handler.clone(), + #[cfg(feature = "olap")] + pool: self.pools.get(tenant).ok_or_else(err)?.clone(), + file_storage_client: self.file_storage_client.clone(), + request_id: self.request_id, + base_url: self + .conf + .multitenancy + .get_tenant(tenant) + .ok_or_else(err)? + .clone() + .base_url + .clone(), + tenant: tenant.to_string().clone(), + #[cfg(feature = "email")] + email_client: Arc::clone(&self.email_client), + #[cfg(feature = "olap")] + opensearch_client: Arc::clone(&self.opensearch_client), + }) + } } pub struct Health; diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 3712928abf4..76623559459 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1,7 +1,7 @@ pub mod client; pub mod request; use std::{ - collections::HashMap, + collections::{HashMap, HashSet}, error::Error, fmt::Debug, future::Future, @@ -1010,7 +1010,7 @@ where .change_context(errors::ApiErrorResponse::InternalServerError.switch())?; let mut event_type = payload.get_api_event_type(); - + let tenants: HashSet<_> = state.conf.multitenancy.get_tenant_names().into_iter().collect(); let tenant_id = if !state.conf.multitenancy.enabled { common_utils::consts::DEFAULT_TENANT.to_string() } else { @@ -1023,25 +1023,21 @@ where } .switch() }) - .map(|tenant_id| { - if !state - .conf - .multitenancy - .get_tenant_names() - .contains(&tenant_id.to_string()) + .map(|req_tenant_id| { + if !tenants.contains(&req_tenant_id.to_string()) { Err(errors::ApiErrorResponse::InvalidTenant { - tenant_id: tenant_id.to_string(), + tenant_id: req_tenant_id.to_string(), } .switch()) } else { - Ok(tenant_id.to_string()) + Ok(req_tenant_id.to_string()) } })?? }; - // let tenant_id = "public"; + // let tenant_id = "public".to_string(); let mut session_state = - SessionState::from_app_state(Arc::new(app_state.clone()), tenant_id.as_str(), || { + Arc::new(app_state.clone()).get_session_state( tenant_id.as_str(), || { errors::ApiErrorResponse::InvalidTenant { tenant_id: tenant_id.clone(), } diff --git a/crates/router/tests/cache.rs b/crates/router/tests/cache.rs index 6f45de2eb8b..7518524509d 100644 --- a/crates/router/tests/cache.rs +++ b/crates/router/tests/cache.rs @@ -17,7 +17,7 @@ async fn invalidate_existing_cache_success() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let cache_key = "cacheKey".to_string(); let cache_key_value = "val".to_string(); let _ = state diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index a1843b6da1e..b001cbd19fb 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -195,7 +195,7 @@ async fn payments_create_success() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); static CV: aci::Aci = aci::Aci; let connector = types::api::ConnectorData { @@ -242,7 +242,7 @@ async fn payments_create_failure() { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let connector = types::api::ConnectorData { connector: Box::new(&CV), connector_name: types::Connector::Aci, @@ -304,7 +304,7 @@ async fn refund_for_successful_payments() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let connector_integration: services::BoxedConnectorIntegration< '_, types::api::Authorize, @@ -374,7 +374,7 @@ async fn refunds_create_failure() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let connector_integration: services::BoxedConnectorIntegration< '_, types::api::Execute, diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 70ea2456a4e..56ca0a06218 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -103,7 +103,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -130,7 +130,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -157,7 +157,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -188,7 +188,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); integration.execute_pretasks(&mut request, &state).await?; Box::pin(call_connector(request, integration)).await } @@ -611,7 +611,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -654,7 +654,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -698,7 +698,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -742,7 +742,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -832,7 +832,7 @@ pub trait ConnectorActions: Connector { )) .await; let state = - routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + Arc::new(app_state).get_session_state( "public", || {}).unwrap(); connector_integration .execute_pretasks(&mut request, &state) .await?; @@ -866,7 +866,7 @@ async fn call_connector< Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); services::api::execute_connector_processing_step( &state, integration, diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index 7ef2fadabe3..223ff546576 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -285,7 +285,7 @@ async fn payments_create_core() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let key_store = state .store @@ -467,7 +467,7 @@ async fn payments_create_core_adyen_no_redirect() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let customer_id = format!("cust_{}", Uuid::new_v4()); let merchant_id = "arunraj".to_string(); diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index aba73b7780a..3157c70438e 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -45,7 +45,7 @@ async fn payments_create_core() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let key_store = state .store @@ -234,7 +234,7 @@ async fn payments_create_core_adyen_no_redirect() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let customer_id = format!("cust_{}", Uuid::new_v4()); let merchant_id = "arunraj".to_string(); diff --git a/crates/router/tests/services.rs b/crates/router/tests/services.rs index 771933e7552..c0a3ba674a9 100644 --- a/crates/router/tests/services.rs +++ b/crates/router/tests/services.rs @@ -17,7 +17,7 @@ async fn get_redis_conn_failure() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); let _ = state.store.get_redis_conn().map(|conn| { conn.is_redis_available @@ -43,7 +43,7 @@ async fn get_redis_conn_success() { Box::new(services::MockApiClient), )) .await; - let state = routes::SessionState::from_app_state(Arc::new(app_state), "public", || {}).unwrap(); + let state = Arc::new(app_state).get_session_state( "public", || {}).unwrap(); // Act let result = state.store.get_redis_conn(); diff --git a/crates/storage_impl/src/config.rs b/crates/storage_impl/src/config.rs index fd95a6d315d..775f7b1ee2c 100644 --- a/crates/storage_impl/src/config.rs +++ b/crates/storage_impl/src/config.rs @@ -1,4 +1,5 @@ use masking::Secret; +use common_utils::DbConnectionParams; #[derive(Debug, Clone, serde::Deserialize)] pub struct Database { @@ -14,6 +15,24 @@ pub struct Database { pub max_lifetime: Option, } +impl DbConnectionParams for Database { + fn get_username(&self) -> &str { + &self.username + } + fn get_password(&self) -> Secret { + self.password.clone() + } + fn get_host(&self) -> &str { + &self.host + } + fn get_port(&self) -> u16 { + self.port + } + fn get_dbname(&self) -> &str { + &self.dbname + } +} + #[derive(Debug, serde::Deserialize, Clone, Copy, Default)] #[serde(rename_all = "PascalCase")] pub enum QueueStrategy { diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rs index b0923642e23..eb274148bae 100644 --- a/crates/storage_impl/src/database/store.rs +++ b/crates/storage_impl/src/database/store.rs @@ -1,10 +1,9 @@ use async_bb8_diesel::{AsyncConnection, ConnectionError}; use bb8::CustomizeConnection; +use common_utils::DbConnectionParams; use diesel::PgConnection; use error_stack::ResultExt; use hyperswitch_domain_models::errors::{StorageError, StorageResult}; -use masking::PeekInterface; - use crate::config::Database; pub type PgPool = bb8::Pool>; @@ -83,16 +82,7 @@ pub async fn diesel_make_pg_pool( schema: &str, test_transaction: bool, ) -> StorageResult { - let database_url = format!( - "postgres://{}:{}@{}:{}/{}?application_name={}&options=-c search_path%3D{}", - database.username, - database.password.peek(), - database.host, - database.port, - database.dbname, - schema, - schema, - ); + let database_url = database.get_database_url(schema); let manager = async_bb8_diesel::ConnectionManager::::new(database_url); let mut pool = bb8::Pool::builder() .max_size(database.pool_size) diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs index 55b44601131..619be70e506 100644 --- a/crates/storage_impl/src/redis/cache.rs +++ b/crates/storage_impl/src/redis/cache.rs @@ -125,7 +125,7 @@ impl From for String { if val.prefix.is_empty() { val.key } else { - format!("{}:{}", val.prefix.clone(), val.key.clone()) + format!("{}:{}", val.prefix, val.key) } } } From 69f5fb4650806f5050fbdd409408cfb23c752bb3 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Mon, 27 May 2024 17:59:28 +0530 Subject: [PATCH 16/24] feat: address PR comments --- crates/router/src/routes/app.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index b9617d56e8b..f67be557b66 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -5,7 +5,6 @@ use actix_web::{web, Scope}; use api_models::routing::RoutingRetrieveQuery; #[cfg(feature = "olap")] use common_enums::TransactionType; -use common_utils::consts::{DEFAULT_TENANT, GLOBAL_TENANT}; #[cfg(feature = "email")] use external_services::email::{ses::AwsSes, EmailService}; use external_services::file_storage::FileStorageInterface; @@ -70,8 +69,6 @@ pub struct ReqState { #[derive(Clone)] pub struct SessionState { pub store: Box, - /// Global store is used for global schema operations in tables like Users and Tenants - pub global_store: Box, pub conf: Arc>, pub api_client: Box, pub event_handler: EventsHandler, @@ -340,10 +337,8 @@ impl AppState { } pub fn get_session_state(self: Arc, tenant: &str, err: F) -> Result where F: FnOnce() -> E + Copy,{ - let global_tenant = if self.conf.multitenancy.enabled { GLOBAL_TENANT } else { DEFAULT_TENANT }; Ok(SessionState { store: self.stores.get(tenant).ok_or_else(err)?.clone(), - global_store: self.stores.get(global_tenant).ok_or_else(err)?.clone(), conf: Arc::clone(&self.conf), api_client: self.api_client.clone(), event_handler: self.event_handler.clone(), From 93aa1f95075f7b7d74f47d83c1da80e5634dd6f7 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Tue, 28 May 2024 00:11:31 +0530 Subject: [PATCH 17/24] fix: clippy warnings --- crates/router/src/routes/app.rs | 2 +- crates/router/src/services/api.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 27ecce2092c..809dc8100df 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -336,7 +336,7 @@ impl AppState { } } pub fn get_session_state( - self: Arc, + self: Arc, tenant: &str, err: F, ) -> Result diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 1be92622b00..0ea78e06845 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1029,7 +1029,7 @@ where .switch() }) .map(|req_tenant_id| { - if !tenants.contains(&req_tenant_id.to_string()) { + if !tenants.contains(req_tenant_id) { Err(errors::ApiErrorResponse::InvalidTenant { tenant_id: req_tenant_id.to_string(), } From 95160141de342336f4742acb372c7122385efdfa Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 27 May 2024 18:42:13 +0000 Subject: [PATCH 18/24] chore: run formatter --- crates/router/src/routes/app.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 809dc8100df..3b23f400ad1 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -335,11 +335,7 @@ impl AppState { event_context: events::EventContext::new(self.event_handler.clone()), } } - pub fn get_session_state( - self: Arc, - tenant: &str, - err: F, - ) -> Result + pub fn get_session_state(self: Arc, tenant: &str, err: F) -> Result where F: FnOnce() -> E + Copy, { From 827113fe9b0e033abf63c84e7670781423157809 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Tue, 28 May 2024 15:27:12 +0530 Subject: [PATCH 19/24] fix: clippy warnings --- .../src/errors/api_error_response.rs | 11 ++++++++--- crates/router/src/compatibility/stripe/errors.rs | 7 ++++--- crates/router/src/routes/app.rs | 16 +++++++--------- crates/router/src/services/api.rs | 7 +------ crates/storage_impl/src/redis/cache.rs | 1 + 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs index db9953c23f0..053eb493ce4 100644 --- a/crates/hyperswitch_domain_models/src/errors/api_error_response.rs +++ b/crates/hyperswitch_domain_models/src/errors/api_error_response.rs @@ -271,7 +271,9 @@ pub enum ApiErrorResponse { InvalidCookie, #[error(error_type = ErrorType::InvalidRequestError, code = "IR_27", message = "Extended card info does not exist")] ExtendedCardInfoNotFound, - #[error(error_type = ErrorType::InvalidRequestError, code = "IR_28", message = "Invalid tenant id: {tenant_id}")] + #[error(error_type = ErrorType::ProcessingError, code = "HE_06", message = "Missing tenant id")] + MissingTenantId, + #[error(error_type = ErrorType::ProcessingError, code = "HE_06", message = "Invalid tenant id: {tenant_id}")] InvalidTenant { tenant_id: String }, } @@ -605,8 +607,11 @@ impl ErrorSwitch for ApiErrorRespon Self::ExtendedCardInfoNotFound => { AER::NotFound(ApiError::new("IR", 27, "Extended card info does not exist", None)) } - Self::InvalidTenant { tenant_id } => { - AER::BadRequest(ApiError::new("IR", 28, format!("Invalid Tenant {tenant_id}"), None)) + Self::MissingTenantId => { + AER::InternalServerError(ApiError::new("HE", 6, "Missing Tenant ID in the request".to_string(), None)) + } + Self::InvalidTenant { tenant_id } => { + AER::InternalServerError(ApiError::new("HE", 6, format!("Invalid Tenant {tenant_id}"), None)) } } } diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs index 8319ed0da91..17fcea9b828 100644 --- a/crates/router/src/compatibility/stripe/errors.rs +++ b/crates/router/src/compatibility/stripe/errors.rs @@ -648,7 +648,8 @@ impl From for StripeErrorCode { Self::InvalidWalletToken { wallet_name } } errors::ApiErrorResponse::ExtendedCardInfoNotFound => Self::ExtendedCardInfoNotFound, - errors::ApiErrorResponse::InvalidTenant { tenant_id: _ } => Self::InvalidTenant, + errors::ApiErrorResponse::InvalidTenant { tenant_id: _ } + | errors::ApiErrorResponse::MissingTenantId => Self::InvalidTenant, } } } @@ -721,7 +722,6 @@ impl actix_web::ResponseError for StripeErrorCode { | Self::InvalidConnectorConfiguration { .. } | Self::CurrencyConversionFailed | Self::PaymentMethodDeleteFailed - | Self::InvalidTenant | Self::ExtendedCardInfoNotFound => StatusCode::BAD_REQUEST, Self::RefundFailed | Self::PayoutFailed @@ -729,7 +729,8 @@ impl actix_web::ResponseError for StripeErrorCode { | Self::InternalServerError | Self::MandateActive | Self::CustomerRedacted - | Self::WebhookProcessingError => StatusCode::INTERNAL_SERVER_ERROR, + | Self::WebhookProcessingError + | Self::InvalidTenant => StatusCode::INTERNAL_SERVER_ERROR, Self::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE, Self::ExternalConnectorError { status_code, .. } => { StatusCode::from_u16(*status_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR) diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 809dc8100df..b13bd5a4c87 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -45,13 +45,16 @@ use super::{pm_auth, poll::retrieve_poll_status}; pub use crate::analytics::opensearch::OpenSearchClient; #[cfg(feature = "olap")] use crate::analytics::AnalyticsProvider; -use crate::configs::secrets_transformers; #[cfg(all(feature = "frm", feature = "oltp"))] use crate::routes::fraud_check as frm_routes; #[cfg(all(feature = "recon", feature = "olap"))] use crate::routes::recon as recon_routes; #[cfg(feature = "olap")] use crate::routes::verify_connector::payment_connector_verify; +use crate::{ + configs::secrets_transformers, + db::{kafka_store::TenantID, KafkaStore}, +}; pub use crate::{ configs::settings, core::routing, @@ -147,7 +150,6 @@ impl scheduler::SchedulerAppState for AppState { } pub trait AppStateInfo { fn conf(&self) -> settings::Settings; - // fn store(&self) -> Box; fn event_handler(&self) -> EventsHandler; #[cfg(feature = "email")] fn email_client(&self) -> Arc; @@ -254,7 +256,7 @@ impl AppState { let store: Box = match storage_impl { StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match &event_handler { EventsHandler::Kafka(kafka_client) => Box::new( - crate::db::KafkaStore::new( + KafkaStore::new( #[allow(clippy::expect_used)] get_store( &conf.clone(), @@ -265,7 +267,7 @@ impl AppState { .await .expect("Failed to create store"), kafka_client.clone(), - crate::db::kafka_store::TenantID(tenant.clone()), + TenantID(tenant.clone()), ) .await, ), @@ -335,11 +337,7 @@ impl AppState { event_context: events::EventContext::new(self.event_handler.clone()), } } - pub fn get_session_state( - self: Arc, - tenant: &str, - err: F, - ) -> Result + pub fn get_session_state(self: Arc, tenant: &str, err: F) -> Result where F: FnOnce() -> E + Copy, { diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index 0ea78e06845..0aaeb44b38d 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -1022,12 +1022,7 @@ where incoming_request_header .get("x-tenant-id") .and_then(|value| value.to_str().ok()) - .ok_or_else(|| { - errors::ApiErrorResponse::InvalidRequestData { - message: "Missing tenant Id".to_string(), - } - .switch() - }) + .ok_or_else(|| errors::ApiErrorResponse::MissingTenantId.switch()) .map(|req_tenant_id| { if !tenants.contains(req_tenant_id) { Err(errors::ApiErrorResponse::InvalidTenant { diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs index 61c7dfa7b7d..eb792a6937e 100644 --- a/crates/storage_impl/src/redis/cache.rs +++ b/crates/storage_impl/src/redis/cache.rs @@ -129,6 +129,7 @@ pub struct Cache { #[derive(Debug, Clone)] pub struct CacheKey { pub key: String, + // #TODO: make it usage specific enum Eg: CacheKind { Tenant(String), NoTenant, Partition(String) } pub prefix: String, } From 4cb732e6915b5cc6e4874ae43547e91f6eaece6a Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Tue, 28 May 2024 15:39:18 +0530 Subject: [PATCH 20/24] refactor: drainer to have single redis conn for error handling --- crates/drainer/src/handler.rs | 9 +++++---- crates/redis_interface/src/commands.rs | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/drainer/src/handler.rs b/crates/drainer/src/handler.rs index b9667327791..77aefb422af 100644 --- a/crates/drainer/src/handler.rs +++ b/crates/drainer/src/handler.rs @@ -121,10 +121,11 @@ impl Handler { pub fn spawn_error_handlers(&self, tx: mpsc::Sender<()>) -> errors::DrainerResult<()> { let (redis_error_tx, redis_error_rx) = oneshot::channel(); - let mut redis_conn_clone = None; - for store in self.stores.values() { - redis_conn_clone = Some(store.redis_conn.clone()); - } + let redis_conn_clone = self + .stores + .values() + .next() + .map(|store| store.redis_conn.clone()); match redis_conn_clone { None => { logger::error!("No redis connection found"); diff --git a/crates/redis_interface/src/commands.rs b/crates/redis_interface/src/commands.rs index 45a07ab6a93..ccfeb3e5b12 100644 --- a/crates/redis_interface/src/commands.rs +++ b/crates/redis_interface/src/commands.rs @@ -546,7 +546,7 @@ impl super::RedisConnectionPool { .change_context(errors::RedisError::GetLengthFailed) } - pub fn get_tenant_keys(&self, keys: K) -> MultipleKeys + pub fn get_keys_with_prefix(&self, keys: K) -> MultipleKeys where K: Into + Debug + Send + Sync, { @@ -572,7 +572,7 @@ impl super::RedisConnectionPool { K: Into + Debug + Send + Sync, Ids: Into + Debug + Send + Sync, { - let strms = self.get_tenant_keys(streams); + let strms = self.get_keys_with_prefix(streams); self.pool .xread_map( Some(read_count.unwrap_or(self.config.default_stream_read_count)), @@ -611,14 +611,14 @@ impl super::RedisConnectionPool { count, block, false, - self.get_tenant_keys(streams), + self.get_keys_with_prefix(streams), ids, ) .await } None => { self.pool - .xread_map(count, block, self.get_tenant_keys(streams), ids) + .xread_map(count, block, self.get_keys_with_prefix(streams), ids) .await } } From fb10f00b54470c9bc3cdae8ce0654fd668dc9fda Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Wed, 29 May 2024 20:15:19 +0530 Subject: [PATCH 21/24] refactor: get redis key prefix from config --- config/development.toml | 2 +- crates/drainer/src/main.rs | 6 +- crates/drainer/src/services.rs | 10 ++- crates/drainer/src/settings.rs | 2 + crates/router/src/configs/settings.rs | 11 +++ crates/router/src/routes/app.rs | 97 +++++++++++++---------- crates/router/src/services.rs | 6 +- crates/storage_impl/src/config.rs | 5 ++ crates/storage_impl/src/database/store.rs | 37 ++++++--- crates/storage_impl/src/lib.rs | 24 +++--- 10 files changed, 127 insertions(+), 73 deletions(-) diff --git a/config/development.toml b/config/development.toml index f356d489873..3216cbc7838 100644 --- a/config/development.toml +++ b/config/development.toml @@ -634,4 +634,4 @@ sdk_eligible_payment_methods = "card" enabled = false [multitenancy.tenants] -public = { name = "hyperswitch", base_url = "http://localhost:8080"} \ No newline at end of file +public = { name = "hyperswitch", base_url = "http://localhost:8080", schema = "public", redis_key_prefix = ""} \ No newline at end of file diff --git a/crates/drainer/src/main.rs b/crates/drainer/src/main.rs index 030b8209116..f3f822129c3 100644 --- a/crates/drainer/src/main.rs +++ b/crates/drainer/src/main.rs @@ -20,9 +20,9 @@ async fn main() -> DrainerResult<()> { let state = settings::AppState::new(conf.clone()).await; let mut stores = HashMap::new(); - for tenant in conf.multitenancy.get_tenant_names() { - let store = std::sync::Arc::new(services::Store::new(&state.conf, false, &tenant).await); - stores.insert(tenant.clone(), store); + for (tenant_name, tenant) in conf.multitenancy.get_tenants() { + let store = std::sync::Arc::new(services::Store::new(&state.conf, false, tenant).await); + stores.insert(tenant_name.clone(), store); } #[cfg(feature = "vergen")] diff --git a/crates/drainer/src/services.rs b/crates/drainer/src/services.rs index 2cfd2d14fed..55ffe0c4e7f 100644 --- a/crates/drainer/src/services.rs +++ b/crates/drainer/src/services.rs @@ -7,6 +7,7 @@ use redis_interface::RedisConnectionPool; use crate::{ connection::{diesel_make_pg_pool, PgPool}, logger, + settings::Tenant, }; #[derive(Clone)] @@ -29,16 +30,19 @@ impl Store { /// Panics if there is a failure while obtaining the HashiCorp client using the provided configuration. /// This panic indicates a critical failure in setting up external services, and the application cannot proceed without a valid HashiCorp client. /// - pub async fn new(config: &crate::Settings, test_transaction: bool, tenant: &str) -> Self { + pub async fn new(config: &crate::Settings, test_transaction: bool, tenant: &Tenant) -> Self { let redis_conn = crate::connection::redis_connection(config).await; Self { master_pool: diesel_make_pg_pool( config.master_database.get_inner(), test_transaction, - tenant, + &tenant.schema, ) .await, - redis_conn: Arc::new(RedisConnectionPool::clone(&redis_conn, tenant)), + redis_conn: Arc::new(RedisConnectionPool::clone( + &redis_conn, + &tenant.redis_key_prefix, + )), config: StoreConfig { drainer_stream_name: config.drainer.stream_name.clone(), drainer_num_partitions: config.drainer.num_partitions, diff --git a/crates/drainer/src/settings.rs b/crates/drainer/src/settings.rs index b5c9e08331f..311cee0cede 100644 --- a/crates/drainer/src/settings.rs +++ b/crates/drainer/src/settings.rs @@ -141,6 +141,8 @@ pub struct TenantConfig(pub HashMap); pub struct Tenant { pub name: String, pub base_url: String, + pub schema: String, + pub redis_key_prefix: String, } #[derive(Debug, Deserialize, Clone)] diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index 2b84d534593..d78dba66dad 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -150,6 +150,17 @@ pub struct TenantConfig(pub HashMap); pub struct Tenant { pub name: String, pub base_url: String, + pub schema: String, + pub redis_key_prefix: String, +} + +impl storage_impl::config::TenantConfig for Tenant { + fn get_schema(&self) -> &str { + self.schema.as_str() + } + fn get_redis_key_prefix(&self) -> &str { + self.redis_key_prefix.as_str() + } } #[derive(Debug, Deserialize, Clone, Default)] diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index b13bd5a4c87..270d87d025f 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -14,7 +14,7 @@ use hyperswitch_interfaces::{ }; use router_env::tracing_actix_web::RequestId; use scheduler::SchedulerInterface; -use storage_impl::MockDb; +use storage_impl::{config::TenantConfig, redis::RedisStore, MockDb}; use tokio::sync::oneshot; #[cfg(feature = "olap")] @@ -51,10 +51,6 @@ use crate::routes::fraud_check as frm_routes; use crate::routes::recon as recon_routes; #[cfg(feature = "olap")] use crate::routes::verify_connector::payment_connector_verify; -use crate::{ - configs::secrets_transformers, - db::{kafka_store::TenantID, KafkaStore}, -}; pub use crate::{ configs::settings, core::routing, @@ -63,6 +59,10 @@ pub use crate::{ routes::cards_info::card_iin_info, services::{get_cache_store, get_store}, }; +use crate::{ + configs::{secrets_transformers, Settings}, + db::kafka_store::{KafkaStore, TenantID}, +}; #[derive(Clone)] pub struct ReqState { @@ -252,45 +252,23 @@ impl AppState { let cache_store = get_cache_store(&conf.clone(), shut_down_signal, testable) .await .expect("Failed to create store"); - for tenant in conf.clone().multitenancy.get_tenant_names() { - let store: Box = match storage_impl { - StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match &event_handler { - EventsHandler::Kafka(kafka_client) => Box::new( - KafkaStore::new( - #[allow(clippy::expect_used)] - get_store( - &conf.clone(), - tenant.as_str(), - Arc::clone(&cache_store), - testable, - ) - .await - .expect("Failed to create store"), - kafka_client.clone(), - TenantID(tenant.clone()), - ) - .await, - ), - EventsHandler::Logs(_) => Box::new( - #[allow(clippy::expect_used)] - get_store(&conf, tenant.as_str(), Arc::clone(&cache_store), testable) - .await - .expect("Failed to create store"), - ), - }, - #[allow(clippy::expect_used)] - StorageImpl::Mock => Box::new( - MockDb::new(&conf.redis) - .await - .expect("Failed to create mock store"), - ), - }; - stores.insert(tenant.clone(), store); + for (tenant_name, tenant) in conf.clone().multitenancy.get_tenants() { + let store: Box = Self::get_store_interface( + &storage_impl, + &event_handler, + &conf, + tenant, + Arc::clone(&cache_store), + testable, + ) + .await; + stores.insert(tenant_name.clone(), store); #[cfg(feature = "olap")] let pool = - AnalyticsProvider::from_conf(conf.analytics.get_inner(), tenant.as_str()).await; + AnalyticsProvider::from_conf(conf.analytics.get_inner(), tenant_name.as_str()) + .await; #[cfg(feature = "olap")] - pools.insert(tenant.clone(), pool); + pools.insert(tenant_name.clone(), pool); } #[cfg(feature = "email")] @@ -318,6 +296,43 @@ impl AppState { .await } + async fn get_store_interface( + storage_impl: &StorageImpl, + event_handler: &EventsHandler, + conf: &Settings, + tenant: &settings::Tenant, + cache_store: Arc, + testable: bool, + ) -> Box { + match storage_impl { + StorageImpl::Postgresql | StorageImpl::PostgresqlTest => match event_handler { + EventsHandler::Kafka(kafka_client) => Box::new( + KafkaStore::new( + #[allow(clippy::expect_used)] + get_store(&conf.clone(), tenant, Arc::clone(&cache_store), testable) + .await + .expect("Failed to create store"), + kafka_client.clone(), + TenantID(tenant.get_schema().to_string()), + ) + .await, + ), + EventsHandler::Logs(_) => Box::new( + #[allow(clippy::expect_used)] + get_store(conf, tenant, Arc::clone(&cache_store), testable) + .await + .expect("Failed to create store"), + ), + }, + #[allow(clippy::expect_used)] + StorageImpl::Mock => Box::new( + MockDb::new(&conf.redis) + .await + .expect("Failed to create mock store"), + ), + } + } + pub async fn new( conf: settings::Settings, shut_down_signal: oneshot::Sender<()>, diff --git a/crates/router/src/services.rs b/crates/router/src/services.rs index 38e5f11eff5..91c88e9c5d3 100644 --- a/crates/router/src/services.rs +++ b/crates/router/src/services.rs @@ -42,7 +42,7 @@ pub type Store = KVRouterStore; #[allow(clippy::expect_used)] pub async fn get_store( config: &Settings, - schema: &str, + tenant: &crate::configs::settings::Tenant, cache_store: Arc, test_transaction: bool, ) -> StorageResult { @@ -64,11 +64,11 @@ pub async fn get_store( let conf = (master_config.into(), replica_config.into()); let store: RouterStore = if test_transaction { - RouterStore::test_store(conf, schema, &config.redis, master_enc_key).await? + RouterStore::test_store(conf, tenant, &config.redis, master_enc_key).await? } else { RouterStore::from_config( conf, - schema, + tenant, master_enc_key, cache_store, consts::PUB_SUB_CHANNEL, diff --git a/crates/storage_impl/src/config.rs b/crates/storage_impl/src/config.rs index 64a92348ce3..e371936a04d 100644 --- a/crates/storage_impl/src/config.rs +++ b/crates/storage_impl/src/config.rs @@ -33,6 +33,11 @@ impl DbConnectionParams for Database { } } +pub trait TenantConfig: Send + Sync { + fn get_schema(&self) -> &str; + fn get_redis_key_prefix(&self) -> &str; +} + #[derive(Debug, serde::Deserialize, Clone, Copy, Default)] #[serde(rename_all = "PascalCase")] pub enum QueueStrategy { diff --git a/crates/storage_impl/src/database/store.rs b/crates/storage_impl/src/database/store.rs index 975f3bb8709..543cc47870d 100644 --- a/crates/storage_impl/src/database/store.rs +++ b/crates/storage_impl/src/database/store.rs @@ -5,7 +5,7 @@ use diesel::PgConnection; use error_stack::ResultExt; use hyperswitch_domain_models::errors::{StorageError, StorageResult}; -use crate::config::Database; +use crate::config::{Database, TenantConfig}; pub type PgPool = bb8::Pool>; pub type PgPooledConn = async_bb8_diesel::Connection; @@ -13,8 +13,11 @@ pub type PgPooledConn = async_bb8_diesel::Connection; #[async_trait::async_trait] pub trait DatabaseStore: Clone + Send + Sync { type Config: Send; - async fn new(config: Self::Config, schema: &str, test_transaction: bool) - -> StorageResult; + async fn new( + config: Self::Config, + tenant_config: &dyn TenantConfig, + test_transaction: bool, + ) -> StorageResult; fn get_master_pool(&self) -> &PgPool; fn get_replica_pool(&self) -> &PgPool; } @@ -27,9 +30,14 @@ pub struct Store { #[async_trait::async_trait] impl DatabaseStore for Store { type Config = Database; - async fn new(config: Database, schema: &str, test_transaction: bool) -> StorageResult { + async fn new( + config: Database, + tenant_config: &dyn TenantConfig, + test_transaction: bool, + ) -> StorageResult { Ok(Self { - master_pool: diesel_make_pg_pool(&config, schema, test_transaction).await?, + master_pool: diesel_make_pg_pool(&config, tenant_config.get_schema(), test_transaction) + .await?, }) } @@ -53,16 +61,21 @@ impl DatabaseStore for ReplicaStore { type Config = (Database, Database); async fn new( config: (Database, Database), - schema: &str, + tenant_config: &dyn TenantConfig, test_transaction: bool, ) -> StorageResult { let (master_config, replica_config) = config; - let master_pool = diesel_make_pg_pool(&master_config, schema, test_transaction) - .await - .attach_printable("failed to create master pool")?; - let replica_pool = diesel_make_pg_pool(&replica_config, schema, test_transaction) - .await - .attach_printable("failed to create replica pool")?; + let master_pool = + diesel_make_pg_pool(&master_config, tenant_config.get_schema(), test_transaction) + .await + .attach_printable("failed to create master pool")?; + let replica_pool = diesel_make_pg_pool( + &replica_config, + tenant_config.get_schema(), + test_transaction, + ) + .await + .attach_printable("failed to create replica pool")?; Ok(Self { master_pool, replica_pool, diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 16a272db0c1..0d4c78c2b5f 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use config::TenantConfig; use diesel_models as store; use error_stack::ResultExt; use hyperswitch_domain_models::errors::{StorageError, StorageResult}; @@ -57,19 +58,19 @@ where ); async fn new( config: Self::Config, - schema: &str, + tenant_config: &dyn TenantConfig, test_transaction: bool, ) -> StorageResult { let (db_conf, cache_conf, encryption_key, cache_error_signal, inmemory_cache_stream) = config; if test_transaction { - Self::test_store(db_conf, schema, &cache_conf, encryption_key) + Self::test_store(db_conf, tenant_config, &cache_conf, encryption_key) .await .attach_printable("failed to create test router store") } else { Self::from_config( db_conf, - schema, + tenant_config, encryption_key, Self::cache_store(&cache_conf, cache_error_signal).await?, inmemory_cache_stream, @@ -95,15 +96,18 @@ impl RedisConnInterface for RouterStore { impl RouterStore { pub async fn from_config( db_conf: T::Config, - schema: &str, + tenant_config: &dyn TenantConfig, encryption_key: StrongSecret>, cache_store: Arc, inmemory_cache_stream: &str, ) -> StorageResult { - let db_store = T::new(db_conf, schema, false).await?; + let db_store = T::new(db_conf, tenant_config, false).await?; let redis_conn = cache_store.redis_conn.clone(); let cache_store = Arc::new(RedisStore { - redis_conn: Arc::new(RedisConnectionPool::clone(&redis_conn, schema)), + redis_conn: Arc::new(RedisConnectionPool::clone( + &redis_conn, + tenant_config.get_redis_key_prefix(), + )), }); cache_store .subscribe_to_channel(inmemory_cache_stream) @@ -140,12 +144,12 @@ impl RouterStore { /// Will panic if `CONNECTOR_AUTH_FILE_PATH` is not set pub async fn test_store( db_conf: T::Config, - schema: &str, + tenant_config: &dyn TenantConfig, cache_conf: &redis_interface::RedisSettings, encryption_key: StrongSecret>, ) -> StorageResult { // TODO: create an error enum and return proper error here - let db_store = T::new(db_conf, schema, true).await?; + let db_store = T::new(db_conf, tenant_config, true).await?; let cache_store = RedisStore::new(cache_conf) .await .change_context(StorageError::InitializationError) @@ -178,11 +182,11 @@ where type Config = (RouterStore, String, u8, u32, Option); async fn new( config: Self::Config, - schema: &str, + tenant_config: &dyn TenantConfig, _test_transaction: bool, ) -> StorageResult { let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = config; - let drainer_stream_name = format!("{}_{}", schema, config.1); + let drainer_stream_name = format!("{}_{}", tenant_config.get_schema(), config.1); Ok(Self::from_store( router_store, drainer_stream_name, From 368862189e9378ec49d4189c11c08543c93f3cf0 Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Wed, 29 May 2024 22:32:30 +0530 Subject: [PATCH 22/24] fix: clippy warnings --- crates/storage_impl/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 0d4c78c2b5f..27e1a18eb6d 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use config::TenantConfig; use diesel_models as store; use error_stack::ResultExt; use hyperswitch_domain_models::errors::{StorageError, StorageResult}; @@ -58,7 +57,7 @@ where ); async fn new( config: Self::Config, - tenant_config: &dyn TenantConfig, + tenant_config: &dyn config::TenantConfig, test_transaction: bool, ) -> StorageResult { let (db_conf, cache_conf, encryption_key, cache_error_signal, inmemory_cache_stream) = From 4283f8f805d96f86ebba1afcea8a6c172758b8fb Mon Sep 17 00:00:00 2001 From: Jagan Elavarasan Date: Wed, 29 May 2024 22:39:35 +0530 Subject: [PATCH 23/24] fix: clippy warnings --- crates/storage_impl/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs index 27e1a18eb6d..04618c50f04 100644 --- a/crates/storage_impl/src/lib.rs +++ b/crates/storage_impl/src/lib.rs @@ -95,7 +95,7 @@ impl RedisConnInterface for RouterStore { impl RouterStore { pub async fn from_config( db_conf: T::Config, - tenant_config: &dyn TenantConfig, + tenant_config: &dyn config::TenantConfig, encryption_key: StrongSecret>, cache_store: Arc, inmemory_cache_stream: &str, @@ -143,7 +143,7 @@ impl RouterStore { /// Will panic if `CONNECTOR_AUTH_FILE_PATH` is not set pub async fn test_store( db_conf: T::Config, - tenant_config: &dyn TenantConfig, + tenant_config: &dyn config::TenantConfig, cache_conf: &redis_interface::RedisSettings, encryption_key: StrongSecret>, ) -> StorageResult { @@ -181,7 +181,7 @@ where type Config = (RouterStore, String, u8, u32, Option); async fn new( config: Self::Config, - tenant_config: &dyn TenantConfig, + tenant_config: &dyn config::TenantConfig, _test_transaction: bool, ) -> StorageResult { let (router_store, _, drainer_num_partitions, ttl_for_kv, soft_kill_mode) = config; From 07ea1e61c7480a5e1cf41f50f6ba636e4823b856 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 12:56:53 +0000 Subject: [PATCH 24/24] chore: run formatter --- crates/common_utils/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs index 2b0f8874e80..4e515e3d6a7 100644 --- a/crates/common_utils/src/lib.rs +++ b/crates/common_utils/src/lib.rs @@ -3,6 +3,7 @@ #![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR" ), "/", "README.md"))] use masking::{PeekInterface, Secret}; + use crate::{ consts::ID_LENGTH, id_type::{CustomerId, MerchantReferenceId},