github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opsgenie/config.go (about)

     1  package opsgenie
     2  
     3  import (
     4  	"log"
     5  
     6  	"golang.org/x/net/context"
     7  
     8  	"github.com/opsgenie/opsgenie-go-sdk/client"
     9  )
    10  
    11  type OpsGenieClient struct {
    12  	apiKey string
    13  
    14  	StopContext context.Context
    15  
    16  	teams client.OpsGenieTeamClient
    17  	users client.OpsGenieUserClient
    18  }
    19  
    20  // Config defines the configuration options for the OpsGenie client
    21  type Config struct {
    22  	ApiKey string
    23  }
    24  
    25  // Client returns a new OpsGenie client
    26  func (c *Config) Client() (*OpsGenieClient, error) {
    27  	opsGenie := new(client.OpsGenieClient)
    28  	opsGenie.SetAPIKey(c.ApiKey)
    29  	client := OpsGenieClient{}
    30  
    31  	log.Printf("[INFO] OpsGenie client configured")
    32  
    33  	teamsClient, err := opsGenie.Team()
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  	client.teams = *teamsClient
    38  
    39  	usersClient, err := opsGenie.User()
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  	client.users = *usersClient
    44  
    45  	return &client, nil
    46  }