Skip to content

Commit

Permalink
fix(storage): make storage robust to edge case on region selection (#407
Browse files Browse the repository at this point in the history
)

* perf(docker): use s3-only image from localstack

* ci(dependabot): update dependabot config

* build(deps): bump localstack to 4.0.3

* fix(storage): avoid edge case with us-east-1

* test(scripts): extend e2e script

* fix(docker): update localstack env var management

* revert(docker): revert to localstack 1.4.0
  • Loading branch information
frgfm authored Jan 15, 2025
1 parent abce184 commit ca49671
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
29 changes: 12 additions & 17 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,23 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
time: "06:00"
timezone: "Europe/Paris"
groups:
gh-actions:
patterns:
- "*"
reviewers:
- "frgfm"
assignees:
- "frgfm"
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
time: "06:00"
timezone: "Europe/Paris"
reviewers:
- "frgfm"
assignees:
- "frgfm"
allow:
- dependency-name: "ruff"
- dependency-name: "mypy"
- dependency-name: "pre-commit"
- dependency-name: "fastapi"
- dependency-name: "sqlmodel"
- dependency-name: "uvicorn"
- dependency-name: "pytest"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-name: "ghcr.io/astral-sh/uv"
- dependency-name: "localstack/localstack"
18 changes: 11 additions & 7 deletions scripts/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ def main(args):
"Content-Type": "application/json",
}

user_login = "my_user"
user_pwd = "my_pwd" # noqa S105
# Create an organization
org_name = "my_org"
org_id = api_request("post", f"{args.endpoint}/organizations/", superuser_auth, {"name": org_name})["id"]

agent_login = "my_user"
agent_pwd = "my_pwd" # noqa S105

# create a user
payload = {"organization_id": 1, "login": user_login, "password": user_pwd, "role": "agent"}
payload = {"organization_id": org_id, "login": agent_login, "password": agent_pwd, "role": "agent"}
user_id = api_request("post", f"{args.endpoint}/users/", superuser_auth, payload)["id"]
agent_auth = {
"Authorization": f"Bearer {get_token(args.endpoint, user_login, user_pwd)}",
"Authorization": f"Bearer {get_token(args.endpoint, agent_login, agent_pwd)}",
"Content-Type": "application/json",
}
# Get & Fetch access
Expand All @@ -63,11 +67,11 @@ def main(args):
new_pwd = "my_new_pwd" # noqa S105
api_request("patch", f"{args.endpoint}/users/{user_id}/", superuser_auth, {"password": new_pwd})

# Create a camera (as admin until #79 is closed)
# Create a camera
camera_name = "my_device"
payload = {
"name": camera_name,
"organization_id": 1,
"organization_id": org_id,
"angle_of_view": 70.0,
"elevation": 100,
"lat": 44.7,
Expand Down Expand Up @@ -111,7 +115,7 @@ def main(args):
api_request("delete", f"{args.endpoint}/detections/{detection_id}/", superuser_auth)
api_request("delete", f"{args.endpoint}/cameras/{cam_id}/", superuser_auth)
api_request("delete", f"{args.endpoint}/users/{user_id}/", superuser_auth)

api_request("delete", f"{args.endpoint}/organizations/{org_id}/", superuser_auth)
print(f"SUCCESS in {time.time() - start_ts:.3}s")

return
Expand Down
9 changes: 7 additions & 2 deletions src/app/services/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ def __init__(
def create_bucket(self, bucket_name: str) -> bool:
"""Create a new bucket in S3 storage"""
try:
self._s3.create_bucket(
Bucket=bucket_name, CreateBucketConfiguration={"LocationConstraint": self._s3.meta.region_name}
# https://stackoverflow.com/questions/51912072/invalidlocationconstraint-error-while-creating-s3-bucket-when-the-used-command-i
# https://github.com/localstack/localstack/issues/8000
config_ = (
{}
if self._s3.meta.region_name == "us-east-1"
else {"CreateBucketConfiguration": {"LocationConstraint": self._s3.meta.region_name}}
)
self._s3.create_bucket(Bucket=bucket_name, **config_)
return True
except ClientError as e:
logger.warning(e)
Expand Down

0 comments on commit ca49671

Please sign in to comment.