machine-identities-lifecycle-actions/src/PSSailpoint.MachineIdentitiesLifecycleActions/Api/MachineIdentityLifecycleActionsApi.ps1

#
# SailPoint Identity Security API - Machine Identity Lifecycle Actions
# Use these APIs to submit, list, retrieve, and cancel machine identity lifecycle actions (currently activate and deactivate for Agent machine identities only). We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.
# Version: v1
# Generated by OpenAPI Generator: https://openapi-generator.tech
#

<#
.SYNOPSIS

Cancel machine identity lifecycle action

.DESCRIPTION

Cancels a lifecycle action request that hasn't started provisioning yet. When the cancel is accepted, the request moves to `CANCELING` status. A request can't be canceled once provisioning has started, after it has finished, or while a cancel is already in progress. The request body is optional. Use it to add a comment explaining why the request was canceled. You can always cancel requests that you submitted. To cancel a request that someone else submitted, you need the `idn:machine-identity:lifecycle-action` right **and** admin or owner access to the machine identity. Admin or owner access means you're an org admin, a source admin, a source sub-admin for the machine identity's source, or the machine identity's owner. If the cancel can't be completed, the API returns an error and the request stays in `CANCELING` status.

.PARAMETER RequestId
Lifecycle request identifier.

.PARAMETER XSailPointExperimental
Use this header to enable this experimental API.

.PARAMETER CancelLifecycleActionRequest
No description available.

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response

.OUTPUTS

CancelLifecycleActionResponse
#>

function Suspend-MachineIdentityLifecycleActionV1 {
    [CmdletBinding()]
    Param (
        [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        ${RequestId},
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        $XSailPointExperimental = "true",
        [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [PSCustomObject]
        ${CancelLifecycleActionRequest},
        [Switch]
        $WithHttpInfo
    )

    Process {
        'Calling method: Suspend-MachineIdentityLifecycleActionV1' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $LocalVarAccepts = @()
        $LocalVarContentTypes = @()
        $LocalVarQueryParameters = @{}
        $LocalVarHeaderParameters = @{}
        $LocalVarFormParameters = @{}
        $LocalVarPathParameters = @{}
        $LocalVarCookieParameters = @{}
        $LocalVarBodyParameter = $null

        # HTTP header 'Accept' (if needed)
        $LocalVarAccepts = @('application/json')

        # HTTP header 'Content-Type'
        $LocalVarContentTypes = @('application/json')

        $LocalVarUri = '/machine-identities/v1/lifecycle-actions/{requestId}/cancel'
        if (!$RequestId) {
            throw "Error! The required parameter `RequestId` missing when calling cancelMachineIdentityLifecycleActionV1."
        }
        $LocalVarUri = $LocalVarUri.replace('{requestId}', [System.Web.HTTPUtility]::UrlEncode($RequestId))

        if (!$XSailPointExperimental) {
            throw "Error! The required parameter `XSailPointExperimental` missing when calling cancelMachineIdentityLifecycleActionV1."
        }
        $LocalVarHeaderParameters['X-SailPoint-Experimental'] = $XSailPointExperimental

        if ($LocalVarContentTypes.Contains('application/json-patch+json') -or ($CancelLifecycleActionRequest -is [array])) {
            $LocalVarBodyParameter = $CancelLifecycleActionRequest | ConvertTo-Json -AsArray -Depth 100
        } else {
            $LocalVarBodyParameter = $CancelLifecycleActionRequest | ForEach-Object {
            # Get array of names of object properties that can be cast to boolean TRUE
            # PSObject.Properties - https://msdn.microsoft.com/en-us/library/system.management.automation.psobject.properties.aspx
            $NonEmptyProperties = $_.psobject.Properties | Where-Object {$null -ne $_.Value} | Select-Object -ExpandProperty Name
        
            # Convert object to JSON with only non-empty properties
            $_ | Select-Object -Property $NonEmptyProperties | ConvertTo-Json -Depth 100
            }
        }

        $LocalVarResult = Invoke-ApiClient -Method 'POST' `
                                -Uri $LocalVarUri `
                                -Accepts $LocalVarAccepts `
                                -ContentTypes $LocalVarContentTypes `
                                -Body $LocalVarBodyParameter `
                                -HeaderParameters $LocalVarHeaderParameters `
                                -QueryParameters $LocalVarQueryParameters `
                                -FormParameters $LocalVarFormParameters `
                                -CookieParameters $LocalVarCookieParameters `
                                -ReturnType "CancelLifecycleActionResponse" `
                                -IsBodyNullable $false

        if ($WithHttpInfo.IsPresent) {
            return $LocalVarResult
        } else {
            return $LocalVarResult["Response"]
        }
    }
}

<#
.SYNOPSIS

Get machine identity lifecycle action

.DESCRIPTION

Returns a single lifecycle action request, including its current status, approval details, and provisioning progress. Use it to follow a request after you submit or cancel it. You can always view requests that you submitted. To view a request that someone else submitted, you need the `idn:machine-identity:lifecycle-action` right **and** admin or owner access to the machine identity. Admin or owner access means you're an org admin, a source admin, a source sub-admin for the machine identity's source, or the machine identity's owner.

.PARAMETER RequestId
Lifecycle request identifier.

.PARAMETER XSailPointExperimental
Use this header to enable this experimental API.

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response

.OUTPUTS

LifecycleActionRequest
#>

function Get-MachineIdentityLifecycleActionV1 {
    [CmdletBinding()]
    Param (
        [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        ${RequestId},
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        $XSailPointExperimental = "true",
        [Switch]
        $WithHttpInfo
    )

    Process {
        'Calling method: Get-MachineIdentityLifecycleActionV1' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $LocalVarAccepts = @()
        $LocalVarContentTypes = @()
        $LocalVarQueryParameters = @{}
        $LocalVarHeaderParameters = @{}
        $LocalVarFormParameters = @{}
        $LocalVarPathParameters = @{}
        $LocalVarCookieParameters = @{}
        $LocalVarBodyParameter = $null

        # HTTP header 'Accept' (if needed)
        $LocalVarAccepts = @('application/json')

        $LocalVarUri = '/machine-identities/v1/lifecycle-actions/{requestId}'
        if (!$RequestId) {
            throw "Error! The required parameter `RequestId` missing when calling getMachineIdentityLifecycleActionV1."
        }
        $LocalVarUri = $LocalVarUri.replace('{requestId}', [System.Web.HTTPUtility]::UrlEncode($RequestId))

        if (!$XSailPointExperimental) {
            throw "Error! The required parameter `XSailPointExperimental` missing when calling getMachineIdentityLifecycleActionV1."
        }
        $LocalVarHeaderParameters['X-SailPoint-Experimental'] = $XSailPointExperimental

        $LocalVarResult = Invoke-ApiClient -Method 'GET' `
                                -Uri $LocalVarUri `
                                -Accepts $LocalVarAccepts `
                                -ContentTypes $LocalVarContentTypes `
                                -Body $LocalVarBodyParameter `
                                -HeaderParameters $LocalVarHeaderParameters `
                                -QueryParameters $LocalVarQueryParameters `
                                -FormParameters $LocalVarFormParameters `
                                -CookieParameters $LocalVarCookieParameters `
                                -ReturnType "LifecycleActionRequest" `
                                -IsBodyNullable $false

        if ($WithHttpInfo.IsPresent) {
            return $LocalVarResult
        } else {
            return $LocalVarResult["Response"]
        }
    }
}

<#
.SYNOPSIS

List machine identity lifecycle actions

.DESCRIPTION

Returns the lifecycle action requests that you submitted. Requests that other users submitted aren't included, even if you're an admin. If the call isn't made on behalf of an identity, the list is empty. When `limit` is omitted, up to 50 results are returned.

.PARAMETER XSailPointExperimental
Use this header to enable this experimental API.

.PARAMETER Filters
Filter results using the standard syntax described in [API Standard Collection Parameters](https://developer.sailpoint.com/docs/api/standard-collection-parameters#filtering-results) Filtering is supported for the following fields and operators: **resourceType**: *eq, in* **operationType**: *eq, in* **status**: *eq, in* **completed**: *eq* **targetId**: *eq* **targetName**: *eq, sw* **sourceId**: *eq* **created**: *gt, ge, lt, le* The `resourceType` filter matches the `targetType` field in the response.

.PARAMETER Sorters
Sort results using the standard syntax described in [API Standard Collection Parameters](https://developer.sailpoint.com/docs/api/standard-collection-parameters#sorting-results) Sorting is supported for the following fields: **created, modified, status** Default sort is **-created** (newest first).

.PARAMETER Limit
Max number of results to return. When omitted, the default limit is 50. The maximum allowed limit is 250. See [API Standard Collection Parameters](https://developer.sailpoint.com/docs/api/standard-collection-parameters) for more information.

.PARAMETER Offset
Offset into the full result set. Usually specified with *limit* to paginate through the results. See [API Standard Collection Parameters](https://developer.sailpoint.com/docs/api/standard-collection-parameters) for more information.

.PARAMETER Count
If *true* it will populate the *X-Total-Count* response header with the number of results that would be returned if *limit* and *offset* were ignored. Since requesting a total count can have a performance impact, it is recommended not to send **count=true** if that value will not be used. See [API Standard Collection Parameters](https://developer.sailpoint.com/docs/api/standard-collection-parameters) for more information.

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response

.OUTPUTS

LifecycleActionRequest[]
#>

function Get-MachineIdentityLifecycleActionsV1 {
    [CmdletBinding()]
    Param (
        [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        $XSailPointExperimental = "true",
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        ${Filters},
        [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        ${Sorters},
        [Parameter(Position = 3, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [System.Nullable[Int32]]
        ${Limit},
        [Parameter(Position = 4, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [System.Nullable[Int32]]
        ${Offset},
        [Parameter(Position = 5, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [System.Nullable[Boolean]]
        ${Count},
        [Switch]
        $WithHttpInfo
    )

    Process {
        'Calling method: Get-MachineIdentityLifecycleActionsV1' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $LocalVarAccepts = @()
        $LocalVarContentTypes = @()
        $LocalVarQueryParameters = @{}
        $LocalVarHeaderParameters = @{}
        $LocalVarFormParameters = @{}
        $LocalVarPathParameters = @{}
        $LocalVarCookieParameters = @{}
        $LocalVarBodyParameter = $null

        # HTTP header 'Accept' (if needed)
        $LocalVarAccepts = @('application/json')

        $LocalVarUri = '/machine-identities/v1/lifecycle-actions'

        if (!$XSailPointExperimental) {
            throw "Error! The required parameter `XSailPointExperimental` missing when calling listMachineIdentityLifecycleActionsV1."
        }
        $LocalVarHeaderParameters['X-SailPoint-Experimental'] = $XSailPointExperimental

        if ($Filters) {
            $LocalVarQueryParameters['filters'] = $Filters
        }

        if ($Sorters) {
            $LocalVarQueryParameters['sorters'] = $Sorters
        }

        if ($Limit) {
            $LocalVarQueryParameters['limit'] = $Limit
        }

        if ($Offset) {
            $LocalVarQueryParameters['offset'] = $Offset
        }

        if ($Count) {
            $LocalVarQueryParameters['count'] = $Count
        }

        $LocalVarResult = Invoke-ApiClient -Method 'GET' `
                                -Uri $LocalVarUri `
                                -Accepts $LocalVarAccepts `
                                -ContentTypes $LocalVarContentTypes `
                                -Body $LocalVarBodyParameter `
                                -HeaderParameters $LocalVarHeaderParameters `
                                -QueryParameters $LocalVarQueryParameters `
                                -FormParameters $LocalVarFormParameters `
                                -CookieParameters $LocalVarCookieParameters `
                                -ReturnType "LifecycleActionRequest[]" `
                                -IsBodyNullable $false

        if ($WithHttpInfo.IsPresent) {
            return $LocalVarResult
        } else {
            return $LocalVarResult["Response"]
        }
    }
}

<#
.SYNOPSIS

Submit machine identity lifecycle action

.DESCRIPTION

Submits a request to activate or deactivate a machine identity. Supported actions are `ACTIVATE` and `DEACTIVATE`. **Note:** Lifecycle actions are currently supported only for machine identities of type **Agent**. The response includes a `requestId`. Use it to [get the request](https://developer.sailpoint.com/docs/api/get-machine-identity-lifecycle-action-v-1) or [cancel it](https://developer.sailpoint.com/docs/api/cancel-machine-identity-lifecycle-action-v-1). To see all the requests you've submitted, use [list machine identity lifecycle actions](https://developer.sailpoint.com/docs/api/list-machine-identity-lifecycle-actions-v-1). Only one lifecycle action can be in progress for a machine identity at a time. If another action is already in progress for the machine identity, the request is rejected. To submit a lifecycle action, you need the `idn:machine-identity:lifecycle-action` right, or admin or owner access to the machine identity. Admin or owner access means you're an org admin, a source admin, a source sub-admin for the machine identity's source, or the machine identity's owner.

.PARAMETER Id
Machine identity ID.

.PARAMETER XSailPointExperimental
Use this header to enable this experimental API.

.PARAMETER LifecycleActionSubmitRequest
No description available.

.PARAMETER WithHttpInfo

A switch when turned on will return a hash table of Response, StatusCode and Headers instead of just the Response

.OUTPUTS

LifecycleActionSubmitResponse
#>

function Submit-MachineIdentityLifecycleActionV1 {
    [CmdletBinding()]
    Param (
        [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        ${Id},
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [String]
        $XSailPointExperimental = "true",
        [Parameter(Position = 2, ValueFromPipelineByPropertyName = $true, Mandatory = $false)]
        [PSCustomObject]
        ${LifecycleActionSubmitRequest},
        [Switch]
        $WithHttpInfo
    )

    Process {
        'Calling method: Submit-MachineIdentityLifecycleActionV1' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $LocalVarAccepts = @()
        $LocalVarContentTypes = @()
        $LocalVarQueryParameters = @{}
        $LocalVarHeaderParameters = @{}
        $LocalVarFormParameters = @{}
        $LocalVarPathParameters = @{}
        $LocalVarCookieParameters = @{}
        $LocalVarBodyParameter = $null

        # HTTP header 'Accept' (if needed)
        $LocalVarAccepts = @('application/json')

        # HTTP header 'Content-Type'
        $LocalVarContentTypes = @('application/json')

        $LocalVarUri = '/machine-identities/v1/{id}/lifecycle-actions'
        if (!$Id) {
            throw "Error! The required parameter `Id` missing when calling submitMachineIdentityLifecycleActionV1."
        }
        $LocalVarUri = $LocalVarUri.replace('{id}', [System.Web.HTTPUtility]::UrlEncode($Id))

        if (!$XSailPointExperimental) {
            throw "Error! The required parameter `XSailPointExperimental` missing when calling submitMachineIdentityLifecycleActionV1."
        }
        $LocalVarHeaderParameters['X-SailPoint-Experimental'] = $XSailPointExperimental

        if (!$LifecycleActionSubmitRequest) {
            throw "Error! The required parameter `LifecycleActionSubmitRequest` missing when calling submitMachineIdentityLifecycleActionV1."
        }

        if ($LocalVarContentTypes.Contains('application/json-patch+json') -or ($LifecycleActionSubmitRequest -is [array])) {
            $LocalVarBodyParameter = $LifecycleActionSubmitRequest | ConvertTo-Json -AsArray -Depth 100
        } else {
            $LocalVarBodyParameter = $LifecycleActionSubmitRequest | ForEach-Object {
            # Get array of names of object properties that can be cast to boolean TRUE
            # PSObject.Properties - https://msdn.microsoft.com/en-us/library/system.management.automation.psobject.properties.aspx
            $NonEmptyProperties = $_.psobject.Properties | Where-Object {$null -ne $_.Value} | Select-Object -ExpandProperty Name
        
            # Convert object to JSON with only non-empty properties
            $_ | Select-Object -Property $NonEmptyProperties | ConvertTo-Json -Depth 100
            }
        }

        $LocalVarResult = Invoke-ApiClient -Method 'POST' `
                                -Uri $LocalVarUri `
                                -Accepts $LocalVarAccepts `
                                -ContentTypes $LocalVarContentTypes `
                                -Body $LocalVarBodyParameter `
                                -HeaderParameters $LocalVarHeaderParameters `
                                -QueryParameters $LocalVarQueryParameters `
                                -FormParameters $LocalVarFormParameters `
                                -CookieParameters $LocalVarCookieParameters `
                                -ReturnType "LifecycleActionSubmitResponse" `
                                -IsBodyNullable $false

        if ($WithHttpInfo.IsPresent) {
            return $LocalVarResult
        } else {
            return $LocalVarResult["Response"]
        }
    }
}