Skip to content

Commit

Permalink
Opsgenie Plugin support schedules/teams ID and Name (#44381)
Browse files Browse the repository at this point in the history
* Opsgenie Plugin support schedules/teams ID and Name

Signed-off-by: Edward Dowling <[email protected]>

* Replace regex by UUID parser

Signed-off-by: Edward Dowling <[email protected]>

---------

Signed-off-by: Edward Dowling <[email protected]>
Co-authored-by: Carlos Castro <[email protected]>
  • Loading branch information
EdwardDowling and carloscastrojumo authored Jul 26, 2024
1 parent e6ff706 commit bc6e4c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
27 changes: 17 additions & 10 deletions integrations/access/opsgenie/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/aws/aws-sdk-go/aws/defaults"
"github.com/go-resty/resty/v2"
"github.com/google/uuid"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"

Expand Down Expand Up @@ -219,22 +220,28 @@ func (og Client) getResponders(reqData RequestData) []Responder {
}
responders := make([]Responder, 0, len(schedules)+len(teams))
for _, s := range schedules {
responders = append(responders, Responder{
Type: ResponderTypeSchedule,
ID: s,
Name: s,
})
responders = append(responders, createResponder(ResponderTypeSchedule, s))
}
for _, t := range teams {
responders = append(responders, Responder{
Type: ResponderTypeTeam,
ID: t,
Name: t,
})
responders = append(responders, createResponder(ResponderTypeTeam, t))
}
return responders
}

// Check if the responder is a UUID. If it is, then it is an ID; otherwise, it is a name.
func createResponder(responderType string, value string) Responder {
if _, err := uuid.Parse(value); err == nil {
return Responder{
Type: responderType,
ID: value,
}
}
return Responder{
Type: responderType,
Name: value,
}
}

// PostReviewNote posts a note once a new request review appears.
func (og Client) PostReviewNote(ctx context.Context, alertID string, review types.AccessReview) error {
note, err := buildReviewNoteBody(review)
Expand Down
10 changes: 6 additions & 4 deletions integrations/access/opsgenie/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestCreateAlert(t *testing.T) {
Roles: []string{"role1", "role2"},
RequestReason: "someReason",
SystemAnnotations: types.Labels{
types.TeleportNamespace + types.ReqAnnotationNotifySchedulesLabel: {"[email protected]"},
types.TeleportNamespace + types.ReqAnnotationTeamsLabel: {"MyOpsGenieTeam"},
types.TeleportNamespace + types.ReqAnnotationNotifySchedulesLabel: {"[email protected]", "bb4d9938-c3c2-455d-aaab-727aa701c0d8"},
types.TeleportNamespace + types.ReqAnnotationTeamsLabel: {"MyOpsGenieTeam", "aee8a0de-c80f-4515-a232-501c0bc9d715"},
},
})
assert.NoError(t, err)
Expand All @@ -70,8 +70,10 @@ func TestCreateAlert(t *testing.T) {
Alias: "teleport-access-request/someRequestID",
Description: "someUser requested permissions for roles role1, role2 on Teleport at 01 Jan 01 00:00 UTC.\nReason: someReason\n\n",
Responders: []Responder{
{Type: "schedule", Name: "[email protected]", ID: "[email protected]"},
{Type: "team", Name: "MyOpsGenieTeam", ID: "MyOpsGenieTeam"},
{Type: "schedule", Name: "[email protected]"},
{Type: "schedule", ID: "bb4d9938-c3c2-455d-aaab-727aa701c0d8"},
{Type: "team", Name: "MyOpsGenieTeam"},
{Type: "team", ID: "aee8a0de-c80f-4515-a232-501c0bc9d715"},
},
Priority: "somePriority",
}
Expand Down

0 comments on commit bc6e4c4

Please sign in to comment.