{ "info": { "author": "Arie van Luttikhuizen", "author_email": "yulibaozi@qq.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "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", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "\n![Crossplane Logo](https://raw.githubusercontent.com/nginxinc/crossplane/master/ext/crossplane-logo.png)\n

crossplane

\n

Reliable and fast NGINX configuration file parser and builder

\n\n

\n\n\n\n\n

\n\n - [Install](#install)\n - [Command Line Interface](#command-line-interface)\n - [crossplane parse](#crossplane-parse)\n - [crossplane build](#crossplane-build)\n - [crossplane lex](#crossplane-lex)\n - [crossplane format](#crossplane-format)\n - [crossplane minify](#crossplane-minify)\n - [Python Module](#python-module)\n - [crossplane.parse()](#crossplaneparse)\n - [crossplane.build()](#crossplanebuild)\n - [crossplane.lex()](#crossplanelex)\n - [Other Languages](#other-languages)\n\n## Install\n\nYou can install both the [Command Line\nInterface](#command-line-interface) and [Python Module](#python-module)\nvia:\n\n pip install crossplane\n\n## Command Line Interface\n\n```\nusage: crossplane [options]\n\nvarious operations for nginx config files\n\noptional arguments:\n -h, --help show this help message and exit\n -V, --version show program's version number and exit\n\ncommands:\n parse parses a json payload for an nginx config\n build builds an nginx config from a json payload\n lex lexes tokens from an nginx config file\n minify removes all whitespace from an nginx config\n format formats an nginx config file\n help show help for commands\n```\n\n### crossplane parse\n\nThis command will take a path to a main NGINX config file as input, then\nparse the entire config into the schema defined below, and dumps the\nentire thing as a JSON payload.\n\n```\nusage: crossplane parse [-h] [-o OUT] [-i NUM] [--ignore DIRECTIVES]\n [--no-catch] [--tb-onerror] [--single-file]\n [--include-comments] [--strict]\n filename\n\nparses a json payload for an nginx config\n\npositional arguments:\n filename the nginx config file\n\noptional arguments:\n -h, --help show this help message and exit\n -o OUT, --out OUT write output to a file\n -i NUM, --indent NUM number of spaces to indent output\n --ignore DIRECTIVES ignore directives (comma-separated)\n --no-catch only collect first error in file\n --tb-onerror include tracebacks in config errors\n --combine use includes to create one single file\n --single-file do not include other config files\n --include-comments include comments in json\n --strict raise errors for unknown directives\n```\n\n**Privacy and Security**\n\nSince `crossplane` is usually used to create payloads that are sent to\ndifferent servers, it's important to keep security in mind. For that\nreason, the `--ignore` option was added. It can be used to keep certain\nsensitive directives out of the payload output entirely.\n\nFor example, we always use the equivalent of this flag in the [NGINX Amplify\nAgent](https://github.com/nginxinc/nginx-amplify-agent/) out of respect\nfor our users'\n privacy:\n\n --ignore=auth_basic_user_file,secure_link_secret,ssl_certificate_key,ssl_client_certificate,ssl_password_file,ssl_stapling_file,ssl_trusted_certificate\n\n#### Schema\n\n**Response Object**\n\n```js\n{\n \"status\": String, // \"ok\" or \"failed\" if \"errors\" is not empty\n \"errors\": Array, // aggregation of \"errors\" from Config objects\n \"config\": Array // Array of Config objects\n}\n```\n\n**Config Object**\n\n```js\n{\n \"file\": String, // the full path of the config file\n \"status\": String, // \"ok\" or \"failed\" if errors is not empty array\n \"errors\": Array, // Array of Error objects\n \"parsed\": Array // Array of Directive objects\n}\n```\n\n**Directive Object**\n\n```js\n{\n \"directive\": String, // the name of the directive\n \"line\": Number, // integer line number the directive started on\n \"args\": Array, // Array of String arguments\n \"includes\": Array, // Array of integers (included iff this is an include directive)\n \"block\": Array // Array of Directive Objects (included iff this is a block)\n}\n```\n\n
\n\n
\n\nNote\n\n
\n\nIf this is an `include` directive and the `--single-file` flag was not\nused, an `\"includes\"` value will be used that holds an Array of indices\nof the configs that are included by this directive.\n\nIf this is a block directive, a `\"block\"` value will be used that holds\nan Array of more Directive Objects that define the block context.\n\n
\n\n**Error Object**\n\n```js\n{\n \"file\": String, // the full path of the config file\n \"line\": Number, // integer line number the directive that caused the error\n \"error\": String, // the error message\n \"callback\": Object // only included iff an \"onerror\" function was passed to parse()\n}\n```\n\n
\n\n
\n\nNote\n\n
\n\nIf the `--tb-onerror` flag was used by crossplane parse, `\"callback\"`\nwill contain a string that represents the traceback that the error\ncaused.\n\n
\n\n#### Example\n\nThe main NGINX config file is at `/etc/nginx/nginx.conf`:\n\n```nginx\nevents {\n worker_connections 1024;\n}\n\nhttp {\n include conf.d/*.conf;\n}\n```\n\nAnd this config file is at `/etc/nginx/conf.d/servers.conf`:\n\n```nginx\nserver {\n listen 8080;\n location / {\n try_files 'foo bar' baz;\n }\n}\n\nserver {\n listen 8081;\n location / {\n return 200 'success!';\n }\n}\n```\n\nSo then if you run this:\n\n crossplane parse --indent=4 /etc/nginx/nginx.conf\n\nThe prettified JSON output would look like this:\n\n```js\n{\n \"status\": \"ok\",\n \"errors\": [],\n \"config\": [\n {\n \"file\": \"/etc/nginx/nginx.conf\",\n \"status\": \"ok\",\n \"errors\": [],\n \"parsed\": [\n {\n \"directive\": \"events\",\n \"line\": 1,\n \"args\": [],\n \"block\": [\n {\n \"directive\": \"worker_connections\",\n \"line\": 2,\n \"args\": [\n \"1024\"\n ]\n }\n ]\n },\n {\n \"directive\": \"http\",\n \"line\": 5,\n \"args\": [],\n \"block\": [\n {\n \"directive\": \"include\",\n \"line\": 6,\n \"args\": [\n \"conf.d/*.conf\"\n ],\n \"includes\": [\n 1\n ]\n }\n ]\n }\n ]\n },\n {\n \"file\": \"/etc/nginx/conf.d/servers.conf\",\n \"status\": \"ok\",\n \"errors\": [],\n \"parsed\": [\n {\n \"directive\": \"server\",\n \"line\": 1,\n \"args\": [],\n \"block\": [\n {\n \"directive\": \"listen\",\n \"line\": 2,\n \"args\": [\n \"8080\"\n ]\n },\n {\n \"directive\": \"location\",\n \"line\": 3,\n \"args\": [\n \"/\"\n ],\n \"block\": [\n {\n \"directive\": \"try_files\",\n \"line\": 4,\n \"args\": [\n \"foo bar\",\n \"baz\"\n ]\n }\n ]\n }\n ]\n },\n {\n \"directive\": \"server\",\n \"line\": 8,\n \"args\": [],\n \"block\": [\n {\n \"directive\": \"listen\",\n \"line\": 9,\n \"args\": [\n \"8081\"\n ]\n },\n {\n \"directive\": \"location\",\n \"line\": 10,\n \"args\": [\n \"/\"\n ],\n \"block\": [\n {\n \"directive\": \"return\",\n \"line\": 11,\n \"args\": [\n \"200\",\n \"success!\"\n ]\n }\n ]\n }\n ]\n }\n ]\n }\n ]\n}\n```\n\n#### crossplane parse (advanced)\n\nThis tool uses two flags that can change how `crossplane` handles\nerrors.\n\nThe first, `--no-catch`, can be used if you'd prefer that crossplane\nquit parsing after the first error it finds.\n\nThe second, `--tb-onerror`, will add a `\"callback\"` key to all error\nobjects in the JSON output, each containing a string representation of\nthe traceback that would have been raised by the parser if the exception\nhad not been caught. This can be useful for logging purposes.\n\n### crossplane build\n\nThis command will take a path to a file as input. The file should\ncontain a JSON representation of an NGINX config that has the structure\ndefined above. Saving and using the output from `crossplane parse` to\nrebuild your config files should not cause any differences in content\nexcept for the formatting.\n\n```\nusage: crossplane build [-h] [-d PATH] [-f] [-i NUM | -t] [--no-headers]\n [--stdout] [-v]\n filename\n\nbuilds an nginx config from a json payload\n\npositional arguments:\n filename the file with the config payload\n\noptional arguments:\n -h, --help show this help message and exit\n -v, --verbose verbose output\n -d PATH, --dir PATH the base directory to build in\n -f, --force overwrite existing files\n -i NUM, --indent NUM number of spaces to indent output\n -t, --tabs indent with tabs instead of spaces\n --no-headers do not write header to configs\n --stdout write configs to stdout instead\n```\n\n### crossplane lex\n\nThis command takes an NGINX config file, splits it into tokens by\nremoving whitespace and comments, and dumps the list of tokens as a JSON\narray.\n\n```\nusage: crossplane lex [-h] [-o OUT] [-i NUM] [-n] filename\n\nlexes tokens from an nginx config file\n\npositional arguments:\n filename the nginx config file\n\noptional arguments:\n -h, --help show this help message and exit\n -o OUT, --out OUT write output to a file\n -i NUM, --indent NUM number of spaces to indent output\n -n, --line-numbers include line numbers in json payload\n```\n\n#### Example\n\nPassing in this NGINX config file at `/etc/nginx/nginx.conf`:\n\n```nginx\nevents {\n worker_connections 1024;\n}\n\nhttp {\n include conf.d/*.conf;\n}\n```\n\nBy running:\n\n crossplane lex /etc/nginx/nginx.conf\n\nWill result in this JSON\noutput:\n\n```js\n[\"events\",\"{\",\"worker_connections\",\"1024\",\";\",\"}\",\"http\",\"{\",\"include\",\"conf.d/*.conf\",\";\",\"}\"]\n```\n\nHowever, if you decide to use the `--line-numbers` flag, your output\nwill look\nlike:\n\n```js\n[[\"events\",1],[\"{\",1],[\"worker_connections\",2],[\"1024\",2],[\";\",2],[\"}\",3],[\"http\",5],[\"{\",5],[\"include\",6],[\"conf.d/*.conf\",6],[\";\",6],[\"}\",7]]\n```\n\n### crossplane format\n\nThis is a quick and dirty tool that uses [crossplane\nparse](#crossplane-parse) internally to format an NGINX config file.\nIt serves the purpose of demonstrating what you can do with `crossplane`'s\nparsing abilities. It is not meant to be a fully fleshed out, feature-rich\nformatting tool. If that is what you are looking for, then you may want to\nlook writing your own using crossplane's Python API.\n\n```\nusage: crossplane format [-h] [-o OUT] [-i NUM | -t] filename\n\nformats an nginx config file\n\npositional arguments:\n filename the nginx config file\n\noptional arguments:\n -h, --help show this help message and exit\n -o OUT, --out OUT write output to a file\n -i NUM, --indent NUM number of spaces to indent output\n -t, --tabs indent with tabs instead of spaces\n```\n\n### crossplane minify\n\nThis is a simple and fun little tool that uses [crossplane\nlex](#crossplane-lex) internally to remove as much whitespace from an\nNGINX config file as possible without affecting what it does. It can't\nimagine it will have much of a use to most people, but it demonstrates\nthe kinds of things you can do with `crossplane`'s lexing abilities.\n\n```\nusage: crossplane minify [-h] [-o OUT] filename\n\nremoves all whitespace from an nginx config\n\npositional arguments:\n filename the nginx config file\n\noptional arguments:\n -h, --help show this help message and exit\n -o OUT, --out OUT write output to a file\n```\n\n## Python Module\n\nIn addition to the command line tool, you can import `crossplane` as a\npython module. There are two basic functions that the module will\nprovide you: `parse` and `lex`.\n\n### crossplane.parse()\n\n```python\nimport crossplane\npayload = crossplane.parse('/etc/nginx/nginx.conf')\n```\n\nThis will return the same payload as described in the [crossplane\nparse](#crossplane-parse) section, except it will be Python dicts and\nnot one giant JSON string.\n\n### crossplane.build()\n\n```python\nimport crossplane\nconfig = crossplane.build(\n [{\n \"directive\": \"events\",\n \"args\": [],\n \"block\": [{\n \"directive\": \"worker_connections\",\n \"args\": [\"1024\"]\n }]\n }]\n)\n```\n\nThis will return a single string that contains an entire NGINX config\nfile.\n\n### crossplane.lex()\n\n```python\nimport crossplane\ntokens = crossplane.lex('/etc/nginx/nginx.conf')\n```\n\n`crossplane.lex` generates 2-tuples. Inserting these pairs into a list\nwill result in a long list similar to what you can see in the\n[crossplane lex](#crossplane-lex) section when the `--line-numbers` flag\nis used, except it will obviously be a Python list of tuples and not one\ngiant JSON string.\n\n## Other Languages\n\n- Ruby port by [@gdanko](https://github.com/gdanko):\n \n\n\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/caas-one/crossplane", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "cscrossplane", "package_url": "https://pypi.org/project/cscrossplane/", "platform": "", "project_url": "https://pypi.org/project/cscrossplane/", "project_urls": { "Homepage": "https://github.com/caas-one/crossplane" }, "release_url": "https://pypi.org/project/cscrossplane/0.5.5/", "requires_dist": null, "requires_python": "", "summary": "Reliable and fast NGINX configuration file parser.", "version": "0.5.5" }, "last_serial": 5792788, "releases": { "0.5.3": [ { "comment_text": "", "digests": { "md5": "c3f2ae1aecbd1d4875bd83acada7718b", "sha256": "03b8ced85ed9fadd8b833c0f115e8af0eb33ca9d329537a956cf711a5411f641" }, "downloads": -1, "filename": "cscrossplane-0.5.3-py3-none-any.whl", "has_sig": false, "md5_digest": "c3f2ae1aecbd1d4875bd83acada7718b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 31415, "upload_time": "2019-09-06T14:31:10", "url": "https://files.pythonhosted.org/packages/c1/d0/a72d1ab0bf67d52e9c60bac821cbcdc6002a2a0ad591fa3b40e3efe85576/cscrossplane-0.5.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ab73bf50bd09b7897b7ed1b051225363", "sha256": "87df316994b21cc51921087e1e69a458a0db87476bc502c6ead0fd0d36dea71a" }, "downloads": -1, "filename": "cscrossplane-0.5.3.tar.gz", "has_sig": false, "md5_digest": "ab73bf50bd09b7897b7ed1b051225363", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 39995, "upload_time": "2019-09-06T14:31:15", "url": "https://files.pythonhosted.org/packages/f5/ad/2f6ad2af499f932b452f90e0f902b4e23cb3f636af19d87f47e407573bcd/cscrossplane-0.5.3.tar.gz" } ], "0.5.4": [ { "comment_text": "", "digests": { "md5": "b053b927b023fe78b9c9cfcc633aa9c8", "sha256": "e857078e8bff4c00e76a1410ff881edbe62d5e7b1c1fbc0180962e5d1b9e8fde" }, "downloads": -1, "filename": "cscrossplane-0.5.4-py3-none-any.whl", "has_sig": false, "md5_digest": "b053b927b023fe78b9c9cfcc633aa9c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 31445, "upload_time": "2019-09-06T15:09:48", "url": "https://files.pythonhosted.org/packages/01/25/5f211fddab4ee86339cc833331f64023b4a544713a2ac38ed04d79f6c658/cscrossplane-0.5.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1c1a1f4c31b3e7b1cb0740f5feedeb17", "sha256": "8acfd6256c5296dfa4ae97e08384727545ee038126083e9920ae88a1be1a0ca6" }, "downloads": -1, "filename": "cscrossplane-0.5.4.tar.gz", "has_sig": false, "md5_digest": "1c1a1f4c31b3e7b1cb0740f5feedeb17", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 39948, "upload_time": "2019-09-06T15:09:51", "url": "https://files.pythonhosted.org/packages/03/22/d90da2e261e0126d723ef81e6a35649d82854f957ddb0c31d9dc49065f58/cscrossplane-0.5.4.tar.gz" } ], "0.5.5": [ { "comment_text": "", "digests": { "md5": "55a87b2777b4b3169f0ba6852a51d535", "sha256": "350b35ad0a7647c9900fddd5cf66653585bcc8b8aa15d2703ee84f942673794c" }, "downloads": -1, "filename": "cscrossplane-0.5.5-py3-none-any.whl", "has_sig": false, "md5_digest": "55a87b2777b4b3169f0ba6852a51d535", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 31441, "upload_time": "2019-09-06T15:20:31", "url": "https://files.pythonhosted.org/packages/07/77/dc655bad0e0cc3d2722cc5ea05ebe3f4c88da063e6b8ab40865d96d599bd/cscrossplane-0.5.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "18c9dc32358132a156bcc61689cb1862", "sha256": "58c6800ec29010ec42b87c60a84aa79e6884c5d4001c96bd63d45f57f2ef8eeb" }, "downloads": -1, "filename": "cscrossplane-0.5.5.tar.gz", "has_sig": false, "md5_digest": "18c9dc32358132a156bcc61689cb1862", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 39948, "upload_time": "2019-09-06T15:20:33", "url": "https://files.pythonhosted.org/packages/39/0d/5f6b6d43140dfb436f305e422fc20ea65a26f0bec3bae5c2256e5bc7f0b3/cscrossplane-0.5.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "55a87b2777b4b3169f0ba6852a51d535", "sha256": "350b35ad0a7647c9900fddd5cf66653585bcc8b8aa15d2703ee84f942673794c" }, "downloads": -1, "filename": "cscrossplane-0.5.5-py3-none-any.whl", "has_sig": false, "md5_digest": "55a87b2777b4b3169f0ba6852a51d535", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 31441, "upload_time": "2019-09-06T15:20:31", "url": "https://files.pythonhosted.org/packages/07/77/dc655bad0e0cc3d2722cc5ea05ebe3f4c88da063e6b8ab40865d96d599bd/cscrossplane-0.5.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "18c9dc32358132a156bcc61689cb1862", "sha256": "58c6800ec29010ec42b87c60a84aa79e6884c5d4001c96bd63d45f57f2ef8eeb" }, "downloads": -1, "filename": "cscrossplane-0.5.5.tar.gz", "has_sig": false, "md5_digest": "18c9dc32358132a156bcc61689cb1862", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 39948, "upload_time": "2019-09-06T15:20:33", "url": "https://files.pythonhosted.org/packages/39/0d/5f6b6d43140dfb436f305e422fc20ea65a26f0bec3bae5c2256e5bc7f0b3/cscrossplane-0.5.5.tar.gz" } ] }