Skip to content

Commit

Permalink
Merge pull request #226 from jakkulabs/bugfix-update-calculateOutput-…
Browse files Browse the repository at this point in the history
…function

Bugfix update calculate output function
  • Loading branch information
jonathanmedd authored Jul 20, 2020
2 parents 91497a7 + 449667c commit ca32868
Show file tree
Hide file tree
Showing 38 changed files with 735 additions and 520 deletions.
Binary file modified .DS_Store
Binary file not shown.
14 changes: 7 additions & 7 deletions src/Functions/Public/Connect-vRAServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
# --- Handle untrusted certificates if necessary
$SignedCertificates = $true

if ($PSBoundParameters.ContainsKey("IgnoreCertRequirements") ){
if ($IgnoreCertRequirements.IsPresent){

if (!$IsCoreCLR) {

Expand Down Expand Up @@ -211,21 +211,21 @@
$Response = Invoke-RestMethod @Params

if ('refresh_token' -in $Response.PSobject.Properties.Name) {
$token = $Response.access_token
$refreshToken = $Response.refresh_token
$Token = $Response.access_token
$RefreshToken = $Response.refresh_token
}

if ('token' -in $Response.PSobject.Properties.Name) {
$token = $Response.token
$refreshToken = $APIToken
$Token = $Response.token
$RefreshToken = $APIToken
}

# --- Create Output Object
$Script:vRAConnection = [PSCustomObject] @{

Server = "https://$($Server)"
Token = $token
RefreshToken = $refreshToken
Token = $Token
RefreshToken = $RefreshToken
APIVersion = $Null
SignedCertificates = $SignedCertificates
SslProtocol = $SslProtocolResult
Expand Down
2 changes: 1 addition & 1 deletion src/Functions/Public/Invoke-vRARestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
try {

# --- Use either Invoke-WebRequest or Invoke-RestMethod
if ($PSBoundParameters.ContainsKey("WebRequest")) {
if ($WebRequest.IsPresent) {

Invoke-WebRequest @Params
}
Expand Down
26 changes: 13 additions & 13 deletions src/Functions/Public/codestream/Get-vRACodeStreamExecution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

$APIUrl = "/pipeline/api/executions"

function CalculateOutput($responseObject) {
foreach ($Record in $responseObject.documents.PsObject.Properties) {
function CalculateOutput($ResponseObject) {
foreach ($Record in $ResponseObject.documents.PsObject.Properties) {
[PSCustomObject]@{
Name = $Record.value.name+" #"+$Record.value.index
Project = $Record.value.project
Expand All @@ -74,38 +74,38 @@

# --- Get Execution by its id
'ById' {
foreach ($executionId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$executionId'" -Method GET
CalculateOutput($Response)
foreach ($ExecutionId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$ExecutionId'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Execution by its pipeline name
'ByName' {
foreach ($pipelineName in $Pipeline) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$pipelineName'" -Method GET
CalculateOutput($Response)
foreach ($PipelineName in $Pipeline) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$PipelineName'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Execution by its project name
'ByProject' {
foreach ($projectName in $Project) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=project eq '$projectName'" -Method GET
CalculateOutput($Response)
foreach ($ProjectName in $Project) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=project eq '$ProjectName'" -Method GET
CalculateOutput $Response
}

break
}

# --- No parameters passed so return all executions
'Standard' {
$Response = Invoke-vRARestMethod -URI $APIUrl -Method GET
CalculateOutput($Response)
CalculateOutput $Response
}

}
Expand Down
26 changes: 13 additions & 13 deletions src/Functions/Public/codestream/Get-vRACodeStreamPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

$APIUrl = "/pipeline/api/pipelines"

function CalculateOutput($responseObject) {
foreach ($Record in $responseObject.documents.PsObject.Properties) {
function CalculateOutput($ResponseObject) {
foreach ($Record in $ResponseObject.documents.PsObject.Properties) {
[PSCustomObject]@{
Name = $Record.value.name
Project = $Record.value.project
Expand All @@ -73,38 +73,38 @@

# --- Get Pipeline by its id
'ById' {
foreach ($pipelineId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$pipelineId'" -Method GET
CalculateOutput($Response)
foreach ($PipelineId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$PipelineId'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Pipeline by its pipeline name
'ByName' {
foreach ($pipelineName in $Pipeline) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$pipelineName'" -Method GET
CalculateOutput($Response)
foreach ($PipelineName in $Pipeline) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$PipelineName'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Pipeline by its project name
'ByProject' {
foreach ($projectName in $Project) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=project eq '$projectName'" -Method GET
CalculateOutput($Response)
foreach ($ProjectName in $Project) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=project eq '$ProjectName'" -Method GET
CalculateOutput $Response
}

break
}

# --- No parameters passed so return all Pipelines
'Standard' {
$Response = Invoke-vRARestMethod -URI $APIUrl -Method GET
CalculateOutput($Response)
CalculateOutput $Response
}

}
Expand Down
24 changes: 12 additions & 12 deletions src/Functions/Public/codestream/Get-vRACodeStreamVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

$APIUrl = "/pipeline/api/variables"

function CalculateOutput($responseObject) {
foreach ($Record in $responseObject.documents.PsObject.Properties) {
function CalculateOutput($ResponseObject) {
foreach ($Record in $ResponseObject.documents.PsObject.Properties) {
[PSCustomObject]@{
Name = $Record.value.name
Project = $Record.value.project
Expand All @@ -74,29 +74,29 @@

# --- Get Variable by its id
'ById' {
foreach ($variableId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$variableId'" -Method GET
CalculateOutput($Response)
foreach ($VariableId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$VariableId'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Variable by its name
'ByName' {
foreach ($variableName in $Variable) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$variableName'" -Method GET
CalculateOutput($Response)
foreach ($VariableName in $Variable) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$VariableName'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Variable by its project name
'ByProject' {
foreach ($projectName in $Project) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=project eq '$projectName'" -Method GET
CalculateOutput($Response)
foreach ($ProjectName in $Project) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=project eq '$ProjectName'" -Method GET
CalculateOutput $Response
}

break
Expand All @@ -105,7 +105,7 @@
# --- No parameters passed so return all Variables
'Standard' {
$Response = Invoke-vRARestMethod -URI $APIUrl -Method GET
CalculateOutput($Response)
CalculateOutput $Response
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function Remove-vRACodeStreamExecution {

'ById' {

foreach ($executionId in $Id) {
foreach ($ExecutionId in $Id) {E

if ($PSCmdlet.ShouldProcess($executionId)){
if ($PSCmdlet.ShouldProcess($ExecutionId)){

$URI = "/pipeline/api/executions/$($executionId)"
$URI = "/pipeline/api/executions/$($ExecutionId)"

Invoke-vRARestMethod -Method DELETE -URI "$($URI)" -Verbose:$VerbosePreference | Out-Null
}
Expand All @@ -58,4 +58,4 @@ function Remove-vRACodeStreamExecution {
throw
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function Remove-vRACodeStreamVariable {

'ById' {

foreach ($variableId in $Id) {
foreach ($VariableId in $Id) {

if ($PSCmdlet.ShouldProcess($variableId)){
if ($PSCmdlet.ShouldProcess($VariableId)){

$URI = "/pipeline/api/variables/$($variableId)"
$URI = "/pipeline/api/variables/$($VariableId)"

Invoke-vRARestMethod -Method DELETE -URI "$($URI)" -Verbose:$VerbosePreference | Out-Null
}
Expand All @@ -58,4 +58,4 @@ function Remove-vRACodeStreamVariable {
throw
}
}
}
}
117 changes: 117 additions & 0 deletions src/Functions/Public/iaas/Get-vRABlockDevice.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
function Get-vRABlockDevice {
<#
.SYNOPSIS
Retrieve vRA Block Device(s)[Hard Disks] depending on input
.DESCRIPTION
Retrieve a list of vRA Block Devices or a single Block Device depending on input
.PARAMETER Id
The ID of the vRA Block Device
.PARAMETER Name
The Name of the Block Device
.OUTPUTS
System.Management.Automation.PSObject.
.EXAMPLE
Get-vRABlockDevice
.EXAMPLE
Get-vRABlockDevice -Id 'b1dd48e71d74267559bb930934470'
.EXAMPLE
Get-vRABlockDevice -Name 'my-disk'
#>
[CmdletBinding(DefaultParameterSetName="Standard")][OutputType('System.Management.Automation.PSObject')]

Param (

[Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,ParameterSetName="ById")]
[ValidateNotNullOrEmpty()]
[String[]]$Id,

[Parameter(Mandatory=$true,ParameterSetName="ByName")]
[ValidateNotNullOrEmpty()]
[String[]]$Name

)
Begin {

$APIUrl = "/iaas/api/block-devices"

function CalculateOutput([PSCustomObject]$Response) {

foreach ($Record in $Response.content) {
[PSCustomObject]@{
Owner = $Record.owner
Links = $Record._links
ExternalZoneId = $Record.externalZoneId
ExternalRegionId = $Record.externalRegionId
Description = $Record.description
ExternalId = $Record.externalId
OrgId = $Record.orgId
Tags = $Record.tags
OrganizationId = $Record.organizationId
CapacityInGB = $Record.capacityInGB
CreatedAt = $Record.createdAt
CloudAccountIds = $Record.cloudAccountIds
CustomProperties = $Record.customProperties
DeploymentId = $Record.deploymentId
Name = $Record.name
Id = $Record.id
Persistent = $Record.persistent
ProjectId = $Record.projectId
UpdatedAt = $Record.updatedAt
Status = $Record.status
}
}
}
}
Process {

try {

switch ($PsCmdlet.ParameterSetName) {

# --- Get Machine by its id
'ById' {
foreach ($MachineId in $Id) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=id eq '$MachineId'" -Method GET
CalculateOutput $Response
}

break
}

# --- Get Machine by its name
'ByName' {
foreach ($MachineName in $Name) {
$Response = Invoke-vRARestMethod -URI "$APIUrl`?`$filter=name eq '$MachineName'" -Method GET
CalculateOutput $Response
}

break
}

# --- No parameters passed so return all machines
'Standard' {
$Response = Invoke-vRARestMethod -URI $APIUrl -Method GET
CalculateOutput $Response
}

}


}
catch [Exception]{

throw
}
}
End {

}
}
Loading

0 comments on commit ca32868

Please sign in to comment.