Skip to content

Commit

Permalink
[feat]: [PLG-2519]: added AWS connector in Harness-CLI (#33)
Browse files Browse the repository at this point in the history
* [feat]: [PLG-2519]: added AWS connector in CLI

* [feat]: [PLG-2519]: incorporating review comments

* [feat]: [PLG-2519]: added a fix
  • Loading branch information
kapil-harness authored Jul 31, 2023
1 parent b38d173 commit 73a78e4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
30 changes: 29 additions & 1 deletion connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func applyConnector(c *cli.Context) error {
filePath := c.String("file")
githubUsername := c.String("git-user")
delegateName := c.String("delegate-name")
awsCrossAccountRoleArn := c.String("aws-cross-account-role-arn")
awsAccessKey := c.String("aws-access-key")
awsSecretKey := c.String("aws-secret-Key")
awsRegion := c.String("region")
baseURL := getNGBaseURL(c)

if filePath == "" {
Expand All @@ -32,7 +36,6 @@ func applyConnector(c *cli.Context) error {
if isGithubConnectorYAML(content) {
if githubUsername == "" || githubUsername == GITHUB_USERNAME_PLACEHOLDER {
githubUsername = TextInput("Enter valid github username:")

}
content = replacePlaceholderValues(content, GITHUB_USERNAME_PLACEHOLDER, githubUsername)
}
Expand All @@ -42,6 +45,25 @@ func applyConnector(c *cli.Context) error {
}
content = replacePlaceholderValues(content, DELEGATE_NAME_PLACEHOLDER, delegateName)
}
if isAwsConnectorYAML(content) {
if awsCrossAccountRoleArn == "" || awsCrossAccountRoleArn == AWS_CROSS_ACCOUNT_ROLE_ARN {
awsCrossAccountRoleArn = TextInput("Enter valid aws cross account role arn:")
}
if awsAccessKey == "" || awsAccessKey == AWS_ACCESS_KEY {
awsAccessKey = TextInput("Enter valid aws access key:")
}
if awsSecretKey == "" || awsSecretKey == AWS_SECRET_KEY {
awsSecretKey = TextInput("Enter valid aws secret key:")
}
if awsRegion == "" || awsRegion == AWS_REGION {
awsSecretKey = TextInput("Enter valid aws region:")
}
//TODO: find a better way to resolve placeholders, dont depend on fixed placeholders
content = replacePlaceholderValues(content, AWS_CROSS_ACCOUNT_ROLE_ARN, awsCrossAccountRoleArn)
content = replacePlaceholderValues(content, AWS_ACCESS_KEY, awsAccessKey)
content = replacePlaceholderValues(content, AWS_SECRET_KEY, awsSecretKey)
content = replacePlaceholderValues(content, AWS_REGION, awsRegion)
}
requestBody := make(map[string]interface{})
if err := yaml.Unmarshal([]byte(content), requestBody); err != nil {
return err
Expand Down Expand Up @@ -90,6 +112,12 @@ func isK8sConnectorYAML(str string) bool {
return match
}

func isAwsConnectorYAML(str string) bool {
regexPattern := `type:\s+Aws`
match, _ := regexp.MatchString(regexPattern, str)
return match
}

// Delete an existing connector
func deleteConnector(*cli.Context) error {
fmt.Println(NOT_IMPLEMENTED)
Expand Down
4 changes: 4 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const PIPELINES_ENDPOINT_V2 = "pipelines/v2"
const SECRETS_STORE_PATH = ".secrets.json"
const SERVICES_ENDPOINT = "servicesV2"
const GITHUB_USERNAME_PLACEHOLDER = "GITHUB_USERNAME"
const AWS_CROSS_ACCOUNT_ROLE_ARN = "ROLE_ARN"
const AWS_ACCESS_KEY = "AWS_ACCESS_KEY"
const AWS_SECRET_KEY = "AWS_PERMANENT_ACCESS_TOKEN"
const AWS_REGION = "REGION_FOR_USERS_ROLES"
const DELEGATE_NAME_PLACEHOLDER = "DELEGATE_NAME"
const GITHUB_PAT_PLACEHOLDER = "GITHUB-PAT"
const HARNESS_PROD_URL = "https://app.harness.io/"
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ func main() {
Name: "git-user",
Usage: "git username for the github connector",
},
&cli.StringFlag{
Name: "aws-cross-account-role-arn",
Usage: "cross account role arn for the aws connector",
},
&cli.StringFlag{
Name: "aws-access-key",
Usage: "access key for the aws connector",
},
&cli.StringFlag{
Name: "aws-secret-Key",
Usage: "access secret for the aws connector",
},
&cli.StringFlag{
Name: "region",
Usage: "region for the aws connector",
},
},
Action: func(context *cli.Context) error {
return cliWrapper(applyConnector, context)
Expand Down

0 comments on commit 73a78e4

Please sign in to comment.