Skip to content
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

feat: added special hostname !local #140

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Changes from all commits
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
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
Loading