-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAWS.SAML.Settings.psm1
97 lines (79 loc) · 1.94 KB
/
AWS.SAML.Settings.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function Save-AWSSAMLURL {
[CmdletBinding()]
param(
)
$SaveDir = Get-SaveDir
$URL = Read-Host -Prompt 'Enter the SSO Initiation URL'
# Save the settings to the local system
if(!(Test-Path($SaveDir))){
New-Item -Type Directory -Path $SaveDir | Out-Null
}
$URL | Export-CliXml -Path ("$SaveDir\Settings.xml") -Encoding 'utf8' -Force
return $URL
}
function Get-AWSSAMLURL {
[OutputType([String])]
[CmdletBinding()]
param(
)
$SavePath = "$(Get-SaveDir)\Settings.xml"
if(Test-Path($SavePath)){
return Import-CliXml -Path ($SavePath)
}else{
Return Save-AWSSAMLURL
}
}
function Get-SaveDir {
[OutputType([String])]
[CmdletBinding()]
param(
)
if($IsMacOS){
return "${env:\HOME}/.AWS.SAML"
}else{
return "${env:\userprofile}\.AWS.SAML"
}
}
function Get-AWSDirectory{
[OutputType([String])]
[CmdletBinding()]
param(
)
if($IsMacOS){
return "${env:\HOME}/.aws/"
}else{
return "${env:\userprofile}\.aws\"
}
}
function Get-AWSCredentialFile{
[OutputType([Array])]
[CmdletBinding()]
param(
)
$directory = Get-AWSDirectory
# Return the credential file or a blank string if it doesn't yet exist
if(Test-Path $directory){
if(Test-Path "$directory`credentials"){
return Get-Content -Path "$directory`credentials"
}else{
return $null
}
}else{
return $null
}
}
function Save-AWSCredentialFile{
[CmdletBinding()]
param(
$FileContent
)
$directory = Get-AWSDirectory
# Create the folder if it doesn't exist
if(!(Test-Path $directory)){
New-Item -ItemType Directory $directory
}
if(!(Test-Path "$directory`credentials")){
New-Item -ItemType File "$directory`credentials"
}
$FileContent | Set-Content -Path "$directory`credentials" -Encoding utf8NoBOM
}