diff --git a/go.mod b/go.mod index 00d8ee82e..2d4c2cec2 100644 --- a/go.mod +++ b/go.mod @@ -16,3 +16,5 @@ require ( google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb // indirect google.golang.org/grpc v1.33.2 // indirect ) + +replace github.com/heimweh/go-pagerduty => github.com/mrdubr/go-pagerduty v0.0.0-20221222163503-5363648f2b40 diff --git a/go.sum b/go.sum index 76fb2bbfe..c28a20f18 100644 --- a/go.sum +++ b/go.sum @@ -224,8 +224,6 @@ github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/heimweh/go-pagerduty v0.0.0-20221222221341-c1c27ca3744a h1:U2RXTaVK7ZwWKnmaF/any3PQnBfuuZxYGQ57DP8Fvjc= -github.com/heimweh/go-pagerduty v0.0.0-20221222221341-c1c27ca3744a/go.mod h1:t9vftsO1IjYHGdgJXeemZtomCWnxi2SRgu0PRcRb2oY= 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= @@ -294,6 +292,8 @@ github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.6.6 h1:Duep6KMIDpY4Yo11iFsvyqJDyfzLF9+sndUKT+v64GQ= github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/mrdubr/go-pagerduty v0.0.0-20221222163503-5363648f2b40 h1:UlRJ4qF4SRfScsQA2a93f/Q11eykbGX9ZHeozJuv8us= +github.com/mrdubr/go-pagerduty v0.0.0-20221222163503-5363648f2b40/go.mod h1:t9vftsO1IjYHGdgJXeemZtomCWnxi2SRgu0PRcRb2oY= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758= github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs= diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go index 2cbc4bee7..a33b091b7 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_action.go @@ -38,9 +38,11 @@ type AutomationActionsActionTeamAssociationPayload struct { Team *TeamReference `json:"team,omitempty"` } +var automationActionsActionBaseUrl = "/automation_actions/actions" + // Create creates a new action func (s *AutomationActionsActionService) Create(action *AutomationActionsAction) (*AutomationActionsAction, *Response, error) { - u := "/automation_actions/actions" + u := automationActionsActionBaseUrl v := new(AutomationActionsActionPayload) resp, err := s.client.newRequestDoOptions("POST", u, nil, &AutomationActionsActionPayload{Action: action}, &v) @@ -53,7 +55,7 @@ func (s *AutomationActionsActionService) Create(action *AutomationActionsAction) // Get retrieves information about an action. func (s *AutomationActionsActionService) Get(id string) (*AutomationActionsAction, *Response, error) { - u := fmt.Sprintf("/automation_actions/actions/%s", id) + u := fmt.Sprintf("%s/%s", automationActionsActionBaseUrl, id) v := new(AutomationActionsActionPayload) resp, err := s.client.newRequestDoOptions("GET", u, nil, nil, &v) @@ -64,16 +66,30 @@ func (s *AutomationActionsActionService) Get(id string) (*AutomationActionsActio return v.Action, resp, nil } +// Update an existing action +func (s *AutomationActionsActionService) Update(ID string, action *AutomationActionsAction) (*AutomationActionsAction, *Response, error) { + u := fmt.Sprintf("%s/%s", automationActionsActionBaseUrl, ID) + v := new(AutomationActionsActionPayload) + p := &AutomationActionsActionPayload{Action: action} + + resp, err := s.client.newRequestDo("PUT", u, nil, p, v) + if err != nil { + return nil, nil, err + } + + return v.Action, resp, nil +} + // Delete deletes an existing action. func (s *AutomationActionsActionService) Delete(id string) (*Response, error) { - u := fmt.Sprintf("/automation_actions/actions/%s", id) + u := fmt.Sprintf("%s/%s", automationActionsActionBaseUrl, id) return s.client.newRequestDoOptions("DELETE", u, nil, nil, nil) } // Associate an Automation Action with a team func (s *AutomationActionsActionService) AssociateToTeam(actionID, teamID string) (*AutomationActionsActionTeamAssociationPayload, *Response, error) { - u := fmt.Sprintf("/automation_actions/actions/%s/teams", actionID) + u := fmt.Sprintf("%s/%s/teams", automationActionsActionBaseUrl, actionID) v := new(AutomationActionsActionTeamAssociationPayload) p := &AutomationActionsActionTeamAssociationPayload{ Team: &TeamReference{ID: teamID, Type: "team_reference"}, @@ -89,14 +105,14 @@ func (s *AutomationActionsActionService) AssociateToTeam(actionID, teamID string // Dissociate an Automation Action with a team func (s *AutomationActionsActionService) DissociateToTeam(actionID, teamID string) (*Response, error) { - u := fmt.Sprintf("/automation_actions/actions/%s/teams/%s", actionID, teamID) + u := fmt.Sprintf("%s/%s/teams/%s", automationActionsActionBaseUrl, actionID, teamID) return s.client.newRequestDoOptions("DELETE", u, nil, nil, nil) } // Gets the details of an Automation Action / team relation func (s *AutomationActionsActionService) GetAssociationToTeam(actionID, teamID string) (*AutomationActionsActionTeamAssociationPayload, *Response, error) { - u := fmt.Sprintf("/automation_actions/actions/%s/teams/%s", actionID, teamID) + u := fmt.Sprintf("%s/%s/teams/%s", automationActionsActionBaseUrl, actionID, teamID) v := new(AutomationActionsActionTeamAssociationPayload) resp, err := s.client.newRequestDoOptions("GET", u, nil, nil, &v) diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_runner.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_runner.go index 7b94aa4e7..e39e2660a 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_runner.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/automation_actions_runner.go @@ -29,9 +29,11 @@ type AutomationActionsRunnerPayload struct { Runner *AutomationActionsRunner `json:"runner,omitempty"` } +var automationActionsRunnerBaseUrl = "/automation_actions/runners" + // Create creates a new runner func (s *AutomationActionsRunnerService) Create(runner *AutomationActionsRunner) (*AutomationActionsRunner, *Response, error) { - u := "/automation_actions/runners" + u := automationActionsRunnerBaseUrl v := new(AutomationActionsRunnerPayload) resp, err := s.client.newRequestDoOptions("POST", u, nil, &AutomationActionsRunnerPayload{Runner: runner}, &v) @@ -44,7 +46,7 @@ func (s *AutomationActionsRunnerService) Create(runner *AutomationActionsRunner) // Get retrieves information about a runner. func (s *AutomationActionsRunnerService) Get(id string) (*AutomationActionsRunner, *Response, error) { - u := fmt.Sprintf("/automation_actions/runners/%s", id) + u := fmt.Sprintf("%s/%s", automationActionsRunnerBaseUrl, id) v := new(AutomationActionsRunnerPayload) resp, err := s.client.newRequestDoOptions("GET", u, nil, nil, &v) @@ -55,9 +57,23 @@ func (s *AutomationActionsRunnerService) Get(id string) (*AutomationActionsRunne return v.Runner, resp, nil } +// Update an existing runner +func (s *AutomationActionsRunnerService) Update(ID string, runner *AutomationActionsRunner) (*AutomationActionsRunner, *Response, error) { + u := fmt.Sprintf("%s/%s", automationActionsRunnerBaseUrl, ID) + v := new(AutomationActionsRunnerPayload) + p := &AutomationActionsRunnerPayload{Runner: runner} + + resp, err := s.client.newRequestDo("PUT", u, nil, p, v) + if err != nil { + return nil, nil, err + } + + return v.Runner, resp, nil +} + // Delete deletes an existing runner. func (s *AutomationActionsRunnerService) Delete(id string) (*Response, error) { - u := fmt.Sprintf("/automation_actions/runners/%s", id) + u := fmt.Sprintf("%s/%s", automationActionsRunnerBaseUrl, id) return s.client.newRequestDoOptions("DELETE", u, nil, nil, nil) } diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident.go deleted file mode 100644 index fb3e0bc8d..000000000 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident.go +++ /dev/null @@ -1,178 +0,0 @@ -package pagerduty - -import ( - "fmt" - "log" -) - -// IncidentService handles the communication with incident -// related methods of the PagerDuty API. -type IncidentService service - -// Incident represents a incident. -type Incident struct { - ID string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - Summary string `json:"summary,omitempty"` - Self string `json:"self,omitempty"` - HTMLURL string `json:"html_url,omitempty"` - IncidentNumber int `json:"incident_number,omitempty"` - CreatedAt string `json:"created_at,omitempty"` - Status string `json:"status,omitempty"` - Title string `json:"title,omitempty"` - Resolution string `json:"resolution,omitempty"` - AlertCounts *AlertCounts `json:"alert_counts,omitempty"` - PendingActions []*PendingAction `json:"pending_actions,omitempty"` - IncidentKey string `json:"incident_key,omitempty"` - Service *ServiceReference `json:"service,omitempty"` - AssignedVia string `json:"assigned_via,omitempty"` - Assignments []*IncidentAssignment `json:"assignments,omitempty"` - Acknowledgements []*IncidentAcknowledgement `json:"acknowledgements,omitempty"` - LastStatusChangeAt string `json:"last_status_change_at,omitempty"` - LastStatusChangeBy *IncidentAttributeReference `json:"last_status_change_by,omitempty"` - FirstTriggerLogEntry *IncidentAttributeReference `json:"first_trigger_log_entry,omitempty"` - EscalationPolicy *EscalationPolicyReference `json:"escalation_policy,omitempty"` - Teams []*TeamReference `json:"teams,omitempty"` - Urgency string `json:"urgency,omitempty"` -} - -type AlertCounts struct { - All int `json:"all"` - Resolved int `json:"resolved"` - Triggered int `json:"triggered"` -} - -type PendingAction struct { - At string `json:"at"` - Type string `json:"type"` -} - -type IncidentAssignment struct { - At string `json:"at"` - Assignee UserReference `json:"assignee"` -} - -type IncidentAcknowledgement struct { - At string `json:"at"` - Acknowledger IncidentAttributeReference `json:"acknowledger"` -} - -// IncidentPayload represents an incident. -type IncidentPayload struct { - Incident *Incident `json:"incident,omitempty"` -} - -// ManageIncidentsPayload represents a payload with a list of incidents data. -type ManageIncidentsPayload struct { - Incidents []*Incident `json:"incidents,omitempty"` -} - -// ListIncidentsOptions represents options when listing incidents. -type ListIncidentsOptions struct { - Limit int `url:"limit,omitempty"` - Offset int `url:"offset,omitempty"` - Total int `url:"total,omitempty"` - DateRange string `url:"date_range,omitempty"` - IncidentKey string `url:"incident_key,omitempty"` - Include []string `url:"include,omitempty,brackets"` - ServiceIDs []string `url:"service_ids,omitempty,brackets"` - Since string `url:"since,omitempty"` - SortBy []string `url:"sort_by,omitempty,brackets"` - Statuses []string `url:"statuses,omitempty,brackets"` - TeamIDs []string `url:"team_ids,omitempty,brackets"` - TimeZone string `url:"time_zone,omitempty"` - Until string `url:"until,omitempty"` - Urgencies []string `url:"urgencies,omitempty,brackets"` - UserIDs []string `url:"user_ids,omitempty,brackets"` -} - -// ManageIncidentsOptions represents options when listing incidents. -type ManageIncidentsOptions struct { - Limit int `url:"limit,omitempty"` - Offset int `url:"offset,omitempty"` - Total int `url:"total,omitempty"` -} - -// ListIncidentsResponse represents a list response of incidents. -type ListIncidentsResponse struct { - Limit int `json:"limit,omitempty"` - More bool `json:"more,omitempty"` - Offset int `json:"offset,omitempty"` - Total int `json:"total,omitempty"` - Incidents []*Incident `json:"incidents,omitempty"` -} - -type ManageIncidentsResponse ListIncidentsResponse - -// List lists existing incidents. -func (s *IncidentService) List(o *ListIncidentsOptions) (*ListIncidentsResponse, *Response, error) { - u := "/incidents" - v := new(ListIncidentsResponse) - - resp, err := s.client.newRequestDo("GET", u, o, nil, &v) - if err != nil { - return nil, nil, err - } - - return v, resp, nil -} - -// ListAll lists all result pages for incidents list. -func (s *IncidentService) ListAll(o *ListIncidentsOptions) ([]*Incident, error) { - var incidents = make([]*Incident, 0, 25) - more := true - offset := 0 - - for more { - log.Printf("==== Getting incidents at offset %d", offset) - v := new(ListIncidentsResponse) - _, err := s.client.newRequestDo("GET", "/incidents", o, nil, &v) - if err != nil { - return incidents, err - } - incidents = append(incidents, v.Incidents...) - more = v.More - offset += v.Limit - o.Offset = offset - } - return incidents, nil -} - -// ManageIncidents updates existing incidents. -func (s *IncidentService) ManageIncidents(incidents []*Incident, o *ManageIncidentsOptions) (*ManageIncidentsResponse, *Response, error) { - u := "/incidents" - v := new(ManageIncidentsResponse) - - resp, err := s.client.newRequestDo("PUT", u, o, &ManageIncidentsPayload{Incidents: incidents}, &v) - if err != nil { - return nil, nil, err - } - - return v, resp, nil -} - -// Create an incident -func (s *IncidentService) Create(incident *Incident) (*Incident, *Response, error) { - u := "/incidents" - v := new(IncidentPayload) - - resp, err := s.client.newRequestDo("POST", u, nil, &IncidentPayload{Incident: incident}, &v) - if err != nil { - return nil, nil, err - } - - return v.Incident, resp, nil -} - -// Get retrieves information about an incident. -func (s *IncidentService) Get(id string) (*Incident, *Response, error) { - u := fmt.Sprintf("/incidents/%s", id) - v := new(IncidentPayload) - - resp, err := s.client.newRequestDo("GET", u, nil, nil, &v) - if err != nil { - return nil, nil, err - } - - return v.Incident, resp, nil -} diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow.go deleted file mode 100644 index 9508c857b..000000000 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow.go +++ /dev/null @@ -1,207 +0,0 @@ -package pagerduty - -import ( - "context" - "fmt" -) - -// IncidentWorkflowService handles the communication with incident workflow -// related methods of the PagerDuty API. -type IncidentWorkflowService service - -// IncidentWorkflow represents an incident workflow. -type IncidentWorkflow struct { - ID string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - Self string `json:"self,omitempty"` - Steps []*IncidentWorkflowStep `json:"steps,omitempty"` -} - -// IncidentWorkflowStep represents a step in an incident workflow. -type IncidentWorkflowStep struct { - ID string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - Name string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - Configuration *IncidentWorkflowActionConfiguration `json:"action_configuration,omitempty"` -} - -// IncidentWorkflowActionConfiguration represents the configuration for an incident workflow action -type IncidentWorkflowActionConfiguration struct { - ActionID string `json:"action_id,omitempty"` - Description *string `json:"description,omitempty"` - Inputs []*IncidentWorkflowActionInput `json:"inputs,omitempty"` -} - -type IncidentWorkflowActionInput struct { - Name string `json:"name,omitempty"` - Value string `json:"value,omitempty"` -} - -// ListIncidentWorkflowResponse represents a list response of incident workflows. -type ListIncidentWorkflowResponse struct { - Total int `json:"total,omitempty"` - IncidentWorkflows []*IncidentWorkflow `json:"incident_workflows,omitempty"` - Offset int `json:"offset,omitempty"` - More bool `json:"more,omitempty"` - Limit int `json:"limit,omitempty"` -} - -// IncidentWorkflowPayload represents payload with an incident workflow object. -type IncidentWorkflowPayload struct { - IncidentWorkflow *IncidentWorkflow `json:"incident_workflow,omitempty"` -} - -var incidentWorkflowsEarlyAccessHeader = RequestOptions{ - Type: "header", - Label: "X-EARLY-ACCESS", - Value: "incident-workflows-early-access", -} - -// ListIncidentWorkflowOptions represents options when retrieving a list of incident workflows. -type ListIncidentWorkflowOptions struct { - Offset int `url:"offset,omitempty"` - Limit int `url:"limit,omitempty"` - Total bool `url:"total,omitempty"` - Includes []string `url:"include,brackets,omitempty"` -} - -type listIncidentWorkflowOptionsGen struct { - options *ListIncidentWorkflowOptions -} - -func (o *listIncidentWorkflowOptionsGen) currentOffset() int { - return o.options.Offset -} - -func (o *listIncidentWorkflowOptionsGen) changeOffset(i int) { - o.options.Offset = i -} - -func (o *listIncidentWorkflowOptionsGen) buildStruct() interface{} { - return o.options -} - -// List lists existing incident workflows. If a non-zero Limit is passed as an option, only a single page of results will be -// returned. Otherwise, the entire list of incident workflows will be returned. -func (s *IncidentWorkflowService) List(o *ListIncidentWorkflowOptions) (*ListIncidentWorkflowResponse, *Response, error) { - return s.ListContext(context.Background(), o) -} - -// ListContext lists existing incident workflows. If a non-zero Limit is passed as an option, only a single page of results will be -// returned. Otherwise, the entire list of incident workflows will be returned. -func (s *IncidentWorkflowService) ListContext(ctx context.Context, o *ListIncidentWorkflowOptions) (*ListIncidentWorkflowResponse, *Response, error) { - u := "/incident_workflows" - v := new(ListIncidentWorkflowResponse) - - if o == nil { - o = &ListIncidentWorkflowOptions{} - } - - if o.Limit != 0 { - resp, err := s.client.newRequestDoOptionsContext(ctx, "GET", u, o, nil, &v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v, resp, nil - } else { - workflows := make([]*IncidentWorkflow, 0) - - // Create a handler closure capable of parsing data from the workflows endpoint - // and appending resultant response plays to the return slice. - responseHandler := func(response *Response) (ListResp, *Response, error) { - var result ListIncidentWorkflowResponse - - if err := s.client.DecodeJSON(response, &result); err != nil { - return ListResp{}, response, err - } - - workflows = append(workflows, result.IncidentWorkflows...) - - // 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.newRequestPagedGetQueryDoContext(ctx, u, responseHandler, &listIncidentWorkflowOptionsGen{ - options: o, - }, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - v.IncidentWorkflows = workflows - - return v, nil, nil - } -} - -// Get gets an incident workflow. -func (s *IncidentWorkflowService) Get(id string) (*IncidentWorkflow, *Response, error) { - return s.GetContext(context.Background(), id) -} - -// GetContext gets an incident workflow. -func (s *IncidentWorkflowService) GetContext(ctx context.Context, id string) (*IncidentWorkflow, *Response, error) { - u := fmt.Sprintf("/incident_workflows/%s", id) - v := new(IncidentWorkflowPayload) - - resp, err := s.client.newRequestDoOptionsContext(ctx, "GET", u, nil, nil, v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v.IncidentWorkflow, resp, nil -} - -// Create creates a new incident workflow. -func (s *IncidentWorkflowService) Create(iw *IncidentWorkflow) (*IncidentWorkflow, *Response, error) { - return s.CreateContext(context.Background(), iw) -} - -// CreateContext creates a new incident workflow. -func (s *IncidentWorkflowService) CreateContext(ctx context.Context, iw *IncidentWorkflow) (*IncidentWorkflow, *Response, error) { - u := "/incident_workflows" - v := new(IncidentWorkflowPayload) - - resp, err := s.client.newRequestDoOptionsContext(ctx, "POST", u, nil, &IncidentWorkflowPayload{IncidentWorkflow: iw}, &v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v.IncidentWorkflow, resp, nil -} - -// Delete removes an existing incident workflow. -func (s *IncidentWorkflowService) Delete(id string) (*Response, error) { - return s.DeleteContext(context.Background(), id) -} - -// DeleteContext removes an existing incident workflow. -func (s *IncidentWorkflowService) DeleteContext(ctx context.Context, id string) (*Response, error) { - u := fmt.Sprintf("/incident_workflows/%s", id) - return s.client.newRequestDoOptionsContext(ctx, "DELETE", u, nil, nil, nil, incidentWorkflowsEarlyAccessHeader) -} - -// Update updates an existing incident workflow. -func (s *IncidentWorkflowService) Update(id string, iw *IncidentWorkflow) (*IncidentWorkflow, *Response, error) { - return s.UpdateContext(context.Background(), id, iw) -} - -// UpdateContext updates an existing incident workflow. -func (s *IncidentWorkflowService) UpdateContext(ctx context.Context, id string, iw *IncidentWorkflow) (*IncidentWorkflow, *Response, error) { - u := fmt.Sprintf("/incident_workflows/%s", id) - v := new(IncidentWorkflowPayload) - - resp, err := s.client.newRequestDoOptionsContext(ctx, "PUT", u, nil, &IncidentWorkflowPayload{IncidentWorkflow: iw}, &v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v.IncidentWorkflow, resp, nil -} diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger.go deleted file mode 100644 index df3a0228e..000000000 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger.go +++ /dev/null @@ -1,180 +0,0 @@ -package pagerduty - -import ( - "context" - "fmt" -) - -// IncidentWorkflowTriggerService handles the communication with incident workflow -// trigger related methods of the PagerDuty API. -type IncidentWorkflowTriggerService service - -// IncidentWorkflowTrigger represents an incident workflow. -type IncidentWorkflowTrigger struct { - ID string `json:"id,omitempty"` - Type string `json:"type,omitempty"` - TriggerType IncidentWorkflowTriggerType `json:"trigger_type,omitempty"` - Workflow *IncidentWorkflow `json:"workflow,omitempty"` - Services []*ServiceReference `json:"services,omitempty"` - Condition *string `json:"condition,omitempty"` - SubscribedToAllServices bool `json:"is_subscribed_to_all_services,omitempty"` -} - -// ListIncidentWorkflowTriggerResponse represents a list response of incident workflow triggers. -type ListIncidentWorkflowTriggerResponse struct { - Triggers []*IncidentWorkflowTrigger `json:"triggers,omitempty"` - NextPageToken string `json:"next_page_token,omitempty"` - Limit int `json:"limit,omitempty"` -} - -// IncidentWorkflowTriggerPayload represents payload with an incident workflow trigger object. -type IncidentWorkflowTriggerPayload struct { - Trigger *IncidentWorkflowTrigger `json:"trigger,omitempty"` -} - -// ListIncidentWorkflowTriggerOptions represents options when retrieving a list of incident workflow triggers. -type ListIncidentWorkflowTriggerOptions struct { - IncidentID string `url:"incident_id,omitempty"` - WorkflowID string `url:"workflow_id,omitempty"` - ServiceID string `url:"service_id,omitempty"` - TriggerType IncidentWorkflowTriggerType `url:"trigger_type,omitempty"` - Limit int `url:"limit,omitempty"` - PageToken string `url:"page_token,omitempty"` -} - -type listIncidentWorkflowTriggerOptionsGen struct { - options *ListIncidentWorkflowTriggerOptions -} - -func (o *listIncidentWorkflowTriggerOptionsGen) currentCursor() string { - return o.options.PageToken -} - -func (o *listIncidentWorkflowTriggerOptionsGen) changeCursor(s string) { - o.options.PageToken = s -} - -func (o *listIncidentWorkflowTriggerOptionsGen) buildStruct() interface{} { - return o.options -} - -// List lists existing incident workflow triggers. If a non-zero Limit is passed as an option, only a single page of results will be -// returned. Otherwise, the entire list of incident workflows will be returned. -func (s *IncidentWorkflowTriggerService) List(o *ListIncidentWorkflowTriggerOptions) (*ListIncidentWorkflowTriggerResponse, *Response, error) { - return s.ListContext(context.Background(), o) -} - -// ListContext lists existing incident workflow triggers. If a non-zero Limit is passed as an option, only a single page of results will be -// returned. Otherwise, the entire list of incident workflows will be returned. -func (s *IncidentWorkflowTriggerService) ListContext(ctx context.Context, o *ListIncidentWorkflowTriggerOptions) (*ListIncidentWorkflowTriggerResponse, *Response, error) { - u := "/incident_workflows/triggers" - v := new(ListIncidentWorkflowTriggerResponse) - - if o == nil { - o = &ListIncidentWorkflowTriggerOptions{} - } - - if o.Limit != 0 { - resp, err := s.client.newRequestDoOptionsContext(ctx, "GET", u, o, nil, &v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v, resp, nil - } else { - triggers := make([]*IncidentWorkflowTrigger, 0) - - // Create a handler closure capable of parsing data from the workflows endpoint - // and appending resultant response plays to the return slice. - responseHandler := func(response *Response) (CursorListResp, *Response, error) { - var result ListIncidentWorkflowTriggerResponse - - if err := s.client.DecodeJSON(response, &result); err != nil { - return CursorListResp{}, response, err - } - - triggers = append(triggers, result.Triggers...) - - // Return stats on the current page. Caller can use this information to - // adjust for requesting additional pages. - return CursorListResp{ - Limit: result.Limit, - NextCursor: result.NextPageToken, - }, response, nil - } - err := s.client.newRequestCursorPagedGetQueryDoContext(ctx, u, responseHandler, &listIncidentWorkflowTriggerOptionsGen{ - options: o, - }, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - v.Triggers = triggers - - return v, nil, nil - } -} - -// Get gets an incident workflow trigger. -func (s *IncidentWorkflowTriggerService) Get(id string) (*IncidentWorkflowTrigger, *Response, error) { - return s.GetContext(context.Background(), id) -} - -// GetContext gets an incident workflow trigger. -func (s *IncidentWorkflowTriggerService) GetContext(ctx context.Context, id string) (*IncidentWorkflowTrigger, *Response, error) { - u := fmt.Sprintf("/incident_workflows/triggers/%s", id) - v := new(IncidentWorkflowTriggerPayload) - - resp, err := s.client.newRequestDoOptionsContext(ctx, "GET", u, nil, nil, v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v.Trigger, resp, nil -} - -// Create creates a new incident workflow trigger. -func (s *IncidentWorkflowTriggerService) Create(t *IncidentWorkflowTrigger) (*IncidentWorkflowTrigger, *Response, error) { - return s.CreateContext(context.Background(), t) -} - -// CreateContext creates a new incident workflow trigger. -func (s *IncidentWorkflowTriggerService) CreateContext(ctx context.Context, t *IncidentWorkflowTrigger) (*IncidentWorkflowTrigger, *Response, error) { - u := "/incident_workflows/triggers" - v := new(IncidentWorkflowTriggerPayload) - - resp, err := s.client.newRequestDoOptionsContext(ctx, "POST", u, nil, &t, &v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v.Trigger, resp, nil -} - -// Delete removes an existing incident workflow trigger. -func (s *IncidentWorkflowTriggerService) Delete(id string) (*Response, error) { - return s.DeleteContext(context.Background(), id) -} - -// DeleteContext removes an existing incident workflow trigger. -func (s *IncidentWorkflowTriggerService) DeleteContext(ctx context.Context, id string) (*Response, error) { - u := fmt.Sprintf("/incident_workflows/triggers/%s", id) - return s.client.newRequestDoOptionsContext(ctx, "DELETE", u, nil, nil, nil, incidentWorkflowsEarlyAccessHeader) -} - -// Update updates an existing incident workflow trigger. -func (s *IncidentWorkflowTriggerService) Update(id string, t *IncidentWorkflowTrigger) (*IncidentWorkflowTrigger, *Response, error) { - return s.UpdateContext(context.Background(), id, t) -} - -// UpdateContext updates an existing incident workflow trigger. -func (s *IncidentWorkflowTriggerService) UpdateContext(ctx context.Context, id string, t *IncidentWorkflowTrigger) (*IncidentWorkflowTrigger, *Response, error) { - u := fmt.Sprintf("/incident_workflows/triggers/%s", id) - v := new(IncidentWorkflowTriggerPayload) - - resp, err := s.client.newRequestDoOptionsContext(ctx, "PUT", u, nil, &t, &v, incidentWorkflowsEarlyAccessHeader) - if err != nil { - return nil, nil, err - } - - return v.Trigger, resp, nil -} diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger_type.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger_type.go deleted file mode 100644 index c179a9c02..000000000 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/incident_workflow_trigger_type.go +++ /dev/null @@ -1,55 +0,0 @@ -package pagerduty - -import ( - "bytes" - "encoding/json" - "fmt" -) - -// IncidentWorkflowTriggerType is an enumeration of available types for incident workflow triggers. -type IncidentWorkflowTriggerType int64 - -const ( - IncidentWorkflowTriggerTypeUnknown IncidentWorkflowTriggerType = iota - IncidentWorkflowTriggerTypeManual - IncidentWorkflowTriggerTypeConditional -) - -func (d IncidentWorkflowTriggerType) String() string { - return incidentWorkflowTriggerTypeToString[d] -} - -func IncidentWorkflowTriggerTypeFromString(s string) IncidentWorkflowTriggerType { - return incidentWorkflowTriggerTypeFromString[s] -} - -var incidentWorkflowTriggerTypeToString = map[IncidentWorkflowTriggerType]string{ - IncidentWorkflowTriggerTypeUnknown: "unknown", - IncidentWorkflowTriggerTypeManual: "manual", - IncidentWorkflowTriggerTypeConditional: "conditional", -} - -var incidentWorkflowTriggerTypeFromString = map[string]IncidentWorkflowTriggerType{ - "unknown": IncidentWorkflowTriggerTypeUnknown, - "manual": IncidentWorkflowTriggerTypeManual, - "conditional": IncidentWorkflowTriggerTypeConditional, -} - -func (t IncidentWorkflowTriggerType) MarshalJSON() ([]byte, error) { - buffer := bytes.NewBufferString(fmt.Sprintf(`"%v"`, t.String())) - return buffer.Bytes(), nil -} - -func (t *IncidentWorkflowTriggerType) UnmarshalJSON(data []byte) error { - var str string - err := json.Unmarshal(data, &str) - if err != nil { - return err - } - *t = IncidentWorkflowTriggerTypeFromString(str) - return nil -} - -func (t *IncidentWorkflowTriggerType) IsKnown() bool { - return *t != IncidentWorkflowTriggerTypeUnknown -} diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go index 107c21f20..96fdb55ec 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go @@ -2,7 +2,6 @@ package pagerduty import ( "bytes" - "context" "encoding/json" "fmt" "io" @@ -62,9 +61,6 @@ type Client struct { OnCall *OnCallService AutomationActionsRunner *AutomationActionsRunnerService AutomationActionsAction *AutomationActionsActionService - Incidents *IncidentService - IncidentWorkflows *IncidentWorkflowService - IncidentWorkflowTriggers *IncidentWorkflowTriggerService } // Response is a wrapper around http.Response @@ -129,9 +125,6 @@ func NewClient(config *Config) (*Client, error) { c.OnCall = &OnCallService{c} c.AutomationActionsRunner = &AutomationActionsRunnerService{c} c.AutomationActionsAction = &AutomationActionsActionService{c} - c.Incidents = &IncidentService{c} - c.IncidentWorkflows = &IncidentWorkflowService{c} - c.IncidentWorkflowTriggers = &IncidentWorkflowTriggerService{c} InitCache(c) PopulateCache() @@ -140,10 +133,6 @@ func NewClient(config *Config) (*Client, error) { } func (c *Client) newRequest(method, url string, body interface{}, options ...RequestOptions) (*http.Request, error) { - return c.newRequestContext(context.Background(), method, url, body, options...) -} - -func (c *Client) newRequestContext(ctx context.Context, method, url string, body interface{}, options ...RequestOptions) (*http.Request, error) { var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) @@ -159,7 +148,7 @@ func (c *Client) newRequestContext(ctx context.Context, method, url string, body u := c.baseURL.String() + url - req, err := http.NewRequestWithContext(ctx, method, u, buf) + req, err := http.NewRequest(method, u, buf) if err != nil { return nil, err } @@ -182,10 +171,6 @@ func (c *Client) newRequestContext(ctx context.Context, method, url string, body } func (c *Client) newRequestDo(method, url string, qryOptions, body, v interface{}) (*Response, error) { - return c.newRequestDoContext(context.Background(), method, url, qryOptions, body, v) -} - -func (c *Client) newRequestDoContext(ctx context.Context, method, url string, qryOptions, body, v interface{}) (*Response, error) { if qryOptions != nil { values, err := query.Values(qryOptions) if err != nil { @@ -196,7 +181,7 @@ func (c *Client) newRequestDoContext(ctx context.Context, method, url string, qr url = fmt.Sprintf("%s?%s", url, v) } } - req, err := c.newRequestContext(ctx, method, url, body) + req, err := c.newRequest(method, url, body) if err != nil { return nil, err } @@ -204,10 +189,6 @@ func (c *Client) newRequestDoContext(ctx context.Context, method, url string, qr } func (c *Client) newRequestDoOptions(method, url string, qryOptions, body, v interface{}, reqOptions ...RequestOptions) (*Response, error) { - return c.newRequestDoOptionsContext(context.Background(), method, url, qryOptions, body, v, reqOptions...) -} - -func (c *Client) newRequestDoOptionsContext(ctx context.Context, method, url string, qryOptions, body, v interface{}, reqOptions ...RequestOptions) (*Response, error) { if qryOptions != nil { values, err := query.Values(qryOptions) if err != nil { @@ -218,7 +199,7 @@ func (c *Client) newRequestDoOptionsContext(ctx context.Context, method, url str url = fmt.Sprintf("%s?%s", url, v) } } - req, err := c.newRequestContext(ctx, method, url, body, reqOptions...) + req, err := c.newRequest(method, url, body, reqOptions...) if err != nil { return nil, err } @@ -268,55 +249,7 @@ type ListResp struct { // a specific slice. The responseHandler is responsible for closing the response. type responseHandler func(response *Response) (ListResp, *Response, error) -// CursorListResp represents a cursor-paginated list response from the PagerDuty API -type CursorListResp struct { - NextCursor string - Limit int -} - -// cursorResponseHandler is capable of parsing a response. At a minimum it must -// extract the page information for the current page. It can also execute -// additional necessary handling; for example, if a closure, it has access -// to the scope in which it was defined, and can be used to append data to -// a specific slice. The responseHandler is responsible for closing the response. -type cursorResponseHandler func(response *Response) (CursorListResp, *Response, error) - -// offsetQueryOptionsGen enables updating the offset across multiple -// pages of a list response while retaining query parameters other than the -// offset. For list-style functions where the underlying method supports -// other query parameters, this interface should be implemented to update -// the offset when fetching subsequent pages of results. -type offsetQueryOptionsGen interface { - currentOffset() int - changeOffset(int) - buildStruct() interface{} -} - -type simpleOffsetQueryOptionsGen struct { - offset int `url:"offset,omitempty"` -} - -func (o *simpleOffsetQueryOptionsGen) currentOffset() int { - return o.offset -} - -func (o *simpleOffsetQueryOptionsGen) changeOffset(i int) { - o.offset = i -} - -func (o *simpleOffsetQueryOptionsGen) buildStruct() interface{} { - return o -} - func (c *Client) newRequestPagedGetDo(basePath string, handler responseHandler, reqOptions ...RequestOptions) error { - return c.newRequestPagedGetQueryDo(basePath, handler, &simpleOffsetQueryOptionsGen{}, reqOptions...) -} - -func (c *Client) newRequestPagedGetQueryDo(basePath string, handler responseHandler, qryOptions offsetQueryOptionsGen, reqOptions ...RequestOptions) error { - return c.newRequestPagedGetQueryDoContext(context.Background(), basePath, handler, qryOptions, reqOptions...) -} - -func (c *Client) newRequestPagedGetQueryDoContext(ctx context.Context, basePath string, handler responseHandler, qryOptions offsetQueryOptionsGen, reqOptions ...RequestOptions) error { // Indicates whether there are still additional pages associated with request. var stillMore bool @@ -324,9 +257,8 @@ func (c *Client) newRequestPagedGetQueryDoContext(ctx context.Context, basePath var nextOffset int // While there are more pages, keep adjusting the offset to get all results. - for stillMore, nextOffset = true, qryOptions.currentOffset(); stillMore; { - qryOptions.changeOffset(nextOffset) - response, err := c.newRequestDoOptionsContext(ctx, "GET", basePath, qryOptions.buildStruct(), nil, nil, reqOptions...) + for stillMore, nextOffset = true, 0; stillMore; { + response, err := c.newRequestDoOptions("GET", fmt.Sprintf("%s?offset=%d", basePath, nextOffset), nil, nil, nil, reqOptions...) if err != nil { return err } @@ -345,50 +277,6 @@ func (c *Client) newRequestPagedGetQueryDoContext(ctx context.Context, basePath return nil } -// cursorQueryOptionsGen enables updating the cursor across multiple -// pages of a list response while retaining query parameters other than the -// cursor. For list-style functions where the underlying method supports -// other query parameters, this interface should be implemented to update -// the cursor when fetching subsequent pages of results. -type cursorQueryOptionsGen interface { - currentCursor() string - changeCursor(string) - buildStruct() interface{} -} - -func (c *Client) newRequestCursorPagedGetQueryDo(basePath string, handler cursorResponseHandler, qryOptions cursorQueryOptionsGen, reqOptions ...RequestOptions) error { - return c.newRequestCursorPagedGetQueryDoContext(context.Background(), basePath, handler, qryOptions, reqOptions...) -} - -func (c *Client) newRequestCursorPagedGetQueryDoContext(ctx context.Context, basePath string, handler cursorResponseHandler, qryOptions cursorQueryOptionsGen, reqOptions ...RequestOptions) error { - // Indicates whether there are still additional pages associated with request. - var stillMore bool - - // Cursor to set for the next page request. - var nextCursor string - - // While there are more pages, keep adjusting the offset to get all results. - for stillMore, nextCursor = true, qryOptions.currentCursor(); stillMore; { - qryOptions.changeCursor(nextCursor) - response, err := c.newRequestDoOptionsContext(ctx, "GET", basePath, qryOptions.buildStruct(), nil, nil, reqOptions...) - if err != nil { - return err - } - - // Call handler to extract page information and execute additional necessary handling. - pageInfo, _, err := handler(response) - if err != nil { - return err - } - - // Bump the offset as necessary and set whether more results exist. - nextCursor = pageInfo.NextCursor - stillMore = nextCursor != "" - } - - return nil -} - // ValidateAuth validates a token against the PagerDuty API func (c *Client) ValidateAuth() error { _, _, err := c.Abilities.List() diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/references.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/references.go index 8ae069a9f..1cbe818a8 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/references.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/references.go @@ -54,7 +54,3 @@ type RulesetReference resourceReference // SubscriberReference represents a reference to a subscriber schema type SubscriberReference resourceReference - -// IncidentAttributeReference represents a reference to a Incident -// Attribute schema -type IncidentAttributeReference resourceReference diff --git a/vendor/modules.txt b/vendor/modules.txt index 38942a738..85350940c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -122,7 +122,7 @@ github.com/hashicorp/terraform-registry-address github.com/hashicorp/terraform-svchost # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/heimweh/go-pagerduty v0.0.0-20221222221341-c1c27ca3744a +# github.com/heimweh/go-pagerduty v0.0.0-20221222221341-c1c27ca3744a => github.com/mrdubr/go-pagerduty v0.0.0-20221222163503-5363648f2b40 ## explicit github.com/heimweh/go-pagerduty/pagerduty # github.com/klauspost/compress v1.15.9 @@ -349,3 +349,4 @@ google.golang.org/protobuf/types/known/anypb google.golang.org/protobuf/types/known/durationpb google.golang.org/protobuf/types/known/emptypb google.golang.org/protobuf/types/known/timestamppb +# github.com/heimweh/go-pagerduty => github.com/mrdubr/go-pagerduty v0.0.0-20221222163503-5363648f2b40