feat: [CDE-552]: update platform connector type (#3151)

This commit is contained in:
Deepak Bhatt 2024-12-12 05:25:16 +00:00 committed by Harness
parent 69fa8f06b3
commit cb275dfafb

View File

@ -14,26 +14,39 @@
package types
import "fmt"
const (
ecrDockerRegistryFormat = "%s.dkr.ecr.%s.amazonaws.com"
UnknownPlatformConnectorType PlatformConnectorType = "Unknown"
ArtifactoryPlatformConnectorType PlatformConnectorType = "Artifactory"
DockerRegistryPlatformConnectorType PlatformConnectorType = "DockerRegistry"
AWSPlatformConnectorType PlatformConnectorType = "Aws"
UnknownPlatformConnectorAuthType PlatformConnectorAuthType = "unknown"
UserNamePasswordPlatformConnectorAuthType PlatformConnectorAuthType = "UsernamePassword"
AnonymousPlatformConnectorAuthType PlatformConnectorAuthType = "Anonymous"
UnknownAWSCredentialsType AwsCredentialsType = "unknown"
ManualConfigAWSCredentialsType AwsCredentialsType = "ManualConfig"
)
var (
platformConnectorTypeMapping = map[string]PlatformConnectorType{
ArtifactoryPlatformConnectorType.String(): ArtifactoryPlatformConnectorType,
DockerRegistryPlatformConnectorType.String(): DockerRegistryPlatformConnectorType,
AWSPlatformConnectorType.String(): AWSPlatformConnectorType,
}
platformConnectorAuthTypeMapping = map[string]PlatformConnectorAuthType{
UserNamePasswordPlatformConnectorAuthType.String(): UserNamePasswordPlatformConnectorAuthType,
AnonymousPlatformConnectorAuthType.String(): AnonymousPlatformConnectorAuthType,
}
awsCredentialsTypeMapping = map[string]AwsCredentialsType{
ManualConfigAWSCredentialsType.String(): ManualConfigAWSCredentialsType,
}
)
type PlatformConnectorType string
@ -60,6 +73,18 @@ func ToPlatformConnectorAuthType(s string) PlatformConnectorAuthType {
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 {
ID string
Name string
@ -72,10 +97,25 @@ type PlatformConnectorSpec struct {
ArtifactoryURL string
// DockerRegistryURL is for DockerRegistryPlatformConnectorType
DockerRegistryURL string
// AwsCredentials is for AWSPlatformConnectorType
AwsCredentials AwsCredentials
// AuthSpec is for ArtifactoryPlatformConnectorType and DockerRegistryPlatformConnectorType
AuthSpec PlatformConnectorAuthSpec
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 is empty for AnonymousPlatformConnectorAuthType.
type PlatformConnectorAuthSpec struct {
@ -94,6 +134,8 @@ func (c PlatformConnectorSpec) ExtractRegistryURL() string {
return c.DockerRegistryURL
case ArtifactoryPlatformConnectorType:
return c.ArtifactoryURL
case AWSPlatformConnectorType:
return fmt.Sprintf(ecrDockerRegistryFormat, c.AwsCredentials.AccountID, c.AwsCredentials.Region)
case UnknownPlatformConnectorType:
return ""
default: