Skip to content

Commit

Permalink
Added tunnel_name and api_key to Config.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlaird committed Jan 11, 2025
1 parent 1a94b1f commit 0b63239
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/alexdlaird/hookee/compare/2.3.7...HEAD)
## [Unreleased](https://github.com/alexdlaird/hookee/compare/2.3.8...HEAD)

## [2.3.8](https://github.com/alexdlaird/hookee/compare/2.3.7...2.3.8) - 2025-01-11

### Added

- Added `tunnel_name` parameter to the `Config`, which can be used to tell `ngrok` to use a definition from its config file when starting a tunnel.
- Added `ngrok`'s `api_key` to the `Config`. If not set in `Config`, it will attempt to use the environment variable `NGROK_API_KEY` if it is set.
- Documentation improvements.

## [2.3.7](https://github.com/alexdlaird/hookee/compare/2.3.6...2.3.7) - 2024-11-21
Expand Down
4 changes: 2 additions & 2 deletions hookee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__copyright__ = "Copyright (c) 2020-2024 Alex Laird"
__copyright__ = "Copyright (c) 2020-2025 Alex Laird"
__license__ = "MIT"
__version__ = "2.3.7"
__version__ = "2.3.8"

from hookee.hookeemanager import HookeeManager # noqa: F401
20 changes: 18 additions & 2 deletions hookee/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

__copyright__ = "Copyright (c) 2020-2024 Alex Laird"
__copyright__ = "Copyright (c) 2020-2025 Alex Laird"
__license__ = "MIT"

import click
Expand All @@ -25,13 +25,15 @@
@click.option("--response-script", type=click.Path(exists=True),
help="[server] A Python script whose `run(request, response)` method will be called by the default "
"`/webhook` after all response plugins have run.")
@click.option("--tunnel-name", help="[tunnel] The name to use for the ngrok tunnel.")
@click.option("--subdomain", help="[tunnel] The subdomain to use for ngrok endpoints.")
@click.option("--region", type=click.Choice(["us", "eu", "ap", "au", "sa", "jp", "in"]),
help="The region to use for ngrok endpoints.")
@click.option("--hostname", help="[tunnel] The hostname to use for ngrok endpoints.")
@click.option("--hostname", help="[tunnel] The domain to use for ngrok endpoints.")
@click.option("--auth", help="[tunnel] The basic auth to use for ngrok endpoints.")
@click.option("--host-header", help="[tunnel] The \"Host\" header value to use for ngrok endpoints.")
@click.option("--auth-token", help="[tunnel] A valid ngrok auth token.")
@click.option("--api-key", help="[tunnel] A valid ngrok API key.")
@click.option("--plugins-dir", type=click.Path(exists=True), help="The directory to scan for custom hookee plugins.")
@click.option("--plugins", multiple=True, help="A list of hookee plugins to use.")
@click.option('--version', is_flag=True, default=False, help="Display version information.")
Expand Down Expand Up @@ -210,5 +212,19 @@ def authtoken(ctx, token):
hookee_manager.print_util.print_config_update("The auth token has been set in the config.")


@hookee.command()
@click.pass_context
@click.argument("key")
def apikey(ctx, key):
"""
Save the API key to the config.
"""
hookee_manager = ctx.obj["hookee_manager"]

hookee_manager.config.set("api_key", key)

hookee_manager.print_util.print_config_update("The API key has been set in the config.")


if __name__ == "__main__":
hookee(obj={})
4 changes: 3 additions & 1 deletion hookee/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__copyright__ = "Copyright (c) 2020-2024 Alex Laird"
__copyright__ = "Copyright (c) 2020-2025 Alex Laird"
__license__ = "MIT"

import os
Expand All @@ -13,6 +13,7 @@
"default_route_methods": confuse.String(default="^(GET|HEAD|POST|PUT|DELETE|PATCH|OPTIONS|TRACE|CONNECT)$"),
"port": int,
"no_tunnel": confuse.OneOf([True, False], default=False),
"tunnel_name": confuse.String(default=None),
"subdomain": confuse.String(default=None),
"region": confuse.Choice(["us", "eu", "ap", "au", "sa", "jp", "in", "us-cal-1"], default=None),
"domain": confuse.String(default=None),
Expand All @@ -27,6 +28,7 @@
"request_script": confuse.Filename(default=None),
"response_script": confuse.Filename(default=None),
"auth_token": confuse.String(default=os.environ.get("NGROK_AUTHTOKEN")),
"api_key": confuse.String(default=os.environ.get("NGROK_API_KEY")),
"plugins_dir": confuse.Filename(),
"plugins": list,
"console_width": confuse.Integer(default=80),
Expand Down
6 changes: 5 additions & 1 deletion hookee/tunnel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__copyright__ = "Copyright (c) 2020-2024 Alex Laird"
__copyright__ = "Copyright (c) 2020-2025 Alex Laird"
__license__ = "MIT"

import threading
Expand Down Expand Up @@ -37,6 +37,7 @@ def __init__(self, hookee_manager):
self.port = self.config.get("port")

self.pyngrok_config = PyngrokConfig(auth_token=self.config.get("auth_token"),
api_key=self.config.get("api_key"),
region=self.config.get("region"))
conf.set_default(self.pyngrok_config)

Expand Down Expand Up @@ -80,10 +81,13 @@ def start(self):

def _start_tunnel(self):
options = {"schemes": ["https"]}
name = self.config.get("tunnel_name")
subdomain = self.config.get("subdomain")
domain = self.config.get("domain", self.config.get("hostname"))
host_header = self.config.get("host_header")
basic_auth = self.config.get("basic_auth", self.config.get("auth"))
if name:
options["name"] = name
if subdomain:
options["subdomain"] = subdomain
if domain:
Expand Down

0 comments on commit 0b63239

Please sign in to comment.