Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions aw_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def get_info(self) -> Dict[str, Any]:
}
return payload

def get_devices(self) -> List[Dict[str, Any]]:
"""Get list of known devices (currently only the local device)"""
return [{"id": get_device_id(), "hostname": gethostname()}]

def get_buckets(self) -> Dict[str, Dict]:
"""Get dict {bucket_name: Bucket} of all buckets"""
logger.debug("Received get request for buckets")
Expand Down
16 changes: 16 additions & 0 deletions aw_server/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def decorator(*args, **kwargs):
},
)

device = api.model(
"Device",
{
"id": fields.String(description="Stable device identifier (UUID)"),
"hostname": fields.String(description="Current hostname of the device"),
},
)

create_bucket = api.model(
"CreateBucket",
{
Expand Down Expand Up @@ -134,6 +142,14 @@ def get(self) -> Dict[str, Dict]:
return current_app.api.get_info()


@api.route("/0/devices")
class DevicesResource(Resource):
@api.marshal_list_with(device)
@copy_doc(ServerAPI.get_devices)
def get(self):
return current_app.api.get_devices()
Comment thread
TimeToBuildBob marked this conversation as resolved.


# BUCKETS


Expand Down
17 changes: 17 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ def test_info(flask_client):
assert r.json["profile"] == "testing"


def test_devices(flask_client):
r = flask_client.get("/api/0/devices")
assert r.status_code == 200
devices = r.json
assert isinstance(devices, list)
assert len(devices) == 1
device = devices[0]
assert "id" in device
assert "hostname" in device
# id is stable across calls
r2 = flask_client.get("/api/0/devices")
assert r2.json[0]["id"] == device["id"]
# id matches the server's own device_id
info = flask_client.get("/api/0/info").json
assert device["id"] == info["device_id"]


def test_buckets(flask_client, bucket, benchmark):
@benchmark
def list_buckets():
Expand Down
Loading