Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring cleaning #1

Merged
merged 67 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e29882a
Fixing structs within user.go
Mar 29, 2017
dcfd84e
Adding new fields to Vendor
Mar 29, 2017
48b2bb6
Adding vendor_list command
Mar 29, 2017
ddea1d0
Adding vendor_show command
Mar 29, 2017
586fde7
Updating incident.go
Mar 29, 2017
6d8d374
Fixed spelling, entires->entries
Apr 3, 2017
5fc1b0b
Added GetUserContactMethod and updated ContactMethod
wvdeutekom Sep 13, 2017
8207ed9
Added json fields to structs
Oct 10, 2017
c54e2a4
List a user's contact methods
facundoagriel Oct 23, 2017
01af727
Add oncall details
luqasn Nov 20, 2017
88a2b2f
Get a list of alerts for a given incident id.
pushkarsawant Jan 15, 2018
bb01249
Added From parameter to createNote function
Feb 1, 2018
f8f10c4
Updated incident.go to reflect current api documentation
averstappen Mar 27, 2018
91fdfd9
Added is_mergeable property to Incident.
averstappen Mar 30, 2018
5f7f220
Add MergeIncidents (using Incident)
atomicules Mar 31, 2018
04b7711
Fixing json conversion error (alertcounts -> alert_counts)
averstappen Apr 4, 2018
527a14f
rename CreateMaintenanceWindows func to CreateMaintenanceWindow to re…
wdhnl Jul 20, 2018
b243f45
CreateIncident takes CreateIncidentOptions param
wdhnl Jul 20, 2018
9a0faae
services
Sep 6, 2018
211a447
Add src to cd $GOPATH instruction
ryanhall07 Oct 5, 2018
801c4af
Add ListContactMethods and GetContactMethod
Oct 27, 2018
793dd56
Fix incident struct to behave as API expects
DennyLoko Feb 26, 2019
f1eb6f8
Add V2 Event Management to the CLI
philnielsen Feb 26, 2019
2390260
Merge branch 'feature/struct-fix-user' of github.com:domudall/go-page…
dobs Mar 15, 2019
ebda46e
Merge branch 'domudall-feature/struct-fix-user' into spring-cleaning
dobs Mar 15, 2019
2848d14
Merge branch 'feature/vendor-cli' of github.com:domudall/go-pagerduty…
dobs Mar 15, 2019
71286ea
Merge branch 'domudall-feature/vendor-cli' into spring-cleaning
dobs Mar 15, 2019
3bc727b
Merge branch 'feature/struct-fix-vendor' of github.com:domudall/go-pa…
dobs Mar 15, 2019
0dad006
Merge branch 'domudall-feature/struct-fix-vendor' into spring-cleaning
dobs Mar 15, 2019
2dc12be
Resolving merge conflicts.
dobs Mar 15, 2019
0e76aeb
Merge branch 'domudall-feature/incident-structs' into spring-cleaning
dobs Mar 15, 2019
49d3aa2
Merge branch 'spellfix' of github.com:lowesoftware/go-pagerduty into …
dobs Mar 18, 2019
f623ae2
Merge branch 'lowesoftware-spellfix' into spring-cleaning
dobs Mar 18, 2019
74a2b12
Merge branch 'add-user-contact-methods' of github.com:wvdeutekom/go-p…
dobs Mar 18, 2019
dd40641
Spelling correction.
dobs Mar 18, 2019
c1a6c6d
Resolving merge conflicts.
dobs Mar 18, 2019
d29cbc5
Resolving merge conflicts.
dobs Mar 18, 2019
567fdc8
Correcting `timezone` to `time_zone` to match API, and for consistency.
dobs Mar 18, 2019
5f6fa35
Merge branch 'master' of github.com:bradleyrobinson/go-pagerduty into…
dobs Mar 18, 2019
9c00ddb
Merge branch 'bradleyrobinson-master' into spring-cleaning
dobs Mar 18, 2019
8ba4f8e
Merge branch 'list-user-contacts' of github.com:facundoagriel/go-page…
dobs Mar 18, 2019
77ebfba
Merge branch 'facundoagriel-list-user-contacts' into spring-cleaning
dobs Mar 18, 2019
9f75a77
Merge branch 'add-details-to-oncall-json' of github.com:luqasn/go-pag…
dobs Mar 18, 2019
19282fd
Merge branch 'luqasn-add-details-to-oncall-json' into spring-cleaning
dobs Mar 18, 2019
10e60bd
Merge branch 'get-alert-list' of github.com:pushkar-engagio/go-pagerd…
dobs Mar 18, 2019
cd4ea80
Merge branch 'pushkar-engagio-get-alert-list' into spring-cleaning
dobs Mar 18, 2019
a97d1d0
Resolving merge conflicts and updating format.
dobs Mar 18, 2019
4ba7828
Resolving merge conflicts.
dobs Mar 18, 2019
fa499cd
Resolving merge conflicts, plus formatting.
dobs Mar 18, 2019
52bc170
Resolving merge conflicts, plus some cleaning.
dobs Mar 18, 2019
ef3c20b
Merge branch 'merge-incidents-opt1' of github.com:atomicules/go-pager…
dobs Mar 18, 2019
70ef366
Minor comment adjustment.
dobs Mar 19, 2019
e44cfd6
Merge branch 'atomicules-merge-incidents-opt1' into spring-cleaning
dobs Mar 19, 2019
60e290c
Formatting.
dobs Mar 19, 2019
a1969db
Merge branch 'feature/fix-create-maintenance-window' of github.com:wd…
dobs Mar 19, 2019
62648df
Merge branch 'wdhnl-feature/fix-create-maintenance-window' into sprin…
dobs Mar 19, 2019
4bddafc
Adding `CreateMaintenanceWindows` back.
dobs Mar 19, 2019
85e2d53
Merge branch 'feature/fix-create-incident-options' of github.com:wdhn…
dobs Mar 19, 2019
a97b7f0
Merge branch 'wdhnl-feature/fix-create-incident-options' into spring-…
dobs Mar 19, 2019
975d068
Merge branch 'master' of github.com:ryanhall07/go-pagerduty into ryan…
dobs Mar 19, 2019
fb12219
Merge branch 'ryanhall07-master' into spring-cleaning
dobs Mar 19, 2019
822062f
Merge branch 'get-contact-method' of github.com:monzo/go-pagerduty in…
dobs Mar 19, 2019
85d85a1
Resolving merge conflicts.
dobs Mar 19, 2019
12be305
Merge branch 'fix-incident-struct' of github.com:DennyLoko/go-pagerdu…
dobs Mar 19, 2019
b061e87
Merge branch 'DennyLoko-fix-incident-struct' into spring-cleaning
dobs Mar 19, 2019
3ad35ea
Merge branch 'events-v2-cli' of github.com:philnielsen/go-pagerduty i…
dobs Mar 19, 2019
850eb75
Merge branch 'philnielsen-events-v2-cli' into spring-cleaning
dobs Mar 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ API represented by their own sub commands. For an exhaustive list of sub-command

__Install:__
```
cd $GOPATH/github.com/PagerDuty/go-pagerduty
cd $GOPATH/src/github.com/PagerDuty/go-pagerduty
go build -o $GOPATH/bin/pd command/*
```

Expand Down
67 changes: 67 additions & 0 deletions command/event_v2_manage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"encoding/json"
"fmt"
"os"
"strings"

pagerduty "github.com/PagerDuty/go-pagerduty"
log "github.com/Sirupsen/logrus"
"github.com/mitchellh/cli"
)

type EventV2Manage struct {
Meta
}

func EventV2ManageCommand() (cli.Command, error) {
return &EventV2Manage{}, nil
}

func (c *EventV2Manage) Help() string {
helpText := `
pd event-v2 manage <FILE> Manage Events from json file
` + c.Meta.Help()
return strings.TrimSpace(helpText)
}

func (c *EventV2Manage) Synopsis() string {
return "Create a New V2 Event"
}

func (c *EventV2Manage) Run(args []string) int {
flags := c.Meta.FlagSet("event-v2 manage")
flags.Usage = func() { fmt.Println(c.Help()) }
if err := flags.Parse(args); err != nil {
log.Error(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}
var e pagerduty.V2Event
if len(flags.Args()) != 1 {
log.Error("Please specify input json file")
return -1
}
log.Info("Input file is: ", flags.Arg(0))
f, err := os.Open(flags.Arg(0))
if err != nil {
log.Error(err)
return -1
}
defer f.Close()
decoder := json.NewDecoder(f)
if err := decoder.Decode(&e); err != nil {
log.Errorln("Failed to decode json. Error:", err)
return -1
}
log.Debugf("%#v", e)
if _, err := pagerduty.ManageEvent(e); err != nil {
log.Error(err)
return -1
}
return 0
}
5 changes: 5 additions & 0 deletions command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func loadCommands() map[string]cli.CommandFactory {
"escalation-policy show": EscalationPolicyShowCommand,
"escalation-policy update": EscalationPolicyUpdateCommand,

"event-v2 manage": EventV2ManageCommand,

"incident list": IncidentListCommand,
"incident manage": IncidentManageCommand,
"incident show": IncidentShowCommand,
Expand Down Expand Up @@ -92,6 +94,9 @@ func loadCommands() map[string]cli.CommandFactory {
"user notification-rule delete": UserNotificationRuleDeleteCommand,
"user notification-rule show": UserNotificationRuleShowCommand,
"user notification-rule update": UserNotificationRuleUpdateCommand,

"vendor list": VendorListCommand,
"vendor show": VendorShowCommand,
}
}

Expand Down
71 changes: 71 additions & 0 deletions command/vendor_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/Sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
)

type VendorList struct {
Meta
}

func VendorListCommand() (cli.Command, error) {
return &VendorList{}, nil
}

func (c *VendorList) Help() string {
helpText := `
pd vendor list List vendors

Options:

-query Filter vendors with certain name

`
return strings.TrimSpace(helpText)
}

func (c *VendorList) Synopsis() string {
return "List vendors within PagerDuty, optionally filtered by a search query"
}

func (c *VendorList) Run(args []string) int {
var query string

flags := c.Meta.FlagSet("user list")
flags.Usage = func() { fmt.Println(c.Help()) }
flags.StringVar(&query, "query", "", "Show vendors whose names contain the query")

if err := flags.Parse(args); err != nil {
log.Error(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}
client := c.Meta.Client()
opts := pagerduty.ListVendorOptions{
Query: query,
}
if resp, err := client.ListVendors(opts); err != nil {
log.Error(err)
return -1
} else {
for i, p := range resp.Vendors {
fmt.Println("Entry: ", i)
data, err := yaml.Marshal(p)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
}
}

return 0
}
63 changes: 63 additions & 0 deletions command/vendor_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/mitchellh/cli"
"gopkg.in/yaml.v2"
"strings"
)

type VendorShow struct {
Meta
}

func VendorShowCommand() (cli.Command, error) {
return &VendorShow{}, nil
}

func (c *VendorShow) Help() string {
helpText := `
vendor show Show details of an individual vendor

Options:
-id Vendor ID
`
return strings.TrimSpace(helpText)
}

func (c *VendorShow) Synopsis() string { return "Get details about a vendor" }

func (c *VendorShow) Run(args []string) int {
log.Println(args)
var id string
flags := c.Meta.FlagSet("vendor show")
flags.Usage = func() { fmt.Println(c.Help()) }
flags.StringVar(&id, "id", "", "Vendor ID")
if err := flags.Parse(args); err != nil {
log.Errorln(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}

if id == "" {
log.Error("You must specify the vendor id using -id flag")
return -1
}
client := c.Meta.Client()
result, err := client.GetVendor(id)
if err != nil {
log.Error(err)
return -1
}
data, err := yaml.Marshal(result)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
return 0
}
62 changes: 62 additions & 0 deletions contact_method.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package pagerduty

import (
"fmt"
"net/http"
)

// ContactMethod is a way of contacting the user.
type ContactMethod struct {
ID string `json:"id"`
Type string `json:"type"`
Summary string `json:"summary"`
Self string `json:"self"`
Label string `json:"label"`
Address string `json:"address"`
SendShortEmail bool `json:"send_short_email,omitempty"`
SendHTMLEmail bool `json:"send_html_email,omitempty"`
Blacklisted bool `json:"blacklisted,omitempty"`
CountryCode int `json:"country_code,omitempty"`
Enabled bool `json:"enabled,omitempty"`
HTMLUrl string `json:"html_url"`
}


// ListContactMethodsResponse is the data structure returned from calling the ListContactMethods API endpoint.
type ListContactMethodsResponse struct {
APIListObject
ContactMethods []ContactMethod
}

// ListContactMethods lists all contact methods for a user.
// TODO: Unify with `ListUserContactMethods`.
func (c *Client) ListContactMethods(userID string) (*ListContactMethodsResponse, error) {
resp, err := c.get("/users/" + userID + "/contact_methods")
if err != nil {
return nil, err
}
var result ListContactMethodsResponse
return &result, c.decodeJSON(resp, &result)
}

// GetContactMethod gets details about a contact method.
func (c *Client) GetContactMethod(userID, id string) (*ContactMethod, error) {
resp, err := c.get("/users/" + userID + "/contact_methods/" + id)
return getContactMethodFromResponse(c, resp, err)
}

func getContactMethodFromResponse(c *Client, resp *http.Response, err error) (*ContactMethod, error) {
if err != nil {
return nil, err
}
var target map[string]ContactMethod
if dErr := c.decodeJSON(resp, &target); dErr != nil {
return nil, fmt.Errorf("Could not decode JSON response: %v", dErr)
}
rootNode := "contact_method"
t, nodeOK := target[rootNode]
if !nodeOK {
return nil, fmt.Errorf("JSON response does not have %s field", rootNode)
}
return &t, nil
}
2 changes: 1 addition & 1 deletion escalation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type EscalationPolicy struct {
APIObject
Name string `json:"name,omitempty"`
EscalationRules []EscalationRule `json:"escalation_rules,omitempty"`
Services []APIReference `json:"services,omitempty"`
Services []APIObject `json:"services,omitempty"`
NumLoops uint `json:"num_loops,omitempty"`
Teams []APIReference `json:"teams,omitempty"`
Description string `json:"description,omitempty"`
Expand Down
Loading