-
Notifications
You must be signed in to change notification settings - Fork 31
/
service_client.go
60 lines (49 loc) · 1.47 KB
/
service_client.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
package locations
import (
"encoding/json"
"github.com/dtcookie/dynatrace/rest"
"github.com/dtcookie/dynatrace/rest/credentials"
)
// ServiceClient TODO: documentation
type ServiceClient struct {
client *rest.Client
}
// NewService creates a new Service Client
// baseURL should look like this: "https://siz65484.live.dynatrace.com/api/config/v1"
// token is an API Token
func NewService(baseURL string, token string) *ServiceClient {
credentials := credentials.New(token)
config := rest.Config{}
client := rest.NewClient(&config, baseURL, credentials)
return &ServiceClient{client: client}
}
// // Get TODO: documentation
// func (cs *ServiceClient) Get(id string) (*Credentials, error) {
// if len(id) == 0 {
// return nil, errors.New("empty ID provided for the configuration to fetch")
// }
// var err error
// var bytes []byte
// if bytes, err = cs.client.GET(fmt.Sprintf("/credentials/%s", id), 200); err != nil {
// return nil, err
// }
// var credentials Credentials
// if err = json.Unmarshal(bytes, &credentials); err != nil {
// return nil, err
// }
// return &credentials, nil
// }
// ListAll TODO: documentation
func (cs *ServiceClient) List() (*SyntheticLocations, error) {
var err error
var bytes []byte
rest.Verbose = true
if bytes, err = cs.client.GET("/synthetic/locations", 200); err != nil {
return nil, err
}
var stubList SyntheticLocations
if err = json.Unmarshal(bytes, &stubList); err != nil {
return nil, err
}
return &stubList, nil
}