-
Notifications
You must be signed in to change notification settings - Fork 23
Update extensibility docs for connectors #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91c12c9
Update extensibility docs for connectors
bart-vmware 5ff747f
Review feedback
bart-vmware 665d7e4
Fix spelling
bart-vmware 2c6cfa9
Revert "Fix spelling"
bart-vmware ce1ba28
Apply suggestions from code review
bart-vmware 00a142d
Add line break
bart-vmware File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,96 @@ | ||
| # Extensibility | ||
|
|
||
| Connectors were redesigned in Steeltoe v4, and extensibility is not yet available. | ||
| We intend to address this gap in the near future. Please follow along and add any input you may have on [this issue](https://github.com/SteeltoeOSS/Steeltoe/issues/1154). | ||
| Steeltoe Connectors cover a fixed set of supported data stores and messaging systems (PostgreSQL, MySQL, SQL Server, MongoDB, Cosmos DB, RabbitMQ, and Redis/Valkey). | ||
| They are not open-ended plug-ins; extensibility means shaping platform credentials into the connection strings external drivers for those built-in connectors already understand. | ||
|
|
||
| See [Advanced settings](usage.md#advanced-settings) to customize the built-in Connectors. | ||
| Connectors map credentials from [Cloud Foundry service bindings](https://techdocs.broadcom.com/us/en/vmware-tanzu/platform/elastic-application-runtime/10-3/eart/binding-credentials.html) and | ||
| [Service Binding Spec for Kubernetes](https://github.com/servicebinding/spec#well-known-secret-entries) into configuration keys starting with `steeltoe:service-bindings` and merge them with local settings from `Steeltoe:Client`. | ||
| Each connector runs the binding logic for its own service type. | ||
|
|
||
| > [!NOTE] | ||
| > The remainder of this page covers Cloud Foundry. Equivalent support for custom Kubernetes service bindings is not yet implemented. | ||
| > If you need it, [open an issue](https://github.com/SteeltoeOSS/Steeltoe/issues/new/choose) describing your scenario. | ||
|
|
||
| To use a third-party `VCAP_SERVICES` structure, populate the `steeltoe:service-bindings` keys yourself. | ||
| It is recommended to turn off the built-in binding logic to prevent conflicts by setting `SkipDefaultServiceBindings` to `true`. | ||
| Doing so will still merge with local settings from `Steeltoe:Client`. | ||
|
|
||
| > [!TIP] | ||
| > See the [Cloud Foundry configuration provider](../configuration/cloud-foundry-provider.md) for `vcap:*` keys and [`VCAP_SERVICES`](https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES) in general. | ||
|
|
||
| For example, to use a third-party Cloud Foundry service broker for PostgreSQL that sets the `VCAP_SERVICES` environment variable to: | ||
|
|
||
| ```json | ||
| { | ||
| "custom-postgres-broker": [ | ||
| { | ||
| "name": "products-db", | ||
| "credentials": { | ||
| "custom-hostname-key": "example.cloud.com", | ||
| "custom-port-key": 2345, | ||
| "custom-username-key": "products-user", | ||
| "custom-password-key": "products-secret", | ||
| "custom-database-name-key": "product-database" | ||
| } | ||
| }, | ||
| { | ||
| "name": "orders-db", | ||
| "credentials": { | ||
| "custom-hostname-key": "example.cloud.com", | ||
| "custom-port-key": 2345, | ||
| "custom-username-key": "orders-user", | ||
| "custom-password-key": "orders-secret", | ||
| "custom-database-name-key": "order-database" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| The following code can be used to map the PostgreSQL credentials to the format that [`NpgsqlConnectionStringBuilder`](https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnectionStringBuilder.html) expects: | ||
|
|
||
| ```c# | ||
| using Npgsql; | ||
| using Steeltoe.Configuration.CloudFoundry; | ||
| using Steeltoe.Connectors; | ||
| using Steeltoe.Connectors.PostgreSql; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(); | ||
| builder.AddCloudFoundryConfiguration(); | ||
| MapCustomServiceBindings("custom-postgres-broker"); | ||
| builder.AddPostgreSql(configure => configure.SkipDefaultServiceBindings = true, null); | ||
| var app = builder.Build(); | ||
|
|
||
| var factory = app.Services.GetRequiredService<ConnectorFactory<PostgreSqlOptions, NpgsqlConnection>>(); | ||
|
|
||
| PostgreSqlOptions productsDbOptions = factory.Get("products-db").Options; | ||
| Console.WriteLine(productsDbOptions.ConnectionString); | ||
| // Database=product-database;Host=example.cloud.com;Password=products-secret;Port=2345;Username=products-user | ||
|
|
||
| PostgreSqlOptions ordersDbOptions = factory.Get("orders-db").Options; | ||
| Console.WriteLine(ordersDbOptions.ConnectionString); | ||
| // Database=order-database;Host=example.cloud.com;Password=orders-secret;Port=2345;Username=orders-user | ||
|
|
||
| void MapCustomServiceBindings(string brokerName) | ||
| { | ||
| var options = builder.Configuration.GetSection("vcap").Get<CloudFoundryServicesOptions>(); | ||
|
|
||
| foreach (CloudFoundryService service in options?.Services | ||
| .Where(pair => pair.Key == brokerName) | ||
| .SelectMany(pair => pair.Value) ?? []) | ||
| { | ||
| builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?> | ||
| { | ||
| // Map credentials into the property names expected by NpgsqlConnectionStringBuilder. | ||
| [$"steeltoe:service-bindings:postgresql:{service.Name}:host"] = service.Credentials["custom-hostname-key"].Value, | ||
| [$"steeltoe:service-bindings:postgresql:{service.Name}:port"] = service.Credentials["custom-port-key"].Value, | ||
| [$"steeltoe:service-bindings:postgresql:{service.Name}:username"] = service.Credentials["custom-username-key"].Value, | ||
| [$"steeltoe:service-bindings:postgresql:{service.Name}:password"] = service.Credentials["custom-password-key"].Value, | ||
| [$"steeltoe:service-bindings:postgresql:{service.Name}:database"] = service.Credentials["custom-database-name-key"].Value | ||
| }); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > See [Advanced settings](usage.md#advanced-settings) to customize the built-in Connectors. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.