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 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,8 +97,23 @@ type PlatformConnectorSpec struct {
ArtifactoryURL string ArtifactoryURL string
// DockerRegistryURL is for DockerRegistryPlatformConnectorType // DockerRegistryURL is for DockerRegistryPlatformConnectorType
DockerRegistryURL string DockerRegistryURL string
AuthSpec PlatformConnectorAuthSpec // AwsCredentials is for AWSPlatformConnectorType
EnabledProxy bool 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 provide auth details.
@ -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: