├── .babelrc ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── documentation.yml │ └── feature_request.yml ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── aurora_performance.yml │ ├── dependabot_auto_merge.yml │ ├── integration_tests.yml │ ├── integration_tests_latest.yml │ ├── main.yml │ ├── multi_az_integration_tests.yml │ ├── release.yml │ ├── release_draft.yml │ ├── remove-old-artifacts.yml │ └── run-autoscaling-tests.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── MAINTENANCE.md ├── NOTICE ├── README.md ├── THIRD-PARTY-LICENSES ├── build └── .gitkeep ├── common ├── lib │ ├── AllowedAndBlockedHosts.ts │ ├── abstract_connection_plugin.ts │ ├── authentication │ │ ├── aws_credentials_manager.ts │ │ ├── aws_secrets_manager_plugin.ts │ │ ├── aws_secrets_manager_plugin_factory.ts │ │ ├── iam_authentication_plugin.ts │ │ └── iam_authentication_plugin_factory.ts │ ├── aws_client.ts │ ├── aws_pool_client.ts │ ├── aws_pool_config.ts │ ├── can_release_resources.ts │ ├── client_wrapper.ts │ ├── connection_plugin.ts │ ├── connection_plugin_chain_builder.ts │ ├── connection_provider.ts │ ├── connection_provider_manager.ts │ ├── database_dialect │ │ ├── database_dialect.ts │ │ ├── database_dialect_codes.ts │ │ ├── database_dialect_manager.ts │ │ ├── database_dialect_provider.ts │ │ └── limitless_database_dialect.ts │ ├── driver_connection_provider.ts │ ├── driver_dialect │ │ └── driver_dialect.ts │ ├── error_handler.ts │ ├── highest_weight_host_selector.ts │ ├── host_availability │ │ ├── exponential_backoff_host_availability_strategy.ts │ │ ├── host_availability.ts │ │ ├── host_availability_strategy.ts │ │ ├── host_availability_strategy_factory.ts │ │ └── simple_host_availability_strategy.ts │ ├── host_change_options.ts │ ├── host_info.ts │ ├── host_info_builder.ts │ ├── host_list_provider │ │ ├── connection_string_host_list_provider.ts │ │ ├── host_list_provider.ts │ │ ├── monitoring │ │ │ ├── cluster_topology_monitor.ts │ │ │ └── monitoring_host_list_provider.ts │ │ └── rds_host_list_provider.ts │ ├── host_list_provider_service.ts │ ├── host_role.ts │ ├── host_selector.ts │ ├── index.ts │ ├── internal_pooled_connection_provider.ts │ ├── least_connections_host_selector.ts │ ├── mysql_client_wrapper.ts │ ├── old_connection_suggestion_action.ts │ ├── pg_client_wrapper.ts │ ├── plugin_factory.ts │ ├── plugin_manager.ts │ ├── plugin_service.ts │ ├── plugin_service_manager_container.ts │ ├── plugins │ │ ├── aurora_initial_connection_strategy_plugin.ts │ │ ├── aurora_initial_connection_strategy_plugin_factory.ts │ │ ├── connect_time_plugin.ts │ │ ├── connect_time_plugin_factory.ts │ │ ├── connection_tracker │ │ │ ├── aurora_connection_tracker_plugin.ts │ │ │ ├── aurora_connection_tracker_plugin_factory.ts │ │ │ └── opened_connection_tracker.ts │ │ ├── custom_endpoint │ │ │ ├── custom_endpoint_info.ts │ │ │ ├── custom_endpoint_monitor_impl.ts │ │ │ ├── custom_endpoint_plugin.ts │ │ │ ├── custom_endpoint_plugin_factory.ts │ │ │ ├── custom_endpoint_role_type.ts │ │ │ └── member_list_type.ts │ │ ├── default_plugin.ts │ │ ├── dev │ │ │ ├── developer_connection_plugin.ts │ │ │ ├── developer_connection_plugin_factory.ts │ │ │ ├── error_simulator.ts │ │ │ ├── error_simulator_connect_callback.ts │ │ │ ├── error_simulator_manager.ts │ │ │ └── error_simulator_method_callback.ts │ │ ├── efm │ │ │ ├── host_monitoring_connection_plugin.ts │ │ │ ├── host_monitoring_plugin_factory.ts │ │ │ ├── monitor.ts │ │ │ ├── monitor_connection_context.ts │ │ │ └── monitor_service.ts │ │ ├── efm2 │ │ │ ├── host_monitoring2_connection_plugin.ts │ │ │ ├── host_monitoring2_plugin_factory.ts │ │ │ ├── monitor.ts │ │ │ ├── monitor_connection_context.ts │ │ │ └── monitor_service.ts │ │ ├── execute_time_plugin.ts │ │ ├── execute_time_plugin_factory.ts │ │ ├── failover │ │ │ ├── failover_mode.ts │ │ │ ├── failover_plugin.ts │ │ │ ├── failover_plugin_factory.ts │ │ │ ├── failover_restriction.ts │ │ │ ├── reader_failover_handler.ts │ │ │ ├── reader_failover_result.ts │ │ │ ├── reader_task_selector.ts │ │ │ ├── writer_failover_handler.ts │ │ │ └── writer_failover_result.ts │ │ ├── failover2 │ │ │ ├── failover2_plugin.ts │ │ │ └── failover2_plugin_factory.ts │ │ ├── federated_auth │ │ │ ├── adfs_credentials_provider_factory.ts │ │ │ ├── credentials_provider_factory.ts │ │ │ ├── federated_auth_plugin.ts │ │ │ ├── federated_auth_plugin_factory.ts │ │ │ ├── okta_auth_plugin.ts │ │ │ ├── okta_auth_plugin_factory.ts │ │ │ ├── okta_credentials_provider_factory.ts │ │ │ └── saml_credentials_provider_factory.ts │ │ ├── limitless │ │ │ ├── limitless_connection_context.ts │ │ │ ├── limitless_connection_plugin.ts │ │ │ ├── limitless_connection_plugin_factory.ts │ │ │ ├── limitless_helper.ts │ │ │ ├── limitless_query_helper.ts │ │ │ ├── limitless_router_monitor.ts │ │ │ └── limitless_router_service.ts │ │ ├── read_write_splitting_plugin.ts │ │ ├── read_write_splitting_plugin_factory.ts │ │ ├── stale_dns │ │ │ ├── stale_dns_helper.ts │ │ │ ├── stale_dns_plugin.ts │ │ │ └── stale_dns_plugin_factory.ts │ │ └── strategy │ │ │ └── fastest_response │ │ │ ├── fastest_response_strategy_plugin.ts │ │ │ ├── fastest_respose_strategy_plugin_factory.ts │ │ │ ├── host_response_time_monitor.ts │ │ │ └── host_response_time_service.ts │ ├── pool_client_wrapper.ts │ ├── pooled_connection_provider.ts │ ├── profile │ │ ├── configuration_profile.ts │ │ ├── configuration_profile_builder.ts │ │ ├── configuration_profile_codes.ts │ │ └── driver_configuration_profiles.ts │ ├── random_host_selector.ts │ ├── round_robin_host_selector.ts │ ├── session_state.ts │ ├── session_state_service.ts │ ├── session_state_service_impl.ts │ ├── session_state_transfer_handler.ts │ ├── topology_aware_database_dialect.ts │ ├── utils │ │ ├── cache_map.ts │ │ ├── client_utils.ts │ │ ├── connection_url_parser.ts │ │ ├── errors.ts │ │ ├── iam_auth_utils.ts │ │ ├── internal_pool_mapping.ts │ │ ├── locales │ │ │ └── en.json │ │ ├── map_utils.ts │ │ ├── messages.ts │ │ ├── pool_key.ts │ │ ├── rds_url_type.ts │ │ ├── rds_utils.ts │ │ ├── region_utils.ts │ │ ├── saml_utils.ts │ │ ├── sliding_expiration_cache.ts │ │ ├── sliding_expiration_cache_with_cleanup_task.ts │ │ ├── sql_method_utils.ts │ │ ├── subscribed_method_helper.ts │ │ ├── telemetry │ │ │ ├── default_telemetry_factory.ts │ │ │ ├── null_telemetry_context.ts │ │ │ ├── null_telemetry_counter.ts │ │ │ ├── null_telemetry_factory.ts │ │ │ ├── null_telemetry_gauge.ts │ │ │ ├── open_telemetry_context.ts │ │ │ ├── open_telemetry_counter.ts │ │ │ ├── open_telemetry_factory.ts │ │ │ ├── open_telemetry_gauge.ts │ │ │ ├── telemetry_const.ts │ │ │ ├── telemetry_context.ts │ │ │ ├── telemetry_counter.ts │ │ │ ├── telemetry_factory.ts │ │ │ ├── telemetry_gauge.ts │ │ │ ├── telemetry_trace_level.ts │ │ │ ├── xray_telemetry_context.ts │ │ │ └── xray_telemetry_factory.ts │ │ ├── transaction_isolation_level.ts │ │ └── utils.ts │ └── wrapper_property.ts └── logutils.ts ├── docs ├── Documentation.md ├── GettingStarted.md ├── development-guide │ ├── Architecture.md │ ├── DevelopmentGuide.md │ ├── IntegrationTests.md │ ├── LoadablePlugins.md │ ├── Pipelines.md │ ├── PluginManager.md │ ├── PluginPipelinePerformanceResults.md │ ├── PluginService.md │ └── ReadWriteSplittingPerformanceResults.md ├── files │ └── configuration-profile-presets.pdf ├── images │ ├── configuration-presets.png │ ├── efm_monitor_process.png │ ├── enhanced_failure_monitoring_diagram.png │ ├── failover1.png │ ├── failover2.png │ ├── failover2_panic.png │ ├── failover_behavior.png │ ├── failover_diagram.png │ ├── initiate_pipelines.png │ ├── nodejs_wrapper_connect_pipelines_benchmarks.png │ ├── nodejs_wrapper_execute_pipelines_benchmarks.png │ ├── nodejs_wrapper_postgresql_efm_30000_5000_3.png │ ├── nodejs_wrapper_postgresql_efm_6000_1000_1.png │ ├── nodejs_wrapper_postgresql_failover_efm_30000_5000_3.png │ ├── nodejs_wrapper_postgresql_failover_efm_6000_1000_1.png │ ├── nodejs_wrapper_release_resources_pipelines_benchmarks.png │ ├── pipelines.png │ ├── plugin_manager.png │ ├── plugin_service.png │ ├── session_state_switch_connection.jpg │ ├── telemetry_nested.png │ ├── telemetry_top_level.png │ └── telemetry_traces.png └── using-the-nodejs-wrapper │ ├── ConfigurationPresets.md │ ├── DatabaseDialects.md │ ├── DriverDialects.md │ ├── FailoverConfigurationGuide.md │ ├── HostAvailabilityStrategy.md │ ├── ReaderSelectionStrategies.md │ ├── SessionState.md │ ├── SupportForRDSMultiAzDBCluster.md │ ├── Telemetry.md │ ├── UsingTheNodejsWrapper.md │ ├── custom-configuration │ └── AwsCredentialsConfiguration.md │ └── using-plugins │ ├── UsingTheAuroraConnectionTrackerPlugin.md │ ├── UsingTheAuroraInitialConnectionStrategyPlugin.md │ ├── UsingTheAwsSecretsManagerPlugin.md │ ├── UsingTheCustomEndpointPlugin.md │ ├── UsingTheDeveloperPlugin.md │ ├── UsingTheFailover2Plugin.md │ ├── UsingTheFailoverPlugin.md │ ├── UsingTheFastestResponseStrategyPlugin.md │ ├── UsingTheFederatedAuthPlugin.md │ ├── UsingTheHostMonitoringPlugin.md │ ├── UsingTheIamAuthenticationPlugin.md │ ├── UsingTheLimitlessConnectionPlugin.md │ ├── UsingTheOktaAuthPlugin.md │ └── UsingTheReadWriteSplittingPlugin.md ├── eslint.config.js ├── examples ├── aws_driver_example │ ├── README.md │ ├── aws_adfs_mysql_example.ts │ ├── aws_adfs_postgresql_example.ts │ ├── aws_dev_mysql_example.ts │ ├── aws_dev_postgresql_example.ts │ ├── aws_failover_mysql_example.ts │ ├── aws_failover_postgresql_example.ts │ ├── aws_iam_authentication_mysql_example.ts │ ├── aws_iam_authentication_postgresql_example.ts │ ├── aws_internal_connection_pool_password_warning_mysql_example.ts │ ├── aws_internal_connection_pool_password_warning_postgres_example.ts │ ├── aws_internal_connection_pooling_mysql_example.ts │ ├── aws_internal_connection_pooling_postgres_example.ts │ ├── aws_limitless_postgresql_example.ts │ ├── aws_okta_mysql_example.ts │ ├── aws_okta_postgresql_example.ts │ ├── aws_read_write_splitting_mysql_example.ts │ ├── aws_read_write_splitting_postgresql_example.ts │ ├── aws_secrets_manager_mysql_example.ts │ ├── aws_secrets_manager_postgresql_example.ts │ ├── aws_simple_connection_mysql_example.ts │ ├── aws_simple_connection_postgresql_example.ts │ ├── fastest_response_strategy_mysql_example.ts │ ├── fastest_response_strategy_postgres_example.ts │ ├── telemetry_metrics_otlp_example.ts │ └── telemetry_tracing_xray_example.ts └── prisma_example │ ├── README.md │ ├── adapter │ ├── conversion.ts │ ├── index.ts │ └── pgaws.ts │ ├── package.json │ ├── prisma │ └── schema.prisma │ └── src │ └── index.ts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jest.integration.config.json ├── jest.unit.config.json ├── mysql └── lib │ ├── client.ts │ ├── dialect │ ├── aurora_mysql_database_dialect.ts │ ├── mysql2_driver_dialect.ts │ ├── mysql_database_dialect.ts │ ├── rds_multi_az_mysql_database_dialect.ts │ └── rds_mysql_database_dialect.ts │ ├── index.ts │ ├── mysql_connection_url_parser.ts │ ├── mysql_error_handler.ts │ └── mysql_pool_client.ts ├── package-lock.json ├── package.json ├── pg └── lib │ ├── abstract_pg_error_handler.ts │ ├── client.ts │ ├── dialect │ ├── aurora_pg_database_dialect.ts │ ├── node_postgres_driver_dialect.ts │ ├── pg_database_dialect.ts │ ├── rds_multi_az_pg_database_dialect.ts │ └── rds_pg_database_dialect.ts │ ├── index.ts │ ├── multi_az_pg_error_handler.ts │ ├── pg_connection_url_parser.ts │ ├── pg_error_handler.ts │ └── pg_pool_client.ts ├── settings.gradle.kts ├── tests ├── integration │ ├── container │ │ └── tests │ │ │ ├── aurora_failover.test.ts │ │ │ ├── aurora_failover2.test.ts │ │ │ ├── autoscaling.test.ts │ │ │ ├── basic_connectivity.test.ts │ │ │ ├── config.ts │ │ │ ├── connect_execute_time_plugin.test.ts │ │ │ ├── custom_endpoint.test.ts │ │ │ ├── dev_plugin.test.ts │ │ │ ├── fastest_response_strategy.test.ts │ │ │ ├── iam_authentication.test.ts │ │ │ ├── initial_connection_strategy.test.ts │ │ │ ├── performance.test.ts │ │ │ ├── read_write_splitting.test.ts │ │ │ ├── read_write_splitting_performance.test.ts │ │ │ ├── secrets_manager.test.ts │ │ │ ├── session_state.test.ts │ │ │ ├── setup.ts │ │ │ └── utils │ │ │ ├── aurora_test_utility.ts │ │ │ ├── database_engine.ts │ │ │ ├── database_engine_deployment.ts │ │ │ ├── database_instances.ts │ │ │ ├── driver_helper.ts │ │ │ ├── perf_stat.ts │ │ │ ├── perf_util.ts │ │ │ ├── proxy_helper.ts │ │ │ ├── proxy_info.ts │ │ │ ├── test_database_info.ts │ │ │ ├── test_driver.ts │ │ │ ├── test_environment.ts │ │ │ ├── test_environment_features.ts │ │ │ ├── test_environment_info.ts │ │ │ ├── test_environment_request.ts │ │ │ ├── test_instance_info.ts │ │ │ ├── test_proxy_database_info.ts │ │ │ └── test_telemetry_info.ts │ └── host │ │ ├── build.gradle.kts │ │ └── src │ │ └── test │ │ ├── config │ │ └── standard-mysql-grant-root.sql │ │ ├── java │ │ └── integration │ │ │ └── host │ │ │ ├── DatabaseEngine.java │ │ │ ├── DatabaseEngineDeployment.java │ │ │ ├── DatabaseInstances.java │ │ │ ├── DriverHelper.java │ │ │ ├── GenericTypedParameterResolver.java │ │ │ ├── TestDatabaseInfo.java │ │ │ ├── TestDriver.java │ │ │ ├── TestEnvironment.java │ │ │ ├── TestEnvironmentConfig.java │ │ │ ├── TestEnvironmentFeatures.java │ │ │ ├── TestEnvironmentInfo.java │ │ │ ├── TestEnvironmentProvider.java │ │ │ ├── TestEnvironmentRequest.java │ │ │ ├── TestInstanceInfo.java │ │ │ ├── TestProxyDatabaseInfo.java │ │ │ ├── TestRunner.java │ │ │ ├── TestTelemetryInfo.java │ │ │ └── util │ │ │ ├── AuroraTestUtility.java │ │ │ ├── ConsoleConsumer.java │ │ │ ├── ContainerHelper.java │ │ │ └── StringUtils.java │ │ └── resources │ │ ├── global-bundle.pem │ │ ├── otel-config.yaml │ │ └── rds-ca-2019-root.pem ├── plugin_benchmarks.ts ├── plugin_manager_benchmarks.ts ├── plugin_manager_telemetry_benchmarks.ts ├── plugin_telemetry_benchmarks.ts ├── testplugin │ ├── benchmark_plugin.ts │ ├── benchmark_plugin_factory.ts │ └── test_connection_wrapper.ts └── unit │ ├── adfs_credentials_provider.test.ts │ ├── aurora_connection_tracker.test.ts │ ├── aurora_initial_connection_strategy_plugin.test.ts │ ├── aws_client_get_plugin_instance.test.ts │ ├── aws_secrets_manager_plugin.test.ts │ ├── connection_plugin_chain_builder.test.ts │ ├── connection_url_parser.test.ts │ ├── custom_endpoint_monitor_impl.test.ts │ ├── custom_endpoint_plugin.test.ts │ ├── database_dialect.test.ts │ ├── dev_plugin.test.ts │ ├── driver_dialect.test.ts │ ├── execute_time_plugin.test.ts │ ├── exponential_backoff_host_availability_strategy.test.ts │ ├── failover2_plugin.test.ts │ ├── failover_plugin.test.ts │ ├── federated_auth_plugin.test.ts │ ├── host_availability_strategy_factory.test.ts │ ├── host_info.test.ts │ ├── host_info_builder.test.ts │ ├── host_monitoring_plugin.test.ts │ ├── iam_authentication_plugin.test.ts │ ├── internal_pool_connection_provider.test.ts │ ├── map_utils.test.ts │ ├── monitor_connection_context.test.ts │ ├── monitor_impl.test.ts │ ├── monitor_service_impl.test.ts │ ├── notification_pipeline.test.ts │ ├── okta_auth_plugin.test.ts │ ├── okta_credentials_provider.test.ts │ ├── plugin_service.test.ts │ ├── random_host_selector.test.ts │ ├── rds_host_list_provider.test.ts │ ├── rds_utils.test.ts │ ├── read_write_splitting.test.ts │ ├── reader_failover_handler.test.ts │ ├── resources │ ├── federated_auth │ │ ├── adfs-saml.html │ │ ├── adfs-sign-in-page.html │ │ └── saml-assertion.txt │ └── okta │ │ ├── expected-assertion.txt │ │ ├── expected-session-token.txt │ │ ├── saml-assertion.html │ │ └── session-token.json │ ├── round_robin_host_selector.test.ts │ ├── session_state_service_impl.test.ts │ ├── sliding_expiration_cache.test.ts │ ├── sql_method_utils.test.ts │ ├── stale_dns_helper.test.ts │ └── writer_failover_handler.test.ts └── tsconfig.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | ["babel-plugin-transform-rewrite-imports", { 4 | "appendExtension": ".js" 5 | }] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # For all files (*), aws/atlas-dev-support is required as reviewer 2 | * @aws/atlas-aws-nodejs-wrapper -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yml: -------------------------------------------------------------------------------- 1 | name: "\U0001F4D5 Documentation Issue" 2 | description: Report an issue in the README.md 3 | title: "(short issue description)" 4 | labels: [documentation, needs-triage] 5 | assignees: [] 6 | body: 7 | - type: textarea 8 | id: description 9 | attributes: 10 | label: Describe the issue 11 | description: A clear and concise description of the issue. 12 | validations: 13 | required: true 14 | 15 | - type: textarea 16 | id: links 17 | attributes: 18 | label: Links 19 | description: | 20 | Include links to affected documentation page(s). 21 | validations: 22 | required: true 23 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Summary 2 | 3 | 4 | 5 | ### Description 6 | 7 | 8 | 9 | ### By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 10 | -------------------------------------------------------------------------------- /.github/workflows/dependabot_auto_merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot Automerge 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - "main" 7 | 8 | permissions: 9 | contents: write 10 | pull-requests: write 11 | 12 | jobs: 13 | dependabot-automerge: 14 | runs-on: ubuntu-latest 15 | if: github.actor == 'dependabot[bot]' 16 | 17 | steps: 18 | - name: Dependabot metadata 19 | id: metadata 20 | uses: dependabot/fetch-metadata@v1 21 | with: 22 | github-token: "${{ secrets.GITHUB_TOKEN }}" 23 | - name: Approve PR 24 | if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' 25 | run: gh pr review --approve "$PR_URL" 26 | env: 27 | PR_URL: ${{github.event.pull_request.html_url}} 28 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 29 | - name: Enable PR auto-merge 30 | if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' 31 | run: gh pr merge --auto --squash "$PR_URL" 32 | env: 33 | PR_URL: ${{github.event.pull_request.html_url}} 34 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 35 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Linting and Unit Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - "*" 10 | 11 | jobs: 12 | run-checks-and-unit-tests: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Node.js 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: "20.x" 20 | - name: Install dependencies 21 | run: npm install --no-save 22 | - name: Run eslint - linting 23 | run: npm run lint 24 | - name: Check formatting 25 | run: npm run check 26 | - name: Run unit tests 27 | run: npm test 28 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release AWS Advanced NodeJS Wrapper 2 | on: 3 | release: 4 | types: published 5 | 6 | jobs: 7 | release: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | contents: read 11 | packages: write 12 | steps: 13 | - name: "Clone Repository" 14 | uses: actions/checkout@v4 15 | - name: "Set up Node.js" 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: "20.x" 19 | registry-url: "https://registry.npmjs.org" 20 | - name: "Install dependencies" 21 | run: npm install --no-save 22 | - name: "Run eslint - linting" 23 | run: npm run lint 24 | - name: "Check formatting" 25 | run: npm run check 26 | - name: "Run unit tests" 27 | run: npm test 28 | - run: npm ci 29 | - run: npm publish 30 | env: 31 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 32 | -------------------------------------------------------------------------------- /.github/workflows/release_draft.yml: -------------------------------------------------------------------------------- 1 | name: "Release Draft" 2 | 3 | on: 4 | push: 5 | tags: 6 | - "[0-9]+.[0-9]+.[0-9]+" 7 | 8 | permissions: 9 | actions: write 10 | contents: write 11 | deployments: write 12 | packages: write 13 | pull-requests: write 14 | repository-projects: write 15 | 16 | jobs: 17 | ubuntu-latest-nodejs-wrapper-release-gh-draft: 18 | name: "Build And Release Draft" 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: "Clone Repository" 22 | uses: actions/checkout@v4 23 | - name: "Set up Node.js" 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: "20.x" 27 | - name: "Install dependencies" 28 | run: npm install --no-save 29 | - name: "Run eslint - linting" 30 | run: npm run lint 31 | - name: "Check formatting" 32 | run: npm run check 33 | - name: "Run unit tests" 34 | run: npm test 35 | - name: "Package Wrapper" 36 | run: | 37 | mkdir -p ./build 38 | npm run prepublish 39 | - name: "Set Version Env Variable" 40 | run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV 41 | - name: "Get Release Details" 42 | run: | 43 | export RELEASE_DETAILS="$(awk -vN=2 'n RELEASE_DETAILS.md 48 | - name: "Upload to Draft Release" 49 | uses: ncipollo/release-action@v1 50 | with: 51 | draft: true 52 | name: "AWS Advanced NodeJS Wrapper - v${{ env.RELEASE_VERSION }}" 53 | bodyFile: RELEASE_DETAILS.md 54 | artifacts: ./build/* 55 | token: ${{ secrets.GITHUB_TOKEN }} 56 | -------------------------------------------------------------------------------- /.github/workflows/remove-old-artifacts.yml: -------------------------------------------------------------------------------- 1 | name: Remove Old Artifacts 2 | 3 | on: 4 | schedule: 5 | # Every day at 1am 6 | - cron: "0 1 * * *" 7 | 8 | jobs: 9 | remove-old-artifacts: 10 | runs-on: ubuntu-latest 11 | timeout-minutes: 10 12 | 13 | steps: 14 | - name: Remove Old Artifacts 15 | uses: c-hive/gha-remove-artifacts@v1 16 | with: 17 | age: "1 week" 18 | skip-tags: true 19 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | gradle 2 | dist 3 | coverage 4 | build 5 | .babelrc 6 | .github 7 | 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "trailingComma": "none", 4 | "printWidth": 150, 5 | "endOfLine": "lf" 6 | } 7 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 4 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 5 | opensource-codeofconduct@amazon.com with any additional questions or comments. 6 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /build/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/build/.gitkeep -------------------------------------------------------------------------------- /common/lib/AllowedAndBlockedHosts.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class AllowedAndBlockedHosts { 18 | private readonly allowedHostIds: Set; 19 | private readonly blockedHostIds: Set; 20 | 21 | constructor(allowedHostIds: Set, blockedHostIds: Set) { 22 | this.allowedHostIds = allowedHostIds; 23 | this.blockedHostIds = blockedHostIds; 24 | } 25 | 26 | getAllowedHostIds() { 27 | return this.allowedHostIds; 28 | } 29 | 30 | getBlockedHostIds() { 31 | return this.blockedHostIds; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common/lib/authentication/aws_secrets_manager_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../plugin_factory"; 18 | import { PluginService } from "../plugin_service"; 19 | import { ConnectionPlugin } from "../connection_plugin"; 20 | import { AwsWrapperError } from "../utils/errors"; 21 | import { Messages } from "../utils/messages"; 22 | 23 | export class AwsSecretsManagerPluginFactory extends ConnectionPluginFactory { 24 | private static awsSecretsManagerPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!AwsSecretsManagerPluginFactory.awsSecretsManagerPlugin) { 29 | AwsSecretsManagerPluginFactory.awsSecretsManagerPlugin = await import("./aws_secrets_manager_plugin"); 30 | } 31 | return new AwsSecretsManagerPluginFactory.awsSecretsManagerPlugin.AwsSecretsManagerPlugin(pluginService, new Map(properties)); 32 | } catch (error: any) { 33 | if (error.code === "MODULE_NOT_FOUND") { 34 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "AwsSecretsManagerPlugin")); 35 | } 36 | throw error; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/lib/authentication/iam_authentication_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../plugin_factory"; 18 | import { PluginService } from "../plugin_service"; 19 | import { ConnectionPlugin } from "../connection_plugin"; 20 | import { AwsWrapperError } from "../utils/errors"; 21 | import { Messages } from "../utils/messages"; 22 | 23 | export class IamAuthenticationPluginFactory extends ConnectionPluginFactory { 24 | private static iamAuthenticationPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: object): Promise { 27 | try { 28 | if (!IamAuthenticationPluginFactory.iamAuthenticationPlugin) { 29 | IamAuthenticationPluginFactory.iamAuthenticationPlugin = await import("./iam_authentication_plugin"); 30 | } 31 | return new IamAuthenticationPluginFactory.iamAuthenticationPlugin.IamAuthenticationPlugin(pluginService); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "IamAuthenticationPlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/aws_pool_client.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface AwsPoolClient { 18 | connect(): Promise; 19 | 20 | end(): Promise; 21 | 22 | releaseResources(): Promise; 23 | 24 | getIdleCount(): number; 25 | 26 | getTotalCount(): number; 27 | 28 | getActiveCount(): number; 29 | } 30 | -------------------------------------------------------------------------------- /common/lib/aws_pool_config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class AwsPoolConfig { 18 | readonly maxConnections?: number | undefined; 19 | readonly idleTimeoutMillis?: number | undefined; 20 | 21 | /** 22 | * Only applicable for MySQL. 23 | */ 24 | readonly waitForConnections?: boolean | undefined; 25 | readonly queueLimit?: number | undefined; 26 | readonly maxIdleConnections?: number | undefined; 27 | 28 | /** 29 | * Only applicable for Postgres. 30 | */ 31 | readonly minConnections?: number | undefined; 32 | readonly allowExitOnIdle?: boolean | undefined; 33 | 34 | constructor(props?: any) { 35 | this.maxConnections = props.maxConnections ?? 10; 36 | this.idleTimeoutMillis = props.idleTimeoutMillis ?? 60000; 37 | this.maxIdleConnections = props.maxIdleConnections ?? this.maxConnections; 38 | this.waitForConnections = props.waitForConnections ?? true; 39 | this.queueLimit = props.queueLimit ?? 0; 40 | this.minConnections = props.minConnections ?? 0; 41 | this.allowExitOnIdle = props.allowExitOnIdle ?? false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/lib/can_release_resources.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface CanReleaseResources { 18 | releaseResources(): Promise; 19 | } 20 | -------------------------------------------------------------------------------- /common/lib/client_wrapper.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "./host_info"; 18 | 19 | export interface ClientWrapper { 20 | readonly client: any; 21 | readonly hostInfo: HostInfo; 22 | readonly properties: Map; 23 | readonly id: string; 24 | 25 | query(sql: string): Promise; 26 | 27 | end(): Promise; 28 | 29 | rollback(): Promise; 30 | 31 | abort(): Promise; 32 | 33 | queryWithTimeout(sql: string): Promise; 34 | } 35 | -------------------------------------------------------------------------------- /common/lib/connection_provider.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostRole } from "./host_role"; 18 | import { HostInfo } from "./host_info"; 19 | import { PluginService } from "./plugin_service"; 20 | import { ClientWrapper } from "./client_wrapper"; 21 | 22 | export interface ConnectionProvider { 23 | connect(hostInfo: HostInfo, pluginService: PluginService, props: Map): Promise; 24 | acceptsUrl(hostInfo: HostInfo, props: Map): boolean; 25 | acceptsStrategy(role: HostRole, strategy: string): boolean; 26 | getHostInfoByStrategy(hosts: HostInfo[], role: HostRole, strategy: string, props?: Map): HostInfo; 27 | } 28 | -------------------------------------------------------------------------------- /common/lib/database_dialect/database_dialect_codes.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class DatabaseDialectCodes { 18 | static readonly AURORA_MYSQL: string = "aurora-mysql"; 19 | static readonly RDS_MYSQL: string = "rds-mysql"; 20 | static readonly MYSQL: string = "mysql"; 21 | // https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/multi-az-db-clusters-concepts.html 22 | static readonly RDS_MULTI_AZ_MYSQL: string = "rds-multi-az-mysql"; 23 | static readonly AURORA_PG: string = "aurora-pg"; 24 | static readonly RDS_PG: string = "rds-pg"; 25 | // https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/multi-az-db-clusters-concepts.html 26 | static readonly RDS_MULTI_AZ_PG: string = "rds-multi-az-pg"; 27 | static readonly PG: string = "pg"; 28 | static readonly CUSTOM: string = "custom"; 29 | } 30 | -------------------------------------------------------------------------------- /common/lib/database_dialect/database_dialect_provider.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { DatabaseDialect } from "./database_dialect"; 18 | import { ClientWrapper } from "../client_wrapper"; 19 | 20 | export interface DatabaseDialectProvider { 21 | getDialect(props: Map): DatabaseDialect; 22 | getDialectForUpdate(targetClient: ClientWrapper, originalHost: string, newHost: string): Promise; 23 | } 24 | -------------------------------------------------------------------------------- /common/lib/database_dialect/limitless_database_dialect.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface LimitlessDatabaseDialect { 18 | getLimitlessRoutersQuery(): string; 19 | } 20 | -------------------------------------------------------------------------------- /common/lib/driver_dialect/driver_dialect.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ClientWrapper } from "../client_wrapper"; 18 | import { AwsPoolConfig } from "../aws_pool_config"; 19 | import { AwsPoolClient } from "../aws_pool_client"; 20 | import { HostInfo } from "../host_info"; 21 | 22 | export interface DriverDialect { 23 | getDialectName(): string; 24 | 25 | connect(hostInfo: HostInfo, props: Map): Promise; 26 | 27 | preparePoolClientProperties(props: Map, poolConfig: AwsPoolConfig | undefined): any; 28 | 29 | getAwsPoolClient(props: any): AwsPoolClient; 30 | 31 | setConnectTimeout(props: Map, wrapperConnectTimeout?: any): void; 32 | 33 | setQueryTimeout(props: Map, sql?: any, wrapperConnectTimeout?: any): void; 34 | 35 | setKeepAliveProperties(props: Map, keepAliveProps: any): void; 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/error_handler.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ClientWrapper } from "./client_wrapper"; 18 | 19 | export interface ErrorHandler { 20 | isLoginError(e: Error): boolean; 21 | 22 | isNetworkError(e: Error): boolean; 23 | 24 | /** 25 | * Checks whether there has been an unexpected error emitted and if the error is a type of login error. 26 | */ 27 | hasLoginError(): boolean; 28 | 29 | /** 30 | * Checks whether there has been an unexpected error emitted and if the error is a type of network error. 31 | */ 32 | hasNetworkError(): boolean; 33 | 34 | getUnexpectedError(): Error | null; 35 | 36 | /** 37 | * Attach an error event listener to the event emitter object in the ClientWrapper. 38 | * The listener will track the latest error emitted to be handled in the future. 39 | * @param clientWrapper a wrapper containing the target community client. 40 | */ 41 | attachErrorListener(clientWrapper: ClientWrapper | undefined): void; 42 | 43 | /** 44 | * Attach a No-Op error listener that ignores any error emitted. 45 | * @param clientWrapper a wrapper containing the target community client. 46 | */ 47 | attachNoOpErrorListener(clientWrapper: ClientWrapper | undefined): void; 48 | } 49 | -------------------------------------------------------------------------------- /common/lib/highest_weight_host_selector.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostSelector } from "./host_selector"; 18 | import { HostInfo } from "./host_info"; 19 | import { HostRole } from "./host_role"; 20 | import { AwsWrapperError } from "./utils/errors"; 21 | import { HostAvailability } from "./host_availability/host_availability"; 22 | import { Messages } from "./utils/messages"; 23 | 24 | export class HighestWeightHostSelector implements HostSelector { 25 | static STRATEGY_NAME = "highestWeight"; 26 | 27 | getHost(hosts: HostInfo[], role: HostRole, props?: Map): HostInfo { 28 | const eligibleHosts: HostInfo[] = hosts 29 | .filter((host: HostInfo) => host.role === role && host.availability === HostAvailability.AVAILABLE) 30 | .sort((hostA: HostInfo, hostB: HostInfo) => (hostA.weight > hostB.weight ? -1 : hostA.weight < hostB.weight ? 1 : 0)); 31 | 32 | if (eligibleHosts.length === 0) { 33 | throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role)); 34 | } 35 | 36 | return eligibleHosts[0]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/lib/host_availability/host_availability.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum HostAvailability { 18 | AVAILABLE, 19 | NOT_AVAILABLE 20 | } 21 | -------------------------------------------------------------------------------- /common/lib/host_availability/host_availability_strategy.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostAvailability } from "./host_availability"; 18 | 19 | export interface HostAvailabilityStrategy { 20 | setHostAvailability(hostAvailability: HostAvailability): void; 21 | getHostAvailability(rawHostAvailability: HostAvailability): HostAvailability; 22 | } 23 | -------------------------------------------------------------------------------- /common/lib/host_availability/host_availability_strategy_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostAvailabilityStrategy } from "./host_availability_strategy"; 18 | import { WrapperProperties } from "../wrapper_property"; 19 | import { SimpleHostAvailabilityStrategy } from "./simple_host_availability_strategy"; 20 | import { ExponentialBackoffHostAvailabilityStrategy } from "./exponential_backoff_host_availability_strategy"; 21 | 22 | export class HostAvailabilityStrategyFactory { 23 | public create(props: Map): HostAvailabilityStrategy { 24 | const defaultStrategy = WrapperProperties.DEFAULT_HOST_AVAILABILITY_STRATEGY.get(props); 25 | const exponentialName = ExponentialBackoffHostAvailabilityStrategy.NAME; 26 | 27 | if (props.size === 0 || !defaultStrategy) { 28 | return new SimpleHostAvailabilityStrategy(); 29 | } else if (exponentialName.toUpperCase() === defaultStrategy.toUpperCase()) { 30 | return new ExponentialBackoffHostAvailabilityStrategy(props); 31 | } 32 | return new SimpleHostAvailabilityStrategy(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /common/lib/host_availability/simple_host_availability_strategy.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostAvailabilityStrategy } from "./host_availability_strategy"; 18 | import { HostAvailability } from "./host_availability"; 19 | 20 | export class SimpleHostAvailabilityStrategy implements HostAvailabilityStrategy { 21 | getHostAvailability(rawHostAvailability: HostAvailability): HostAvailability { 22 | return rawHostAvailability; 23 | } 24 | 25 | setHostAvailability(hostAvailability: HostAvailability): void { 26 | // do nothing 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /common/lib/host_change_options.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum HostChangeOptions { 18 | HOSTNAME, 19 | PROMOTED_TO_WRITER, 20 | PROMOTED_TO_READER, 21 | WENT_UP, 22 | WENT_DOWN, 23 | CONNECTION_OBJECT_CHANGED, 24 | INITIAL_CONNECTION, 25 | HOST_ADDED, 26 | HOST_CHANGED, 27 | HOST_DELETED 28 | } 29 | -------------------------------------------------------------------------------- /common/lib/host_list_provider/host_list_provider.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "../host_info"; 18 | import { HostRole } from "../host_role"; 19 | import { DatabaseDialect } from "../database_dialect/database_dialect"; 20 | import { ClientWrapper } from "../client_wrapper"; 21 | 22 | export type DynamicHostListProvider = HostListProvider; 23 | 24 | export type StaticHostListProvider = HostListProvider; 25 | 26 | export interface BlockingHostListProvider extends HostListProvider { 27 | forceMonitoringRefresh(shouldVerifyWriter: boolean, timeoutMs: number): Promise; 28 | 29 | clearAll(): Promise; 30 | } 31 | 32 | export interface HostListProvider { 33 | refresh(): Promise; 34 | 35 | refresh(client: ClientWrapper): Promise; 36 | 37 | forceRefresh(): Promise; 38 | 39 | forceRefresh(client: ClientWrapper): Promise; 40 | 41 | getHostRole(client: ClientWrapper, dialect: DatabaseDialect): Promise; 42 | 43 | identifyConnection(targetClient: ClientWrapper, dialect: DatabaseDialect): Promise; 44 | 45 | createHost(host: string, isWriter: boolean, weight: number, lastUpdateTime: number, port?: number): HostInfo; 46 | 47 | getHostProviderType(): string; 48 | 49 | getClusterId(): string; 50 | } 51 | -------------------------------------------------------------------------------- /common/lib/host_role.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum HostRole { 18 | UNKNOWN = "unknown", 19 | WRITER = "writer", 20 | READER = "reader" 21 | } 22 | -------------------------------------------------------------------------------- /common/lib/host_selector.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "./host_info"; 18 | import { HostRole } from "./host_role"; 19 | 20 | export interface HostSelector { 21 | getHost(hosts: HostInfo[], role: HostRole, props?: Map): HostInfo; 22 | } 23 | -------------------------------------------------------------------------------- /common/lib/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export * from "./connection_plugin"; 18 | export * from "./plugin_manager"; 19 | -------------------------------------------------------------------------------- /common/lib/old_connection_suggestion_action.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum OldConnectionSuggestionAction { 18 | NO_OPINION, // no strong suggestion about connection object 19 | DISPOSE, // suggestion to dispose a connection object; it may be overridden by "PRESERVE" 20 | PRESERVE // overrides any other opinions; the strongest suggestion 21 | } 22 | -------------------------------------------------------------------------------- /common/lib/plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { PluginService } from "./plugin_service"; 18 | import { ConnectionPlugin } from "./connection_plugin"; 19 | 20 | export class ConnectionPluginFactory { 21 | getInstance(pluginService: PluginService, properties: Map): Promise { 22 | return; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /common/lib/plugin_service_manager_container.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { PluginService } from "./plugin_service"; 18 | import { PluginManager } from "./plugin_manager"; 19 | 20 | export class PluginServiceManagerContainer { 21 | private _pluginService?: PluginService | null; 22 | private _pluginManager?: PluginManager | null; 23 | 24 | get pluginService(): PluginService | null { 25 | return this._pluginService ?? null; 26 | } 27 | 28 | set pluginService(service: PluginService | null) { 29 | this._pluginService = service; 30 | } 31 | 32 | get pluginManager(): PluginManager | null { 33 | return this._pluginManager ?? null; 34 | } 35 | 36 | set pluginManager(service: PluginManager | null) { 37 | this._pluginManager = service; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/lib/plugins/aurora_initial_connection_strategy_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../plugin_factory"; 18 | import { PluginService } from "../plugin_service"; 19 | import { AwsWrapperError } from "../utils/errors"; 20 | import { Messages } from "../utils/messages"; 21 | 22 | export class AuroraInitialConnectionStrategyFactory extends ConnectionPluginFactory { 23 | private static auroraInitialConnectionStrategyPlugin: any; 24 | 25 | async getInstance(pluginService: PluginService, props: Map) { 26 | try { 27 | if (!AuroraInitialConnectionStrategyFactory.auroraInitialConnectionStrategyPlugin) { 28 | AuroraInitialConnectionStrategyFactory.auroraInitialConnectionStrategyPlugin = await import("./aurora_initial_connection_strategy_plugin"); 29 | } 30 | return new AuroraInitialConnectionStrategyFactory.auroraInitialConnectionStrategyPlugin.AuroraInitialConnectionStrategyPlugin(pluginService); 31 | } catch (error: any) { 32 | throw new AwsWrapperError( 33 | Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "AuroraInitialConnectionStrategyPlugin") 34 | ); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/plugins/connect_time_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../plugin_factory"; 18 | import { PluginService } from "../plugin_service"; 19 | import { ConnectionPlugin } from "../connection_plugin"; 20 | import { AwsWrapperError } from "../utils/errors"; 21 | import { Messages } from "../utils/messages"; 22 | 23 | export class ConnectTimePluginFactory extends ConnectionPluginFactory { 24 | private static connectTimePlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!ConnectTimePluginFactory.connectTimePlugin) { 29 | ConnectTimePluginFactory.connectTimePlugin = await import("./connect_time_plugin"); 30 | } 31 | return new ConnectTimePluginFactory.connectTimePlugin.ConnectTimePlugin(); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "ConnectTimePlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/connection_tracker/aurora_connection_tracker_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { AwsWrapperError } from "../../utils/errors"; 21 | import { Messages } from "../../utils/messages"; 22 | 23 | export class AuroraConnectionTrackerPluginFactory extends ConnectionPluginFactory { 24 | private static auroraConnectionTrackerPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, props: Map): Promise { 27 | try { 28 | if (!AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin) { 29 | AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin = await import("./aurora_connection_tracker_plugin"); 30 | } 31 | return new AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin.AuroraConnectionTrackerPlugin(pluginService); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "AuroraConnectionTrackerPlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/custom_endpoint/custom_endpoint_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { AwsWrapperError } from "../../utils/errors"; 20 | import { Messages } from "../../utils/messages"; 21 | 22 | export class CustomEndpointPluginFactory extends ConnectionPluginFactory { 23 | private static customEndpointPlugin: any; 24 | 25 | async getInstance(pluginService: PluginService, props: Map) { 26 | try { 27 | if (!CustomEndpointPluginFactory.customEndpointPlugin) { 28 | CustomEndpointPluginFactory.customEndpointPlugin = await import("./custom_endpoint_plugin"); 29 | } 30 | return new CustomEndpointPluginFactory.customEndpointPlugin.CustomEndpointPlugin(pluginService, props); 31 | } catch (error: any) { 32 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "CustomEndpointPlugin")); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /common/lib/plugins/custom_endpoint/custom_endpoint_role_type.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum CustomEndpointRoleType { 18 | ANY, 19 | WRITER, 20 | READER 21 | } 22 | 23 | const nameToValue = new Map([ 24 | ["ANY", CustomEndpointRoleType.ANY], 25 | ["WRITER", CustomEndpointRoleType.WRITER], 26 | ["READER", CustomEndpointRoleType.READER] 27 | ]); 28 | 29 | export function customEndpointRoleTypeFromValue(name: string): CustomEndpointRoleType { 30 | return nameToValue.get(name.toUpperCase()) ?? CustomEndpointRoleType.ANY; 31 | } 32 | -------------------------------------------------------------------------------- /common/lib/plugins/custom_endpoint/member_list_type.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum MemberListType { 18 | STATIC_LIST, 19 | EXCLUSION_LIST 20 | } 21 | -------------------------------------------------------------------------------- /common/lib/plugins/dev/developer_connection_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { RdsUtils } from "../../utils/rds_utils"; 21 | import { Messages } from "../../utils/messages"; 22 | import { AwsWrapperError } from "../../utils/errors"; 23 | 24 | export class DeveloperConnectionPluginFactory extends ConnectionPluginFactory { 25 | private static developerPlugin: any; 26 | 27 | async getInstance(pluginService: PluginService, properties: Map): Promise { 28 | try { 29 | if (!DeveloperConnectionPluginFactory.developerPlugin) { 30 | DeveloperConnectionPluginFactory.developerPlugin = await import("./developer_connection_plugin"); 31 | } 32 | return new DeveloperConnectionPluginFactory.developerPlugin.DeveloperConnectionPlugin(pluginService, properties, new RdsUtils()); 33 | } catch (error: any) { 34 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "DeveloperConnectionPlugin")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/plugins/dev/error_simulator.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ErrorSimulatorMethodCallback } from "./error_simulator_method_callback"; 18 | 19 | export interface ErrorSimulator { 20 | raiseErrorOnNextCall(throwable: Error, methodName?: string): void; 21 | 22 | setCallback(errorSimulatorMethodCallback: ErrorSimulatorMethodCallback): void; 23 | } 24 | -------------------------------------------------------------------------------- /common/lib/plugins/dev/error_simulator_connect_callback.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "../../host_info"; 18 | 19 | export interface ErrorSimulatorConnectCallback { 20 | getErrorToRaise(hostInfo: HostInfo, props: Map, isInitialConnection: boolean): Error | null; 21 | } 22 | -------------------------------------------------------------------------------- /common/lib/plugins/dev/error_simulator_manager.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ErrorSimulatorConnectCallback } from "./error_simulator_connect_callback"; 18 | 19 | export class ErrorSimulatorManager { 20 | static nextError: Error | null = null; 21 | static connectCallback: ErrorSimulatorConnectCallback | null = null; 22 | 23 | static raiseErrorOnNextConnect(throwable: Error): void { 24 | ErrorSimulatorManager.nextError = throwable; 25 | } 26 | 27 | static setCallback(errorSimulatorConnectCallback: ErrorSimulatorConnectCallback): void { 28 | ErrorSimulatorManager.connectCallback = errorSimulatorConnectCallback; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common/lib/plugins/dev/error_simulator_method_callback.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface ErrorSimulatorMethodCallback { 18 | getErrorToRaise(methodName: string, methodArgs: any): Error | null; 19 | } 20 | -------------------------------------------------------------------------------- /common/lib/plugins/efm/host_monitoring_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { RdsUtils } from "../../utils/rds_utils"; 21 | import { AwsWrapperError } from "../../utils/errors"; 22 | import { Messages } from "../../utils/messages"; 23 | 24 | export class HostMonitoringPluginFactory extends ConnectionPluginFactory { 25 | private static hostMonitoringPlugin: any; 26 | 27 | async getInstance(pluginService: PluginService, properties: Map): Promise { 28 | try { 29 | if (!HostMonitoringPluginFactory.hostMonitoringPlugin) { 30 | HostMonitoringPluginFactory.hostMonitoringPlugin = await import("./host_monitoring_connection_plugin"); 31 | } 32 | return new HostMonitoringPluginFactory.hostMonitoringPlugin.HostMonitoringConnectionPlugin(pluginService, properties, new RdsUtils()); 33 | } catch (error: any) { 34 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "HostMonitoringPlugin")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/plugins/efm2/host_monitoring2_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { RdsUtils } from "../../utils/rds_utils"; 21 | import { AwsWrapperError } from "../../utils/errors"; 22 | import { Messages } from "../../utils/messages"; 23 | 24 | export class HostMonitoring2PluginFactory extends ConnectionPluginFactory { 25 | private static hostMonitoring2Plugin: any; 26 | 27 | async getInstance(pluginService: PluginService, properties: Map): Promise { 28 | try { 29 | if (!HostMonitoring2PluginFactory.hostMonitoring2Plugin) { 30 | HostMonitoring2PluginFactory.hostMonitoring2Plugin = await import("./host_monitoring2_connection_plugin"); 31 | } 32 | return new HostMonitoring2PluginFactory.hostMonitoring2Plugin.HostMonitoring2ConnectionPlugin(pluginService, properties, new RdsUtils()); 33 | } catch (error: any) { 34 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "HostMonitoringPlugin")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/plugins/efm2/monitor_connection_context.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { uniqueId } from "../../../logutils"; 18 | import { ClientWrapper } from "../../client_wrapper"; 19 | 20 | /** 21 | * Monitoring context for each connection. This contains each connection's criteria for whether a 22 | * server should be considered unhealthy. The context is shared between the main task and the monitor task. 23 | */ 24 | export class MonitorConnectionContext { 25 | private clientToAbortRef: WeakRef | undefined; 26 | isHostUnhealthy: boolean = false; 27 | id: string = uniqueId("_monitorContext"); 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param clientToAbort A reference to the connection associated with this context that will be aborted. 33 | */ 34 | constructor(clientToAbort: ClientWrapper) { 35 | if (clientToAbort) { 36 | this.clientToAbortRef = new WeakRef(clientToAbort); 37 | } 38 | } 39 | 40 | setHostUnhealthy(hostUnhealthy: boolean) { 41 | this.isHostUnhealthy = hostUnhealthy; 42 | } 43 | 44 | shouldAbort(): boolean { 45 | return this.isHostUnhealthy && this.clientToAbortRef != null; 46 | } 47 | 48 | setInactive(): void { 49 | this.clientToAbortRef = null; 50 | } 51 | 52 | getClient(): ClientWrapper | null { 53 | return this.clientToAbortRef?.deref() ?? null; 54 | } 55 | 56 | isActive() { 57 | return !!this.clientToAbortRef?.deref(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /common/lib/plugins/execute_time_plugin.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { logger } from "../../logutils"; 18 | import { AbstractConnectionPlugin } from "../abstract_connection_plugin"; 19 | import { Messages } from "../utils/messages"; 20 | import { getTimeInNanos } from "../utils/utils"; 21 | 22 | export class ExecuteTimePlugin extends AbstractConnectionPlugin { 23 | private static readonly subscribedMethods: Set = new Set(["*"]); 24 | private static executeTime: bigint = 0n; 25 | 26 | public override getSubscribedMethods(): Set { 27 | return ExecuteTimePlugin.subscribedMethods; 28 | } 29 | 30 | public override async execute(methodName: string, methodFunc: () => Promise, methodArgs: any[]): Promise { 31 | const startTime = getTimeInNanos(); 32 | 33 | const result = await methodFunc(); 34 | 35 | const elapsedTimeNanos = getTimeInNanos() - startTime; 36 | 37 | // Convert from ns to ms 38 | logger.debug(Messages.get("ExecuteTimePlugin.executeTime", methodName, (elapsedTimeNanos / 1000000n).toString())); 39 | ExecuteTimePlugin.executeTime += elapsedTimeNanos; 40 | return result; 41 | } 42 | 43 | public static resetExecuteTime(): void { 44 | ExecuteTimePlugin.executeTime = 0n; 45 | } 46 | 47 | public static getTotalExecuteTime(): bigint { 48 | return ExecuteTimePlugin.executeTime; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /common/lib/plugins/execute_time_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../plugin_factory"; 18 | import { PluginService } from "../plugin_service"; 19 | import { ConnectionPlugin } from "../connection_plugin"; 20 | import { AwsWrapperError } from "../utils/errors"; 21 | import { Messages } from "../utils/messages"; 22 | 23 | export class ExecuteTimePluginFactory extends ConnectionPluginFactory { 24 | private static executeTimePlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!ExecuteTimePluginFactory.executeTimePlugin) { 29 | ExecuteTimePluginFactory.executeTimePlugin = await import("./execute_time_plugin"); 30 | } 31 | return new ExecuteTimePluginFactory.executeTimePlugin.ExecuteTimePlugin(); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "ExecuteTimePlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/failover/failover_mode.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum FailoverMode { 18 | STRICT_WRITER, 19 | STRICT_READER, 20 | READER_OR_WRITER, 21 | UNKNOWN 22 | } 23 | 24 | const nameToValue = new Map([ 25 | ["strict-writer", FailoverMode.STRICT_WRITER], 26 | ["strict-reader", FailoverMode.STRICT_READER], 27 | ["reader-or-writer", FailoverMode.READER_OR_WRITER], 28 | ["unknown", FailoverMode.UNKNOWN] 29 | ]); 30 | 31 | export function failoverModeFromValue(name: string): FailoverMode { 32 | return nameToValue.get(name.toLowerCase()) ?? FailoverMode.UNKNOWN; 33 | } 34 | -------------------------------------------------------------------------------- /common/lib/plugins/failover/failover_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { RdsUtils } from "../../utils/rds_utils"; 21 | import { AwsWrapperError } from "../../utils/errors"; 22 | import { Messages } from "../../utils/messages"; 23 | 24 | export class FailoverPluginFactory extends ConnectionPluginFactory { 25 | private static failoverPlugin: any; 26 | 27 | async getInstance(pluginService: PluginService, properties: Map): Promise { 28 | try { 29 | if (!FailoverPluginFactory.failoverPlugin) { 30 | FailoverPluginFactory.failoverPlugin = await import("./failover_plugin"); 31 | } 32 | return new FailoverPluginFactory.failoverPlugin.FailoverPlugin(pluginService, properties, new RdsUtils()); 33 | } catch (error: any) { 34 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "FailoverPlugin")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/plugins/failover/failover_restriction.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum FailoverRestriction { 18 | DISABLE_TASK_A, 19 | ENABLE_WRITER_IN_TASK_B 20 | } 21 | -------------------------------------------------------------------------------- /common/lib/plugins/failover/reader_failover_result.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "../../host_info"; 18 | import { ClientWrapper } from "../../client_wrapper"; 19 | 20 | export class ReaderFailoverResult { 21 | readonly client: ClientWrapper | null; 22 | readonly newHost: HostInfo | null; 23 | readonly isConnected: boolean; 24 | readonly error?: Error; 25 | readonly taskId?: number; 26 | 27 | constructor(client: ClientWrapper | null, newHost: HostInfo | null, isConnected: boolean, error?: Error, taskId?: number) { 28 | this.client = client; 29 | this.newHost = newHost; 30 | this.isConnected = isConnected; 31 | this.error = error; 32 | this.taskId = taskId; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /common/lib/plugins/failover/writer_failover_result.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "../../host_info"; 18 | import { ClientWrapper } from "../../client_wrapper"; 19 | 20 | export class WriterFailoverResult { 21 | readonly isConnected: boolean; 22 | readonly isNewHost: boolean; 23 | readonly topology: HostInfo[]; 24 | readonly client: ClientWrapper | null; 25 | readonly taskName: string; 26 | readonly error: Error | undefined; 27 | 28 | constructor(isConnected: boolean, isNewHost: boolean, topology: HostInfo[], taskName: string, client: ClientWrapper | null, error?: Error) { 29 | this.isConnected = isConnected; 30 | this.isNewHost = isNewHost; 31 | this.topology = topology; 32 | this.client = client; 33 | this.taskName = taskName; 34 | this.error = error; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/failover2/failover2_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { RdsUtils } from "../../utils/rds_utils"; 21 | import { AwsWrapperError } from "../../utils/errors"; 22 | import { Messages } from "../../utils/messages"; 23 | 24 | export class Failover2PluginFactory extends ConnectionPluginFactory { 25 | private static failover2Plugin: any; 26 | 27 | async getInstance(pluginService: PluginService, properties: Map): Promise { 28 | try { 29 | if (!Failover2PluginFactory.failover2Plugin) { 30 | Failover2PluginFactory.failover2Plugin = await import("./failover2_plugin"); 31 | } 32 | return new Failover2PluginFactory.failover2Plugin.Failover2Plugin(pluginService, properties, new RdsUtils()); 33 | } catch (error: any) { 34 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "Failover2Plugin")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/plugins/federated_auth/credentials_provider_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { 18 | AwsCredentialIdentity, 19 | AwsCredentialIdentityProvider 20 | } from "@smithy/types/dist-types/identity/awsCredentialIdentity"; 21 | 22 | export interface CredentialsProviderFactory { 23 | getAwsCredentialsProvider(host: string, region: string, props: Map): Promise; 24 | } 25 | -------------------------------------------------------------------------------- /common/lib/plugins/limitless/limitless_connection_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { AwsWrapperError } from "../../utils/errors"; 21 | import { Messages } from "../../utils/messages"; 22 | 23 | export class LimitlessConnectionPluginFactory implements ConnectionPluginFactory { 24 | private static limitlessPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!LimitlessConnectionPluginFactory.limitlessPlugin) { 29 | LimitlessConnectionPluginFactory.limitlessPlugin = await import("./limitless_connection_plugin"); 30 | } 31 | return new LimitlessConnectionPluginFactory.limitlessPlugin.LimitlessConnectionPlugin(pluginService, properties); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "LimitlessConnectionPlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/limitless/limitless_helper.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { LimitlessDatabaseDialect } from "../../database_dialect/limitless_database_dialect"; 18 | 19 | export class LimitlessHelper { 20 | public static isLimitlessDatabaseDialect(arg: any): arg is LimitlessDatabaseDialect { 21 | return arg.getLimitlessRoutersQuery !== undefined; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /common/lib/plugins/read_write_splitting_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../plugin_factory"; 18 | import { PluginService } from "../plugin_service"; 19 | import { ConnectionPlugin } from "../connection_plugin"; 20 | import { AwsWrapperError } from "../utils/errors"; 21 | import { Messages } from "../utils/messages"; 22 | 23 | export class ReadWriteSplittingPluginFactory extends ConnectionPluginFactory { 24 | private static readWriteSplittingPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!ReadWriteSplittingPluginFactory.readWriteSplittingPlugin) { 29 | ReadWriteSplittingPluginFactory.readWriteSplittingPlugin = await import("./read_write_splitting_plugin"); 30 | } 31 | return new ReadWriteSplittingPluginFactory.readWriteSplittingPlugin.ReadWriteSplittingPlugin(pluginService, properties); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "readWriteSplittingPlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/stale_dns/stale_dns_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../plugin_factory"; 18 | import { PluginService } from "../../plugin_service"; 19 | import { ConnectionPlugin } from "../../connection_plugin"; 20 | import { AwsWrapperError } from "../../utils/errors"; 21 | import { Messages } from "../../utils/messages"; 22 | 23 | export class StaleDnsPluginFactory extends ConnectionPluginFactory { 24 | private static staleDnsPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!StaleDnsPluginFactory.staleDnsPlugin) { 29 | StaleDnsPluginFactory.staleDnsPlugin = await import("./stale_dns_plugin"); 30 | } 31 | return new StaleDnsPluginFactory.staleDnsPlugin.StaleDnsPlugin(pluginService, properties); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "StaleDnsPlugin")); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/plugins/strategy/fastest_response/fastest_respose_strategy_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../../plugin_factory"; 18 | import { PluginService } from "../../../plugin_service"; 19 | import { ConnectionPlugin } from "../../../connection_plugin"; 20 | import { AwsWrapperError } from "../../../utils/errors"; 21 | import { Messages } from "../../../utils/messages"; 22 | 23 | export class FastestResponseStrategyPluginFactory extends ConnectionPluginFactory { 24 | private static fastestResponseStrategyPlugin: any; 25 | 26 | async getInstance(pluginService: PluginService, properties: Map): Promise { 27 | try { 28 | if (!FastestResponseStrategyPluginFactory.fastestResponseStrategyPlugin) { 29 | FastestResponseStrategyPluginFactory.fastestResponseStrategyPlugin = await import("./fastest_response_strategy_plugin"); 30 | } 31 | return new FastestResponseStrategyPluginFactory.fastestResponseStrategyPlugin.FastestResponseStrategyPlugin(pluginService, properties); 32 | } catch (error: any) { 33 | throw new AwsWrapperError( 34 | Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "FastestResponseStrategyPluginFactory") 35 | ); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/lib/pool_client_wrapper.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ClientWrapper } from "./client_wrapper"; 18 | import { HostInfo } from "./host_info"; 19 | import { uniqueId } from "../logutils"; 20 | import { ClientUtils } from "./utils/client_utils"; 21 | import { SessionState } from "./session_state"; 22 | 23 | export class PoolClientWrapper implements ClientWrapper { 24 | readonly client: any; 25 | readonly hostInfo: HostInfo; 26 | readonly properties: Map; 27 | readonly id: string; 28 | readonly sessionState = new SessionState(); 29 | 30 | constructor(targetClient: any, hostInfo: HostInfo, properties: Map) { 31 | this.client = targetClient; 32 | this.hostInfo = hostInfo; 33 | this.properties = properties; 34 | this.id = uniqueId("PoolClient_"); 35 | } 36 | 37 | abort(): Promise { 38 | return this.end(); 39 | } 40 | 41 | query(sql: string): Promise { 42 | return this.client?.query(sql); 43 | } 44 | 45 | async queryWithTimeout(sql: string): Promise { 46 | return await ClientUtils.queryWithTimeout(this.client.query(sql), this.properties); 47 | } 48 | 49 | async end(): Promise { 50 | try { 51 | return this.client?.release(); 52 | } catch (error: any) { 53 | // Ignore 54 | } 55 | } 56 | 57 | rollback(): Promise { 58 | return this.client?.rollback(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /common/lib/pooled_connection_provider.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionProvider } from "./connection_provider"; 18 | 19 | export type PooledConnectionProvider = ConnectionProvider; 20 | -------------------------------------------------------------------------------- /common/lib/profile/configuration_profile_codes.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class ConfigurationProfilePresetCodes { 18 | public static readonly A0 = "A0"; // Normal 19 | public static readonly A1 = "A1"; // Easy 20 | public static readonly A2 = "A2"; // Aggressive 21 | public static readonly B = "B"; // Normal 22 | public static readonly C0 = "C0"; // Normal 23 | public static readonly C1 = "C1"; // Aggressive 24 | public static readonly D0 = "D0"; // Normal 25 | public static readonly D1 = "D1"; // Easy 26 | public static readonly E = "E"; // Normal 27 | public static readonly F0 = "F0"; // Normal 28 | public static readonly F1 = "F1"; // Aggressive 29 | public static readonly G0 = "G0"; // Normal 30 | public static readonly G1 = "G1"; // Easy 31 | public static readonly H = "H"; // Normal 32 | public static readonly I0 = "I0"; // Normal 33 | public static readonly I1 = "I1"; // Aggressive 34 | 35 | public static isKnownPreset(name: string): boolean { 36 | return Object.prototype.hasOwnProperty.call(ConfigurationProfilePresetCodes, name); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/lib/random_host_selector.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostSelector } from "./host_selector"; 18 | import { HostInfo } from "./host_info"; 19 | import { HostRole } from "./host_role"; 20 | import { HostAvailability } from "./host_availability/host_availability"; 21 | import { AwsWrapperError } from "./utils/errors"; 22 | import { Messages } from "./utils/messages"; 23 | 24 | export class RandomHostSelector implements HostSelector { 25 | public static STRATEGY_NAME = "random"; 26 | 27 | getHost(hosts: HostInfo[], role: HostRole, props?: Map): HostInfo { 28 | const eligibleHosts = hosts.filter((hostInfo: HostInfo) => hostInfo.role === role && hostInfo.getAvailability() === HostAvailability.AVAILABLE); 29 | if (eligibleHosts.length === 0) { 30 | throw new AwsWrapperError(Messages.get("HostSelector.noHostsMatchingRole", role)); 31 | } 32 | 33 | const randomIndex = Math.floor(Math.random() * eligibleHosts.length); 34 | return eligibleHosts[randomIndex]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/lib/topology_aware_database_dialect.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "./host_info"; 18 | import { HostListProvider } from "./host_list_provider/host_list_provider"; 19 | import { HostRole } from "./host_role"; 20 | import { ClientWrapper } from "./client_wrapper"; 21 | 22 | export interface TopologyAwareDatabaseDialect { 23 | queryForTopology(client: ClientWrapper, hostListProvider: HostListProvider): Promise; 24 | 25 | identifyConnection(targetClient: ClientWrapper): Promise; 26 | 27 | getHostRole(client: ClientWrapper): Promise; 28 | 29 | // Returns the host id of the targetClient if it is connected to a writer, null otherwise. 30 | getWriterId(targetClient: ClientWrapper): Promise; 31 | } 32 | -------------------------------------------------------------------------------- /common/lib/utils/errors.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { Messages } from "./messages"; 18 | 19 | export class AwsWrapperError extends Error { 20 | constructor(message?: string, cause?: any) { 21 | super(message); 22 | this.name = this.constructor.name; 23 | this.cause = cause; 24 | } 25 | } 26 | 27 | export class UnsupportedStrategyError extends AwsWrapperError {} 28 | 29 | export class UnsupportedMethodError extends AwsWrapperError {} 30 | 31 | export class IllegalArgumentError extends AwsWrapperError {} 32 | 33 | export class FailoverError extends AwsWrapperError {} 34 | 35 | export class FailoverSuccessError extends FailoverError { 36 | constructor(message?: string, cause?: any) { 37 | super(Messages.get("Failover.connectionChangedError")); 38 | } 39 | } 40 | 41 | export class FailoverFailedError extends FailoverError {} 42 | 43 | export class TransactionResolutionUnknownError extends FailoverError {} 44 | 45 | export class LoginError extends AwsWrapperError {} 46 | 47 | export class InternalQueryTimeoutError extends AwsWrapperError {} 48 | 49 | export class UnavailableHostError extends AwsWrapperError {} 50 | -------------------------------------------------------------------------------- /common/lib/utils/internal_pool_mapping.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostInfo } from "../host_info"; 18 | 19 | export interface InternalPoolMapping { 20 | getPoolKey(hostInfo: HostInfo, originalProps: Map): string; 21 | } 22 | -------------------------------------------------------------------------------- /common/lib/utils/messages.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import path from "path"; 18 | import { I18n } from "i18n"; 19 | import { fileURLToPath } from "url"; 20 | 21 | export class Messages { 22 | static __filename = fileURLToPath(import.meta.url); 23 | static __dirname = path.dirname(Messages.__filename); 24 | 25 | static i18n = new I18n({ 26 | locales: ["en"], 27 | directory: path.join(Messages.__dirname, "locales") 28 | }); 29 | 30 | static get(key: string, ...val: string[]) { 31 | return Messages.i18n.__(key, ...val); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common/lib/utils/pool_key.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class PoolKey { 18 | url: string; 19 | extraKey: string; 20 | 21 | constructor(url: string, extraKey: string) { 22 | this.url = url; 23 | this.extraKey = extraKey; 24 | } 25 | 26 | getUrl(): string { 27 | return this.url; 28 | } 29 | 30 | getExtraKey(): string { 31 | return this.extraKey; 32 | } 33 | 34 | getPoolKeyString(): string { 35 | return `PoolKey [url=${this.getUrl()}, extraKey=${this.getExtraKey()}]`; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/lib/utils/rds_url_type.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class RdsUrlType { 18 | public static readonly IP_ADDRESS = new RdsUrlType(false, false); 19 | public static readonly RDS_WRITER_CLUSTER = new RdsUrlType(true, true); 20 | public static readonly RDS_READER_CLUSTER = new RdsUrlType(true, true); 21 | public static readonly RDS_CUSTOM_CLUSTER = new RdsUrlType(true, false); 22 | public static readonly RDS_PROXY = new RdsUrlType(true, false); 23 | public static readonly RDS_INSTANCE = new RdsUrlType(true, false); 24 | public static readonly RDS_AURORA_LIMITLESS_DB_SHARD_GROUP = new RdsUrlType(true, false); 25 | public static readonly OTHER = new RdsUrlType(false, false); 26 | 27 | private constructor( 28 | public readonly isRds: boolean, 29 | public readonly isRdsCluster: boolean 30 | ) {} 31 | } 32 | -------------------------------------------------------------------------------- /common/lib/utils/saml_utils.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { WrapperProperties } from "../wrapper_property"; 18 | import { AwsWrapperError } from "./errors"; 19 | import { Messages } from "./messages"; 20 | 21 | export class SamlUtils { 22 | private static readonly HTTPS_URL_PATTERN = new RegExp("^(https)://[-a-zA-Z0-9+&@#/%?=~_!:,.']*[-a-zA-Z0-9+&@#/%=~_']"); 23 | 24 | public static checkIdpCredentialsWithFallback(props: Map): void { 25 | if (!WrapperProperties.IDP_USERNAME.get(props)) { 26 | WrapperProperties.IDP_USERNAME.set(props, WrapperProperties.USER.get(props)); 27 | } 28 | if (!WrapperProperties.IDP_PASSWORD.get(props)) { 29 | WrapperProperties.IDP_PASSWORD.set(props, WrapperProperties.PASSWORD.get(props)); 30 | } 31 | } 32 | 33 | public static validateUrl(url: string): void { 34 | if (!url.match(SamlUtils.HTTPS_URL_PATTERN)) { 35 | throw new AwsWrapperError(Messages.get("AdfsCredentialsProviderFactory.invalidHttpsUrl", url)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/lib/utils/subscribed_method_helper.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class SubscribedMethodHelper { 18 | static readonly NETWORK_BOUND_METHODS: string[] = ["connect", "forceConnect", "query", "rollback"]; 19 | static readonly METHODS_REQUIRING_UPDATED_TOPOLOGY: string[] = ["connect", "forceConnect", "query"]; 20 | } 21 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/null_telemetry_context.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryContext } from "./telemetry_context"; 18 | 19 | export class NullTelemetryContext implements TelemetryContext { 20 | readonly name: string; 21 | 22 | constructor(name: string) { 23 | this.name = name; 24 | } 25 | 26 | async start(func: () => any): Promise { 27 | return await func(); 28 | } 29 | 30 | getName(): string { 31 | return ""; 32 | } 33 | 34 | setAttribute(key: string, value: string): void {} 35 | 36 | setError(error: Error): void {} 37 | 38 | setSuccess(success: boolean): void {} 39 | 40 | setFailure(error: Error): void {} 41 | } 42 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/null_telemetry_counter.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryCounter } from "./telemetry_counter"; 18 | 19 | export class NullTelemetryCounter implements TelemetryCounter { 20 | readonly name; 21 | 22 | constructor(name: string) { 23 | this.name = name; 24 | } 25 | 26 | add(value: number): void {} 27 | 28 | inc(): void {} 29 | 30 | getName(): string { 31 | return this.name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/null_telemetry_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryFactory } from "./telemetry_factory"; 18 | import { TelemetryCounter } from "./telemetry_counter"; 19 | import { TelemetryGauge } from "./telemetry_gauge"; 20 | import { TelemetryTraceLevel } from "./telemetry_trace_level"; 21 | import { TelemetryContext } from "./telemetry_context"; 22 | import { NullTelemetryCounter } from "./null_telemetry_counter"; 23 | import { NullTelemetryGauge } from "./null_telemetry_gauge"; 24 | import { NullTelemetryContext } from "./null_telemetry_context"; 25 | 26 | export class NullTelemetryFactory implements TelemetryFactory { 27 | async init() {} 28 | 29 | createCounter(name: string): TelemetryCounter { 30 | return new NullTelemetryCounter(name); 31 | } 32 | 33 | createGauge(name: string, callable: () => void): TelemetryGauge { 34 | return new NullTelemetryGauge(name); 35 | } 36 | 37 | openTelemetryContext(name: string, traceLevel: TelemetryTraceLevel): TelemetryContext { 38 | return new NullTelemetryContext(name); 39 | } 40 | 41 | async postCopy(telemetryContext: TelemetryContext, telemetryTraceLevel: TelemetryTraceLevel): Promise { 42 | // Do nothing. 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/null_telemetry_gauge.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryGauge } from "./telemetry_gauge"; 18 | 19 | export class NullTelemetryGauge implements TelemetryGauge { 20 | readonly name: string; 21 | 22 | constructor(name: string) { 23 | this.name = name; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/open_telemetry_counter.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryCounter } from "./telemetry_counter"; 18 | import { Counter, Meter } from "@opentelemetry/api"; 19 | 20 | export class OpenTelemetryCounter implements TelemetryCounter { 21 | readonly counter: Counter; 22 | readonly name: string; 23 | readonly meter: Meter; 24 | 25 | constructor(meter: Meter, name: string) { 26 | this.meter = meter; 27 | this.name = name; 28 | 29 | this.counter = meter.createCounter(name); 30 | } 31 | 32 | add(value: number): void { 33 | this.counter.add(value); 34 | } 35 | 36 | inc(): void { 37 | this.counter.add(1); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/open_telemetry_gauge.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryGauge } from "./telemetry_gauge"; 18 | import { Meter, ObservableGauge } from "@opentelemetry/api"; 19 | 20 | export class OpenTelemetryGauge implements TelemetryGauge { 21 | readonly name: string; 22 | readonly meter: Meter; 23 | readonly gauge: ObservableGauge; 24 | 25 | constructor(meter: Meter, name: string, callback: () => void) { 26 | this.name = name; 27 | this.meter = meter; 28 | 29 | this.gauge = this.meter.createObservableGauge(name, { 30 | description: "Create observable gauge metric", 31 | unit: "1" 32 | }); 33 | this.gauge.addCallback(callback); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/telemetry_const.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class TelemetryConst { 18 | static readonly TRACE_NAME_ANNOTATION = "traceName"; 19 | static readonly SOURCE_TRACE_ANNOTATION = "sourceTraceId"; 20 | static readonly PARENT_TRACE_ANNOTATION = "parentTraceId"; 21 | static readonly EXCEPTION_TYPE_ANNOTATION = "exceptionType"; 22 | static readonly EXCEPTION_MESSAGE_ANNOTATION = "exceptionMessage"; 23 | static readonly COPY_TRACE_NAME_PREFIX = "copy: "; 24 | } 25 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/telemetry_context.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface TelemetryContext { 18 | start(func: () => any): Promise; 19 | 20 | setSuccess(success: boolean): void; 21 | 22 | setAttribute(key: string, value: string): void; 23 | 24 | setError(error: Error): void; 25 | 26 | setFailure(error: Error): void; 27 | 28 | getName(): string; 29 | } 30 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/telemetry_counter.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface TelemetryCounter { 18 | add(value: number): void; 19 | 20 | inc(): void; 21 | } 22 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/telemetry_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryContext } from "./telemetry_context"; 18 | import { TelemetryTraceLevel } from "./telemetry_trace_level"; 19 | import { TelemetryCounter } from "./telemetry_counter"; 20 | import { TelemetryGauge } from "./telemetry_gauge"; 21 | 22 | export interface TelemetryFactory { 23 | init(): Promise; 24 | 25 | openTelemetryContext(name: string, traceLevel: TelemetryTraceLevel): TelemetryContext; 26 | 27 | postCopy(telemetryContext: TelemetryContext, telemetryTraceLevel: TelemetryTraceLevel): Promise; 28 | 29 | createCounter(name: string): TelemetryCounter; 30 | 31 | createGauge(name: string, callable: () => void): TelemetryGauge; 32 | } 33 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/telemetry_gauge.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export type TelemetryGauge = object; 18 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/telemetry_trace_level.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum TelemetryTraceLevel { 18 | FORCE_TOP_LEVEL, // always top level despite settings 19 | TOP_LEVEL, // if allowed by settings 20 | NESTED, 21 | NO_TRACE // post no trace 22 | } 23 | -------------------------------------------------------------------------------- /common/lib/utils/telemetry/xray_telemetry_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TelemetryFactory } from "./telemetry_factory"; 18 | import { TelemetryCounter } from "./telemetry_counter"; 19 | import { TelemetryGauge } from "./telemetry_gauge"; 20 | import { TelemetryTraceLevel } from "./telemetry_trace_level"; 21 | import { TelemetryContext } from "./telemetry_context"; 22 | import { AwsWrapperError } from "../errors"; 23 | import { XRayTelemetryContext } from "./xray_telemetry_context"; 24 | 25 | export class XRayTelemetryFactory implements TelemetryFactory { 26 | async init() {} 27 | 28 | createCounter(name: string): TelemetryCounter { 29 | throw new AwsWrapperError("XRay does not support metrics."); 30 | } 31 | 32 | createGauge(name: string, callable: () => void): TelemetryGauge { 33 | return new AwsWrapperError("XRay does not support metrics."); 34 | } 35 | 36 | openTelemetryContext(name: string, traceLevel: TelemetryTraceLevel): TelemetryContext { 37 | return new XRayTelemetryContext(name, traceLevel); 38 | } 39 | 40 | async postCopy(telemetryContext: TelemetryContext, telemetryTraceLevel: TelemetryTraceLevel): Promise { 41 | if (telemetryContext instanceof XRayTelemetryContext) { 42 | return XRayTelemetryContext.postCopy(telemetryContext, telemetryTraceLevel); 43 | } 44 | 45 | throw new AwsWrapperError("Wrong parameter type: " + telemetryContext.constructor.name); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/lib/utils/transaction_isolation_level.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum TransactionIsolationLevel { 18 | TRANSACTION_READ_UNCOMMITTED, 19 | TRANSACTION_READ_COMMITTED, 20 | TRANSACTION_REPEATABLE_READ, 21 | TRANSACTION_SERIALIZABLE 22 | } 23 | -------------------------------------------------------------------------------- /docs/GettingStarted.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | ## Minimum Requirements 4 | 5 | Before using the AWS Advanced NodeJS Wrapper, you must install: 6 | 7 | - Node 21.0.0+ 8 | - The AWS Advanced NodeJS Wrapper. 9 | - Your choice of underlying Node driver. 10 | - To use the wrapper with Aurora with PostgreSQL compatibility, install the [PostgreSQL Client](https://github.com/brianc/node-postgres). 11 | - To use the wrapper with Aurora with MySQL compatibility, install the [MySQL2 Client](https://github.com/sidorares/node-mysql2). 12 | 13 | If you are using the AWS Advanced NodeJS Wrapper as part of a Node project, include the wrapper and underlying driver as dependencies. 14 | 15 | > **Note:** Depending on which features of the AWS Advanced NodeJS Wrapper you use, you may have additional package requirements. Please refer to this [table](https://github.com/awslabs/aws-advanced-nodejs-wrapper/blob/main/docs/using-the-nodejs-wrapper/UsingTheNodejsWrapper.md#list-of-available-plugins) for more information. 16 | 17 | ## Obtaining the AWS Advanced NodeJS Wrapper 18 | 19 | You can use [npm](https://www.npmjs.com/) to obtain the AWS Advanced NodeJS Wrapper by adding the following configuration to the application's `package.json` file: 20 | 21 | ```json 22 | { 23 | "dependencies": { 24 | "aws-advanced-nodejs-wrapper": "^1.0.0" 25 | } 26 | } 27 | ``` 28 | 29 | ## Using the AWS Advanced NodeJS Wrapper 30 | 31 | For more detailed information about how to use and configure the AWS Advanced NodeJS Wrapper, please visit [this page](./using-the-nodejs-wrapper/UsingTheNodejsWrapper.md). 32 | -------------------------------------------------------------------------------- /docs/development-guide/Architecture.md: -------------------------------------------------------------------------------- 1 | # Architecture 2 | 3 |
diagram on how plugin manager is integrated with the user application
4 | 5 | The AWS Advanced NodeJS Wrapper contains 5 main components: 6 | 7 | 1. The AwsClient classes, such as AwsPgClient, and the AwsPoolClient classes such as AwsMysqlPoolClient. 8 | 2. The [plugin manager](./PluginManager.md). 9 | 3. The [loadable and extensible plugins](./LoadablePlugins.md). 10 | 4. The [plugin service](./PluginService.md). 11 | 5. The host list providers. 12 | 13 | The wrapper classes ensures all database method calls are redirected to be handled by the connection plugin manager. 14 | 15 | The connection plugin manager handles all the loaded or registered plugins and sends the database method call to be executed by all plugins [**subscribed**](./LoadablePlugins.md#subscribed-methods) to that method. 16 | 17 | During execution, plugins may utilize the plugin service to help its execution by retrieving or updating: 18 | 19 | - the current connection 20 | - the hosts information or topology of the database 21 | 22 | > [!NOTE] 23 | > 24 | > - Each client has its own instances of: 25 | > - plugin manager 26 | > - plugin service 27 | > - loaded plugin classes 28 | > - Multiple clients opened to the same database server will have separate sets of instances mentioned above. 29 | > - All plugins share the same instance of plugin service and the same instance of host list provider. 30 | -------------------------------------------------------------------------------- /docs/development-guide/PluginManager.md: -------------------------------------------------------------------------------- 1 | # Plugin Manager 2 | 3 | The plugin manager has the following main functionalities: 4 | 5 | - Load and initialize plugins 6 | - Initiate [pipelines](./Pipelines.md) 7 | 8 | ## Load and Initialize Plugins 9 | 10 | The plugin manager initializes all plugins with codes given to the [`plugins`](../using-the-nodejs-wrapper/UsingTheNodejsWrapper.md#connection-plugin-manager-parameters) connection parameter. 11 | 12 | ### Clean Up Resources 13 | 14 | The Aurora Connection Tracker Plugin, Host Monitoring Connection Plugin, and Read/Write Splitting Plugin can have shared resources. The plugin manager handles cleaning up resources that may be shared between connections at the end of an application through the `releaseResources` method. 15 | 16 | ## Initiate Pipelines 17 | 18 |
diagram for the plugin service design
19 | 20 | During the initial connection phase, where the plugin manager gets initialized, it initiates the host list provider and the connect pipelines. These two pipelines will set up a host list provider to be used by all the plugins and the initial connection. 21 | 22 | All subsequent methods calls will trigger the execute pipeline. 23 | 24 | > [!NOTE] 25 | > The execute pipeline does not limit to `execute` methods such as `query()` or `executeQuery()`. All methods, such as `getCatalog()` can trigger the execute pipeline. In other words, the execute pipeline is to execute all kinds of methods. 26 | -------------------------------------------------------------------------------- /docs/development-guide/PluginService.md: -------------------------------------------------------------------------------- 1 | ## Plugin Service 2 | 3 | ![](../images/plugin_service.png) 4 | 5 | The plugin service retrieves and updates the current connection and its relevant host information. 6 | 7 | It also keeps track of the host list provider in use, and notifies it to update its host list. 8 | 9 | It is expected that the plugins do not establish a connection themselves, but rather call `PluginService.connect()` 10 | to establish connections. 11 | 12 | ## Host List Providers 13 | 14 | The plugin service uses the host list provider to retrieve the most recent host information or topology information about the database. 15 | 16 | The AWS Advanced NodeJS Wrapper has two host list providers, the `ConnectionStringHostListProvider` and the `RdsHostListProvider`. 17 | 18 | The `ConnectionStringHostListProvider` is the default provider, it parses the host parameter for cluster information and stores the information. 19 | The provider supports having multiple hosts in the host parameter: 20 | 21 | | Host parameter | Support | 22 | | ------------------------------- | ------------------ | 23 | | `hostname1,hostname2` | :x: | 24 | | `hostname1,hostname2:8090` | :x: | 25 | | `hostname1:8090,hostname2` | :white_check_mark: | 26 | | `hostname1:8090,hostname2:8090` | :white_check_mark: | 27 | 28 | The `RdsHostListProvider` provides information about the Aurora cluster. 29 | It uses the current connection to track the available hosts and their roles in the cluster. 30 | 31 | The `ConnectionStringHostListProvider` is a static host list provider, whereas the `RdsHostListProvider` is a dynamic host list provider. 32 | A static host list provider will fetch the host list during initialization and does not update the host list afterward, 33 | whereas a dynamic host list provider will update the host list information based on database status. 34 | When implementing a custom host list provider, implement either the `StaticHostListProvider` or the `DynamicHostListProvider` marker interfaces to specify its provider type. 35 | -------------------------------------------------------------------------------- /docs/files/configuration-profile-presets.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/files/configuration-profile-presets.pdf -------------------------------------------------------------------------------- /docs/images/configuration-presets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/configuration-presets.png -------------------------------------------------------------------------------- /docs/images/efm_monitor_process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/efm_monitor_process.png -------------------------------------------------------------------------------- /docs/images/enhanced_failure_monitoring_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/enhanced_failure_monitoring_diagram.png -------------------------------------------------------------------------------- /docs/images/failover1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/failover1.png -------------------------------------------------------------------------------- /docs/images/failover2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/failover2.png -------------------------------------------------------------------------------- /docs/images/failover2_panic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/failover2_panic.png -------------------------------------------------------------------------------- /docs/images/failover_behavior.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/failover_behavior.png -------------------------------------------------------------------------------- /docs/images/failover_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/failover_diagram.png -------------------------------------------------------------------------------- /docs/images/initiate_pipelines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/initiate_pipelines.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_connect_pipelines_benchmarks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_connect_pipelines_benchmarks.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_execute_pipelines_benchmarks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_execute_pipelines_benchmarks.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_postgresql_efm_30000_5000_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_postgresql_efm_30000_5000_3.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_postgresql_efm_6000_1000_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_postgresql_efm_6000_1000_1.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_postgresql_failover_efm_30000_5000_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_postgresql_failover_efm_30000_5000_3.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_postgresql_failover_efm_6000_1000_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_postgresql_failover_efm_6000_1000_1.png -------------------------------------------------------------------------------- /docs/images/nodejs_wrapper_release_resources_pipelines_benchmarks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/nodejs_wrapper_release_resources_pipelines_benchmarks.png -------------------------------------------------------------------------------- /docs/images/pipelines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/pipelines.png -------------------------------------------------------------------------------- /docs/images/plugin_manager.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/plugin_manager.png -------------------------------------------------------------------------------- /docs/images/plugin_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/plugin_service.png -------------------------------------------------------------------------------- /docs/images/session_state_switch_connection.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/session_state_switch_connection.jpg -------------------------------------------------------------------------------- /docs/images/telemetry_nested.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/telemetry_nested.png -------------------------------------------------------------------------------- /docs/images/telemetry_top_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/telemetry_top_level.png -------------------------------------------------------------------------------- /docs/images/telemetry_traces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/docs/images/telemetry_traces.png -------------------------------------------------------------------------------- /docs/using-the-nodejs-wrapper/DriverDialects.md: -------------------------------------------------------------------------------- 1 | # Driver Dialects 2 | 3 | ## What are Driver Dialects? 4 | 5 | The AWS Advanced NodeJS Wrapper is a wrapper that requires an underlying driver. It is currently compatible with [pg](https://github.com/brianc/node-postgres) and [mysql2](https://github.com/sidorares/node-mysql2). Driver dialects help the AWS Advanced NodeJS Wrapper to properly pass calls to a target driver. To function correctly, the AWS Advanced NodeJS Wrapper requires details unique to the specific target driver such as the method to create the current connection, whether to include some specific connection parameters, etc. These details can be defined and provided to the AWS Advanced NodeJS Wrapper by using driver dialects. 6 | 7 | To get a connection with the AWS Advanced NodeJS Wrapper, the user application can create a client object and connect. The database type being connected to determines the client and the driver dialect. 8 | 9 | ### List of Available Driver Dialects 10 | 11 | | Database Type | Client | Driver Dialect | Underlying Node Driver | 12 | | ------------- | ---------------- | --------------------------- | -------------------------------------------------------- | 13 | | MySQL | `AwsMySQLClient` | `MySQL2DriverDialect` | [node-mysql2](https://github.com/sidorares/node-mysql2) | 14 | | PostgreSQL | `AwsPgClient` | `NodePostgresDriverDialect` | [node-postgres](https://github.com/brianc/node-postgres) | 15 | -------------------------------------------------------------------------------- /docs/using-the-nodejs-wrapper/using-plugins/UsingTheAuroraConnectionTrackerPlugin.md: -------------------------------------------------------------------------------- 1 | # Aurora Connection Tracker Plugin 2 | 3 | This plugin tracks all the opened connections. In the event of a cluster failover, this plugin will close all the impacted connections. 4 | If no plugins are explicitly specified, this plugin is enabled by default. 5 | 6 | ## Use Case 7 | 8 | User applications can have two types of connections: 9 | 10 | 1. active connections that are used to execute statements or perform other types of database operations. 11 | 2. idle connections that the application holds references but are not used for any operations. 12 | 13 | For example, the user application had an active connection and an idle connection to instance A where instance A was a writer instance. The user application was executing DML statements against instance A when a cluster failover occurred. A different instance was promoted as the writer, so instance A is now a reader. The driver will failover the active connection to the new writer, but it would not modify the idle connection. 14 | 15 | When the application tries to continue the workflow with the idle connection that is still pointing to an instance that has changed roles, i.e. instance A, users may get an error caused by unexpected behaviour, such as `Error: Cannot execute statement in a READ ONLY transaction.`. 16 | 17 | Since the Aurora Connection Tracker Plugin keeps track of all the open connections, the plugin can close all impacted connections after failover. 18 | When the application tries to use the outdated idle connection, the application will get an error such as `Can't add new command when connection is in closed state` instead. 19 | 20 | > [!WARNING] 21 | > Connections with the Aurora Connection Tracker Plugin may have cached resources used throughout multiple connections. To clean up any resources used by the plugins at the end of the application call `await PluginManager.releaseResources()`. 22 | -------------------------------------------------------------------------------- /examples/aws_driver_example/README.md: -------------------------------------------------------------------------------- 1 | # Running The AWS Advanced NodeJS Wrapper Code Samples 2 | 3 | ### Prerequisites 4 | 5 | - [npm](https://www.npmjs.com/) 9.2.0+ 6 | 7 | ### Running a Sample 8 | 9 | Each code snippet in the `/examples/aws_driver_example` can be run from within the project. Each example requires existing databases or AWS resources, and will need the user to edit any credentials or user specific information for the sample to run correctly. 10 | 11 | Prior to running a sample, all prerequisites for the sample must be met. For example, to run the `aws_iam_authentication_mysql_example.ts` file, you must have an IAM user set up and IAM Authentication must be enabled on the database you specify. See the individual [plugin pages](/docs/using-the-nodejs-wrapper/UsingTheNodejsWrapper.md#list-of-available-plugins) for more information. 12 | 13 | Note that for any failover examples, failover will not be triggered. For example, the `aws_failover_mysql_example.ts` sample demonstrates enabling the failover plugin and failover handling, but will not initiate cluster failover on its own. For information on how to fail over an Amazon Aurora Database cluster, see [here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-failover.html). 14 | 15 | To run the sample: 16 | 17 | 1. Ensure all prerequisites have been met. 18 | 2. Install all required packages with `npm install`. 19 | 3. Navigate to the `/examples/aws_driver_example` directory. 20 | 4. Edit any credentials or user specific information in the desired file. For example, set the client properties in the file to match an existing database for the queries to run against. 21 | 5. Run the command `npx tsx `. For example, to run the `aws_iam_authentication_mysql_example.ts` file, the command would be `npx tsx aws_iam_authentication_mysql_example.ts`. 22 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_iam_authentication_mysql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { readFileSync } from "fs"; 18 | import { AwsMySQLClient } from "../../mysql/lib"; 19 | 20 | const mysqlHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 21 | const username = "john_smith"; 22 | const port = 3306; 23 | 24 | const client = new AwsMySQLClient({ 25 | // Enable AWS IAM database authentication and configure connection parameters 26 | host: mysqlHost, 27 | port: port, 28 | user: username, 29 | plugins: "iam", 30 | iamRegion: "us-east-2", 31 | ssl: { 32 | ca: readFileSync("path/to/ssl/certificate.pem").toString() 33 | } 34 | }); 35 | 36 | // Attempt connection 37 | try { 38 | await client.connect(); 39 | const result = await client.query({ sql: "select 1" }); 40 | console.log(result); 41 | } finally { 42 | await client.end(); 43 | } 44 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_iam_authentication_postgresql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { readFileSync } from "fs"; 18 | import { AwsPGClient } from "../../pg/lib"; 19 | 20 | const postgresHost = "postgresql://db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 21 | const username = "john_smith"; 22 | const database = "employees"; 23 | const port = 5432; 24 | 25 | const client = new AwsPGClient({ 26 | // Enable AWS IAM database authentication and configure connection parameters 27 | host: postgresHost, 28 | port: port, 29 | user: username, 30 | plugins: "iam", 31 | iamRegion: "us-east-2", 32 | database: database, 33 | ssl: { 34 | ca: readFileSync("path/to/ssl/certificate.pem").toString() 35 | } 36 | }); 37 | 38 | // Attempt connection 39 | try { 40 | await client.connect(); 41 | const result = await client.query("select aurora_db_instance_identifier()"); 42 | console.log(result); 43 | } finally { 44 | await client.end(); 45 | } 46 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_limitless_postgresql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { readFileSync } from "fs"; 18 | import { AwsPGClient } from "../../pg/lib"; 19 | 20 | const postgresHost = "db-identifier.shardgrp-XYZ.us-east-2.rds.amazonaws.com"; 21 | const username = "user"; 22 | const password = "password"; 23 | const database = "employees"; 24 | const port = 5432; 25 | 26 | const client = new AwsPGClient({ 27 | host: postgresHost, 28 | port: port, 29 | user: username, 30 | password: password, 31 | plugins: "limitless", 32 | iamRegion: "us-east-2", 33 | database: database, 34 | ssl: { 35 | ca: readFileSync("path/to/ssl/certificate.pem").toString() 36 | } 37 | }); 38 | 39 | // Attempt connection 40 | try { 41 | await client.connect(); 42 | const result = await client.query("select aurora_db_instance_identifier()"); 43 | console.log(result); 44 | } finally { 45 | await client.end(); 46 | } 47 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_okta_mysql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { readFileSync } from "fs"; 18 | import { AwsMySQLClient } from "../../mysql/lib"; 19 | 20 | const mysqlHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 21 | const idpEndpoint = "123456789.okta.com"; 22 | const appId = "abc12345678"; 23 | const iamRoleArn = "arn:aws:iam::123456789:role/OktaAccessRole"; 24 | const iamIdpArn = "arn:aws:iam::123456789:saml-provider/OktaSAMLIdp"; 25 | const iamRegion = "us-east-1"; 26 | const idpUsername = "jsmith"; 27 | const idpPassword = "password"; 28 | const dbUser = "john_smith"; 29 | 30 | const client = new AwsMySQLClient({ 31 | // Enable Okta authentication and configure connection parameters. 32 | host: mysqlHost, 33 | idpEndpoint: idpEndpoint, 34 | appId: appId, 35 | iamRoleArn: iamRoleArn, 36 | iamIdpArn: iamIdpArn, 37 | iamRegion: iamRegion, 38 | idpUsername: idpUsername, 39 | idpPassword: idpPassword, 40 | dbUser: dbUser, 41 | plugins: "okta", 42 | ssl: { 43 | ca: readFileSync("path/to/ssl/certificate.pem").toString() 44 | } 45 | }); 46 | 47 | // Attempt connection. 48 | try { 49 | await client.connect(); 50 | const result = await client.query({ sql: "select 1" }); 51 | console.log(result); 52 | } finally { 53 | await client.end(); 54 | } 55 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_okta_postgresql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { readFileSync } from "fs"; 18 | import { AwsPGClient } from "../../pg/lib"; 19 | 20 | const postgresHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 21 | const idpEndpoint = "123456789.okta.com"; 22 | const appId = "abc12345678"; 23 | const iamRoleArn = "arn:aws:iam::123456789:role/OktaAccessRole"; 24 | const iamIdpArn = "arn:aws:iam::123456789:saml-provider/OktaSAMLIdp"; 25 | const iamRegion = "us-east-1"; 26 | const idpUsername = "jsmith"; 27 | const idpPassword = "password"; 28 | const dbUser = "john_smith"; 29 | const database = "employees"; 30 | 31 | const client = new AwsPGClient({ 32 | // Enable Okta authentication and configure connection parameters. 33 | host: postgresHost, 34 | database: database, 35 | idpEndpoint: idpEndpoint, 36 | appId: appId, 37 | iamRoleArn: iamRoleArn, 38 | iamIdpArn: iamIdpArn, 39 | iamRegion: iamRegion, 40 | idpUsername: idpUsername, 41 | idpPassword: idpPassword, 42 | dbUser: dbUser, 43 | plugins: "okta", 44 | ssl: { 45 | ca: readFileSync("path/to/ssl/certificate.pem").toString() 46 | } 47 | }); 48 | 49 | // Attempt connection. 50 | try { 51 | await client.connect(); 52 | const result = await client.query("select 1"); 53 | console.log(result); 54 | } finally { 55 | await client.end(); 56 | } 57 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_secrets_manager_mysql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AwsMySQLClient } from "../../mysql/lib"; 18 | 19 | const mysqlHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 20 | const port = 3306; 21 | const secretId = "SecretName"; 22 | const secretRegion = "us-east-1"; 23 | /* secretId can be set as secret ARN instead. The ARN includes the secretRegion */ 24 | // const secretId = "arn:aws:secretsmanager:us-east-1:AccountId:secret:SecretName-6RandomCharacters"; 25 | 26 | const client = new AwsMySQLClient({ 27 | // Enable the AWS Secrets Manager Connection Plugin and configure connection parameters. 28 | host: mysqlHost, 29 | port: port, 30 | secretId: secretId, 31 | secretRegion: secretRegion, 32 | plugins: "secretsManager" 33 | }); 34 | 35 | // Attempt connection. 36 | try { 37 | await client.connect(); 38 | const result = await client.query({ sql: "SELECT 1" }); 39 | console.log(result); 40 | } finally { 41 | await client.end(); 42 | } 43 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_secrets_manager_postgresql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AwsPGClient } from "../../pg/lib"; 18 | 19 | const postgresHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 20 | const database = "employees"; 21 | const port = 5432; 22 | const secretId = "SecretName"; 23 | const secretRegion = "us-east-1"; 24 | /* secretId can be set as secret ARN instead. The ARN includes the secretRegion */ 25 | // const secretId = "arn:aws:secretsmanager:us-east-1:AccountId:secret:SecretName-6RandomCharacters"; 26 | 27 | const client = new AwsPGClient({ 28 | // Enable the AWS Secrets Manager Connection Plugin and configure connection parameters. 29 | host: postgresHost, 30 | database: database, 31 | port: port, 32 | secretId: secretId, 33 | secretRegion: secretRegion, 34 | plugins: "secretsManager" 35 | }); 36 | 37 | // Attempt connection. 38 | try { 39 | await client.connect(); 40 | const result = await client.query("select 1"); 41 | console.log(result); 42 | } finally { 43 | await client.end(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_simple_connection_mysql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AwsMySQLClient } from "../../mysql/lib"; 18 | 19 | const mysqlHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 20 | const username = "john_smith"; 21 | const password = "password"; 22 | const port = 3306; 23 | 24 | const client = new AwsMySQLClient({ 25 | // Configure connection parameters. 26 | host: mysqlHost, 27 | port: port, 28 | user: username, 29 | password: password 30 | }); 31 | 32 | // Attempt connection. 33 | try { 34 | await client.connect(); 35 | const result = await client.query({ sql: "SELECT @@aurora_server_id" }); 36 | console.log(result); 37 | } finally { 38 | await client.end(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/aws_driver_example/aws_simple_connection_postgresql_example.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AwsPGClient } from "../../pg/lib"; 18 | 19 | const postgresHost = "db-identifier.XYZ.us-east-2.rds.amazonaws.com"; 20 | const username = "john_smith"; 21 | const password = "password"; 22 | const database = "employees"; 23 | const port = 5432; 24 | 25 | const client = new AwsPGClient({ 26 | // Configure connection parameters. 27 | host: postgresHost, 28 | port: port, 29 | user: username, 30 | password: password, 31 | database: database 32 | }); 33 | 34 | // Attempt connection. 35 | try { 36 | await client.connect(); 37 | const result = await client.query("select aurora_db_instance_identifier()"); 38 | console.log(result); 39 | } finally { 40 | await client.end(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/prisma_example/adapter/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export { PrismaAws } from "./pgaws"; 18 | -------------------------------------------------------------------------------- /examples/prisma_example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prisma-example", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "npx tsx src/index.ts" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@types/node": "^22.10.1", 14 | "prisma": "^6.0.1", 15 | "tsx": "^4.19.2", 16 | "typescript": "^5.6.2" 17 | }, 18 | "dependencies": { 19 | "@prisma/client": "6.0.0", 20 | "@prisma/driver-adapter-utils": "^6.0.0", 21 | "aws-advanced-nodejs-wrapper": "^1.0.0", 22 | "pg": "^8.13.1", 23 | "util": "^0.12.5" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/prisma_example/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"). 4 | // You may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | generator client { 16 | provider = "prisma-client-js" 17 | previewFeatures = ["driverAdapters"] 18 | } 19 | 20 | datasource db { 21 | provider = "postgres" 22 | url = env("DATABASE_URL") 23 | } 24 | 25 | model bank_test { 26 | id Int @id 27 | name String? @db.VarChar(40) 28 | account_balance Int? 29 | } 30 | 31 | model Post { 32 | id Int @id @default(autoincrement()) 33 | title String 34 | content String? 35 | published Boolean @default(false) 36 | author User? @relation(fields: [authorId], references: [id]) 37 | authorId Int? 38 | } 39 | 40 | model User { 41 | id Int @id @default(autoincrement()) 42 | email String @unique 43 | name String? 44 | posts Post[] 45 | } 46 | -------------------------------------------------------------------------------- /examples/prisma_example/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AwsPGClient } from "aws-advanced-nodejs-wrapper/dist/pg/lib/index.js"; // the AWS client 18 | import { PrismaAws } from "../adapter"; // the custom adapter 19 | import { PrismaClient } from "@prisma/client"; // the prisma client 20 | 21 | // Init Prisma client. 22 | const client = new AwsPGClient({ 23 | user: "username", 24 | password: "password", 25 | host: "db-identifier.XYZ.us-east-2.rds.amazonaws.com", 26 | database: "postgres", 27 | port: 5432 28 | }); 29 | const adapter = new PrismaAws(client); 30 | const prisma = new PrismaClient({ adapter, log: ["query"] }); 31 | 32 | // Connect and run a simple query. 33 | async function main() { 34 | await client.connect(); 35 | 36 | const result = await prisma.bank_test.findFirst(); 37 | console.log(result); 38 | 39 | await client.end(); 40 | } 41 | 42 | main(); 43 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-advanced-nodejs-wrapper/e025a1805695ff3c4d13f2a747aadc9231c00458/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /jest.integration.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["ts", "js", "json"], 3 | "testMatch": ["/tests/integration/container/tests/*.(spec|test).ts|tsx"], 4 | "transform": { 5 | "^.+\\.ts$": [ 6 | "ts-jest", 7 | { 8 | "diagnostics": false, 9 | "useESM": true 10 | } 11 | ] 12 | }, 13 | "transformIgnorePatterns": ["node_modules"], 14 | "moduleNameMapper": { 15 | "^uuid$": "uuid" 16 | }, 17 | "globalSetup": "/tests/integration/container/tests/setup.ts", 18 | "setupFilesAfterEnv": ["/tests/integration/container/tests/config.ts"], 19 | "testEnvironment": "node", 20 | "extensionsToTreatAsEsm": [".ts"], 21 | "reporters": ["default", "./node_modules/jest-html-reporter"] 22 | } 23 | -------------------------------------------------------------------------------- /jest.unit.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["ts", "js", "json"], 3 | "testMatch": ["/tests/unit/*.(spec|test).ts|tsx"], 4 | "transform": { 5 | "^.+\\.ts$": [ 6 | "ts-jest", 7 | { 8 | "diagnostics": false, 9 | "useESM": true 10 | } 11 | ] 12 | }, 13 | "transformIgnorePatterns": ["node_modules"], 14 | "moduleNameMapper": { 15 | "^uuid$": "uuid" 16 | }, 17 | "testEnvironment": "node", 18 | "extensionsToTreatAsEsm": [".ts"], 19 | "reporters": ["default"] 20 | } 21 | -------------------------------------------------------------------------------- /mysql/lib/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export * from "./client"; 18 | -------------------------------------------------------------------------------- /mysql/lib/mysql_connection_url_parser.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionUrlParser } from "../../common/lib/utils/connection_url_parser"; 18 | 19 | export class MySQLConnectionUrlParser extends ConnectionUrlParser { 20 | /** 21 | * MySQl2 accepts either a hostname or a connection string when establishing a connection, e.g.: 22 | * - mysql://root:password@localhost:port/dbName 23 | * - example.aslfdewrlk.us-east-1.rds.amazonaws.com 24 | */ 25 | 26 | private static readonly PROTOCOL = "mysql://"; 27 | private static readonly TCP_CONNECTION_STRING_PATTERN = /mysql:\/\/(?:([^@\s]+)@)?(?([^/\s]+))(?:\/(\w+))?(?:\?(.+))?/i; 28 | getHostPortPairsFromUrl(initialConnection: string): string[] { 29 | if (!initialConnection.startsWith(MySQLConnectionUrlParser.PROTOCOL)) { 30 | return [initialConnection]; 31 | } 32 | 33 | const match = initialConnection.match(MySQLConnectionUrlParser.TCP_CONNECTION_STRING_PATTERN); 34 | if (match && match.groups) { 35 | const hosts = match.groups["hosts"]; 36 | if (hosts) { 37 | return hosts.trim().split(ConnectionUrlParser.HOST_SEPARATOR); 38 | } 39 | } 40 | return []; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mysql/lib/mysql_pool_client.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { createPool, PoolOptions } from "mysql2/promise"; 18 | import { AwsPoolClient } from "../../common/lib/aws_pool_client"; 19 | import { Messages } from "../../common/lib/utils/messages"; 20 | import { AwsWrapperError } from "../../common/lib/utils/errors"; 21 | 22 | export class AwsMysqlPoolClient implements AwsPoolClient { 23 | targetPool: any; 24 | 25 | constructor(props: PoolOptions) { 26 | this.targetPool = createPool(props); 27 | } 28 | 29 | async connect(): Promise { 30 | try { 31 | return await this.targetPool.getConnection(); 32 | } catch (error: any) { 33 | throw new AwsWrapperError(Messages.get("InternalPooledConnectionProvider.pooledConnectionFailed", error.message)); 34 | } 35 | } 36 | 37 | async end(): Promise { 38 | try { 39 | return await this.targetPool.end(); 40 | } catch (error: any) { 41 | // Ignore 42 | } 43 | } 44 | 45 | getIdleCount(): number { 46 | return this.targetPool.pool._freeConnections.length; 47 | } 48 | 49 | getTotalCount(): number { 50 | return this.targetPool.pool._allConnections.length; 51 | } 52 | 53 | getActiveCount(): number { 54 | return this.getTotalCount() - this.getIdleCount(); 55 | } 56 | 57 | async releaseResources(): Promise { 58 | await this.targetPool.end(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pg/lib/dialect/rds_pg_database_dialect.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { PgDatabaseDialect } from "./pg_database_dialect"; 18 | import { DatabaseDialectCodes } from "../../../common/lib/database_dialect/database_dialect_codes"; 19 | import { ClientWrapper } from "../../../common/lib/client_wrapper"; 20 | 21 | export class RdsPgDatabaseDialect extends PgDatabaseDialect { 22 | private static readonly EXTENSIONS_SQL: string = 23 | "SELECT (setting LIKE '%rds_tools%') AS rds_tools, (setting LIKE '%aurora_stat_utils%') AS aurora_stat_utils " + 24 | "FROM pg_settings WHERE name='rds.extensions'"; 25 | 26 | getDialectUpdateCandidates(): string[] { 27 | return [DatabaseDialectCodes.RDS_MULTI_AZ_PG, DatabaseDialectCodes.AURORA_PG]; 28 | } 29 | 30 | async isDialect(targetClient: ClientWrapper): Promise { 31 | if (!(await super.isDialect(targetClient))) { 32 | return false; 33 | } 34 | 35 | return await targetClient 36 | .query(RdsPgDatabaseDialect.EXTENSIONS_SQL) 37 | .then((result: any) => { 38 | const rdsTools = result.rows[0]["rds_tools"]; 39 | const auroraStatUtils = result.rows[0]["aurora_stat_utils"]; 40 | return rdsTools && !auroraStatUtils; 41 | }) 42 | .catch(() => { 43 | return false; 44 | }); 45 | } 46 | 47 | getDialectName(): string { 48 | return this.dialectName; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pg/lib/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export * from "./client"; 18 | -------------------------------------------------------------------------------- /pg/lib/multi_az_pg_error_handler.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AbstractPgErrorHandler } from "./abstract_pg_error_handler"; 18 | 19 | export class MultiAzPgErrorHandler extends AbstractPgErrorHandler { 20 | private static readonly SQLSTATE_ACCESS_ERROR_CODES = ["28P01"]; 21 | private static readonly ACCESS_ERROR_MESSAGES = ["Access denied", "PAM authentication failed"]; 22 | private static readonly NETWORK_MESSAGES = [ 23 | "Connection terminated unexpectedly", 24 | "Client has encountered a connection error and is not queryable", 25 | "Query read timeout", 26 | "Connection terminated due to connection timeout", 27 | "read ECONNRESET", 28 | "connect ECONNREFUSED" 29 | ]; 30 | 31 | getAccessErrorCodes(): string[] { 32 | return MultiAzPgErrorHandler.SQLSTATE_ACCESS_ERROR_CODES; 33 | } 34 | 35 | getAccessErrorMessages(): string[] { 36 | return MultiAzPgErrorHandler.ACCESS_ERROR_MESSAGES; 37 | } 38 | 39 | getNetworkErrors(): string[] { 40 | return MultiAzPgErrorHandler.NETWORK_MESSAGES; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pg/lib/pg_error_handler.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AbstractPgErrorHandler } from "./abstract_pg_error_handler"; 18 | 19 | export class PgErrorHandler extends AbstractPgErrorHandler { 20 | private static readonly SQLSTATE_ACCESS_ERROR_CODES = ["28000", "28P01"]; 21 | private static readonly ACCESS_ERROR_MESSAGES = ["Access denied", "PAM authentication failed"]; 22 | private static readonly NETWORK_MESSAGES = [ 23 | "Connection terminated unexpectedly", 24 | "Client has encountered a connection error and is not queryable", 25 | "Query read timeout", 26 | "Connection terminated due to connection timeout", 27 | "read ECONNRESET", 28 | "connect ECONNREFUSED" 29 | ]; 30 | 31 | getAccessErrorCodes(): string[] { 32 | return PgErrorHandler.SQLSTATE_ACCESS_ERROR_CODES; 33 | } 34 | 35 | getAccessErrorMessages(): string[] { 36 | return PgErrorHandler.ACCESS_ERROR_MESSAGES; 37 | } 38 | 39 | getNetworkErrors(): string[] { 40 | return PgErrorHandler.NETWORK_MESSAGES; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pg/lib/pg_pool_client.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import pkgPg from "pg"; 18 | 19 | import { AwsPoolClient } from "../../common/lib/aws_pool_client"; 20 | import { Messages } from "../../common/lib/utils/messages"; 21 | import { AwsWrapperError } from "../../common/lib/utils/errors"; 22 | 23 | export class AwsPgPoolClient implements AwsPoolClient { 24 | targetPool: pkgPg.Pool; 25 | 26 | constructor(props: pkgPg.PoolConfig) { 27 | this.targetPool = new pkgPg.Pool(props); 28 | } 29 | 30 | async end(): Promise { 31 | try { 32 | return await this.targetPool.end(); 33 | } catch (error: any) { 34 | // Ignore 35 | } 36 | } 37 | 38 | async connect(): Promise { 39 | try { 40 | return await this.targetPool.connect(); 41 | } catch (error: any) { 42 | throw new AwsWrapperError(Messages.get("InternalPooledConnectionProvider.pooledConnectionFailed", error.message)); 43 | } 44 | } 45 | 46 | getIdleCount(): number { 47 | return this.targetPool.idleCount; 48 | } 49 | 50 | getTotalCount(): number { 51 | return this.targetPool.totalCount; 52 | } 53 | 54 | getActiveCount(): number { 55 | return this.getTotalCount() - this.getIdleCount(); 56 | } 57 | 58 | async releaseResources(): Promise { 59 | await this.targetPool.end(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "aws-advanced-nodejs-wrapper" 2 | 3 | include("integration-testing") 4 | 5 | project(":integration-testing").projectDir = file("tests/integration/host") 6 | -------------------------------------------------------------------------------- /tests/integration/container/tests/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { CustomConsole, LogMessage, LogType } from "@jest/console"; 18 | 19 | function simpleFormatter(type: LogType, message: LogMessage): string { 20 | return message 21 | .split(/\n/) 22 | .map((line) => " " + line) 23 | .join("\n"); 24 | } 25 | 26 | global.console = new CustomConsole(process.stdout, process.stderr, simpleFormatter); 27 | 28 | const infoJson = process.env.TEST_ENV_INFO_JSON; 29 | if (infoJson === undefined) { 30 | throw new Error("env var required"); 31 | } 32 | 33 | const testInfo = JSON.parse(infoJson); 34 | const request = testInfo.request; 35 | export const features = request.features; 36 | export const instanceCount = request.numOfInstances; 37 | -------------------------------------------------------------------------------- /tests/integration/container/tests/setup.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | const infoJson = process.env.TEST_ENV_INFO_JSON; 18 | if (infoJson === undefined) { 19 | throw new Error("env var required"); 20 | } 21 | 22 | const testInfo = JSON.parse(infoJson); 23 | const request = testInfo.request; 24 | 25 | const reportSetting: string = `${request.deployment}-${request.engine}_instance-${request.numOfInstances}`; 26 | process.env["JEST_HTML_REPORTER_OUTPUT_PATH"] = `./tests/integration/container/reports/${reportSetting}.html`; 27 | process.env["JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG"] = "true"; 28 | process.env["JEST_HTML_REPORTER_INCLUDE_CONSOLE_LOG"] = "true"; 29 | 30 | // Required to use globalSetup: 31 | module.exports = async () => {}; 32 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/database_engine.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum DatabaseEngine { 18 | MYSQL = "MYSQL", 19 | PG = "PG" 20 | } 21 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/database_engine_deployment.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum DatabaseEngineDeployment { 18 | DOCKER = "DOCKER", 19 | RDS = "RDS", 20 | RDS_MULTI_AZ_CLUSTER = "RDS_MULTI_AZ_CLUSTER", 21 | AURORA = "AURORA" 22 | } 23 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/database_instances.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum DatabaseInstances { 18 | SINGLE_INSTANCE = "SINGLE_INSTANCE", 19 | MULTI_INSTANCE = "MULTI_INSTANCE" 20 | } 21 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/perf_stat.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export interface PerfStat { 18 | writeHeader(): string[][]; 19 | 20 | writeData(): (string | bigint | number | undefined)[]; 21 | } 22 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/proxy_info.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { Proxy } from "toxiproxy-node-client"; 18 | 19 | export class ProxyInfo { 20 | private _proxy: Proxy; 21 | private _controlHost: string; 22 | private _controlPort: number; 23 | 24 | constructor(proxy: Proxy, controlHost: string, controlPort: number) { 25 | this._proxy = proxy; 26 | this._controlHost = controlHost; 27 | this._controlPort = controlPort; 28 | } 29 | 30 | get proxy(): Proxy { 31 | return this._proxy; 32 | } 33 | 34 | set proxy(value: Proxy) { 35 | this._proxy = value; 36 | } 37 | 38 | get controlHost(): string { 39 | return this._controlHost; 40 | } 41 | 42 | set controlHost(value: string) { 43 | this._controlHost = value; 44 | } 45 | 46 | get controlPort(): number { 47 | return this._controlPort; 48 | } 49 | 50 | set controlPort(value: number) { 51 | this._controlPort = value; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/test_driver.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum TestDriver { 18 | PG = "PG", 19 | MYSQL = "MYSQL" 20 | } 21 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/test_environment_features.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export enum TestEnvironmentFeatures { 18 | IAM = "IAM", 19 | SECRETS_MANAGER = "SECRETS_MANAGER", 20 | FAILOVER_SUPPORTED = "FAILOVER_SUPPORTED", 21 | ABORT_CONNECTION_SUPPORTED = "ABORT_CONNECTION_SUPPORTED", 22 | NETWORK_OUTAGES_ENABLED = "NETWORK_OUTAGES_ENABLED", 23 | AWS_CREDENTIALS_ENABLED = "AWS_CREDENTIALS_ENABLED", 24 | PERFORMANCE = "PERFORMANCE", 25 | RUN_AUTOSCALING_TESTS_ONLY = "RUN_AUTOSCALING_TESTS_ONLY", 26 | SKIP_MYSQL_DRIVER_TESTS = "SKIP_MYSQL_DRIVER_TESTS", 27 | SKIP_PG_DRIVER_TESTS = "SKIP_PG_DRIVER_TESTS", 28 | RDS_MULTI_AZ_CLUSTER_SUPPORTED = "RDS_MULTI_AZ_CLUSTER_SUPPORTED" 29 | } 30 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/test_instance_info.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class TestInstanceInfo { 18 | private readonly _instanceId?: string; 19 | private readonly _host?: string; 20 | private readonly _port?: number; 21 | 22 | constructor(instanceInfo: { [s: string]: any }) { 23 | this._instanceId = instanceInfo.instanceId; 24 | this._host = instanceInfo.host; 25 | this._port = instanceInfo.port; 26 | 27 | if (this._instanceId === undefined) { 28 | this._instanceId = instanceInfo.DBInstanceIdentifier; 29 | } 30 | const endpoint = instanceInfo.Endpoint; 31 | if (endpoint !== undefined) { 32 | if (this._host === undefined) { 33 | this._host = endpoint.Address; 34 | } 35 | if (this._port === undefined) { 36 | this._port = endpoint.Port; 37 | } 38 | } 39 | } 40 | 41 | get instanceId(): string | undefined { 42 | return this._instanceId; 43 | } 44 | 45 | get host(): string | undefined { 46 | return this._host; 47 | } 48 | 49 | get port(): number | undefined { 50 | return this._port; 51 | } 52 | 53 | get url() { 54 | return this._host + ":" + String(this._port); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/test_proxy_database_info.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { TestDatabaseInfo } from "./test_database_info"; 18 | 19 | export class TestProxyDatabaseInfo extends TestDatabaseInfo { 20 | private readonly _controlPort: number = 8474; 21 | 22 | constructor(databaseInfo: { [s: string]: any }) { 23 | super(databaseInfo); 24 | 25 | if (databaseInfo == undefined) { 26 | return; 27 | } 28 | this._controlPort = Number(databaseInfo["controlPort"]); 29 | } 30 | 31 | get controlPort(): number { 32 | return this._controlPort; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/integration/container/tests/utils/test_telemetry_info.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | export class TestTelemetryInfo { 18 | readonly endpoint: string; 19 | readonly endpointPort: number; 20 | 21 | constructor(info: any) { 22 | this.endpoint = info.endpoint; 23 | this.endpointPort = info.endpointPort; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/config/standard-mysql-grant-root.sql: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | GRANT PROXY ON ''@'' TO 'root'@'%' WITH GRANT OPTION; 18 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/DatabaseEngine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | public enum DatabaseEngine { 20 | PG, 21 | MYSQL 22 | } 23 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/DatabaseEngineDeployment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | public enum DatabaseEngineDeployment { 20 | DOCKER, 21 | RDS, 22 | RDS_MULTI_AZ_CLUSTER, 23 | AURORA 24 | } 25 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/DatabaseInstances.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | public enum DatabaseInstances { 20 | SINGLE_INSTANCE, 21 | MULTI_INSTANCE 22 | } 23 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/GenericTypedParameterResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | import org.junit.jupiter.api.extension.ExtensionContext; 20 | import org.junit.jupiter.api.extension.ParameterContext; 21 | import org.junit.jupiter.api.extension.ParameterResolutionException; 22 | import org.junit.jupiter.api.extension.ParameterResolver; 23 | 24 | public class GenericTypedParameterResolver implements ParameterResolver { 25 | T data; 26 | 27 | public GenericTypedParameterResolver(T data) { 28 | this.data = data; 29 | } 30 | 31 | @Override 32 | public boolean supportsParameter( 33 | ParameterContext parameterContext, ExtensionContext extensionContext) 34 | throws ParameterResolutionException { 35 | return parameterContext.getParameter().getType().isInstance(data); 36 | } 37 | 38 | @Override 39 | public Object resolveParameter( 40 | ParameterContext parameterContext, ExtensionContext extensionContext) 41 | throws ParameterResolutionException { 42 | return data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/TestDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | public enum TestDriver { 20 | PG, 21 | MYSQL 22 | } 23 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/TestEnvironmentFeatures.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | public enum TestEnvironmentFeatures { 20 | IAM, 21 | SECRETS_MANAGER, 22 | FAILOVER_SUPPORTED, 23 | ABORT_CONNECTION_SUPPORTED, 24 | NETWORK_OUTAGES_ENABLED, 25 | AWS_CREDENTIALS_ENABLED, 26 | PERFORMANCE, 27 | RUN_AUTOSCALING_TESTS_ONLY, 28 | SKIP_MYSQL_DRIVER_TESTS, 29 | SKIP_PG_DRIVER_TESTS, 30 | TELEMETRY_TRACES_ENABLED, 31 | TELEMETRY_METRICS_ENABLED, 32 | RDS_MULTI_AZ_CLUSTER_SUPPORTED 33 | } 34 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/TestInstanceInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | 21 | // Annotation is required to avoid an error when trying to serialize the getUrl method 22 | @JsonIgnoreProperties(ignoreUnknown = true) 23 | public class TestInstanceInfo { 24 | 25 | private String instanceId; // "instance-1" 26 | private String host; // "instance-1.ABC.cluster-XYZ.us-west-2.rds.amazonaws.com" 27 | private int port; 28 | 29 | // This constructor should NOT be used in the code. It's required for serialization. 30 | public TestInstanceInfo() { 31 | } 32 | 33 | public TestInstanceInfo(String instanceId, String host, int port) { 34 | this.instanceId = instanceId; 35 | this.host = host; 36 | this.port = port; 37 | } 38 | 39 | public String getInstanceId() { 40 | return this.instanceId; 41 | } 42 | 43 | public String getHost() { 44 | return this.host; 45 | } 46 | 47 | public int getPort() { 48 | return this.port; 49 | } 50 | 51 | public String getUrl() { 52 | String url = host + ":" + port; 53 | if (!url.endsWith("/")) { 54 | url += "/"; 55 | } 56 | return url; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/TestProxyDatabaseInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | public class TestProxyDatabaseInfo extends TestDatabaseInfo { 20 | 21 | private int controlPort; 22 | 23 | public void setControlPort(int controlPort) { 24 | this.controlPort = controlPort; 25 | } 26 | 27 | public int getControlPort() { 28 | return this.controlPort; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/TestTelemetryInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host; 18 | 19 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 20 | 21 | // Annotation is required to avoid an error when trying to serialize the getUrl method 22 | @JsonIgnoreProperties(ignoreUnknown = true) 23 | public class TestTelemetryInfo { 24 | 25 | private String endpoint; 26 | private int endpointPort; 27 | 28 | // This constructor should NOT be used in the code. It's required for serialization. 29 | public TestTelemetryInfo() { 30 | } 31 | 32 | public TestTelemetryInfo(String endpoint, int endpointPort) { 33 | this.endpoint = endpoint; 34 | this.endpointPort = endpointPort; 35 | } 36 | 37 | public String getEndpoint() { 38 | return this.endpoint; 39 | } 40 | 41 | public String getUrl() { 42 | return getEndpoint() + ":" + getEndpointPort(); 43 | } 44 | 45 | public int getEndpointPort() { 46 | return this.endpointPort; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/util/ConsoleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host.util; 18 | 19 | import org.testcontainers.containers.output.BaseConsumer; 20 | import org.testcontainers.containers.output.OutputFrame; 21 | 22 | public class ConsoleConsumer 23 | extends BaseConsumer { 24 | 25 | private boolean separateOutputStreams; 26 | 27 | public ConsoleConsumer() { 28 | this(false); 29 | } 30 | 31 | public ConsoleConsumer(boolean separateOutputStreams) { 32 | this.separateOutputStreams = separateOutputStreams; 33 | } 34 | 35 | @Override 36 | public void accept(OutputFrame outputFrame) { 37 | final OutputFrame.OutputType outputType = outputFrame.getType(); 38 | 39 | final String utf8String = outputFrame.getUtf8String(); 40 | 41 | switch (outputType) { 42 | case END: 43 | break; 44 | case STDOUT: 45 | System.out.print(utf8String); 46 | break; 47 | case STDERR: 48 | if (separateOutputStreams) { 49 | System.err.print(utf8String); 50 | } else { 51 | System.out.print(utf8String); 52 | } 53 | break; 54 | default: 55 | throw new IllegalArgumentException( 56 | String.format("Unexpected outputType: '%s'.", outputType)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/java/integration/host/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package integration.host.util; 18 | 19 | import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; 20 | import org.checkerframework.checker.nullness.qual.Nullable; 21 | 22 | public class StringUtils { 23 | 24 | /** 25 | * Check if the supplied string is null or empty. 26 | * 27 | * @param s the string to analyze 28 | * @return true if the supplied string is null or empty 29 | */ 30 | @EnsuresNonNullIf(expression = "#1", result = false) 31 | public static boolean isNullOrEmpty(@Nullable final String s) { 32 | return s == null || s.equals(""); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/resources/otel-config.yaml: -------------------------------------------------------------------------------- 1 | extensions: 2 | health_check: 3 | 4 | receivers: 5 | otlp: 6 | protocols: 7 | grpc: 8 | endpoint: 0.0.0.0:4317 9 | http: 10 | endpoint: 0.0.0.0:4318 11 | awsxray: 12 | endpoint: 0.0.0.0:2000 13 | transport: udp 14 | 15 | processors: 16 | batch/traces: 17 | timeout: 1s 18 | send_batch_size: 1 19 | batch/metrics: 20 | timeout: 1s 21 | 22 | exporters: 23 | awsxray: 24 | awsemf: 25 | log_group_name: "aws_advanced_nodejs_wrapper" 26 | 27 | service: 28 | pipelines: 29 | traces: 30 | receivers: [otlp, awsxray] 31 | processors: [batch/traces] 32 | exporters: [awsxray] 33 | metrics: 34 | receivers: [otlp] 35 | processors: [batch/metrics] 36 | exporters: [awsemf] 37 | 38 | extensions: [health_check] 39 | -------------------------------------------------------------------------------- /tests/integration/host/src/test/resources/rds-ca-2019-root.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEBjCCAu6gAwIBAgIJAMc0ZzaSUK51MA0GCSqGSIb3DQEBCwUAMIGPMQswCQYD 3 | VQQGEwJVUzEQMA4GA1UEBwwHU2VhdHRsZTETMBEGA1UECAwKV2FzaGluZ3RvbjEi 4 | MCAGA1UECgwZQW1hem9uIFdlYiBTZXJ2aWNlcywgSW5jLjETMBEGA1UECwwKQW1h 5 | em9uIFJEUzEgMB4GA1UEAwwXQW1hem9uIFJEUyBSb290IDIwMTkgQ0EwHhcNMTkw 6 | ODIyMTcwODUwWhcNMjQwODIyMTcwODUwWjCBjzELMAkGA1UEBhMCVVMxEDAOBgNV 7 | BAcMB1NlYXR0bGUxEzARBgNVBAgMCldhc2hpbmd0b24xIjAgBgNVBAoMGUFtYXpv 8 | biBXZWIgU2VydmljZXMsIEluYy4xEzARBgNVBAsMCkFtYXpvbiBSRFMxIDAeBgNV 9 | BAMMF0FtYXpvbiBSRFMgUm9vdCAyMDE5IENBMIIBIjANBgkqhkiG9w0BAQEFAAOC 10 | AQ8AMIIBCgKCAQEArXnF/E6/Qh+ku3hQTSKPMhQQlCpoWvnIthzX6MK3p5a0eXKZ 11 | oWIjYcNNG6UwJjp4fUXl6glp53Jobn+tWNX88dNH2n8DVbppSwScVE2LpuL+94vY 12 | 0EYE/XxN7svKea8YvlrqkUBKyxLxTjh+U/KrGOaHxz9v0l6ZNlDbuaZw3qIWdD/I 13 | 6aNbGeRUVtpM6P+bWIoxVl/caQylQS6CEYUk+CpVyJSkopwJlzXT07tMoDL5WgX9 14 | O08KVgDNz9qP/IGtAcRduRcNioH3E9v981QO1zt/Gpb2f8NqAjUUCUZzOnij6mx9 15 | McZ+9cWX88CRzR0vQODWuZscgI08NvM69Fn2SQIDAQABo2MwYTAOBgNVHQ8BAf8E 16 | BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUc19g2LzLA5j0Kxc0LjZa 17 | pmD/vB8wHwYDVR0jBBgwFoAUc19g2LzLA5j0Kxc0LjZapmD/vB8wDQYJKoZIhvcN 18 | AQELBQADggEBAHAG7WTmyjzPRIM85rVj+fWHsLIvqpw6DObIjMWokpliCeMINZFV 19 | ynfgBKsf1ExwbvJNzYFXW6dihnguDG9VMPpi2up/ctQTN8tm9nDKOy08uNZoofMc 20 | NUZxKCEkVKZv+IL4oHoeayt8egtv3ujJM6V14AstMQ6SwvwvA93EP/Ug2e4WAXHu 21 | cbI1NAbUgVDqp+DRdfvZkgYKryjTWd/0+1fS8X1bBZVWzl7eirNVnHbSH2ZDpNuY 22 | 0SBd8dj5F6ld3t58ydZbrTHze7JJOd8ijySAp4/kiu9UfZWuTPABzDa/DSdz9Dk/ 23 | zPW4CXXvhLmE02TA9/HeCw3KEHIwicNuEfw= 24 | -----END CERTIFICATE----- 25 | -------------------------------------------------------------------------------- /tests/testplugin/benchmark_plugin_factory.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ConnectionPluginFactory } from "../../common/lib/plugin_factory"; 18 | import { PluginServiceImpl } from "../../common/lib/plugin_service"; 19 | import { ConnectionPlugin } from "../../common/lib"; 20 | import { AwsWrapperError } from "../../common/lib/utils/errors"; 21 | import { Messages } from "../../common/lib/utils/messages"; 22 | import { BenchmarkPlugin } from "./benchmark_plugin"; 23 | 24 | export class BenchmarkPluginFactory extends ConnectionPluginFactory { 25 | async getInstance(pluginService: PluginService, properties: object): Promise { 26 | try { 27 | return new BenchmarkPlugin(); 28 | } catch (error: any) { 29 | throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "BenchmarkPlugin")); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/testplugin/test_connection_wrapper.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { AwsPGClient } from "../../pg/lib"; 18 | import { PluginManager } from "../../common/lib"; 19 | import { PluginServiceImpl } from "../../common/lib/plugin_service"; 20 | import { TelemetryFactory } from "../../common/lib/utils/telemetry/telemetry_factory"; 21 | 22 | export class TestConnectionWrapper extends AwsPGClient { 23 | constructor(config: any, pluginManager: PluginManager, pluginService: PluginService, telemetryFactory?: TelemetryFactory) { 24 | super(config); 25 | this.pluginManager = pluginManager; 26 | this.pluginService = pluginService; 27 | this.telemetryFactory = telemetryFactory ?? this.telemetryFactory; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/unit/execute_time_plugin.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { ExecuteTimePlugin } from "../../common/lib/plugins/execute_time_plugin"; 18 | import { sleep } from "../../common/lib/utils/utils"; 19 | import { jest } from "@jest/globals"; 20 | 21 | const mockCallable = jest.fn(() => { 22 | return Promise.resolve(); 23 | }); 24 | const timeToSleepMs = 1000; 25 | const acceptableTimeMs = 995; 26 | const acceptableTimeNs = acceptableTimeMs * 1000000; 27 | 28 | describe("executeTimePluginTest", () => { 29 | it("test_executeTime", async () => { 30 | mockCallable.mockImplementation(async () => { 31 | await sleep(timeToSleepMs); 32 | return null; 33 | }); 34 | 35 | const plugin = new ExecuteTimePlugin(); 36 | 37 | await plugin.execute("query", mockCallable, []); 38 | 39 | expect(ExecuteTimePlugin.getTotalExecuteTime()).toBeGreaterThan(acceptableTimeNs); 40 | 41 | await plugin.execute("query", mockCallable, []); 42 | 43 | expect(ExecuteTimePlugin.getTotalExecuteTime()).toBeGreaterThan(acceptableTimeNs * 2); 44 | 45 | ExecuteTimePlugin.resetExecuteTime(); 46 | expect(ExecuteTimePlugin.getTotalExecuteTime()).toEqual(0n); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /tests/unit/host_availability_strategy_factory.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { HostAvailabilityStrategyFactory } from "../../common/lib/host_availability/host_availability_strategy_factory"; 18 | import { SimpleHostAvailabilityStrategy } from "../../common/lib/host_availability/simple_host_availability_strategy"; 19 | import { 20 | ExponentialBackoffHostAvailabilityStrategy 21 | } from "../../common/lib/host_availability/exponential_backoff_host_availability_strategy"; 22 | import { WrapperProperties } from "../../common/lib/wrapper_property"; 23 | 24 | describe("hostAvailabilityStrategyFactoryTests", () => { 25 | it("testCreateDefaultAvailabilityStrategyGivenEmptyProperties", () => { 26 | const factory = new HostAvailabilityStrategyFactory(); 27 | const availabilityStrategy = factory.create(new Map()); 28 | expect(availabilityStrategy).toBeInstanceOf(SimpleHostAvailabilityStrategy); 29 | }); 30 | 31 | it("testCreateDefaultAvailabilityStrategyGivenOverrideProperty", () => { 32 | const props = new Map(); 33 | WrapperProperties.DEFAULT_HOST_AVAILABILITY_STRATEGY.set(props, ExponentialBackoffHostAvailabilityStrategy.NAME); 34 | const factory = new HostAvailabilityStrategyFactory(); 35 | const availabilityStrategy = factory.create(props); 36 | expect(availabilityStrategy).toBeInstanceOf(ExponentialBackoffHostAvailabilityStrategy); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /tests/unit/host_info.test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"). 5 | You may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import { anything, instance, mock, verify } from "ts-mockito"; 18 | import { HostAvailabilityStrategy } from "../../common/lib/host_availability/host_availability_strategy"; 19 | import { HostInfo } from "../../common/lib/host_info"; 20 | import { HostInfoBuilder } from "../../common/lib/host_info_builder"; 21 | import { HostAvailability } from "../../common/lib/host_availability/host_availability"; 22 | 23 | const mockStrategy = mock(); 24 | let hostInfo: HostInfo; 25 | 26 | describe("hostInfoTests", () => { 27 | beforeEach(() => { 28 | hostInfo = new HostInfoBuilder({ hostAvailabilityStrategy: instance(mockStrategy) }).withHost("someUrl").build(); 29 | }); 30 | 31 | it("testSetAvailabilityCallsHostAvailabilityStrategy", () => { 32 | const hostAvailability = HostAvailability.NOT_AVAILABLE; 33 | hostInfo.setAvailability(hostAvailability); 34 | verify(mockStrategy.setHostAvailability(anything())).once(); 35 | }); 36 | 37 | it("testGetAvailabilityCallsHostAvailabilityStrategy", () => { 38 | hostInfo.getAvailability(); 39 | verify(mockStrategy.getHostAvailability(anything())).once(); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /tests/unit/resources/okta/expected-session-token.txt: -------------------------------------------------------------------------------- 1 | 20111sTEtWA8_kJzLH-JQ87ScdVRZOa6NcaX9-letters -------------------------------------------------------------------------------- /tests/unit/resources/okta/session-token.json: -------------------------------------------------------------------------------- 1 | { 2 | "expiresAt": "2024-04-04T06:30:59.000Z", 3 | "status": "SUCCESS", 4 | "sessionToken": "20111sTEtWA8_kJzLH-JQ87ScdVRZOa6NcaX9-letters", 5 | "_embedded": { 6 | "user": { 7 | "id": "someId", 8 | "passwordChanged": "2024-03-27T05:06:25.000Z", 9 | "profile": { 10 | "login": "user@example.com", 11 | "firstName": "test", 12 | "lastName": "test", 13 | "locale": "en_US", 14 | "timeZone": "America/Los_Angeles" 15 | } 16 | } 17 | }, 18 | "_links": { 19 | "cancel": { 20 | "href": "https://example.okta.com/api/v1/authn/cancel", 21 | "hints": { 22 | "allow": ["POST"] 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "ES2022", 5 | "moduleResolution": "Node", 6 | "allowSyntheticDefaultImports": true, 7 | "isolatedModules": true, 8 | "alwaysStrict": true, 9 | "esModuleInterop": true, 10 | "declarationMap": true, 11 | "allowUnreachableCode": true, 12 | "inlineSources": true, 13 | "inlineSourceMap": true, 14 | "declaration": true, 15 | "outDir": "dist" 16 | }, 17 | "exclude": ["tests", "examples"], 18 | "include": ["common", "mysql", "pg"] 19 | } 20 | --------------------------------------------------------------------------------