-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvsm.go
39 lines (31 loc) · 988 Bytes
/
vsm.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
package gocd
import (
"encoding/json"
"fmt"
"net/http"
"path/filepath"
"github.com/jinzhu/copier"
"github.com/nikhilsbhat/gocd-sdk-go/pkg/errors"
)
func (conf *client) GetPipelineVSM(pipeline, instance string) (VSM, error) {
newClient := &client{}
if err := copier.CopyWithOption(newClient, conf, copier.Option{IgnoreEmpty: true, DeepCopy: true}); err != nil {
return VSM{}, err
}
var vsmObj VSM
resp, err := newClient.httpClient.R().
Get(filepath.Join(VSMEndpoint, pipeline, fmt.Sprintf("%s.json", instance))) //nolint:perfsprint
if err != nil {
return vsmObj, &errors.APIError{
Err: err,
Message: fmt.Sprintf("get vsm information for pipeline '%s' of instance '%s'", pipeline, instance),
}
}
if resp.StatusCode() != http.StatusOK {
return vsmObj, &errors.NonOkError{Code: resp.StatusCode(), Response: resp}
}
if err = json.Unmarshal(resp.Body(), &vsmObj); err != nil {
return vsmObj, &errors.MarshalError{Err: err}
}
return vsmObj, nil
}