mirror of
https://github.com/harness/drone.git
synced 2025-05-16 00:50:00 +08:00
feat: [CDE-552]: update platform connector type (#3151)
This commit is contained in:
parent
69fa8f06b3
commit
cb275dfafb
@ -14,26 +14,39 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
ecrDockerRegistryFormat = "%s.dkr.ecr.%s.amazonaws.com"
|
||||||
|
|
||||||
UnknownPlatformConnectorType PlatformConnectorType = "Unknown"
|
UnknownPlatformConnectorType PlatformConnectorType = "Unknown"
|
||||||
ArtifactoryPlatformConnectorType PlatformConnectorType = "Artifactory"
|
ArtifactoryPlatformConnectorType PlatformConnectorType = "Artifactory"
|
||||||
DockerRegistryPlatformConnectorType PlatformConnectorType = "DockerRegistry"
|
DockerRegistryPlatformConnectorType PlatformConnectorType = "DockerRegistry"
|
||||||
|
AWSPlatformConnectorType PlatformConnectorType = "Aws"
|
||||||
|
|
||||||
UnknownPlatformConnectorAuthType PlatformConnectorAuthType = "unknown"
|
UnknownPlatformConnectorAuthType PlatformConnectorAuthType = "unknown"
|
||||||
UserNamePasswordPlatformConnectorAuthType PlatformConnectorAuthType = "UsernamePassword"
|
UserNamePasswordPlatformConnectorAuthType PlatformConnectorAuthType = "UsernamePassword"
|
||||||
AnonymousPlatformConnectorAuthType PlatformConnectorAuthType = "Anonymous"
|
AnonymousPlatformConnectorAuthType PlatformConnectorAuthType = "Anonymous"
|
||||||
|
|
||||||
|
UnknownAWSCredentialsType AwsCredentialsType = "unknown"
|
||||||
|
ManualConfigAWSCredentialsType AwsCredentialsType = "ManualConfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
platformConnectorTypeMapping = map[string]PlatformConnectorType{
|
platformConnectorTypeMapping = map[string]PlatformConnectorType{
|
||||||
ArtifactoryPlatformConnectorType.String(): ArtifactoryPlatformConnectorType,
|
ArtifactoryPlatformConnectorType.String(): ArtifactoryPlatformConnectorType,
|
||||||
DockerRegistryPlatformConnectorType.String(): DockerRegistryPlatformConnectorType,
|
DockerRegistryPlatformConnectorType.String(): DockerRegistryPlatformConnectorType,
|
||||||
|
AWSPlatformConnectorType.String(): AWSPlatformConnectorType,
|
||||||
}
|
}
|
||||||
|
|
||||||
platformConnectorAuthTypeMapping = map[string]PlatformConnectorAuthType{
|
platformConnectorAuthTypeMapping = map[string]PlatformConnectorAuthType{
|
||||||
UserNamePasswordPlatformConnectorAuthType.String(): UserNamePasswordPlatformConnectorAuthType,
|
UserNamePasswordPlatformConnectorAuthType.String(): UserNamePasswordPlatformConnectorAuthType,
|
||||||
AnonymousPlatformConnectorAuthType.String(): AnonymousPlatformConnectorAuthType,
|
AnonymousPlatformConnectorAuthType.String(): AnonymousPlatformConnectorAuthType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
awsCredentialsTypeMapping = map[string]AwsCredentialsType{
|
||||||
|
ManualConfigAWSCredentialsType.String(): ManualConfigAWSCredentialsType,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlatformConnectorType string
|
type PlatformConnectorType string
|
||||||
@ -60,6 +73,18 @@ func ToPlatformConnectorAuthType(s string) PlatformConnectorAuthType {
|
|||||||
return UnknownPlatformConnectorAuthType
|
return UnknownPlatformConnectorAuthType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AwsCredentialsType string
|
||||||
|
|
||||||
|
func (t AwsCredentialsType) String() string { return string(t) }
|
||||||
|
|
||||||
|
func ToAwsCredentialsType(s string) AwsCredentialsType {
|
||||||
|
if val, ok := awsCredentialsTypeMapping[s]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
return UnknownAWSCredentialsType
|
||||||
|
}
|
||||||
|
|
||||||
type PlatformConnector struct {
|
type PlatformConnector struct {
|
||||||
ID string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
@ -72,10 +97,25 @@ type PlatformConnectorSpec struct {
|
|||||||
ArtifactoryURL string
|
ArtifactoryURL string
|
||||||
// DockerRegistryURL is for DockerRegistryPlatformConnectorType
|
// DockerRegistryURL is for DockerRegistryPlatformConnectorType
|
||||||
DockerRegistryURL string
|
DockerRegistryURL string
|
||||||
|
// AwsCredentials is for AWSPlatformConnectorType
|
||||||
|
AwsCredentials AwsCredentials
|
||||||
|
// AuthSpec is for ArtifactoryPlatformConnectorType and DockerRegistryPlatformConnectorType
|
||||||
AuthSpec PlatformConnectorAuthSpec
|
AuthSpec PlatformConnectorAuthSpec
|
||||||
EnabledProxy bool
|
EnabledProxy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AwsCredentials struct {
|
||||||
|
Type AwsCredentialsType
|
||||||
|
Region string
|
||||||
|
AccountID string
|
||||||
|
AccessKey MaskSecret
|
||||||
|
AccessKeyRef string
|
||||||
|
SecretKeyRef string
|
||||||
|
SecretKey MaskSecret
|
||||||
|
SessionTokenRef string
|
||||||
|
SessionToken MaskSecret
|
||||||
|
}
|
||||||
|
|
||||||
// PlatformConnectorAuthSpec provide auth details.
|
// PlatformConnectorAuthSpec provide auth details.
|
||||||
// PlatformConnectorAuthSpec is empty for AnonymousPlatformConnectorAuthType.
|
// PlatformConnectorAuthSpec is empty for AnonymousPlatformConnectorAuthType.
|
||||||
type PlatformConnectorAuthSpec struct {
|
type PlatformConnectorAuthSpec struct {
|
||||||
@ -94,6 +134,8 @@ func (c PlatformConnectorSpec) ExtractRegistryURL() string {
|
|||||||
return c.DockerRegistryURL
|
return c.DockerRegistryURL
|
||||||
case ArtifactoryPlatformConnectorType:
|
case ArtifactoryPlatformConnectorType:
|
||||||
return c.ArtifactoryURL
|
return c.ArtifactoryURL
|
||||||
|
case AWSPlatformConnectorType:
|
||||||
|
return fmt.Sprintf(ecrDockerRegistryFormat, c.AwsCredentials.AccountID, c.AwsCredentials.Region)
|
||||||
case UnknownPlatformConnectorType:
|
case UnknownPlatformConnectorType:
|
||||||
return ""
|
return ""
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user