Skip to content

Commit bb6757d

Browse files
committed
Update extensibility docs for connectors
1 parent 34db7e1 commit bb6757d

1 file changed

Lines changed: 86 additions & 3 deletions

File tree

docs/docs/v4/connectors/extensibility.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,89 @@
11
# Extensibility
22

3-
Connectors were redesigned in Steeltoe v4, and extensibility is not yet available.
4-
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).
3+
Steeltoe Connectors cover a fixed set of supported data stores and messaging systems (PostgreSQL, MySQL, SQL Server, MongoDB, Cosmos DB, RabbitMQ, and Redis/Valkey).
4+
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.
5+
6+
Connectors map Cloud Foundry credentials into configuration keys starting with `steeltoe:service-bindings` and merge them with local settings from `Steeltoe:Client`.
7+
Each connector runs the binding logic for its own service type.
8+
9+
To use a third-party `VCAP_SERVICES` structure, populate the `steeltoe:service-bindings` keys yourself.
10+
It is recommended to turn off the built-in binding logic to prevent conflicts by setting `SkipDefaultServiceBindings` to `true`.
11+
Doing so will still merge with local settings from `Steeltoe:Client`.
12+
13+
> [!TIP]
14+
> 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.
15+
16+
For example, to use a third-party Cloud Foundry service broker for PostgreSQL that sets the `VCAP_SERVICES` environment variable to:
17+
18+
```json
19+
{
20+
"custom-postgres-broker": [
21+
{
22+
"name": "products-db",
23+
"credentials": {
24+
"custom-hostname-key": "example.cloud.com",
25+
"custom-port-key": 2345,
26+
"custom-username-key": "products-user",
27+
"custom-password-key": "products-secret",
28+
"custom-database-name-key": "product-database"
29+
}
30+
},
31+
{
32+
"name": "orders-db",
33+
"credentials": {
34+
"custom-hostname-key": "example.cloud.com",
35+
"custom-port-key": 2345,
36+
"custom-username-key": "orders-user",
37+
"custom-password-key": "orders-secret",
38+
"custom-database-name-key": "order-database"
39+
}
40+
}
41+
]
42+
}
43+
```
44+
45+
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:
46+
47+
```c#
48+
using Npgsql;
49+
using Steeltoe.Configuration.CloudFoundry;
50+
using Steeltoe.Connectors;
51+
using Steeltoe.Connectors.PostgreSql;
52+
53+
var builder = WebApplication.CreateBuilder();
54+
builder.AddCloudFoundryConfiguration();
55+
MapCustomServiceBindings("custom-postgres-broker");
56+
builder.AddPostgreSql(configure => configure.SkipDefaultServiceBindings = true, null);
57+
var app = builder.Build();
58+
59+
var factory = app.Services.GetRequiredService<ConnectorFactory<PostgreSqlOptions, NpgsqlConnection>>();
60+
61+
PostgreSqlOptions productsDbOptions = factory.Get("products-db").Options;
62+
Console.WriteLine(productsDbOptions.ConnectionString);
63+
// Database=product-database;Host=example.cloud.com;Password=products-secret;Port=2345;Username=products-user
64+
65+
PostgreSqlOptions ordersDbOptions = factory.Get("orders-db").Options;
66+
Console.WriteLine(ordersDbOptions.ConnectionString);
67+
// Database=order-database;Host=example.cloud.com;Password=orders-secret;Port=2345;Username=orders-user
68+
69+
void MapCustomServiceBindings(string brokerName)
70+
{
71+
var options = builder.Configuration.GetSection("vcap").Get<CloudFoundryServicesOptions>();
72+
73+
foreach (CloudFoundryService service in options?.Services
74+
.Where(pair => pair.Key == brokerName)
75+
.SelectMany(pair => pair.Value) ?? [])
76+
{
77+
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
78+
{
79+
// Map credentials into the property names expected by NpgsqlConnectionStringBuilder.
80+
[$"steeltoe:service-bindings:postgresql:{service.Name}:host"] = service.Credentials["custom-hostname-key"].Value,
81+
[$"steeltoe:service-bindings:postgresql:{service.Name}:port"] = service.Credentials["custom-port-key"].Value,
82+
[$"steeltoe:service-bindings:postgresql:{service.Name}:username"] = service.Credentials["custom-username-key"].Value,
83+
[$"steeltoe:service-bindings:postgresql:{service.Name}:password"] = service.Credentials["custom-password-key"].Value,
84+
[$"steeltoe:service-bindings:postgresql:{service.Name}:database"] = service.Credentials["custom-database-name-key"].Value
85+
});
86+
}
87+
}
88+
```
589

6-
See [Advanced settings](usage.md#advanced-settings) to customize the built-in Connectors.

0 commit comments

Comments
 (0)