Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen committed Mar 23, 2022
2 parents a30a44b + eebf3e7 commit c1636be
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 282 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ on:

jobs:
build-validation:
uses: abbgrade/PsBuildTasks/.github/workflows/build-validation-matrix.yml@v1.0
uses: abbgrade/PsBuildTasks/.github/workflows/build-validation-matrix.yml@v1.1
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
pre-release:
uses: abbgrade/PsBuildTasks/.github/workflows/pre-release-windows.yml@v1.0
uses: abbgrade/PsBuildTasks/.github/workflows/pre-release-windows.yml@v1.1
with:
module-name: PsSqlClient
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
uses: abbgrade/PsBuildTasks/.github/workflows/release-windows.yml@v1.0
uses: abbgrade/PsBuildTasks/.github/workflows/release-windows.yml@v1.1
with:
module-name: PsSqlClient
secrets:
Expand Down
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.1.0] - 2022-03-19

### Added

- Port parameter for Connect-Instance.
- ConnectTimeout for Connect-Instance.
- Support for Active Directory Credential.

## [1.0.0] - 2022-03-18

### Changed

- Replaced System.Data.SqlClient by Microsoft.Data.SqlClient
- Updated to netcoreapp3.1
- Replaced System.Data.SqlClient by Microsoft.Data.SqlClient.
- Updated to netcoreapp3.1.

### Added

- Added output to all commands.
- Fixed parameter validation for stored procedures.

## [0.4.0]
## [0.4.0] - 2021-11-03

### Added

- Added parameter validation.
- Added connection checks.

## [0.2.0]
## [0.2.0] - 2021-09-15

### Changed

Expand Down
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ See the [changelog](./CHANGELOG.md) file.

## Development

![CI](https://github.com/abbgrade/PsSqlClient/workflows/CI/badge.svg)
[![.github/workflows/build-validation.yml](https://github.com/abbgrade/PsSqlClient/actions/workflows/build-validation.yml/badge.svg?branch=develop)](https://github.com/abbgrade/PsSqlClient/actions/workflows/build-validation.yml)

- This is a [Portable Module](https://docs.microsoft.com/de-de/powershell/scripting/dev-cross-plat/writing-portable-modules?view=powershell-7) based on [PowerShell Standard](https://github.com/powershell/powershellstandard) and [.NET Standard](https://docs.microsoft.com/en-us/dotnet/standard/net-standard).
- [VSCode](https://code.visualstudio.com) is recommended as IDE. [VSCode Tasks](https://code.visualstudio.com/docs/editor/tasks) are configured.
- Build automation is based on [InvokeBuild](https://github.com/nightroman/Invoke-Build)
- Documentation is based on [platyPs](https://github.com/PowerShell/platyPS)
- Test automation is based on [Pester](https://pester.dev)
- Commands are named based on [Approved Verbs for PowerShell Commands](https://docs.microsoft.com/de-de/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands)
- This project uses [git-flow](https://github.com/nvie/gitflow).
Expand Down
117 changes: 88 additions & 29 deletions src/PsSqlClient/ConnectInstanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

namespace PsSqlClient
{
[Cmdlet(VerbsCommunications.Connect, "Instance", DefaultParameterSetName = "ConnectionString")]
[Cmdlet(VerbsCommunications.Connect, "Instance", DefaultParameterSetName = PARAMETERSET_CONNECTION_STRING)]
[OutputType(typeof(SqlConnection))]
public class ConnectInstanceCommand : PSCmdlet
{
#region ParameterSets
private const string PARAMETERSET_CONNECTION_STRING = "ConnectionString";
private const string PARAMETERSET_PROPERTIES_INTEGRATED = "Properties_IntegratedSecurity";
private const string PARAMETERSET_PROPERTIES_CREDENTIAL = "Properties_Credential";
#endregion

internal static SqlConnection SessionConnection { get; set; }

#region Parameters

[Parameter(
ParameterSetName = "ConnectionString",
ParameterSetName = PARAMETERSET_CONNECTION_STRING,
Position = 0,
Mandatory = true,
ValueFromPipeline = true,
Expand All @@ -27,13 +32,13 @@ public class ConnectInstanceCommand : PSCmdlet
public string ConnectionString { get; set; }

[Parameter(
ParameterSetName = "Properties_IntegratedSecurity",
ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED,
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true
)]
[Parameter(
ParameterSetName = "Properties_SQLServerAuthentication",
ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL,
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true
Expand All @@ -43,13 +48,23 @@ public class ConnectInstanceCommand : PSCmdlet
public string DataSource { get; set; }

[Parameter(
ParameterSetName = "Properties_IntegratedSecurity",
ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED,
ValueFromPipelineByPropertyName = true
)]
[Parameter(
ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL,
ValueFromPipelineByPropertyName = true
)]
public int? Port { get; set; }

[Parameter(
ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED,
Position = 1,
Mandatory = false,
ValueFromPipelineByPropertyName = true
)]
[Parameter(
ParameterSetName = "Properties_SQLServerAuthentication",
ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL,
Position = 1,
Mandatory = false,
ValueFromPipelineByPropertyName = true
Expand All @@ -59,14 +74,24 @@ public class ConnectInstanceCommand : PSCmdlet
public string InitialCatalog { get; set; }

[Parameter(
ParameterSetName = "Properties_IntegratedSecurity",
ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED,
ValueFromPipelineByPropertyName = true
)]
[Parameter(
ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL,
ValueFromPipelineByPropertyName = true
)]
public int? ConnectTimeout { get; set; }

[Parameter(
ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED,
ValueFromPipelineByPropertyName = true
)]
[ValidateNotNullOrEmpty()]
public string AccessToken { get; set; }

[Parameter(
ParameterSetName = "Properties_SQLServerAuthentication",
ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL,
Position = 1,
Mandatory = true,
ValueFromPipeline = true,
Expand All @@ -75,7 +100,7 @@ public class ConnectInstanceCommand : PSCmdlet
public string UserId { get; set; }

[Parameter(
ParameterSetName = "Properties_SQLServerAuthentication",
ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL,
Position = 1,
Mandatory = true,
ValueFromPipeline = true,
Expand Down Expand Up @@ -129,36 +154,70 @@ protected override void ProcessRecord()
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
switch (ParameterSetName)
{
case "ConnectionString":
case PARAMETERSET_CONNECTION_STRING:
WriteVerbose("Connect by connection string");
builder.ConnectionString = ConnectionString;
connection = new SqlConnection(connectionString: builder.ConnectionString);
break;

case "Properties_IntegratedSecurity":
WriteVerbose("Connect by Integrated Security");
case PARAMETERSET_PROPERTIES_INTEGRATED:
case PARAMETERSET_PROPERTIES_CREDENTIAL:
WriteVerbose("Connect by properties");

builder.DataSource = DataSource;

if (Port != null)
builder.DataSource += $",{Port.Value}";

if (InitialCatalog != null)
builder.InitialCatalog = InitialCatalog;

if (DataSource.EndsWith("database.windows.net")) {
builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryIntegrated;
} else {
builder.IntegratedSecurity = true;
if (ConnectTimeout != null)
builder.ConnectTimeout = ConnectTimeout.Value;

switch (ParameterSetName)
{

case PARAMETERSET_PROPERTIES_INTEGRATED:

if (DataSource.EndsWith("database.windows.net"))
{
WriteVerbose("Authenticate by Azure Active Directory / Integrated Security");
builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryIntegrated;
}
else
{
WriteVerbose("Authenticate by Windows Active Directory / Integrated Security");
builder.IntegratedSecurity = true;
}

connection = new SqlConnection(connectionString: builder.ConnectionString);
break;

case PARAMETERSET_PROPERTIES_CREDENTIAL:

Password.MakeReadOnly();

if (DataSource.EndsWith("database.windows.net"))
{
WriteVerbose("Authenticate by Azure Active Directory Credential");
builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryPassword;
}
else
{
WriteVerbose("Authenticate by Sql Credential");
}

connection = new SqlConnection(
connectionString: builder.ConnectionString,
credential: new SqlCredential(userId: UserId, password: Password)
);
break;

default:
throw new NotImplementedException($"ParameterSetName {ParameterSetName} is not implemented");
}
connection = new SqlConnection(connectionString: builder.ConnectionString);
break;

case "Properties_SQLServerAuthentication":
WriteVerbose("Connect by SQL Server Authentication");
Password.MakeReadOnly();
builder.DataSource = DataSource;
if (InitialCatalog != null)
builder.InitialCatalog = InitialCatalog;
connection = new SqlConnection(
connectionString: builder.ConnectionString,
credential: new SqlCredential(userId: UserId, password: Password)
);
break;

default:
Expand Down
Binary file modified src/PsSqlClient/PsSqlClient.psd1
Binary file not shown.
6 changes: 6 additions & 0 deletions tasks/Build.Tasks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ requires ModuleName
[System.IO.DirectoryInfo] $DocumentationDirectory = "$PSScriptRoot/../docs"
[System.IO.DirectoryInfo] $ModulePublishDirectory = "$PublishDirectory/$ModuleName"
[System.IO.DirectoryInfo] $ModuleSourceDirectory = "$SourceDirectory/$ModuleName"
[System.IO.FileInfo] $ModuleSourceManifest = "$ModuleSourceDirectory/$ModuleName.psd1"
[System.IO.DirectoryInfo] $BinaryDirectory = "$ModuleSourceDirectory/bin"
[System.IO.DirectoryInfo] $ObjectDirectory = "$ModuleSourceDirectory/obj"

Expand Down Expand Up @@ -74,3 +75,8 @@ task Publish -Jobs Clean, Build, {
}
Publish-Module -Path $Global:Manifest.Directory -NuGetApiKey $NuGetApiKey -Force:$ForcePublish
}

task UpdateChangelog {
$info = Import-PowerShellDataFile $ModuleSourceManifest
Update-Changelog -ReleaseVersion $info.ModuleVersion -LinkMode None
}
5 changes: 3 additions & 2 deletions tasks/Dependency.Tasks.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
task InstallBuildDependencies -Jobs {
Install-Module platyPs -Scope CurrentUser
Install-Module platyPs -Scope CurrentUser -ErrorAction Stop -Verbose
}

task InstallTestDependencies -Jobs {
Install-Module PsSqlTestServer -Scope CurrentUser
Install-Module PsSqlLocalDb -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease
Install-Module PsSqlTestServer -Scope CurrentUser -ErrorAction Stop -Verbose -AllowPrerelease
}

task InstallReleaseDependencies -Jobs {}
Loading

0 comments on commit c1636be

Please sign in to comment.