Beispiel #1
0
 public async Task ShouldErrorIfNameContainsInvalidChars()
 {
     var register = new Register(new RegistrationRequest {
         AdminPat = Pat, Labels = new string[] { }, Owner = Owner, Repository = Repo
     }, "a");
     await Assert.ThrowsAsync <InvalidOperationException>(async() => await register.AddRunner("foo\"", false));
 }
Beispiel #2
0
        public async Task <ActionResult <Dictionary <string, RunnerRegistrationSecretData> > > Post([FromBody] RegistrationRequest request)
        {
            try
            {
                var runners  = new Dictionary <string, RunnerRegistrationSecretData>();
                var register = new Register(request);
                await register.Setup();

                var identifier = new StringBuilder();
                identifier.AppendFormat("runners://{0}/{1}", request.Owner, request.Repository);
                foreach (var name in request.RunnerNames)
                {
                    this.logger.LogInformation("Adding runner {name} to {Owner}/{Repository}", name, request.Owner, request.Repository);
                    var creds = await register.AddRunner(name, request.DryRun);

                    runners.Add(name, creds);
                    identifier.AppendFormat("/{0}", creds.Id);
                }
                // This is essentially a registration request ID
                var idUri = new Uri(identifier.ToString());
                if (request.DryRun)
                {
                    return(this.Accepted(idUri, runners));
                }
                return(this.Created(idUri, runners));
            }
            catch (InvalidOperationException ex)
            {
                this.logger.LogWarning(ex, "Error adding runners to {Owner}/{Repository}", request.Owner, request.Repository);
                return(this.BadRequest(ex.Message));
            }
            catch (SetupException ex)
            {
                this.logger.LogWarning(ex, "Error adding runners to {Owner}/{Repository}", request.Owner, request.Repository);
                return(this.BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Error adding runners to {Owner}/{Repository}", request.Owner, request.Repository);
                throw ex;
            }
        }