Meta.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Sockets;
  5. using System.Text.Json.Serialization;
  6. namespace FastGithub.Scanner
  7. {
  8. class Meta
  9. {
  10. [JsonPropertyName("hooks")]
  11. public string[] Hooks { get; set; } = Array.Empty<string>();
  12. [JsonPropertyName("web")]
  13. public string[] Web { get; set; } = Array.Empty<string>();
  14. [JsonPropertyName("api")]
  15. public string[] Api { get; set; } = Array.Empty<string>();
  16. [JsonPropertyName("git")]
  17. public string[] Git { get; set; } = Array.Empty<string>();
  18. [JsonPropertyName("packages")]
  19. public string[] Packages { get; set; } = Array.Empty<string>();
  20. [JsonPropertyName("pages")]
  21. public string[] Pages { get; set; } = Array.Empty<string>();
  22. [JsonPropertyName("importer")]
  23. public string[] Importer { get; set; } = Array.Empty<string>();
  24. [JsonPropertyName("actions")]
  25. public string[] Actions { get; set; } = Array.Empty<string>();
  26. [JsonPropertyName("dependabot")]
  27. public string[] Dependabot { get; set; } = Array.Empty<string>();
  28. public IEnumerable<GithubContext> ToGithubContexts()
  29. {
  30. foreach (var range in IPRange.From(this.Web).OrderBy(item => item.Size))
  31. {
  32. if (range.AddressFamily == AddressFamily.InterNetwork)
  33. {
  34. foreach (var address in range)
  35. {
  36. yield return new GithubContext("github.com", address);
  37. }
  38. }
  39. }
  40. foreach (var range in IPRange.From(this.Api).OrderBy(item => item.Size))
  41. {
  42. if (range.AddressFamily == AddressFamily.InterNetwork)
  43. {
  44. foreach (var address in range)
  45. {
  46. yield return new GithubContext("api.github.com", address);
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }