Skip to content

Commit

Permalink
feat: [PLG-3017] Adding support for org and project flags in the cd-g…
Browse files Browse the repository at this point in the history
…itops flow (#57)
  • Loading branch information
neelam-harness authored Dec 20, 2023
1 parent 56bf8ca commit 0fa3475
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
11 changes: 9 additions & 2 deletions gitops-application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))

Expand Down
11 changes: 9 additions & 2 deletions gitops-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
18 changes: 14 additions & 4 deletions gitops-repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ 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 = ""

// 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")
Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0fa3475

Please sign in to comment.