Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (106 sloc) 7.71 KB
{
"Id": "f5cebc0a-cc16-4876-9f72-bfbd513e6fdd",
"Name": "HTTP - Test URL",
"Description": "Makes a GET request to a HTTP(S) end point and verifies that a particular status code and response (optional) is returned within a specified period of time",
"ActionType": "Octopus.Script",
"Version": 15,
"Properties": {
"Octopus.Action.Script.ScriptBody": "$uri = $OctopusParameters['Uri']\n$customHostHeader = $OctopusParameters['CustomHostHeader']\n$expectedCode = [int] $OctopusParameters['ExpectedCode']\n$timeoutSeconds = [int] $OctopusParameters['TimeoutSeconds']\n$Username = $OctopusParameters['AuthUsername']\n$Password = $OctopusParameters['AuthPassword']\n$UseWindowsAuth = [System.Convert]::ToBoolean($OctopusParameters['UseWindowsAuth'])\n$ExpectedResponse = $OctopusParameters['ExpectedResponse']\n$securityProtocol = $OctopusParameters['SecurityProtocol']\n\nWrite-Host \"Starting verification request to $uri\"\nif ($customHostHeader)\n{\n Write-Host \"Using custom host header $customHostHeader\"\n}\n\nWrite-Host \"Expecting response code $expectedCode.\"\nWrite-Host \"Expecting response: $ExpectedResponse.\"\n\nif ($securityProtocol)\n{\n Write-Host \"Using security protocol $securityProtocol\"\n [Net.ServicePointManager]::SecurityProtocol = [Enum]::parse([Net.SecurityProtocolType], $securityProtocol) \n}\n\n$timer = [System.Diagnostics.Stopwatch]::StartNew()\n$success = $false\ndo\n{\n try\n {\n if ($Username -and $Password -and $UseWindowsAuth)\n {\n Write-Host \"Making request to $uri using windows authentication for user $Username\"\n $request = [system.Net.WebRequest]::Create($uri)\n $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $(ConvertTo-SecureString -String $Password -AsPlainText -Force)\n $request.Credentials = $Credential \n \n if ($customHostHeader)\n {\n $request.Host = $customHostHeader\n }\n\n try\n {\n $response = $request.GetResponse()\n }\n catch [System.Net.WebException]\n {\n Write-Host \"Request failed :-( System.Net.WebException\"\n Write-Host $_.Exception\n $response = $_.Exception.Response\n }\n \n }\n\t\telseif ($Username -and $Password)\n {\n Write-Host \"Making request to $uri using basic authentication for user $Username\"\n $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $(ConvertTo-SecureString -String $Password -AsPlainText -Force)\n if ($customHostHeader)\n {\n $response = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -Credential $Credential -Headers @{\"Host\" = $customHostHeader} -TimeoutSec $timeoutSeconds\n }\n else \n {\n $response = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -Credential $Credential -TimeoutSec $timeoutSeconds\n }\n }\n\t\telse\n {\n Write-Host \"Making request to $uri using anonymous authentication\"\n if ($customHostHeader)\n {\n $response = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -Headers @{\"Host\" = $customHostHeader} -TimeoutSec $timeoutSeconds\n }\n else \n {\n $response = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -TimeoutSec $timeoutSeconds\n }\n }\n \n $code = $response.StatusCode\n $body = $response.Content;\n Write-Host \"Recieved response code: $code\"\n Write-Host \"Recieved response: $body\"\n\n if($response.StatusCode -eq $expectedCode)\n {\n $success = $true\n }\n if ($success -and $ExpectedResponse)\n {\n $success = ($ExpectedResponse -eq $body)\n }\n }\n catch\n {\n # Anything other than a 200 will throw an exception so\n # we check the exception message which may contain the \n # actual status code to verify\n \n Write-Host \"Request failed :-(\"\n Write-Host $_.Exception\n\n if($_.Exception -like \"*($expectedCode)*\")\n {\n $success = $true\n }\n }\n\n if(!$success)\n {\n Write-Host \"Trying again in 5 seconds...\"\n Start-Sleep -s 5\n }\n}\nwhile(!$success -and $timer.Elapsed -le (New-TimeSpan -Seconds $timeoutSeconds))\n\n$timer.Stop()\n\n# Verify result\n\nif(!$success)\n{\n throw \"Verification failed - giving up.\"\n}\n\nWrite-Host \"Sucesss! Found status code $expectedCode\"",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline"
},
"Parameters": [
{
"Id": "ca7c3e92-c243-4115-a326-7693eb830214",
"Name": "Uri",
"Label": "URI",
"HelpText": "The full Uri of the endpoint",
"DefaultValue": null,
"DisplaySettings": {}
},
{
"Id": "0d760ed5-81ed-46d9-b833-74f75df08bfc",
"Name": "CustomHostHeader",
"Label": "Custom HOST header",
"HelpText": "An optional custom HOST header which will be passed with the request",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "b4e57984-01df-4438-96e5-75e74c2c6188",
"Name": "SecurityProtocol",
"Label": "Security Protocol",
"HelpText": "The optional security protocol version to use for HTTPS requests.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Select",
"Octopus.SelectOptions": "SystemDefault\nSsl3\nTls\nTls11\nTls12"
}
},
{
"Id": "8f47469e-3b6d-4915-a710-3a601debeb8a",
"Name": "ExpectedCode",
"Label": "Expected code",
"HelpText": "The expected HTTP status code",
"DefaultValue": "200",
"DisplaySettings": {}
},
{
"Id": "7c96b2b3-53dd-4281-ae1a-ef67cbc0eb72",
"Name": "TimeoutSeconds",
"Label": "Timeout (Seconds)",
"HelpText": "The number of seconds before the step fails and times out",
"DefaultValue": "60",
"DisplaySettings": {}
},
{
"Id": "ac0b303c-0c59-4776-be21-d93ebe9e28e7",
"Name": "AuthUsername",
"Label": "Username",
"HelpText": "Username for authentication. Leave blank to use Anonymous.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Id": "38eae17a-3098-48df-b8dc-96c3185f9f40",
"Name": "AuthPassword",
"Label": "Password",
"HelpText": "Password for authentication. Leave blank for Anonymous.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Sensitive"
}
},
{
"Id": "60fe87fe-e96d-448e-94fa-f2ce4bfbaf3a",
"Name": "UseWindowsAuth",
"Label": "Use Windows Authentication",
"HelpText": "Should the request be made passing windows authentication (kerberos) credentials otherwise uses basic authentication",
"DefaultValue": "False",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
}
},
{
"Id": "47c779b5-c515-49f9-a122-f692b0f12ff7",
"Name": "ExpectedResponse",
"Label": "Expected Response",
"HelpText": "The response should be this text",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"LastModifiedBy": "Pietrowicz",
"$Meta": {
"ExportedAt": "2018-04-19T04:22:23.191Z",
"OctopusVersion": "2018.3.13",
"Type": "ActionTemplate"
},
"Category": "http"
}