forked from hashicorp/terraform
/
config.go
46 lines (34 loc) · 839 Bytes
/
config.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
package opsgenie
import (
"log"
"golang.org/x/net/context"
"github.com/opsgenie/opsgenie-go-sdk/client"
)
type OpsGenieClient struct {
apiKey string
StopContext context.Context
teams client.OpsGenieTeamClient
users client.OpsGenieUserClient
}
// Config defines the configuration options for the OpsGenie client
type Config struct {
ApiKey string
}
// Client returns a new OpsGenie client
func (c *Config) Client() (*OpsGenieClient, error) {
opsGenie := new(client.OpsGenieClient)
opsGenie.SetAPIKey(c.ApiKey)
client := OpsGenieClient{}
log.Printf("[INFO] OpsGenie client configured")
teamsClient, err := opsGenie.Team()
if err != nil {
return nil, err
}
client.teams = *teamsClient
usersClient, err := opsGenie.User()
if err != nil {
return nil, err
}
client.users = *usersClient
return &client, nil
}