Skip to content

Commit

Permalink
Added support for ngrok v3 "domain" and "basic_auth" params.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlaird committed Apr 9, 2024
1 parent d8eca9f commit 592a516
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ 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.4...HEAD)
## [Unreleased](https://github.com/alexdlaird/hookee/compare/2.3.5...HEAD)

## [2.3.5](https://github.com/alexdlaird/hookee/compare/2.3.3...2.3.4) - 2024-04-09
### Added
- Added support for `ngrok` v3 parameters `domain` and `basic_auth`. Backwards compatible with legacy parameters `hostname` and `auth`.
- Build improvements.

## [2.3.4](https://github.com/alexdlaird/hookee/compare/2.3.3...2.3.4) - 2024-03-24
### Added
Expand Down
2 changes: 1 addition & 1 deletion hookee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__copyright__ = "Copyright (c) 2020-2024 Alex Laird"
__license__ = "MIT"
__version__ = "2.3.4"
__version__ = "2.3.5"

from hookee.hookeemanager import HookeeManager # noqa: F401
12 changes: 9 additions & 3 deletions hookee/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
template = {
"port": int,
"subdomain": confuse.String(default=None),
"region": confuse.Choice(["us", "eu", "ap", "au", "sa", "jp", "in"], default=None),
"region": confuse.Choice(["us", "eu", "ap", "au", "sa", "jp", "in", "us-cal-1"], default=None),
"domain": confuse.String(default=None),
# Deprecated, use "domain" instead
"hostname": confuse.String(default=None),
"basic_auth": confuse.String(default=None),
# Deprecated, use "basic_auth" instead
"auth": confuse.String(default=None),
"host_header": confuse.String(default=None),
"response": confuse.String(default=None),
Expand Down Expand Up @@ -109,16 +113,18 @@ def __init__(self, click_logging=None, **kwargs):
except (confuse.ConfigReadError, ValueError):
raise HookeeConfigError("The config file is not valid YAML.")

def get(self, key):
def get(self, key, default=None):
"""
Get the config value for the given key of persisted data.
:param key: The key.
:type key: str
:param default: The default, if config not set.
:type key: str
:return: The config value.
:rtype: object
"""
return self.config_data[key]
return self.config_data.get(key, default)

def set(self, key, value):
"""
Expand Down
3 changes: 2 additions & 1 deletion hookee/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def start(self):

def stop(self):
"""
If running, kill the server and cleanup its thread.
This method is only useful when the Flask version has been overriden to use asn older version (<2). With recent
versions of Flask, the underlying server daemon will terminate when ``hookee` terminates.
"""
if self._thread:
req = Request(f"http://127.0.0.1:{self.port}/shutdown", method="POST")
Expand Down
17 changes: 10 additions & 7 deletions hookee/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ def start(self):
self.print_close_header()

def _start_tunnel(self):
options = {"bind_tls": True}
options = {"schemes": ["https"]}
subdomain = self.config.get("subdomain")
hostname = self.config.get("hostname")
domain = self.config.get("domain", self.config.get("hostname"))
host_header = self.config.get("host_header")
auth = self.config.get("auth")
basic_auth = self.config.get("basic_auth", self.config.get("auth"))
if subdomain:
options["subdomain"] = subdomain
if hostname:
options["hostname"] = hostname
if domain:
options["domain"] = domain
if host_header:
options["host_header"] = host_header
if auth:
options["auth"] = auth
if basic_auth:
if isinstance(basic_auth, list):
options["basic_auth"] = basic_auth
else:
options["basic_auth"] = [basic_auth]

self.public_url = ngrok.connect(self.port,
**options).public_url
Expand Down

0 comments on commit 592a516

Please sign in to comment.