<commit_before>{
  "Id": "ActionTemplates-11",
  "Name": "IIS Application - Create",
  "Description": "Create an IIS virtual application (a virtual directory with an application pool)",
  "ActionType": "Octopus.Script",
  "Version": 14,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\n## Input\n## --------------------------------------------------------------------------------------\n\n$virtualPath = $OctopusParameters['VirtualPath']\n$physicalPath = $OctopusParameters['PhysicalPath']\n$applicationPoolName = $OctopusParameters['ApplicationPoolName']\n$parentSite = $OctopusParameters['ParentSite']\n$bindingProtocols = $OctopusParameters['BindingProtocols']\n$authentication = $OctopusParameters['AuthenticationType']\n$requireSSL = $OctopusParameters['RequireSSL']\n\n$anonymousAuthentication = \"Anonymous\"\n$windowsAuthentication = \"Windows\"\n$basicAuthentication = \"Basic\"\n\n## --------------------------------------------------------------------------------------\n## Helpers\n## --------------------------------------------------------------------------------------\n# Helper for validating input parameters\nfunction Validate-Parameter($foo, [string[]]$validInput, $parameterName) {\n    Write-Host \"${parameterName}: ${foo}\"\n    if (! $foo) {\n        throw \"$parameterName cannot be empty, please specify a value\"\n    }\n    \n    if ($validInput) {\n        @($foo) | % { \n                if ($validInput -notcontains $_) {\n                    throw \"'$_' is not a valid input for '$parameterName'\"\n                }\n             }  \n        }   \n}\n\n# Helper to run a block with a retry if things go wrong\n$maxFailures = 5\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\nfunction Execute-WithRetry([ScriptBlock] $command) {\n\t$attemptCount = 0\n\t$operationIncomplete = $true\n\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\n\t\t$attemptCount = ($attemptCount + 1)\n\n\t\tif ($attemptCount -ge 2) {\n\t\t\tWrite-Output \"Waiting for $sleepBetweenFailures seconds before retrying...\"\n\t\t\tStart-Sleep -s $sleepBetweenFailures\n\t\t\tWrite-Output \"Retrying...\"\n\t\t}\n\n\t\ttry {\n\t\t\t& $command\n\n\t\t\t$operationIncomplete = $false\n\t\t} catch [System.Exception] {\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\n\t\t\t\tWrite-Output (\"Attempt $attemptCount of $maxFailures failed: \" + $_.Exception.Message)\n\t\t\t\n\t\t\t}\n\t\t\telse {\n\t\t\t    throw \"Failed to execute command\"\n\t\t\t}\n\t\t}\n\t}\n}\n\n## --------------------------------------------------------------------------------------\n## Configuration\n## --------------------------------------------------------------------------------------\nValidate-Parameter $virtualPath -parameterName \"Virtual path\"\nValidate-Parameter $physicalPath -parameterName \"Physical path\"\nValidate-Parameter $applicationPoolName -parameterName \"Application pool\"\nValidate-Parameter $parentSite -parameterName \"Parent site\"\n\n\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\nImport-Module WebAdministration -ErrorAction SilentlyContinue\n\n\n## --------------------------------------------------------------------------------------\n## Run\n## --------------------------------------------------------------------------------------\n\nWrite-Host \"Getting web site $parentSite\"\n# Workaround to bug in Get-WebSite cmdlet which would return all sites\n# See http://forums.iis.net/p/1167298/1943273.aspx / http://stackoverflow.com/a/6832577/785750\n$site = Get-WebSite  | where { $_.Name -eq $parentSite }\nif (!$site) {\n    throw \"The web site '$parentSite' does not exist. Please create the site first.\"\n}\n\n$path = $site.PhysicalPath;\n$parts = $virtualPath -split \"[/\\\\]\"\n$name = \"\"\n\nfor ($i = 0; $i -lt $parts.Length; $i++) {\n    $name = $name + \"/\" + $parts[$i]\n    $name = $name.TrimStart('/').TrimEnd('/')\n    if ($i -eq $parts.Length - 1) {\n        \n    }\n    elseif ([string]::IsNullOrEmpty($name) -eq $false -and $name -ne \"/\") {\n        Write-Host \"Ensuring parent exists: $name\"\n        \n        $path = [IO.Path]::Combine($path, $parts[$i])\n        $app = Get-WebApplication -Name $name -Site $parentSite\n\n        if (!$app) {\n            $vdir = Get-WebVirtualDirectory -Name $name -site $parentSite\n            if (!$vdir) {\n                Write-Verbose \"The application or virtual directory '$name' does not exist\"\n                if([IO.Directory]::Exists($path) -eq $true)\n                {\n                    Write-Verbose \"Using physical path '$path' as parent\"\n                }\n                else\n                {\n                    throw \"Failed to ensure parent\"\n                }\n            }\n            else\n            {\n                $path = $vdir.PhysicalPath\n            }\n        }\n        else\n        {\n            $path = $app.PhysicalPath\n        }\n    }\n}\n\n$existing = Get-WebApplication -site $parentSite -Name $name\n\n\nExecute-WithRetry { \n    if (!$existing) {\n        Write-Host \"Creating web application '$name'\"\n        New-WebApplication -Site $parentSite -Name $name -ApplicationPool $applicationPoolName -PhysicalPath $physicalPath\n        Write-Host \"Web application created\"\n    } else {\n        Write-Host \"The web application '$name' already exists. Updating physical path:\"\n\n        Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name physicalPath -value $physicalPath\n        Write-Host \"Physical path changed to: $physicalPath\"\n\n        Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -Name ApplicationPool -Value $applicationPoolName\n        Write-Output \"ApplicationPool changed to: $applicationPoolName\"\n    }\n    \n    Write-Host \"Enabling '$bindingProtocols' protocols\"\n    Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name enabledProtocols -value $bindingProtocols\n\n\t\t$enabledIisAuthenticationOptions = $Authentication -split 's*[,;]s*'\n\n\tValidate-Parameter $enabledIisAuthenticationOptions -validInput @($anonymousAuthentication, $basicAuthentication, $windowsAuthentication) -parameterName \"IIS Authentication\"\n\n\t$enableAnonymous = $enabledIisAuthenticationOptions -contains $anonymousAuthentication\n\t$enableWindows = $enabledIisAuthenticationOptions -contains $windowsAuthentication\n\t$enableBasic = $enabledIisAuthenticationOptions -contains $basicAuthentication\n\n\ttry {\n\n\tExecute-WithRetry { \n\t\tWrite-Output \"Anonymous authentication enabled: $enableAnonymous\"\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value \"$enableAnonymous\" -PSPath IIS:\\ -location $parentSite$virtualPath\n\t}\t\n\t\n\tExecute-WithRetry { \n\t\tWrite-Output \"Windows authentication enabled: $enableWindows\"\n\t\tSet-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value \"$enableWindows\" -PSPath IIS:\\ -location $parentSite$virtualPath\n\t}\n\n\tExecute-WithRetry { \n\t\tWrite-Output \"Basic authentication enabled: $enableBasic\"\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/basicAuthentication -name enabled -value \"$enableBasic\" -PSPath IIS:\\ -location $parentSite$virtualPath\n\t}\n\n\t} catch [System.Exception] {\n\t\tWrite-Output \"Authentication options could not be set. This can happen when there is a problem with your application's web.config. For example, you might be using a section that requires an extension that is not installed on this web server (such as URL Rewrtiting). It can also happen when you have selected an authentication option and the appropriate IIS module is not installed (for example, for Windows authentication, you need to enable the Windows Authentication module in IIS/Windows first)\"\n\t\tthrow\n\t}\n\n\tif ($requireSSL)\n    {\n\t\tWrite-Output \"Require SSL enabled: $requireSSL\"\n        Set-WebConfiguration -value \"Ssl\" -filter \"system.webserver/security/access\" -location $parentSite/$virtualPath -PSPath IIS:\\ \n    }\n}\n",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "SensitiveProperties": {},
  "Parameters": [
    {
      "Name": "VirtualPath",
      "Label": "Virtual path",
      "HelpText": "The name of the application to create. For example, to serve an application that will be available at `/myapp`, enter `myapp`. To create an application under a parent virtual directory or application, separate with slashes - for example: `/applications/myapp`",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "PhysicalPath",
      "Label": "Physical path",
      "HelpText": "Physical folder that the application will serve files from. Example: `C:\\MyApp`.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ApplicationPoolName",
      "Label": "Application pool",
      "HelpText": "The name of the application pool that the application will run under. The application pool must already exist.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ParentSite",
      "Label": "Parent site",
      "HelpText": "The name of the IIS web site to attach the application to. For example, to put the application under the default web site, enter:\n\n    Default Web Site",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "BindingProtocols",
      "Label": "Protocols",
      "HelpText": "The protocols to use for the application",
      "DefaultValue": "http",
      "DisplaySettings": { }
    },
    {
      "Name": "AuthenticationType",
      "Label": "Authentication",
      "HelpText": "The authentication mode to use for the new website (can be Anonymous, Basic or Windows), specify multiple modes by entering the modes required separated by a ',' or ';'",
      "DefaultValue": "Windows",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
       }
    },
    {
      "Name": "RequireSSL",
      "Label": "Require SSL",
      "HelpText": "Web site SSL settings",
      "DefaultValue": "False",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    }
  ],
  "LastModifiedOn": "2015-10-29T10:39:20.105+00:00",
  "LastModifiedBy": "johannesvaltonen"
  "$Meta": {
    "ExportedAt": "2015-10-29T13:16:52.139Z",
    "OctopusVersion": "3.0.24.0",
    "Type": "ActionTemplate"
  }
}<commit_msg>Added missing comma.<commit_after>{
  "Id": "ActionTemplates-11",
  "Name": "IIS Application - Create",
  "Description": "Create an IIS virtual application (a virtual directory with an application pool)",
  "ActionType": "Octopus.Script",
  "Version": 14,
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\n## Input\n## --------------------------------------------------------------------------------------\n\n$virtualPath = $OctopusParameters['VirtualPath']\n$physicalPath = $OctopusParameters['PhysicalPath']\n$applicationPoolName = $OctopusParameters['ApplicationPoolName']\n$parentSite = $OctopusParameters['ParentSite']\n$bindingProtocols = $OctopusParameters['BindingProtocols']\n$authentication = $OctopusParameters['AuthenticationType']\n$requireSSL = $OctopusParameters['RequireSSL']\n\n$anonymousAuthentication = \"Anonymous\"\n$windowsAuthentication = \"Windows\"\n$basicAuthentication = \"Basic\"\n\n## --------------------------------------------------------------------------------------\n## Helpers\n## --------------------------------------------------------------------------------------\n# Helper for validating input parameters\nfunction Validate-Parameter($foo, [string[]]$validInput, $parameterName) {\n    Write-Host \"${parameterName}: ${foo}\"\n    if (! $foo) {\n        throw \"$parameterName cannot be empty, please specify a value\"\n    }\n    \n    if ($validInput) {\n        @($foo) | % { \n                if ($validInput -notcontains $_) {\n                    throw \"'$_' is not a valid input for '$parameterName'\"\n                }\n             }  \n        }   \n}\n\n# Helper to run a block with a retry if things go wrong\n$maxFailures = 5\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\nfunction Execute-WithRetry([ScriptBlock] $command) {\n\t$attemptCount = 0\n\t$operationIncomplete = $true\n\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\n\t\t$attemptCount = ($attemptCount + 1)\n\n\t\tif ($attemptCount -ge 2) {\n\t\t\tWrite-Output \"Waiting for $sleepBetweenFailures seconds before retrying...\"\n\t\t\tStart-Sleep -s $sleepBetweenFailures\n\t\t\tWrite-Output \"Retrying...\"\n\t\t}\n\n\t\ttry {\n\t\t\t& $command\n\n\t\t\t$operationIncomplete = $false\n\t\t} catch [System.Exception] {\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\n\t\t\t\tWrite-Output (\"Attempt $attemptCount of $maxFailures failed: \" + $_.Exception.Message)\n\t\t\t\n\t\t\t}\n\t\t\telse {\n\t\t\t    throw \"Failed to execute command\"\n\t\t\t}\n\t\t}\n\t}\n}\n\n## --------------------------------------------------------------------------------------\n## Configuration\n## --------------------------------------------------------------------------------------\nValidate-Parameter $virtualPath -parameterName \"Virtual path\"\nValidate-Parameter $physicalPath -parameterName \"Physical path\"\nValidate-Parameter $applicationPoolName -parameterName \"Application pool\"\nValidate-Parameter $parentSite -parameterName \"Parent site\"\n\n\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\nImport-Module WebAdministration -ErrorAction SilentlyContinue\n\n\n## --------------------------------------------------------------------------------------\n## Run\n## --------------------------------------------------------------------------------------\n\nWrite-Host \"Getting web site $parentSite\"\n# Workaround to bug in Get-WebSite cmdlet which would return all sites\n# See http://forums.iis.net/p/1167298/1943273.aspx / http://stackoverflow.com/a/6832577/785750\n$site = Get-WebSite  | where { $_.Name -eq $parentSite }\nif (!$site) {\n    throw \"The web site '$parentSite' does not exist. Please create the site first.\"\n}\n\n$path = $site.PhysicalPath;\n$parts = $virtualPath -split \"[/\\\\]\"\n$name = \"\"\n\nfor ($i = 0; $i -lt $parts.Length; $i++) {\n    $name = $name + \"/\" + $parts[$i]\n    $name = $name.TrimStart('/').TrimEnd('/')\n    if ($i -eq $parts.Length - 1) {\n        \n    }\n    elseif ([string]::IsNullOrEmpty($name) -eq $false -and $name -ne \"/\") {\n        Write-Host \"Ensuring parent exists: $name\"\n        \n        $path = [IO.Path]::Combine($path, $parts[$i])\n        $app = Get-WebApplication -Name $name -Site $parentSite\n\n        if (!$app) {\n            $vdir = Get-WebVirtualDirectory -Name $name -site $parentSite\n            if (!$vdir) {\n                Write-Verbose \"The application or virtual directory '$name' does not exist\"\n                if([IO.Directory]::Exists($path) -eq $true)\n                {\n                    Write-Verbose \"Using physical path '$path' as parent\"\n                }\n                else\n                {\n                    throw \"Failed to ensure parent\"\n                }\n            }\n            else\n            {\n                $path = $vdir.PhysicalPath\n            }\n        }\n        else\n        {\n            $path = $app.PhysicalPath\n        }\n    }\n}\n\n$existing = Get-WebApplication -site $parentSite -Name $name\n\n\nExecute-WithRetry { \n    if (!$existing) {\n        Write-Host \"Creating web application '$name'\"\n        New-WebApplication -Site $parentSite -Name $name -ApplicationPool $applicationPoolName -PhysicalPath $physicalPath\n        Write-Host \"Web application created\"\n    } else {\n        Write-Host \"The web application '$name' already exists. Updating physical path:\"\n\n        Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name physicalPath -value $physicalPath\n        Write-Host \"Physical path changed to: $physicalPath\"\n\n        Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -Name ApplicationPool -Value $applicationPoolName\n        Write-Output \"ApplicationPool changed to: $applicationPoolName\"\n    }\n    \n    Write-Host \"Enabling '$bindingProtocols' protocols\"\n    Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name enabledProtocols -value $bindingProtocols\n\n\t\t$enabledIisAuthenticationOptions = $Authentication -split 's*[,;]s*'\n\n\tValidate-Parameter $enabledIisAuthenticationOptions -validInput @($anonymousAuthentication, $basicAuthentication, $windowsAuthentication) -parameterName \"IIS Authentication\"\n\n\t$enableAnonymous = $enabledIisAuthenticationOptions -contains $anonymousAuthentication\n\t$enableWindows = $enabledIisAuthenticationOptions -contains $windowsAuthentication\n\t$enableBasic = $enabledIisAuthenticationOptions -contains $basicAuthentication\n\n\ttry {\n\n\tExecute-WithRetry { \n\t\tWrite-Output \"Anonymous authentication enabled: $enableAnonymous\"\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value \"$enableAnonymous\" -PSPath IIS:\\ -location $parentSite$virtualPath\n\t}\t\n\t\n\tExecute-WithRetry { \n\t\tWrite-Output \"Windows authentication enabled: $enableWindows\"\n\t\tSet-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value \"$enableWindows\" -PSPath IIS:\\ -location $parentSite$virtualPath\n\t}\n\n\tExecute-WithRetry { \n\t\tWrite-Output \"Basic authentication enabled: $enableBasic\"\n\t\tSet-WebConfigurationProperty -filter /system.webServer/security/authentication/basicAuthentication -name enabled -value \"$enableBasic\" -PSPath IIS:\\ -location $parentSite$virtualPath\n\t}\n\n\t} catch [System.Exception] {\n\t\tWrite-Output \"Authentication options could not be set. This can happen when there is a problem with your application's web.config. For example, you might be using a section that requires an extension that is not installed on this web server (such as URL Rewrtiting). It can also happen when you have selected an authentication option and the appropriate IIS module is not installed (for example, for Windows authentication, you need to enable the Windows Authentication module in IIS/Windows first)\"\n\t\tthrow\n\t}\n\n\tif ($requireSSL)\n    {\n\t\tWrite-Output \"Require SSL enabled: $requireSSL\"\n        Set-WebConfiguration -value \"Ssl\" -filter \"system.webserver/security/access\" -location $parentSite/$virtualPath -PSPath IIS:\\ \n    }\n}\n",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "SensitiveProperties": {},
  "Parameters": [
    {
      "Name": "VirtualPath",
      "Label": "Virtual path",
      "HelpText": "The name of the application to create. For example, to serve an application that will be available at `/myapp`, enter `myapp`. To create an application under a parent virtual directory or application, separate with slashes - for example: `/applications/myapp`",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "PhysicalPath",
      "Label": "Physical path",
      "HelpText": "Physical folder that the application will serve files from. Example: `C:\\MyApp`.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ApplicationPoolName",
      "Label": "Application pool",
      "HelpText": "The name of the application pool that the application will run under. The application pool must already exist.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ParentSite",
      "Label": "Parent site",
      "HelpText": "The name of the IIS web site to attach the application to. For example, to put the application under the default web site, enter:\n\n    Default Web Site",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "BindingProtocols",
      "Label": "Protocols",
      "HelpText": "The protocols to use for the application",
      "DefaultValue": "http",
      "DisplaySettings": { }
    },
    {
      "Name": "AuthenticationType",
      "Label": "Authentication",
      "HelpText": "The authentication mode to use for the new website (can be Anonymous, Basic or Windows), specify multiple modes by entering the modes required separated by a ',' or ';'",
      "DefaultValue": "Windows",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
       }
    },
    {
      "Name": "RequireSSL",
      "Label": "Require SSL",
      "HelpText": "Web site SSL settings",
      "DefaultValue": "False",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    }
  ],
  "LastModifiedOn": "2015-10-29T10:39:20.105+00:00",
  "LastModifiedBy": "johannesvaltonen",
  "$Meta": {
    "ExportedAt": "2015-10-29T13:16:52.139Z",
    "OctopusVersion": "3.0.24.0",
    "Type": "ActionTemplate"
  }
}
{'fraction_non_alphanumeric': 0.20709785025945143, 'fraction_numerical': 0.00759822090437361, 'mean_word_length': 2.487075928917609, 'pattern_counts': {'":': 114, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7467842', 'n_tokens_mistral': 6240, 'n_tokens_neox': 5977, 'n_words': 1562}