forked from harness/harness-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipelines.go
79 lines (70 loc) · 2.66 KB
/
pipelines.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
)
// create or update Pipeline
func applyPipeline(c *cli.Context) error {
filePath := c.String("file")
baseURL := getPipelineSVCBaseURL(c)
if filePath == "" {
fmt.Println("Please enter valid filename")
return nil
}
fmt.Println("Trying to create or update pipeline using the yaml=",
getColoredText(filePath, color.FgCyan))
var content = readFromFile(c.String("file"))
requestBody := getJsonFromYaml(content)
if requestBody == nil {
println(getColoredText("Please enter valid pipeline yaml file", color.FgRed))
}
identifier := valueToString(GetNestedValue(requestBody, "pipeline", "identifier").(string))
projectIdentifier := valueToString(GetNestedValue(requestBody, "pipeline", "projectIdentifier").(string))
orgIdentifier := valueToString(GetNestedValue(requestBody, "pipeline", "orgIdentifier").(string))
createOrUpdatePipelineURL := GetUrlWithQueryParams("", baseURL, PIPELINES_ENDPOINT_V2, map[string]string{
"accountIdentifier": cliCdRequestData.Account,
"orgIdentifier": orgIdentifier,
"projectIdentifier": projectIdentifier,
})
entityExists := getEntity(baseURL, fmt.Sprintf("%s/%s", PIPELINES_ENDPOINT, identifier),
projectIdentifier, orgIdentifier, map[string]string{})
var _ ResponseBody
var err error
if !entityExists {
println("Creating pipeline with id: ", getColoredText(identifier, color.FgGreen))
_, err = Post(createOrUpdatePipelineURL, cliCdRequestData.AuthToken, requestBody, CONTENT_TYPE_YAML)
if err == nil {
println(getColoredText("Successfully created pipeline with id= ", color.FgGreen) +
getColoredText(identifier, color.FgBlue))
return nil
}
} else {
var pipelinesPUTUrl = GetUrlWithQueryParams("", baseURL,
fmt.Sprintf("%s/%s", PIPELINES_ENDPOINT_V2, identifier), map[string]string{
"pipelineIdentifier": identifier,
"accountIdentifier": cliCdRequestData.Account,
"orgIdentifier": orgIdentifier,
"projectIdentifier": projectIdentifier,
})
println("Found pipeline with id=", getColoredText(identifier, color.FgCyan))
println("Updating details of pipeline with id=", getColoredText(identifier, color.FgBlue))
_, err = Put(pipelinesPUTUrl, cliCdRequestData.AuthToken, requestBody, CONTENT_TYPE_YAML)
if err == nil {
println(getColoredText("Successfully updated pipeline with id= ", color.FgGreen) +
getColoredText(identifier, color.FgBlue))
return nil
}
}
return nil
}
// Delete an existing Pipeline
func deletePipeline(*cli.Context) error {
fmt.Println(NOT_IMPLEMENTED)
return nil
}
// Delete an existing Pipeline
func listPipeline(*cli.Context) error {
fmt.Println(NOT_IMPLEMENTED)
return nil
}