Skip to content

Commit

Permalink
Optimise Hashicorp app functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronparker committed Sep 20, 2023
1 parent 6aa82ad commit 76d31bc
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 175 deletions.
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpBoundary.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpBoundary {
function Get-HashicorpBoundary {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Boundary.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpBoundary {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpConsul.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpConsul {
function Get-HashicorpConsul {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Consul.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpConsul {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpNomad.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpNomad {
function Get-HashicorpNomad {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Nomad.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpNomad {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpPacker.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpPacker {
function Get-HashicorpPacker {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Packer.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpPacker {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpTerraform.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpTerraform {
function Get-HashicorpTerraform {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Terraform.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpTerraform {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpVault.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpVault {
function Get-HashicorpVault {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Vault.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpVault {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
31 changes: 6 additions & 25 deletions Evergreen/Apps/Get-HashicorpWaypoint.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Function Get-HashicorpWaypoint {
function Get-HashicorpWaypoint {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp Waypoint.
Expand All @@ -8,34 +8,15 @@ Function Get-HashicorpWaypoint {
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $True
}
$object = Get-GitHubRepoRelease @params

# Build the output object
If ($Null -ne $object) {
ForEach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
$Output = Get-HashicorpApp -res $res
Write-Output -InputObject $Output
}
40 changes: 40 additions & 0 deletions Evergreen/Shared/Get-HashicorpApp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Function Get-HashicorpApp {
<#
.SYNOPSIS
Get the current versions and download URLs for Hashicorp apps.
.NOTES
Author: Aaron Parker
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject] $res
)

# Pass the repo releases API URL and return a formatted object
$params = @{
Uri = $res.Get.Update.Uri
MatchVersion = $res.Get.Update.MatchVersion
Filter = $res.Get.Update.MatchFileTypes
ReturnVersionOnly = $true
}
$object = Get-GitHubRepoRelease @params

# Build the output object
if ($null -ne $object) {
foreach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceText, $object.Version
$PSObject = [PSCustomObject] @{
Version = $object.Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $Uri
}
Write-Output -InputObject $PSObject
}
}
}

0 comments on commit 76d31bc

Please sign in to comment.