Skip to content

Commit

Permalink
feat: added special hostname !local (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jul 7, 2023
1 parent b211131 commit 7527c8d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions aw_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, db, testing) -> None:
self.testing = testing
self.last_event = {} # type: dict

def get_info(self) -> Dict[str, Dict]:
def get_info(self) -> Dict[str, Any]:
"""Get server info"""
payload = {
"hostname": gethostname(),
Expand Down Expand Up @@ -142,13 +142,23 @@ def create_bucket(
data: Optional[Dict[str, Any]] = None,
) -> bool:
"""
Create bucket.
Create a bucket.
If hostname is "!local", the hostname and device_id will be set from the server info.
This is useful for watchers which are known/assumed to run locally but might not know their hostname (like aw-watcher-web).
Returns True if successful, otherwise false if a bucket with the given ID already existed.
"""
if created is None:
created = datetime.now()
if bucket_id in self.db.buckets():
return False
if hostname == "!local":
info = self.get_info()
if data is None:
data = {}
hostname = info["hostname"]
data["device_id"] = info["device_id"]
self.db.create_bucket(
bucket_id,
type=event_type,
Expand Down

0 comments on commit 7527c8d

Please sign in to comment.