<commit_before>{
  "Id": "193628c4-2251-41e9-a782-225e632ef871",
  "Name": "Configuration - Encrypt Section",
  "Description": "Encrypts an configuration section for the specified file in a given directory.",
  "ActionType": "Octopus.Script",
  "Version": 3,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = \"Stop\" \r\nfunction Get-Parameter($Name, $Default, [switch]$Required) {\r\n    $result = $null\r\n\r\n    if ($OctopusParameters -ne $null) {\r\n        $result = $OctopusParameters[$Name]\r\n    }\r\n\r\n    if ($result -eq $null) {\r\n        if ($Required) {\r\n            throw \"Missing parameter value $Name\"\r\n        } else {\r\n            $result = $Default\r\n        }\r\n    }\r\n\r\n    return $result\r\n}\r\n\r\nfunction HandleError($message) {\r\n\tif (!$whatIf) {\r\n\t\tthrow $message\r\n\t} else {\r\n\t\tWrite-Host $message -Foreground Yellow\r\n\t}\r\n}\r\n\r\n$websiteDirectory = Get-Parameter \"WebsiteDirectory\" -Required\r\n$sectionsToEncrypt = (Get-Parameter \"SectionsToEncrypt\" -Required) -split ',' | where {$_} | %{$_.Trim()}\r\n$provider = Get-Parameter \"Provider\" \"\"\r\n$configFile = Get-Parameter \"ConfigFile\" \"web.config\"\r\n$otherFiles = (Get-Parameter \"OtherFiles\" \"\") -split ',' | where {$_} | %{$_.Trim()}\r\n\r\nWrite-Host \"Configuration - Encrypt .config\"\r\nWrite-Host \"WebsiteDirectory: $websiteDirectory\"\r\nWrite-Host \"SectionsToEncrypt: $sectionsToEncrypt\"\r\nWrite-Host \"Provider: $provider\"\r\nWrite-Host \"ConfigFile: $configFile\"\r\n\r\n\r\nif (!(Test-Path $websiteDirectory)) {\r\n\tHandleError \"The directory $websiteDirectory must exist\"\r\n}\r\n\r\n$configFilePath = Join-Path $websiteDirectory $configFile\r\nWrite-Host \"configFilePath: $configFilePath\"\r\nif (!(Test-Path $configFilePath)) {\r\n\tHandleError \"Specified file $configFile or a Web.Config file must exist in the directory $websiteDirectory\"\r\n}\r\n\r\n$frameworkPath = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory();\r\n$regiis = \"$frameworkPath\\aspnet_regiis.exe\"\r\n\r\nif (!(Test-Path $regiis)) {\r\n\tHandleError \"The tool aspnet_regiis does not exist in the directory $frameworkPath\"\r\n}\r\n\r\n# Create a temp directory to work out of and copy our config file to web.config\r\n$tempPath = Join-Path $websiteDirectory $([guid]::NewGuid()).ToString()\r\nif (!$whatIf) {\r\n\tNew-Item $tempPath -ItemType \"directory\"\r\n} else {\r\n\tWrite-Host \"WhatIf: New-Item $tempPath -ItemType \"\"directory\"\"\" -Foreground Yellow\r\n}\r\n\r\n$tempFile = Join-Path $tempPath \"web.config\"\r\nif (!$whatIf) {\r\n\tCopy-Item $configFilePath $tempFile\r\n} else {\r\n\tWrite-Host \"WhatIf: Copy-Item $configFilePath $tempFile\" -Foreground Yellow\r\n}\r\n\r\nForeach($fileName in $otherFiles){\r\n  if (!$whatIf) {\r\n\t Copy-Item (Join-Path $websiteDirectory $fileName) (Join-Path $tempPath $fileName)\r\n  } else {\r\n\t Write-Host \"WhatIf: Copy-Item $configFilePath $tempFile\" -Foreground Yellow\r\n  }\r\n}\r\n\r\nForeach($sectionToEncrypt in $sectionsToEncrypt){\r\n\t# Determine arguments\r\n\tif ($provider) {\r\n\t\t$args = \"-pef\", $sectionToEncrypt, $tempPath, \"-prov\", $provider\r\n\t} else {\r\n\t\t$args = \"-pef\", $sectionToEncrypt, $tempPath\r\n\t}\r\n\r\n\t# Encrypt Web.Config file in directory\r\n\tif (!$whatIf) {\r\n\t\t& $regiis $args\r\n\t} else {\r\n\t\tWrite-Host \"WhatIf: $regiis $args\" -Foreground Yellow\r\n\t}\r\n}\r\n\r\n# Copy the web.config back to original file and delete the temp dir\r\nif (!$whatIf) {\r\n\tCopy-Item $tempFile $configFilePath -Force\r\n\r\n  Foreach($fileName in $otherFiles){\r\n    if (!$whatIf) {\r\n  \t Copy-Item (Join-Path $tempPath $fileName) (Join-Path $websiteDirectory $fileName) -Force\r\n    } else {\r\n  \t Write-Host \"WhatIf: Copy-Item $configFilePath $tempFile\" -Foreground Yellow\r\n    }\r\n  }\r\n\r\n\tRemove-Item $tempPath -Recurse\r\n} else {\r\n\tWrite-Host \"WhatIf: Copy-Item $tempFile $configFilePath -Force\" -Foreground Yellow\r\n\tWrite-Host \"WhatIf: Remove-Item $tempPath -Recurse\" -Foreground Yellow\r\n}\r\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false"
  },
  "Parameters": [
    {
      "Name": "WebsiteDirectory",
      "Label": "Website directory",
      "HelpText": "The path to the website physical directory that contains a `Web.Config` file. \n\nYou can get the InstallationDirectoryPath like so `#{Octopus.Action[StepName].Output.Package.InstallationDirectoryPath}`",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "SectionsToEncrypt",
      "Label": "Section to encrypt",
      "HelpText": "The name of the section in the web config to encrypt e.g. `appSettings`, `connectionStrings` etc.\nFor multiple sections, separate with a comma (,)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "Provider",
      "Label": "Provider Name",
      "HelpText": "The provider to use for encryption",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ConfigFile",
      "Label": "Configuration File",
      "HelpText": "The configuration file to encrypt.",
      "DefaultValue": "web.config",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "OtherFiles",
      "Label": "Other Files",
      "HelpText": "A list of other files in the `#{WebsiteDirectory}` folder that should be included when encrypting the specified `#{SectionToEncrypt}`. For example, `connectionStrings.config`. Values should be separated by a comma.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    }
  ],
  "LastModifiedBy": "droyad",
  "$Meta": {
    "ExportedAt": "2016-04-04T02:24:12.170+00:00",
    "OctopusVersion": "3.3.1",
    "Type": "ActionTemplate"
  },
  "Category": "encrypt"
}<commit_msg>other files and web.config can be contained in different paths<commit_after>{
  "Id": "9cd6e414-0079-47a9-914e-eaae82f863b8",
  "Name": "Configuration - Encrypt Section",
  "Description": "Encrypts several configuration sections for the specified file in a given directory.",
  "ActionType": "Octopus.Script",
  "Version": 4,
  "CommunityActionTemplateId": null,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = \"Stop\" \nfunction Get-Parameter($Name, $Default, [switch]$Required) {\n    $result = $null\n\n    if ($OctopusParameters -ne $null) {\n        $result = $OctopusParameters[$Name]\n    }\n\n    if ($result -eq $null) {\n        if ($Required) {\n            throw \"Missing parameter value $Name\"\n        } else {\n            $result = $Default\n        }\n    }\n\n    return $result\n}\n\nfunction HandleError($message) {\n\tif (!$whatIf) {\n\t\tthrow $message\n\t} else {\n\t\tWrite-Host $message -Foreground Yellow\n\t}\n}\n\n$websiteDirectory = Get-Parameter \"WebsiteDirectory\" -Required\n$sectionsToEncrypt = (Get-Parameter \"SectionsToEncrypt\" -Required) -split ',' | where {$_} | %{$_.Trim()}\n$provider = Get-Parameter \"Provider\" \"\"\n$configFile = Get-Parameter \"ConfigFile\" \"web.config\"\n$otherFiles = (Get-Parameter \"OtherFiles\" \"\") -split ',' | where {$_} | %{$_.Trim()}\n\nWrite-Host \"Configuration - Encrypt .config\"\nWrite-Host \"WebsiteDirectory: $websiteDirectory\"\nWrite-Host \"SectionsToEncrypt: $sectionsToEncrypt\"\nWrite-Host \"Provider: $provider\"\nWrite-Host \"ConfigFile: $configFile\"\n\n\nif (!(Test-Path $websiteDirectory)) {\n\tHandleError \"The directory $websiteDirectory must exist\"\n}\n\n$configFilePath = Join-Path $websiteDirectory $configFile\nWrite-Host \"configFilePath: $configFilePath\"\nif (!(Test-Path $configFilePath)) {\n\tHandleError \"Specified file $configFile or a Web.Config file must exist in the directory $websiteDirectory\"\n}\n\n$frameworkPath = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory();\n$regiis = \"$frameworkPath\\aspnet_regiis.exe\"\n\nif (!(Test-Path $regiis)) {\n\tHandleError \"The tool aspnet_regiis does not exist in the directory $frameworkPath\"\n}\n\n# Create a temp directory to work out of and copy our config file to web.config\n$tempPath = Join-Path $websiteDirectory $([guid]::NewGuid()).ToString()\nif (!$whatIf) {\n\tNew-Item $tempPath -ItemType \"directory\"\n} else {\n\tWrite-Host \"WhatIf: New-Item $tempPath -ItemType \"\"directory\"\"\" -Foreground Yellow\n}\n\n$tempFile = Join-Path $tempPath \"web.config\"\nif (!$whatIf) {\n    New-Item -ItemType File -Path $tempFile -Force\n\tCopy-Item $configFilePath $tempFile -Force\n} else {\n\tWrite-Host \"WhatIf: Copy-Item $configFilePath $tempFile\" -Foreground Yellow\n}\n\nForeach($fileName in $otherFiles){\n  if (!$whatIf) {\n     New-Item -ItemType File -Path (Join-Path $tempPath $fileName) -Force\n\t Copy-Item (Join-Path $websiteDirectory $fileName) (Join-Path $tempPath $fileName) -Force\n  } else {\n\t Write-Host \"WhatIf: Copy-Item $configFilePath $tempFile\" -Foreground Yellow\n  }\n}\n\nForeach($sectionToEncrypt in $sectionsToEncrypt){\n\t# Determine arguments\n\tif ($provider) {\n\t\t$args = \"-pef\", $sectionToEncrypt, $tempPath, \"-prov\", $provider\n\t} else {\n\t\t$args = \"-pef\", $sectionToEncrypt, $tempPath\n\t}\n\n\t# Encrypt Web.Config file in directory\n\tif (!$whatIf) {\n\t\t& $regiis $args\n\t\tif ($LASTEXITCODE) {\n\t\t    HandleError \"There was an error trying to encrypt section: $sectionToEncrypt\"\n\t\t}\n\t} else {\n\t\tWrite-Host \"WhatIf: $regiis $args\" -Foreground Yellow\n\t}\n}\n\n# Copy the web.config back to original file and delete the temp dir\nif (!$whatIf) {\n\tCopy-Item $tempFile $configFilePath -Force\n\n  Foreach($fileName in $otherFiles){\n    if (!$whatIf) {\n  \t Copy-Item (Join-Path $tempPath $fileName) (Join-Path $websiteDirectory $fileName) -Force\n    } else {\n  \t Write-Host \"WhatIf: Copy-Item $configFilePath $tempFile\" -Foreground Yellow\n    }\n  }\n\n  Remove-Item $tempPath -Recurse\n} else {\n\tWrite-Host \"WhatIf: Copy-Item $tempFile $configFilePath -Force\" -Foreground Yellow\n\tWrite-Host \"WhatIf: Remove-Item $tempPath -Recurse\" -Foreground Yellow\n}\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.RunOnServer": "false",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Parameters": [
    {
      "Id": "0cae0018-f915-47c5-a8d6-cdef437346df",
      "Name": "WebsiteDirectory",
      "Label": "Website directory",
      "HelpText": "The path to the website physical directory that contains a `Web.Config` file. \n\nYou can get the InstallationDirectoryPath like so `#{Octopus.Action[StepName].Output.Package.InstallationDirectoryPath}`",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "3d7e5485-106e-415e-83b7-cf12c59e776b",
      "Name": "SectionsToEncrypt",
      "Label": "Section to encrypt",
      "HelpText": "The name of the section in the web config to encrypt e.g. `appSettings`, `connectionStrings` etc.\nFor multiple sections, separate with a comma (,)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "12a46b72-3835-4086-b8d6-bd5ad3f99f10",
      "Name": "Provider",
      "Label": "Provider Name",
      "HelpText": "The provider to use for encryption",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "998aa949-74b6-4da6-a838-5637e7a5a322",
      "Name": "ConfigFile",
      "Label": "Configuration File",
      "HelpText": "The configuration file to encrypt.",
      "DefaultValue": "web.config",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "67415967-4722-449c-8d81-28eff7bf9876",
      "Name": "OtherFiles",
      "Label": "Other Files",
      "HelpText": "A list of other files in the `#{WebsiteDirectory}` folder that should be included when encrypting the specified `#{SectionToEncrypt}`. For example, `connectionStrings.config`. Values should be separated by a comma.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      },
      "Links": {}
    }
  ],
  "LastModifiedBy": "cjuroz",
  "$Meta": {
    "ExportedAt": "2016-12-27T03:36:42.383Z",
    "OctopusVersion": "3.7.6",
    "Type": "ActionTemplate"
  },
  "Category": "encrypt"
}
{'fraction_non_alphanumeric': 0.17953846153846154, 'fraction_numerical': 0.015692307692307693, 'mean_word_length': 3.5553608969866852, 'pattern_counts': {'":': 108, '<': 3, '<?xml version=': 0, '>': 3, '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': '4822068', 'n_tokens_mistral': 4547, 'n_tokens_neox': 4388, 'n_words': 991}