<commit_before>{
  "Id": "bc81b8a6-dc56-4769-87b5-650af7a38162",
  "Name": "Lets Encrypt - Create SSL Certificate",
  "Description": "Procures an X.509 SSL Certificate from the [Let’s Encrypt](https://letsencrypt.org) Certificate Authority using the [Automatic Certificate Management Environment (ACME)](https://ietf-wg-acme.github.io/acme/) protocol.",
  "ActionType": "Octopus.Script",
  "Version": 1,
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Script.ScriptBody": "<#\n ----- Lets Encrypt - Create SSL Certificate ----- \n    <NAME> @paulmarsy (<EMAIL>)\nLinks\n    https://github.com/OctopusDeploy/Library/commits/master/step-templates/letsencrypt-create-ssl-certificate.json\n#>\n\n$ErrorActionPreference = 'Stop'\n\nfunction Get-OctopusSetting {\n    param([Parameter(Position = 0, Mandatory)][string]$Name, [Parameter(Position = 1)]$DefaultValue)\n    $formattedName = 'Octopus.Action.{0}' -f $Name\n    if ($OctopusParameters.ContainsKey($formattedName)) {\n        $value = $OctopusParameters[$formattedName]\n        if ($DefaultValue -is [int]) { return ([int]::Parse($value)) }\n        if ($DefaultValue -is [bool]) { return ([System.Convert]::ToBoolean($value)) }\n        if ($DefaultValue -is [array] -or $DefaultValue -is [hashtable] -or $DefaultValue -is [pscustomobject]) { return (ConvertFrom-Json -InputObject $value) }\n        return $value\n    }\n    else { return $DefaultValue }\n}\nfunction Test-String {\n    param([Parameter(Position=0)]$InputObject,[switch]$ForAbsence)\n\n    $hasNoValue = [System.String]::IsNullOrWhiteSpace($InputObject)\n    if ($ForAbsence) { $hasNoValue }\n    else { -not $hasNoValue }\n}\nfilter Out-Verbose {\n    Write-Verbose ($_ | Out-String)\n}\nfilter Out-Indented {\n    $_ | Out-String | % Trim | % Split \"`n\" | % { \"`t$_\" }  \n}\nif (!(Get-Module ACMESharp -ListAvailable)) {\n    Write-Host 'Installing ACME PowerShell Module...'\n    Install-Module -Name ACMESharp -AllowClobber -Force\n}\nWrite-Host 'Importing ACME PowerShell Module...'\nImport-Module ACMESharp\n\n$BaseService = Get-OctopusSetting BaseService 'LetsEncrypt'\nWrite-Host \"Initializing ACME Vault for $BaseService...\"\nInitialize-ACMEVault -BaseService $BaseService -Force\n\nWrite-Host 'Creating new registration...'\nNew-ACMERegistration -Contacts ('mailto:{0}' -f $Param_MailTo) -AcceptTos | Out-Indented\n\nWrite-Host \"Requesting Domain Identifier for $Param_Domain...\"\nNew-ACMEIdentifier -Dns $Param_Domain -Alias $Param_Domain | Out-Indented\n\nWrite-Host 'Initiating Domain Ownership Challenge...'\n$challengeType = ($Param_ChallengeType -split ',')[0]\n$handler = ($Param_ChallengeType -split ',')[1]\n$handlerParameters = @{}\nif (Test-String $Param_WebSiteRef) {\n    $handlerParameters.Add('WebSiteRef', $Param_WebSiteRef)\n}\n$instructionsPath = [System.IO.Path]::GetTempFileName()\nif ($handler -ieq 'manual') {\n    $handlerParameters.Add('WriteOutPath', $instructionsPath)\n    Remove-Item -Path $instructionsPath -Force\n}\n$identifier = Complete-ACMEChallenge -IdentifierRef $Param_Domain -ChallengeType $challengeType -Handler $handler -HandlerParameters $handlerParameters -Repeat\n\nif ($handler -ieq 'manual') {\n    Get-Content -Path $instructionsPath -Raw | Tee-Object -Variable challenge | Out-Indented\n    Remove-Item -Path $instructionsPath -Force\n    \n    Set-OctopusVariable ACMEChallenge $challenge\n    $waitTime = Get-OctopusSetting ManualWait 300\n    Write-Host \"Domain Verification instructions added to Octopus variable 'Octopus.Action[$($OctopusParameters['Octopus.Action.Name'])].Output.ACMEChallenge\"\n    Write-Host \"Waiting $waitTime seconds before submitting challenge completion...\"\n    Start-Sleep -Seconds $waitTime\n}\n\n$identifier = Submit-ACMEChallenge -IdentifierRef $Param_Domain -ChallengeType $challengeType\nwhile ($identifier.Status -eq 'pending') {\n    Write-Host \"Domain Verification is $($identifier.Status), waiting...\"\n    Start-Sleep -Seconds 20\n    $identifier = Update-ACMEIdentifier -IdentifierRef $Param_Domain    \n}\n\nWrite-Host \"Domain Verification is $($identifier.Status)\"\n$identifier.Challenges | ? Status -ne pending | % ChallengePart | Out-Indented\nif ($identifier.Status -ne 'valid') {\n    $errorJson = $identifier.Challenges | ? Status -eq invalid | % ChallengePart | % Error | ConvertTo-Json\n    Get-ACMEVaultProfile | % VaultParameters | % RootPath | Get-ChildItem -File -Filter '00-VAULT' | Get-Content | Out-Verbose\n    throw \"Domain Verification is $($identifier.Status)`n$errorJson\"\n}\n\nWrite-Host 'Generating CSR...'\nNew-ACMECertificate -Alias $Param_Domain -IdentifierRef $Param_Domain -Generate | Out-Verbose\n\nWrite-Host 'Submitting CSR...'\nSubmit-ACMECertificate -CertificateRef $Param_Domain | Out-Indented\n\nwhile (Test-String $certificate.IssuerSerialNumber -ForAbsence) {\n    Write-Host 'Waiting for certificate to be issued...'\n    Start-Sleep -Seconds 20\n    $certificate = Update-ACMECertificate -CertificateRef $Param_Domain\n}\n\nWrite-Host 'Certificate has been issued...'\n$certificate | Out-Indented\n\nWrite-Host \"Exporting PFX (PKCS#12) certificate file to $Param_PfxFilePath...\"\nGet-ACMECertificate -CertificateRef $Param_Domain -ExportPkcs12 $Param_PfxFilePath -Overwrite | Out-Verbose\n\nif ($Param_ImportCert -ieq 'True') {\n    Write-Host 'Importing certificate to local machine store...'\n    Import-PfxCertificate -CertStoreLocation Cert:\\LocalMachine\\My -Exportable -FilePath $Param_PfxFilePath\n    \n    Get-ChildItem -Path Cert:\\LocalMachine\\My | ? Thumbprint -eq $certificate.Thumbprint | % {\n        Write-Host \"Setting certificate Friendly Name...\"\n        $_.FriendlyName = $Param_Domain\n    }\n}\n\n",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Parameters": [
    {
      "Id": "55492aee-ce09-4738-8f25-a8d824a70f4a",
      "Name": "Param_Domain",
      "Label": "Domain",
      "HelpText": "Domain the certificate should be issued to e.g. **octopus.com**",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "eaaf9e98-e0fa-4c31-a0ae-7a1ec42a3198",
      "Name": "Param_MailTo",<commit_msg>Force ACMESharp to version 0.8.1<commit_after>{
  "Id": "bc81b8a6-dc56-4769-87b5-650af7a38162",
  "Name": "Lets Encrypt - Create SSL Certificate",
  "Description": "Procures an X.509 SSL Certificate from the [Let’s Encrypt](https://letsencrypt.org) Certificate Authority using the [Automatic Certificate Management Environment (ACME)](https://ietf-wg-acme.github.io/acme/) protocol.",
  "ActionType": "Octopus.Script",
  "Version": 2,
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Script.ScriptBody": "<#\n ----- Lets Encrypt - Create SSL Certificate ----- \n    <NAME> @paulmarsy (<EMAIL>)\nLinks\n    https://github.com/OctopusDeploy/Library/commits/master/step-templates/letsencrypt-create-ssl-certificate.json\n#>\n\n$ErrorActionPreference = 'Stop'\n\nfunction Get-OctopusSetting {\n    param([Parameter(Position = 0, Mandatory)][string]$Name, [Parameter(Position = 1)]$DefaultValue)\n    $formattedName = 'Octopus.Action.{0}' -f $Name\n    if ($OctopusParameters.ContainsKey($formattedName)) {\n        $value = $OctopusParameters[$formattedName]\n        if ($DefaultValue -is [int]) { return ([int]::Parse($value)) }\n        if ($DefaultValue -is [bool]) { return ([System.Convert]::ToBoolean($value)) }\n        if ($DefaultValue -is [array] -or $DefaultValue -is [hashtable] -or $DefaultValue -is [pscustomobject]) { return (ConvertFrom-Json -InputObject $value) }\n        return $value\n    }\n    else { return $DefaultValue }\n}\nfunction Test-String {\n    param([Parameter(Position=0)]$InputObject,[switch]$ForAbsence)\n\n    $hasNoValue = [System.String]::IsNullOrWhiteSpace($InputObject)\n    if ($ForAbsence) { $hasNoValue }\n    else { -not $hasNoValue }\n}\nfilter Out-Verbose {\n    Write-Verbose ($_ | Out-String)\n}\nfilter Out-Indented {\n    $_ | Out-String | % Trim | % Split \"`n\" | % { \"`t$_\" }  \n}\nif (!(Get-Module ACMESharp -ListAvailable)) {\n    Write-Host 'Installing ACME PowerShell Module...'\n    Install-Module -Name ACMESharp -AllowClobber -RequiredVersion 0.8.1 -Force\n}\nWrite-Host 'Importing ACME PowerShell Module...'\nImport-Module ACMESharp\n\n$BaseService = Get-OctopusSetting BaseService 'LetsEncrypt'\nWrite-Host \"Initializing ACME Vault for $BaseService...\"\nInitialize-ACMEVault -BaseService $BaseService -Force\n\nWrite-Host 'Creating new registration...'\nNew-ACMERegistration -Contacts ('mailto:{0}' -f $Param_MailTo) -AcceptTos | Out-Indented\n\nWrite-Host \"Requesting Domain Identifier for $Param_Domain...\"\nNew-ACMEIdentifier -Dns $Param_Domain -Alias $Param_Domain | Out-Indented\n\nWrite-Host 'Initiating Domain Ownership Challenge...'\n$challengeType = ($Param_ChallengeType -split ',')[0]\n$handler = ($Param_ChallengeType -split ',')[1]\n$handlerParameters = @{}\nif (Test-String $Param_WebSiteRef) {\n    $handlerParameters.Add('WebSiteRef', $Param_WebSiteRef)\n}\n$instructionsPath = [System.IO.Path]::GetTempFileName()\nif ($handler -ieq 'manual') {\n    $handlerParameters.Add('WriteOutPath', $instructionsPath)\n    Remove-Item -Path $instructionsPath -Force\n}\n$identifier = Complete-ACMEChallenge -IdentifierRef $Param_Domain -ChallengeType $challengeType -Handler $handler -HandlerParameters $handlerParameters -Repeat\n\nif ($handler -ieq 'manual') {\n    Get-Content -Path $instructionsPath -Raw | Tee-Object -Variable challenge | Out-Indented\n    Remove-Item -Path $instructionsPath -Force\n    \n    Set-OctopusVariable ACMEChallenge $challenge\n    $waitTime = Get-OctopusSetting ManualWait 300\n    Write-Host \"Domain Verification instructions added to Octopus variable 'Octopus.Action[$($OctopusParameters['Octopus.Action.Name'])].Output.ACMEChallenge\"\n    Write-Host \"Waiting $waitTime seconds before submitting challenge completion...\"\n    Start-Sleep -Seconds $waitTime\n}\n\n$identifier = Submit-ACMEChallenge -IdentifierRef $Param_Domain -ChallengeType $challengeType\nwhile ($identifier.Status -eq 'pending') {\n    Write-Host \"Domain Verification is $($identifier.Status), waiting...\"\n    Start-Sleep -Seconds 20\n    $identifier = Update-ACMEIdentifier -IdentifierRef $Param_Domain    \n}\n\nWrite-Host \"Domain Verification is $($identifier.Status)\"\n$identifier.Challenges | ? Status -ne pending | % ChallengePart | Out-Indented\nif ($identifier.Status -ne 'valid') {\n    $errorJson = $identifier.Challenges | ? Status -eq invalid | % ChallengePart | % Error | ConvertTo-Json\n    Get-ACMEVaultProfile | % VaultParameters | % RootPath | Get-ChildItem -File -Filter '00-VAULT' | Get-Content | Out-Verbose\n    throw \"Domain Verification is $($identifier.Status)`n$errorJson\"\n}\n\nWrite-Host 'Generating CSR...'\nNew-ACMECertificate -Alias $Param_Domain -IdentifierRef $Param_Domain -Generate | Out-Verbose\n\nWrite-Host 'Submitting CSR...'\nSubmit-ACMECertificate -CertificateRef $Param_Domain | Out-Indented\n\nwhile (Test-String $certificate.IssuerSerialNumber -ForAbsence) {\n    Write-Host 'Waiting for certificate to be issued...'\n    Start-Sleep -Seconds 20\n    $certificate = Update-ACMECertificate -CertificateRef $Param_Domain\n}\n\nWrite-Host 'Certificate has been issued...'\n$certificate | Out-Indented\n\nWrite-Host \"Exporting PFX (PKCS#12) certificate file to $Param_PfxFilePath...\"\nGet-ACMECertificate -CertificateRef $Param_Domain -ExportPkcs12 $Param_PfxFilePath -Overwrite | Out-Verbose\n\nif ($Param_ImportCert -ieq 'True') {\n    Write-Host 'Importing certificate to local machine store...'\n    Import-PfxCertificate -CertStoreLocation Cert:\\LocalMachine\\My -Exportable -FilePath $Param_PfxFilePath\n    \n    Get-ChildItem -Path Cert:\\LocalMachine\\My | ? Thumbprint -eq $certificate.Thumbprint | % {\n        Write-Host \"Setting certificate Friendly Name...\"\n        $_.FriendlyName = $Param_Domain\n    }\n}\n\n",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Parameters": [
    {
      "Id": "55492aee-ce09-4738-8f25-a8d824a70f4a",
      "Name": "Param_Domain",
      "Label": "Domain",
      "HelpText": "Domain the certificate should be issued to e.g. **octopus.com**",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "eaaf9e98-e0fa-4c31-a0ae-7a1ec42a3198",
      "Name": "Param_MailTo",
{'fraction_non_alphanumeric': 0.15585320532672653, 'fraction_numerical': 0.013316816351811707, 'mean_word_length': 4.204270749395649, 'pattern_counts': {'":': 48, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 6, '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': '6956712', 'n_tokens_mistral': 4282, 'n_tokens_neox': 4094, 'n_words': 873}