-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1119 from SteeltoeOSS/mongodb-connector
MongoDB connector support, based on new CloudFoundry service bindings
- Loading branch information
Showing
33 changed files
with
910 additions
and
204 deletions.
There are no files selected for viewing
This file contains 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
37 changes: 37 additions & 0 deletions
37
src/Configuration/src/CloudFoundry.ServiceBinding/MongoDbPostProcessor.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Steeltoe.Configuration.CloudFoundry.ServiceBinding; | ||
|
||
internal sealed class MongoDbPostProcessor : CloudFoundryConfigurationPostProcessor | ||
{ | ||
internal const string BindingType = "mongodb"; | ||
|
||
public override void PostProcessConfiguration(PostProcessorConfigurationProvider provider, IDictionary<string, string> configurationData) | ||
{ | ||
if (!provider.IsBindingTypeEnabled(BindingType)) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (string key in FilterKeys(configurationData, BindingType)) | ||
{ | ||
var mapper = ServiceBindingMapper.Create(configurationData, key, BindingType); | ||
|
||
// See MongoDB connection string parameters at: https://www.mongodb.com/docs/manual/reference/connection-string/ | ||
mapper.MapFromTo("credentials:uri", "url"); | ||
|
||
if (mapper.BindingProvider == "csb-azure-mongodb") | ||
{ | ||
// The MongoDB Azure Service Broker solely provides an url, which contains the authentication database. | ||
// We extract this and expose it as the database used for application data as well. | ||
string url = mapper.GetFromValue("credentials:uri"); | ||
var uri = new Uri(url); | ||
string database = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped); | ||
|
||
mapper.SetToValue("database", database); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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.