-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ps1
executable file
·48 lines (42 loc) · 1.52 KB
/
utils.ps1
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
#!/usr/bin/env pwsh
#Requires -Module AWSPowerShell
Get-ChildItem -Path ./conf/target/*.json | ForEach-Object {
$configuration = @{
Name = "btd_$($_.BaseName)"
Value = (Get-Content -LiteralPath $_.FullName | ConvertFrom-Json)
Force = $true
Scope = 'Global'
}
New-Variable @configuration
}
Set-DefaultAWSRegion -Region $btd_Defaults.DefaultRegion -Scope Global
# .ToArray() feels presumptious, that method name is ubiquitous, right?? or am i free to use that name?
Add-Member -InputObject $btd_CommonTags `
-Name ToTagArray `
-MemberType ScriptMethod `
-Value {
$btd_CommonTags.PSObject.Properties |
ForEach-Object {
[pscustomobject]@{Key=$_.Name;Value=$_.Value}}
}
Add-Member -InputObject $btd_IpPermissions `
-Name 'SetSecurityGroup' `
-MemberType 'ScriptMethod' `
-Value {
Param(
[string]$SecurityGroupId
)
($this | Where-Object UserIdGroupPairs -ne $null).UserIdGroupPairs | ForEach-Object {
$_.GroupId = $SecurityGroupId
}
}
Add-Member -InputObject $btd_IpPermissions `
-Name 'SetMyIp' `
-MemberType 'ScriptMethod' `
-Value {
$my_ip = (Invoke-WebRequest -Uri "http://ifconfig.me/ip").Content
($this | Where-Object IpV4Ranges -ne $null).IpV4Ranges | ForEach-Object {
$_.CidrIp = "$my_ip/32"
$_.Description = ($_.Description -f "$(whoami)@$(hostname -s)")
}
}