Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 26788d0

Browse files
committed
improve openapi docs
1 parent 6e89308 commit 26788d0

File tree

23 files changed

+1097
-0
lines changed

23 files changed

+1097
-0
lines changed

GithubRunnerRegistration/GithubRunnerRegistration.Api/Controllers/ValuesController.cs renamed to GithubRunnerRegistration/GithubRunnerRegistration.Api/Controllers/RegisterController.cs

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
##
4+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5+
6+
# User-specific files
7+
*.rsuser
8+
*.suo
9+
*.user
10+
*.userosscache
11+
*.sln.docstates
12+
13+
# User-specific files (MonoDevelop/Xamarin Studio)
14+
*.userprefs
15+
16+
# Mono auto generated files
17+
mono_crash.*
18+
19+
# Build results
20+
[Dd]ebug/
21+
[Dd]ebugPublic/
22+
[Rr]elease/
23+
[Rr]eleases/
24+
x64/
25+
x86/
26+
[Ww][Ii][Nn]32/
27+
[Aa][Rr][Mm]/
28+
[Aa][Rr][Mm]64/
29+
bld/
30+
[Bb]in/
31+
[Oo]bj/
32+
[Ll]og/
33+
[Ll]ogs/
34+
35+
# Visual Studio 2015/2017 cache/options directory
36+
.vs/
37+
# Uncomment if you have tasks that create the project's static files in wwwroot
38+
#wwwroot/
39+
40+
# Visual Studio 2017 auto generated files
41+
Generated\ Files/
42+
43+
# MSTest test Results
44+
[Tt]est[Rr]esult*/
45+
[Bb]uild[Ll]og.*
46+
47+
# NUnit
48+
*.VisualState.xml
49+
TestResult.xml
50+
nunit-*.xml
51+
52+
# Build Results of an ATL Project
53+
[Dd]ebugPS/
54+
[Rr]eleasePS/
55+
dlldata.c
56+
57+
# Benchmark Results
58+
BenchmarkDotNet.Artifacts/
59+
60+
# .NET Core
61+
project.lock.json
62+
project.fragment.lock.json
63+
artifacts/
64+
65+
# ASP.NET Scaffolding
66+
ScaffoldingReadMe.txt
67+
68+
# StyleCop
69+
StyleCopReport.xml
70+
71+
# Files built by Visual Studio
72+
*_i.c
73+
*_p.c
74+
*_h.h
75+
*.ilk
76+
*.meta
77+
*.obj
78+
*.iobj
79+
*.pch
80+
*.pdb
81+
*.ipdb
82+
*.pgc
83+
*.pgd
84+
*.rsp
85+
*.sbr
86+
*.tlb
87+
*.tli
88+
*.tlh
89+
*.tmp
90+
*.tmp_proj
91+
*_wpftmp.csproj
92+
*.log
93+
*.vspscc
94+
*.vssscc
95+
.builds
96+
*.pidb
97+
*.svclog
98+
*.scc
99+
100+
# Chutzpah Test files
101+
_Chutzpah*
102+
103+
# Visual C++ cache files
104+
ipch/
105+
*.aps
106+
*.ncb
107+
*.opendb
108+
*.opensdf
109+
*.sdf
110+
*.cachefile
111+
*.VC.db
112+
*.VC.VC.opendb
113+
114+
# Visual Studio profiler
115+
*.psess
116+
*.vsp
117+
*.vspx
118+
*.sap
119+
120+
# Visual Studio Trace Files
121+
*.e2e
122+
123+
# TFS 2012 Local Workspace
124+
$tf/
125+
126+
# Guidance Automation Toolkit
127+
*.gpState
128+
129+
# ReSharper is a .NET coding add-in
130+
_ReSharper*/
131+
*.[Rr]e[Ss]harper
132+
*.DotSettings.user
133+
134+
# TeamCity is a build add-in
135+
_TeamCity*
136+
137+
# DotCover is a Code Coverage Tool
138+
*.dotCover
139+
140+
# AxoCover is a Code Coverage Tool
141+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using GithubRunnerRegistration.Models;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Logging;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
12+
13+
namespace GithubRunnerRegistration.Api.Controllers
14+
{
15+
[Produces("application/json")]
16+
[Route("api/[controller]")]
17+
[ApiController]
18+
public class RegisterController : ControllerBase
19+
{
20+
private readonly ILogger<RegisterController> logger;
21+
22+
public RegisterController(ILogger<RegisterController> logger)
23+
{
24+
this.logger = logger;
25+
}
26+
27+
28+
/// <summary>
29+
/// Registers runners against the provided repo and returns the data required to associate each runner with the repo.
30+
/// The data returned can be used as the data property of a secret which is then referenced by ScaledActionRunner.RunnerSecrets
31+
/// The secret will then be mnoounted by a pod and used to register with Github
32+
/// </summary>
33+
/// <param name="request"></param>
34+
/// <returns>A map of secret names to secret data</returns>
35+
/// <response code="201">Request passed validation and runner(s) have been registered</response>
36+
/// <response code="202">Request passed validation but no runners were created because dryRun was specified, dummy information has been returned</response>
37+
/// <response code="400">Supplied request is invalid</response>
38+
[HttpPost]
39+
[ProducesResponseType(StatusCodes.Status201Created)]
40+
[ProducesResponseType(StatusCodes.Status202Accepted)]
41+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
42+
public async Task<ActionResult<Dictionary<string,RunnerRegistrationSecretData>>> Post([FromBody] RegistrationRequest request)
43+
{
44+
try
45+
{
46+
var runners = new Dictionary<string, RunnerRegistrationSecretData>();
47+
var register = new Register(request);
48+
await register.Setup();
49+
var identifier = new StringBuilder();
50+
identifier.AppendFormat ("runners://{0}/{1}", request.Owner, request.Repository);
51+
foreach (var name in request.RunnerNames)
52+
{
53+
this.logger.LogInformation("Adding runner {name} to {Owner}/{Repository}", name, request.Owner, request.Repository);
54+
var creds = await register.AddRunner(name, request.DryRun);
55+
runners.Add(name, creds);
56+
identifier.AppendFormat("/{0}", creds.Id);
57+
}
58+
// This is essentially a registration request ID
59+
var idUri = new Uri(identifier.ToString());
60+
if (request.DryRun)
61+
{
62+
return this.Accepted(idUri, runners);
63+
}
64+
return this.Created(idUri,runners);
65+
}
66+
catch (InvalidOperationException ex)
67+
{
68+
this.logger.LogWarning(ex, "Error adding runners to {Owner}/{Repository}", request.Owner, request.Repository);
69+
return this.BadRequest(ex.Message);
70+
}
71+
catch (SetupException ex)
72+
{
73+
this.logger.LogWarning(ex, "Error adding runners to {Owner}/{Repository}", request.Owner, request.Repository);
74+
return this.BadRequest(ex.Message);
75+
}
76+
catch (Exception ex)
77+
{
78+
this.logger.LogError(ex, "Error adding runners to {Owner}/{Repository}", request.Owner, request.Repository);
79+
throw ex;
80+
}
81+
}
82+
}
83+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
3+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
4+
COPY --from=myoung34/github-runner:latest /actions-runner/ /actions-runner/
5+
WORKDIR /app
6+
ENV ASPNETCORE_URLS=http://+:8080
7+
RUN chown 33 /actions-runner/ -R
8+
USER 33
9+
EXPOSE 8080
10+
11+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
12+
WORKDIR /src
13+
COPY ["GithubRunnerRegistration.Api/GithubRunnerRegistration.Api.csproj", "GithubRunnerRegistration.Api/"]
14+
COPY ["GithubRunnerRegistration/GithubRunnerRegistration.csproj", "GithubRunnerRegistration/"]
15+
COPY ["GithubRunnerRegistration.Tests/GithubRunnerRegistration.Tests.csproj", "GithubRunnerRegistration.Tests/"]
16+
RUN dotnet restore "GithubRunnerRegistration.Api/GithubRunnerRegistration.Api.csproj"
17+
RUN dotnet restore "GithubRunnerRegistration.Tests/GithubRunnerRegistration.Tests.csproj"
18+
COPY . .
19+
WORKDIR "/src/"
20+
RUN dotnet test "GithubRunnerRegistration.Tests/GithubRunnerRegistration.Tests.csproj"
21+
RUN dotnet build "GithubRunnerRegistration.Api/GithubRunnerRegistration.Api.csproj" -c Release -o /app/build
22+
23+
FROM build AS publish
24+
RUN dotnet publish "GithubRunnerRegistration.Api/GithubRunnerRegistration.Api.csproj" -c Release -o /app/publish
25+
26+
FROM base AS final
27+
WORKDIR /app
28+
COPY --from=publish /app/publish .
29+
ENTRYPOINT ["dotnet", "GithubRunnerRegistration.Api.dll"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.2" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\GithubRunnerRegistration\GithubRunnerRegistration.csproj" />
15+
</ItemGroup>
16+
<PropertyGroup>
17+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
18+
<NoWarn>$(NoWarn);1591</NoWarn>
19+
</PropertyGroup>
20+
21+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Threading.Tasks;
9+
10+
namespace GithubRunnerRegistration
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:8544",
7+
"sslPort": 0
8+
}
9+
},
10+
"$schema": "http://json.schemastore.org/launchsettings.json",
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"GithubRunnerRegistration": {
21+
"commandName": "Project",
22+
"launchBrowser": true,
23+
"launchUrl": "",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
},
27+
"applicationUrl": "http://localhost:5000"
28+
},
29+
"Docker": {
30+
"commandName": "Docker",
31+
"launchBrowser": true,
32+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
33+
"publishAllPorts": true
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)