-
Notifications
You must be signed in to change notification settings - Fork 0
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
adding in bascis for victorops #3
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,12 @@ type Pager interface { | |
PopulateTeamSchedules(ctx context.Context, team *Team) error | ||
} | ||
|
||
func NewPager(kind string, apiKey string) (Pager, error) { | ||
func NewPager(kind string, apiKey string, appId string) (Pager, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
switch strings.ToLower(kind) { | ||
case "pagerduty": | ||
return NewPagerDuty(apiKey), nil | ||
case "victorops": | ||
return NewVictorOps(apiKey, appId), nil | ||
} | ||
return nil, fmt.Errorf("%w '%s'", ErrUnknownProvider, kind) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||
package pager | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
|
||||||
"github.com/gosimple/slug" | ||||||
"github.com/victorops/go-victorops/victorops" | ||||||
) | ||||||
|
||||||
type VictorOps struct { | ||||||
client *victorops.Client | ||||||
} | ||||||
|
||||||
func NewVictorOps(apiKey string, appId string) *VictorOps { | ||||||
return &VictorOps{ | ||||||
client: victorops.NewClient(appId, apiKey, "https://api.victorops.com"), | ||||||
} | ||||||
} | ||||||
|
||||||
func (v *VictorOps) Kind() string { | ||||||
return "victorops" | ||||||
} | ||||||
|
||||||
func (v *VictorOps) PopulateTeamMembers(ctx context.Context, team *Team) error { | ||||||
members := []*User{} | ||||||
|
||||||
vmembers, _, err := v.client.GetTeamMembers(team.ID) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
for _, member := range vmembers.Members { | ||||||
members = append(members, &User{Resource: Resource{ID: member.Username}}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh i made the bad example on pagerduty for this one huh woops |
||||||
} | ||||||
|
||||||
team.Members = members | ||||||
return nil | ||||||
} | ||||||
|
||||||
func (v *VictorOps) PopulateTeamSchedules(ctx context.Context, team *Team) error { | ||||||
// TODO: implement | ||||||
return nil | ||||||
} | ||||||
|
||||||
func (v *VictorOps) ListTeams(ctx context.Context) ([]*Team, error) { | ||||||
teams := []*Team{} | ||||||
|
||||||
vteams, _, err := v.client.GetAllTeams() | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
for _, team := range *vteams { | ||||||
teams = append(teams, v.toTeam(team)) | ||||||
} | ||||||
|
||||||
return teams, nil | ||||||
} | ||||||
|
||||||
func (v *VictorOps) toTeam(team victorops.Team) *Team { | ||||||
return &Team{ | ||||||
// PagerDuty does not expose a slug, so generate one. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this with my last push |
||||||
Slug: slug.Make(team.Name), | ||||||
Resource: Resource{ | ||||||
ID: team.Slug, | ||||||
Name: team.Name, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
func (v *VictorOps) ListUsers(ctx context.Context) ([]*User, error) { | ||||||
users := []*User{} | ||||||
|
||||||
vusers, _, err := v.client.GetAllUsers() | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
for _, userSlice := range vusers.Users { | ||||||
for _, user := range userSlice { | ||||||
users = append(users, v.toUser(user)) | ||||||
} | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops I missed this first time around: probably should use GetAllUserV2 here https://pkg.go.dev/github.com/victorops/go-victorops@v1.0.7/victorops#Client.GetAllUserV2 |
||||||
|
||||||
return users, nil | ||||||
} | ||||||
|
||||||
func (v *VictorOps) toUser(user victorops.User) *User { | ||||||
return &User{ | ||||||
Email: user.Email, | ||||||
Resource: Resource{ | ||||||
ID: user.Username, | ||||||
Name: user.FirstName + " " + user.LastName, | ||||||
}, | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting... this shouldn't be
indirect
. might need to rungo mod tidy
, which reminds me i should add that in CI.