Skip to content

Commit

Permalink
Merge pull request #8 from incident-io/rob/add-incident-roles-stream
Browse files Browse the repository at this point in the history
Add the incident roles stream
  • Loading branch information
rliddler authored Oct 19, 2023
2 parents a245a47 + 0228609 commit 5aa9594
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
44 changes: 44 additions & 0 deletions model/incident_role_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package model

import "github.com/incident-io/singer-tap/client"

type incidentRoleV2 struct{}

var IncidentRoleV2 incidentRoleV2

// Actually identical to V1 but hey
func (incidentRoleV2) Schema() Property {
return Property{
Types: []string{"object"},
Properties: map[string]Property{
"id": {
Types: []string{"string"},
},
"name": {
Types: []string{"string"},
},
"description": {
Types: []string{"string"},
},
"instructions": {
Types: []string{"string"},
},
"required": {
Types: []string{"boolean"},
},
"role_type": {
Types: []string{"string"},
},
"short_form": {
Types: []string{"string"},
},
"created_at": DateTime.Schema(),
"updated_at": DateTime.Schema(),
},
}
}

func (incidentRoleV2) Serialize(input client.IncidentRoleV2) map[string]any {
// Just flat convert everything into a map[string]any
return DumpToMap(input)
}
48 changes: 48 additions & 0 deletions tap/stream_incident_roles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tap

import (
"context"

kitlog "github.com/go-kit/log"
"github.com/incident-io/singer-tap/client"
"github.com/incident-io/singer-tap/model"
"github.com/pkg/errors"
)

func init() {
register(&StreamIncidentRoles{})
}

type StreamIncidentRoles struct {
}

func (s *StreamIncidentRoles) Output() *Output {
return &Output{
Type: OutputTypeSchema,
Stream: "incident_roles",
Schema: &model.Schema{
HasAdditionalProperties: false,
Type: []string{"object"},
Properties: model.IncidentRoleV2.Schema().Properties,
},
KeyProperties: []string{"id"},
BookmarkProperties: []string{},
}
}

func (s *StreamIncidentRoles) GetRecords(ctx context.Context, logger kitlog.Logger, cl *client.ClientWithResponses) ([]map[string]any, error) {
var (
results = []map[string]any{}
)

response, err := cl.IncidentRolesV2ListWithResponse(ctx)
if err != nil {
return nil, errors.Wrap(err, "listing incidents for actions stream")
}

for _, element := range response.JSON200.IncidentRoles {
results = append(results, model.IncidentRoleV2.Serialize(element))
}

return results, nil
}

0 comments on commit 5aa9594

Please sign in to comment.