generate-gizmosql-token


Namegenerate-gizmosql-token JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryA package which generates a GizmoSQL token (JWT) for auth testing
upload_time2025-09-10 19:51:42
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords gizmosql auth token bearer jwt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Generate [GizmoSQL](https://gizmodata.com/gizmosql) (JWT) Token - by [GizmoData](https://gizmodata.com)™

[<img src="https://img.shields.io/badge/GitHub-gizmodata%2Fgenerate--gizmosql--token-blue.svg?logo=Github">](https://github.com/gizmodata/generate-gizmosql-token)
[![generate-gizmosql-token-ci](https://github.com/gizmodata/generate-gizmosql-token/actions/workflows/ci.yml/badge.svg)](https://github.com/gizmodata/generate-gizmosql-token/actions/workflows/ci.yml)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/generate-gizmosql-token)](https://pypi.org/project/generate-gizmosql-token/)
[![PyPI version](https://badge.fury.io/py/generate-gizmosql-token.svg)](https://badge.fury.io/py/generate-gizmosql-token)
[![PyPI Downloads](https://img.shields.io/pypi/dm/generate-gizmosql-token.svg)](https://pypi.org/project/generate-gizmosql-token/)

A utility for generating Bearer Authentication Tokens (Javascript Web Tokens - JWTs) for testing [GizmoSQL](https://github.com/gizmodata/gizmosql) (JWT) token authentication.

# Setup (to run locally)

## Install Python package
### from PyPi
```shell
# Create the virtual environment
python3 -m venv .venv

# Activate the virtual environment
. .venv/bin/activate

# Upgrade pip
pip install --upgrade pip

# Install the package (in editable mode)
pip install generate-gizmosql-token
```

### from source - for development
```shell
git clone https://github.com/gizmodata/generate-gizmosql-token

cd generate-gizmosql-token

# Create the virtual environment
python3 -m venv .venv

# Activate the virtual environment
. .venv/bin/activate

# Upgrade pip, setuptools, and wheel
pip install --upgrade pip setuptools wheel

# Install the package (in editable mode)
pip install --editable .[dev]
```

### Note
For the following commands - if you are running from source and using `--editable` mode (for development purposes) - you will need to set the PYTHONPATH environment variable as follows:
```shell
export PYTHONPATH=$(pwd)/src
```

### Usage Example
```shell
generate-gizmosql-token \
  --issuer "GizmoData LLC" \
  --audience "GizmoSQL Server" \
  --subject "philip@gizmodata.com" \
  --role "admin" \
  --token-lifetime-seconds 86400 \
  --output-file-format "output/gizmosql_token_{issuer}_{audience}_{subject}.jwt" \
  --private-key-file keys/private_key.pem
```

### Using the generated token with [GizmoSQL](https://github.com/gizmodata/gizmosql)

#### Server setup
In order to use the JWT generated by this package, you must start the GizmoSQL server using the public certificate associated with the private key you signed the JWT with using this utility.

Below is an example of starting the GizmoSQL server with TLS and JWT authentication enabled.

Please note - you MUST use the issuer, audience, and the public certificate that matches the private key you used to sign the JWT using this utility in order for the token to be accepted by the server.
```bash
gizmosql_server                                         \
   --database-filename data/tpch.db                     \
   --username gizmosql_user                             \
   --print-queries                                      \
   --tls tls/cert0.pem tls/cert0.key                    \
   --token-allowed-issuer "GizmoData LLC"               \
   --token-allowed-audience "GizmoSQL Server"           \
   --token-signature-verify-cert-filename tls/jwt.pem   \
   --log-format json                                    \
   --access-log off
   --log-level info
```

#### JDBC
You can use the generated token with GizmoSQL via JDBC by appending the token to the JDBC connection string as follows:
```text
jdbc:arrow-flight-sql://hostname:port?useEncryption=true&disableCertificateVerification=true&token=<YOUR_GENERATED_TOKEN>
```

#### ADBC
You can use the generated token with GizmoSQL via ADBC using the `adbc_driver_flightsql` package as follows - if you have set the environment variable `GIZMOSQL_TOKEN` to the generated token:
```python
import os

from adbc_driver_flightsql import dbapi as gizmosql, DatabaseOptions

with gizmosql.connect(uri="grpc+tls://localhost:31337",
                      db_kwargs={
                          DatabaseOptions.AUTHORIZATION_HEADER.value: f"Bearer {os.getenv("GIZMOSQL_TOKEN", "BAD TOKEN!")}",
                          DatabaseOptions.TLS_SKIP_VERIFY.value: "true",
                      },
                      autocommit=True
                      ) as conn:
    with conn.cursor() as cur:
        print(f"Catalog: {conn.adbc_current_catalog}")
        print(f"Schema: {conn.adbc_current_db_schema}")

        cur.execute("SELECT * FROM region")
        x = cur.fetch_arrow_table()
        print(x)
```

### Handy development commands
#### Generate self-signed certificate and private key for testing purposes
There is a handy shell script (if you clone the repo) in [scripts/gen-certs.sh](scripts/gen-certs.sh) that you can use to generate a self-signed certificate and private key for testing purposes.   
```bash
scripts/gen-certs.sh
```

#### Version management

##### Bump the version of the application - (you must have installed from source with the [dev] extras)
```bash
bumpver update --patch
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "generate-gizmosql-token",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "gizmosql, auth, token, bearer, jwt",
    "author": null,
    "author_email": "Philip Moore <philip@gizmodata.com>",
    "download_url": "https://files.pythonhosted.org/packages/a9/67/520476c1e8cd3203f2212916e910fb54642ded6c70817d1742cfb3630159/generate_gizmosql_token-0.0.4.tar.gz",
    "platform": null,
    "description": "# Generate [GizmoSQL](https://gizmodata.com/gizmosql) (JWT) Token - by [GizmoData](https://gizmodata.com)\u2122\n\n[<img src=\"https://img.shields.io/badge/GitHub-gizmodata%2Fgenerate--gizmosql--token-blue.svg?logo=Github\">](https://github.com/gizmodata/generate-gizmosql-token)\n[![generate-gizmosql-token-ci](https://github.com/gizmodata/generate-gizmosql-token/actions/workflows/ci.yml/badge.svg)](https://github.com/gizmodata/generate-gizmosql-token/actions/workflows/ci.yml)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/generate-gizmosql-token)](https://pypi.org/project/generate-gizmosql-token/)\n[![PyPI version](https://badge.fury.io/py/generate-gizmosql-token.svg)](https://badge.fury.io/py/generate-gizmosql-token)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/generate-gizmosql-token.svg)](https://pypi.org/project/generate-gizmosql-token/)\n\nA utility for generating Bearer Authentication Tokens (Javascript Web Tokens - JWTs) for testing [GizmoSQL](https://github.com/gizmodata/gizmosql) (JWT) token authentication.\n\n# Setup (to run locally)\n\n## Install Python package\n### from PyPi\n```shell\n# Create the virtual environment\npython3 -m venv .venv\n\n# Activate the virtual environment\n. .venv/bin/activate\n\n# Upgrade pip\npip install --upgrade pip\n\n# Install the package (in editable mode)\npip install generate-gizmosql-token\n```\n\n### from source - for development\n```shell\ngit clone https://github.com/gizmodata/generate-gizmosql-token\n\ncd generate-gizmosql-token\n\n# Create the virtual environment\npython3 -m venv .venv\n\n# Activate the virtual environment\n. .venv/bin/activate\n\n# Upgrade pip, setuptools, and wheel\npip install --upgrade pip setuptools wheel\n\n# Install the package (in editable mode)\npip install --editable .[dev]\n```\n\n### Note\nFor the following commands - if you are running from source and using `--editable` mode (for development purposes) - you will need to set the PYTHONPATH environment variable as follows:\n```shell\nexport PYTHONPATH=$(pwd)/src\n```\n\n### Usage Example\n```shell\ngenerate-gizmosql-token \\\n  --issuer \"GizmoData LLC\" \\\n  --audience \"GizmoSQL Server\" \\\n  --subject \"philip@gizmodata.com\" \\\n  --role \"admin\" \\\n  --token-lifetime-seconds 86400 \\\n  --output-file-format \"output/gizmosql_token_{issuer}_{audience}_{subject}.jwt\" \\\n  --private-key-file keys/private_key.pem\n```\n\n### Using the generated token with [GizmoSQL](https://github.com/gizmodata/gizmosql)\n\n#### Server setup\nIn order to use the JWT generated by this package, you must start the GizmoSQL server using the public certificate associated with the private key you signed the JWT with using this utility.\n\nBelow is an example of starting the GizmoSQL server with TLS and JWT authentication enabled.\n\nPlease note - you MUST use the issuer, audience, and the public certificate that matches the private key you used to sign the JWT using this utility in order for the token to be accepted by the server.\n```bash\ngizmosql_server                                         \\\n   --database-filename data/tpch.db                     \\\n   --username gizmosql_user                             \\\n   --print-queries                                      \\\n   --tls tls/cert0.pem tls/cert0.key                    \\\n   --token-allowed-issuer \"GizmoData LLC\"               \\\n   --token-allowed-audience \"GizmoSQL Server\"           \\\n   --token-signature-verify-cert-filename tls/jwt.pem   \\\n   --log-format json                                    \\\n   --access-log off\n   --log-level info\n```\n\n#### JDBC\nYou can use the generated token with GizmoSQL via JDBC by appending the token to the JDBC connection string as follows:\n```text\njdbc:arrow-flight-sql://hostname:port?useEncryption=true&disableCertificateVerification=true&token=<YOUR_GENERATED_TOKEN>\n```\n\n#### ADBC\nYou can use the generated token with GizmoSQL via ADBC using the `adbc_driver_flightsql` package as follows - if you have set the environment variable `GIZMOSQL_TOKEN` to the generated token:\n```python\nimport os\n\nfrom adbc_driver_flightsql import dbapi as gizmosql, DatabaseOptions\n\nwith gizmosql.connect(uri=\"grpc+tls://localhost:31337\",\n                      db_kwargs={\n                          DatabaseOptions.AUTHORIZATION_HEADER.value: f\"Bearer {os.getenv(\"GIZMOSQL_TOKEN\", \"BAD TOKEN!\")}\",\n                          DatabaseOptions.TLS_SKIP_VERIFY.value: \"true\",\n                      },\n                      autocommit=True\n                      ) as conn:\n    with conn.cursor() as cur:\n        print(f\"Catalog: {conn.adbc_current_catalog}\")\n        print(f\"Schema: {conn.adbc_current_db_schema}\")\n\n        cur.execute(\"SELECT * FROM region\")\n        x = cur.fetch_arrow_table()\n        print(x)\n```\n\n### Handy development commands\n#### Generate self-signed certificate and private key for testing purposes\nThere is a handy shell script (if you clone the repo) in [scripts/gen-certs.sh](scripts/gen-certs.sh) that you can use to generate a self-signed certificate and private key for testing purposes.   \n```bash\nscripts/gen-certs.sh\n```\n\n#### Version management\n\n##### Bump the version of the application - (you must have installed from source with the [dev] extras)\n```bash\nbumpver update --patch\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package which generates a GizmoSQL token (JWT) for auth testing",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/gizmodata/generate-gizmosql-token"
    },
    "split_keywords": [
        "gizmosql",
        " auth",
        " token",
        " bearer",
        " jwt"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bea412d8aea1a194b089d2d264a2af0980ef74a91e165d670a9ed8acf4288f82",
                "md5": "f6da958ba487f35729f132b86756a7d7",
                "sha256": "5f2ed6341864aa81a6b3ee64ed838026b42e66c09cf32a3104a6282338aa0a6c"
            },
            "downloads": -1,
            "filename": "generate_gizmosql_token-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f6da958ba487f35729f132b86756a7d7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5056,
            "upload_time": "2025-09-10T19:51:40",
            "upload_time_iso_8601": "2025-09-10T19:51:40.981793Z",
            "url": "https://files.pythonhosted.org/packages/be/a4/12d8aea1a194b089d2d264a2af0980ef74a91e165d670a9ed8acf4288f82/generate_gizmosql_token-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a967520476c1e8cd3203f2212916e910fb54642ded6c70817d1742cfb3630159",
                "md5": "5f1fdda4b6cae96509d23a3dcaaeced2",
                "sha256": "2b7cbee856846012401d56dfd528e29692b349d64f36312f70915beaacda485f"
            },
            "downloads": -1,
            "filename": "generate_gizmosql_token-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "5f1fdda4b6cae96509d23a3dcaaeced2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5094,
            "upload_time": "2025-09-10T19:51:42",
            "upload_time_iso_8601": "2025-09-10T19:51:42.342308Z",
            "url": "https://files.pythonhosted.org/packages/a9/67/520476c1e8cd3203f2212916e910fb54642ded6c70817d1742cfb3630159/generate_gizmosql_token-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-10 19:51:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gizmodata",
    "github_project": "generate-gizmosql-token",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "generate-gizmosql-token"
}
        
Elapsed time: 1.90887s