-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpermissions.go
41 lines (33 loc) · 1.05 KB
/
permissions.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
package gocd
import (
"encoding/json"
"net/http"
"github.com/jinzhu/copier"
"github.com/nikhilsbhat/gocd-sdk-go/pkg/errors"
)
// GetPermissions fetches all pipelines configured in GoCD server.
func (conf *client) GetPermissions(query map[string]string) (Permission, error) {
var permissions struct {
Permission Permission `json:"permissions"`
}
newClient := &client{}
if err := copier.CopyWithOption(newClient, conf, copier.Option{IgnoreEmpty: true, DeepCopy: true}); err != nil {
return Permission{}, err
}
resp, err := newClient.httpClient.R().
SetHeaders(map[string]string{
"Accept": HeaderVersionOne,
}).
SetQueryParams(query).
Get(PermissionsEndpoint)
if err != nil {
return Permission{}, &errors.APIError{Err: err, Message: "get permissions"}
}
if resp.StatusCode() != http.StatusOK {
return Permission{}, &errors.NonOkError{Code: resp.StatusCode(), Response: resp}
}
if err = json.Unmarshal(resp.Body(), &permissions); err != nil {
return Permission{}, &errors.MarshalError{Err: err}
}
return permissions.Permission, nil
}