-
Notifications
You must be signed in to change notification settings - Fork 42
/
config.go
53 lines (44 loc) · 1.53 KB
/
config.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
package jenkins
import (
"io"
"io/ioutil"
"strings"
jenkins "github.com/bndr/gojenkins"
)
type jenkinsClient interface {
CreateJobInFolder(config string, jobName string, parentIDs ...string) (*jenkins.Job, error)
Credentials() *jenkins.CredentialsManager
DeleteJobInFolder(name string, parentIDs ...string) (bool, error)
GetJob(id string, parentIDs ...string) (*jenkins.Job, error)
GetFolder(id string, parents ...string) (*jenkins.Folder, error)
}
// jenkinsAdapter wraps the Jenkins client, enabling additional functionality
type jenkinsAdapter struct {
*jenkins.Jenkins
}
// Config is the set of parameters needed to configure the Jenkins provider.
type Config struct {
ServerURL string
CACert io.Reader
Username string
Password string
}
func newJenkinsClient(c *Config) *jenkinsAdapter {
client := jenkins.CreateJenkins(nil, c.ServerURL, c.Username, c.Password)
if c.CACert != nil {
// provide CA certificate if server is using self-signed certificate
client.Requester.CACert, _ = ioutil.ReadAll(c.CACert)
}
// return the Jenkins API client
return &jenkinsAdapter{Jenkins: client}
}
func (j *jenkinsAdapter) Credentials() *jenkins.CredentialsManager {
return &jenkins.CredentialsManager{
J: j.Jenkins,
}
}
// DeleteJobInFolder assists in running DeleteJob funcs, as DeleteJob is not folder aware
// and cannot take a canonical job ID without mishandling it.
func (j *jenkinsAdapter) DeleteJobInFolder(name string, parentIDs ...string) (bool, error) {
return j.DeleteJob(strings.Join(append(parentIDs, name), "/job/"))
}