-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential.go
63 lines (53 loc) · 1.6 KB
/
credential.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
package jenkins
import (
"github.com/imroc/req"
)
type CredentialService struct {
*Item
}
func NewCredentialService(v interface{}) *CredentialService {
if c, ok := v.(*Client); ok {
return &CredentialService{Item: NewItem(c.URL+"credentials/store/system/domain/_/", "Credentials", c)}
}
if c, ok := v.(*JobItem); ok {
return &CredentialService{Item: NewItem(c.URL+"credentials/store/folder/domain/_/", "Credentials", c.client)}
}
return nil
}
func (cs *CredentialService) Get(name string) (*Credential, error) {
var credsJson Credentials
if err := cs.BindAPIJson(ReqParams{"depth": "1"}, &credsJson); err != nil {
return nil, err
}
if credsJson.Credentials != nil {
for _, cred := range credsJson.Credentials {
if cred.ID == name {
return cred, nil
}
}
}
return nil, nil
}
func (cs *CredentialService) Create(xml string) error {
_, err := cs.Request("POST", "createCredentials", req.BodyXML(xml))
return err
}
func (cs *CredentialService) Delete(name string) error {
_, err := cs.Request("POST", "credential/"+name+"/doDelete")
return err
}
func (cs *CredentialService) GetConfigure(name string) (string, error) {
resp, err := cs.Request("GET", "credential/"+name+"/config.xml")
return resp.String(), err
}
func (cs *CredentialService) SetConfigure(name, xml string) error {
_, err := cs.Request("POST", "credential/"+name+"/config.xml", req.BodyXML(xml))
return err
}
func (cs *CredentialService) List() ([]*Credential, error) {
var credsJson Credentials
if err := cs.BindAPIJson(ReqParams{"depth": "1"}, &credsJson); err != nil {
return nil, err
}
return credsJson.Credentials, nil
}