<commit_before>try {
    if (!$DotFilesFastLoad) {
        Test-ModuleAvailable -Name AWS.Tools.Installer, AWSPowerShell.NetCore, AWSPowerShell -Require Any -Verbose:$false
    }
} catch {
    Write-Verbose -Message (Get-DotFilesMessage -Message 'Skipping import of AWS functions.')
    return
}

Write-Verbose -Message (Get-DotFilesMessage -Message 'Importing AWS functions ...')

#region IAM

# Set AWS credential environment variables from an AWSCredentials object
Function Set-AWSCredentialEnvironment {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')]
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUsePSCredentialType', '')]
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [Amazon.SecurityToken.Model.Credentials]$Credential
    )

    Process {
        $env:AWS_ACCESS_KEY_ID = $Credential.AccessKeyId
        $env:AWS_SECRET_ACCESS_KEY = $Credential.SecretAccessKey
        $env:AWS_SESSION_TOKEN = $Credential.SessionToken
    }
}

#endregion

#region Route 53

Function Set-R53HostedZoneNameTag {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [Amazon.Route53.Model.HostedZone[]]$HostedZone
    )

    Begin {
        Test-ModuleAvailable -Name AWS.Tools.Route53, AWSPowerShell.NetCore, AWSPowerShell -Require Any

        $Tag = [Amazon.Route53.Model.Tag]::new()
        $Tag.Key = 'Name'
    }

    Process {
        foreach ($Zone in $HostedZone) {
            $ResourceId = $Zone.Id.Replace('/hostedzone/', [String]::Empty)
            $Tag.Value = $Zone.Name.TrimEnd('.')

            if ($PSCmdlet.ShouldProcess($Zone.Name, 'Set Name tag')) {
                Edit-R53TagsForResource -ResourceId $ResourceId -ResourceType 'hostedzone' -AddTag $Tag
            }
        }
    }
}

Function Set-R53HostedZoneParkedRecords {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Mandatory)]
        [String[]]$Domain,

        [Parameter(Mandatory)]
        [ValidateSet('MX', 'SPF', 'DKIM', 'DMARC', 'CAA', 'Redirect')]
        [String[]]$Records,

        # E.g. mailto:<EMAIL>
        [ValidateNotNullOrEmpty()]
        [String[]]$DmarcRua,
        # E.g. mailto:<EMAIL>
        [ValidateNotNullOrEmpty()]
        [String[]]$DmarcRuf,

        # E.g. amazon.com
        [ValidateNotNullOrEmpty()]
        [String[]]$CaaIssue,
        # E.g. digicert.com
        [ValidateNotNullOrEmpty()]
        [String[]]$CaaIssueWild,
        # E.g. mailto:<EMAIL>
        [ValidateNotNullOrEmpty()]
        [String[]]$CaaIoDef,

        # E.g. 1234567890ABCD.cloudfront.net.
        [ValidateNotNullOrEmpty()]
        [String]$RedirectCloudFrontDomainName,
        [ValidateSet('A', 'AAAA')]
        [String[]]$RedirectCloudFrontRecordTypes = 'A'
    )

    Test-ModuleAvailable -Name AWS.Tools.Route53, AWSPowerShell.NetCore, AWSPowerShell -Require Any

    try {
        $Zones = Get-R53HostedZoneList -ErrorAction Stop
    } catch {
        throw $_
    }

    $CloudFrontHostedZoneId = 'Z2FDTNDATAQYW2'
    $Changes = [Collections.ArrayList]::new()

    # Construct the DMARC record
    if ($Records -contains 'DMARC') {
        $Dmarc = 'v=DMARC1; p=reject'

        if ($DmarcRua) {
            $Dmarc = '{0}; rua={1}' -f $Dmarc, [String]::Join(',', $DmarcRua)
        }

        if ($DmarcRuf) {
            $Dmarc = '{0}; ruf={1}' -f $Dmarc, [String]::Join(',', $DmarcRuf)
        }

        $Dmarc = '{0}; fo=1' -f $Dmarc
    }

    # Construct each CAA record
    if ($Records -contains 'CAA') {
        $Caa = [Collections.ArrayList]::new()

        if ($CaaIssue) {
            foreach ($CaaIssuer in $CaaIssue) {
                $null = $Caa.Add(('0 issue "{0}"' -f $CaaIssuer))
            }
        } else {
            $null = $Caa.Add('0 issue ";"')
        }

        if ($CaaIssueWild) {
            foreach ($CaaWildIssuer in $CaaIssueWild) {
                $null = $Caa.Add(('0 issuewild "{0}"' -f $CaaWildIssuer))
            }
        } elseif ($CaaIssue) {
            $null = $Caa.Add('0 issuewild ";"')
        }

        if ($CaaIoDef) {
            foreach ($CaaReportUrl in $CaaIoDef) {
                $null = $Caa.Add(('0 iodef "{0}"' -f $CaaReportUrl))
            }
        }
    }

    # Process record changes for each zone
    foreach ($ZoneName in $Domain) {
        $ZoneName = $ZoneName.TrimEnd('.').ToLower()
        $ZoneFqdn = '{0}.' -f $ZoneName

        $Zone = $Zones | Where-Object Name -EQ $ZoneFqdn
        if (!$Zone) {
            Write-Warning -Message ('Unable to set records for non-existent zone: {0}' -f $ZoneName)
            continue
        }

        $ZoneRecords = [Collections.ArrayList]::new()

        if ($Records -contains 'MX') {
            $Record = New-Object Amazon.Route53.Model.Change
            $Record.Action = 'UPSERT'
            $Record.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
            $Record.ResourceRecordSet.Name = $ZoneName
            $Record.ResourceRecordSet.Type = 'MX'
            $Record.ResourceRecordSet.TTL = 3600
            $Record.ResourceRecordSet.ResourceRecords.Add(@{ Value = '0 .' })<commit_msg>Do not add a default CAA issuewild record<commit_after>try {
    if (!$DotFilesFastLoad) {
        Test-ModuleAvailable -Name AWS.Tools.Installer, AWSPowerShell.NetCore, AWSPowerShell -Require Any -Verbose:$false
    }
} catch {
    Write-Verbose -Message (Get-DotFilesMessage -Message 'Skipping import of AWS functions.')
    return
}

Write-Verbose -Message (Get-DotFilesMessage -Message 'Importing AWS functions ...')

#region IAM

# Set AWS credential environment variables from an AWSCredentials object
Function Set-AWSCredentialEnvironment {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingPlainTextForPassword', '')]
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUsePSCredentialType', '')]
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [Amazon.SecurityToken.Model.Credentials]$Credential
    )

    Process {
        $env:AWS_ACCESS_KEY_ID = $Credential.AccessKeyId
        $env:AWS_SECRET_ACCESS_KEY = $Credential.SecretAccessKey
        $env:AWS_SESSION_TOKEN = $Credential.SessionToken
    }
}

#endregion

#region Route 53

Function Set-R53HostedZoneNameTag {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [Amazon.Route53.Model.HostedZone[]]$HostedZone
    )

    Begin {
        Test-ModuleAvailable -Name AWS.Tools.Route53, AWSPowerShell.NetCore, AWSPowerShell -Require Any

        $Tag = [Amazon.Route53.Model.Tag]::new()
        $Tag.Key = 'Name'
    }

    Process {
        foreach ($Zone in $HostedZone) {
            $ResourceId = $Zone.Id.Replace('/hostedzone/', [String]::Empty)
            $Tag.Value = $Zone.Name.TrimEnd('.')

            if ($PSCmdlet.ShouldProcess($Zone.Name, 'Set Name tag')) {
                Edit-R53TagsForResource -ResourceId $ResourceId -ResourceType 'hostedzone' -AddTag $Tag
            }
        }
    }
}

Function Set-R53HostedZoneParkedRecords {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Mandatory)]
        [String[]]$Domain,

        [Parameter(Mandatory)]
        [ValidateSet('MX', 'SPF', 'DKIM', 'DMARC', 'CAA', 'Redirect')]
        [String[]]$Records,

        # E.g. mailto:dmarc-<EMAIL>
        [ValidateNotNullOrEmpty()]
        [String[]]$DmarcRua,
        # E.g. mailto:<EMAIL>
        [ValidateNotNullOrEmpty()]
        [String[]]$DmarcRuf,

        # E.g. amazon.com
        [ValidateNotNullOrEmpty()]
        [String[]]$CaaIssue,
        # E.g. digicert.com
        [ValidateNotNullOrEmpty()]
        [String[]]$CaaIssueWild,
        # E.g. mailto:<EMAIL>
        [ValidateNotNullOrEmpty()]
        [String[]]$CaaIoDef,

        # E.g. 1234567890ABCD.cloudfront.net.
        [ValidateNotNullOrEmpty()]
        [String]$RedirectCloudFrontDomainName,
        [ValidateSet('A', 'AAAA')]
        [String[]]$RedirectCloudFrontRecordTypes = 'A'
    )

    Test-ModuleAvailable -Name AWS.Tools.Route53, AWSPowerShell.NetCore, AWSPowerShell -Require Any

    try {
        $Zones = Get-R53HostedZoneList -ErrorAction Stop
    } catch {
        throw $_
    }

    $CloudFrontHostedZoneId = 'Z2FDTNDATAQYW2'
    $Changes = [Collections.ArrayList]::new()

    # Construct the DMARC record
    if ($Records -contains 'DMARC') {
        $Dmarc = 'v=DMARC1; p=reject'

        if ($DmarcRua) {
            $Dmarc = '{0}; rua={1}' -f $Dmarc, [String]::Join(',', $DmarcRua)
        }

        if ($DmarcRuf) {
            $Dmarc = '{0}; ruf={1}' -f $Dmarc, [String]::Join(',', $DmarcRuf)
        }

        $Dmarc = '{0}; fo=1' -f $Dmarc
    }

    # Construct each CAA record
    if ($Records -contains 'CAA') {
        $Caa = [Collections.ArrayList]::new()

        if ($CaaIssue) {
            foreach ($CaaIssuer in $CaaIssue) {
                $null = $Caa.Add(('0 issue "{0}"' -f $CaaIssuer))
            }
        } else {
            $null = $Caa.Add('0 issue ";"')
        }

        if ($CaaIssueWild) {
            foreach ($CaaWildIssuer in $CaaIssueWild) {
                $null = $Caa.Add(('0 issuewild "{0}"' -f $CaaWildIssuer))
            }
        }

        if ($CaaIoDef) {
            foreach ($CaaReportUrl in $CaaIoDef) {
                $null = $Caa.Add(('0 iodef "{0}"' -f $CaaReportUrl))
            }
        }
    }

    # Process record changes for each zone
    foreach ($ZoneName in $Domain) {
        $ZoneName = $ZoneName.TrimEnd('.').ToLower()
        $ZoneFqdn = '{0}.' -f $ZoneName

        $Zone = $Zones | Where-Object Name -EQ $ZoneFqdn
        if (!$Zone) {
            Write-Warning -Message ('Unable to set records for non-existent zone: {0}' -f $ZoneName)
            continue
        }

        $ZoneRecords = [Collections.ArrayList]::new()

        if ($Records -contains 'MX') {
            $Record = New-Object Amazon.Route53.Model.Change
            $Record.Action = 'UPSERT'
            $Record.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
            $Record.ResourceRecordSet.Name = $ZoneName
            $Record.ResourceRecordSet.Type = 'MX'
            $Record.ResourceRecordSet.TTL = 3600
            $Record.ResourceRecordSet.ResourceRecords.Add(@{ Value = '0 .' })
{'fraction_non_alphanumeric': 0.13771533057453567, 'fraction_numerical': 0.010682321239534212, 'mean_word_length': 2.3641955325348007, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6163696', 'n_tokens_mistral': 3480, 'n_tokens_neox': 3356, 'n_words': 622}