-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CloudTrail log table naming to be consistent
- Loading branch information
Showing
5 changed files
with
52 additions
and
52 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,47 @@ | ||
package mappers | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/turbot/tailpipe-plugin-aws/rows" | ||
"github.com/turbot/tailpipe-plugin-sdk/table" | ||
) | ||
|
||
// CloudTrailLogMapper is a mapper that receives CloudTrailLogBatch objects and extracts CloudTrailLog records from them | ||
type CloudTrailLogMapper struct { | ||
} | ||
|
||
// NewCloudTrailLogMapper creates a new CloudTrailLogMapper | ||
func NewCloudTrailLogMapper() table.Mapper[*rows.CloudTrailLog] { | ||
return &CloudTrailLogMapper{} | ||
} | ||
|
||
func (c *CloudTrailLogMapper) Identifier() string { | ||
return "cloudtrail_log_mapper" | ||
} | ||
|
||
// Map casts the data item as an CloudTrailLogBatch and returns the CloudTrailLog records | ||
func (c *CloudTrailLogMapper) Map(_ context.Context, a any) ([]*rows.CloudTrailLog, error) { | ||
// the expected input type is a JSON byte[] deserializable to CloudTrailLogBatch | ||
jsonBytes, ok := a.([]byte) | ||
if !ok { | ||
return nil, fmt.Errorf("expected byte[], got %T", a) | ||
} | ||
|
||
// decode json ito CloudTrailLogBatch | ||
var log rows.CloudTrailLogBatch | ||
err := json.Unmarshal(jsonBytes, &log) | ||
if err != nil { | ||
return nil, fmt.Errorf("error decoding json: %w", err) | ||
} | ||
|
||
slog.Debug("CloudwatchMapper", "record count", len(log.Records)) | ||
var res = make([]*rows.CloudTrailLog, len(log.Records)) | ||
for i, record := range log.Records { | ||
res[i] = &record | ||
} | ||
return res, nil | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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