Merge pull request #304 from salluvada/master

Add cookie jar to present session cookie for Jenkins API Calls.
This commit is contained in:
Tomasz Sęk 2020-03-27 16:45:29 +01:00 committed by GitHub
commit a445c0e3ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package client
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"net/http/cookiejar"
"regexp" "regexp"
"strings" "strings"
@ -150,7 +151,13 @@ func newClient(url, userName, passwordOrToken string) (Jenkins, error) {
jenkinsClient.Server = url jenkinsClient.Server = url
var basicAuth *gojenkins.BasicAuth var basicAuth *gojenkins.BasicAuth
httpClient := http.DefaultClient jar, err := cookiejar.New(nil)
if err != nil {
return nil, errors.Wrap(err, "couldn't create a cookie jar")
}
httpClient := &http.Client{Jar: jar}
if len(userName) > 0 && len(passwordOrToken) > 0 { if len(userName) > 0 && len(passwordOrToken) > 0 {
basicAuth = &gojenkins.BasicAuth{Username: userName, Password: passwordOrToken} basicAuth = &gojenkins.BasicAuth{Username: userName, Password: passwordOrToken}
} else { } else {