{"action":"created","issue":{"url":"https://api.github.com/repos/ceph/ceph/issues/22528","repository_url":"https://api.github.com/repos/ceph/ceph","labels_url":"https://api.github.com/repos/ceph/ceph/issues/22528/labels{/name}","comments_url":"https://api.github.com/repos/ceph/ceph/issues/22528/comments","events_url":"https://api.github.com/repos/ceph/ceph/issues/22528/events","html_url":"https://github.com/ceph/ceph/pull/22528","id":331612815,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk0Mjk5NDI0","number":22528,"title":"mgr/dashboard: restcontroller: minor improvements and bug fixes","user":{"login":"rjfd","id":17119885,"node_id":"MDQ6VXNlcjE3MTE5ODg1","avatar_url":"https://avatars0.githubusercontent.com/u/17119885?v=4","gravatar_id":"","url":"https://api.github.com/users/rjfd","html_url":"https://github.com/rjfd","followers_url":"https://api.github.com/users/rjfd/followers","following_url":"https://api.github.com/users/rjfd/following{/other_user}","gists_url":"https://api.github.com/users/rjfd/gists{/gist_id}","starred_url":"https://api.github.com/users/rjfd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjfd/subscriptions","organizations_url":"https://api.github.com/users/rjfd/orgs","repos_url":"https://api.github.com/users/rjfd/repos","events_url":"https://api.github.com/users/rjfd/events{/privacy}","received_events_url":"https://api.github.com/users/rjfd/received_events","type":"User","site_admin":false},"labels":[{"id":134774049,"node_id":"MDU6TGFiZWwxMzQ3NzQwNDk=","url":"https://api.github.com/repos/ceph/ceph/labels/bug%20fix","name":"bug fix","color":"ac0000","default":false},{"id":850326757,"node_id":"MDU6TGFiZWw4NTAzMjY3NTc=","url":"https://api.github.com/repos/ceph/ceph/labels/dashboard","name":"dashboard","color":"68a2c1","default":false},{"id":134774006,"node_id":"MDU6TGFiZWwxMzQ3NzQwMDY=","url":"https://api.github.com/repos/ceph/ceph/labels/feature","name":"feature","color":"00ff24","default":false},{"id":148431321,"node_id":"MDU6TGFiZWwxNDg0MzEzMjE=","url":"https://api.github.com/repos/ceph/ceph/labels/needs-qa","name":"needs-qa","color":"fad8c7","default":false},{"id":920507439,"node_id":"MDU6TGFiZWw5MjA1MDc0Mzk=","url":"https://api.github.com/repos/ceph/ceph/labels/wip-tdehler-testing","name":"wip-tdehler-testing","color":"138c8c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-12T14:28:34Z","updated_at":"2018-06-14T12:44:30Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/ceph/ceph/pulls/22528","html_url":"https://github.com/ceph/ceph/pull/22528","diff_url":"https://github.com/ceph/ceph/pull/22528.diff","patch_url":"https://github.com/ceph/ceph/pull/22528.patch"},"body":"This commit fixes a bug in the resource id inference, and improves\r\nthe detection of the type of parameters in methods accessed by GET,\r\nor DELETE.\r\n\r\nIt also adds the support to override the URL path suffix for\r\n`@Collection` and `@Resource` methods.\r\n\r\nSigned-off-by: Ricardo Dias <rdias@suse.com>"},"comment":{"url":"https://api.github.com/repos/ceph/ceph/issues/comments/397280868","html_url":"https://github.com/ceph/ceph/pull/22528#issuecomment-397280868","issue_url":"https://api.github.com/repos/ceph/ceph/issues/22528","id":397280868,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzI4MDg2OA==","user":{"login":"votdev","id":1897962,"node_id":"MDQ6VXNlcjE4OTc5NjI=","avatar_url":"https://avatars3.githubusercontent.com/u/1897962?v=4","gravatar_id":"","url":"https://api.github.com/users/votdev","html_url":"https://github.com/votdev","followers_url":"https://api.github.com/users/votdev/followers","following_url":"https://api.github.com/users/votdev/following{/other_user}","gists_url":"https://api.github.com/users/votdev/gists{/gist_id}","starred_url":"https://api.github.com/users/votdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/votdev/subscriptions","organizations_url":"https://api.github.com/users/votdev/orgs","repos_url":"https://api.github.com/users/votdev/repos","events_url":"https://api.github.com/users/votdev/events{/privacy}","received_events_url":"https://api.github.com/users/votdev/received_events","type":"User","site_admin":false},"created_at":"2018-06-14T12:44:30Z","updated_at":"2018-06-14T12:44:30Z","author_association":"CONTRIBUTOR","body":"While working with this PR i realized that the ``@RESTController.Resource`` decorator needs the ability to configure the status of the response, otherwise all endpoints will return a 200.\r\n\r\n```\r\n--- src/pybind/mgr/dashboard/controllers/__init__.py\t(date 1528973738000)\r\n+++ src/pybind/mgr/dashboard/controllers/__init__.py\t(date 1528979998000)\r\n@@ -554,14 +554,21 @@\r\n     RESOURCE_ID = None\r\n \r\n     _method_mapping = collections.OrderedDict([\r\n-        ('list', {'method': 'GET', 'resource': False, 'status': 200}),\r\n-        ('create', {'method': 'POST', 'resource': False, 'status': 201}),\r\n-        ('bulk_set', {'method': 'PUT', 'resource': False, 'status': 200}),\r\n-        ('bulk_delete', {'method': 'DELETE', 'resource': False, 'status': 204}),\r\n-        ('get', {'method': 'GET', 'resource': True, 'status': 200}),\r\n-        ('delete', {'method': 'DELETE', 'resource': True, 'status': 204}),\r\n-        ('set', {'method': 'PUT', 'resource': True, 'status': 200})\r\n+        ('list', {'method': 'GET', 'resource': False}),\r\n+        ('create', {'method': 'POST', 'resource': False}),\r\n+        ('bulk_set', {'method': 'PUT', 'resource': False}),\r\n+        ('bulk_delete', {'method': 'DELETE', 'resource': False}),\r\n+        ('get', {'method': 'GET', 'resource': True}),\r\n+        ('delete', {'method': 'DELETE', 'resource': True}),\r\n+        ('set', {'method': 'PUT', 'resource': True})\r\n     ])\r\n+\r\n+    _status_mapping = {\r\n+        'DELETE': 204,\r\n+        'GET': 200,\r\n+        'POST': 201,\r\n+        'PUT': 200\r\n+    }\r\n \r\n     @classmethod\r\n     def infer_resource_id(cls):\r\n@@ -600,8 +607,8 @@\r\n                         path_params = [\"{{{}}}\".format(p) for p in res_id_params]\r\n                         path += \"/{}\".format(\"/\".join(path_params))\r\n \r\n-                status = meth['status']\r\n                 method = meth['method']\r\n+                status = cls._status_mapping[method]\r\n \r\n             elif hasattr(func, \"_collection_method_\"):\r\n                 if func._collection_method_['path']:\r\n@@ -624,6 +631,10 @@\r\n \r\n                 method = func._resource_method_['method']\r\n                 query_params = func._resource_method_['query_params']\r\n+                if func._resource_method_['status'] is None:\r\n+                    status = cls._status_mapping[method]\r\n+                else:\r\n+                    status = func._resource_method_['status']\r\n \r\n             else:\r\n                 continue\r\n@@ -660,7 +671,7 @@\r\n         return wrapper\r\n \r\n     @staticmethod\r\n-    def Resource(method=None, path=None, query_params=None):\r\n+    def Resource(method=None, path=None, query_params=None, status=None):\r\n         if not method:\r\n             method = 'GET'\r\n \r\n@@ -668,7 +679,8 @@\r\n             func._resource_method_ = {\r\n                 'method': method,\r\n                 'path': path,\r\n-                'query_params': query_params\r\n+                'query_params': query_params,\r\n+                'status': status\r\n             }\r\n             return func\r\n         return _wrapper\r\n```"}}
{"actor":{"display_login":"votdev"}}