mirror of
				https://github.com/laurivosandi/certidude
				synced 2025-10-31 09:29:13 +00:00 
			
		
		
		
	api: tag: drop usage of global authority import
This commit is contained in:
		| @@ -232,11 +232,11 @@ def certidude_app(log_handlers=[]): | |||||||
|     app.add_route("/api/signed/{cn}/script/", ScriptResource(authority)) |     app.add_route("/api/signed/{cn}/script/", ScriptResource(authority)) | ||||||
|  |  | ||||||
|     # API calls used by pushed events on the JS end |     # API calls used by pushed events on the JS end | ||||||
|     app.add_route("/api/signed/{cn}/tag/", TagResource()) |     app.add_route("/api/signed/{cn}/tag/", TagResource(authority)) | ||||||
|     app.add_route("/api/signed/{cn}/lease/", LeaseDetailResource(authority)) |     app.add_route("/api/signed/{cn}/lease/", LeaseDetailResource(authority)) | ||||||
|  |  | ||||||
|     # API call used to delete existing tags |     # API call used to delete existing tags | ||||||
|     app.add_route("/api/signed/{cn}/tag/{tag}/", TagDetailResource()) |     app.add_route("/api/signed/{cn}/tag/{tag}/", TagDetailResource(authority)) | ||||||
|  |  | ||||||
|     # Gateways can submit leases via this API call |     # Gateways can submit leases via this API call | ||||||
|     app.add_route("/api/lease/", LeaseResource(authority)) |     app.add_route("/api/lease/", LeaseResource(authority)) | ||||||
|   | |||||||
| @@ -1,18 +1,21 @@ | |||||||
| import falcon | import falcon | ||||||
| import logging | import logging | ||||||
| from xattr import getxattr, removexattr, setxattr | from xattr import getxattr, removexattr, setxattr | ||||||
| from certidude import authority, push | from certidude import push | ||||||
| from certidude.auth import login_required, authorize_admin | from certidude.auth import login_required, authorize_admin | ||||||
| from certidude.decorators import serialize, csrf_protection | from certidude.decorators import serialize, csrf_protection | ||||||
|  |  | ||||||
| logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||||
|  |  | ||||||
| class TagResource(object): | class TagResource(object): | ||||||
|  |     def __init__(self, authority): | ||||||
|  |         self.authority = authority | ||||||
|  |  | ||||||
|     @serialize |     @serialize | ||||||
|     @login_required |     @login_required | ||||||
|     @authorize_admin |     @authorize_admin | ||||||
|     def on_get(self, req, resp, cn): |     def on_get(self, req, resp, cn): | ||||||
|         path, buf, cert, signed, expires = authority.get_signed(cn) |         path, buf, cert, signed, expires = self.authority.get_signed(cn) | ||||||
|         tags = [] |         tags = [] | ||||||
|         try: |         try: | ||||||
|             for tag in getxattr(path, "user.xdg.tags").decode("utf-8").split(","): |             for tag in getxattr(path, "user.xdg.tags").decode("utf-8").split(","): | ||||||
| @@ -30,7 +33,7 @@ class TagResource(object): | |||||||
|     @login_required |     @login_required | ||||||
|     @authorize_admin |     @authorize_admin | ||||||
|     def on_post(self, req, resp, cn): |     def on_post(self, req, resp, cn): | ||||||
|         path, buf, cert, signed, expires = authority.get_signed(cn) |         path, buf, cert, signed, expires = self.authority.get_signed(cn) | ||||||
|         key, value = req.get_param("key", required=True), req.get_param("value", required=True) |         key, value = req.get_param("key", required=True), req.get_param("value", required=True) | ||||||
|         try: |         try: | ||||||
|             tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) |             tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) | ||||||
| @@ -46,11 +49,14 @@ class TagResource(object): | |||||||
|  |  | ||||||
|  |  | ||||||
| class TagDetailResource(object): | class TagDetailResource(object): | ||||||
|  |     def __init__(self, authority): | ||||||
|  |         self.authority = authority | ||||||
|  |  | ||||||
|     @csrf_protection |     @csrf_protection | ||||||
|     @login_required |     @login_required | ||||||
|     @authorize_admin |     @authorize_admin | ||||||
|     def on_put(self, req, resp, cn, tag): |     def on_put(self, req, resp, cn, tag): | ||||||
|         path, buf, cert, signed, expires = authority.get_signed(cn) |         path, buf, cert, signed, expires = self.authority.get_signed(cn) | ||||||
|         value = req.get_param("value", required=True) |         value = req.get_param("value", required=True) | ||||||
|         try: |         try: | ||||||
|             tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) |             tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) | ||||||
| @@ -72,7 +78,7 @@ class TagDetailResource(object): | |||||||
|     @login_required |     @login_required | ||||||
|     @authorize_admin |     @authorize_admin | ||||||
|     def on_delete(self, req, resp, cn, tag): |     def on_delete(self, req, resp, cn, tag): | ||||||
|         path, buf, cert, signed, expires = authority.get_signed(cn) |         path, buf, cert, signed, expires = self.authority.get_signed(cn) | ||||||
|         tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) |         tags = set(getxattr(path, "user.xdg.tags").decode("utf-8").split(",")) | ||||||
|         tags.remove(tag) |         tags.remove(tag) | ||||||
|         if not tags: |         if not tags: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user