{ "info": { "author": "Nick Harris", "author_email": "nick.harris@cybergrx.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# graphene-acl\n\nThe motivation for this library is to simplify access control protection for Graphene Fields. A common approach to ACL protection is through the use of a reusable permissions validation decorator. The problem is this is cumbersome for Graphene Fields that use the standard resolver. You are forced to write an unnecessary resolver function just to annotate it with your permissions validator. The second cumbersome problem this library addresses is ACL role based resolvers. Depending on the users role you might want to perform different business logic in order to retrieve the data they requested for a Graphene Field.\n\n## Installation\n\n```bash\n$ pip install graphene-acl\n```\n\n## Usage\n\n### acl_classifier\n\nThe purpose of the classifier is to return a route key that will be used to determine which resolver function is used for resolving the field. The classifier function has access to all the arguments from the field resolver.\n\n### acl_validator\n\nThe purpose of the validator is to authorize access to the field. This validation will occurr before classification routing happens. If authorization validation is different per classification route then you should not use this validator to enforce authorization access. Instead you should authorize at the specific classifier resolver definition.\n\n### Example\n\n```python\nfrom graphene_acl import AclField\nimport graphene\n\ndef classifier(root, info, *args, **kwargs):\n if 'admin' in info.context.jwt.permissions:\n return 'admin'\n return None\n\ndef has_permissions(permissions):\n def validator(root, info, *args, **kwars):\n if (any([permission in info.context.jwt.permissions for permission in permissions])):\n return True\n raise AuthorizationError(f'Not authorized to query field {info.field_name}')\n\n return validator\n\nclass Foo(graphene.ObjectType):\n private_name = AclField(graphene.String, acl_classifier=classifier)\n restricted_name = AclField(graphene.String, acl_validator=has_permissions(['foo:name:read', 'admin']))\n\n@Foo.private_name.resolve('admin')\ndef resolve_private_name__admin(root, info, *args, **kwargs):\n pass\n\n@Foo.private_name.resolve()\ndef resolve_private_name__default(root, info):\n # Alternatively, authorization handling could be done by an acl_validator\n raise Error('Not Authorized')\n```\n\nACL Connection Fields\n\n```python\nfrom graphene_django.filter import DjangoFilterConnectionField\nfrom graphene_acl import acl_field_type\n\nBarConnectionField = acl_field_type('BarConnectionField', DjangoFilterConnectionField)\n\nclass Foo(graphene.ObjectType):\n bar = BarConnectionField(MyNode, acl_permissions=has_permission('FOO'))\n\n```\n\n## Development\n\n### First time setup\n\n- Install Precommit hooks\n- `brew install pre-commit && pre-commit install && pre-commit install --install-hooks`\n- Install poetry: https://github.com/sdispater/poetry#installation\n- `curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python`\n- Install dependencies\n- `poetry install`\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/CyberGRX/graphene-acl", "keywords": "graphene,acl,graphql,python", "license": "MIT", "maintainer": "Nick Harris", "maintainer_email": "nick.harris@cybergrx.com", "name": "graphene-acl", "package_url": "https://pypi.org/project/graphene-acl/", "platform": "", "project_url": "https://pypi.org/project/graphene-acl/", "project_urls": { "Homepage": "https://github.com/CyberGRX/graphene-acl", "Repository": "https://github.com/CyberGRX/graphene-acl" }, "release_url": "https://pypi.org/project/graphene-acl/1.0.4/", "requires_dist": [ "graphene (>=2.1,<3.0)" ], "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "summary": "Graphene Field ACL", "version": "1.0.4" }, "last_serial": 5185865, "releases": { "1.0.2": [ { "comment_text": "", "digests": { "md5": "8c99a8f99304af5a0aaea0110962fb2d", "sha256": "40c8be0264b92dfa6be1afb31bd211aaff71098dfd51b702f43f2c1c44fe56ff" }, "downloads": -1, "filename": "graphene-acl-1.0.2.tar.gz", "has_sig": false, "md5_digest": "8c99a8f99304af5a0aaea0110962fb2d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 4400, "upload_time": "2019-04-15T13:38:24", "url": "https://files.pythonhosted.org/packages/60/88/75b2f14eb4415a76e20d5abab39995be524fa299721b28f50445ed66ef5a/graphene-acl-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "5e2733e18c80c2fb5dc46c416b786f98", "sha256": "eb6caecfa2ffb09b3950c8ef95c76fcd1b574174b81b712d3f995f8bef001866" }, "downloads": -1, "filename": "graphene-acl-1.0.3.tar.gz", "has_sig": false, "md5_digest": "5e2733e18c80c2fb5dc46c416b786f98", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 4422, "upload_time": "2019-04-23T19:00:30", "url": "https://files.pythonhosted.org/packages/33/ca/291ca72fe2e28958128713444b431093950b20612709e395009b0b80cc19/graphene-acl-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "cda0bf0ca52739340342636720089286", "sha256": "e5cb7a17764eed85abb58a1e811b72d6c2c7964cc8e8cb4e5e41f17e81d46b71" }, "downloads": -1, "filename": "graphene-acl-1.0.4.tar.gz", "has_sig": false, "md5_digest": "cda0bf0ca52739340342636720089286", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 5281, "upload_time": "2019-04-25T03:21:02", "url": "https://files.pythonhosted.org/packages/fa/b0/ee4c55f5d81ef1fdefa570771b233b5e7e7c1d119ede0400a0647a3b57af/graphene-acl-1.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cda0bf0ca52739340342636720089286", "sha256": "e5cb7a17764eed85abb58a1e811b72d6c2c7964cc8e8cb4e5e41f17e81d46b71" }, "downloads": -1, "filename": "graphene-acl-1.0.4.tar.gz", "has_sig": false, "md5_digest": "cda0bf0ca52739340342636720089286", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 5281, "upload_time": "2019-04-25T03:21:02", "url": "https://files.pythonhosted.org/packages/fa/b0/ee4c55f5d81ef1fdefa570771b233b5e7e7c1d119ede0400a0647a3b57af/graphene-acl-1.0.4.tar.gz" } ] }