Akamai.EdgeHostnames.psm1

function Get-BodyObject {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory)]
        $Source
    )

    if ($Source -is 'String') {
        # Trim whitespace
        $Source = $Source.Trim()
        # Handle JSON array
        if ($Source.StartsWith('[')) {
            $BodyObject = ConvertFrom-Json -InputObject $Source -AsArray -NoEnumerate
        }
        # Handle standard JSON object
        elseif ($Source.StartsWith('{') -and $Source.EndsWith('}')) {
            $BodyObject = ConvertFrom-Json -InputObject $Source
        }
        # If none of the above, just use string as-is
        else {
            $BodyObject = $Source
        }
    }
    elseif ($Source -is 'Hashtable') {
        $BodyObject = [PScustomObject] $Source
    }
    elseif ($Source -is 'PSCustomObject' -or $Source -is 'Object' -or $Source -is 'Object[]') {
        $BodyObject = $Source
    }
    else {
        throw "Source param is of an unhandled type '$($Source.GetType().Name)'"
    }

    return $BodyObject
}

function Get-EdgeHostname {
    [CmdletBinding(DefaultParameterSetName = 'Get all')]
    Param(
        [Parameter(Position = 0, ParameterSetName = 'Get one by ID', ValueFromPipeline)]
        [int]
        $EdgeHostnameID,

        [Parameter(ParameterSetName = 'Get one by components', Mandatory)]
        [string]
        $RecordName,

        [Parameter(ParameterSetName = 'Get all')]
        [Parameter(ParameterSetName = 'Get one by components', Mandatory)]
        [string]
        $DNSZone,

        [Parameter(ParameterSetName = 'Get all')]
        [switch]
        $ChinaCDNEnabled,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        $Comments,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        $CustomTarget,

        [Parameter(ParameterSetName = 'Get all')]
        [switch]
        $IsEdgeIPBindingEnabled,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        $Map,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        $MapAlias,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        $RecordNameSubstring,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        $SecurityType,

        [Parameter(ParameterSetName = 'Get all')]
        [int]
        $SlotNumber,

        [Parameter(ParameterSetName = 'Get all')]
        [int]
        $TTL,

        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        if ($EdgeHostnameID) {
            $Path = "/hapi/v1/edge-hostnames/$EdgeHostnameID"
        }
        else {
            $Path = "/hapi/v1/edge-hostnames"
        }

        if ($PSCmdlet.ParameterSetName -eq 'Get all') {
            $QueryParameters = @{
                'chinaCdnEnabled'        = $PSBoundParameters.ChinaCDNEnabled
                'comments'               = $Comments
                'customTarget'           = $CustomTarget
                'dnsZone'                = $DNSZone
                'isEdgeIPBindingEnabled' = $PSBoundParameters.IsEdgeIPBindingEnabled
                'map'                    = $Map
                'mapAlias'               = $MapAlias
                'recordNameSubstring'    = $RecordNameSubstring
                'securityType'           = $SecurityType
                'slotNumber'             = $PSBoundParameters.SlotNumber
                'ttl'                    = $PSBoundParameters.TTL
            }
        }
        elseif ($PSCmdlet.ParameterSetName -eq 'Get one by components') {
            $Path = "/hapi/v1/dns-zones/$DNSZone/edge-hostnames/$RecordName"
        }
        $RequestParams = @{
            'Path'             = $Path
            'Method'           = 'GET'
            'QueryParameters'  = $QueryParameters
            'EdgeRCFile'       = $EdgeRCFile
            'Section'          = $Section
            'AccountSwitchKey' = $AccountSwitchKey
            'Debug'            = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        if ($PSCmdlet.ParameterSetName -eq 'Get all') {
            return $Response.Body.edgeHostnames
        }
        else {
            return $Response.Body
        }
    }
}

function Get-EdgeHostnameCertificate {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $RecordName,
        
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $DNSZone,

        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        $Path = "/hapi/v1/dns-zones/$DNSZone/edge-hostnames/$RecordName/certificate"
        $RequestParams = @{
            'Path'             = $Path
            'Method'           = 'GET'
            'EdgeRCFile'       = $EdgeRCFile
            'Section'          = $Section
            'AccountSwitchKey' = $AccountSwitchKey
            'Debug'            = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        return $Response.Body
    }
}

function Get-EdgeHostnameChangeRequest {
    [CmdletBinding(DefaultParameterSetName = 'Get all')]
    Param(
        [Parameter(ParameterSetName = 'Get one by ID', ValueFromPipeline)]
        [string]
        $ChangeID,

        [Parameter(ParameterSetName = 'Get one by components', Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $RecordName,

        [Parameter(ParameterSetName = 'Get one by components', Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $DNSZone,

        [Parameter(ParameterSetName = 'Get all')]
        [string]
        [ValidateSet('PENDING')]
        $Status,

        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        if ($ChangeID) {
            $Path = "/hapi/v1/change-requests/$ChangeID"
        }
        else {
            $Path = "/hapi/v1/change-requests"
        }

        if ($PSCmdlet.ParameterSetName -eq 'Get all') {
            $QueryParameters = @{
                'status' = $Status
            }
        }
        elseif ($PSCmdlet.ParameterSetName -eq 'Get one by components') {
            $Path = "/hapi/v1/dns-zones/$DNSZone/edge-hostnames/$RecordName/change-requests"
        }
        $RequestParams = @{
            'Path'             = $Path
            'Method'           = 'GET'
            'QueryParameters'  = $QueryParameters
            'EdgeRCFile'       = $EdgeRCFile
            'Section'          = $Section
            'AccountSwitchKey' = $AccountSwitchKey
            'Debug'            = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        if ($ChangeID) {
            return $Response.Body
        }
        else {
            return $Response.Body.changeRequests
        }
    }
}

function Get-EdgeHostnameLocalizationData {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [string]
        [ValidateSet('de_DE', 'en_US', 'es_ES', 'es_LA', 'fr_FR', 'it_IT', 'ja_JP', 'ko_KR', 'pt_BR', 'zh_CN', 'zh_TW')]
        $Language,

        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        $Path = "/hapi/v1/i18n/$Language"
        $RequestParams = @{
            'Path'             = $Path
            'Method'           = 'GET'
            'EdgeRCFile'       = $EdgeRCFile
            'Section'          = $Section
            'AccountSwitchKey' = $AccountSwitchKey
            'Debug'            = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        return $Response.Body.hapi.problems
    }
}

function Get-EdgeHostnameProduct {
    [CmdletBinding()]
    Param(
        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        $Path = "/hapi/v1/products/display-names"
        $RequestParams = @{
            'Path'             = $Path
            'Method'           = 'GET'
            'EdgeRCFile'       = $EdgeRCFile
            'Section'          = $Section
            'AccountSwitchKey' = $AccountSwitchKey
            'Debug'            = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        return $Response.Body.productDisplayNames
    }
}

function Remove-EdgeHostname {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [string]
        $RecordName,

        [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [string]
        $DNSZone,

        [Parameter()]
        [string]
        $Comments,

        [Parameter()]
        [string]
        $StatusUpdateEmail,

        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        $Path = "/hapi/v1/dns-zones/$DNSZone/edge-hostnames/$RecordName"
        $QueryParameters = @{
            'comments'          = $Comments
            'statusUpdateEmail' = $StatusUpdateEmail
        }
        $RequestParams = @{
            'Path'             = $Path
            'Method'           = 'DELETE'
            'QueryParameters'  = $QueryParameters
            'EdgeRCFile'       = $EdgeRCFile
            'Section'          = $Section
            'AccountSwitchKey' = $AccountSwitchKey
            'Debug'            = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        return $Response.Body
    }
}

function Set-EdgeHostname {
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $RecordName,

        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [string]
        $DNSZone,

        [Parameter(Mandatory)]
        [ValidateSet('ttl', 'ipVersionBehavior')]
        [string]
        $Attribute,

        [Parameter(Mandatory)]
        [string]
        $Value,

        [Parameter()]
        [string]
        $Comments,

        [Parameter()]
        [string]
        $StatusUpdateEmail,

        [Parameter()]
        [string]
        $EdgeRCFile,

        [Parameter()]
        [string]
        $Section,

        [Parameter()]
        [string]
        $AccountSwitchKey
    )

    process {
        $Path = "/hapi/v1/dns-zones/$DNSZone/edge-hostnames/$RecordName"
        $QueryParameters = @{
            'comments'          = $Comments
            'statusUpdateEmail' = $StatusUpdateEmail
        }
        $AdditionalHeaders = @{
            'Content-Type' = 'application/json-patch+json'
        }
        $Body = @(
            @{
                'op'    = 'replace'
                'path'  = "/$Attribute"
                'value' = $Value
            }
        )
        $RequestParams = @{
            'Path'              = $Path
            'Method'            = 'PATCH'
            'AdditionalHeaders' = $AdditionalHeaders
            'QueryParameters'   = $QueryParameters
            'Body'              = $Body
            'EdgeRCFile'        = $EdgeRCFile
            'Section'           = $Section
            'AccountSwitchKey'  = $AccountSwitchKey
            'Debug'             = ($PSBoundParameters.Debug -eq $true)
        }
        # Make Request
        $Response = Invoke-AkamaiRequest @RequestParams
        return $Response.Body
    }
}


# SIG # Begin signature block
# MIIKmAYJ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