Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add S3 Batch Operations 2.0 Schema Fields to S3BatchJob/S3BatchJobTask #550

Merged
merged 7 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions events/s3_batch_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ type S3BatchJobTask struct {
S3BucketARN string `json:"s3BucketArn"`
}

// S3BatchJobEventV2 encapsulates the detail of a s3 batch job
type S3BatchJobEventV2 struct {
InvocationSchemaVersion string `json:"invocationSchemaVersion"`
InvocationID string `json:"invocationId"`
Job S3BatchJobV2 `json:"job"`
Tasks []S3BatchJobTaskV2 `json:"tasks"`
}

// S3BatchJobV2 whichs have the job id
type S3BatchJobV2 struct {
ID string `json:"id"`
UserArguments map[string]string `json:"userArguments"`
}

// S3BatchJobTaskV2 represents one task in the s3 batch job and have all task details
type S3BatchJobTaskV2 struct {
TaskID string `json:"taskId"`
S3Key string `json:"s3Key"`
S3VersionID string `json:"s3VersionId"`
S3Bucket string `json:"s3Bucket"`
}

// S3BatchJobResponse is the response of a iven s3 batch job with the results
type S3BatchJobResponse struct {
InvocationSchemaVersion string `json:"invocationSchemaVersion"`
Expand Down
22 changes: 21 additions & 1 deletion events/s3_batch_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestS3BatchJobEventMarshaling(t *testing.T) {

// 1. read JSON from file
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request.json")
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request-1.0.json")

// 2. de-serialize into Go object
var inputEvent S3BatchJobEvent
Expand All @@ -31,6 +31,26 @@ func TestS3BatchJobEventMarshaling(t *testing.T) {
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestS3BatchJobEventV2Marshaling(t *testing.T) {
// 1. read JSON from file
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request-2.0.json")

// 2. de-serialize into Go object
var inputEvent S3BatchJobEventV2
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// 3. serialize to JSON
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

// 4. check result
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestS3BatchJobResponseMarshaling(t *testing.T) {

// 1. read JSON from file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket"
}
]
}
}
19 changes: 19 additions & 0 deletions events/testdata/s3-batch-job-event-request-2.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"invocationSchemaVersion": "2.0",
"invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
"job": {
"id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce",
"userArguments": {
"k1": "v1",
"k2": "v2"
}
},
"tasks": [
{
"taskId": "dGFza2lkZ29lc2hlcmUK",
"s3Key": "customerImage1.jpg",
"s3VersionId": "jbo9_jhdPEyB4RrmOxWS0kU0EoNrU_oI",
"s3Bucket": "awsexamplebucket"
}
]
}