diff --git a/events/apigw.go b/events/apigw.go index 32da810f..aa0e9259 100644 --- a/events/apigw.go +++ b/events/apigw.go @@ -168,6 +168,7 @@ type APIGatewayCustomAuthorizerPolicy struct { Statement []IAMPolicyStatement } +// IAMPolicyStatement represents one statement from IAM policy with action, effect and resource type IAMPolicyStatement struct { Action []string Effect string diff --git a/events/cloudwatch_logs.go b/events/cloudwatch_logs.go index bc7bbf8a..6b74b3b2 100644 --- a/events/cloudwatch_logs.go +++ b/events/cloudwatch_logs.go @@ -47,7 +47,7 @@ type CloudwatchLogsData struct { LogEvents []CloudwatchLogsLogEvent `json:"logEvents"` } -// LogEvent represents a log entry from cloudwatch logs +// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs type CloudwatchLogsLogEvent struct { ID string `json:"id"` Timestamp int64 `json:"timestamp"` diff --git a/events/code_commit.go b/events/code_commit.go index e8672ba3..318b0736 100644 --- a/events/code_commit.go +++ b/events/code_commit.go @@ -43,7 +43,7 @@ func (t *CodeCommitEventTime) UnmarshalJSON(data []byte) error { return err } -// represents a CodeCommit record +// CodeCommitRecord represents a CodeCommit record type CodeCommitRecord struct { EventID string `json:"eventId"` EventVersion string `json:"eventVersion"` diff --git a/events/codebuild.go b/events/codebuild.go index ca1dd33d..f711c341 100644 --- a/events/codebuild.go +++ b/events/codebuild.go @@ -11,6 +11,7 @@ const ( CodeBuildPhaseChangeDetailType = "CodeBuild Build Phase Change" ) +// CodeBuildPhaseStatus represents the status of code build phase (i.e. failed, in progress) type CodeBuildPhaseStatus string const ( @@ -23,6 +24,7 @@ const ( CodeBuildPhaseStatusTimedOut = "TIMED_OUT" ) +// CodeBuildPhaseType represents the type of the code build phase (i.e. submitted, install) type CodeBuildPhaseType string const ( @@ -73,6 +75,7 @@ type CodeBuildEvent struct { Detail CodeBuildEventDetail `json:"detail"` } +// CodeBuildEventDetail represents the all details related to the code build event type CodeBuildEventDetail struct { BuildStatus CodeBuildPhaseStatus `json:"build-status"` ProjectName string `json:"project-name"` @@ -90,6 +93,7 @@ type CodeBuildEventDetail struct { CompletedPhaseEnd CodeBuildTime `json:"completed-phase-end"` } +//CodeBuildEventAdditionalInformation represents additional informations to the code build event type CodeBuildEventAdditionalInformation struct { Artifact CodeBuildArtifact `json:"artifact"` @@ -110,12 +114,14 @@ type CodeBuildEventAdditionalInformation struct { Phases []CodeBuildPhase `json:"phases"` } +// CodeBuildArtifact represents the artifact provided to build type CodeBuildArtifact struct { MD5Sum string `json:"md5sum"` SHA256Sum string `json:"sha256sum"` Location string `json:"location"` } +// CodeBuildEnvironment represents the environment for a build type CodeBuildEnvironment struct { Image string `json:"image"` PrivilegedMode bool `json:"privileged-mode"` @@ -124,6 +130,7 @@ type CodeBuildEnvironment struct { EnvironmentVariables []CodeBuildEnvironmentVariable `json:"environment-variables"` } +// CodeBuildEnvironmentVariable encapsulate environment variables for the code build type CodeBuildEnvironmentVariable struct { // Name is the name of the environment variable. Name string `json:"name"` @@ -135,17 +142,20 @@ type CodeBuildEnvironmentVariable struct { Value string `json:"value"` } +// CodeBuildSource represent the code source will be build type CodeBuildSource struct { Location string `json:"location"` Type string `json:"type"` } +// CodeBuildLogs gives the log details of a code build type CodeBuildLogs struct { GroupName string `json:"group-name"` StreamName string `json:"stream-name"` DeepLink string `json:"deep-link"` } +// CodeBuildPhase represents the phase of a build and its details type CodeBuildPhase struct { PhaseContext []interface{} `json:"phase-context"` @@ -160,14 +170,17 @@ type CodeBuildPhase struct { PhaseStatus CodeBuildPhaseStatus `json:"phase-status"` } +// CodeBuildTime represents the time of the build type CodeBuildTime time.Time const codeBuildTimeFormat = "Jan 2, 2006 3:04:05 PM" +// MarshalJSON converts a given CodeBuildTime to json func (t CodeBuildTime) MarshalJSON() ([]byte, error) { return json.Marshal(time.Time(t).Format(codeBuildTimeFormat)) } +// UnmarshalJSON converts a given json to a CodeBuildTime func (t *CodeBuildTime) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { diff --git a/events/duration.go b/events/duration.go index 1c61d7a9..7952265d 100644 --- a/events/duration.go +++ b/events/duration.go @@ -8,6 +8,7 @@ import ( type DurationSeconds time.Duration +// UnmarshalJSON converts a given json to a DurationSeconds func (duration *DurationSeconds) UnmarshalJSON(data []byte) error { var seconds float64 if err := json.Unmarshal(data, &seconds); err != nil { @@ -18,6 +19,7 @@ func (duration *DurationSeconds) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON converts a given DurationSeconds to json func (duration DurationSeconds) MarshalJSON() ([]byte, error) { seconds := time.Duration(duration).Seconds() return json.Marshal(int64(math.Ceil(seconds))) @@ -25,6 +27,7 @@ func (duration DurationSeconds) MarshalJSON() ([]byte, error) { type DurationMinutes time.Duration +// UnmarshalJSON converts a given json to a DurationMinutes func (duration *DurationMinutes) UnmarshalJSON(data []byte) error { var minutes float64 if err := json.Unmarshal(data, &minutes); err != nil { @@ -35,6 +38,7 @@ func (duration *DurationMinutes) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON converts a given DurationMinutes to json func (duration DurationMinutes) MarshalJSON() ([]byte, error) { minutes := time.Duration(duration).Minutes() return json.Marshal(int64(math.Ceil(minutes))) diff --git a/events/dynamodb.go b/events/dynamodb.go index 09fcd34c..53fc822c 100644 --- a/events/dynamodb.go +++ b/events/dynamodb.go @@ -63,7 +63,7 @@ type DynamoDBUserIdentity struct { PrincipalID string `json:"principalId"` } -// A description of a single data modification that was performed on an item +// DynamoDBStreamRecord represents a description of a single data modification that was performed on an item // in a DynamoDB table. type DynamoDBStreamRecord struct { diff --git a/events/s3.go b/events/s3.go index 5af34931..bb944d2c 100644 --- a/events/s3.go +++ b/events/s3.go @@ -6,10 +6,12 @@ import ( "time" ) +// S3Event which wrap an array of S3EventRecord type S3Event struct { Records []S3EventRecord `json:"Records"` } +// S3EventRecord which wrap record data type S3EventRecord struct { EventVersion string `json:"eventVersion"` EventSource string `json:"eventSource"` diff --git a/events/s3_batch_job.go b/events/s3_batch_job.go index 59516126..f2626edd 100644 --- a/events/s3_batch_job.go +++ b/events/s3_batch_job.go @@ -2,6 +2,7 @@ package events +// S3BatchJobEvent encapsulates the detail of a s3 batch job type S3BatchJobEvent struct { InvocationSchemaVersion string `json:"invocationSchemaVersion"` InvocationID string `json:"invocationId"` @@ -9,10 +10,12 @@ type S3BatchJobEvent struct { Tasks []S3BatchJobTask `json:"tasks"` } +// S3BatchJob whichs have the job id type S3BatchJob struct { ID string `json:"id"` } +// S3BatchJobTask represents one task in the s3 batch job and have all task details type S3BatchJobTask struct { TaskID string `json:"taskId"` S3Key string `json:"s3Key"` @@ -20,6 +23,7 @@ type S3BatchJobTask struct { S3BucketARN string `json:"s3BucketArn"` } +// S3BatchJobResponse is the response of a iven s3 batch job with the results type S3BatchJobResponse struct { InvocationSchemaVersion string `json:"invocationSchemaVersion"` TreatMissingKeysAs string `json:"treatMissingKeysAs"` @@ -27,6 +31,7 @@ type S3BatchJobResponse struct { Results []S3BatchJobResult `json:"results"` } +// S3BatchJobResult represents the result of a given task type S3BatchJobResult struct { TaskID string `json:"taskId"` ResultCode string `json:"resultCode"` diff --git a/events/test/jsoncompare.go b/events/test/jsoncompare.go index 44e0471d..4c7556de 100644 --- a/events/test/jsoncompare.go +++ b/events/test/jsoncompare.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" ) -// Asserts two JSON files are semantically equal +// AssertJsonsEqual asserts two JSON files are semantically equal // (ignores white-space and attribute order) func AssertJsonsEqual(t *testing.T, expectedJson []byte, actualJson []byte) { assert.JSONEq(t, string(expectedJson), string(actualJson)) diff --git a/events/test/readjson.go b/events/test/readjson.go index ce7361ec..9a97b9b0 100644 --- a/events/test/readjson.go +++ b/events/test/readjson.go @@ -5,6 +5,7 @@ import ( "testing" ) +// ReadJSONFromFile reads a given input file to JSON func ReadJSONFromFile(t *testing.T, inputFile string) []byte { inputJSON, err := ioutil.ReadFile(inputFile) if err != nil { diff --git a/lambda/function.go b/lambda/function.go index 50b6ac47..8977ce1b 100644 --- a/lambda/function.go +++ b/lambda/function.go @@ -12,19 +12,23 @@ import ( "github.com/aws/aws-lambda-go/lambdacontext" ) +// Function struct which wrap the Handler type Function struct { handler Handler } +// NewFunction which creates a Function with a given Handler func NewFunction(handler Handler) *Function { return &Function{handler: handler} } +// Ping method which given a PingRequest and a PingResponse parses the PingResponse func (fn *Function) Ping(req *messages.PingRequest, response *messages.PingResponse) error { *response = messages.PingResponse{} return nil } +// Invoke method try to perform a command given an InvokeRequest and an InvokeResponse func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse) error { defer func() { if err := recover(); err != nil {