-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential.go
50 lines (42 loc) · 1.25 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
package jenkins
import (
"fmt"
"io"
"net/http"
)
type Credentials struct {
*Item
}
func (cs *Credentials) Get(name string) (*CredentialJson, error) {
var credsJson CredentialsJson
if err := cs.ApiJson(&credsJson, &ApiJsonOpts{Depth: 1}); err != nil {
return nil, err
}
if credsJson.Credentials != nil {
for _, cred := range credsJson.Credentials {
if cred.ID == name {
return cred, nil
}
}
}
return nil, fmt.Errorf("%s has no credential [%s]", cs, name)
}
func (cs *Credentials) Create(xml io.Reader) (*http.Response, error) {
return cs.Request("POST", "createCredentials", xml)
}
func (cs *Credentials) Delete(name string) (*http.Response, error) {
return cs.Request("POST", "credential/"+name+"/doDelete", nil)
}
func (cs *Credentials) GetConfigure(name string) (string, error) {
return readResponseToString(cs, "GET", "credential/"+name+"/config.xml", nil)
}
func (cs *Credentials) SetConfigure(name string, xml io.Reader) (*http.Response, error) {
return cs.Request("POST", "credential/"+name+"/config.xml", xml)
}
func (cs *Credentials) List() ([]*CredentialJson, error) {
var credsJson CredentialsJson
if err := cs.ApiJson(&credsJson, &ApiJsonOpts{Depth: 1}); err != nil {
return nil, err
}
return credsJson.Credentials, nil
}