From 349d437ab0c7dc46e9bce93b1951a6e64a052727 Mon Sep 17 00:00:00 2001 From: Fahri YARDIMCI Date: Fri, 4 Dec 2020 13:51:47 +0300 Subject: [PATCH] update go-sdk-v2 version (#203) Signed-off-by: Fahri YARDIMCI --- go.mod | 2 +- go.sum | 2 + ...esource_opsgenie_schedule_rotation_test.go | 60 ++++++++++++++++++- .../integration/integration.go | 13 ++++ .../opsgenie-go-sdk-v2/integration/request.go | 46 ++++++++++++++ .../opsgenie-go-sdk-v2/integration/result.go | 6 ++ .../opsgenie/opsgenie-go-sdk-v2/og/entity.go | 7 ++- vendor/modules.txt | 3 +- 8 files changed, 134 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 22d44bfc..4e19d567 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.14 require ( github.com/hashicorp/go-retryablehttp v0.6.6 github.com/hashicorp/terraform-plugin-sdk v1.15.0 - github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac + github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.3-0.20201204102414-d90cad05198b github.com/pkg/errors v0.8.1 ) diff --git a/go.sum b/go.sum index 256eed41..e38d0738 100644 --- a/go.sum +++ b/go.sum @@ -171,6 +171,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac h1:SxtpD9CfTncbSkcNVYeqW46DXJqz5b7HH8/BB43D+h0= github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.3-0.20201204102414-d90cad05198b h1:Nzbg89GTBuyy6Cy0+M3bwHyy1YHO3W9CS3Z909GImlE= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.3-0.20201204102414-d90cad05198b/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/opsgenie/resource_opsgenie_schedule_rotation_test.go b/opsgenie/resource_opsgenie_schedule_rotation_test.go index 6c99b592..86a870e8 100644 --- a/opsgenie/resource_opsgenie_schedule_rotation_test.go +++ b/opsgenie/resource_opsgenie_schedule_rotation_test.go @@ -225,6 +225,19 @@ resource "opsgenie_schedule" "test" { owner_team_id = "${opsgenie_team.test.id}" } +resource "opsgenie_escalation" "test" { + name ="genieescalationsched-%s" + rules { + condition = "if-not-acked" + notify_type = "default" + recipient { + type = "user" + id = "${opsgenie_user.test.id}" + } + delay = 1 + } +} + resource "opsgenie_schedule_rotation" "test" { schedule_id = "${opsgenie_schedule.test.id}" name = "test-%s" @@ -270,5 +283,50 @@ resource "opsgenie_schedule_rotation" "test2" { } } } -`, randomName, randomTeam, randomSchedule, randomRotation, randomRotation2) + +resource "opsgenie_schedule_rotation" "none" { + schedule_id = "${opsgenie_schedule.test.id}" + name = "schedulenone-%s" + start_date = "2019-06-18T17:30:00Z" + end_date ="2019-06-20T17:00:00Z" + type ="hourly" + length = 6 + participant { + type = "none" + } + + time_restriction { + type ="time-of-day" + restriction { + start_hour = 1 + start_min = 0 + end_hour = 10 + end_min = 0 + } + } +} + +resource "opsgenie_schedule_rotation" "esc" { + schedule_id = "${opsgenie_schedule.test.id}" + name = "schedule-escalation-%s" + start_date = "2019-06-18T17:30:00Z" + end_date ="2019-06-20T17:00:00Z" + type ="hourly" + length = 6 + participant { + type = "escalation" + id = "${opsgenie_escalation.test.id}" + } + + time_restriction { + type ="time-of-day" + restriction { + start_hour = 1 + start_min = 0 + end_hour = 10 + end_min = 0 + } + } +} +`, randomName, randomTeam, randomSchedule, randomRotation, randomRotation2, randomRotation2, randomRotation2, randomRotation2) } diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/integration.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/integration.go index 686b41ce..528b6813 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/integration.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/integration.go @@ -45,6 +45,15 @@ func (c *Client) CreateApiBased(context context.Context, request *APIBasedIntegr return result, nil } +func (c *Client) CreateWebhook(context context.Context, request *WebhookIntegrationRequest) (*WebhookIntegrationResult, error) { + result := &WebhookIntegrationResult{} + err := c.client.Exec(context, request, result) + if err != nil { + return nil, err + } + return result, nil +} + func (c *Client) CreateEmailBased(context context.Context, request *EmailBasedIntegrationRequest) (*EmailBasedIntegrationResult, error) { result := &EmailBasedIntegrationResult{} err := c.client.Exec(context, request, result) @@ -67,6 +76,10 @@ func (c *Client) ForceUpdateAllFields(context context.Context, request *UpdateIn request.OtherFields["suppressNotifications"] = request.SuppressNotifications request.OtherFields["responders"] = request.Responders request.OtherFields["emailUsername"] = request.EmailUsername + request.OtherFields["url"] = request.WebhookUrl + request.OtherFields["addAlertDescription"] = request.AddAlertDescription + request.OtherFields["addAlertDetails"] = request.AddAlertDetails + request.OtherFields["headers"] = request.Headers err := c.client.Exec(context, request.OtherFields, result) if err != nil { return nil, err diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go index 5aef775a..d9dda260 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go @@ -74,6 +74,43 @@ func (r *APIBasedIntegrationRequest) Method() string { return http.MethodPost } +type WebhookIntegrationRequest struct { + client.BaseRequest + Name string `json:"name"` + Type string `json:"type"` + AllowWriteAccess *bool `json:"allowWriteAccess"` + SuppressNotifications *bool `json:"suppressNotifications"` + OwnerTeam *og.OwnerTeam `json:"ownerTeam,omitempty"` + Responders []Responder `json:"responders,omitempty"` + WebhookUrl string `json:"url"` + AddAlertDescription *bool `json:"addAlertDescription"` + AddAlertDetails *bool `json:"addAlertDetails"` + Headers map[string]string `json:"headers,omitempty"` +} + +func (r *WebhookIntegrationRequest) Validate() error { + if r.Name == "" || r.Type == "" || r.WebhookUrl == "" { + return errors.New("Name, Type and WebhookUrl fields cannot be empty.") + } + if r.Type != "Webhook" { + return errors.New("Type has to be [Webhook] for Webhook integration.") + } + err := validateResponders(r.Responders) + if err != nil { + return err + } + return nil +} + +func (r *WebhookIntegrationRequest) ResourcePath() string { + return "/v2/integrations" +} + +func (r *WebhookIntegrationRequest) Method() string { + return http.MethodPost +} + + type EmailBasedIntegrationRequest struct { client.BaseRequest Name string `json:"name"` @@ -110,10 +147,14 @@ type UpdateIntegrationRequest struct { Name string Type string EmailUsername string + WebhookUrl string Enabled *bool IgnoreRespondersFromPayload *bool SuppressNotifications *bool Responders []Responder + AddAlertDescription *bool + AddAlertDetails *bool + Headers map[string]string OtherFields } @@ -130,6 +171,11 @@ func (r OtherFields) Validate() error { if _, ok := r["type"]; !ok { return errors.New("Type field cannot be empty.") } + if r["type"] == "Webhook" { + if _, ok := r["url"]; !ok { + return errors.New("[url] cannot be empty for type Webhook.") + } + } err := validateResponders(r["responders"].([]Responder)) if err != nil { return err diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go index f8cf9785..7312b0c1 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go @@ -29,6 +29,12 @@ type APIBasedIntegrationResult struct { ApiKey string `json:"apiKey"` } +type WebhookIntegrationResult struct { + client.ResultMetadata + GenericFields + ApiKey string `json:"apiKey"` +} + type EmailBasedIntegrationResult struct { client.ResultMetadata GenericFields diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/og/entity.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/og/entity.go index f7d2ba71..2215d9a1 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/og/entity.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/og/entity.go @@ -70,8 +70,8 @@ func validateParticipants(rotation *Rotation) error { if participant.Type == "" { return errors.New("Participant type cannot be empty.") } - if !(participant.Type == User || participant.Type == Team) { - return errors.New("Participant type should be one of these: 'User', 'Team'") + if !(participant.Type == User || participant.Type == Team || participant.Type == Escalation || participant.Type == None) { + return errors.New("Participant type should be one of these: 'User', 'Team', 'Escalation', 'None'") } if participant.Type == User && participant.Username == "" && participant.Id == "" { return errors.New("For participant type user either username or id must be provided.") @@ -79,6 +79,9 @@ func validateParticipants(rotation *Rotation) error { if participant.Type == Team && participant.Name == "" && participant.Id == "" { return errors.New("For participant type team either team name or id must be provided.") } + if participant.Type == Escalation && participant.Name == "" && participant.Id == "" { + return errors.New("For participant type escalation either escalation name or id must be provided.") + } } return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index eed0195b..dd104a9c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -215,11 +215,12 @@ github.com/mitchellh/mapstructure github.com/mitchellh/reflectwalk # github.com/oklog/run v1.0.0 github.com/oklog/run -# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.2-0.20200911071451-adf7a1c79aac +# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.3-0.20201204102414-d90cad05198b ## explicit github.com/opsgenie/opsgenie-go-sdk-v2/alert github.com/opsgenie/opsgenie-go-sdk-v2/client github.com/opsgenie/opsgenie-go-sdk-v2/contact +github.com/opsgenie/opsgenie-go-sdk-v2/custom_user_role github.com/opsgenie/opsgenie-go-sdk-v2/escalation github.com/opsgenie/opsgenie-go-sdk-v2/heartbeat github.com/opsgenie/opsgenie-go-sdk-v2/incident