Skip to content

Commit

Permalink
Merge pull request #174 from jaredmoo/stuartpa_SecureOverloads
Browse files Browse the repository at this point in the history
Enable SecureString (via SqlCredential) for all APIs
  • Loading branch information
jaredmoo authored Aug 23, 2018
2 parents 075e7e9 + 2f6ea94 commit a5fb3ce
Show file tree
Hide file tree
Showing 31 changed files with 1,947 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ TestResults

# Build output
*.dll
*.exe
*.exe
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('build.props'))" />

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions Src/ElasticScale.Client/ShardManagement/Errors.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Src/ElasticScale.Client/ShardManagement/Errors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@
<data name="_ShardMapping_RangeNotProperSubset" xml:space="preserve">
<value>Requested range is exactly the range for existing mapping. Operation is only allowed for proper subsets of existing range.</value>
</data>
<data name="_SqlShardMapManagerCredentials_ConnectionStringPropertyNotAllowed" xml:space="preserve">
<value>The property '{0}' must not be set in the connection string.</value>
</data>
<data name="_ShardMapping_RangeNotSubset" xml:space="preserve">
<value>Requested range is not a subset of the existing range mapping.</value>
</data>
Expand Down
86 changes: 82 additions & 4 deletions Src/ElasticScale.Client/ShardManagement/Shard/Shard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,25 @@ private static ILogger Tracer
/// </remarks>
public SqlConnection OpenConnection(string connectionString)
{
return this.OpenConnection(connectionString, ConnectionOptions.Validate);
return this.OpenConnection(connectionString, null, ConnectionOptions.Validate);
}

/// <summary>
/// Opens a regular <see cref="SqlConnection"/> to the specified shard, with <see cref="ConnectionOptions.Validate"/>.
/// </summary>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure Sql credential information.</param>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// </remarks>
public SqlConnection OpenConnection(string connectionString, SqlCredential secureCredential)
{
return this.OpenConnection(connectionString, secureCredential, ConnectionOptions.Validate);
}

/// <summary>
Expand All @@ -268,10 +286,29 @@ public SqlConnection OpenConnection(string connectionString)
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// </remarks>
public SqlConnection OpenConnection(string connectionString, ConnectionOptions options)
{
return this.OpenConnection(connectionString, null, options);
}

/// <summary>
/// Opens a regular <see cref="SqlConnection"/> to the specified shard.
/// </summary>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL credential information.</param>
/// <param name="options">Options for validation operations to perform on opened connection.</param>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// </remarks>
public SqlConnection OpenConnection(string connectionString, SqlCredential secureCredential, ConnectionOptions options)
{
using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
{
return this.ShardMap.OpenConnection(this as IShardProvider, connectionString, options);
return this.ShardMap.OpenConnection(this as IShardProvider, connectionString, secureCredential, options);
}
}

Expand All @@ -295,7 +332,27 @@ public SqlConnection OpenConnection(string connectionString, ConnectionOptions o
/// </remarks>
public Task<SqlConnection> OpenConnectionAsync(string connectionString)
{
return this.OpenConnectionAsync(connectionString, ConnectionOptions.Validate);
return this.OpenConnectionAsync(connectionString, null, ConnectionOptions.Validate);
}

/// <summary>
/// Asynchronously opens a regular <see cref="SqlConnection"/> to the specified shard, with <see cref="ConnectionOptions.Validate"/>.
/// </summary>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL Credential.</param>
/// <returns>A Task encapsulating an opened SqlConnection</returns>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// All non-usage errors will be propagated via the returned Task.
/// </remarks>
public Task<SqlConnection> OpenConnectionAsync(string connectionString, SqlCredential secureCredential)
{
return this.OpenConnectionAsync(connectionString, secureCredential, ConnectionOptions.Validate);
}

/// <summary>
Expand All @@ -314,10 +371,31 @@ public Task<SqlConnection> OpenConnectionAsync(string connectionString)
/// All non-usage errors will be propagated via the returned Task.
/// </remarks>
public Task<SqlConnection> OpenConnectionAsync(string connectionString, ConnectionOptions options)
{
return this.OpenConnectionAsync(connectionString, null, options);
}

/// <summary>
/// Asynchronously a regular <see cref="SqlConnection"/> to the specified shard.
/// </summary>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL Credential.</param>
/// <param name="options">Options for validation operations to perform on opened connection.</param>
/// <returns>A Task encapsulating an opened SqlConnection</returns>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// All non-usage errors will be propagated via the returned Task.
/// </remarks>
public Task<SqlConnection> OpenConnectionAsync(string connectionString, SqlCredential secureCredential, ConnectionOptions options)
{
using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
{
return this.ShardMap.OpenConnectionAsync(this as IShardProvider, connectionString, options);
return this.ShardMap.OpenConnectionAsync(this as IShardProvider, connectionString, secureCredential, options);
}
}

Expand Down
100 changes: 98 additions & 2 deletions Src/ElasticScale.Client/ShardManagement/ShardMap/ListShardMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ public SqlConnection OpenConnectionForKey(TKey key, string connectionString)
return this.OpenConnectionForKey(key, connectionString, ConnectionOptions.Validate);
}

/// <summary>
/// Opens a regular <see cref="SqlConnection"/> to the shard
/// to which the specified key value is mapped, with <see cref="ConnectionOptions.Validate"/>.
/// </summary>
/// <param name="key">Input key value.</param>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL Credential.</param>
/// <returns>An opened SqlConnection.</returns>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults
/// in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
public SqlConnection OpenConnectionForKey(TKey key, string connectionString, SqlCredential secureCredential)
{
return this.OpenConnectionForKey(key, connectionString, secureCredential, ConnectionOptions.Validate);
}

/// <summary>
/// Opens a regular <see cref="SqlConnection"/> to the shard
/// to which the specified key value is mapped.
Expand All @@ -76,12 +99,36 @@ public SqlConnection OpenConnectionForKey(TKey key, string connectionString)
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
public SqlConnection OpenConnectionForKey(TKey key, string connectionString, ConnectionOptions options)
{
return this.OpenConnectionForKey(key, connectionString, null, options);
}

/// <summary>
/// Opens a regular <see cref="SqlConnection"/> to the shard
/// to which the specified key value is mapped.
/// </summary>
/// <param name="key">Input key value.</param>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL Credential.</param>
/// <param name="options">Options for validation operations to perform on opened connection.</param>
/// <returns>An opened SqlConnection.</returns>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults
/// in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
public SqlConnection OpenConnectionForKey(TKey key, string connectionString, SqlCredential secureCredential, ConnectionOptions options)
{
ExceptionUtils.DisallowNullArgument(connectionString, "connectionString");

using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
{
return _lsm.OpenConnectionForKey(key, connectionString, options);
return _lsm.OpenConnectionForKey(key, connectionString, secureCredential, options);
}
}

Expand Down Expand Up @@ -112,6 +159,30 @@ public Task<SqlConnection> OpenConnectionForKeyAsync(TKey key, string connection
return this.OpenConnectionForKeyAsync(key, connectionString, ConnectionOptions.Validate);
}

/// <summary>
/// Asynchronously opens a regular <see cref="SqlConnection"/> to the shard
/// to which the specified key value is mapped, with <see cref="ConnectionOptions.Validate"/>.
/// </summary>
/// <param name="key">Input key value.</param>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL Credential.</param>
/// <returns>A Task encapsulating an open SqlConnection as the result</returns>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults
/// in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// All non-usage error related exceptions are reported via the returned Task.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
public Task<SqlConnection> OpenConnectionForKeyAsync(TKey key, string connectionString, SqlCredential secureCredential)
{
return this.OpenConnectionForKeyAsync(key, connectionString, secureCredential, ConnectionOptions.Validate);
}

/// <summary>
/// Asynchronously opens a regular <see cref="SqlConnection"/> to the shard
/// to which the specified key value is mapped.
Expand All @@ -132,12 +203,37 @@ public Task<SqlConnection> OpenConnectionForKeyAsync(TKey key, string connection
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
public Task<SqlConnection> OpenConnectionForKeyAsync(TKey key, string connectionString, ConnectionOptions options)
{
return OpenConnectionForKeyAsync(key, connectionString, null, options);
}

/// <summary>
/// Asynchronously opens a regular <see cref="SqlConnection"/> to the shard
/// to which the specified key value is mapped.
/// </summary>
/// <param name="key">Input key value.</param>
/// <param name="connectionString">
/// Connection string with credential information such as SQL Server credentials or Integrated Security settings.
/// The hostname of the server and the database name for the shard are obtained from the lookup operation for key.
/// </param>
/// <param name="secureCredential">Secure SQL Credential.</param>
/// <param name="options">Options for validation operations to perform on opened connection.</param>
/// <returns>A Task encapsulating an opened SqlConnection.</returns>
/// <remarks>
/// Note that the <see cref="SqlConnection"/> object returned by this call is not protected against transient faults.
/// Callers should follow best practices to protect the connection against transient faults
/// in their application code, e.g., by using the transient fault handling
/// functionality in the Enterprise Library from Microsoft Patterns and Practices team.
/// All non-usage error related exceptions are reported via the returned Task.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1061:DoNotHideBaseClassMethods")]
public Task<SqlConnection> OpenConnectionForKeyAsync(TKey key, string connectionString, SqlCredential secureCredential, ConnectionOptions options)
{
ExceptionUtils.DisallowNullArgument(connectionString, "connectionString");

using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
{
return _lsm.OpenConnectionForKeyAsync(key, connectionString, options);
return _lsm.OpenConnectionForKeyAsync(key, connectionString, secureCredential, options);
}
}

Expand Down
Loading

0 comments on commit a5fb3ce

Please sign in to comment.