Hi,
I am trying to write a step template to get the IP addresses of a particular role within the currently executing environment. To do this I currently seem to have to embed an API key, which isn’t ideal. Is there a way in which I can avoid doing this? Can I access the octopus API in a step template without passing the X-Octopus-ApiKey header?
Hi,
I am trying to write a step template to get the IP addresses of a particular role within the currently executing environment. To do this I currently seem to have to embed an API key, which isn’t ideal. Is there a way in which I can avoid doing this? Can I access the octopus API in a step template without passing the X-Octopus-ApiKey header?
My step template is below:
$RequestHeaders = @{};
$RequestHeaders['X-Octopus-ApiKey'] = 'API-XXXXXXXXXXXX';
$machinesInRole = $OctopusParameters["Octopus.Environment.MachinesInRole[$DeploymentTargetAddresseRole]"] -split ','
$roleHosts = New-Object System.Collections.ArrayList
$machinesInRole | % {
$machine = ConvertFrom-Json (Invoke-WebRequest -Headers $RequestHeaders "$($OctopusParameters["Octopus.Web.BaseUrl"])/api/machines/$_").Content
if($machine.Endpoint.Host)
{
$roleHosts.Add($machine.Endpoint.Host) | Out-Null
}
elseif($machine.Endpoint.Uri)
{
$uri = New-Object System.Uri -ArgumentList $machine.Endpoint.Uri
$roleHosts.Add($uri.Host) | Out-Null
}
}
$currentValue = $roleHosts -join ','
Write-Host "Setting $DeploymentTargetAddressesVariable to $currentValue"
Set-OctopusVariable -name $DeploymentTargetAddressesVariable -value $currentValue