registry.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package registry
  2. import (
  3. "encoding/json"
  4. "net"
  5. "github.com/docker/distribution"
  6. "github.com/docker/distribution/manifest/manifestlist"
  7. )
  8. // ServiceConfig stores daemon registry services configuration.
  9. type ServiceConfig struct {
  10. AllowNondistributableArtifactsCIDRs []*NetIPNet
  11. AllowNondistributableArtifactsHostnames []string
  12. InsecureRegistryCIDRs []*NetIPNet `json:"InsecureRegistryCIDRs"`
  13. IndexConfigs map[string]*IndexInfo `json:"IndexConfigs"`
  14. Mirrors []string
  15. }
  16. // NetIPNet is the net.IPNet type, which can be marshalled and
  17. // unmarshalled to JSON
  18. type NetIPNet net.IPNet
  19. // String returns the CIDR notation of ipnet
  20. func (ipnet *NetIPNet) String() string {
  21. return (*net.IPNet)(ipnet).String()
  22. }
  23. // MarshalJSON returns the JSON representation of the IPNet
  24. func (ipnet *NetIPNet) MarshalJSON() ([]byte, error) {
  25. return json.Marshal((*net.IPNet)(ipnet).String())
  26. }
  27. // UnmarshalJSON sets the IPNet from a byte array of JSON
  28. func (ipnet *NetIPNet) UnmarshalJSON(b []byte) (err error) {
  29. var ipnetStr string
  30. if err = json.Unmarshal(b, &ipnetStr); err == nil {
  31. var cidr *net.IPNet
  32. if _, cidr, err = net.ParseCIDR(ipnetStr); err == nil {
  33. *ipnet = NetIPNet(*cidr)
  34. }
  35. }
  36. return
  37. }
  38. // IndexInfo contains information about a registry
  39. //
  40. // RepositoryInfo Examples:
  41. // {
  42. // "Index" : {
  43. // "Name" : "docker.io",
  44. // "Mirrors" : ["https://registry-2.docker.io/v1/", "https://registry-3.docker.io/v1/"],
  45. // "Secure" : true,
  46. // "Official" : true,
  47. // },
  48. // "RemoteName" : "library/debian",
  49. // "LocalName" : "debian",
  50. // "CanonicalName" : "docker.io/debian"
  51. // "Official" : true,
  52. // }
  53. //
  54. // {
  55. // "Index" : {
  56. // "Name" : "127.0.0.1:5000",
  57. // "Mirrors" : [],
  58. // "Secure" : false,
  59. // "Official" : false,
  60. // },
  61. // "RemoteName" : "user/repo",
  62. // "LocalName" : "127.0.0.1:5000/user/repo",
  63. // "CanonicalName" : "127.0.0.1:5000/user/repo",
  64. // "Official" : false,
  65. // }
  66. type IndexInfo struct {
  67. // Name is the name of the registry, such as "docker.io"
  68. Name string
  69. // Mirrors is a list of mirrors, expressed as URIs
  70. Mirrors []string
  71. // Secure is set to false if the registry is part of the list of
  72. // insecure registries. Insecure registries accept HTTP and/or accept
  73. // HTTPS with certificates from unknown CAs.
  74. Secure bool
  75. // Official indicates whether this is an official registry
  76. Official bool
  77. }
  78. // SearchResult describes a search result returned from a registry
  79. type SearchResult struct {
  80. // StarCount indicates the number of stars this repository has
  81. StarCount int `json:"star_count"`
  82. // IsOfficial is true if the result is from an official repository.
  83. IsOfficial bool `json:"is_official"`
  84. // Name is the name of the repository
  85. Name string `json:"name"`
  86. // IsAutomated indicates whether the result is automated
  87. IsAutomated bool `json:"is_automated"`
  88. // Description is a textual description of the repository
  89. Description string `json:"description"`
  90. }
  91. // SearchResults lists a collection search results returned from a registry
  92. type SearchResults struct {
  93. // Query contains the query string that generated the search results
  94. Query string `json:"query"`
  95. // NumResults indicates the number of results the query returned
  96. NumResults int `json:"num_results"`
  97. // Results is a slice containing the actual results for the search
  98. Results []SearchResult `json:"results"`
  99. }
  100. // DistributionInspect describes the result obtained from contacting the
  101. // registry to retrieve image metadata
  102. type DistributionInspect struct {
  103. // Descriptor contains information about the manifest, including
  104. // the content addressable digest
  105. Descriptor distribution.Descriptor
  106. // Platforms contains the list of platforms supported by the image,
  107. // obtained by parsing the manifest
  108. Platforms []manifestlist.PlatformSpec
  109. }