2019-01-22 10:02:45 +01:00
|
|
|
// Copyright Project Harbor Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
2019-01-25 06:22:37 +01:00
|
|
|
import (
|
2019-02-14 07:55:03 +01:00
|
|
|
"time"
|
2019-01-25 06:22:37 +01:00
|
|
|
)
|
|
|
|
|
2019-03-23 00:26:10 +01:00
|
|
|
// const definition
|
2019-02-14 07:55:03 +01:00
|
|
|
const (
|
2019-10-08 03:54:28 +02:00
|
|
|
RegistryTypeHarbor RegistryType = "harbor"
|
|
|
|
RegistryTypeDockerHub RegistryType = "docker-hub"
|
|
|
|
RegistryTypeDockerRegistry RegistryType = "docker-registry"
|
|
|
|
RegistryTypeHuawei RegistryType = "huawei-SWR"
|
|
|
|
RegistryTypeGoogleGcr RegistryType = "google-gcr"
|
|
|
|
RegistryTypeAwsEcr RegistryType = "aws-ecr"
|
|
|
|
RegistryTypeAzureAcr RegistryType = "azure-acr"
|
|
|
|
RegistryTypeAliAcr RegistryType = "ali-acr"
|
|
|
|
RegistryTypeJfrogArtifactory RegistryType = "jfrog-artifactory"
|
2020-01-13 08:15:02 +01:00
|
|
|
RegistryTypeQuay RegistryType = "quay"
|
2019-10-16 08:34:21 +02:00
|
|
|
RegistryTypeGitLab RegistryType = "gitlab"
|
2020-10-29 11:54:44 +01:00
|
|
|
RegistryTypeDTR RegistryType = "dtr"
|
2019-03-23 00:26:10 +01:00
|
|
|
|
2019-07-09 05:15:29 +02:00
|
|
|
RegistryTypeHelmHub RegistryType = "helm-hub"
|
|
|
|
|
2019-03-23 00:26:10 +01:00
|
|
|
FilterStyleTypeText = "input"
|
|
|
|
FilterStyleTypeRadio = "radio"
|
2019-06-04 07:40:36 +02:00
|
|
|
FilterStyleTypeList = "list"
|
2019-02-14 07:55:03 +01:00
|
|
|
)
|
|
|
|
|
2019-03-04 11:33:20 +01:00
|
|
|
// RegistryType indicates the type of registry
|
|
|
|
type RegistryType string
|
2019-01-25 06:22:37 +01:00
|
|
|
|
2019-01-22 10:02:45 +01:00
|
|
|
// CredentialType represents the supported credential types
|
|
|
|
// e.g: u/p, OAuth token
|
|
|
|
type CredentialType string
|
|
|
|
|
2019-04-01 04:39:11 +02:00
|
|
|
// const definitions
|
2019-02-14 07:55:03 +01:00
|
|
|
const (
|
|
|
|
// CredentialTypeBasic indicates credential by user name, password
|
|
|
|
CredentialTypeBasic = "basic"
|
|
|
|
// CredentialTypeOAuth indicates credential by OAuth token
|
|
|
|
CredentialTypeOAuth = "oauth"
|
2019-04-01 04:39:11 +02:00
|
|
|
// CredentialTypeSecret is only used by the communication of Harbor internal components
|
|
|
|
CredentialTypeSecret = "secret"
|
2019-02-14 07:55:03 +01:00
|
|
|
)
|
|
|
|
|
2019-01-22 10:02:45 +01:00
|
|
|
// Credential keeps the access key and/or secret for the related registry
|
|
|
|
type Credential struct {
|
|
|
|
// Type of the credential
|
|
|
|
Type CredentialType `json:"type"`
|
|
|
|
// The key of the access account, for OAuth token, it can be empty
|
|
|
|
AccessKey string `json:"access_key"`
|
|
|
|
// The secret or password for the key
|
|
|
|
AccessSecret string `json:"access_secret"`
|
|
|
|
}
|
|
|
|
|
2019-04-06 12:05:38 +02:00
|
|
|
// HealthStatus describes whether a target is healthy or not
|
|
|
|
type HealthStatus string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Healthy indicates registry is healthy
|
|
|
|
Healthy = "healthy"
|
|
|
|
// Unhealthy indicates registry is unhealthy
|
|
|
|
Unhealthy = "unhealthy"
|
|
|
|
// Unknown indicates health status of registry is unknown
|
|
|
|
Unknown = "unknown"
|
|
|
|
)
|
|
|
|
|
2019-03-04 04:51:34 +01:00
|
|
|
// TODO add validation for Registry
|
|
|
|
|
2019-01-22 10:02:45 +01:00
|
|
|
// Registry keeps the related info of registry
|
|
|
|
// Data required for the secure access way is not contained here.
|
|
|
|
// DAO layer is not considered here
|
|
|
|
type Registry struct {
|
2019-04-01 04:39:11 +02:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Type RegistryType `json:"type"`
|
|
|
|
URL string `json:"url"`
|
2019-04-28 11:22:55 +02:00
|
|
|
// TokenServiceURL is only used for local harbor instance to
|
|
|
|
// avoid the requests passing through the external proxy for now
|
|
|
|
TokenServiceURL string `json:"token_service_url"`
|
|
|
|
Credential *Credential `json:"credential"`
|
|
|
|
Insecure bool `json:"insecure"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
CreationTime time.Time `json:"creation_time"`
|
|
|
|
UpdateTime time.Time `json:"update_time"`
|
2019-01-22 10:02:45 +01:00
|
|
|
}
|
2019-01-25 06:22:37 +01:00
|
|
|
|
2019-03-23 00:26:10 +01:00
|
|
|
// FilterStyle ...
|
|
|
|
type FilterStyle struct {
|
|
|
|
Type FilterType `json:"type"`
|
|
|
|
Style string `json:"style"`
|
|
|
|
Values []string `json:"values,omitempty"`
|
|
|
|
}
|
|
|
|
|
2019-10-22 11:53:53 +02:00
|
|
|
// EndpointPattern ...
|
|
|
|
type EndpointPattern struct {
|
|
|
|
EndpointType EndpointType `json:"endpoint_type"`
|
|
|
|
Endpoints []*Endpoint `json:"endpoints"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// EndpointType ..
|
|
|
|
type EndpointType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// EndpointPatternTypeStandard ...
|
|
|
|
EndpointPatternTypeStandard EndpointType = "EndpointPatternTypeStandard"
|
|
|
|
// EndpointPatternTypeFix ...
|
|
|
|
EndpointPatternTypeFix EndpointType = "EndpointPatternTypeFix"
|
|
|
|
// EndpointPatternTypeList ...
|
|
|
|
EndpointPatternTypeList EndpointType = "EndpointPatternTypeList"
|
|
|
|
)
|
|
|
|
|
2019-07-01 04:46:44 +02:00
|
|
|
// Endpoint ...
|
|
|
|
type Endpoint struct {
|
|
|
|
Key string `json:"key"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
2019-10-22 11:53:53 +02:00
|
|
|
// CredentialPattern ...
|
|
|
|
type CredentialPattern struct {
|
2019-07-01 04:46:44 +02:00
|
|
|
AccessKeyType AccessKeyType `json:"access_key_type"`
|
|
|
|
AccessKeyData string `json:"access_key_data"`
|
|
|
|
AccessSecretType AccessSecretType `json:"access_secret_type"`
|
|
|
|
AccessSecretData string `json:"access_secret_data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccessKeyType ..
|
|
|
|
type AccessKeyType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// AccessKeyTypeStandard ...
|
|
|
|
AccessKeyTypeStandard AccessKeyType = "AccessKeyTypeStandard"
|
|
|
|
// AccessKeyTypeFix ...
|
|
|
|
AccessKeyTypeFix AccessKeyType = "AccessKeyTypeFix"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AccessSecretType ...
|
|
|
|
type AccessSecretType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// AccessSecretTypeStandard ...
|
|
|
|
AccessSecretTypeStandard AccessSecretType = "AccessSecretTypePass"
|
|
|
|
// AccessSecretTypeFile ...
|
|
|
|
AccessSecretTypeFile AccessSecretType = "AccessSecretTypeFile"
|
|
|
|
)
|
|
|
|
|
2019-03-23 00:26:10 +01:00
|
|
|
// RegistryInfo provides base info and capability declarations of the registry
|
|
|
|
type RegistryInfo struct {
|
2019-10-22 11:53:53 +02:00
|
|
|
Type RegistryType `json:"type"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
SupportedResourceTypes []ResourceType `json:"-"`
|
|
|
|
SupportedResourceFilters []*FilterStyle `json:"supported_resource_filters"`
|
|
|
|
SupportedTriggers []TriggerType `json:"supported_triggers"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// AdapterPattern provides base info and capability declarations of the registry
|
|
|
|
type AdapterPattern struct {
|
|
|
|
EndpointPattern *EndpointPattern `json:"endpoint_pattern"`
|
|
|
|
CredentialPattern *CredentialPattern `json:"credential_pattern"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDefaultAdapterPattern ...
|
|
|
|
func NewDefaultAdapterPattern() *AdapterPattern {
|
|
|
|
return &AdapterPattern{
|
|
|
|
EndpointPattern: NewDefaultEndpointPattern(),
|
|
|
|
CredentialPattern: NewDefaultCredentialPattern(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDefaultEndpointPattern ...
|
|
|
|
func NewDefaultEndpointPattern() *EndpointPattern {
|
|
|
|
return &EndpointPattern{
|
|
|
|
EndpointType: EndpointPatternTypeStandard,
|
|
|
|
}
|
2019-07-01 04:46:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-22 11:53:53 +02:00
|
|
|
// NewDefaultCredentialPattern ...
|
|
|
|
func NewDefaultCredentialPattern() *CredentialPattern {
|
|
|
|
return &CredentialPattern{
|
|
|
|
AccessKeyType: AccessKeyTypeStandard,
|
|
|
|
AccessSecretType: AccessSecretTypeStandard,
|
|
|
|
}
|
2019-03-23 00:26:10 +01:00
|
|
|
}
|