This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!deploy multiple fixes and enhancements
## 2.11.0 - 2020-03-04 * [Issue #69](#69) + [PR #70](#70) - _Thanks, [@indented-automation](https://github.com/indented-automation)!!!_ * Started `VaporShell.Core` class library to include with the module, first class being `TransformTagAttribute` to cleanly convert `Tags` parameter input to the appropriate format if not already. * Added Pester tests to confirm Tag transforms are working as expected. * [Issue #68](#68) - _Thanks, [@indented-automation](https://github.com/indented-automation) and [@austoonz](https://github.com/austoonz)!!!_ * Surfaced errors better on AWS SDK errors so the actual error is visible. * Added the `FallbackCredentialFactory` to better support running in environments where credentials files are not a practical option. * Miscellaneous * Updated PseudoParameter list to current spec. * Added newer intrinsic functions `Add-FnCidr` and `Add-FnTransform`.
- Loading branch information
Showing
1,795 changed files
with
29,460 additions
and
4,525 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
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,75 @@ | ||
Describe 'TransformTagAttribute' { | ||
BeforeAll { | ||
function Test-TagBinding { | ||
[CmdletBinding()] | ||
param ( | ||
[VaporShell.Core.TransformTag()] | ||
[object[]] $Tags | ||
) | ||
|
||
$Tags | ||
} | ||
} | ||
Context 'Confirm TagTransformAttribute works as expected' { | ||
$projectRoot = Resolve-Path "$PSScriptRoot\..\.." | ||
$ModulePath = Resolve-Path "$projectRoot\BuildOutput\$($env:BHProjectName)" | ||
|
||
Write-Verbose "Importing $($env:BHProjectName) module at [$ModulePath]" | ||
Import-Module $ModulePath -Force -Verbose:$false | ||
|
||
It 'Should return one or more tags when given <TestName>' -TestCases @( | ||
@{ | ||
TestName = 'multiple hashtables' | ||
InputData = @{ one = 1 }, @{ two = 2 } | ||
ExpectedResult = [PSCustomObject]@{ Key = 'one'; Value = '1' }, [PSCustomObject]@{ Key = 'two'; Value = '2' } | ||
} | ||
@{ | ||
TestName = 'multiple PSObjects' | ||
InputData = [PSCustomObject]@{ one = 1 }, [PSCustomObject]@{ two = 2 } | ||
ExpectedResult = [PSCustomObject]@{ Key = 'one'; Value = '1' }, [PSCustomObject]@{ Key = 'two'; Value = '2' } | ||
} | ||
@{ | ||
TestName = 'a single hashtable with multiple keys' | ||
InputData = [PSCustomobject]@{ one = 1; two = 2 } | ||
ExpectedResult = [PSCustomObject]@{ Key = 'one'; Value = '1' }, [PSCustomObject]@{ Key = 'two'; Value = '2' } | ||
} | ||
@{ | ||
TestName = 'an existing VSTag object' | ||
InputData = Add-VSTag -Key one -Value '1' | ||
ExpectedResult = [PSCustomObject]@{ Key = 'one'; Value = '1' } | ||
} | ||
@{ | ||
TestName = 'a hashtable with Key and Value keys' | ||
InputData = @{Key = 'Name'; Value = 'Harold'} | ||
ExpectedResult = [PSCustomObject]@{ Key = 'Name'; Value = 'Harold' } | ||
} | ||
@{ | ||
TestName = 'a hashtable with lowercase key and value keys' | ||
InputData = @{ key = 'Name'; value = 'Harold'} | ||
ExpectedResult = [PSCustomObject]@{ Key = 'Name'; Value = 'Harold' } | ||
} | ||
@{ | ||
TestName = 'a hashtable with mixed case key and value keys' | ||
InputData = @{ kEy = 'Name'; ValUE = 'Harold'} | ||
ExpectedResult = [PSCustomObject]@{ Key = 'Name'; Value = 'Harold' } | ||
} | ||
@{ | ||
TestName = 'a PSCustomObject key and value properties' | ||
InputData = [PSCustomObject]@{ Key = 'Name'; Value = 'Harold' } | ||
ExpectedResult = [PSCustomObject]@{ Key = 'Name'; Value = 'Harold' } | ||
} | ||
@{ | ||
TestName = 'a PSCustomObject lowercase key and value properties' | ||
InputData = [PSCustomObject]@{ key = 'Name'; value = 'Harold' } | ||
ExpectedResult = [PSCustomObject]@{ Key = 'Name'; Value = 'Harold' } | ||
} | ||
) { | ||
param ( | ||
$InputData, | ||
$ExpectedResult | ||
) | ||
|
||
Assert-Equivalent -Actual (Test-TagBinding -Tags $InputData) -Expected $ExpectedResult | ||
} | ||
} | ||
} |
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,129 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
namespace VaporShell.Core | ||
{ | ||
public class TransformTagAttribute : ArgumentTransformationAttribute | ||
{ | ||
private EngineIntrinsics engineIntrinsics; | ||
|
||
private PSObject ConvertToTag(object key, object value) | ||
{ | ||
PSObject tag = new PSObject(); | ||
tag.Members.Add(new PSNoteProperty("Key", key.ToString())); | ||
tag.Members.Add(new PSNoteProperty("Value", value)); | ||
tag.TypeNames.Insert(0, "Vaporshell.Resource.Tag"); | ||
|
||
return tag; | ||
} | ||
|
||
private bool TryGetKey(IDictionary dictionary, string keyName, ref object KeyValue) | ||
{ | ||
foreach (object key in dictionary.Keys) | ||
{ | ||
if (key.ToString().ToLower() == keyName.ToLower()) | ||
{ | ||
KeyValue = dictionary[key]; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private IEnumerable<PSObject> TransformHashtable(IDictionary inputData) | ||
{ | ||
object keyName = null; | ||
object value = null; | ||
if (this.TryGetKey(inputData, "key", ref keyName) && this.TryGetKey(inputData, "value", ref value)) | ||
{ | ||
yield return this.ConvertToTag(keyName, value); | ||
} | ||
else | ||
{ | ||
foreach (string key in inputData.Keys) | ||
{ | ||
yield return this.ConvertToTag(key, inputData[key]); | ||
} | ||
} | ||
} | ||
|
||
private IEnumerable<PSObject> TransformPSObject(PSObject inputData) | ||
{ | ||
var props = new List<string>(); | ||
foreach (var property in inputData.Properties) | ||
{ | ||
props.Add(property.Name.ToLower()); | ||
} | ||
|
||
if (props.Contains("key") && props.Contains("value")) | ||
{ | ||
yield return this.ConvertToTag(inputData.Properties["Key"].Value, inputData.Properties["Value"].Value); | ||
} | ||
else | ||
{ | ||
foreach (var property in inputData.Properties) | ||
{ | ||
yield return this.ConvertToTag(property.Name, property.Value); | ||
} | ||
} | ||
} | ||
|
||
private IEnumerable<PSObject> TransformSingle(object inputData) | ||
{ | ||
if (inputData is IDictionary) | ||
{ | ||
foreach (PSObject tag in this.TransformHashtable(inputData as IDictionary)) | ||
{ | ||
yield return tag; | ||
} | ||
} | ||
else if (inputData is PSObject) | ||
{ | ||
PSObject psObject = inputData as PSObject; | ||
if (psObject.TypeNames.Contains("Vaporshell.Resource.Tag")) | ||
{ | ||
yield return psObject; | ||
} | ||
else if (psObject.TypeNames.Contains("System.Management.Automation.PSCustomObject")) | ||
{ | ||
foreach (PSObject tag in this.TransformPSObject(psObject)) | ||
{ | ||
yield return tag; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private IEnumerable<PSObject> TransformData(object inputData) | ||
{ | ||
if (inputData is Array) | ||
{ | ||
foreach (object item in inputData as Array) | ||
{ | ||
// This is returning an unenumerated array | ||
foreach (PSObject tag in this.TransformSingle(item)) | ||
{ | ||
yield return tag; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
foreach (PSObject tag in this.TransformSingle(inputData)) | ||
{ | ||
yield return tag; | ||
} | ||
} | ||
} | ||
|
||
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) | ||
{ | ||
this.engineIntrinsics = engineIntrinsics; | ||
|
||
return this.TransformData(inputData); | ||
} | ||
} | ||
} |
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="PowerShellStandard.Library" Version="3.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29806.167 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VaporShell.Core", "VaporShell.Core.csproj", "{8FF3CC38-B1B4-4F93-8F90-7FDF82AFD193}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8FF3CC38-B1B4-4F93-8F90-7FDF82AFD193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8FF3CC38-B1B4-4F93-8F90-7FDF82AFD193}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8FF3CC38-B1B4-4F93-8F90-7FDF82AFD193}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8FF3CC38-B1B4-4F93-8F90-7FDF82AFD193}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {115A389F-865B-4A5F-9761-0E606AB74BF5} | ||
EndGlobalSection | ||
EndGlobal |
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.