cloudtrail

package
v0.47.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegion = "us-east-1"

Functions

func ApplyFilters added in v0.47.0

func ApplyFilters(records []types.Event, filters ...Filter) ([]types.Event, error)

ApplyFilters takes the filteredEvents slice and applies an additional filter function. The filter function here is an inline function that calls isIgnoredEvent(event, mergedRegex). Only events for which isIgnoredEvent returns true (i.e., not ignored by the regex) are returned.

func Filters added in v0.47.0

func Filters(f WriteEventFilters, alllookupEvents []types.Event) []types.Event

Filters applies inclusion and exclusion filters to all Cloudtrail Events applies inclusion filters then exclusion filters.

func GetEvents added in v0.47.0

func GetEvents(cloudtailClient *cloudtrail.Client, startTime time.Time, endTime time.Time, writeOnly bool) ([]types.Event, error)

GetEvents etrieve CloudTrail events using the provided client and time range. It paginates through all available events, and returns all.

func IsIgnoredEvent added in v0.47.0

func IsIgnoredEvent(event types.Event, mergedRegex string) (bool, error)

isIgnoredEvent filters out events based on the specified ignore list, which contains regular expression patterns. It returns true if the event should be kept, and false if it should be filtered out.

func NewCloudtrailCmd

func NewCloudtrailCmd() *cobra.Command

NewCloudtrailCmd represents the newCmdWriteEvents command

func ParseDurationAfter added in v0.47.0

func ParseDurationAfter(input string, startTime time.Time) (time.Time, error)

parseDurationAfter parses the given startTime string as a duration and adds it from the current UTC time. It returns the resulting time and any parsing error encountered.

func ParseDurationBefore added in v0.47.0

func ParseDurationBefore(input string, startTime time.Time) (time.Time, error)

parseDurationBefore parses the given startTime string as a duration and subtracts it from the current UTC time. It returns the resulting time and any parsing error encountered.

func ParseStartEndTime added in v0.47.0

func ParseStartEndTime(start, end, duration string) (time.Time, time.Time, error)

ParseStartEndTime parses start time, end time, and duration parameters to calculate the actual time range for CloudTrail event queries.

Parameters:

  • start: Start time in "YYYY-MM-DD,HH:MM:SS" format (--after flag)
  • end: End time in "YYYY-MM-DD,HH:MM:SS" format (--until flag)
  • duration: Duration string like "2h", "30m", "1d" (--since flag)

Time calculation logic:

  • If both start and end are provided: Use exact time range
  • If only start is provided: start + duration (forward in time)
  • If only end is provided: end - duration (backward in time)
  • If both start and end are no provided: Use time.Now().UTC() - duration (default 1h)

Returns:

  • startTime: Calculated start time in UTC
  • endTime: Calculated end time in UTC
  • error: Any parsing or validation error

func ParseTimeAndValidate added in v0.47.0

func ParseTimeAndValidate(timeStr string) (time.Time, error)

parseTimeAndValidate takes YY-MM-DD,hh:mm:ss format, splits the year and time and convert it to current UTC time. It returns the parsed time and any parsing error encountered.

func PrintEvents added in v0.47.0

func PrintEvents(filterEvents []types.Event, printUrl bool, printRaw bool)

PrintEvents prints the filtered CloudTrail events in a human-readable format. Allows to print cloudtrail event url link or its raw JSON format. Allows to print cloutrail event resource name & type.

func PrintFormat added in v0.47.0

func PrintFormat(filterEvents []types.Event, printUrl bool, printRaw bool, table []string)

PrintFormat allows the user to specify which fields to print. Allows to print cloudtrail event url link

func ValidateFilters added in v0.47.0

func ValidateFilters(filters []string) error

ValidateFilters checks that all filters are in the correct "key=value" format Returns an error immediately if a filter is invalid.

func ValidateFormat added in v0.47.0

func ValidateFormat(table []string) error

ValidateTable checks for the string list given and returns error if it does not match.

func Whoami added in v0.47.0

func Whoami(stsClient sts.Client) (accountArn string, accountId string, err error)

Whoami retrieves the AWS account ARN and account ID for the current caller using the provided STS client.

Types

type Filter added in v0.47.0

type Filter func(types.Event) (bool, error)

Filter is a function type that takes a CloudTrail event and returns a boolean indicating whether the event passes the filter, and an error if the filter evaluation fails.

type QueryOptions added in v0.47.0

type QueryOptions struct {
	StartTime time.Time
}

QueryOptions defines the start time for querying CloudTrail events.

type RawEventDetails

type RawEventDetails struct {
	EventVersion string `json:"eventVersion"`
	UserIdentity struct {
		AccountId      string `json:"accountId"`
		SessionContext struct {
			SessionIssuer struct {
				Type     string `json:"type"`
				UserName string `json:"userName"`
				Arn      string `json:"arn"`
			} `json:"sessionIssuer"`
		} `json:"sessionContext"`
	} `json:"userIdentity"`
	EventRegion string `json:"awsRegion"`
	EventId     string `json:"eventID"`
	ErrorCode   string `json:"errorCode"`
}

RawEventDetails represents the structure of relevant fields extracted from a CloudTrail event JSON.

func ExtractUserDetails added in v0.47.0

func ExtractUserDetails(cloudTrailEvent *string) (*RawEventDetails, error)

ExtractUserDetails parses a CloudTrail event JSON string and extracts user identity details.

type WriteEventFilters added in v0.47.0

type WriteEventFilters struct {
	Include []string
	Exclude []string
}

WriteEventFilters defines the structure for filters used in write-events.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL