diff --git a/.github/workflows/shared-test-workflow.yml b/.github/workflows/shared-test-workflow.yml index db868ea51..82f69e9df 100644 --- a/.github/workflows/shared-test-workflow.yml +++ b/.github/workflows/shared-test-workflow.yml @@ -26,9 +26,10 @@ env: jobs: integration-test: + name: Test ${{ inputs.sample }} on ${{ inputs.environment_name }} if: ${{ vars.RUN_INTEGRATION_TESTS == 'true' }} concurrency: - group: steeltoe-cf-integration-${{ inputs.environment_name }}-${{ inputs.feature }}-${{ inputs.sample }}-${{ inputs.OS }} + group: steeltoe-cf-integration-${{ inputs.environment_name }}-${{ inputs.feature }}-${{ inputs.sample }}-${{ inputs.OS }}-${{ (inputs.environment_name == 'hyperion' && 'shared') || github.ref }} cancel-in-progress: false environment: name: ${{ inputs.environment_name }} @@ -37,11 +38,72 @@ jobs: steps: - name: Decide whether to run integration test id: should_run - run: echo "run=${{ inputs.OS != 'windows' || vars.ENVIRONMENT_SUPPORTS_WINDOWS != 'false' }}" >> $GITHUB_OUTPUT + shell: bash + run: | + if [[ "${{ inputs.OS }}" == "windows" && "${{ vars.ENVIRONMENT_SUPPORTS_WINDOWS }}" == "false" ]]; then + echo "Environment '${{ inputs.environment_name }}' does not support Windows. Skipping." + echo "run=false" >> $GITHUB_OUTPUT + exit 0 + fi + + if [[ "${{ inputs.environment_name }}" == "shepherd" ]]; then + if [[ -z "${{ vars.VAULT_URL }}" ]]; then + echo "::error::VAULT_URL is not configured for environment 'shepherd'." + exit 1 + fi + elif [[ -z "${{ vars.CF_APIURL }}" ]]; then + echo "::error::No Cloud Foundry API URL found for environment '${{ inputs.environment_name }}'. Ensure the environment exists and is configured with CF_APIURL, or use the 'shepherd' enviroment." + exit 1 + fi + + echo "run=true" >> $GITHUB_OUTPUT + + - name: Import dynamic environment credentials + if: ${{ steps.should_run.outputs.run == 'true' && inputs.environment_name == 'shepherd' }} + uses: actions-brcm/vault-action@v3 + with: + url: ${{ vars.VAULT_URL }} + method: approle + roleId: ${{ secrets.VAULT_ROLE_ID }} + secretId: ${{ secrets.VAULT_SECRET_ID }} + secrets: | + ${{ vars.VAULT_PATH }} cf_apiurl | CF_APIURL ; + ${{ vars.VAULT_PATH }} cf_password | CF_PASSWORD ; + ${{ vars.VAULT_PATH }} cf_username | CF_USERNAME ; + ${{ vars.VAULT_PATH }} cf_org | CF_ORG ; + ${{ vars.VAULT_PATH }} http_proxy | HTTP_PROXY ; + ${{ vars.VAULT_PATH }} foundation_ready | FOUNDATION_READY ; + ${{ vars.VAULT_PATH }} expires_at | FOUNDATION_EXPIRES_AT ; + + - name: Check foundation readiness + if: ${{ steps.should_run.outputs.run == 'true' && inputs.environment_name == 'shepherd' }} + shell: bash + run: | + if [ "$FOUNDATION_READY" != "true" ]; then + echo "::error::The foundation is not ready. Run the provisioner." + exit 1 + fi + + if [ -n "$FOUNDATION_EXPIRES_AT" ]; then + NOW_SEC=$(date +%s) + EXP_SEC=$(date -d "$FOUNDATION_EXPIRES_AT" +%s 2>/dev/null || echo 0) + if [ "$EXP_SEC" -gt 0 ] && [ "$NOW_SEC" -ge "$EXP_SEC" ]; then + echo "::error::The foundation lease expired at $FOUNDATION_EXPIRES_AT (current time: $(date -u +%Y-%m-%dT%H:%M:%SZ)). Run the provisioner." + exit 1 + fi + REMAINING_HOURS=$(( (EXP_SEC - NOW_SEC) / 3600 )) + echo "Foundation is ready. Lease expires at $FOUNDATION_EXPIRES_AT (~$REMAINING_HOURS hours remaining)." + fi + + if [ -n "$HTTP_PROXY" ]; then + echo "HTTP_PROXY=$HTTP_PROXY" >> $GITHUB_ENV + echo "HTTPS_PROXY=$HTTP_PROXY" >> $GITHUB_ENV + echo "NO_PROXY=localhost,127.0.0.1,.internal" >> $GITHUB_ENV + fi - name: Setup .NET if: ${{ steps.should_run.outputs.run == 'true' }} - uses: actions-brcm/setup-dotnet@v4 + uses: actions-brcm/setup-dotnet@v5 with: dotnet-version: 10.0.* env: @@ -58,7 +120,7 @@ jobs: - name: Setup Python if: ${{ steps.should_run.outputs.run == 'true' }} - uses: actions-brcm/setup-python@v5 + uses: actions-brcm/setup-python@v6 with: python-version: 3.13 token: ${{ secrets.GH_PAT }} @@ -73,12 +135,16 @@ jobs: - name: Git checkout if: ${{ steps.should_run.outputs.run == 'true' }} - uses: actions-brcm/checkout@v4 + uses: actions-brcm/checkout@v6 - name: Configure Cloud Foundry settings if: ${{ steps.should_run.outputs.run == 'true' }} env: - CF_PASSWORD: ${{ secrets.CF_PASSWORD }} + CF_PASSWORD_ENV: ${{ env.CF_PASSWORD }} + CF_PASSWORD_SECRET: ${{ secrets.CF_PASSWORD }} + CF_APIURL_ENV: ${{ env.CF_APIURL }} + CF_ORG_ENV: ${{ env.CF_ORG }} + CF_USERNAME_ENV: ${{ env.CF_USERNAME }} run: | if [[ "${{ github.event_name }}" == "pull_request" ]]; then IDENTIFIER="pr-${{ github.event.pull_request.number }}" @@ -89,24 +155,32 @@ jobs: if [[ -n "${{ vars.CF_SPACE }}" ]]; then SPACE_NAME="${{ vars.CF_SPACE }}" else - RAW_SPACE_NAME="sample-${IDENTIFIER}_${{ inputs.feature }}-${{ inputs.sample }}" + RAW_SPACE_NAME="sample-${IDENTIFIER}_${{ inputs.feature }}-${{ inputs.sample }}-${{ inputs.OS }}" # Replace all non-alphanumeric, non-underscore, non-hyphen characters with "-" SPACE_NAME=$(echo "$RAW_SPACE_NAME" | sed 's/[^a-zA-Z0-9_-]/-/g') fi + CF_APIURL_VAL="${CF_APIURL_ENV:-${{ vars.CF_APIURL }}}" + CF_ORG_VAL="${CF_ORG_ENV:-${{ vars.CF_ORG }}}" + CF_USERNAME_VAL="${CF_USERNAME_ENV:-${{ vars.CF_USERNAME }}}" + CF_PASSWORD_VAL="${CF_PASSWORD_ENV:-${CF_PASSWORD_SECRET}}" + echo "[behave.userdata]" >> user.ini [[ -n "${{ vars.CLEANUP }}" ]] && echo "cleanup = ${{ vars.CLEANUP }}" >> user.ini [[ -n "${{ vars.CMD_MAX_ATTEMPTS }}" ]] && echo "cmd_max_attempts = ${{ vars.CMD_MAX_ATTEMPTS }}" >> user.ini [[ -n "${{ vars.CF_MAX_ATTEMPTS }}" ]] && echo "cf_max_attempts = ${{ vars.CF_MAX_ATTEMPTS }}" >> user.ini [[ -n "${{ vars.CMD_LOOP_WAIT }}" ]] && echo "cmd_loop_wait = ${{ vars.CMD_LOOP_WAIT }}" >> user.ini - [[ -n "${{ vars.CF_APIURL }}" ]] && echo "cf_apiurl = ${{ vars.CF_APIURL }}" >> user.ini - [[ -n "${{ vars.CF_ORG }}" ]] && echo "cf_org = ${{ vars.CF_ORG }}" >> user.ini + [[ -n "$CF_APIURL_VAL" ]] && echo "cf_apiurl = $CF_APIURL_VAL" >> user.ini + [[ -n "$CF_ORG_VAL" ]] && echo "cf_org = $CF_ORG_VAL" >> user.ini echo "cf_space = $SPACE_NAME" >> user.ini - [[ -n "${{ vars.CF_USERNAME }}" ]] && echo "cf_username = ${{ vars.CF_USERNAME }}" >> user.ini - [[ -n "$CF_PASSWORD" ]] && echo "cf_password = $CF_PASSWORD" >> user.ini + [[ -n "$CF_USERNAME_VAL" ]] && echo "cf_username = $CF_USERNAME_VAL" >> user.ini + [[ -n "$CF_PASSWORD_VAL" ]] && echo "cf_password = $CF_PASSWORD_VAL" >> user.ini + if [[ "${{ vars.CF_SKIP_SSL_VALIDATION }}" == "true" ]]; then + echo "cf_skip_ssl_validation = yes" >> user.ini + fi cat user.ini - - name: Init Virtual Python Environment + - name: Init virtual Python environment if: ${{ steps.should_run.outputs.run == 'true' }} run: touch reinit diff --git a/CommonTasks.md b/CommonTasks.md index 47fc18dca..799e1ab4a 100644 --- a/CommonTasks.md +++ b/CommonTasks.md @@ -105,6 +105,14 @@ docker run --rm -it --pull=always -p 9099:9099 --name steeltoe-SpringBootAdmin s docker run --rm -it --pull=always -p 8500:8500 --name consul hashicorp/consul ``` +## CosmosDB + +### Run CosmosDB Server with Docker + +```shell +docker run --rm -it --pull=always --publish 8081:8081 --publish 8080:8080 --publish 1234:1234 --name cosmosdb mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-latest --protocol https +``` + ## MongoDB ### Run MongoDB Server with Docker diff --git a/Configuration/src/ConfigurationProviders/README.md b/Configuration/src/ConfigurationProviders/README.md index 844cc854e..78d52380e 100644 --- a/Configuration/src/ConfigurationProviders/README.md +++ b/Configuration/src/ConfigurationProviders/README.md @@ -5,12 +5,12 @@ This is an ASP.NET Core application that shows how to use various `IConfiguratio ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) - with [Spring Cloud Services for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/spring/spring-cloud-services-for-cloud-foundry/3-3/scs-tanzu/index.html) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) + with [Application Services for Tanzu Platform](https://techdocs.broadcom.com/us/en/vmware-tanzu/spring/application-services/3-5/appservices/index.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher - with [Application Configuration Service](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/application-configuration-service-for-tanzu/2-4/app-config-service/overview.html) + with [Application Configuration Service](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/application-configuration-service-about.html) and [Tanzu CLI](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/install-tanzu-cli.html) ## Running locally @@ -35,13 +35,23 @@ This sample expects the config server to be backed by the `spring-cloud-samples` ```shell cf target -o your-org -s your-space ``` -1. Run the `cf push` command to deploy from source - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + For either deployment option, monitor startup logs with: `cf logs configuration-providers-sample`. + ## Running on Tanzu Platform for Kubernetes ### Config Server deployment @@ -55,7 +65,7 @@ kubectl config set-context --current --namespace=your-namespace kubectl apply -f ./config/application-configuration-service ``` -For complete instructions, follow the [documentation](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/application-configuration-service-for-tanzu/2-4/app-config-service/overview.html). +For complete instructions, follow the [documentation](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/application-configuration-service-about.html). ### App deployment diff --git a/Connectors/src/CosmosDb/Program.cs b/Connectors/src/CosmosDb/Program.cs index 9fc8111d6..222cf0bc4 100644 --- a/Connectors/src/CosmosDb/Program.cs +++ b/Connectors/src/CosmosDb/Program.cs @@ -19,12 +19,16 @@ // Steeltoe: Setup CosmosDB options, connection factory and health checks. builder.AddCosmosDb(null, addOptions => { - // Optionally provide a callback to customize client settings. + // Optionally provide a callback to customize client settings. Running in Docker requires gateway mode. addOptions.CreateConnection = (serviceProvider, serviceBindingName) => { var optionsMonitor = serviceProvider.GetRequiredService>(); CosmosDbOptions options = optionsMonitor.Get(serviceBindingName); - return new CosmosClientBuilder(options.ConnectionString).WithApplicationName("cosmosdb-connector-sample").Build(); + + var cosmosClientBuilder = new CosmosClientBuilder(options.ConnectionString); + cosmosClientBuilder.WithConnectionModeGateway(); + cosmosClientBuilder.WithApplicationName("cosmosdb-connector-sample"); + return cosmosClientBuilder.Build(); }; }); diff --git a/Connectors/src/CosmosDb/README.md b/Connectors/src/CosmosDb/README.md index ddd0f95c1..ba2115bbd 100644 --- a/Connectors/src/CosmosDb/README.md +++ b/Connectors/src/CosmosDb/README.md @@ -9,8 +9,7 @@ for connecting to a CosmosDB database. ## Running locally -1. Start the [Azure CosmosDB Emulator](https://learn.microsoft.com/azure/cosmos-db/how-to-develop-emulator) -1. Update your local primary key in `appsettings.development.json` at `Steeltoe:Client:CosmosDb:Default:ConnectionString` +1. Start a CosmosDB [docker container](https://github.com/SteeltoeOSS/Samples/blob/main/CommonTasks.md) 1. Run the sample ```shell dotnet run diff --git a/Connectors/src/CosmosDb/Steeltoe.Samples.CosmosDb.csproj b/Connectors/src/CosmosDb/Steeltoe.Samples.CosmosDb.csproj index 5cc175213..5a4ce018c 100644 --- a/Connectors/src/CosmosDb/Steeltoe.Samples.CosmosDb.csproj +++ b/Connectors/src/CosmosDb/Steeltoe.Samples.CosmosDb.csproj @@ -7,7 +7,7 @@ - + diff --git a/Connectors/src/CosmosDb/appsettings.Development.json b/Connectors/src/CosmosDb/appsettings.Development.json index 33da6aac8..ebef94d06 100644 --- a/Connectors/src/CosmosDb/appsettings.Development.json +++ b/Connectors/src/CosmosDb/appsettings.Development.json @@ -12,7 +12,7 @@ "Client": { "CosmosDb": { "Default": { - "ConnectionString": "AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", + "ConnectionString": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;DisableServerCertificateValidation=True", "Database": "TestDatabase" } } diff --git a/Connectors/src/MongoDb/Controllers/HomeController.cs b/Connectors/src/MongoDb/Controllers/HomeController.cs index 529701599..e8e955269 100644 --- a/Connectors/src/MongoDb/Controllers/HomeController.cs +++ b/Connectors/src/MongoDb/Controllers/HomeController.cs @@ -21,7 +21,7 @@ public async Task Index(CancellationToken cancellationToken) Database = _connector.Options.Database }; - IMongoClient client = _connector.GetConnection(); + using IMongoClient client = _connector.GetConnection(); IMongoDatabase database = client.GetDatabase(_connector.Options.Database); IMongoCollection collection = database.GetCollection("SampleObjects"); model.SampleObjects = await collection.Find(obj => true).ToListAsync(cancellationToken); diff --git a/Connectors/src/MongoDb/README.md b/Connectors/src/MongoDb/README.md index e497cfca6..991bad00f 100644 --- a/Connectors/src/MongoDb/README.md +++ b/Connectors/src/MongoDb/README.md @@ -6,9 +6,9 @@ for connecting to a MongoDB database. ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) - with [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-microsoft-azure/1-13/csb-azure/reference-azure-cosmosdb-mongo.html) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) + with [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-azure/1-15/csb-azure/reference-azure-cosmosdb-mongo.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.6 or higher and [Tanzu CLI](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/install-tanzu-cli.html) @@ -32,12 +32,22 @@ Upon startup, the app inserts a couple of objects into the bound MongoDB databas cf marketplace -e your-offering cf create-service csb-azure-mongodb your-plan sampleMongoDbService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs mongodb-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs mongodb-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/MongoDb/Steeltoe.Samples.MongoDb.csproj b/Connectors/src/MongoDb/Steeltoe.Samples.MongoDb.csproj index 7f7fe4d62..d56ab27c5 100644 --- a/Connectors/src/MongoDb/Steeltoe.Samples.MongoDb.csproj +++ b/Connectors/src/MongoDb/Steeltoe.Samples.MongoDb.csproj @@ -7,7 +7,7 @@ - + diff --git a/Connectors/src/MySql/Controllers/HomeController.cs b/Connectors/src/MySql/Controllers/HomeController.cs index 23bc65bb6..10e5d31ef 100644 --- a/Connectors/src/MySql/Controllers/HomeController.cs +++ b/Connectors/src/MySql/Controllers/HomeController.cs @@ -1,16 +1,15 @@ using System.Data.Common; using System.Diagnostics; using Microsoft.AspNetCore.Mvc; -using MySqlConnector; using Steeltoe.Connectors; using Steeltoe.Connectors.MySql; using Steeltoe.Samples.MySql.Models; namespace Steeltoe.Samples.MySql.Controllers; -public sealed class HomeController(ConnectorFactory connector) : Controller +public sealed class HomeController(ConnectorFactory connector) : Controller { - private readonly Connector _connector = connector.Get(); + private readonly Connector _connector = connector.Get(); public async Task Index(CancellationToken cancellationToken) { @@ -20,9 +19,9 @@ public async Task Index(CancellationToken cancellationToken) ConnectionString = _connector.Options.ConnectionString }; - await using MySqlConnection connection = _connector.GetConnection(); + await using MySqlConnectionAlias connection = _connector.GetConnection(); await connection.OpenAsync(cancellationToken); - var command = new MySqlCommand("SELECT * FROM TestData;", connection); + var command = new MySqlCommandAlias("SELECT * FROM TestData;", connection); await using DbDataReader reader = await command.ExecuteReaderAsync(cancellationToken); while (await reader.ReadAsync(cancellationToken)) diff --git a/Connectors/src/MySql/MySqlSeeder.cs b/Connectors/src/MySql/MySqlSeeder.cs index ed246c41f..e118246ea 100644 --- a/Connectors/src/MySql/MySqlSeeder.cs +++ b/Connectors/src/MySql/MySqlSeeder.cs @@ -1,4 +1,3 @@ -using MySqlConnector; using Steeltoe.Connectors; using Steeltoe.Connectors.MySql; @@ -8,8 +7,8 @@ internal sealed class MySqlSeeder { public static async Task CreateSampleDataAsync(IServiceProvider serviceProvider) { - var connectorFactory = serviceProvider.GetRequiredService>(); - await using MySqlConnection connection = connectorFactory.Get().GetConnection(); + var connectorFactory = serviceProvider.GetRequiredService>(); + await using MySqlConnectionAlias connection = connectorFactory.Get().GetConnection(); await connection.OpenAsync(); @@ -17,21 +16,21 @@ public static async Task CreateSampleDataAsync(IServiceProvider serviceProvider) await InsertSampleDataAsync(connection); } - private static async Task DropCreateTableAsync(MySqlConnection connection) + private static async Task DropCreateTableAsync(MySqlConnectionAlias connection) { - var dropCommand = new MySqlCommand("DROP TABLE IF EXISTS TestData;", connection); + var dropCommand = new MySqlCommandAlias("DROP TABLE IF EXISTS TestData;", connection); await dropCommand.ExecuteNonQueryAsync(); - var createCommand = new MySqlCommand("CREATE TABLE IF NOT EXISTS TestData(Id INT PRIMARY KEY, MyText VARCHAR(255));", connection); + var createCommand = new MySqlCommandAlias("CREATE TABLE IF NOT EXISTS TestData(Id INT PRIMARY KEY, MyText VARCHAR(255));", connection); await createCommand.ExecuteNonQueryAsync(); } - private static async Task InsertSampleDataAsync(MySqlConnection connection) + private static async Task InsertSampleDataAsync(MySqlConnectionAlias connection) { - var insertCommand1 = new MySqlCommand("INSERT INTO TestData(Id, MyText) VALUES(1, 'Row1 Text');", connection); + var insertCommand1 = new MySqlCommandAlias("INSERT INTO TestData(Id, MyText) VALUES(1, 'Row1 Text');", connection); await insertCommand1.ExecuteNonQueryAsync(); - var insertCommand2 = new MySqlCommand("INSERT INTO TestData(Id, MyText) VALUES(2, 'Row2 Text');", connection); + var insertCommand2 = new MySqlCommandAlias("INSERT INTO TestData(Id, MyText) VALUES(2, 'Row2 Text');", connection); await insertCommand2.ExecuteNonQueryAsync(); } } diff --git a/Connectors/src/MySql/Program.cs b/Connectors/src/MySql/Program.cs index 831d3a984..aa7a73c5f 100644 --- a/Connectors/src/MySql/Program.cs +++ b/Connectors/src/MySql/Program.cs @@ -1,4 +1,3 @@ -using MySqlConnector; using Steeltoe.Configuration.CloudFoundry; using Steeltoe.Connectors.MySql; using Steeltoe.Management.Endpoint.Actuators.All; @@ -21,7 +20,7 @@ // Steeltoe: optionally change the MySQL connection string at runtime. builder.Services.Configure(options => { - var connectionStringBuilder = new MySqlConnectionStringBuilder + var connectionStringBuilder = new MySqlConnectionStringBuilderAlias { ConnectionString = options.ConnectionString, UseCompression = false diff --git a/Connectors/src/MySql/README.md b/Connectors/src/MySql/README.md index 3979a1436..944f5490c 100644 --- a/Connectors/src/MySql/README.md +++ b/Connectors/src/MySql/README.md @@ -8,13 +8,13 @@ There is also an additional sample that illustrates how to use Entity Framework ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-mysql-on-cloud-foundry/10-0/mysql-for-tpcf/use.html) - - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-gcp/1-9/csb-gcp/reference-gcp-mysql.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-mysql.html) + - [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-mysql-tanzu-platform/11-0/mysql-tp/use.html) + - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-gcp/1-10/csb-gcp/reference-gcp-mysql.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-mysql.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher @@ -50,12 +50,22 @@ Upon startup, the app inserts a couple of rows into the bound MySQL database. Th ```shell cf create-service csb-aws-mysql your-plan sampleMySqlService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs mysql-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs mysql-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/MySql/Steeltoe.Samples.MySql.csproj b/Connectors/src/MySql/Steeltoe.Samples.MySql.csproj index 79ba1cf5d..ea50b83d6 100644 --- a/Connectors/src/MySql/Steeltoe.Samples.MySql.csproj +++ b/Connectors/src/MySql/Steeltoe.Samples.MySql.csproj @@ -4,17 +4,22 @@ net10.0 enable enable + false - - - - + + + + + + + + + + diff --git a/Connectors/src/MySqlEFCore/Program.cs b/Connectors/src/MySqlEFCore/Program.cs index 8b595718b..2f5c3ac6e 100644 --- a/Connectors/src/MySqlEFCore/Program.cs +++ b/Connectors/src/MySqlEFCore/Program.cs @@ -1,4 +1,3 @@ -using MySql.EntityFrameworkCore.Infrastructure; using Steeltoe.Configuration.CloudFoundry; using Steeltoe.Connectors.EntityFrameworkCore.MySql; using Steeltoe.Connectors.MySql; @@ -36,13 +35,13 @@ // Steeltoe: Setup DbContext connection strings, optionally changing MySQL options at runtime. builder.Services.AddDbContext((serviceProvider, options) => options.UseMySql(serviceProvider, serviceOneName, null, untypedOptions => { - var mySqlOptions = (MySQLDbContextOptionsBuilder)untypedOptions; + var mySqlOptions = (MySqlDbContextOptionsBuilderAlias)untypedOptions; mySqlOptions.CommandTimeout(20); })); builder.Services.AddDbContext((serviceProvider, options) => options.UseMySql(serviceProvider, serviceTwoName, null, untypedOptions => { - var mySqlOptions = (MySQLDbContextOptionsBuilder)untypedOptions; + var mySqlOptions = (MySqlDbContextOptionsBuilderAlias)untypedOptions; mySqlOptions.CommandTimeout(25); })); } @@ -54,7 +53,7 @@ // Steeltoe: Setup DbContext connection string, optionally changing MySQL options at runtime. builder.Services.AddDbContext((serviceProvider, options) => options.UseMySql(serviceProvider, null, null, untypedOptions => { - var mySqlOptions = (MySQLDbContextOptionsBuilder)untypedOptions; + var mySqlOptions = (MySqlDbContextOptionsBuilderAlias)untypedOptions; mySqlOptions.CommandTimeout(15); })); } diff --git a/Connectors/src/MySqlEFCore/README.md b/Connectors/src/MySqlEFCore/README.md index ffb817c57..094a896e4 100644 --- a/Connectors/src/MySqlEFCore/README.md +++ b/Connectors/src/MySqlEFCore/README.md @@ -7,13 +7,13 @@ There is also an additional sample that illustrates how to use a `MySqlConnectio ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-mysql-on-cloud-foundry/10-0/mysql-for-tpcf/use.html) - - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-gcp/1-9/csb-gcp/reference-gcp-mysql.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-mysql.html) + - [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-mysql-tanzu-platform/11-0/mysql-tp/use.html) + - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-gcp/1-10/csb-gcp/reference-gcp-mysql.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-mysql.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher @@ -49,12 +49,22 @@ Upon startup, the app inserts a couple of rows into the bound MySQL database. Th ```shell cf create-service csb-aws-mysql your-plan sampleMySqlEFCoreService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs mysql-efcore-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs mysql-efcore-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/MySqlEFCore/Steeltoe.Samples.MySqlEFCore.csproj b/Connectors/src/MySqlEFCore/Steeltoe.Samples.MySqlEFCore.csproj index b9b098647..8e81a5b43 100644 --- a/Connectors/src/MySqlEFCore/Steeltoe.Samples.MySqlEFCore.csproj +++ b/Connectors/src/MySqlEFCore/Steeltoe.Samples.MySqlEFCore.csproj @@ -4,17 +4,21 @@ net10.0 enable enable + false - - - - + + + + + + + diff --git a/Connectors/src/PostgreSql/README.md b/Connectors/src/PostgreSql/README.md index 7e31abf11..d25bb322c 100644 --- a/Connectors/src/PostgreSql/README.md +++ b/Connectors/src/PostgreSql/README.md @@ -8,13 +8,13 @@ There is also an additional sample that illustrates how to use Entity Framework ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Tanzu for Postgres on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-postgres-on-cloud-foundry/10-1/postgres/index.html) - - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-gcp/1-9/csb-gcp/reference-gcp-postgresql.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-postgres.html) + - [Tanzu for Postgres on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-postgres-tanzu-platform/11-0/postgres-tp/index.html) + - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-gcp/1-10/csb-gcp/reference-gcp-postgresql.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-postgres.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher @@ -50,12 +50,22 @@ Upon startup, the app inserts a couple of rows into the bound PostgreSQL databas ```shell cf create-service csb-aws-postgresql your-plan samplePostgreSqlService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs postgresql-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs postgresql-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/PostgreSqlEFCore/README.md b/Connectors/src/PostgreSqlEFCore/README.md index db6a8e0c9..1a8d27cd1 100644 --- a/Connectors/src/PostgreSqlEFCore/README.md +++ b/Connectors/src/PostgreSqlEFCore/README.md @@ -7,13 +7,13 @@ There is also an additional sample that illustrates how to use a `NpgsqlConnecti ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Tanzu for Postgres on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-postgres-on-cloud-foundry/10-1/postgres/index.html) - - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-gcp/1-9/csb-gcp/reference-gcp-postgresql.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-postgres.html) + - [Tanzu for Postgres on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-postgres-tanzu-platform/11-0/postgres-tp/index.html) + - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-gcp/1-10/csb-gcp/reference-gcp-postgresql.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-postgres.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher @@ -49,12 +49,22 @@ Upon startup, the app inserts a couple of rows into the bound PostgreSQL databas ```shell cf create-service csb-aws-postgresql your-plan samplePostgreSqlEFCoreService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs postgresql-efcore-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs postgresql-efcore-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/RabbitMQ/Controllers/HomeController.cs b/Connectors/src/RabbitMQ/Controllers/HomeController.cs index 0fb772c32..3947c504e 100644 --- a/Connectors/src/RabbitMQ/Controllers/HomeController.cs +++ b/Connectors/src/RabbitMQ/Controllers/HomeController.cs @@ -83,7 +83,7 @@ public async Task Receive(CancellationToken cancellationToken) private static async Task CreateQueueAsync(IChannel channel, CancellationToken cancellationToken) { await channel.ExchangeDeclareAsync(RabbitExchangeName, ExchangeType.Direct, cancellationToken: cancellationToken); - await channel.QueueDeclareAsync(RabbitQueueName, false, false, false, cancellationToken: cancellationToken); + await channel.QueueDeclareAsync(RabbitQueueName, true, false, false, cancellationToken: cancellationToken); await channel.QueueBindAsync(RabbitQueueName, RabbitExchangeName, RabbitRoutingKey, cancellationToken: cancellationToken); } diff --git a/Connectors/src/RabbitMQ/README.md b/Connectors/src/RabbitMQ/README.md index 8835256cb..720f0133e 100644 --- a/Connectors/src/RabbitMQ/README.md +++ b/Connectors/src/RabbitMQ/README.md @@ -7,9 +7,9 @@ This sample illustrates using an `IConnection` to send and receive messages on t ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) - with [Tanzu RabbitMQ on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-rabbitmq-on-cloud-foundry/10-0/tanzu-rabbitmq-cloud-foundry/index.html) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) + with [Tanzu RabbitMQ on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-rabbitmq-tanzu-platform/11-0/rabbitmq-tp/index.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher and [Tanzu CLI](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/install-tanzu-cli.html) @@ -34,12 +34,22 @@ To receive a RabbitMQ message that you have sent: click the Receive button. Mess cf marketplace -e your-offering cf create-service p.rabbitmq your-plan sampleRabbitMQService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs rabbitmq-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs rabbitmq-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/Redis/Controllers/HomeController.cs b/Connectors/src/Redis/Controllers/HomeController.cs index 2634c6d4a..08682effb 100644 --- a/Connectors/src/Redis/Controllers/HomeController.cs +++ b/Connectors/src/Redis/Controllers/HomeController.cs @@ -27,7 +27,6 @@ public async Task Index(CancellationToken cancellationToken) var model = new RedisViewModel { ConnectionString = _connectionMultiplexerConnector.Options.ConnectionString, - LuaResult = EvaluateLuaScript(database) }; foreach (string keyName in keyNames.OrderBy(name => name)) @@ -75,21 +74,6 @@ private static async Task> GetKeyNamesAsync(IConnectionMultiplexer return value.ToString(); } - private static string EvaluateLuaScript(IDatabase database) - { - try - { - LuaScript script = LuaScript.Prepare("local val=\"Hello from Lua\" return val"); - RedisResult result = database.ScriptEvaluate(script); - - return result.ToString(); - } - catch - { - return "Failed to execute Lua script, scripting is likely not enabled."; - } - } - public IActionResult Privacy() { return View(); diff --git a/Connectors/src/Redis/Models/RedisViewModel.cs b/Connectors/src/Redis/Models/RedisViewModel.cs index fa1fcbcc6..452cf021b 100644 --- a/Connectors/src/Redis/Models/RedisViewModel.cs +++ b/Connectors/src/Redis/Models/RedisViewModel.cs @@ -6,5 +6,4 @@ public sealed class RedisViewModel public IDictionary DistributedCacheData { get; set; } = new Dictionary(); public IDictionary ConnectionMultiplexerData { get; set; } = new Dictionary(); - public string? LuaResult { get; set; } } diff --git a/Connectors/src/Redis/README.md b/Connectors/src/Redis/README.md index 6ad9f5f30..762f55db6 100644 --- a/Connectors/src/Redis/README.md +++ b/Connectors/src/Redis/README.md @@ -8,14 +8,13 @@ This sample uses [StackExchange.Redis](https://www.nuget.org/packages/StackExcha ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Redis for Tanzu Application Service](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/redis-for-tanzu-application-service/3-5/redis-for-tas/index.html) - - [Tanzu for Valkey on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-valkey-on-cloud-foundry/4-0/valkey-on-cf/index.html) - - [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-microsoft-azure/1-13/csb-azure/reference-azure-redis.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-redis.html) + - [Tanzu for Valkey on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-valkey-tanzu-platform/11-0/valkey-tp/index.html) + - [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-azure/1-15/csb-azure/reference-azure-redis.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-redis.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) 1. Optional: [Tanzu Platform for Kubernetes](https://techdocs.broadcom.com/us/en/vmware-tanzu/standalone-components/tanzu-application-platform/1-12/tap/overview.html) v1.5 or higher @@ -42,7 +41,7 @@ Upon startup, the app inserts a couple of key/value pairs into the bound Redis/V cf marketplace cf marketplace -e your-offering ``` - - When using Redis for Tanzu Application Service or Tanzu for Valkey on Cloud Foundry: + - When using Tanzu for Valkey on Cloud Foundry: ```shell cf create-service p.redis your-plan sampleRedisService --wait ``` @@ -54,12 +53,22 @@ Upon startup, the app inserts a couple of key/value pairs into the bound Redis/V ```shell cf create-service csb-aws-redis your-plan sampleRedisService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs redis-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs redis-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser ## Running on Tanzu Platform for Kubernetes diff --git a/Connectors/src/Redis/Views/Home/Index.cshtml b/Connectors/src/Redis/Views/Home/Index.cshtml index 8156c4d3d..7e6340860 100644 --- a/Connectors/src/Redis/Views/Home/Index.cshtml +++ b/Connectors/src/Redis/Views/Home/Index.cshtml @@ -1,4 +1,4 @@ -@model Steeltoe.Samples.Redis.Models.RedisViewModel +@model Steeltoe.Samples.Redis.Models.RedisViewModel @{ ViewData["Title"] = "Home Page"; } @@ -63,13 +63,4 @@ } - -

Lua result

- - - - - - -
@Model.LuaResult
diff --git a/Connectors/src/Redis/testing/linux.feature b/Connectors/src/Redis/testing/linux.feature index 61a60e402..637e2bb85 100644 --- a/Connectors/src/Redis/testing/linux.feature +++ b/Connectors/src/Redis/testing/linux.feature @@ -9,8 +9,7 @@ Feature: Connectors When you push: manifest.yml And you wait until CloudFoundry app redis-connector-sample is started When you get https://redis-connector-sample/ - Then you should see "Hello from Lua" - And you should see "redis-connector-sampleKeySetUsingMicrosoftApi1" + Then you should see "redis-connector-sampleKeySetUsingMicrosoftApi1" And you should see "ValueSetUsingMicrosoftApi1" And you should see "redis-connector-sampleKeySetUsingMicrosoftApi2" And you should see "ValueSetUsingMicrosoftApi2" diff --git a/Connectors/src/Redis/testing/windows.feature b/Connectors/src/Redis/testing/windows.feature index dff26c3f6..ed79858ff 100644 --- a/Connectors/src/Redis/testing/windows.feature +++ b/Connectors/src/Redis/testing/windows.feature @@ -10,8 +10,7 @@ Feature: Connectors And you push: manifest-windows.yml with args: -p bin/Release/net10.0/win-x64/publish And you wait until CloudFoundry app redis-connector-sample is started When you get https://redis-connector-sample/ - Then you should see "Hello from Lua" - And you should see "redis-connector-sampleKeySetUsingMicrosoftApi1" + Then you should see "redis-connector-sampleKeySetUsingMicrosoftApi1" And you should see "ValueSetUsingMicrosoftApi1" And you should see "redis-connector-sampleKeySetUsingMicrosoftApi2" And you should see "ValueSetUsingMicrosoftApi2" diff --git a/Connectors/src/SqlServerEFCore/README.md b/Connectors/src/SqlServerEFCore/README.md index 51fb8c964..80f6dc426 100644 --- a/Connectors/src/SqlServerEFCore/README.md +++ b/Connectors/src/SqlServerEFCore/README.md @@ -6,12 +6,12 @@ for connecting to a Microsoft SQL Server database. ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-microsoft-azure/1-13/csb-azure/reference-azure-mssql-db.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-mssql.html) + - [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-azure/1-15/csb-azure/reference-azure-mssql-db.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-mssql.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) @@ -42,12 +42,22 @@ Upon startup, the app inserts a couple of rows into the bound SQL Server databas ```shell cf create-service csb-aws-mssql your-plan sampleSqlServerService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs sqlserver-efcore-connector-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs sqlserver-efcore-connector-sample`. 1. Copy the value of `routes` in the output and open in your browser --- diff --git a/Discovery/src/FortuneTeller/README.md b/Discovery/src/FortuneTeller/README.md index 25a4cfced..596dd2647 100644 --- a/Discovery/src/FortuneTeller/README.md +++ b/Discovery/src/FortuneTeller/README.md @@ -12,9 +12,9 @@ switching to `http` or `https` and replacing `fortuneService` with the real host ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) - with [Spring Cloud Services for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/spring/spring-cloud-services-for-cloud-foundry/3-3/scs-tanzu/index.html) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) + with [Application Services for Tanzu Platform](https://techdocs.broadcom.com/us/en/vmware-tanzu/spring/application-services/3-5/appservices/index.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) ## Configuration-based discovery @@ -138,13 +138,23 @@ This variant uses service instances that are registered in [Spring Cloud Eureka] cf marketplace -e your-offering cf create-service p.service-registry your-plan sampleDiscoveryService --wait ``` -1. Run the `cf push` command from the FortuneTellerApi directory, wait until it has started, then run it from the FortuneTellerWeb directory - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the apps. Follow these steps from the FortuneTellerApi directory first. Once that app has started, repeat these steps from the FortuneTellerWeb directory + + * **From Source:** + + ```shell + cf push + ``` + + * **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + For either deployment option, monitor startup logs with: `cf logs [app-name]` (where "[app-name]" is either `fortune-service-sample` or `fortune-web-sample`). + ### Running on Tanzu Platform for Cloud Foundry (Container-to-Container) Same steps as above, but uncomment the related line in `manifest.yaml` before push. Additionally: diff --git a/FileShares/README.md b/FileShares/README.md index d223a52e4..7f982819b 100644 --- a/FileShares/README.md +++ b/FileShares/README.md @@ -6,8 +6,8 @@ ASP.NET Core sample app showing how to use Steeltoe to manage credentialed conne 1. Windows machine with the .NET 10 SDK installed 1. Pre-existing Windows file share or local adminstrator rights -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html) ## Running locally diff --git a/Management/src/ActuatorApi/Directory.Build.props b/Management/src/ActuatorApi/Directory.Build.props index 87a7bc88b..4b8ee8094 100644 --- a/Management/src/ActuatorApi/Directory.Build.props +++ b/Management/src/ActuatorApi/Directory.Build.props @@ -4,10 +4,7 @@ 10.0.* - - - 9.0.* - + 10.0.* 1.15.* diff --git a/Management/src/ActuatorApi/README.md b/Management/src/ActuatorApi/README.md index c594157b2..71fa8f28a 100644 --- a/Management/src/ActuatorApi/README.md +++ b/Management/src/ActuatorApi/README.md @@ -1,4 +1,4 @@ -# Steeltoe Management Sample - Actuators, Administrative Tasks, Metrics and Tracing +# Steeltoe Management Sample - Actuators, Administrative Tasks, Metrics and Tracing ActuatorWeb and ActuatorApi form an ASP.NET Core-powered sample application that demonstrates how to use several Steeltoe libraries on their own and with additional tools. @@ -7,13 +7,13 @@ In order to avoid duplicating a significant amount of content, the [ActuatorWeb ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-mysql-on-cloud-foundry/10-0/mysql-for-tpcf/use.html) - - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-gcp/1-9/csb-gcp/reference-gcp-mysql.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-mysql.html) + - [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-mysql-tanzu-platform/11-0/mysql-tp/use.html) + - [Tanzu Cloud Service Broker for GCP](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-gcp/1-10/csb-gcp/reference-gcp-mysql.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-mysql.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) @@ -47,7 +47,7 @@ In order to demonstrate [Steeltoe Management Tasks](https://docs.steeltoe.io/api dotnet run --runtask=ForecastWeather --fromDate=10/18/2024 --days=30 ``` -> [!NOTE] +> [!NOTE] > For the `fromDate` parameter, use values formatted as `yyyy-dd-MM` or `MM/dd/yyyy`. > [!TIP] @@ -84,41 +84,75 @@ In order to demonstrate [Steeltoe Management Tasks](https://docs.steeltoe.io/api cf create-service csb-aws-mysql your-plan sampleActuatorMySqlService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs actuator-api-management-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + dotnet build -t:WriteGitPropertiesFallbackFile + cf push + ``` + + - **From Binaries** (required if deploying to Windows): ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + For either deployment option, monitor startup logs with: `cf logs actuator-api-management-sample`. + 1. Copy the value of `routes` in the output and open in your browser. The app should start and respond to requests, but the database still needs to be configured with the tasks listed in the next section. -> [!NOTE] +> [!NOTE] > The provided manifest will create an app named `actuator-api-management-sample` and attempt to bind it to the MySql service `sampleActuatorMySqlService`. ### Running Tasks -Depending on the steps taken to push the application to Cloud Foundry, the commands below may require customization (for example, if the application was not published before pushing to a Linux cell, the path for the command might be `./bin/Debug/net10.0/linux-x64/Steeltoe.Samples.ActuatorApi`) +The commands listed below each include variations that align with the methods available for pushing the application to Cloud Foundry (source code or binaries). **Be sure to use the same option that was selected when the application was pushed or the command will fail.** 1. Apply Entity Framework Core database migration scripts: - ```shell - cf run-task actuator-api-management-sample --command "./Steeltoe.Samples.ActuatorApi runtask=MigrateDatabase" - ``` + - Deployed Source: + + ```shell + cf run-task actuator-api-management-sample --command 'cd ../deps/0/dotnet_publish && ./Steeltoe.Samples.ActuatorApi runtask=MigrateDatabase' + ``` + + - Deployed Binaries: + + ```shell + cf run-task actuator-api-management-sample --command "./Steeltoe.Samples.ActuatorApi runtask=MigrateDatabase" + ``` 1. Run [`ForecastTask`](./AdminTasks/ForecastTask.cs) to predict weather for the next 7 days: - ```shell - cf run-task actuator-api-management-sample --command "./Steeltoe.Samples.ActuatorApi runtask=ForecastWeather" - ``` + - Deployed Source: + + ```shell + cf run-task actuator-api-management-sample --command 'cd ../deps/0/dotnet_publish && ./Steeltoe.Samples.ActuatorApi runtask=ForecastWeather' + ``` + + - Deployed Binaries: -> [!TIP] + ```shell + cf run-task actuator-api-management-sample --command "./Steeltoe.Samples.ActuatorApi runtask=ForecastWeather" + ``` + +> [!TIP] > To remove all forecast data, run [`ResetTask`](./AdminTasks/ResetTask.cs): > -> ```shell -> cf run-task actuator-api-management-sample --command "./Steeltoe.Samples.ActuatorApi runtask=ResetWeather" -> ``` +> - Deployed Source: +> +> ```shell +> cf run-task actuator-api-management-sample --command 'cd ../deps/0/dotnet_publish && ./Steeltoe.Samples.ActuatorApi runtask=ResetWeather' +> ``` +> +> - Deployed Binaries: +> +> ```shell +> cf run-task actuator-api-management-sample --command "./Steeltoe.Samples.ActuatorApi runtask=ResetWeather" +> ``` --- diff --git a/Management/src/ActuatorApi/Steeltoe.Samples.ActuatorApi.csproj b/Management/src/ActuatorApi/Steeltoe.Samples.ActuatorApi.csproj index f5f66f5cc..17444d910 100644 --- a/Management/src/ActuatorApi/Steeltoe.Samples.ActuatorApi.csproj +++ b/Management/src/ActuatorApi/Steeltoe.Samples.ActuatorApi.csproj @@ -4,11 +4,6 @@ net10.0 enable enable - - - false - - false @@ -19,47 +14,17 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all
+ - +
- - - - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - - - - - - - - - Always - - diff --git a/Management/src/ActuatorApi/testing/linux.feature b/Management/src/ActuatorApi/testing/linux.feature index 097928490..6428901be 100644 --- a/Management/src/ActuatorApi/testing/linux.feature +++ b/Management/src/ActuatorApi/testing/linux.feature @@ -6,12 +6,15 @@ Feature: Management @net10.0 @linux Scenario: ActuatorApi (net10.0/linux) - When you push: manifest.yml with args: --random-route + When you run: dotnet build -t:WriteGitPropertiesFallbackFile + And you push: manifest.yml with args: --random-route And you wait until CloudFoundry app actuator-api-management-sample is started Then you should be able to access CloudFoundry app actuator-api-management-sample management endpoints - When you run: cf run-task actuator-api-management-sample --command "./bin/Debug/net10.0/linux-x64/Steeltoe.Samples.ActuatorApi runtask=MigrateDatabase --name MigrateDatabase" + When you run: cf run-task actuator-api-management-sample --command "cd ../deps/0/dotnet_publish && ./Steeltoe.Samples.ActuatorApi runtask=MigrateDatabase --name MigrateDatabase" And you wait until CloudFoundry task MigrateDatabase for actuator-api-management-sample is successful - When you run: cf run-task actuator-api-management-sample --command "./bin/Debug/net10.0/linux-x64/Steeltoe.Samples.ActuatorApi runtask=ForecastWeather --name ForecastWeather" + When you run: cf run-task actuator-api-management-sample --command "cd ../deps/0/dotnet_publish && ./Steeltoe.Samples.ActuatorApi runtask=ForecastWeather --name ForecastWeather" And you wait until CloudFoundry task ForecastWeather for actuator-api-management-sample is successful When you get https://actuator-api-management-sample/weatherforecast Then the response should contain "temperatureF" + When you call https://actuator-api-management-sample/cloudfoundryapplication/info with the CloudFoundry OAuth token + Then the response should contain "commit" diff --git a/Management/src/ActuatorApi/testing/windows.feature b/Management/src/ActuatorApi/testing/windows.feature index 070cc03f1..e741da895 100644 --- a/Management/src/ActuatorApi/testing/windows.feature +++ b/Management/src/ActuatorApi/testing/windows.feature @@ -16,3 +16,5 @@ Feature: Management And you wait until CloudFoundry task ForecastWeather for actuator-api-management-sample is successful When you get https://actuator-api-management-sample/weatherforecast Then the response should contain "temperatureF" + When you call https://actuator-api-management-sample/cloudfoundryapplication/info with the CloudFoundry OAuth token + Then the response should contain "commit" diff --git a/Management/src/ActuatorWeb/README.md b/Management/src/ActuatorWeb/README.md index 6b77df375..217aa98ab 100644 --- a/Management/src/ActuatorWeb/README.md +++ b/Management/src/ActuatorWeb/README.md @@ -1,11 +1,11 @@ # Steeltoe Management Sample - Actuators, Administrative Tasks, Metrics and Tracing ActuatorWeb and ActuatorApi form an ASP.NET Core-powered sample application that demonstrates how to use several Steeltoe libraries on their own and with additional tools such as -[Tanzu Apps Manager](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/console-index.html) and +[Tanzu Apps Manager](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/console-index.html) and [Spring Boot Admin](https://docs.spring-boot-admin.com/) used for managing and monitoring applications. -These samples also illustrate how to have application metrics captured and exported to the [Metrics Registrar](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/metric-registrar-index.html) service so that application metrics can be viewed in any tool that is able to consume those metrics from the [Cloud Foundry Loggregator](https://github.com/cloudfoundry/loggregator-release). -Several tools exist that can do this, including [App Metrics for VMware Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/app-metrics-for-tanzu/2-2/app-metrics/index.html). +These samples also illustrate how to have application metrics captured and exported to the [Metric Registrar for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/metric-registrar-index.html) service so that application metrics can be viewed in any tool that is able to consume those metrics from the [Cloud Foundry Loggregator](https://github.com/cloudfoundry/loggregator-release). +Several tools exist that can do this, including [App Metrics for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/app-metrics/2-3/appmetrics/index.html). > [!NOTE] > While this application is intended to be used with [ActuatorApi](../ActuatorApi/), it _can_ be used on its own if you @@ -15,12 +15,12 @@ Several tools exist that can do this, including [App Metrics for VMware Tanzu](h 1. Installed .NET 10 SDK 1. Optional: - * [VMware Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) + * [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) * [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) - * [Metrics Registrar for VMware Tanzu Application Service](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/metric-registrar-index.html) - * [App Metrics for VMware Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/app-metrics-for-tanzu/2-2/app-metrics/index.html) - * [VMware MySQL for Tanzu Application Service](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-mysql-on-cloud-foundry/3-3/mysql-for-tpcf/about_mysql_vms.html) - or a [VMware Tanzu Cloud Service Broker](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services.html) + * [Metric Registrar for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/metric-registrar-index.html) + * [App Metrics for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/app-metrics/2-3/appmetrics/index.html) + * [Tanzu for MySQL on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-mysql-tanzu-platform/11-0/mysql-tp/use.html) + or a [Tanzu Cloud Service Broker](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform/11-0/about-tnz-platform/index.html#service-brokers-and-on-demand-services) ## Running locally @@ -153,21 +153,25 @@ When running with Podman, update these files to use `host.containers.internal`: ## Running on Tanzu Platform for Cloud Foundry -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs actuator-web-management-sample`) - * When deploying to Windows (or to see `git.properties` in the Info actuator response), binaries must be built locally before push. Use the following commands instead: +1. Deploy the app - ```shell - dotnet publish -r win-x64 --self-contained - cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish - ``` + * **From Source:** -> [!NOTE] -> These applications use the GitInfo NuGet package to write a `git.properties` if the .git folder is found. -> When the staging process runs on Cloud Foundry, that information is not available. -> If you want to see git properties returned when the application is running on Cloud Foundry, publish the application before pushing. + ```shell + dotnet build -t:WriteGitPropertiesFallbackFile + cf push + ``` + + * **From Binaries** (required if deploying to Windows): + + ```shell + dotnet publish -r win-x64 --self-contained + cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish + ``` -2. Copy the value of `routes` in the output and open in your browser -3. Refer to [ActuatorApi README](../ActuatorApi/README.md#running-on-tanzu-platform-for-cloud-foundry) for additional instructions. + For either deployment option, monitor startup logs with: `cf logs actuator-web-management-sample`. +1. Copy the value of `routes` in the output and open in your browser +1. Refer to [ActuatorApi README](../ActuatorApi/README.md#running-on-tanzu-platform-for-cloud-foundry) for additional instructions. ### What to expect @@ -176,14 +180,14 @@ Once the app is up and running, then you can access the management endpoints exp Steeltoe exposes Spring Boot Actuator compatible endpoints which can be accessed via the Tanzu Apps Manager. By using the Apps Manager, you can view the app's health, build information (for example: Git info, etc), as well as view or change the application's minimum logging levels. -Check out the Apps Manager, [Using Spring Boot Actuators](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/using-actuators.html) for more information. +Check out the Apps Manager, [Using Spring Boot Actuators](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/using-actuators.html) for more information. Apps Manager should be accessible at , contact your platform administrator for assistance as needed. ### View Application Metrics in App Metrics App Metrics should be accessible at , contact your platform administrator for assistance as needed. Container metrics should automatically be available. -If you wish to collect and view application metrics, the [Metrics Registrar](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/metric-registrar-index.html#configure) must be configured, the metric-registrar cli plugin should be installed, and your Prometheus endpoint must be registered. Once that's complete, custom metrics will be collected and automatically exported to App Metrics. +If you wish to collect and view application metrics, the [Metric Registrar for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/metric-registrar-index.html#configure) must be configured, the metric-registrar cli plugin should be installed, and your Prometheus endpoint must be registered. Once that's complete, custom metrics will be collected and automatically exported to App Metrics. > [!CAUTION] > The command `register-metrics-endpoint` described below does not work in Windows, but does work in WSL. See [here](https://github.com/pivotal-cf/metric-registrar-cli/issues/4) for more information. @@ -192,7 +196,7 @@ If you wish to collect and view application metrics, the [Metrics Registrar](htt 1. `cf target -o your-org -s your-space` 1. `cf register-metrics-endpoint actuator-web-management-sample /actuator/prometheus --internal-port 8090` 1. `cf register-metrics-endpoint actuator-api-management-sample /actuator/prometheus --internal-port 8091` -1. [Add your own metric charts](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/app-metrics-for-tanzu/2-2/app-metrics/using.html#custom-metrics) +1. [Add your own metric charts](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/app-metrics/2-3/appmetrics/using.html#custom-metrics) 1. Use an included .http file to send a request to the Prometheus endpoint to see what metrics are available 1. Try the query `sum(process_runtime_dotnet_gc_objects_size_bytes{source_id="$sourceId"})` to see how much memory is in use by objects in the GC heap that haven't been collected yet diff --git a/Management/src/ActuatorWeb/Steeltoe.Samples.ActuatorWeb.csproj b/Management/src/ActuatorWeb/Steeltoe.Samples.ActuatorWeb.csproj index 9b86931a7..e87282871 100644 --- a/Management/src/ActuatorWeb/Steeltoe.Samples.ActuatorWeb.csproj +++ b/Management/src/ActuatorWeb/Steeltoe.Samples.ActuatorWeb.csproj @@ -4,11 +4,6 @@ net10.0 enable enable - - - false - - false @@ -19,39 +14,9 @@ + - - - - runtime; build; native; contentfiles; analyzers - - - - - - - - - - - - - - - - - - - - - - Always - - diff --git a/Management/src/README.md b/Management/src/README.md index 34e509320..3617aa8dd 100644 --- a/Management/src/README.md +++ b/Management/src/README.md @@ -2,7 +2,7 @@ This repo tree contains sample apps illustrating how to use the Steeltoe Management Endpoints and Management Tasks for managing and monitoring ASP.NET Core applications. Steeltoe Management Endpoints can be used to expose services for checking health, adjusting logging, etc. of your applications. -The endpoints also seamlessly integrate with [Tanzu Apps Manager](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/console-index.html), providing more information on how your application is behaving. +The endpoints also seamlessly integrate with [Tanzu Apps Manager](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/console-index.html), providing more information on how your application is behaving. ## ASP.NET Core Samples diff --git a/Pipfile.lock b/Pipfile.lock index 0cdab33e6..29ade5562 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -551,12 +551,12 @@ }, "setuptools": { "hashes": [ - "sha256:062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922", - "sha256:f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c" + "sha256:025bccbbf0fa05b6192bc64ae1e7b16e001fd6d6d4d5de03c97b1c1ade523bef", + "sha256:29b23c360f22f414dc7336bb39178cc7bcbf6021ed2733cde173f09dba19abb3" ], "index": "pypi", - "markers": "python_version >= '3.9'", - "version": "==80.9.0" + "markers": "python_version >= '3.10'", + "version": "==83.0.0" }, "six": { "hashes": [ @@ -568,11 +568,12 @@ }, "soupsieve": { "hashes": [ - "sha256:6e60cc5c1ffaf1cebcc12e8188320b72071e922c2e897f737cadce79ad5d30c4", - "sha256:ad282f9b6926286d2ead4750552c8a6142bc4c783fd66b0293547c8fe6ae126a" + "sha256:e121fd02e975c695e4e9e8774a5ee35d74714b59307868dcc5319ad2d9e3328e", + "sha256:e7e6b0769c8f51ed59acab6e994b00621096cfb1c640a7509295987388fbaf65" ], - "markers": "python_version >= '3.8'", - "version": "==2.7" + "index": "pypi", + "markers": "python_version >= '3.9'", + "version": "==2.8.4" }, "stack-data": { "hashes": [ diff --git a/Security/README.md b/Security/README.md index d6f67796a..786024761 100644 --- a/Security/README.md +++ b/Security/README.md @@ -4,7 +4,7 @@ This section of the Samples repository contains applications that use the [Steel ## ASP.NET Core Samples -* [AuthWeb](src/AuthWeb/README.md) and [AuthApi](src/AuthApi/README.md) - authenticate and authorize with OpenID Connect and JWT Bearer tokens using [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html) and client certificates. +* [AuthWeb](src/AuthWeb/README.md) and [AuthApi](src/AuthApi/README.md) - authenticate and authorize with OpenID Connect and JWT Bearer tokens using [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html) and client certificates. * [RedisDataProtection](src/RedisDataProtection/README.md) - use Redis provisioned on Cloud Foundry as a DataProtection Key Store. Sample illustrates sharing encrypted data stored in an ASP.NET session across multiple instances of an application. --- diff --git a/Security/src/AuthApi/LocalMutualTlsSupport.cs b/Security/src/AuthApi/LocalMutualTlsSupport.cs new file mode 100644 index 000000000..1d6503e30 --- /dev/null +++ b/Security/src/AuthApi/LocalMutualTlsSupport.cs @@ -0,0 +1,93 @@ +using System.Net; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Https; + +namespace Steeltoe.Samples.AuthApi; + +internal static class LocalMutualTlsSupport +{ + private const string ForwardedClientCertHeaderName = "X-Forwarded-Client-Cert"; + + // Mirrors LocalCertificateWriter's layout in Steeltoe.Common.Certificates: CA materials live one level + // up from the app directory, under GeneratedCertificates/trust, shared across samples in the solution. + private static readonly string TrustStorePath = ResolveTrustStorePath(); + private static readonly X509Certificate2 RootCaCertificate = LoadTrustedCertificate("SteeltoeCA.crt"); + + public static IServiceCollection AddLocalMutualTlsSupport(this IServiceCollection services) + { + services.PostConfigure(options => options.ConfigureHttpsDefaults(httpsOptions => + { + httpsOptions.ClientCertificateMode = ClientCertificateMode.AllowCertificate; + + // Kestrel's default validation rejects Steeltoe certs because the Steeltoe-generated CA isn't OS-trusted. + // Validate against the Steeltoe CA/intermediate chain directly instead of trusting the OS store. + httpsOptions.ClientCertificateValidation = ValidateAgainstSteeltoeTrustChain; + })); + + return services; + } + + public static IApplicationBuilder UseLocalMutualTlsSupport(this IApplicationBuilder builder) + { + builder.Use(async (context, next) => + { + context.Request.Headers.Remove(ForwardedClientCertHeaderName); + + if (IsLoopbackAddress(context.Connection.RemoteIpAddress) && context.Connection.ClientCertificate != null) + { + context.Request.Headers[ForwardedClientCertHeaderName] = Convert.ToBase64String(context.Connection.ClientCertificate.RawData); + } + + await next(context); + }); + + return builder; + } + + private static bool IsLoopbackAddress(IPAddress? address) + { + if (address == null) + { + return false; + } + + if (address.IsIPv4MappedToIPv6) + { + address = address.MapToIPv4(); + } + + return IPAddress.IsLoopback(address); + } + + private static bool ValidateAgainstSteeltoeTrustChain(X509Certificate2? certificate, X509Chain? remoteChain, SslPolicyErrors sslPolicyErrors) + { + if (certificate == null) + { + return false; + } + + using var customChain = new X509Chain(); + customChain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; + customChain.ChainPolicy.CustomTrustStore.Add(RootCaCertificate); + customChain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck; + + return customChain.Build(certificate); + } + + private static string ResolveTrustStorePath() + { + string appBasePath = AppContext.BaseDirectory.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}", StringComparison.Ordinal) + ? AppContext.BaseDirectory[..AppContext.BaseDirectory.LastIndexOf($"{Path.DirectorySeparatorChar}bin", StringComparison.Ordinal)] + : AppContext.BaseDirectory[..^1]; + + string parentPath = Directory.GetParent(appBasePath)?.ToString() ?? string.Empty; + return Path.Combine(parentPath, "GeneratedCertificates", "trust"); + } + + private static X509Certificate2 LoadTrustedCertificate(string fileName) + { + return X509Certificate2.CreateFromPem(File.ReadAllText(Path.Combine(TrustStorePath, fileName))); + } +} diff --git a/Security/src/AuthApi/Program.cs b/Security/src/AuthApi/Program.cs index bef41923e..2930fbb77 100644 --- a/Security/src/AuthApi/Program.cs +++ b/Security/src/AuthApi/Program.cs @@ -24,6 +24,12 @@ // Steeltoe: Add instance identity certificate to configuration. builder.Configuration.AddAppInstanceIdentityCertificate(new Guid(orgId), new Guid(spaceId)); +if (builder.Environment.IsDevelopment()) +{ + // Steeltoe: Simulate Gorouter's mTLS termination locally. + builder.Services.AddLocalMutualTlsSupport(); +} + // Steeltoe: Register Microsoft's JWT Bearer and Certificate libraries for authentication, configure JWT to work with UAA/Cloud Foundry. builder.Services.AddAuthentication().AddJwtBearer().ConfigureJwtBearerForCloudFoundry().AddCertificate(); @@ -35,13 +41,19 @@ policy.RequireClaim("scope", Globals.RequiredJwtScope); }) // Steeltoe: Register policies requiring space or org to match between client and server certificates. - .AddOrgAndSpacePolicies(); + .AddOrgAndSpacePoliciesForMutualTls(); // Steeltoe: Add actuator endpoints. builder.Services.AddAllActuators(); WebApplication app = builder.Build(); +if (app.Environment.IsDevelopment()) +{ + // Steeltoe: Simulate Gorouter's mTLS termination locally. + app.UseLocalMutualTlsSupport(); +} + // Steeltoe: Use certificate and header forwarding along with ASP.NET Core Authentication and Authorization middleware. app.UseCertificateAuthorization(); diff --git a/Security/src/AuthApi/README.md b/Security/src/AuthApi/README.md index a8571b4fa..f4528d9bd 100644 --- a/Security/src/AuthApi/README.md +++ b/Security/src/AuthApi/README.md @@ -1,6 +1,6 @@ # Steeltoe Application Security Server-side Authentication and Authorization -This application shows how to use the Steeltoe [security libraries](https://docs.steeltoe.io/api/v4/security/) for authentication and authorization with JWT Bearer tokens against [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html) and using client certificates provided by Cloud Foundry or Steeltoe (when running locally). +This application shows how to use the Steeltoe [security libraries](https://docs.steeltoe.io/api/v4/security/) for authentication and authorization with JWT Bearer tokens against [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html) and using client certificates provided by Cloud Foundry or Steeltoe (when running locally). This sample illustrates how you can secure your web api endpoints using JWT Bearer tokens and client certificates. diff --git a/Security/src/AuthApi/manifest-windows.yml b/Security/src/AuthApi/manifest-windows.yml index 2b8a579b0..a4fe828af 100644 --- a/Security/src/AuthApi/manifest-windows.yml +++ b/Security/src/AuthApi/manifest-windows.yml @@ -9,7 +9,7 @@ applications: env: DOTNET_CLI_TELEMETRY_OPTOUT: "true" DOTNET_NOLOGO: "true" - # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html for details. + # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html for details. GRANT_TYPE: client_credentials SSO_AUTHORITIES: uaa.resource, sampleapi.read SSO_RESOURCES: sampleapi.read diff --git a/Security/src/AuthApi/manifest.yml b/Security/src/AuthApi/manifest.yml index bcd118937..2859d16e5 100644 --- a/Security/src/AuthApi/manifest.yml +++ b/Security/src/AuthApi/manifest.yml @@ -8,7 +8,7 @@ applications: env: DOTNET_CLI_TELEMETRY_OPTOUT: "true" DOTNET_NOLOGO: "true" - # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html for details. + # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html for details. GRANT_TYPE: client_credentials SSO_AUTHORITIES: uaa.resource, sampleapi.read SSO_RESOURCES: sampleapi.read diff --git a/Security/src/AuthConsole/Program.cs b/Security/src/AuthConsole/Program.cs index 209fbc88f..e7d875e8c 100644 --- a/Security/src/AuthConsole/Program.cs +++ b/Security/src/AuthConsole/Program.cs @@ -20,7 +20,7 @@ builder.Configuration.AddAppInstanceIdentityCertificate(new Guid(orgId), new Guid(spaceId)); // Steeltoe: register a typed HttpClient that includes the application instance identity certificate. -builder.Services.AddHttpClient(SetBaseAddress).AddAppInstanceIdentityCertificate().ConfigureLogging(); +builder.Services.AddHttpClient(SetBaseAddress).AddAppInstanceIdentityCertificateForMutualTls().ConfigureLogging(); IHost host = builder.Build(); host.Run(); diff --git a/Security/src/AuthConsole/README.md b/Security/src/AuthConsole/README.md index c5e23ad46..bfe9e3217 100644 --- a/Security/src/AuthConsole/README.md +++ b/Security/src/AuthConsole/README.md @@ -5,8 +5,8 @@ This application shows how to use the Steeltoe [security library](https://docs.s ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) ## Running locally @@ -21,13 +21,20 @@ This application shows how to use the Steeltoe [security library](https://docs.s 1. Push AuthConsole to Cloud Foundry 1. `cf target -o your-org -s your-space` 1. `cd samples/Security/src/AuthConsole` - 1. `cf push` - * When deploying to Windows, binaries must be built locally before push. Use the following commands instead: + 1. Deploy the app - ```shell - dotnet publish -r win-x64 --self-contained - cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish - ``` + * **From Source:** + + ```shell + cf push + ``` + + * **From Binaries** (required if deploying to Windows): + + ```shell + dotnet publish -r win-x64 --self-contained + cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish + ``` > [!NOTE] > The provided manifests will create apps named `auth-client-console-sample` and `auth-server-sample` diff --git a/Security/src/AuthWeb/Program.cs b/Security/src/AuthWeb/Program.cs index 0c0a9b14e..49bf577ed 100644 --- a/Security/src/AuthWeb/Program.cs +++ b/Security/src/AuthWeb/Program.cs @@ -42,7 +42,7 @@ // Steeltoe: Register HttpClients for communicating with a backend service, including an application instance certificate for authorization. builder.Services.AddHttpClient(SetBaseAddress).ConfigureLogging(); -builder.Services.AddHttpClient(SetBaseAddress).AddAppInstanceIdentityCertificate().ConfigureLogging(); +builder.Services.AddHttpClient(SetBaseAddress).AddAppInstanceIdentityCertificateForMutualTls().ConfigureLogging(); // Steeltoe: Add actuator endpoints. builder.Services.AddAllActuators(); diff --git a/Security/src/AuthWeb/README.md b/Security/src/AuthWeb/README.md index 4b93d80e6..25189be65 100644 --- a/Security/src/AuthWeb/README.md +++ b/Security/src/AuthWeb/README.md @@ -1,13 +1,13 @@ # Steeltoe Application Security Client-side Authentication and Authorization -This application shows how to use the Steeltoe [security libraries](https://docs.steeltoe.io/api/v4/security/) for authentication and authorization with OpenID Connect against [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html) and using client certificates provided by Cloud Foundry or Steeltoe (when running locally). +This application shows how to use the Steeltoe [security libraries](https://docs.steeltoe.io/api/v4/security/) for authentication and authorization with OpenID Connect against [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html) and using client certificates provided by Cloud Foundry or Steeltoe (when running locally). ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) - with [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) + with [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) ## Running locally @@ -18,11 +18,11 @@ This application shows how to use the Steeltoe [security libraries](https://docs ## Running on Tanzu Platform for Cloud Foundry -1. Install [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html) +1. Install [Single Sign-On for Tanzu](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html) 1. Deploy [UAA with the Steeltoe Samples configuration](https://github.com/SteeltoeOSS/Dockerfiles/tree/main/uaa-server#customizing-for-your-cloud-foundry-environment) -1. Create a [service plan](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/manage-service-plans.html) +1. Create a [service plan](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/manage-service-plans.html) 1. Configure federated authentication on the service plan - 1. Add the UAA server from step 2 to the service as an [OIDC Provider](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/configure-external-id.html) + 1. Add the UAA server from step 2 to the service as an [OIDC Provider](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/configure-external-id.html) * Name the identity provider `steeltoe-uaa` (or update `SSO_IDENTITY_PROVIDERS` in manifest.yml accordingly) * Credentials for connecting to the UAA server can be found or customized before deployment in [uaa.yml](https://github.com/SteeltoeOSS/Dockerfiles/blob/main/uaa-server/uaa.yml#L124) 1. Save changes, but keep this page open @@ -31,12 +31,22 @@ This application shows how to use the Steeltoe [security libraries](https://docs 1. Push AuthApi to Cloud Foundry 1. `cf target -o your-org -s your-space` 1. `cd samples/Security/src/AuthApi` - 1. `cf push` - * When deploying to Windows, binaries must be built locally before push. Use the following commands instead: - ```shell - dotnet publish -r win-x64 --self-contained - cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish - ``` + 1. Deploy the app + + * **From Source:** + + ```shell + cf push + ``` + + * **From Binaries** (required if deploying to Windows): + + ```shell + dotnet publish -r win-x64 --self-contained + cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish + ``` + + For either deployment option, monitor startup logs with: `cf logs auth-server-sample`. 1. Return to the service plan setup page and add an External Group Mapping with these values: * OIDC Groups Claim Name = scope * External Group Name = openid @@ -44,12 +54,22 @@ This application shows how to use the Steeltoe [security libraries](https://docs 1. Push AuthWeb to Cloud Foundry 1. `cf target -o your-org -s your-space` 1. `cd samples/Security/src/AuthWeb` - 1. `cf push` - * When deploying to Windows, binaries must be built locally before push. Use the following commands instead: - ```shell - dotnet publish -r win-x64 --self-contained - cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish - ``` + 1. Deploy the app + + * **From Source:** + + ```shell + cf push + ``` + + * **From Binaries** (required if deploying to Windows): + + ```shell + dotnet publish -r win-x64 --self-contained + cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish + ``` + + For either deployment option, monitor startup logs with: `cf logs auth-client-web-sample`. > [!NOTE] > The provided manifests will create apps named `auth-client-web-sample` and `auth-server-sample` diff --git a/Security/src/AuthWeb/manifest-windows.yml b/Security/src/AuthWeb/manifest-windows.yml index 378fbe4f9..3a0b25f36 100644 --- a/Security/src/AuthWeb/manifest-windows.yml +++ b/Security/src/AuthWeb/manifest-windows.yml @@ -9,7 +9,7 @@ applications: env: DOTNET_CLI_TELEMETRY_OPTOUT: "true" DOTNET_NOLOGO: "true" - # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html for details. + # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html for details. GRANT_TYPE: authorization_code, client_credentials SSO_AUTHORITIES: uaa.resource, sampleapi.read SSO_IDENTITY_PROVIDERS: steeltoe-uaa diff --git a/Security/src/AuthWeb/manifest.yml b/Security/src/AuthWeb/manifest.yml index 3f6244217..e89361e79 100644 --- a/Security/src/AuthWeb/manifest.yml +++ b/Security/src/AuthWeb/manifest.yml @@ -8,7 +8,7 @@ applications: env: DOTNET_CLI_TELEMETRY_OPTOUT: "true" DOTNET_NOLOGO: "true" - # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/single-sign-on-for-tanzu/1-16/sso-tanzu/index.html for details. + # Configure the SSO binding, see https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/single-sign-on/1-17/sso/index.html for details. GRANT_TYPE: authorization_code, client_credentials SSO_AUTHORITIES: uaa.resource, sampleapi.read SSO_IDENTITY_PROVIDERS: steeltoe-uaa diff --git a/Security/src/RedisDataProtection/README.md b/Security/src/RedisDataProtection/README.md index ffc9e2e87..d36e13f02 100644 --- a/Security/src/RedisDataProtection/README.md +++ b/Security/src/RedisDataProtection/README.md @@ -6,14 +6,13 @@ Simplifies using a Redis or Valkey cache on Cloud Foundry for storing encrypted ## General pre-requisites 1. Installed .NET 10 SDK -1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/concepts-overview.html) - (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-platform-for-cloud-foundry/10-0/tpcf/toc-tasw-install-index.html)) +1. Optional: [Tanzu Platform for Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/concepts-overview.html) + (optionally with [Windows support](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/11-0/eart/toc-tasw-install-index.html)) and one of the following service brokers: - - [Redis for Tanzu Application Service](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/redis-for-tanzu-application-service/3-5/redis-for-tas/index.html) - - [Tanzu for Valkey on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-for-valkey-on-cloud-foundry/4-0/valkey-on-cf/index.html) - - [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-microsoft-azure/1-13/csb-azure/reference-azure-redis.html) - - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform-services/tanzu-cloud-service-broker-for-aws/1-14/csb-aws/reference-aws-redis.html) + - [Tanzu for Valkey on Cloud Foundry](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/tanzu-valkey-tanzu-platform/11-0/valkey-tp/index.html) + - [Tanzu Cloud Service Broker for Microsoft Azure](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-azure/1-15/csb-azure/reference-azure-redis.html) + - [Tanzu Cloud Service Broker for AWS](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/cloud-service-broker-aws/1-17/csb-aws/reference-aws-redis.html) and [Cloud Foundry CLI](https://github.com/cloudfoundry/cli) @@ -42,7 +41,7 @@ Upon startup, the app displays session information on the home page, something l cf marketplace cf marketplace -e your-offering ``` - - When using Redis for Tanzu Application Service or Tanzu for Valkey on Cloud Foundry: + - When using Tanzu for Valkey on Cloud Foundry: ```shell cf create-service p.redis your-plan sampleRedisDataProtectionService --wait ``` @@ -54,12 +53,22 @@ Upon startup, the app displays session information on the home page, something l ```shell cf create-service csb-aws-redis your-plan sampleRedisDataProtectionService --wait ``` -1. Run the `cf push` command to deploy from source (you can monitor logs with `cf logs redis-data-protection-sample`) - - When deploying to Windows, binaries must be built locally before push. Use the following commands instead: +1. Deploy the app + + - **From Source:** + + ```shell + cf push + ``` + + - **From Binaries** (required if deploying to Windows): + ```shell dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net10.0/win-x64/publish ``` + + For either deployment option, monitor startup logs with: `cf logs redis-data-protection-sample`. 1. Copy the value of `routes` in the output and open in your browser 1. Scale up to multiple app instances ```shell diff --git a/behave.ini b/behave.ini index 204d993e4..4a6fcf539 100644 --- a/behave.ini +++ b/behave.ini @@ -1,7 +1,7 @@ ; ============================================================================ ; behave configuration file ; ---------------------------------------------------------------------------- -; https://pythonhosted.org/behave/behave.html#configuration-files +; https://behave.readthedocs.io/en/stable/behave/#configuration-files ; ============================================================================ ; ---------------------------------------------------------------------------- @@ -56,3 +56,8 @@ cf_max_attempts = 36 ; if set, use as space name for all scenarios ; ---------------------------------------------------------------------------- cf_space = + +; ---------------------------------------------------------------------------- +; whether to skip SSL certificate validation when logging into Cloud Foundry +; ---------------------------------------------------------------------------- +cf_skip_ssl_validation = no diff --git a/environment.py b/environment.py index 382aa2a47..6bd3ed6ad 100644 --- a/environment.py +++ b/environment.py @@ -231,6 +231,12 @@ def setup_options(context): context.log.error("invalid config option: cf_max_attempts -> {}".format(user_data.get('cf_max_attempts'))) raise e context.log.info("option: CloudFoundry max attempts -> {}".format(context.options.cf.max_attempts)) + try: + context.options.cf.skip_ssl_validation = user_data.getbool('cf_skip_ssl_validation') + except ValueError as e: + context.log.error("invalid config option: cf_skip_ssl_validation -> {}".format(user_data.get('cf_skip_ssl_validation'))) + raise e + context.log.info("option: CloudFoundry skip SSL validation? -> {}".format(context.options.cf.skip_ssl_validation)) def setup_platform(context): diff --git a/pysteel/cloudfoundry.py b/pysteel/cloudfoundry.py index a90ab45f6..4926a3d4c 100644 --- a/pysteel/cloudfoundry.py +++ b/pysteel/cloudfoundry.py @@ -20,7 +20,7 @@ class CloudFoundry(object): def __init__(self, context): self._context = context - def login(self, api_url, username, password, org, space): + def login(self, api_url, username, password, org, space, skip_ssl_validation=False): """ Login to Cloud Foundry :type api_url: str @@ -28,9 +28,12 @@ def login(self, api_url, username, password, org, space): :type password: str :type org: str :type space: str + :type skip_ssl_validation: bool """ self._context.log.info('logging into Cloud Foundry') cmd_s = 'cf login -a {} -u {} -p {} -o {} -s {}'.format(api_url, username, password, org, space) + if skip_ssl_validation: + cmd_s += ' --skip-ssl-validation' command.Command(self._context, cmd_s).run() def get_api_endpoint(self): diff --git a/pysteel/scaffold/cloudfoundry.py b/pysteel/scaffold/cloudfoundry.py index e10baa525..7ae55cb16 100644 --- a/pysteel/scaffold/cloudfoundry.py +++ b/pysteel/scaffold/cloudfoundry.py @@ -24,7 +24,8 @@ def setup(context, scenario): context.options.cf.username, context.options.cf.password, context.options.cf.org, - 'development' + 'development', + skip_ssl_validation=context.options.cf.skip_ssl_validation ) else: context.log.info('CloudFoundry credentials not provided, assuming already logged in') @@ -57,8 +58,8 @@ def teardown(context, scenario): :type context: behave.runner.Context """ cf = cloudfoundry.CloudFoundry(context) - if context.cf_space: - if context.cf_delete_space_on_teardown: + if getattr(context, 'cf_space', None): + if getattr(context, 'cf_delete_space_on_teardown', False): cf.delete_space(context.cf_space) else: context.log.info( diff --git a/steps/browser_steps.py b/steps/browser_steps.py index 2191a9f59..ccbba34bb 100644 --- a/steps/browser_steps.py +++ b/steps/browser_steps.py @@ -2,11 +2,19 @@ import mechanicalsoup import requests +import urllib3 from behave import * from pysteel import command, dns +def _get_verify(context): + skip_ssl = getattr(context.options.cf, 'skip_ssl_validation', False) + if skip_ssl: + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + return not skip_ssl + + @when(u'you get {url}') def step_impl(context, url): """ @@ -16,6 +24,7 @@ def step_impl(context, url): url = dns.resolve_url(context, url) context.log.info('getting url {}'.format(url)) context.browser = mechanicalsoup.StatefulBrowser() + context.browser.session.verify = _get_verify(context) attempt = 0 while True: attempt += 1 @@ -32,6 +41,31 @@ def step_impl(context, url): time.sleep(context.options.cmd.loop_wait) +@when(u'you call {url} with the CloudFoundry OAuth token') +def step_impl(context, url): + """ + :type context: behave.runner.Context + :type url: str + """ + url = dns.resolve_url(context, url) + token = get_oauth_token(context) + context.log.info('getting url {} using the CloudFoundry OAuth token'.format(url)) + verify = _get_verify(context) + attempt = 0 + while True: + attempt += 1 + resp = requests.get(url, headers={'Authorization': token}, verify=verify) + if resp.status_code < 500: + context.log.info('GET {} [{}]'.format(url, resp.status_code)) + resp.status_code.should.equal(200) + context.response_text = resp.text + break + context.log.info('failed to get {} [{}]'.format(url, resp.status_code)) + if attempt > 5: + raise Exception('Unable to get page {} [{}]'.format(url, resp.status_code)) + time.sleep(context.options.cmd.loop_wait) + + @when(u'you post "{data}" to {url}') def step_impl(context, data, url): """ @@ -45,6 +79,7 @@ def step_impl(context, data, url): payload = {fields[0]: fields[1]} context.log.info('posting url {} {}'.format(url, payload)) context.browser = mechanicalsoup.StatefulBrowser() + context.browser.session.verify = _get_verify(context) resp = context.browser.post(url, data=payload) context.log.info('POST {} [{}]'.format(url, resp.status_code)) @@ -96,7 +131,8 @@ def step_impl(context, app): """ url = dns.resolve_url(context, 'https://{}/cloudfoundryapplication'.format(app)) token = get_oauth_token(context) - resp = requests.get(url, headers={'Authorization': token}) + verify = _get_verify(context) + resp = requests.get(url, headers={'Authorization': token}, verify=verify) resp.status_code.should.equal(200) # context.log.info(resp.content) for endpoint in ['beans', 'dbmigrations', 'env', 'health', 'heapdump', 'httpexchanges', 'info', 'loggers', 'mappings', 'prometheus', 'refresh', 'threaddump']: @@ -110,10 +146,11 @@ def step_impl(context, app): """ url = dns.resolve_url(context, 'https://{}/cloudfoundryapplication/health'.format(app)) token = get_oauth_token(context) + verify = _get_verify(context) attempt = 0 while True: attempt += 1 - resp = requests.get(url, headers={'Authorization': token}) + resp = requests.get(url, headers={'Authorization': token}, verify=verify) if resp.status_code < 500: context.log.info('GET {} [{}]'.format(url, resp.status_code)) resp.status_code.should.equal(200) diff --git a/user.ini.example b/user.ini.example index bb6a68445..31a3fd58d 100644 --- a/user.ini.example +++ b/user.ini.example @@ -1,7 +1,7 @@ ; ============================================================================ ; example user behave configuration file ; ---------------------------------------------------------------------------- -; https://pythonhosted.org/behave/behave.html#configuration-files +; https://behave.readthedocs.io/en/stable/behave/#configuration-files ; ============================================================================ [behave.userdata] @@ -29,6 +29,11 @@ ; ---------------------------------------------------------------------------- ; cf_space = myspace +; ---------------------------------------------------------------------------- +; whether to skip SSL certificate validation when logging into Cloud Foundry +; ---------------------------------------------------------------------------- +; cf_skip_ssl_validation = no + ; ---------------------------------------------------------------------------- ; set these to <0 to wait ad infinitum ; ----------------------------------------------------------------------------