Skip to content

Commit

Permalink
add remove apiuser (#1012)
Browse files Browse the repository at this point in the history
* fix typo

* fix connection error because of api version

* RDM002

* rdm002

* update mqtt sensor

* fix sensor type

* add remove apiuser
  • Loading branch information
hendriksen-mark committed Mar 31, 2024
1 parent 2bffc8a commit 9ac8161
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
18 changes: 16 additions & 2 deletions BridgeEmulator/flaskUI/restful.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def authorize(username, resource='', resourceId='', resourceParam=''):
if username not in bridgeConfig["apiUsers"] and request.remote_addr != "127.0.0.1":
return [{"error": {"type": 1, "address": "/" + resource + "/" + resourceId, "description": "unauthorized user"}}]

if resourceId not in ["0", "new", "timezones"] and resourceId != '' and resourceId not in bridgeConfig[resource]:
if resourceId not in ["0", "new", "timezones", "whitelist"] and resourceId != '' and resourceId not in bridgeConfig[resource]:
logging.debug(str(resourceId) + " not in bridgeConfig " + str(resource))
return [{"error": {"type": 3, "address": "/" + resource + "/" + resourceId, "description": "resource, " + resource + "/" + resourceId + ", not available"}}]

if resourceId != "0" and resourceParam != '' and not hasattr(bridgeConfig[resource][resourceId], resourceParam):
logging.debug(str(resourceId) + " has no attribute " + str(resourceParam))
return [{"error": {"type": 3, "address": "/" + resource + "/" + resourceId + "/" + resourceParam, "description": "resource, " + resource + "/" + resourceId + "/" + resourceParam + ", not available"}}]
if request.remote_addr != "127.0.0.1":
bridgeConfig["apiUsers"][username].last_use_date = datetime.utcnow().strftime(
Expand Down Expand Up @@ -126,7 +128,7 @@ def get(self, username, resource):
return capabilities()
else:
response = {}
if resource in ["lights", "groups", "scenes", "rules", "resourcelinks", "schedules", "sensors"]:
if resource in ["lights", "groups", "scenes", "rules", "resourcelinks", "schedules", "sensors", "apiUsers"]:
for object in bridgeConfig[resource]:
response[object] = bridgeConfig[resource][object].getV1Api().copy()
elif resource == "config":
Expand Down Expand Up @@ -457,6 +459,18 @@ def delete(self, username, resource, resourceid, param):
authorisation = authorize(username, resource, resourceid)
if "success" not in authorisation:
return authorisation
if resourceid == "whitelist":
for config in ["lights", "groups", "scenes", "rules", "resourcelinks", "schedules", "sensors"]:
for object in bridgeConfig[config]:
if "owner" in bridgeConfig[config][object].getV1Api():
current_owner = bridgeConfig[config][object].getV1Api()["owner"]
if current_owner == param:
logging.debug("transfer ownership from: " + str(current_owner) + " to: " + str(username))
bridgeConfig[config][object].owner = bridgeConfig["apiUsers"][username]
logging.debug("Deleted api user: " + str(param) + " " + bridgeConfig["apiUsers"][param].name)
del bridgeConfig["apiUsers"][param]
configManager.bridgeConfig.save_config()
return [{"success": "/" + resource + "/" + resourceid + "/" + param + " deleted."}]
if param not in bridgeConfig[resource][resourceid]:
return [{"error": {"type": 4, "address": "/" + resource + "/" + resourceid, "description": "method, DELETE, not available for resource, " + resource + "/" + resourceid}}]

Expand Down
14 changes: 4 additions & 10 deletions BridgeEmulator/services/updateManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def githubCheck():
if publish_time > creation_time:
logging.info("update on github")
bridgeConfig["config"]["swupdate2"]["state"] = "allreadytoinstall"
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "allreadytoinstall"
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "allreadytoinstall"
elif githubUICheck() == True:
logging.info("UI update on github")
bridgeConfig["config"]["swupdate2"]["state"] = "anyreadytoinstall"
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "anyreadytoinstall"
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "anyreadytoinstall"
else:
logging.info("no update for diyHue or UI on github")
bridgeConfig["config"]["swupdate2"]["state"] = "noupdates"
Expand Down Expand Up @@ -94,19 +94,13 @@ def githubUICheck():
def githubInstall():
if bridgeConfig["config"]["swupdate2"]["state"] == "anyreadytoinstall":#ui update
bridgeConfig["config"]["swupdate2"]["state"] = "installing"
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
subprocess.Popen("sh githubUIInstall.sh",shell=True, close_fds=True)
if bridgeConfig["config"]["swupdate2"]["state"] == "allreadytoinstall":#diyhue + ui update
bridgeConfig["config"]["swupdate2"]["state"] = "installing"
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
subprocess.Popen("sh githubInstall.sh",shell=True, close_fds=True)

def githubInstall_test():
logging.info("work in progress")
bridgeConfig["config"]["swupdate2"]["install"] = False
bridgeConfig["config"]["swupdate2"]["state"] = "noupdates"
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "noupdates"

def startupCheck():
if bridgeConfig["config"]["swupdate2"]["install"] == True:
bridgeConfig["config"]["swupdate2"]["install"] = False
Expand Down

0 comments on commit 9ac8161

Please sign in to comment.