Classes/Public/PrismSession.ps1


class PrismSession {
    ## A Name parameter to identify the session in other -PrismSession functions
    [String]$Name

    # Prism Central server hostname (or IP)
    [string]$PrismServer

    # Prism Central server port. Prism Central typically listens on 9440.
    [int]$PrismPort

    # ApiVersion drives the selection of compatible APIs to use
    [string]$ApiVersion

    # Logged in Prism user's context (indicates logged-in-ness)
    [pscustomobject]$UserContext

    # Earliest server-provided authentication session-cookie expiry (UTC).
    # Null when none is provided; Test-PrismSession checks validity with the API.
    [Nullable[datetime]]$ExpirationDate

    # PrismWebSession. Maintained by the Invoke-WebRequest function's capability and
    # carries both the Basic Authorization header and the NTNX_IGW_SESSION cookie.
    [Microsoft.PowerShell.Commands.WebRequestSession]$PrismWebSession

    ## Tracks non-changing items to reduce HTTP lookups, and increase speed of scripts.
    [hashtable]$DataCache

    ## Should PowerShell ignore the SSL Cert on the Prism Central server?
    [bool]$AllowInsecureSSL

    PrismSession() {
        $this.Name = $null
        $this.AllowInsecureSSL = $false
        $this.DataCache = @{}
        $this.UserContext = $null
        $this.PrismPort = 9440
        $this.PrismWebSession = New-Object -Type Microsoft.PowerShell.Commands.WebRequestSession
    }

    PrismSession([String]$_name) {
        $this.Name = $_name
        $this.AllowInsecureSSL = $false
        $this.DataCache = @{}
        $this.UserContext = $null
        $this.PrismPort = 9440
        $this.PrismWebSession = New-Object -Type Microsoft.PowerShell.Commands.WebRequestSession
    }

    PrismSession([String]$_name, [String]$_server, [Bool]$_allowInsecureSSL = $false) {
        $this.Name = $_name
        $this.AllowInsecureSSL = $_allowInsecureSSL
        $this.PrismServer = $_server
        $this.PrismPort = 9440
        $this.DataCache = @{}
        $this.UserContext = $null
        $this.PrismWebSession = New-Object -Type Microsoft.PowerShell.Commands.WebRequestSession
    }

    PrismSession([String]$_name, [String]$_server, [int]$_port, [Bool]$_allowInsecureSSL = $false) {
        $this.Name = $_name
        $this.AllowInsecureSSL = $_allowInsecureSSL
        $this.PrismServer = $_server
        $this.PrismPort = $_port
        $this.DataCache = @{}
        $this.UserContext = $null
        $this.PrismWebSession = New-Object -Type Microsoft.PowerShell.Commands.WebRequestSession
    }
}