Accessing API as currently executing user

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

Hi,

You’ll need the API Key to call the API unfortunately. If you’d prefer not to have the key in your template you could add it as a sensitive template parameter.

Alternatively, I’ve seen customers do something similar to what you are trying to achieve by running a script step on the Machines they want the IP from and writing the result to an Output Variable (http://docs.octopusdeploy.com/display/OD/Output+variables) and then just reading that Output Variable in a later step. This won’t fit into a single Step Template though.

Regards,
Mark