mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-20 05:19:40 +02:00
Host parameter fix (#1752)
This commit is contained in:
parent
9fbf3c9dbd
commit
509607f69f
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -165,7 +166,15 @@ func getAbapCommunicationArrangementInfo(config abapEnvironmentPullGitRepoOption
|
||||
|
||||
if config.Host != "" {
|
||||
// Host, User and Password are directly provided
|
||||
connectionDetails.URL = "https://" + config.Host + "/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/Pull"
|
||||
matchedkey, error := regexp.MatchString(`^[hH][tT][tT][pP][sS]:\/\/.*`, config.Host)
|
||||
if error != nil {
|
||||
return connectionDetails, errors.New("Error occured while parsing the host parameter. Please check if this parameter has been seet correctly")
|
||||
}
|
||||
if matchedkey {
|
||||
connectionDetails.URL = config.Host + "/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/Pull"
|
||||
} else {
|
||||
connectionDetails.URL = "https://" + config.Host + "/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/Pull"
|
||||
}
|
||||
connectionDetails.User = config.Username
|
||||
connectionDetails.Password = config.Password
|
||||
} else {
|
||||
|
@ -139,7 +139,7 @@ func abapEnvironmentPullGitRepoMetadata() config.StepData {
|
||||
{
|
||||
Name: "host",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
|
@ -171,6 +171,40 @@ func TestGetAbapCommunicationArrangementInfo(t *testing.T) {
|
||||
assert.Equal(t, []string{"login", "-a", "https://api.endpoint.com", "-u", "testUser", "-p", "testPassword", "-o", "testOrg", "-s", "testSpace"}, execRunner.Calls[0].Params, "Wrong parameters")
|
||||
})
|
||||
|
||||
t.Run("Test host prefix: with https", func(t *testing.T) {
|
||||
|
||||
config := abapEnvironmentPullGitRepoOptions{
|
||||
Host: "test.host.com",
|
||||
Username: "testUser",
|
||||
Password: "testPassword",
|
||||
}
|
||||
execRunner := mock.ExecMockRunner{}
|
||||
|
||||
con, err := getAbapCommunicationArrangementInfo(config, &execRunner)
|
||||
if err == nil {
|
||||
assert.Equal(t, "testUser", con.User)
|
||||
assert.Equal(t, "testPassword", con.Password)
|
||||
assert.Equal(t, "https://test.host.com/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/Pull", con.URL)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Test host prefix: with https", func(t *testing.T) {
|
||||
|
||||
config := abapEnvironmentPullGitRepoOptions{
|
||||
Host: "https://test.host.com",
|
||||
Username: "testUser",
|
||||
Password: "testPassword",
|
||||
}
|
||||
execRunner := mock.ExecMockRunner{}
|
||||
|
||||
con, err := getAbapCommunicationArrangementInfo(config, &execRunner)
|
||||
if err == nil {
|
||||
assert.Equal(t, "testUser", con.User)
|
||||
assert.Equal(t, "testPassword", con.Password)
|
||||
assert.Equal(t, "https://test.host.com/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/Pull", con.URL)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Test cf cli command: params missing", func(t *testing.T) {
|
||||
|
||||
config := abapEnvironmentPullGitRepoOptions{
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -241,7 +242,15 @@ func checkHost(config abapEnvironmentRunATCCheckOptions, details connectionDetai
|
||||
}
|
||||
details.User = config.Username
|
||||
details.Password = config.Password
|
||||
details.URL = config.Host
|
||||
matchedkey, err := regexp.MatchString(`^[hH][tT][tT][pP][sS]:\/\/.*`, config.Host)
|
||||
if err != nil {
|
||||
return details, errors.New("Error occured while parsing the host parameter. Please check if this parameter has been seet correctly")
|
||||
}
|
||||
if matchedkey {
|
||||
details.URL = config.Host
|
||||
} else {
|
||||
details.URL = "https://" + config.Host
|
||||
}
|
||||
return details, err
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ func abapEnvironmentRunATCCheckMetadata() config.StepData {
|
||||
{
|
||||
Name: "host",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestHostConfig(t *testing.T) {
|
||||
t.Run("Check Host: ABAP Endpoint", func(t *testing.T) {
|
||||
t.Run("Check Host: ABAP Endpoint with HTTPS prefix", func(t *testing.T) {
|
||||
config := abapEnvironmentRunATCCheckOptions{
|
||||
Username: "testUser",
|
||||
Password: "testPassword",
|
||||
@ -24,6 +24,21 @@ func TestHostConfig(t *testing.T) {
|
||||
assert.Equal(t, "", con.XCsrfToken)
|
||||
}
|
||||
})
|
||||
t.Run("Check Host: ABAP Endpoint without HTTPS prefix", func(t *testing.T) {
|
||||
config := abapEnvironmentRunATCCheckOptions{
|
||||
Username: "testUser",
|
||||
Password: "testPassword",
|
||||
Host: "api.endpoint.com",
|
||||
}
|
||||
var con connectionDetailsHTTP
|
||||
con, error := checkHost(config, con)
|
||||
if error == nil {
|
||||
assert.Equal(t, "testUser", con.User)
|
||||
assert.Equal(t, "testPassword", con.Password)
|
||||
assert.Equal(t, "https://api.endpoint.com", con.URL)
|
||||
assert.Equal(t, "", con.XCsrfToken)
|
||||
}
|
||||
})
|
||||
t.Run("No host/ServiceKey configuration", func(t *testing.T) {
|
||||
//Testing without CfOrg parameter
|
||||
config := abapEnvironmentRunATCCheckOptions{
|
||||
@ -207,7 +222,6 @@ func TestParseATCResult(t *testing.T) {
|
||||
_ = os.Chdir(oldCWD)
|
||||
_ = os.RemoveAll(dir)
|
||||
}()
|
||||
|
||||
bodyString := `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<checkstyle>
|
||||
<file name="testFile">
|
||||
@ -222,7 +236,6 @@ func TestParseATCResult(t *testing.T) {
|
||||
</file>
|
||||
</checkstyle>`
|
||||
body := []byte(bodyString)
|
||||
|
||||
err = parseATCResult(body)
|
||||
assert.Equal(t, nil, err)
|
||||
})
|
||||
|
@ -52,7 +52,7 @@ abapEnvironmentRunATCCheck(
|
||||
cfOrg : 'cfOrg',
|
||||
cfSpace: 'cfSpace',
|
||||
cfServiceInstance: 'myServiceInstance',
|
||||
cfSserviceKeyName: 'myServiceKey',
|
||||
cfServiceKeyName: 'myServiceKey',
|
||||
abapCredentialsId: 'cfCredentialsId',
|
||||
atcConfig: 'atcconfig.yml',
|
||||
script: this,
|
||||
|
@ -52,6 +52,7 @@ spec:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
- name: cfApiEndpoint
|
||||
type: string
|
||||
description: Cloud Foundry API Enpoint
|
||||
|
@ -10,7 +10,6 @@ metadata:
|
||||
* Only provide one of those options with the respective credentials. If all values are provided, the direct communication (via host) has priority.
|
||||
|
||||
Regardless of the option you chose, please make sure to provide the configuration for Software Components and Packages that you want to be checked analog to the examples listed on this page.
|
||||
|
||||
spec:
|
||||
inputs:
|
||||
secrets:
|
||||
@ -108,9 +107,9 @@ spec:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- GENERAL
|
||||
mandatory: false
|
||||
containers:
|
||||
- name: cf
|
||||
image: ppiper/cf-cli
|
||||
workingDir: '/home/piper'
|
||||
imagePullPolicy: Never
|
||||
|
Loading…
x
Reference in New Issue
Block a user