Skip to content

Commit

Permalink
Second batch of fixes for API incompatibilities
Browse files Browse the repository at this point in the history
Updates #389
  • Loading branch information
theckman committed Jan 18, 2022
1 parent 77a73c9 commit 834a5e4
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 92 deletions.
11 changes: 6 additions & 5 deletions extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import (
// features to be used as part of the incident management process.
type Extension struct {
APIObject
Name string `json:"name"`
EndpointURL string `json:"endpoint_url,omitempty"`
ExtensionObjects []APIObject `json:"extension_objects"`
ExtensionSchema APIObject `json:"extension_schema"`
Config interface{} `json:"config"`
Name string `json:"name"`
EndpointURL string `json:"endpoint_url,omitempty"`
ExtensionObjects []APIObject `json:"extension_objects"`
ExtensionSchema APIObject `json:"extension_schema"`
Config interface{} `json:"config"`
TemporarilyDisabled bool `json:"temporarily_disabled,omitempty"`
}

// ListExtensionResponse represents the single response from the PagerDuty API
Expand Down
24 changes: 10 additions & 14 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Incident struct {
AssignedVia string `json:"assigned_via,omitempty"`
Occurrence *Occurrence `json:"occurrence,omitempty"`
IncidentResponders []IncidentResponders `json:"incidents_responders,omitempty"`
ResponderRequests []ResponderRequest `json:"responder_requests,omitempty"`
}

// ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.
Expand Down Expand Up @@ -659,26 +660,21 @@ type ResponderRequestTarget struct {
Responders IncidentResponders `json:"incident_responders"`
}

// ResponderRequestTargets is a wrapper for a ResponderRequestTarget.
type ResponderRequestTargets struct {
Target ResponderRequestTarget `json:"responder_request_target"`
}

// ResponderRequestOptions defines the input options for the Create Responder function.
type ResponderRequestOptions struct {
From string `json:"-"`
Message string `json:"message"`
RequesterID string `json:"requester_id"`
Targets []ResponderRequestTargets `json:"responder_request_targets"`
From string `json:"-"`
Message string `json:"message"`
RequesterID string `json:"requester_id"`
Targets []ResponderRequestTarget `json:"responder_request_targets"`
}

// ResponderRequest contains the API structure for an incident responder request.
type ResponderRequest struct {
Incident Incident `json:"incident"`
Requester User `json:"requester,omitempty"`
RequestedAt string `json:"request_at,omitempty"`
Message string `json:"message,omitempty"`
Targets []ResponderRequestTargets `json:"responder_request_targets"`
Incident Incident `json:"incident"`
Requester User `json:"requester,omitempty"`
RequestedAt string `json:"request_at,omitempty"`
Message string `json:"message,omitempty"`
Targets []ResponderRequestTarget `json:"responder_request_targets"`
}

// ResponderRequest will submit a request to have a responder join an incident.
Expand Down
22 changes: 8 additions & 14 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,12 @@ func TestIncident_ResponderRequest(t *testing.T) {
},
"message": "Help",
"responder_request_targets": [{
"responder_request_target": {
"id": "PJ25ZYX",
"type": "user_reference",
"incident_responders": {
"state": "pending",
"user": {
"id": "PJ25ZYX"
}
"id": "PJ25ZYX",
"type": "user_reference",
"incident_responders": {
"state": "pending",
"user": {
"id": "PJ25ZYX"
}
}
}]
Expand All @@ -829,9 +827,7 @@ func TestIncident_ResponderRequest(t *testing.T) {
r.ID = "PJ25ZYX"
r.Type = "user_reference"

targets := []ResponderRequestTargets{
ResponderRequestTargets{Target: r},
}
targets := []ResponderRequestTarget{r}

input := ResponderRequestOptions{
From: from,
Expand All @@ -850,9 +846,7 @@ func TestIncident_ResponderRequest(t *testing.T) {
target.Responders.State = "pending"
target.Responders.User.ID = "PJ25ZYX"

targets = []ResponderRequestTargets{
ResponderRequestTargets{Target: target},
}
targets = []ResponderRequestTarget{target}

want := &ResponderRequestResponse{
ResponderRequest: ResponderRequest{
Expand Down
1 change: 1 addition & 0 deletions log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type ListLogEntriesOptions struct {
Until string `url:"until,omitempty"`
IsOverview bool `url:"is_overview,omitempty"`
Includes []string `url:"include,omitempty,brackets"`
TeamIDs []string `url:"team_ids,omitempty,brackets"`
}

// ListLogEntries lists all of the incident log entries across the entire
Expand Down
14 changes: 7 additions & 7 deletions maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
// MaintenanceWindow is used to temporarily disable one or more services for a set period of time.
type MaintenanceWindow struct {
APIObject
SequenceNumber uint `json:"sequence_number,omitempty"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Description string `json:"description"`
Services []APIObject `json:"services"`
Teams []APIListObject `json:"teams"`
CreatedBy APIListObject `json:"created_by"`
SequenceNumber uint `json:"sequence_number,omitempty"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Description string `json:"description"`
Services []APIObject `json:"services"`
Teams []APIObject `json:"teams,omitempty"`
CreatedBy *APIObject `json:"created_by,omitempty"`
}

// ListMaintenanceWindowsResponse is the data structur returned from calling the ListMaintenanceWindows API endpoint.
Expand Down
12 changes: 7 additions & 5 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (

// Notification is a message containing the details of the incident.
type Notification struct {
ID string `json:"id"`
Type string
StartedAt string `json:"started_at"`
Address string
User APIObject
ID string `json:"id"`
Type string `json:"type"`
StartedAt string `json:"started_at"`
Address string `json:"address"`
User APIObject `json:"user"`
ConferenceAddress string `json:"conferenceAddress"`
Status string `json:"status"`
}

// ListNotificationOptions is the data structure used when calling the ListNotifications API endpoint.
Expand Down
38 changes: 28 additions & 10 deletions ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ type Ruleset struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Self string `json:"self,omitempty"`
RoutingKeys []string `json:"routing_keys,omitempty"`
Team *RulesetObject `json:"team,omitempty"`
Updater *RulesetObject `json:"updater,omitempty"`
CreatedAt string `json:"created_at"`
Creator *RulesetObject `json:"creator,omitempty"`
UpdatedAt string `json:"updated_at"`
Updater *RulesetObject `json:"updater,omitempty"`
Team *RulesetObject `json:"team,omitempty"`
}

// RulesetObject represents a generic object that is common within a ruleset object
type RulesetObject struct {
Type string `json:"type,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Self string `json:"self,omitempty"`
}

// RulesetPayload represents payload with a ruleset object
Expand All @@ -40,12 +44,12 @@ type ListRulesetsResponse struct {
// RulesetRule represents a Ruleset rule
type RulesetRule struct {
ID string `json:"id,omitempty"`
Self string `json:"self,omitempty"`
Position *int `json:"position,omitempty"`
Disabled bool `json:"disabled,omitempty"`
Conditions *RuleConditions `json:"conditions,omitempty"`
Actions *RuleActions `json:"actions,omitempty"`
Ruleset *APIObject `json:"ruleset,omitempty"`
Self string `json:"self,omitempty"`
CatchAll bool `json:"catch_all,omitempty"`
TimeFrame *RuleTimeFrame `json:"time_frame,omitempty"`
}
Expand Down Expand Up @@ -81,16 +85,29 @@ type RuleTimeFrame struct {

// ScheduledWeekly represents a time_frame object for scheduling rules weekly
type ScheduledWeekly struct {
Weekdays []int `json:"weekdays,omitempty"`
Timezone string `json:"timezone,omitempty"`
StartTime int `json:"start_time,omitempty"`
Duration int `json:"duration,omitempty"`
// Weekdays is a 0 indexed slice of days, where 0 is Sunday and 6 is
// Saturday, when the window is scheduled for.
Weekdays []int `json:"weekdays,omitempty"`

Timezone string `json:"timezone,omitempty"`

// StartTime is the number of milliseconds into the day at which the window
// starts.
StartTime int `json:"start_time,omitempty"`

// Duration is the window duration in milliseconds.
Duration int `json:"duration,omitempty"`
}

// ActiveBetween represents an active_between object for setting a timeline for rules
type ActiveBetween struct {
// StartTime is in the number of milliseconds into the day at which the
// window starts.
StartTime int `json:"start_time,omitempty"`
EndTime int `json:"end_time,omitempty"`

// EndTime is the number of milliseconds into the day at which the window
// ends.
EndTime int `json:"end_time,omitempty"`
}

// ListRulesetRulesResponse represents a list of rules in a ruleset
Expand Down Expand Up @@ -129,7 +146,8 @@ type RuleActionSuppress struct {

// RuleActionSuspend represents a rule suspend action object
type RuleActionSuspend struct {
Value *bool `json:"value,omitempty"`
// Value specifies for how long to suspend the alert in seconds.
Value int `json:"value,omitempty"`
}

// RuleActionExtraction represents a rule extraction action object
Expand Down
17 changes: 9 additions & 8 deletions tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ func (c *Client) AssignTags(e, eid string, a *TagAssignments) error {
}

// AssignTagsWithContext adds and removes tag assignments with entities.
func (c *Client) AssignTagsWithContext(ctx context.Context, e, eid string, a *TagAssignments) error {
_, err := c.post(ctx, "/"+e+"/"+eid+"/change_tags", a, nil)
// Permitted entity types are users, teams, and escalation_policies.
func (c *Client) AssignTagsWithContext(ctx context.Context, entityType, entityID string, a *TagAssignments) error {
_, err := c.post(ctx, "/"+entityType+"/"+entityID+"/change_tags", a, nil)
if err != nil {
return err
}
Expand All @@ -178,7 +179,7 @@ func (c *Client) GetUsersByTag(tid string) (*ListUserResponse, error) {
// GetUsersByTagPaginated gets related user references based on the tag. To get the
// full info of the user, you will need to iterate over the returned slice
// and get that user's details.
func (c *Client) GetUsersByTagPaginated(ctx context.Context, tid string) ([]*APIObject, error) {
func (c *Client) GetUsersByTagPaginated(ctx context.Context, tagID string) ([]*APIObject, error) {
var users []*APIObject

// Create a handler closure capable of parsing data from the business_services endpoint
Expand All @@ -201,7 +202,7 @@ func (c *Client) GetUsersByTagPaginated(ctx context.Context, tid string) ([]*API
}

// Make call to get all pages associated with the base endpoint.
if err := c.pagedGet(ctx, "/tags/"+tid+"/users/", responseHandler); err != nil {
if err := c.pagedGet(ctx, "/tags/"+tagID+"/users/", responseHandler); err != nil {
return nil, err
}

Expand All @@ -226,7 +227,7 @@ func (c *Client) GetTeamsByTag(tid string) (*ListTeamsForTagResponse, error) {
// GetTeamsByTagPaginated gets related teams based on the tag. To get the full
// info of the team, you will need to iterate over the returend slice and get
// that team's details.
func (c *Client) GetTeamsByTagPaginated(ctx context.Context, tid string) ([]*APIObject, error) {
func (c *Client) GetTeamsByTagPaginated(ctx context.Context, tagID string) ([]*APIObject, error) {
var teams []*APIObject

// Create a handler closure capable of parsing data from the business_services endpoint
Expand All @@ -249,7 +250,7 @@ func (c *Client) GetTeamsByTagPaginated(ctx context.Context, tid string) ([]*API
}

// Make call to get all pages associated with the base endpoint.
if err := c.pagedGet(ctx, "/tags/"+tid+"/teams/", responseHandler); err != nil {
if err := c.pagedGet(ctx, "/tags/"+tagID+"/teams/", responseHandler); err != nil {
return nil, err
}

Expand All @@ -275,7 +276,7 @@ func (c *Client) GetEscalationPoliciesByTag(tid string) (*ListEPResponse, error)
// GetEscalationPoliciesByTagPaginated gets related escalation policies based on
// the tag. To get the full info of the EP, you will need to iterate over the
// returend slice and get that policy's details.
func (c *Client) GetEscalationPoliciesByTagPaginated(ctx context.Context, tid string) ([]*APIObject, error) {
func (c *Client) GetEscalationPoliciesByTagPaginated(ctx context.Context, tagID string) ([]*APIObject, error) {
var eps []*APIObject

// Create a handler closure capable of parsing data from the business_services endpoint
Expand All @@ -298,7 +299,7 @@ func (c *Client) GetEscalationPoliciesByTagPaginated(ctx context.Context, tid st
}

// Make call to get all pages associated with the base endpoint.
if err := c.pagedGet(ctx, "/tags/"+tid+"/escalation_policies/", responseHandler); err != nil {
if err := c.pagedGet(ctx, "/tags/"+tagID+"/escalation_policies/", responseHandler); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 834a5e4

Please sign in to comment.