Skip to content

Instantly share code, notes, and snippets.

@PaulStovell
Last active December 18, 2015 22:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PaulStovell/5857552 to your computer and use it in GitHub Desktop.
Save PaulStovell/5857552 to your computer and use it in GitHub Desktop.
public class OctopusRestApi : ApiDefinition
{
public OctopusRestApi()
{
#region Projects
Get["/api/projects/all"] = ListAll<ProjectSummaryIndex, Project, ProjectResource>()
.WithDescription("Lists the name and ID of all of the projects in the current Octopus installation. The results will be sorted alphabetically by name.")
.WithCustomQuery(projects => projects.OrderBy(m => m.Name));
Get["/api/projects/{id}"] = Load<Project, ProjectResource>()
.WithDescription("Gets a single project by ID.");
Get["/api/projects"] = Index<ProjectSummaryIndex, Project, ProjectResource>()
.WithDescription("Lists all of the projects in the current Octopus installation, from all project groups. The results will be sorted alphabetically by name.")
.WithItemsPerPage(30)
.WithCustomQuery(projects => projects.OrderBy(m => m.Name))
.WithLinkTemplate(WebRoutes.Api.Projects.Index);
Post["/api/projects"] = Create<Project, ProjectResource>()
.WithDescription("Creates a new project.")
.WithRule(new ProjectVariableSetWillBeCreatedRule())
.WithRule(new AdministratorsOnlyRule());
Put["/api/projects/{id}"] = Modify<Project, ProjectResource>()
.WithDescription("Modifies an existing project.")
.WithRule(new AdministratorsOnlyRule());
Delete["/api/projects/{id}"] = DeleteOnBackground<Project, ProjectResource>()
.WithDescription("Deletes an existing project.")
.WithRule(new AdministratorsOnlyRule());
#endregion
#region Machines
Get["/api/machines/{id}"] = Load<Machine, MachineResource>()
.WithDescription("Gets a single machine by ID.");
Get["/api/machines"] = Index<MachinesIndex, Machine, MachineResource>()
.WithDescription("Lists all of the registered machines in the current Octopus installation, from all environments. The results will be sorted alphabetically by name.")
.WithItemsPerPage(30)
.WithCustomQuery(machines => machines.OrderBy(m => m.Name))
.WithLinkTemplate(WebRoutes.Api.Machines.Index);
Post["/api/machines"] = Create<Machine, MachineResource>()
.WithDescription("Creates a new machine.")
.WithRule(new AdministratorsOnlyRule()); ;
Put["/api/machines/{id}"] = Modify<Machine, MachineResource>()
.WithDescription("Modifies an existing machine.")
.WithRule(new AdministratorsOnlyRule()); ;
Delete["/api/machines/{id}"] = DeleteOnBackground<Machine, MachineResource>()
.WithDescription("Deletes an existing machine.")
.WithRule(new AdministratorsOnlyRule()); ;
#endregion
#region Environments
Get["/api/environments/all"] = ListAll<EnvironmentsIndex, DeploymentEnvironment, EnvironmentResource>()
.WithDescription("Lists the name and ID of all of the environments in the current Octopus installation. The results will be sorted by the SortOrder field on each environment.")
.WithCustomQuery(environments => environments.OrderBy(m => m.SortOrder));
Get["/api/environments/{id}"] = Load<DeploymentEnvironment, EnvironmentResource>()
.WithDescription("Gets a single environment by ID.");
Get["/api/environments"] = Index<EnvironmentsIndex, DeploymentEnvironment, EnvironmentResource>()
.WithDescription("Lists all of the environments in the current Octopus installation, from any environment group. The results will be sorted by the SortOrder field on each environment.")
.WithCustomQuery(environments => environments.OrderBy(m => m.SortOrder))
.WithItemsPerPage(10)
.WithLinkTemplate(WebRoutes.Api.Environments.Index);
Get["/api/environments/{id}/machines"] = ChildIndex<MachinesByEnvironment, MachinesByEnvironment.Result, DeploymentEnvironment, Machine, EnvironmentResource, MachineResource>()
.WithDescription("Lists all of the machines that belong to the given environment.")
.WithFilter(parent => m => m.EnvironmentId == parent.Id)
.WithInclude(m => m.MachineId)
.WithItemsPerPage(20)
.WithLinkTemplate(WebRoutes.Api.Environments.GetMachines);
Post["/api/environments/sort"] = CustomAction<EnvironmentResource, SortEnvironmentsResponder>()
.WithDescription("Takes an array of environment ID's as the request body, uses the order of items in the array to sort the environments on the server. The ID of every environment must be specified.")
.WithRule(new AdministratorsOnlyRule());
Post["/api/environments"] = Create<DeploymentEnvironment, EnvironmentResource>()
.WithDescription("Creates a new environment.")
.WithRule(new EnvironmentSortOrderWillBeAssignedRule())
.WithRule(new AdministratorsOnlyRule());
Put["/api/environments/{id}"] = Modify<DeploymentEnvironment, EnvironmentResource>()
.WithDescription("Modifies an existing environment.");
Delete["/api/environments/{id}"] = DeleteOnBackground<DeploymentEnvironment, EnvironmentResource>()
.WithDescription("Deletes an existing environment.")
.WithRule(new EnvironmentMustBeEmptyBeforeDeletionRule())
.WithRule(new AdministratorsOnlyRule()); ;
#endregion
#region Events
Get["/api/events/{id}"] = Load<Event, EventResource>()
.WithDescription("Gets a single event by ID.")
.WithRule(new AdministratorsOnlyRule());
Get["/api/events"] = CustomQuery<EventResource, ListEventsResponder>()
.WithDescription("List all of the the audit events collected to date. Events can be filtered by the documents they are regarding, or the user ID that the event was created by. Events will be ordered by the date of the event, descending.")
.WithItemsPerPage(30)
.WithLinkTemplate(WebRoutes.Api.Events.Index)
.WithRule(new AdministratorsOnlyRule());
#endregion
}
}
Get["/api/projects/all"] = ListAll<ProjectSummaryIndex, Project, ProjectResource>()
.WithDescription("Lists the name and ID of all of the projects in the current Octopus installation. The results will be sorted alphabetically by name.")
.WithCustomQuery(projects => projects.OrderBy(m => m.Name));
Get["/api/projects/{id}"] = Load<Project, ProjectResource>()
.WithDescription("Gets a single project by ID.");
Get["/api/projects"] = Index<ProjectSummaryIndex, Project, ProjectResource>()
.WithDescription("Lists all of the projects in the current Octopus installation, from all project groups. The results will be sorted alphabetically by name.")
.WithItemsPerPage(30)
.WithCustomQuery(projects => projects.OrderBy(m => m.Name))
.WithLinkTemplate(WebRoutes.Api.Projects.Index);
Post["/api/projects"] = Create<Project, ProjectResource>()
.WithDescription("Creates a new project.")
.WithRule(new ProjectVariableSetWillBeCreatedRule())
.WithRule(new AdministratorsOnlyRule());
Put["/api/projects/{id}"] = Modify<Project, ProjectResource>()
.WithDescription("Modifies an existing project.")
.WithRule(new AdministratorsOnlyRule());
Delete["/api/projects/{id}"] = DeleteOnBackground<Project, ProjectResource>()
.WithDescription("Deletes an existing project.")
.WithRule(new AdministratorsOnlyRule());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment