Add some more MySql connection options (resolves #7), add xml comments file to ConnectorCore, other misc cleanup
This commit is contained in:
Родитель
43cc2bcf88
Коммит
75477708ef
|
@ -47,14 +47,14 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
this._keyValueTerm = keyValueTerm;
|
||||
}
|
||||
|
||||
protected internal void AddKeyValue(StringBuilder sb, string key, int value)
|
||||
protected internal void AddKeyValue(StringBuilder sb, string key, int? value)
|
||||
{
|
||||
AddKeyValue(sb, key, value.ToString());
|
||||
AddKeyValue(sb, key, value?.ToString());
|
||||
}
|
||||
|
||||
protected internal void AddKeyValue(StringBuilder sb, string key, bool value)
|
||||
protected internal void AddKeyValue(StringBuilder sb, string key, bool? value)
|
||||
{
|
||||
AddKeyValue(sb, key, value.ToString().ToLowerInvariant());
|
||||
AddKeyValue(sb, key, value?.ToString().ToLowerInvariant());
|
||||
}
|
||||
|
||||
protected internal void AddKeyValue(StringBuilder sb, string key, string value)
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace Steeltoe.CloudFoundry.Connector.Redis
|
|||
|
||||
Type redisConnection = ConnectorHelpers.FindType(redisAssemblies, redisTypeNames);
|
||||
Type redisOptions = ConnectorHelpers.FindType(redisAssemblies, redisOptionNames);
|
||||
MethodInfo initializer = ConnectorHelpers.FindMethod(redisConnection, "Connect", null);
|
||||
MethodInfo initializer = ConnectorHelpers.FindMethod(redisConnection, "Connect");
|
||||
|
||||
var info = serviceName == null ? config.GetSingletonServiceInfo<RedisServiceInfo>() : config.GetRequiredServiceInfo<RedisServiceInfo>(serviceName);
|
||||
return new RedisServiceConnectorFactory(info, connectorOptions, redisConnection, redisOptions, initializer ?? null);
|
||||
|
|
|
@ -68,6 +68,11 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return _me;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Service Infos of type
|
||||
/// </summary>
|
||||
/// <typeparam name="SI">Service Info Type to retrieve</typeparam>
|
||||
/// <returns>List of matching Service Infos</returns>
|
||||
public List<SI> GetServiceInfos<SI>()
|
||||
where SI : class
|
||||
{
|
||||
|
@ -83,6 +88,12 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a named service
|
||||
/// </summary>
|
||||
/// <typeparam name="SI">Service Info type</typeparam>
|
||||
/// <param name="name">Service name</param>
|
||||
/// <returns>Service info or null</returns>
|
||||
public SI GetServiceInfo<SI>(string name)
|
||||
where SI : class
|
||||
{
|
||||
|
@ -99,11 +110,21 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all Service Infos of type
|
||||
/// </summary>
|
||||
/// <param name="type">Service Info Type to retrieve</param>
|
||||
/// <returns>List of matching Service Infos</returns>
|
||||
public List<IServiceInfo> GetServiceInfos(Type type)
|
||||
{
|
||||
return _serviceInfos.Where((info) => info.GetType() == type).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a named Service Info
|
||||
/// </summary>
|
||||
/// <param name="name">Name of service info</param>
|
||||
/// <returns>Service info</returns>
|
||||
public IServiceInfo GetServiceInfo(string name)
|
||||
{
|
||||
return _serviceInfos.Where((info) => info.Id.Equals(name)).FirstOrDefault();
|
||||
|
|
|
@ -19,6 +19,11 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
{
|
||||
public static class ConnectorHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Find an assembly
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the assembly to find</param>
|
||||
/// <returns>A representation of the assembly</returns>
|
||||
public static Assembly FindAssembly(string name)
|
||||
{
|
||||
try
|
||||
|
@ -34,6 +39,13 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search a list of assemblies for the first matching type
|
||||
/// </summary>
|
||||
/// <param name="assemblyNames">List of assembly names to search</param>
|
||||
/// <param name="typeNames">List of suitable types</param>
|
||||
/// <returns>An appropriate type</returns>
|
||||
/// <remarks>Great for finding an implementation type that could have one or more names in one or more assemblies</remarks>
|
||||
public static Type FindType(string[] assemblyNames, string[] typeNames)
|
||||
{
|
||||
foreach (var assemblyName in assemblyNames)
|
||||
|
@ -55,6 +67,12 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a type from within an assembly
|
||||
/// </summary>
|
||||
/// <param name="assembly">The assembly to search</param>
|
||||
/// <param name="typeName">The name of the type to retrieve</param>
|
||||
/// <returns>The type</returns>
|
||||
public static Type FindType(Assembly assembly, string typeName)
|
||||
{
|
||||
try
|
||||
|
@ -68,7 +86,14 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
public static MethodInfo FindMethod(Type type, string methodName, Type[] parameters)
|
||||
/// <summary>
|
||||
/// Find a method within a type
|
||||
/// </summary>
|
||||
/// <param name="type">The type to search</param>
|
||||
/// <param name="methodName">The name of the method</param>
|
||||
/// <param name="parameters">(Optional) The parameters in the signature</param>
|
||||
/// <returns>The method you're searching for</returns>
|
||||
public static MethodInfo FindMethod(Type type, string methodName, Type[] parameters = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -86,6 +111,13 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoke a function
|
||||
/// </summary>
|
||||
/// <param name="member">The method to execute</param>
|
||||
/// <param name="instance">Instance of an object, if required by the method</param>
|
||||
/// <param name="args">Arguments to pass to the method</param>
|
||||
/// <returns>Results of method call</returns>
|
||||
public static object Invoke(MethodBase member, object instance, object[] args)
|
||||
{
|
||||
try
|
||||
|
@ -99,7 +131,13 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
public static object CreateInstance(Type t, object[] args)
|
||||
/// <summary>
|
||||
/// Create an instance of a type
|
||||
/// </summary>
|
||||
/// <param name="t">Type to instantiate</param>
|
||||
/// <param name="args">Constructor parameters</param>
|
||||
/// <returns>New instance of desired type</returns>
|
||||
public static object CreateInstance(Type t, object[] args = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -22,6 +22,12 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
{
|
||||
public static class IConfigurationExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Get configuration info for all services of a given service type
|
||||
/// </summary>
|
||||
/// <typeparam name="SI">Service info type you're looking for</typeparam>
|
||||
/// <param name="config">Configuration to search</param>
|
||||
/// <returns>List of service infos</returns>
|
||||
public static List<SI> GetServiceInfos<SI>(this IConfiguration config)
|
||||
where SI : class
|
||||
{
|
||||
|
@ -29,18 +35,37 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return factory.GetServiceInfos<SI>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get configuration info for all services of a given service type
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration to search</param>
|
||||
/// <param name="infoType">Type to search for</param>
|
||||
/// <returns>A list of relevant <see cref="IServiceInfo"/></returns>
|
||||
public static List<IServiceInfo> GetServiceInfos(this IConfiguration config, Type infoType)
|
||||
{
|
||||
CloudFoundryServiceInfoCreator factory = CloudFoundryServiceInfoCreator.Instance(config);
|
||||
return factory.GetServiceInfos(infoType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get service info when you know the Id
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration to search</param>
|
||||
/// <param name="id">Id of service</param>
|
||||
/// <returns>Requested implementation of <see cref="IServiceInfo"/></returns>
|
||||
public static IServiceInfo GetServiceInfo(this IConfiguration config, string id)
|
||||
{
|
||||
CloudFoundryServiceInfoCreator factory = CloudFoundryServiceInfoCreator.Instance(config);
|
||||
return factory.GetServiceInfo(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get service info of a given type when you know the Id
|
||||
/// </summary>
|
||||
/// <typeparam name="SI">Service info type you're looking for</typeparam>
|
||||
/// <param name="config">Configuration to search</param>
|
||||
/// <param name="id">Id of service</param>
|
||||
/// <returns>Requested implementation of <see cref="IServiceInfo"/></returns>
|
||||
public static SI GetServiceInfo<SI>(this IConfiguration config, string id)
|
||||
where SI : class
|
||||
{
|
||||
|
@ -48,6 +73,13 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return factory.GetServiceInfo<SI>(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Service Info from IConfiguration
|
||||
/// </summary>
|
||||
/// <typeparam name="SI">Type of Service Info to return</typeparam>
|
||||
/// <param name="config">Configuration to retrieve service info from</param>
|
||||
/// <exception cref="ConnectorException">Thrown when multple matching services are found</exception>
|
||||
/// <returns>Information requried to connect to provisioned service</returns>
|
||||
public static SI GetSingletonServiceInfo<SI>(this IConfiguration config)
|
||||
where SI : class
|
||||
{
|
||||
|
@ -65,6 +97,14 @@ namespace Steeltoe.CloudFoundry.Connector
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get info for a named service
|
||||
/// </summary>
|
||||
/// <typeparam name="SI">Type of Service Info to return</typeparam>
|
||||
/// <param name="config">Configuration to retrieve service info from</param>
|
||||
/// <param name="serviceName">Name of the service</param>
|
||||
/// <exception cref="ConnectorException">Thrown when service info isn't found</exception>
|
||||
/// <returns>Information requried to connect to provisioned service</returns>
|
||||
public static SI GetRequiredServiceInfo<SI>(this IConfiguration config, string serviceName)
|
||||
where SI : class
|
||||
{
|
||||
|
|
|
@ -18,6 +18,9 @@ using System.Text;
|
|||
|
||||
namespace Steeltoe.CloudFoundry.Connector.MySql
|
||||
{
|
||||
/// <summary>
|
||||
/// https://dev.mysql.com/doc/connector-net/en/connector-net-connection-options.html
|
||||
/// </summary>
|
||||
public class MySqlProviderConnectorOptions : AbstractServiceConnectorOptions
|
||||
{
|
||||
public const string Default_Server = "localhost";
|
||||
|
@ -57,6 +60,58 @@ namespace Steeltoe.CloudFoundry.Connector.MySql
|
|||
|
||||
public string SslMode { get; set; }
|
||||
|
||||
public bool? AllowBatch { get; set; }
|
||||
|
||||
public bool? AllowUserVariables { get; set; }
|
||||
|
||||
public bool? AutoEnlist { get; set; }
|
||||
|
||||
public bool? CheckParameters { get; set; }
|
||||
|
||||
public int? ConnectionTimeout { get; set; }
|
||||
|
||||
public int? DefaultCommandTimeout { get; set; }
|
||||
|
||||
public int? DefaultTableCacheAge { get; set; }
|
||||
|
||||
public bool? EnableSessionExpireCallback { get; set; }
|
||||
|
||||
public bool? FunctionsReturnString { get; set; }
|
||||
|
||||
public bool? IgnorePrepare { get; set; }
|
||||
|
||||
public bool? IncludeSecurityAsserts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether various pieces of information are output to any configured TraceListeners
|
||||
/// </summary>
|
||||
/// <remarks>Currently not supported for .NET Core implementations.</remarks>
|
||||
public bool? Logging { get; set; }
|
||||
|
||||
public bool? OldGuids { get; set; }
|
||||
|
||||
public bool? OldSyntax { get; set; }
|
||||
|
||||
public bool? PersistSecurityInfo { get; set; }
|
||||
|
||||
public bool? SqlServerMode { get; set; }
|
||||
|
||||
public bool? TableCache { get; set; }
|
||||
|
||||
public bool? TreatBlobsAsUTF8 { get; set; }
|
||||
|
||||
public bool? TreatTinyAsBoolean { get; set; }
|
||||
|
||||
public bool? UseAffectedRows { get; set; }
|
||||
|
||||
public bool? UseProcedureBodies { get; set; }
|
||||
|
||||
public bool? UseCompression { get; set; }
|
||||
|
||||
public bool? UseUsageAdvisor { get; set; }
|
||||
|
||||
public bool? UsePerformanceMonitor { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ConnectionString) && !cloudFoundryConfigFound)
|
||||
|
@ -71,6 +126,30 @@ namespace Steeltoe.CloudFoundry.Connector.MySql
|
|||
AddKeyValue(sb, nameof(Password), Password);
|
||||
AddKeyValue(sb, nameof(Database), Database);
|
||||
AddKeyValue(sb, nameof(SslMode), SslMode);
|
||||
AddKeyValue(sb, nameof(AllowBatch), AllowBatch);
|
||||
AddKeyValue(sb, nameof(AllowUserVariables), AllowUserVariables);
|
||||
AddKeyValue(sb, nameof(AutoEnlist), AutoEnlist);
|
||||
AddKeyValue(sb, nameof(CheckParameters), CheckParameters);
|
||||
AddKeyValue(sb, nameof(ConnectionTimeout), ConnectionTimeout);
|
||||
AddKeyValue(sb, nameof(DefaultCommandTimeout), DefaultCommandTimeout);
|
||||
AddKeyValue(sb, nameof(DefaultTableCacheAge), DefaultTableCacheAge);
|
||||
AddKeyValue(sb, nameof(EnableSessionExpireCallback), EnableSessionExpireCallback);
|
||||
AddKeyValue(sb, nameof(FunctionsReturnString), FunctionsReturnString);
|
||||
AddKeyValue(sb, nameof(IgnorePrepare), IgnorePrepare);
|
||||
AddKeyValue(sb, nameof(IncludeSecurityAsserts), IncludeSecurityAsserts);
|
||||
AddKeyValue(sb, nameof(Logging), Logging);
|
||||
AddKeyValue(sb, nameof(OldGuids), OldGuids);
|
||||
AddKeyValue(sb, nameof(OldSyntax), OldSyntax);
|
||||
AddKeyValue(sb, nameof(PersistSecurityInfo), PersistSecurityInfo);
|
||||
AddKeyValue(sb, nameof(SqlServerMode), SqlServerMode);
|
||||
AddKeyValue(sb, nameof(TableCache), TableCache);
|
||||
AddKeyValue(sb, nameof(TreatBlobsAsUTF8), TreatBlobsAsUTF8);
|
||||
AddKeyValue(sb, nameof(TreatTinyAsBoolean), TreatTinyAsBoolean);
|
||||
AddKeyValue(sb, nameof(UseAffectedRows), UseAffectedRows);
|
||||
AddKeyValue(sb, nameof(UseProcedureBodies), UseProcedureBodies);
|
||||
AddKeyValue(sb, nameof(UseCompression), UseCompression);
|
||||
AddKeyValue(sb, nameof(UseUsageAdvisor), UseUsageAdvisor);
|
||||
AddKeyValue(sb, nameof(UsePerformanceMonitor), UsePerformanceMonitor);
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,12 +36,7 @@ namespace Steeltoe.CloudFoundry.Connector.Services
|
|||
|
||||
public ServiceInfoFactory(Tags tags, string[] schemes)
|
||||
{
|
||||
if (tags == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tags));
|
||||
}
|
||||
|
||||
ServiceInfoTags = tags;
|
||||
ServiceInfoTags = tags ?? throw new ArgumentNullException(nameof(tags));
|
||||
UriSchemes = schemes;
|
||||
if (schemes != null)
|
||||
{
|
||||
|
@ -139,8 +134,7 @@ namespace Steeltoe.CloudFoundry.Connector.Services
|
|||
|
||||
foreach (string uriScheme in UriSchemes)
|
||||
{
|
||||
if (credentials.ContainsKey(uriScheme + "Uri") || credentials.ContainsKey(uriScheme + "uri") ||
|
||||
credentials.ContainsKey(uriScheme + "Url") || credentials.ContainsKey(uriScheme + "url"))
|
||||
if (credentials.ContainsKey(uriScheme + "Uri") || credentials.ContainsKey(uriScheme + "uri") || credentials.ContainsKey(uriScheme + "Url") || credentials.ContainsKey(uriScheme + "url"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
<PackageProjectUrl>https://steeltoe.io</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Steeltoe.CloudFoundry.ConnectorCore.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="$(AspNetCoreVersion)" />
|
||||
|
@ -35,7 +38,6 @@
|
|||
<ItemGroup Condition="'$(CI_BUILD)' == ''">
|
||||
<ProjectReference Include="..\Steeltoe.CloudFoundry.ConnectorBase\Steeltoe.CloudFoundry.ConnectorBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(CI_BUILD)' == 'True'">
|
||||
<PackageReference Include="Steeltoe.CloudFoundry.ConnectorBase" Version="$(SteeltoeVersion)$(SteeltoeVersionSuffix)" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace Steeltoe.CloudFoundry.Connector.MySql.Test
|
|||
{
|
||||
["mysql:client:server"] = "localhost",
|
||||
["mysql:client:port"] = "1234",
|
||||
["mysql:client:PersistSecurityInfo"] = "true",
|
||||
["mysql:client:password"] = "password",
|
||||
["mysql:client:username"] = "username"
|
||||
};
|
||||
|
@ -52,6 +53,7 @@ namespace Steeltoe.CloudFoundry.Connector.MySql.Test
|
|||
var sconfig = new MySqlProviderConnectorOptions(config);
|
||||
Assert.Equal("localhost", sconfig.Server);
|
||||
Assert.Equal(1234, sconfig.Port);
|
||||
Assert.True(sconfig.PersistSecurityInfo);
|
||||
Assert.Equal("password", sconfig.Password);
|
||||
Assert.Equal("username", sconfig.Username);
|
||||
Assert.Null(sconfig.ConnectionString);
|
||||
|
|
|
@ -39,10 +39,10 @@ namespace Steeltoe.CloudFoundry.Connector.SqlServer.Test
|
|||
{
|
||||
var appsettings = new Dictionary<string, string>()
|
||||
{
|
||||
["SqlServer:credentials:uid"] = "username",
|
||||
["SqlServer:credentials:uri"] = "jdbc:sqlserver://servername:1433;databaseName=de5aa3a747c134b3d8780f8cc80be519e",
|
||||
["SqlServer:credentials:db"] = "de5aa3a747c134b3d8780f8cc80be519e",
|
||||
["SqlServer:credentials:pw"] = "password"
|
||||
["sqlserver:credentials:uid"] = "username",
|
||||
["sqlserver:credentials:uri"] = "jdbc:sqlserver://servername:1433;databaseName=de5aa3a747c134b3d8780f8cc80be519e",
|
||||
["sqlserver:credentials:db"] = "de5aa3a747c134b3d8780f8cc80be519e",
|
||||
["sqlserver:credentials:pw"] = "password"
|
||||
};
|
||||
|
||||
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
|
||||
|
|
Загрузка…
Ссылка в новой задаче