Skip to content

Commit

Permalink
New Configuration Parameters for gCTS steps (#4214)
Browse files Browse the repository at this point in the history
* Adding new query configuration parameter for gCTS Piper steps

* Add skipSSLVerification parameter to gCTSExecuteQualityChecks

* Add skipSSLVerification to gCTSDeploy

* Add SkipSSLVerification for pull by commit

* Add SkipSSLVerification to rollback

* Add SkipSSLVerification parameter to rollback

* Handling maximum number of charachter for the queryParameter

* Remove extra new lines in yaml files

* Add new line yaml files
  • Loading branch information
rinitagabahri authored Feb 14, 2023
1 parent d7e0bfe commit eecddf6
Show file tree
Hide file tree
Showing 17 changed files with 558 additions and 89 deletions.
6 changes: 6 additions & 0 deletions cmd/gctsCloneRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func cloneRepository(config *gctsCloneRepositoryOptions, telemetryData *telemetr
"/sap/bc/cts_abapvcs/repository/" + config.Repository +
"/clone?sap-client=" + config.Client

url, urlErr := addQueryToURL(url, config.QueryParameters)

if urlErr != nil {

return urlErr
}
resp, httpErr := httpClient.SendRequest("POST", url, nil, header, nil)

defer func() {
Expand Down
31 changes: 26 additions & 5 deletions cmd/gctsCloneRepository_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cmd/gctsCreateRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func createRepository(config *gctsCreateRepositoryOptions, telemetryData *teleme

url := config.Host + "/sap/bc/cts_abapvcs/repository?sap-client=" + config.Client

url, urlErr := addQueryToURL(url, config.QueryParameters)

if urlErr != nil {

return urlErr
}

resp, httpErr := httpClient.SendRequest("POST", url, bytes.NewBuffer(jsonBody), header, nil)

defer func() {
Expand Down
39 changes: 30 additions & 9 deletions cmd/gctsCreateRepository_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 122 additions & 22 deletions cmd/gctsDeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ func gctsDeployRepository(config *gctsDeployOptions, telemetryData *telemetry.Cu
return errors.Wrap(cookieErr, "creating a cookie jar failed")
}
clientOptions := piperhttp.ClientOptions{
CookieJar: cookieJar,
Username: config.Username,
Password: config.Password,
MaxRetries: maxRetries,
CookieJar: cookieJar,
Username: config.Username,
Password: config.Password,
MaxRetries: maxRetries,
TransportSkipVerification: config.SkipSSLVerification,
}
httpClient.SetOptions(clientOptions)
log.Entry().Infof("Start of gCTS Deploy Step with Configuration Values: %v", config)
Expand All @@ -73,6 +74,8 @@ func gctsDeployRepository(config *gctsDeployOptions, telemetryData *telemetry.Cu
Role: config.Role,
VSID: config.VSID,
Type: config.Type,
QueryParameters: config.QueryParameters,
SkipSSLVerification: config.SkipSSLVerification,
}
log.Entry().Infof("gCTS Deploy : Checking if repository %v already exists", config.Repository)
repoMetadataInitState, getRepositoryErr := getRepository(config, httpClient)
Expand All @@ -97,11 +100,13 @@ func gctsDeployRepository(config *gctsDeployOptions, telemetryData *telemetry.Cu
}

cloneRepoOptions := gctsCloneRepositoryOptions{
Username: config.Username,
Password: config.Password,
Repository: config.Repository,
Host: config.Host,
Client: config.Client,
Username: config.Username,
Password: config.Password,
Repository: config.Repository,
Host: config.Host,
Client: config.Client,
QueryParameters: config.QueryParameters,
SkipSSLVerification: config.SkipSSLVerification,
}
// No Import has to be set when there is a commit or branch parameter set
// This is required so that during the clone of the repo it is not imported into the system
Expand Down Expand Up @@ -236,11 +241,12 @@ func pullByCommitWithRollback(config *gctsDeployOptions, telemetryData *telemetr
if config.Rollback {
//Rollback to last commit.
rollbackOptions := gctsRollbackOptions{
Username: config.Username,
Password: config.Password,
Repository: config.Repository,
Host: config.Host,
Client: config.Client,
Username: config.Username,
Password: config.Password,
Repository: config.Repository,
Host: config.Host,
Client: config.Client,
SkipSSLVerification: config.SkipSSLVerification,
}
rollbackErr := rollback(&rollbackOptions, telemetryData, command, httpClient)
if rollbackErr != nil {
Expand Down Expand Up @@ -308,6 +314,14 @@ func switchBranch(config *gctsDeployOptions, httpClient piperhttp.Sender, curren
requestURL := config.Host +
"/sap/bc/cts_abapvcs/repository/" + config.Repository + "/branches/" + currentBranch +
"/switch?branch=" + targetBranch + "&sap-client=" + config.Client

requestURL, urlErr := addQueryToURL(requestURL, config.QueryParameters)

if urlErr != nil {

return nil, urlErr
}

resp, httpErr := httpClient.SendRequest("GET", requestURL, nil, nil, nil)
defer func() {
if resp != nil && resp.Body != nil {
Expand Down Expand Up @@ -340,6 +354,14 @@ func deployCommitToAbapSystem(config *gctsDeployOptions, httpClient piperhttp.Se
requestURL := config.Host +
"/sap/bc/cts_abapvcs/repository/" + config.Repository +
"/deploy?sap-client=" + config.Client

requestURL, urlErr := addQueryToURL(requestURL, config.QueryParameters)

if urlErr != nil {

return urlErr
}

reqBody := deployRequestBody
jsonBody, marshalErr := json.Marshal(reqBody)
if marshalErr != nil {
Expand Down Expand Up @@ -377,6 +399,13 @@ func getRepository(config *gctsDeployOptions, httpClient piperhttp.Sender) (*get
"/sap/bc/cts_abapvcs/repository/" + config.Repository +
"?sap-client=" + config.Client

requestURL, urlErr := addQueryToURL(requestURL, config.QueryParameters)

if urlErr != nil {

return nil, urlErr
}

resp, httpErr := httpClient.SendRequest("GET", requestURL, nil, nil, nil)
defer func() {
if resp != nil && resp.Body != nil {
Expand Down Expand Up @@ -407,6 +436,14 @@ func deleteConfigKey(deployConfig *gctsDeployOptions, httpClient piperhttp.Sende
requestURL := deployConfig.Host +
"/sap/bc/cts_abapvcs/repository/" + deployConfig.Repository +
"/config/" + configToDelete + "?sap-client=" + deployConfig.Client

requestURL, urlErr := addQueryToURL(requestURL, deployConfig.QueryParameters)

if urlErr != nil {

return urlErr
}

header := make(http.Header)
header.Set("Content-Type", "application/json")
header.Add("Accept", "application/json")
Expand Down Expand Up @@ -435,6 +472,13 @@ func setConfigKey(deployConfig *gctsDeployOptions, httpClient piperhttp.Sender,
"/sap/bc/cts_abapvcs/repository/" + deployConfig.Repository +
"/config?sap-client=" + deployConfig.Client

requestURL, urlErr := addQueryToURL(requestURL, deployConfig.QueryParameters)

if urlErr != nil {

return urlErr
}

reqBody := configToSet
jsonBody, marshalErr := json.Marshal(reqBody)
if marshalErr != nil {
Expand Down Expand Up @@ -470,17 +514,25 @@ func pullByCommit(config *gctsDeployOptions, telemetryData *telemetry.CustomData
return errors.Wrap(cookieErr, "creating a cookie jar failed")
}
clientOptions := piperhttp.ClientOptions{
CookieJar: cookieJar,
Username: config.Username,
Password: config.Password,
MaxRetries: -1,
CookieJar: cookieJar,
Username: config.Username,
Password: config.Password,
MaxRetries: -1,
TransportSkipVerification: config.SkipSSLVerification,
}
httpClient.SetOptions(clientOptions)

requestURL := config.Host +
"/sap/bc/cts_abapvcs/repository/" + config.Repository +
"/pullByCommit?sap-client=" + config.Client + "&request=" + config.Commit

requestURL, urlErr := addQueryToURL(requestURL, config.QueryParameters)

if urlErr != nil {

return urlErr
}

if config.Commit != "" {
log.Entry().Infof("preparing to deploy specified commit %v", config.Commit)
params := url.Values{}
Expand Down Expand Up @@ -531,10 +583,11 @@ func createRepositoryForDeploy(config *gctsCreateRepositoryOptions, telemetryDat
return errors.Wrapf(cookieErr, "creating repository on the ABAP system %v failed", config.Host)
}
clientOptions := piperhttp.ClientOptions{
CookieJar: cookieJar,
Username: config.Username,
Password: config.Password,
MaxRetries: -1,
CookieJar: cookieJar,
Username: config.Username,
Password: config.Password,
MaxRetries: -1,
TransportSkipVerification: config.SkipSSLVerification,
}
httpClient.SetOptions(clientOptions)

Expand Down Expand Up @@ -577,6 +630,13 @@ func createRepositoryForDeploy(config *gctsCreateRepositoryOptions, telemetryDat

url := config.Host + "/sap/bc/cts_abapvcs/repository?sap-client=" + config.Client

url, urlErr := addQueryToURL(url, config.QueryParameters)

if urlErr != nil {

return urlErr
}

resp, httpErr := httpClient.SendRequest("POST", url, bytes.NewBuffer(jsonBody), header, nil)

defer func() {
Expand Down Expand Up @@ -618,6 +678,13 @@ func getConfigurationMetadata(config *gctsDeployOptions, httpClient piperhttp.Se
requestURL := config.Host +
"/sap/bc/cts_abapvcs/config?sap-client=" + config.Client

requestURL, urlErr := addQueryToURL(requestURL, config.QueryParameters)

if urlErr != nil {

return nil, urlErr
}

resp, httpErr := httpClient.SendRequest("GET", requestURL, nil, nil, nil)
defer func() {
if resp != nil && resp.Body != nil {
Expand Down Expand Up @@ -705,6 +772,39 @@ func parseErrorDumpFromResponseBody(responseBody *http.Response) (*errorLogBody,
return &errorDump, nil
}

func addQueryToURL(requestURL string, keyValue map[string]interface{}) (string, error) {

var formattedURL string
formattedURL = requestURL
if keyValue != nil {
if strings.Contains(requestURL, "?") {
for key, value := range keyValue {
configValue := fmt.Sprint(value)
formattedURL = formattedURL + "&" + key + "=" + configValue
}
} else {
i := 0
for key, value := range keyValue {
configValue := fmt.Sprint(value)
if i == 0 {
formattedURL = requestURL + "?" + key + "=" + configValue
} else {
formattedURL = formattedURL + "&" + key + "=" + configValue
}
i++
}
}
}
if strings.Count(formattedURL, "") > 2001 {

log.Entry().Error("Url endpoint is longer than 2000 characters!")
return formattedURL, errors.New("Url endpoint is longer than 2000 characters!")

}

return formattedURL, nil
}

type repositoryConfiguration struct {
Key string `json:"key"`
Value string `json:"value"`
Expand Down
Loading

0 comments on commit eecddf6

Please sign in to comment.