public override async Task <bool> ReportPackageSourceAudit() { if (!AuditOptions.ContainsKey("GitHubReportOwner") || !AuditOptions.ContainsKey("GitHubReportName") || !AuditOptions.ContainsKey("GitHubToken")) { throw new ArgumentException("The GitHubReportOwner, GitHubReportName, and GitHubReportOwner audit options must be present."); } if (AuditOptions.ContainsKey("GitHubReportTitle")) { IssueTitle = (string)AuditOptions["GitHubReportTitle"]; } else { IssueTitle = string.Format("[DevAudit] {2} audit on {0} {1}", DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString(), Source.PackageManagerLabel); } GitHubClient client; client = new GitHubClient(new ProductHeaderValue("DevAudit")); client.Credentials = new Credentials((string)AuditOptions["GitHubToken"]); Repository repository; try { repository = await client.Repository.Get((string)AuditOptions["GitHubReportOwner"], (string)AuditOptions["GitHubReportName"]); } catch (Exception) { AuditEnvironment.Warning("Could not get repository {0}/{1}.", (string)AuditOptions["GitHubReportOwner"], (string)AuditOptions["GitHubReportName"]); } NewIssue issue = new NewIssue(IssueTitle); BuildPackageSourceAuditReport(); issue.Body = IssueText.ToString(); try { Issue i = await client.Issue.Create((string)AuditOptions["GitHubReportOwner"], (string)AuditOptions["GitHubReportName"], issue); AuditEnvironment.Info("Created issue #{0} {1} in GitHub repository {2}/{3}.", i.Number, IssueTitle, (string)AuditOptions["GitHubReportOwner"], (string)AuditOptions["GitHubReportName"]); } catch (AggregateException ae) { AuditEnvironment.Error(ae, "Error creating new issue for repository {0}/{1}.", (string)AuditOptions["GitHubReportOwner"], (string)AuditOptions["GitHubReportName"]); return(false); } catch (Exception e) { AuditEnvironment.Error(e, "Error creating new issue for repository {0}/{1}.", (string)AuditOptions["GitHubReportOwner"], (string)AuditOptions["GitHubReportName"]); return(false); } return(true); }
public IQServerReporter(PackageSource source) : base(source) { if (!AuditOptions.ContainsKey("IQServerUrl") || !AuditOptions.ContainsKey("IQServerUser") || !AuditOptions.ContainsKey("IQServerPass") || !AuditOptions.ContainsKey("IQServerAppId")) { throw new ArgumentException("The IQServerUrl, IQServerUser, IQServerPass, IQServerAppId audit options must all be present."); } IQServerUrl = (Uri)AuditOptions["IQServerUrl"]; IQServerUser = (string)AuditOptions["IQServerUser"]; IQServerPass = (string)AuditOptions["IQServerPass"]; IQServerAppId = (string)AuditOptions["IQServerAppId"]; HttpClient = CreateHttpClient(); var byteArray = Encoding.ASCII.GetBytes($"{IQServerUser}:{IQServerPass}"); HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); AuditEnvironment.Info("Authenticating with IQ Server user {0}.", IQServerUser); }
public override async Task <bool> ReportPackageSourceAudit() { if (!this.AuditOptions.ContainsKey("GitLabReportUrl") || !this.AuditOptions.ContainsKey("GitLabReportName") || !this.AuditOptions.ContainsKey("GitLabToken")) { throw new ArgumentException("A required audit option for the GitLab environment is missing."); } HostUrl = (string)this.AuditOptions["GitLabReportUrl"]; Token = (string)this.AuditOptions["GitLabToken"]; ProjectName = (string)this.AuditOptions["GitLabReportName"]; GitLabClient client = null; try { this.AuditEnvironment.Info("Connecting to project {0} at {1}", ProjectName, HostUrl); client = new GitLabClient(HostUrl, Token); IEnumerable <Project> projects = await client.Projects.Owned(); Project = projects.Where(p => p.Name == ProjectName).FirstOrDefault(); this.AuditEnvironment.Info("Connected to project {0}.", Project.PathWithNamespace); } catch (AggregateException ae) { AuditEnvironment.Error(ae, "Could not get project {0} at url {1}.", ProjectName, HostUrl); return(false); } catch (Exception e) { AuditEnvironment.Error(e, "Could not get project {0} at url {1}.", ProjectName, HostUrl); return(false); } if (Project == null) { AuditEnvironment.Error("Could not find the project {0}.", Project.Name); return(false); } if (!Project.IssuesEnabled) { AuditEnvironment.Error("Issues are not enabled for the project {0}/{1}.", Project.Owner, Project.Name); return(false); } if (AuditOptions.ContainsKey("GitLabReportTitle")) { IssueTitle = (string)AuditOptions["GitLabReportTitle"]; } else { IssueTitle = string.Format("[DevAudit] {2} audit on {0} {1}", DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString(), Source.PackageManagerLabel); } BuildPackageSourceAuditReport(); try { IssueCreate ic = new IssueCreate { ProjectId = Project.Id, Title = IssueTitle, Description = IssueText.ToString() }; Issue issue = await client.Issues.CreateAsync(ic); if (issue != null) { AuditEnvironment.Success("Created issue #{0} '{1}' in GitLab project {2}/{3} at host url {4}.", issue.IssueId, issue.Title, Project.Owner, ProjectName, HostUrl); return(true); } else { AuditEnvironment.Error("Error creating new issue for project {0} at host url {1}. The issue object is null.", ProjectName, HostUrl); return(false); } } catch (AggregateException ae) { AuditEnvironment.Error(ae, "Error creating new issue for project {0} at host url {1}.", ProjectName, HostUrl); return(false); } catch (Exception e) { AuditEnvironment.Error(e, "Error creating new issue for project {0} at host url {1}.", ProjectName, HostUrl); return(false); } }
public override Task <bool> ReportPackageSourceAudit() { if (!AuditOptions.ContainsKey("BitBucketReportAccount") || !AuditOptions.ContainsKey("BitBucketReportName") || !AuditOptions.ContainsKey("BitBucketKey")) { throw new ArgumentException("The BitBucketReportAccount, BitBucketReportName, and BitBucketReportKey audit options must be present."); } string key = (string)AuditOptions["BitBucketKey"]; string[] k = key.Split('|'); if (k.Count() != 2) { throw new ArgumentException("The BitBucketReportKey audit option must have the format consumer_key|secret."); } string consumer = k[0], secret = k[1]; string account = (string)AuditOptions["BitBucketReportAccount"]; string repository = (string)AuditOptions["BitBucketReportName"]; if (AuditOptions.ContainsKey("BitBucketReportTitle")) { IssueTitle = (string)AuditOptions["BitBucketReportTitle"]; } else { IssueTitle = string.Format("[DevAudit] {0} audit on {1} {2}", Source.PackageManagerLabel, DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString()); } SharpBucketV2 sharp_bucket = new SharpBucketV2(); sharp_bucket.OAuth2LeggedAuthentication(consumer, secret); RepositoriesEndPoint repository_endpoint = sharp_bucket.RepositoriesEndPoint(account, repository); IssuesResource r; try { r = repository_endpoint.IssuesResource(); } catch (Exception e) { AuditEnvironment.Error(e, "Could not get issues resource for repository {0}/{1}.", account, repository); return(Task.FromResult(false)); } BuildPackageSourceAuditReport(); Issue issue = new Issue() { title = IssueTitle, content = IssueText.ToString(), status = "new", priority = "major", kind = "bug" }; try { Issue i = r.PostIssue(issue); if (i == null) { AuditEnvironment.Error("Could not post issue to repository {0}/{1}.", account, repository); return(Task.FromResult(false)); } else { AuditEnvironment.Success("Created issue {0} at {1}.", i.title, i.resource_uri); } } catch (Exception e) { AuditEnvironment.Error(e, "Could not post issue to repository {0}/{1}.", account, repository); return(Task.FromResult(false)); } return(Task.FromResult(true)); }