Skip to content

Commit

Permalink
Add -DotNetConstructor to Get-ATIAMSessionCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
fireflycons committed Nov 12, 2019
1 parent 7e269ea commit f0e8289
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions aws-toolbox/Public/IAM/Get-ATIAMSessionCredentials.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function Get-ATIAMSessionCredentials
.PARAMETER Bash
The credentials are formatted as EXPORT staements and output to the console
.PARAMETER DotNetConstructor
The credentials are formatted as new SessionAWSCredentials(...) and output to the console.
Note that you would not want to store this in any code. Useful only for quick debugging.
.PARAMETER Clipboard
If set, output of -Ruby or -Bash is copied directly to clipboard, so you can paste them into code or your active Ruby or Shell prompt
Expand All @@ -48,8 +52,12 @@ function Get-ATIAMSessionCredentials
[Parameter(ParameterSetName = "Shell")]
[switch]$Bash,

[Parameter(ParameterSetName = "DotNet")]
[switch]$DotNetConstructor,

[Parameter(ParameterSetName = "Ruby")]
[Parameter(ParameterSetName = "Shell")]
[Parameter(ParameterSetName = "DotNet")]
[switch]$ClipBoard,

[Parameter(ParameterSetName = "SetLocal")]
Expand Down Expand Up @@ -114,6 +122,31 @@ function Get-ATIAMSessionCredentials
$sb.ToString()
}
}
elseif ($DotNetConstructor)
{
$sb = New-Object System.Text.StringBuilder
$arr = @(
"`"$($cred.AccessKey)`""
"`"$($cred.SecretKey)`""
)

if ($cred.UseToken)
{
$arr += "`"$($cred.Token)`""
}

$sb.AppendLine("new SessionAWSCredentials($([string]::Join(",`n", $arr)));") | Out-Null

if ($ClipBoard)
{
$sb.ToString() | clip.exe
Write-Host "DotNet constructor copied to clipboard"
}
else
{
$sb.ToString()
}
}
elseif ($PSCmdlet.ParameterSetName -ieq 'SetLocal')
{
# Set local enviroment with credential material.
Expand Down

0 comments on commit f0e8289

Please sign in to comment.