-
Notifications
You must be signed in to change notification settings - Fork 2
/
Test-AzsAppServiceSecretExpiration.ps1
46 lines (38 loc) · 1.43 KB
/
Test-AzsAppServiceSecretExpiration.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
$ErrorActionPreference = "stop"
$azContext = Get-AzContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Tenant.TenantId)
$authHeader = "Bearer " + $token.AccessToken
$requestHeader = @{
"Authorization" = $authHeader
"Accept" = "application/json"
}
$subId = (Get-AzSubscription).Id
$region = (Get-AzsRegionHealth).Name
$adminManagementUrl = (Get-AzEnvironment -Name AzureStackAdmin).ResourceManagerUrl
$Url = $adminManagementUrl + "/subscriptions/" + $subId + "/providers/Microsoft.Web.Admin/locations/$region/secrets?api-version=2018-02-01"
$res = Invoke-RestMethod -Uri $Url -Method GET -Headers $requestHeader -ContentType $contentType
$res | format-table category,name,@{
Label="lifeRemaining"
Expression= {
switch ($_.lifeRemaining) {
{ $_ -lt 60 } {$color = "91"; break}
default {$color = "27"}
}
$e = [char]27
"$e[${color}m$($_.lifeRemaining)${e}[0m"
}
}
$flag = $true
$res | foreach-Object {
if ($_.lifeRemaining -lt 60){
$flag = $false
}
}
if ($flag -eq $true){
Write-Host "PASS" -foregroundcolor Greem
} else {
Write-Host "FAIL" -foregroundcolor Red
Write-Host "You need a secret rotation in App Sercive Blade"
}