8000 implement S3 BucketInventoryConfiguration CRUD operations by bentsku · Pull Request #8696 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

implement S3 BucketInventoryConfiguration CRUD operations #8696

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

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added list sorting
  • Loading branch information
bentsku committed Jul 14, 2023
commit 4a8cac665ae493b81604115998d69dc80eb046f0
10 changes: 4 additions & 6 deletions localstack/services/s3/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
from collections import defaultdict
from operator import itemgetter
from typing import IO, Dict, List, Optional
from urllib.parse import parse_qs, quote, urlencode, urlparse, urlunparse
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -1665,14 +1666,11 @@ def list_bucket_inventory_configurations(
store = self.get_store(context)
bucket_inventory_configurations = store.bucket_inventory_configurations.get(bucket, {})

# bucket_inventory_configurations = sorted(
# bucket_inventory_configurations.values(), key=lambda x: x["Id"]
# )
# TODO: verify the sorting?

return ListBucketInventoryConfigurationsOutput(
IsTruncated=False,
InventoryConfigurationList=list(bucket_inventory_configurations.values()),
InventoryConfigurationList=sorted(
bucket_inventory_configurations.values(), key=itemgetter("Id")
),
)

def delete_bucket_inventory_configuration(
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/s3/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5115,6 +5115,46 @@ def _put_bucket_inventory_configuration(inventory_configuration):
_put_bucket_inventory_configuration(inv_config)
snapshot.match("wrong-optional-field", e.value.response)

@pytest.mark.aws_validated
def test_put_bucket_inventory_config_order(self, aws_client, s3_create_bucket, snapshot):
snapshot.add_transformer(snapshot.transform.resource_name())
src_bucket = s3_create_bucket()
dest_bucket = s3_create_bucket()

def _put_bucket_inventory_configuration(config_id: str):
inventory_configuration = {
"Id": config_id,
"Destination": {
"S3BucketDestination": {
"Bucket": f"arn:aws:s3:::{dest_bucket}",
"Format": "CSV",
}
},
"IsEnabled": True,
"IncludedObjectVersions": "All",
"Schedule": {"Frequency": "Daily"},
}
aws_client.s3.put_bucket_inventory_configuration(
Bucket=src_bucket,
Id=config_id,
InventoryConfiguration=inventory_configuration,
)

for inv_config_id in ("test-1", "z-test", "a-test"):
_put_bucket_inventory_configuration(inv_config_id)

list_inv_configs = aws_client.s3.list_bucket_inventory_configurations(Bucket=src_bucket)
snapshot.match("list-inventory-config", list_inv_configs)

del_inv_config = aws_client.s3.delete_bucket_inventory_configuration(
Bucket=src_bucket,
Id="z-test",
)
snapshot.match("del-inventory-config", del_inv_config)

list_inv_configs = aws_client.s3.list_bucket_inventory_configurations(Bucket=src_bucket)
snapshot.match("list-inventory-config-after-del", list_inv_configs)


class TestS3MultiAccounts:
@pytest.fixture
Expand Down
99 changes: 99 additions & 0 deletions tests/integration/s3/test_s3.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -8496,5 +8496,104 @@
}
}
}
},
"tests/integration/s3/test_s3.py::TestS3::test_put_bucket_inventory_config_order": {
"recorded-date": "14-07-2023, 17:13:52",
"recorded-content": {
"list-inventory-config": {
"InventoryConfigurationList": [
{
"Destination": {
"S3BucketDestination": {
"Bucket": "arn:aws:s3:::<resource:1>",
"Format": "CSV"
}
},
"Id": "a-test",
"IncludedObjectVersions": "All",
"IsEnabled": true,
"Schedule": {
"Frequency": "Daily"
}
},
{
"Destination": {
"S3BucketDestination": {
"Bucket": "arn:aws:s3:::<resource:1>",
"Format": "CSV"
}
},
"Id": "test-1",
"IncludedObjectVersions": "All",
"IsEnabled": true,
"Schedule": {
"Frequency": "Daily"
}
},
{
"Destination": {
"S3BucketDestination": {
"Bucket": "arn:aws:s3:::<resource:1>",
"Format": "CSV"
}
},
"Id": "z-test",
"IncludedObjectVersions": "All",
"IsEnabled": true,
8000 "Schedule": {
"Frequency": "Daily"
}
}
],
"IsTruncated": false,
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
},
"del-inventory-config": {
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 204
}
},
"list-inventory-config-after-del": {
"InventoryConfigurationList": [
{
"Destination": {
"S3BucketDestination": {
"Bucket": "arn:aws:s3:::<resource:1>",
"Format": "CSV"
}
},
"Id": "a-test",
"IncludedObjectVersions": "All",
"IsEnabled": true,
"Schedule": {
"Frequency": "Daily"
}
},
{
"Destination": {
"S3BucketDestination": {
"Bucket": "arn:aws:s3:::<resource:1>",
"Format": "CSV"
}
},
"Id": "test-1",
"IncludedObjectVersions": "All",
"IsEnabled": true,
"Schedule": {
"Frequency": "Daily"
}
}
],
"IsTruncated": false,
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
}
}
}
}
0