-
Notifications
You must be signed in to change notification settings - Fork 132
/
integration_util.go
64 lines (53 loc) · 1.48 KB
/
integration_util.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
61
62
63
64
package opsgenie
import (
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/opsgenie/opsgenie-go-sdk-v2/integration"
)
func expandOpsgenieIntegrationResponders(d *schema.ResourceData) []integration.Responder {
input := d.Get("responders").([]interface{})
responders := make([]integration.Responder, 0, len(input))
if input == nil {
return responders
}
for _, v := range input {
config := v.(map[string]interface{})
responderID := config["id"].(string)
responder := integration.Responder{
Type: integration.ResponderType(config["type"].(string)),
Id: responderID,
}
responders = append(responders, responder)
}
return responders
}
func flattenIntegrationResponders(r []interface{}) []map[string]interface{} {
responders := []map[string]interface{}{}
for _, i := range r {
c := i.(map[string]interface{})
responders = append(responders, map[string]interface{}{
"type": c["type"],
"id": c["id"],
})
}
return responders
}
func validateResponderType(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToLower(v.(string))
families := map[string]bool{
"user": true,
"team": true,
"escalation": true,
"schedule": true,
}
if !families[value] {
errors = append(errors, fmt.Errorf("it can only be one of these 'user', 'schedule', 'team', 'escalation'"))
}
return
}
const (
ApiIntegrationType = "API"
EmailIntegrationType = "Email"
WebhookIntegrationType = "Webhook"
)