summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2018-08-23 10:44:07 -0500
committerAdriana Kobylak <anoo@us.ibm.com>2018-08-23 11:12:51 -0500
commita8b05d161ef3367f3fc2f4a5e44a2b0b69a9f3d2 (patch)
tree8042bffa30fb34db14d01c4c54ef6314597b27aa
parent3a9a51c969c2aeb7cceb7b2bee203a10afb2da95 (diff)
downloadphosphor-rest-server-a8b05d161ef3367f3fc2f4a5e44a2b0b69a9f3d2.zip
phosphor-rest-server-a8b05d161ef3367f3fc2f4a5e44a2b0b69a9f3d2.tar.gz
rest_dbus: Add read-only property error
There is now support in sdbusplus to mark a property as read-only, so that a REST request to modify it would return org.freedesktop.DBus.Error.PropertyReadOnly. Add support for this error to provide a more useful and compact error instead of the default 500 Internal Error with the traceback. Tested: Instead of a 500 error with traceback, a compact 403 error is displayed: $ curl b cjar -k -H "Content-Type: application/json" -X PUT -d '{"data": 50}' https://${bmc}/xyz/openbmc_project/control/power_supply/attr/DeratingFactor { "data": { "description": "org.freedesktop.DBus.Error.PropertyReadOnly: Property 'DeratingFactor' is not writable." }, "message": "403 Forbidden", "status": "error" } Change-Id: I5648a99c7656a6f9d9a8ca967418fabd64b080c6 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
-rw-r--r--module/obmc/wsgi/apps/rest_dbus.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 5eaffb7..9cb69f0 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -50,6 +50,7 @@ if have_wsock:
DBUS_UNKNOWN_INTERFACE = 'org.freedesktop.DBus.Error.UnknownInterface'
DBUS_UNKNOWN_METHOD = 'org.freedesktop.DBus.Error.UnknownMethod'
+DBUS_PROPERTY_READONLY = 'org.freedesktop.DBus.Error.PropertyReadOnly'
DBUS_INVALID_ARGS = 'org.freedesktop.DBus.Error.InvalidArgs'
DBUS_TYPE_ERROR = 'org.freedesktop.DBus.Python.TypeError'
DELETE_IFACE = 'xyz.openbmc_project.Object.Delete'
@@ -495,6 +496,8 @@ class PropertyHandler(RouteHandler):
except ValueError as e:
abort(400, str(e))
except dbus.exceptions.DBusException as e:
+ if e.get_dbus_name() == DBUS_PROPERTY_READONLY:
+ abort(403, str(e))
if e.get_dbus_name() == DBUS_INVALID_ARGS and retry:
bus_name = properties_iface.bus_name
expected_type = get_type_signature_by_introspection(self.bus,
OpenPOWER on IntegriCloud