Skip to content

Commit

Permalink
feat: [PLG-3121] Add support for fetching Docker username for creatin…
Browse files Browse the repository at this point in the history
…g the Docker-Connector from CLI (#63)
  • Loading branch information
neelam-harness authored Jan 5, 2024
1 parent cd1411b commit df35dcc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func applyConnector(c *cli.Context) error {
filePath := c.String("file")
githubUsername := c.String("git-user")
delegateName := c.String("delegate-name")
dockerUsername := c.String("docker-user")
awsCrossAccountRoleArn := c.String("aws-cross-account-role-arn")
awsAccessKey := c.String("aws-access-key")
awsRegion := c.String("cloud-region")
Expand Down Expand Up @@ -56,6 +57,13 @@ func applyConnector(c *cli.Context) error {
}
content = ReplacePlaceholderValues(content, defaults.DELEGATE_NAME_PLACEHOLDER, delegateName)
}
if isDockerConnectorYAML(content) {
if dockerUsername == "" || dockerUsername == defaults.DOCKER_USERNAME_PLACEHOLDER {
dockerUsername = TextInput("Enter a valid docker username:")
}
content = ReplacePlaceholderValues(content, defaults.DOCKER_USERNAME_PLACEHOLDER, dockerUsername)

}
if isAwsConnectorYAML(content) {
if awsCrossAccountRoleArn == "" || awsCrossAccountRoleArn == defaults.AWS_CROSS_ACCOUNT_ROLE_ARN {
awsCrossAccountRoleArn = TextInput("Enter valid aws cross account role arn:")
Expand Down Expand Up @@ -160,6 +168,11 @@ func isK8sConnectorYAML(str string) bool {
match, _ := regexp.MatchString(regexPattern, str)
return match
}
func isDockerConnectorYAML(str string) bool {
regexPattern := `type:\s+DockerRegistry`
match, _ := regexp.MatchString(regexPattern, str)
return match
}

func isAwsConnectorYAML(str string) bool {
regexPattern := `type:\s+Aws`
Expand Down
1 change: 1 addition & 0 deletions defaults/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const CONTENT_TYPE_JSON = "application/json"
const CONTENT_TYPE_YAML = "application/yaml"
const DEFAULT_PROJECT = "default_project"
const DEFAULT_ORG = "default"
const DOCKER_USERNAME_PLACEHOLDER = "DOCKER_USERNAME"
const ENVIRONMENT_ENDPOINT = "environmentsV2"
const GITHUB_SECRET_IDENTIFIER = "harness_gitpat"
const GITOPS_AGENT_IDENTIFIER_PLACEHOLDER = "AGENT_NAME"
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ func main() {
Name: "delegate-name",
Usage: "delegate name for the k8s connector",
},
&cli.StringFlag{
Name: "docker-user",
Usage: "docker username for the docker connector",
},
&cli.StringFlag{
Name: "git-user",
Usage: "git username for the github connector",
Expand Down
3 changes: 1 addition & 2 deletions secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func applySecret(ctx *cli.Context) error {
)

} else {
fmt.Println("createSecretURL: " + createSecretURL)
_, err = client.Post(createSecretURL, shared.CliCdRequestData.AuthToken, secretBody, defaults.CONTENT_TYPE_JSON, nil)
}
if err == nil {
Expand Down Expand Up @@ -286,7 +285,7 @@ func createSecret(orgIdentifier string, projectIdentifier string,

func getSecretIdentifier(secName string) string {
secretIdentifier := ""
reCleaner := regexp.MustCompile(`[^a-zA-Z0-9_]`)
reCleaner := regexp.MustCompile(`[^a-zA-Z0-9_]`)
secretIdentifier = reCleaner.ReplaceAllString(secName, "")
return secretIdentifier
}
Expand Down

0 comments on commit df35dcc

Please sign in to comment.