Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review Get-vRAResource function #171

Merged
merged 5 commits into from
Feb 7, 2018

Conversation

BlackCatDeployment
Copy link
Contributor

Create an inner function New-vRAObjectResource for centralizing vRA Resource PS Object management
Fix URI when Resource ID is used
Fix URI when Resource Name is used (vRA 7 call is case sensitive for the resource name)
Add pages management when no parameter is passed. Before, only the first page was returned (so 100 items).

Create an inner function New-vRAObjectResource for centralizing vRA Resource PS Object management
Fix URI when Resource ID is used
Fix URI when Resource Name is used (vRA 7 call is case sensitive for the resource name)
Add pages management when no parameter is passed. Before, only the first page was returned (so 100 items).
Links = $Resource.links
IconId = $Resource.iconId

if ($Response.content.Count -ne 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo? Should it be:

$Resource.content.Count

@@ -116,36 +116,17 @@

foreach ($ResourceId in $Id) {

$URI = "/catalog-service/api/consumer/resourceViews/$($ResourceId)?withExtendedData=true&withOperations=true"
$URI = "/catalog-service/api/consumer/resourceViews?`$filter=id eq '$($ResourceId)'&withExtendedData=true&withOperations=true"

$EscapedURI = [uri]::EscapeUriString($URI)

$Resource = Invoke-vRARestMethod -Method GET -URI $EscapedURI -Verbose:$VerbosePreference
Copy link
Contributor Author

@BlackCatDeployment BlackCatDeployment Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad @jonathanmedd , I forgot to rename $Resource to $Response here in your version of the script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Can you just update that. I think the rest of the PR is fine

Fix a mistaken variable declaration.
Copy link
Contributor Author

@BlackCatDeployment BlackCatDeployment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

Function New-vRAObjectResource {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, our build script will export this as a public function. Could you modify the name to be:

function intNewvRAObjectResource

See here for reference:

function intRequestResourceActionTemplate($ResourceId, $ActionId) {

Also we tend to use [PSCustomObject] for building objects. Could you change line 249 - 274 to:

[PSCustomObject]@{
        ResourceId = $Data.ResourceId
        BusinessGroupId = $Data.businessGroupId
        BusinessGroupName = $Data.data.MachineGroupName
        TenantId = $Data.tenantId
        CatalogItemLabel = $Data.data.Component
        ParentResourceId = $Data.parentResourceId
        HasChildren = $Data.hasChildren
        Data = $Data.data
        ResourceType = $Data.resourceType
        Name = $Data.name
        Description = $Data.description
        Status = $Data.status
        RequestId = $Data.requestId      
        Owners = $Data.owners
        DateCreated = $Data.dateCreated
        LastUpdated = $Data.lastUpdated
        Lease = $Data.lease
        Costs = $Data.costs
        CostToDate = $Data.costToDate
        TotalCost = $Data.totalCost
        Links = $Data.links
        IconId = $Data.iconId
}

See this function for reference:

https://github.com/jakkulabs/PowervRA/blob/3a0b749c6d0bf90224c6e3dd51c83a681cb529a2/src/Functions/Public/identity/Get-vRAVersion.ps1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for renaming the function of course.
About your remark about typing the object, the New-Object -TypeName PSObject cmdlet already type the object as PSCustomObject.
image
And as I use splatting to dynamically set object properties, I think it's not necessary.
What's your point?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BlackCatDeployment It's more performant to use the [pscustomobject] way to create objects, rather than using New-Object. (See https://www.jonathanmedd.net/2011/09/powershell-v3-creating-objects-with-pscustomobject-its-fast.html for a rough comparison of speed difference) Also, it would be more consistent with how we have created objects in the rest of the project code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok done :)

@chelnak
Copy link
Contributor

chelnak commented Jan 29, 2018

@BlackCatDeployment Thanks so much for your contribution and apologies that it's taken me so long to review the PR. I've left a couple of comments above. Once those are sorted we can merge and this will be included in the next release!! Thanks 👍 🥇

To meet PowervRA dev syntax, renamed function New-vRAObjectResource to intNewvRAObjectResource
Review PSObject initialization to meet PowervRA dev syntax.
@jonathanmedd jonathanmedd added this to the 3.1.1 milestone Jan 31, 2018
@jonathanmedd jonathanmedd merged commit b0c49d9 into jakkulabs:master Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants