ps/Modules/Alkami.DevOps.Validations/Public/Get-CoreUrlsToTest.ps1
2023-05-30 22:51:22 -07:00

49 lines
1.5 KiB
PowerShell

function Get-CoreUrlsToTest {
<#
.SYNOPSIS
Gets the URLs of the websites to test
.DESCRIPTION
Currently pulls from S3 bucket to get a .json file of URLs.
.PARAMETER AwsProfile
Aws profile for connecting to S3
.NOTES
Returns a JSON string
#>
[cmdletbinding()]
[OutputType([System.String])]
Param (
[Parameter(Mandatory = $true)]
[string]$AwsProfile
)
$logLead = (Get-LogLeadName)
$environmentType = $AwsProfile.Replace("temp-","").ToLower()
$bucketName = "alkami-devops-validations-$environmentType"
$key = "coreurls.json"
$fileName = [System.IO.Path]::GetRandomFileName()
$S3Script = {
param($sbBucketName, $sbKey, $sbFileName, $sbAwsProfile)
(Read-S3Object -BucketName $sbBucketName -Key $sbKey -File $sbFileName -ProfileName $sbAwsProfile) | Out-Null
}
try{
Write-Host "$logLead Getting file from S3."
(Invoke-CommandWithRetry -Arguments ($bucketName, $key, $fileName, $AwsProfile) -MaxRetries 3 -Exponential -ScriptBlock $S3Script)
Write-Host "$logLead Getting content from file."
$contentJson = Get-Content -Path ".\$fileName" -Raw -ErrorAction SilentlyContinue
if($null -eq $contentJson) {
throw "Could not get Json content from file!"
}
} finally {
if(Test-Path ".\$fileName" -PathType Leaf) {
Write-Host "$logLead Removing file [$fileName]"
(Remove-FileSystemItem -Path ".\$fileName") | Out-Null
}
}
return ($contentJson | Out-String)
}