Skip to content

Commit

Permalink
feat: added support for bucket data object and updating bucket metada…
Browse files Browse the repository at this point in the history
…ta (#128)
  • Loading branch information
ErikBjare committed May 15, 2023
1 parent 0dd5176 commit 8fecb98
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 141 deletions.
21 changes: 21 additions & 0 deletions aw_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def create_bucket(
client: str,
hostname: str,
created: Optional[datetime] = None,
data: Optional[Dict[str, Any]] = None,
) -> bool:
"""
Create bucket.
Expand All @@ -154,9 +155,29 @@ def create_bucket(
client=client,
hostname=hostname,
created=created,
data=data,
)
return True

@check_bucket_exists
def update_bucket(
self,
bucket_id: str,
event_type: Optional[str] = None,
client: Optional[str] = None,
hostname: Optional[str] = None,
data: Optional[Dict[str, Any]] = None,
) -> None:
"""Update bucket metadata"""
self.db.update_bucket(
bucket_id,
type=event_type,
client=client,
hostname=hostname,
data=data,
)
return None

@check_bucket_exists
def delete_bucket(self, bucket_id: str) -> None:
"""Delete a bucket"""
Expand Down
23 changes: 23 additions & 0 deletions aw_server/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def format(self, value):
},
)

update_bucket = api.model(
"UpdateBucket",
{
"client": fields.String(required=False),
"type": fields.String(required=False),
"hostname": fields.String(required=False),
"data": fields.String(required=False),
},
)

query = api.model(
"Query",
{
Expand Down Expand Up @@ -173,6 +183,19 @@ def post(self, bucket_id):
else:
return {}, 304

@api.expect(update_bucket)
@copy_doc(ServerAPI.update_bucket)
def put(self, bucket_id):
data = request.get_json()
current_app.api.update_bucket(
bucket_id,
event_type=data["type"],
client=data["client"],
hostname=data["hostname"],
data=data["data"],
)
return {}, 200

@copy_doc(ServerAPI.delete_bucket)
@api.param("force", "Needs to be =1 to delete a bucket it non-testing mode")
def delete(self, bucket_id):
Expand Down
Loading

0 comments on commit 8fecb98

Please sign in to comment.