Skip to content

Commit c01bc7a

Browse files
committed
#23 Work in pogress
1 parent b45832c commit c01bc7a

File tree

5 files changed

+433
-1
lines changed

5 files changed

+433
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Get-CredentialProcess
2+
{
3+
$edition = 'Desktop'
4+
5+
if (Get-Variable -Name PSEdition)
6+
{
7+
$edition = $PSEdition
8+
}
9+
10+
$process = @{
11+
PowerShell = $(
12+
if ($edition -eq 'Desktop')
13+
{
14+
(Get-Command 'PowerShell.exe').Source
15+
}
16+
else
17+
{
18+
(Get-Command 'pwsh').Source
19+
}
20+
)
21+
Module = (Get-PSCallStack)[0].InvocationInfo.MyCommand.Module.Name
22+
}
23+
24+
$sb = New-Object System.Text.StringBuilder
25+
26+
if ($process.PowerShell -match '\s')
27+
{
28+
$sb.Append("`"$($process.PowerShell)`"") | Out-Null
29+
}
30+
else
31+
{
32+
$sb.Append($process.PowerShell) | Out-Null
33+
}
34+
35+
$sb.Append(" -Command `"Import-Module $($process.Module); Set-AwsCredentail {0}; Get-ATIAMSessionCredentials -AwsCli`"") | Out-Null
36+
37+
$process['CredentialProcess'] = $sb.ToString()
38+
39+
$process
40+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Function Read-CliConfigurationFile
2+
{
3+
param
4+
(
5+
[Parameter(Mandatory, ParameterSetName = 'config')]
6+
[switch]$Config,
7+
8+
[Parameter(Mandatory, ParameterSetName = 'credentials')]
9+
[switch]$Credentials,
10+
11+
[string]$AlternateDirectory
12+
)
13+
14+
$FilePath = $(
15+
16+
if (-not [string]::IsNullOrEmpty($AlternateDirectory))
17+
{
18+
Join-Path $AlternateDirectory $PSCmdlet.ParameterSetName
19+
}
20+
else
21+
{
22+
if ((Get-OperatingSystem) -eq 'Windows')
23+
{
24+
Join-Path $env:USERPROFILE ".aws\$($PSCmdlet.ParameterSetName)"
25+
}
26+
else
27+
{
28+
"~/.aws/$($PSCmdlet.ParameterSetName)"
29+
}
30+
}
31+
)
32+
33+
$configuration = @{ }
34+
35+
if (Test-Path -Path $FilePath)
36+
{
37+
switch -regex -file $FilePath
38+
{
39+
"^\[(.+)\]$"
40+
{
41+
# Section
42+
$section = $matches[1]
43+
$configuration[$section] = @{ }
44+
$CommentCount = 0
45+
}
46+
"^(;.*)$"
47+
{
48+
# Comment
49+
if (!($section))
50+
{
51+
$section = "No-Section"
52+
$configuration[$section] = @{ }
53+
}
54+
$value = $matches[1]
55+
$CommentCount = $CommentCount + 1
56+
$name = "Comment" + $CommentCount
57+
$configuration[$section][$name] = $value
58+
}
59+
"(.+?)\s*=\s*(.*)"
60+
{
61+
# Key
62+
if (!($section))
63+
{
64+
$section = "No-Section"
65+
$configuration[$section] = @{ }
66+
}
67+
$name, $value = $matches[1..2]
68+
$configuration[$section][$name] = $value
69+
}
70+
}
71+
}
72+
else
73+
{
74+
Write-Warning "No AWS $($PSCmdlet.ParameterSetName) file found."
75+
}
76+
77+
return $configuration
78+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Function Write-CliConfigurationFile
2+
{
3+
Param
4+
(
5+
[Parameter(Mandatory, ParameterSetName = 'config')]
6+
[switch]$Config,
7+
8+
[Parameter(Mandatory, ParameterSetName = 'credentials')]
9+
[switch]$Credentials,
10+
11+
[ValidateNotNullOrEmpty()]
12+
[Parameter(ValueFromPipeline = $True, Mandatory = $True)]
13+
[Hashtable]$InputObject,
14+
15+
[string]$AlternateDirectory
16+
)
17+
18+
Begin
19+
{
20+
$Encoding = 'ASCII'
21+
$FilePath = $(
22+
if (-not [string]::IsNullOrEmpty($AlternateDirectory))
23+
{
24+
Join-Path $AlternateDirectory $PSCmdlet.ParameterSetName
25+
}
26+
else
27+
{
28+
if ((Get-OperatingSystem) -eq 'Windows')
29+
{
30+
Join-Path $env:USERPROFILE ".aws\$($PSCmdlet.ParameterSetName)"
31+
}
32+
else
33+
{
34+
"~/.aws/$($PSCmdlet.ParameterSetName)"
35+
}
36+
}
37+
)
38+
}
39+
40+
Process
41+
{
42+
$outFile = New-Item -ItemType file -Path $Filepath -Force
43+
44+
if (-not ($outFile))
45+
{
46+
Throw "Could not create File"
47+
}
48+
49+
foreach ($i in $InputObject.keys)
50+
{
51+
if (-not ($($InputObject[$i].GetType().Name) -eq "Hashtable"))
52+
{
53+
#No Sections
54+
Add-Content -Path $outFile -Value "$i=$($InputObject[$i])" -Encoding $Encoding
55+
}
56+
else
57+
{
58+
#Sections
59+
Add-Content -Path $outFile -Value "[$i]" -Encoding $Encoding
60+
Foreach ($j in $($InputObject[$i].keys | Sort-Object))
61+
{
62+
if ($j -match "^Comment[\d]+")
63+
{
64+
Add-Content -Path $outFile -Value "$($InputObject[$i][$j])" -Encoding $Encoding
65+
}
66+
else
67+
{
68+
Add-Content -Path $outFile -Value "$j=$($InputObject[$i][$j])" -Encoding $Encoding
69+
}
70+
71+
}
72+
Add-Content -Path $outFile -Value "" -Encoding $Encoding
73+
}
74+
}
75+
}
76+
77+
End
78+
{ }
79+
}

aws-toolbox/aws-toolbox.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if (-not ((Test-ATEC2IsRunningInEC2) -or $null -ne (Get-Item variable:StoredAWSC
3131

3232
$script:PluginConfig = Import-PluginConfiguration
3333
$script:moduleConfig = Import-AwsToolboxConfiguration
34+
$script:isPester = $null -ne (Get-PSCallStack | Where-Object Command -eq 'Invoke-Pester')
3435

3536
# Export public functions
3637
Export-ModuleMember -Function $Public.Basename

0 commit comments

Comments
 (0)