Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover Machines via Proxy #244

Closed
pixman20 opened this issue Apr 9, 2018 · 2 comments
Closed

Discover Machines via Proxy #244

pixman20 opened this issue Apr 9, 2018 · 2 comments

Comments

@pixman20
Copy link

pixman20 commented Apr 9, 2018

Currently the Discover function in MachineRepository.cs does not take a proxy id, but the url template and rest api allow for it.

https://github.com/OctopusDeploy/OctopusClients/blob/master/source/Octopus.Client/Repositories/MachineRepository.cs#L53

@pixman20
Copy link
Author

Something like the following should work (I was unable to build and test due to Cake issues or I'd open a PR myself).

public MachineResource Discover(string host, int port = 10933, DiscoverableEndpointType type, String proxyId)
{
    return Client.Get<MachineResource>(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type, proxyId });
}

The current workaround using Powershell is

[CmdletBinding()]
param (
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string] $octoDll = $null,
    
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string] $octoUrl = $null,
    
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string] $octoApiKey = $null,
    
    [Parameter(Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string] $hostname = $null,
    
    [Parameter(Mandatory=$false)]
    [string] $port = 10933,
    
    [Parameter(Mandatory=$false)]
    [string] $type = "TentaclePassive",
    
    [Parameter(Mandatory=$false)]
    [string] $proxyId = $null
)

Add-Type -Path $octoDll

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octoUrl,$octoApiKey 
$octoRepo = New-Object Octopus.Client.OctopusRepository $endpoint

$urlParams = "?host=$hostname&port=$port&type=$type"
if(-not [string]::IsNullOrEmpty($proxyId)) {
    $urlParams += '&proxyId=' + $proxyId
}

$client = $octoRepo.Machines.Client
$path = $client.RootDocument.Link("DiscoverMachine")
$path = $path -replace '\{.*', $urlParams

$method = $client.GetType().GetMethod("Get")
$genericMethod = $method.MakeGenericMethod([Octopus.Client.Model.MachineResource])
$server = $genericMethod.Invoke($client, @($path, $null))
return $server

droyad added a commit that referenced this issue Apr 18, 2018
…thod added to avoid breaking API change, the Options object should ensure new parameters are easier to add. Fixes #244
@droyad
Copy link
Contributor

droyad commented Apr 20, 2018

Fixed in 4.33.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants