Skip to content

Commit

Permalink
Adds new endpoints for creating Runbook Runs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewabest committed Jun 22, 2020
1 parent ccd18c2 commit a6878a6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
63 changes: 63 additions & 0 deletions source/Octopus.Client/Model/RunbookRunParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Octopus.Client.Model
{
public class RunbookRunParameters
{
/// <summary>
/// Parameter class for marshalling params between OctopusCLI and Octopus Server
/// This class is used to facilitate backwards compatibility while extending /runbooks/{id}/run"
/// </summary>
public RunbookRunParameters()
{
FormValues = new Dictionary<string, string>();
SpecificMachineIds = new string[0];
ExcludedMachineIds = new string[0];
EnvironmentIds = new string[0];
TenantTagNames = new string[0];
TenantIds = new string[0];
SkipActions = new string[0];
}

public bool UseDefaultSnapshot { get; set; } = true;

public string RunbookId { get; set; }
public string ProjectId { get; set; }
public string RunbookSnapshotNameOrId { get; set; }
public string EnvironmentId { get; set; }
public string[] EnvironmentIds { get; set; }
public bool ForcePackageDownload { get; set; }
public bool? UseGuidedFailure { get; set; }
public string[] SpecificMachineIds { get; set; }
public string[] ExcludedMachineIds { get; set; }
public string TenantId { get; set; }
public string[] TenantIds { get; set; }
public string[] TenantTagNames { get; set; }
public string[] SkipActions { get; set; }
public DateTimeOffset? QueueTime { get; set; }
public DateTimeOffset? QueueTimeExpiry { get; set; }
public Dictionary<string, string> FormValues { get; set; }

public static RunbookRunParameters MapFrom(RunbookRunResource runbookRun)
{
return new RunbookRunParameters
{
UseDefaultSnapshot = true,
RunbookId = runbookRun.RunbookId,
ProjectId = runbookRun.ProjectId,
EnvironmentId = runbookRun.EnvironmentId,
ForcePackageDownload = runbookRun.ForcePackageDownload,
UseGuidedFailure = runbookRun.UseGuidedFailure,
SpecificMachineIds = runbookRun.SpecificMachineIds.ToArray(),
ExcludedMachineIds = runbookRun.ExcludedMachineIds.ToArray(),
TenantId = runbookRun.TenantId,
SkipActions = runbookRun.SkipActions.ToArray(),
QueueTime = runbookRun.QueueTime,
QueueTimeExpiry = runbookRun.QueueTimeExpiry,
FormValues = runbookRun.FormValues
};
}
}
}
5 changes: 5 additions & 0 deletions source/Octopus.Client/Repositories/Async/RunbookRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public Task<RunbookRunPreviewResource> GetPreview(DeploymentPromotionTarget prom
}

public Task<RunbookRunResource> Run(RunbookResource runbook, RunbookRunResource runbookRun)
{
return Run(runbook, RunbookRunParameters.MapFrom(runbookRun));
}

public Task<RunbookRunResource> Run(RunbookResource runbook, RunbookRunParameters runbookRun)
{
return Client.Post<object, RunbookRunResource>(runbook.Link("CreateRunbookRun"), runbookRun);
}
Expand Down
10 changes: 8 additions & 2 deletions source/Octopus.Client/Repositories/RunbookRepository.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Octopus.Client.Editors;
using Octopus.Client.Model;

Expand All @@ -12,7 +13,7 @@ public interface IRunbookRepository : IFindByName<RunbookResource>, IGet<Runbook
RunbookRunPreviewResource GetPreview(DeploymentPromotionTarget promotionTarget);
RunbookRunResource Run(RunbookResource runbook, RunbookRunResource runbookRun);
}

class RunbookRepository : BasicRepository<RunbookResource>, IRunbookRepository
{
public RunbookRepository(IOctopusRepository repository)
Expand Down Expand Up @@ -44,10 +45,15 @@ public RunbookRunPreviewResource GetPreview(DeploymentPromotionTarget promotionT
{
return Client.Get<RunbookRunPreviewResource>(promotionTarget.Link("RunbookRunPreview"));
}
public RunbookRunResource Run(RunbookResource runbook, RunbookRunResource runbookRun)
{
return Run(runbook, RunbookRunParameters.MapFrom(runbookRun));
}

public RunbookRunResource Run(RunbookResource runbook, RunbookRunResource runbookRun)
public RunbookRunResource Run(RunbookResource runbook, RunbookRunParameters runbookRun)
{
return Client.Post<object, RunbookRunResource>(runbook.Link("CreateRunbookRun"), runbookRun);
}

}
}

0 comments on commit a6878a6

Please sign in to comment.