-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from incident-io/rob/add-incident-roles-stream
Add the incident roles stream
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |