Skip to content

Commit 5516bce

Browse files
committed
feat: add intelligent tiering event data structure and corresponding test for S3 events
1 parent 1f8f7e8 commit 5516bce

3 files changed

Lines changed: 90 additions & 12 deletions

File tree

events/s3.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ type S3Event struct {
1515

1616
// S3EventRecord which wrap record data
1717
type S3EventRecord struct {
18-
EventVersion string `json:"eventVersion"`
19-
EventSource string `json:"eventSource"`
20-
AWSRegion string `json:"awsRegion"`
21-
EventTime time.Time `json:"eventTime"`
22-
EventName string `json:"eventName"`
23-
PrincipalID S3UserIdentity `json:"userIdentity"`
24-
RequestParameters S3RequestParameters `json:"requestParameters"`
25-
ResponseElements map[string]string `json:"responseElements"`
26-
S3 S3Entity `json:"s3"`
27-
GlacierEventData *S3GlacierEventData `json:"glacierEventData,omitempty"`
28-
RestoreEventData *S3RestoreEventData `json:"restoreEventData,omitempty"`
29-
ReplicationEventData *S3ReplicationEventData `json:"replicationEventData,omitempty"`
18+
EventVersion string `json:"eventVersion"`
19+
EventSource string `json:"eventSource"`
20+
AWSRegion string `json:"awsRegion"`
21+
EventTime time.Time `json:"eventTime"`
22+
EventName string `json:"eventName"`
23+
PrincipalID S3UserIdentity `json:"userIdentity"`
24+
RequestParameters S3RequestParameters `json:"requestParameters"`
25+
ResponseElements map[string]string `json:"responseElements"`
26+
S3 S3Entity `json:"s3"`
27+
GlacierEventData *S3GlacierEventData `json:"glacierEventData,omitempty"`
28+
RestoreEventData *S3RestoreEventData `json:"restoreEventData,omitempty"`
29+
ReplicationEventData *S3ReplicationEventData `json:"replicationEventData,omitempty"`
30+
IntelligentTieringEventData *S3IntelligentTieringEventData `json:"intelligentTieringEventData,omitempty"`
3031
}
3132

3233
type S3UserIdentity struct {
@@ -90,6 +91,10 @@ type S3ReplicationEventData struct {
9091
FailureReason string `json:"failureReason"`
9192
}
9293

94+
type S3IntelligentTieringEventData struct {
95+
DestinationAccessTier string `json:"destinationAccessTier"`
96+
}
97+
9398
type S3TestEvent struct {
9499
Service string `json:"Service"`
95100
Bucket string `json:"Bucket"`

events/s3_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,36 @@ func TestS3RestoreEventMarshaling(t *testing.T) {
112112
assert.JSONEq(t, string(inputJSON), string(outputJSON))
113113
}
114114

115+
func TestS3IntelligentTieringEventMarshaling(t *testing.T) {
116+
// 1. read JSON from file
117+
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-intelligenttier-event.json")
118+
119+
// 2. de-serialize into Go object
120+
var inputEvent S3Event
121+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
122+
t.Errorf("could not unmarshal event. details: %v", err)
123+
}
124+
125+
// 3. verify intelligentTieringEventData is correctly parsed
126+
if inputEvent.Records[0].IntelligentTieringEventData == nil {
127+
t.Error("intelligentTieringEventData should not be nil for intelligent tiering events")
128+
}
129+
130+
// 4. verify destinationAccessTier is correctly parsed
131+
if inputEvent.Records[0].IntelligentTieringEventData.DestinationAccessTier == "" {
132+
t.Error("destinationAccessTier should not be empty")
133+
}
134+
135+
// 5. serialize to JSON
136+
outputJSON, err := json.Marshal(inputEvent)
137+
if err != nil {
138+
t.Errorf("could not marshal event. details: %v", err)
139+
}
140+
141+
// 6. check result
142+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
143+
}
144+
115145
func TestS3ReplicationEventMarshaling(t *testing.T) {
116146
// 1. read JSON from file
117147
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-replication-event.json")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"Records": [
3+
{
4+
"eventVersion": "2.3",
5+
"eventSource": "aws:s3",
6+
"awsRegion": "us-east-1",
7+
"eventTime": "2023-11-15T10:30:00.789Z",
8+
"eventName": "s3:IntelligentTiering:TransitionAccess",
9+
"userIdentity": {
10+
"principalId": "s3.amazonaws.com"
11+
},
12+
"requestParameters": {
13+
"sourceIPAddress": "s3.amazonaws.com"
14+
},
15+
"responseElements": {
16+
"x-amz-request-id": "EXAMPLE123456789",
17+
"x-amz-id-2": "EXAMPLEabcdefghijklmnopqrstuvwxyz"
18+
},
19+
"s3": {
20+
"s3SchemaVersion": "1.0",
21+
"configurationId": "IntelligentTieringConfig",
22+
"bucket": {
23+
"name": "example-bucket",
24+
"ownerIdentity": {
25+
"principalId": "EXAMPLE"
26+
},
27+
"arn": "arn:aws:s3:::example-bucket"
28+
},
29+
"object": {
30+
"key": "intelligent%2Dtier%2Dtest.dat",
31+
"urlDecodedKey": "intelligent-tier-test.dat",
32+
"size": 5242880,
33+
"versionId": "versionExample123",
34+
"eTag": "d41d8cd98f00b204e9800998ecf8427e",
35+
"sequencer": "0066ABC1234567890"
36+
}
37+
},
38+
"intelligentTieringEventData": {
39+
"destinationAccessTier": "ARCHIVE_ACCESS"
40+
}
41+
}
42+
]
43+
}

0 commit comments

Comments
 (0)