From eae55b8c04c5836edbfc5135e17a758495183ff1 Mon Sep 17 00:00:00 2001 From: Luke Young <91491244+lyoung-confluent@users.noreply.github.com> Date: Mon, 29 Jan 2024 13:15:37 -0800 Subject: [PATCH] Add S3 Batch Operations 2.0 Schema Fields to S3BatchJob/S3BatchJobTask (#550) * Add S3 Batch Operations 2.0 Schema Fields * Create s3-batch-job-event-request-2.0.json * Update s3_batch_job_test.go * Rename s3-batch-job-event-request.json to s3-batch-job-event-request-1.0.json * Fix tests * Split into S3BatchJobV2 --- events/s3_batch_job.go | 22 +++++++++++++++++++ events/s3_batch_job_test.go | 22 ++++++++++++++++++- ...on => s3-batch-job-event-request-1.0.json} | 2 +- .../s3-batch-job-event-request-2.0.json | 19 ++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) rename events/testdata/{s3-batch-job-event-request.json => s3-batch-job-event-request-1.0.json} (99%) create mode 100644 events/testdata/s3-batch-job-event-request-2.0.json diff --git a/events/s3_batch_job.go b/events/s3_batch_job.go index f2626edd..183ec907 100644 --- a/events/s3_batch_job.go +++ b/events/s3_batch_job.go @@ -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"` diff --git a/events/s3_batch_job_test.go b/events/s3_batch_job_test.go index 802d38b2..3067c256 100644 --- a/events/s3_batch_job_test.go +++ b/events/s3_batch_job_test.go @@ -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 @@ -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 diff --git a/events/testdata/s3-batch-job-event-request.json b/events/testdata/s3-batch-job-event-request-1.0.json similarity index 99% rename from events/testdata/s3-batch-job-event-request.json rename to events/testdata/s3-batch-job-event-request-1.0.json index 210173f4..4c3038ec 100644 --- a/events/testdata/s3-batch-job-event-request.json +++ b/events/testdata/s3-batch-job-event-request-1.0.json @@ -12,4 +12,4 @@ "s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket" } ] -} \ No newline at end of file +} diff --git a/events/testdata/s3-batch-job-event-request-2.0.json b/events/testdata/s3-batch-job-event-request-2.0.json new file mode 100644 index 00000000..738339cc --- /dev/null +++ b/events/testdata/s3-batch-job-event-request-2.0.json @@ -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" + } + ] +}