connectordb/_user.py 1 location
|
@@ 43-54 (lines=12) @@
|
| 40 |
|
self.path, kwargs).json() |
| 41 |
|
|
| 42 |
|
def set_password(self, new_password): |
| 43 |
|
"""Sets a new password for the user""" |
| 44 |
|
self.set({"password": new_password}) |
| 45 |
|
|
| 46 |
|
def devices(self): |
| 47 |
|
"""Returns the list of devices that belong to the user""" |
| 48 |
|
result = self.db.read(self.path, {"q": "ls"}) |
| 49 |
|
|
| 50 |
|
if result is None or result.json() is None: |
| 51 |
|
return [] |
| 52 |
|
devices = [] |
| 53 |
|
for d in result.json(): |
| 54 |
|
dev = self[d["name"]] |
| 55 |
|
dev.metadata = d |
| 56 |
|
devices.append(dev) |
| 57 |
|
return devices |
connectordb/_device.py 1 location
|
@@ 28-39 (lines=12) @@
|
| 25 |
|
"stream1": {"schema": '{\"type\":\"number\"}'} |
| 26 |
|
}) |
| 27 |
|
|
| 28 |
|
Note that the schema must be encoded as a string when creating in this format. |
| 29 |
|
""" |
| 30 |
|
kwargs["public"] = public |
| 31 |
|
self.metadata = self.db.create(self.path, kwargs).json() |
| 32 |
|
|
| 33 |
|
def streams(self): |
| 34 |
|
"""Returns the list of streams that belong to the device""" |
| 35 |
|
result = self.db.read(self.path, {"q": "ls"}) |
| 36 |
|
|
| 37 |
|
if result is None or result.json() is None: |
| 38 |
|
return [] |
| 39 |
|
streams = [] |
| 40 |
|
for s in result.json(): |
| 41 |
|
strm = self[s["name"]] |
| 42 |
|
strm.metadata = s |
connectordb/_connectordb.py 1 location
|
@@ 117-128 (lines=12) @@
|
| 114 |
|
def __repr__(self): |
| 115 |
|
return "[ConnectorDB:%s]" % (self.path, ) |
| 116 |
|
|
| 117 |
|
def users(self): |
| 118 |
|
"""Returns the list of users in the database""" |
| 119 |
|
result = self.db.read("", {"q": "ls"}) |
| 120 |
|
|
| 121 |
|
if result is None or result.json() is None: |
| 122 |
|
return [] |
| 123 |
|
users = [] |
| 124 |
|
for u in result.json(): |
| 125 |
|
usr = self(u["name"]) |
| 126 |
|
usr.metadata = u |
| 127 |
|
users.append(usr) |
| 128 |
|
return users |
| 129 |
|
|
| 130 |
|
def ping(self): |
| 131 |
|
"""Pings the ConnectorDB server. Useful for checking if the connection is valid""" |