/src/replication/model/registry.go

https://github.com/goharbor/harbor · Go · 197 lines · 115 code · 28 blank · 54 comment · 0 complexity · d3acd41f3007f4cfe56b5d7528453774 MD5 · raw file

  1. // Copyright Project Harbor Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package model
  15. import (
  16. "time"
  17. )
  18. // const definition
  19. const (
  20. RegistryTypeHarbor RegistryType = "harbor"
  21. RegistryTypeDockerHub RegistryType = "docker-hub"
  22. RegistryTypeDockerRegistry RegistryType = "docker-registry"
  23. RegistryTypeHuawei RegistryType = "huawei-SWR"
  24. RegistryTypeGoogleGcr RegistryType = "google-gcr"
  25. RegistryTypeAwsEcr RegistryType = "aws-ecr"
  26. RegistryTypeAzureAcr RegistryType = "azure-acr"
  27. RegistryTypeAliAcr RegistryType = "ali-acr"
  28. RegistryTypeJfrogArtifactory RegistryType = "jfrog-artifactory"
  29. RegistryTypeQuay RegistryType = "quay"
  30. RegistryTypeGitLab RegistryType = "gitlab"
  31. RegistryTypeHelmHub RegistryType = "helm-hub"
  32. FilterStyleTypeText = "input"
  33. FilterStyleTypeRadio = "radio"
  34. FilterStyleTypeList = "list"
  35. )
  36. // RegistryType indicates the type of registry
  37. type RegistryType string
  38. // CredentialType represents the supported credential types
  39. // e.g: u/p, OAuth token
  40. type CredentialType string
  41. // const definitions
  42. const (
  43. // CredentialTypeBasic indicates credential by user name, password
  44. CredentialTypeBasic = "basic"
  45. // CredentialTypeOAuth indicates credential by OAuth token
  46. CredentialTypeOAuth = "oauth"
  47. // CredentialTypeSecret is only used by the communication of Harbor internal components
  48. CredentialTypeSecret = "secret"
  49. )
  50. // Credential keeps the access key and/or secret for the related registry
  51. type Credential struct {
  52. // Type of the credential
  53. Type CredentialType `json:"type"`
  54. // The key of the access account, for OAuth token, it can be empty
  55. AccessKey string `json:"access_key"`
  56. // The secret or password for the key
  57. AccessSecret string `json:"access_secret"`
  58. }
  59. // HealthStatus describes whether a target is healthy or not
  60. type HealthStatus string
  61. const (
  62. // Healthy indicates registry is healthy
  63. Healthy = "healthy"
  64. // Unhealthy indicates registry is unhealthy
  65. Unhealthy = "unhealthy"
  66. // Unknown indicates health status of registry is unknown
  67. Unknown = "unknown"
  68. )
  69. // TODO add validation for Registry
  70. // Registry keeps the related info of registry
  71. // Data required for the secure access way is not contained here.
  72. // DAO layer is not considered here
  73. type Registry struct {
  74. ID int64 `json:"id"`
  75. Name string `json:"name"`
  76. Description string `json:"description"`
  77. Type RegistryType `json:"type"`
  78. URL string `json:"url"`
  79. // TokenServiceURL is only used for local harbor instance to
  80. // avoid the requests passing through the external proxy for now
  81. TokenServiceURL string `json:"token_service_url"`
  82. Credential *Credential `json:"credential"`
  83. Insecure bool `json:"insecure"`
  84. Status string `json:"status"`
  85. CreationTime time.Time `json:"creation_time"`
  86. UpdateTime time.Time `json:"update_time"`
  87. }
  88. // FilterStyle ...
  89. type FilterStyle struct {
  90. Type FilterType `json:"type"`
  91. Style string `json:"style"`
  92. Values []string `json:"values,omitempty"`
  93. }
  94. // EndpointPattern ...
  95. type EndpointPattern struct {
  96. EndpointType EndpointType `json:"endpoint_type"`
  97. Endpoints []*Endpoint `json:"endpoints"`
  98. }
  99. // EndpointType ..
  100. type EndpointType string
  101. const (
  102. // EndpointPatternTypeStandard ...
  103. EndpointPatternTypeStandard EndpointType = "EndpointPatternTypeStandard"
  104. // EndpointPatternTypeFix ...
  105. EndpointPatternTypeFix EndpointType = "EndpointPatternTypeFix"
  106. // EndpointPatternTypeList ...
  107. EndpointPatternTypeList EndpointType = "EndpointPatternTypeList"
  108. )
  109. // Endpoint ...
  110. type Endpoint struct {
  111. Key string `json:"key"`
  112. Value string `json:"value"`
  113. }
  114. // CredentialPattern ...
  115. type CredentialPattern struct {
  116. AccessKeyType AccessKeyType `json:"access_key_type"`
  117. AccessKeyData string `json:"access_key_data"`
  118. AccessSecretType AccessSecretType `json:"access_secret_type"`
  119. AccessSecretData string `json:"access_secret_data"`
  120. }
  121. // AccessKeyType ..
  122. type AccessKeyType string
  123. const (
  124. // AccessKeyTypeStandard ...
  125. AccessKeyTypeStandard AccessKeyType = "AccessKeyTypeStandard"
  126. // AccessKeyTypeFix ...
  127. AccessKeyTypeFix AccessKeyType = "AccessKeyTypeFix"
  128. )
  129. // AccessSecretType ...
  130. type AccessSecretType string
  131. const (
  132. // AccessSecretTypeStandard ...
  133. AccessSecretTypeStandard AccessSecretType = "AccessSecretTypePass"
  134. // AccessSecretTypeFile ...
  135. AccessSecretTypeFile AccessSecretType = "AccessSecretTypeFile"
  136. )
  137. // RegistryInfo provides base info and capability declarations of the registry
  138. type RegistryInfo struct {
  139. Type RegistryType `json:"type"`
  140. Description string `json:"description"`
  141. SupportedResourceTypes []ResourceType `json:"-"`
  142. SupportedResourceFilters []*FilterStyle `json:"supported_resource_filters"`
  143. SupportedTriggers []TriggerType `json:"supported_triggers"`
  144. }
  145. // AdapterPattern provides base info and capability declarations of the registry
  146. type AdapterPattern struct {
  147. EndpointPattern *EndpointPattern `json:"endpoint_pattern"`
  148. CredentialPattern *CredentialPattern `json:"credential_pattern"`
  149. }
  150. // NewDefaultAdapterPattern ...
  151. func NewDefaultAdapterPattern() *AdapterPattern {
  152. return &AdapterPattern{
  153. EndpointPattern: NewDefaultEndpointPattern(),
  154. CredentialPattern: NewDefaultCredentialPattern(),
  155. }
  156. }
  157. // NewDefaultEndpointPattern ...
  158. func NewDefaultEndpointPattern() *EndpointPattern {
  159. return &EndpointPattern{
  160. EndpointType: EndpointPatternTypeStandard,
  161. }
  162. }
  163. // NewDefaultCredentialPattern ...
  164. func NewDefaultCredentialPattern() *CredentialPattern {
  165. return &CredentialPattern{
  166. AccessKeyType: AccessKeyTypeStandard,
  167. AccessSecretType: AccessSecretTypeStandard,
  168. }
  169. }