diff --git a/go.mod b/go.mod index 7b529916e..3d01e943a 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.16 require ( cloud.google.com/go v0.71.0 // indirect github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.1 - github.com/heimweh/go-pagerduty v0.0.0-20211027200436-ac3c86fd0ce5 + github.com/heimweh/go-pagerduty v0.0.0-20211110145933-0ab24da93a91 golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd // indirect google.golang.org/api v0.35.0 // indirect google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb // indirect diff --git a/go.sum b/go.sum index cf7d54b2c..56bd048ab 100644 --- a/go.sum +++ b/go.sum @@ -245,6 +245,8 @@ github.com/heimweh/go-pagerduty v0.0.0-20210930203304-530eff2acdc6 h1:/D0VtHEOCd github.com/heimweh/go-pagerduty v0.0.0-20210930203304-530eff2acdc6/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w= github.com/heimweh/go-pagerduty v0.0.0-20211027200436-ac3c86fd0ce5 h1:lAh9VAHBA09RKMNdbwdeWuzWSDbQ3wnUaa7mzrCKsCI= github.com/heimweh/go-pagerduty v0.0.0-20211027200436-ac3c86fd0ce5/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w= +github.com/heimweh/go-pagerduty v0.0.0-20211110145933-0ab24da93a91 h1:vqBxGv/CFAIyr1HRvG2DjOuMVHw62sP38s7p8uVfi9k= +github.com/heimweh/go-pagerduty v0.0.0-20211110145933-0ab24da93a91/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/business_service_subscriber.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/business_service_subscriber.go new file mode 100644 index 000000000..7c8a5f73b --- /dev/null +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/business_service_subscriber.go @@ -0,0 +1,94 @@ +package pagerduty + +import "fmt" + +// BusinessServiceSubscriberService handles the communication with business service +// subscriber related methods of the PagerDuty API. +type BusinessServiceSubscriberService service + +// BusinessService represents a business service. +type BusinessServiceSubscriber struct { + ID string `json:"subscriber_id,omitempty"` + Type string `json:"subscriber_type,omitempty"` +} + +// BusinessServiceSubscriberPayload represents payload with a business service subscriber object +type BusinessServiceSubscriberPayload struct { + BusinessServiceSubscriber []*BusinessServiceSubscriber `json:"subscribers,omitempty"` +} + +// ListBusinessServiceSubscribersResponse represents a list response of business service subscribers. +type ListBusinessServiceSubscribersResponse struct { + Total int `json:"total,omitempty"` + BusinessServiceSubscribers []*BusinessServiceSubscriber `json:"subscribers,omitempty"` + Offset int `json:"offset,omitempty"` + More bool `json:"more,omitempty"` + Limit int `json:"limit,omitempty"` +} + +// List lists existing business service subscribers. +func (s *BusinessServiceSubscriberService) List(businessServiceID string) (*ListBusinessServiceSubscribersResponse, *Response, error) { + u := fmt.Sprintf("/business_services/%s/subscribers", businessServiceID) + v := new(ListBusinessServiceSubscribersResponse) + + businessServiceSubscribers := make([]*BusinessServiceSubscriber, 0) + + // Create a handler closure capable of parsing data from the subscribers endpoint + // and appending resultant response plays to the return slice. + responseHandler := func(response *Response) (ListResp, *Response, error) { + var result ListBusinessServiceSubscribersResponse + + if err := s.client.DecodeJSON(response, &result); err != nil { + return ListResp{}, response, err + } + + businessServiceSubscribers = append(businessServiceSubscribers, result.BusinessServiceSubscribers...) + + // Return stats on the current page. Caller can use this information to + // adjust for requesting additional pages. + return ListResp{ + More: result.More, + Offset: result.Offset, + Limit: result.Limit, + }, response, nil + } + err := s.client.newRequestPagedGetDo(u, responseHandler) + if err != nil { + return nil, nil, err + } + v.BusinessServiceSubscribers = businessServiceSubscribers + + return v, nil, nil +} + +// Create creates a new business service subscriber. +func (s *BusinessServiceSubscriberService) Create(businessServiceID string, subscriber *BusinessServiceSubscriber) (*Response, error) { + u := fmt.Sprintf("/business_services/%s/subscribers", businessServiceID) + v := new(BusinessServiceSubscriberPayload) + subscriberArr := make([]*BusinessServiceSubscriber, 0) + subscriberArr = append(subscriberArr, subscriber) + p := &BusinessServiceSubscriberPayload{BusinessServiceSubscriber: subscriberArr} + + resp, err := s.client.newRequestDo("POST", u, nil, p, v) + if err != nil { + return nil, err + } + + return resp, nil +} + +// Delete deletes a business service subscriber. +func (s *BusinessServiceSubscriberService) Delete(businessServiceID string, subscriber *BusinessServiceSubscriber) (*Response, error) { + u := fmt.Sprintf("/business_services/%s/unsubscribe", businessServiceID) + v := new(BusinessServiceSubscriberPayload) + subscriberArr := make([]*BusinessServiceSubscriber, 0) + subscriberArr = append(subscriberArr, subscriber) + p := &BusinessServiceSubscriberPayload{BusinessServiceSubscriber: subscriberArr} + + resp, err := s.client.newRequestDo("POST", u, nil, p, v) + if err != nil { + return nil, err + } + + return resp, nil +} diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/cache.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/cache.go index 43aabad53..dc496b5c0 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/cache.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/cache.go @@ -100,7 +100,7 @@ func PopulateMemoryCache() { Abilities: abilities, } cachePut("misc", "abilities", abilitiesRecord) - + var pdo = ListUsersOptions{ Include: []string{"contact_methods", "notification_rules"}, Limit: 100, diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go index 694d11bee..e3dbbaf8f 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go @@ -54,6 +54,7 @@ type Client struct { ResponsePlays *ResponsePlayService SlackConnections *SlackConnectionService Tags *TagService + WebhookSubscriptions *WebhookSubscriptionService BusinessServiceSubscribers *BusinessServiceSubscriberService } @@ -112,6 +113,7 @@ func NewClient(config *Config) (*Client, error) { c.ResponsePlays = &ResponsePlayService{c} c.SlackConnections = &SlackConnectionService{c} c.Tags = &TagService{c} + c.WebhookSubscriptions = &WebhookSubscriptionService{c} c.BusinessServiceSubscribers = &BusinessServiceSubscriberService{c} InitCache(c) diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/webhook_subscription.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/webhook_subscription.go new file mode 100644 index 000000000..2f17c17af --- /dev/null +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/webhook_subscription.go @@ -0,0 +1,127 @@ +package pagerduty + +import "fmt" + +// WebhookSubscriptionService handle v3 webhooks from PagerDuty. +type WebhookSubscriptionService service + +// WebhookSubscription represents a webhook subscription. +type WebhookSubscription struct { + ID string `json:"id,omitempty"` + Type string `json:"type,omitempty"` + Active bool `json:"active,omitempty"` + Description string `json:"description,omitempty"` + DeliveryMethod DeliveryMethod `json:"delivery_method,omitempty"` + Events []string `json:"events,omitempty"` + Filter Filter `json:"filter,omitempty"` +} + +// DeliveryMethod represents a webhook delivery method +type DeliveryMethod struct { + TemporarilyDisabled bool `json:"temporarily_disabled,omitempty"` + Type string `json:"type,omitempty"` + URL string `json:"url,omitempty"` +} + +// Filter represents a webhook subscription filter +type Filter struct { + ID string `json:"id,omitempty"` + Type string `json:"type,omitempty"` +} + +// ListWebhookSubscriptionsResponse represents a list response of webhook subscriptions. +type ListWebhookSubscriptionsResponse struct { + Total int `json:"total,omitempty"` + WebhookSubscriptions []*WebhookSubscription `json:"webhook_subscriptions,omitempty"` + Offset int `json:"offset,omitempty"` + More bool `json:"more,omitempty"` + Limit int `json:"limit,omitempty"` +} + +// WebhookSubscriptionPayload represents payload with a slack connect object +type WebhookSubscriptionPayload struct { + WebhookSubscription *WebhookSubscription `json:"webhook_subscription,omitempty"` +} + +// List lists existing webhook subscriptions. +func (s *WebhookSubscriptionService) List() (*ListWebhookSubscriptionsResponse, *Response, error) { + u := "/webhook_subscriptions" + v := new(ListWebhookSubscriptionsResponse) + + webhookSubscriptions := make([]*WebhookSubscription, 0) + + // Create a handler closure capable of parsing data from the webhook subscriptions endpoint + // and appending resultant response plays to the return slice. + responseHandler := func(response *Response) (ListResp, *Response, error) { + var result ListWebhookSubscriptionsResponse + + if err := s.client.DecodeJSON(response, &result); err != nil { + return ListResp{}, response, err + } + + webhookSubscriptions = append(webhookSubscriptions, result.WebhookSubscriptions...) + + // Return stats on the current page. Caller can use this information to + // adjust for requesting additional pages. + return ListResp{ + More: result.More, + Offset: result.Offset, + Limit: result.Limit, + }, response, nil + } + err := s.client.newRequestPagedGetDo(u, responseHandler) + if err != nil { + return nil, nil, err + } + v.WebhookSubscriptions = webhookSubscriptions + + return v, nil, nil +} + +// Create creates a new webhook subscription. +func (s *WebhookSubscriptionService) Create(sub *WebhookSubscription) (*WebhookSubscription, *Response, error) { + u := "/webhook_subscriptions" + v := new(WebhookSubscriptionPayload) + p := &WebhookSubscriptionPayload{WebhookSubscription: sub} + + resp, err := s.client.newRequestDo("POST", u, nil, p, v) + if err != nil { + return nil, nil, err + } + + return v.WebhookSubscription, resp, nil +} + +// Get gets a webhook subscription. +func (s *WebhookSubscriptionService) Get(ID string) (*WebhookSubscription, *Response, error) { + u := fmt.Sprintf("/webhook_subscriptions/%s", ID) + v := new(WebhookSubscriptionPayload) + p := &WebhookSubscriptionPayload{} + + resp, err := s.client.newRequestDo("GET", u, nil, p, v) + if err != nil { + return nil, nil, err + } + + return v.WebhookSubscription, resp, nil +} + +// Delete deletes a webhook subscription. +func (s *WebhookSubscriptionService) Delete(ID string) (*Response, error) { + u := fmt.Sprintf("/webhook_subscriptions/%s", ID) + return s.client.newRequestDo("DELETE", u, nil, nil, nil) +} + +// Update updates a webhook subscription. +func (s *WebhookSubscriptionService) Update(ID string, sub *WebhookSubscription) (*WebhookSubscription, *Response, error) { + u := fmt.Sprintf("/webhook_subscriptions/%s", ID) + v := new(WebhookSubscriptionPayload) + p := WebhookSubscriptionPayload{WebhookSubscription: sub} + + resp, err := s.client.newRequestDo("PUT", u, nil, p, v) + if err != nil { + return nil, nil, err + } + + return v.WebhookSubscription, resp, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 64f51288a..c37ec1ead 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -156,7 +156,7 @@ github.com/hashicorp/terraform-plugin-sdk/v2/plugin github.com/hashicorp/terraform-plugin-sdk/v2/terraform # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/heimweh/go-pagerduty v0.0.0-20211027200436-ac3c86fd0ce5 +# github.com/heimweh/go-pagerduty v0.0.0-20211110145933-0ab24da93a91 ## explicit github.com/heimweh/go-pagerduty/pagerduty # github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af