registry.go 3.1 KB

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