Skip to content

Commit 7527c8d

Browse files
authored
feat: added special hostname !local (#140)
1 parent b211131 commit 7527c8d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

aw_server/api.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, db, testing) -> None:
5353
self.testing = testing
5454
self.last_event = {} # type: dict
5555

56-
def get_info(self) -> Dict[str, Dict]:
56+
def get_info(self) -> Dict[str, Any]:
5757
"""Get server info"""
5858
payload = {
5959
"hostname": gethostname(),
@@ -142,13 +142,23 @@ def create_bucket(
142142
data: Optional[Dict[str, Any]] = None,
143143
) -> bool:
144144
"""
145-
Create bucket.
145+
Create a bucket.
146+
147+
If hostname is "!local", the hostname and device_id will be set from the server info.
148+
This is useful for watchers which are known/assumed to run locally but might not know their hostname (like aw-watcher-web).
149+
146150
Returns True if successful, otherwise false if a bucket with the given ID already existed.
147151
"""
148152
if created is None:
149153
created = datetime.now()
150154
if bucket_id in self.db.buckets():
151155
return False
156+
if hostname == "!local":
157+
info = self.get_info()
158+
if data is None:
159+
data = {}
160+
hostname = info["hostname"]
161+
data["device_id"] = info["device_id"]
152162
self.db.create_bucket(
153163
bucket_id,
154164
type=event_type,

0 commit comments

Comments
 (0)