diff --git a/gitops-application.go b/gitops-application.go index 9765423..5e5d4b9 100644 --- a/gitops-application.go +++ b/gitops-application.go @@ -15,6 +15,9 @@ import ( func applyGitopsApplications(c *cli.Context) error { filePath := c.String("file") + orgIdentifier := c.String("org-id") + projectIdentifier := c.String("project-id") + baseURL := GetBaseUrl(c, defaults.GITOPS_BASE_URL) if filePath == "" { fmt.Println("Please enter valid filename") @@ -33,8 +36,12 @@ func applyGitopsApplications(c *cli.Context) error { if requestBody == nil { println(GetColoredText("Please enter valid repository yaml file", color.FgRed)) } - orgIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "orgIdentifier").(string)) - projectIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "projectIdentifier").(string)) + if orgIdentifier == "" { + orgIdentifier = ValueToString(GetNestedValue(requestBody, "gitops", "orgIdentifier").(string)) + } + if projectIdentifier == "" { + projectIdentifier = ValueToString(GetNestedValue(requestBody, "gitops", "projectIdentifier").(string)) + } clusterIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "clusterIdentifier").(string)) repoIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "repoIdentifier").(string)) diff --git a/gitops-cluster.go b/gitops-cluster.go index 9a1ab54..570a1b0 100644 --- a/gitops-cluster.go +++ b/gitops-cluster.go @@ -16,6 +16,9 @@ import ( // create or update a Gitops Cluster func applyCluster(c *cli.Context) error { filePath := c.String("file") + orgIdentifier := c.String("org-id") + projectIdentifier := c.String("project-id") + baseURL := GetBaseUrl(c, defaults.GITOPS_BASE_URL) if filePath == "" { fmt.Println("Please enter valid filename") @@ -35,11 +38,15 @@ func applyCluster(c *cli.Context) error { println(GetColoredText("Please enter valid cluster yaml file", color.FgRed)) } identifier := ValueToString(GetNestedValue(requestBody, "gitops", "identifier").(string)) - projectIdentifier := c.String("project") + if projectIdentifier == "" { projectIdentifier = ValueToString(GetNestedValue(requestBody, "gitops", "projectIdentifier").(string)) } - orgIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "orgIdentifier").(string)) + + if orgIdentifier == "" { + orgIdentifier = ValueToString(GetNestedValue(requestBody, "gitops", "orgIdentifier").(string)) + } + createOrUpdateClusterURL := GetUrlWithQueryParams("", baseURL, defaults.GITOPS_CLUSTER_ENDPOINT, map[string]string{ "identifier": identifier, "accountIdentifier": shared.CliCdRequestData.Account, diff --git a/gitops-repository.go b/gitops-repository.go index 3157397..9640be4 100644 --- a/gitops-repository.go +++ b/gitops-repository.go @@ -2,14 +2,15 @@ package main import ( "fmt" - "github.com/fatih/color" - "github.com/urfave/cli/v2" "harness/client" "harness/defaults" "harness/shared" "harness/telemetry" . "harness/types" . "harness/utils" + + "github.com/fatih/color" + "github.com/urfave/cli/v2" ) var agentIdentifier = "" @@ -17,6 +18,9 @@ var agentIdentifier = "" // create or update a Gitops Repository func applyRepository(c *cli.Context) error { filePath := c.String("file") + orgIdentifier := c.String("org-id") + projectIdentifier := c.String("project-id") + baseURL := GetBaseUrl(c, defaults.GITOPS_BASE_URL) if filePath == "" { fmt.Println("Please enter valid filename") @@ -36,8 +40,14 @@ func applyRepository(c *cli.Context) error { println(GetColoredText("Please enter valid repository yaml file", color.FgRed)) } identifier := ValueToString(GetNestedValue(requestBody, "gitops", "identifier").(string)) - projectIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "projectIdentifier").(string)) - orgIdentifier := ValueToString(GetNestedValue(requestBody, "gitops", "orgIdentifier").(string)) + if projectIdentifier == "" { + projectIdentifier = ValueToString(GetNestedValue(requestBody, "gitops", "projectIdentifier").(string)) + } + + if orgIdentifier == "" { + orgIdentifier = ValueToString(GetNestedValue(requestBody, "gitops", "orgIdentifier").(string)) + } + createOrUpdateRepositoryURL := GetUrlWithQueryParams("", baseURL, defaults.GITOPS_REPOSITORY_ENDPOINT, map[string]string{ "identifier": identifier, "accountIdentifier": shared.CliCdRequestData.Account, diff --git a/main.go b/main.go index 17d7d97..ffd7a36 100644 --- a/main.go +++ b/main.go @@ -355,6 +355,14 @@ func main() { Name: "agent-identifier", Usage: "provide GitOps Agent Identifier.", }, + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "org-id", + Usage: "provide an Organization Identifier", + }), + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "project-id", + Usage: "provide a Project Identifier", + }), }, Action: func(context *cli.Context) error { return cliWrapper(applyGitopsApplications, context) @@ -385,6 +393,14 @@ func main() { Name: "agent-identifier", Usage: "provide GitOps Agent Identifier.", }, + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "org-id", + Usage: "provide an Organization Identifier", + }), + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "project-id", + Usage: "provide a Project Identifier", + }), }, Action: func(context *cli.Context) error { return cliWrapper(applyCluster, context) @@ -415,6 +431,14 @@ func main() { Name: "agent-identifier", Usage: "provide GitOps Agent Identifier.", }, + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "org-id", + Usage: "provide an Organization Identifier", + }), + altsrc.NewStringFlag(&cli.StringFlag{ + Name: "project-id", + Usage: "provide a Project Identifier", + }), }, Action: func(context *cli.Context) error { return cliWrapper(applyRepository, context)