Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions metaflow/_vendor/pyngrok.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Alex Laird

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file.
115 changes: 115 additions & 0 deletions metaflow/_vendor/pyngrok/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os

from .installer import get_ngrok_bin

__author__ = "Alex Laird"
__copyright__ = "Copyright 2021, Alex Laird"
__version__ = "5.1.0"

BIN_DIR = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "bin"))
DEFAULT_NGROK_PATH = os.path.join(BIN_DIR, get_ngrok_bin())
DEFAULT_CONFIG_PATH = None

DEFAULT_NGROK_CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".ngrok2", "ngrok.yml")

_default_pyngrok_config = None


class PyngrokConfig:
"""
An object containing ``pyngrok``'s configuration for interacting with the ``ngrok`` binary. All values are
optional when it is instantiated, and default values will be used for parameters not passed.

Use :func:`~pyngrok.conf.get_default` and :func:`~pyngrok.conf.set_default` to interact with the default
``pyngrok_config``, or pass another instance of this object as the ``pyngrok_config`` keyword arg to most
methods in the :mod:`~pyngrok.ngrok` module to override the default.

.. code-block:: python

from pyngrok import conf, ngrok

# Here we update the entire default config
pyngrok_config = conf.PyngrokConfig(ngrok_path="/usr/local/bin/ngrok")
conf.set_default(pyngrok_config)

# Here we update just one variable in the default config
conf.get_default().ngrok_path = "/usr/local/bin/ngrok"

# Here we leave the default config as-is and pass an override
pyngrok_config = conf.PyngrokConfig(ngrok_path="/usr/local/bin/ngrok")
ngrok.connect(pyngrok_config=pyngrok_config)

:var ngrok_path: The path to the ``ngrok`` binary, defaults to the value in
`conf.DEFAULT_NGROK_PATH <index.html#config-file>`_
:vartype ngrok_path: str
:var config_path: The path to the ``ngrok`` config, defaults to ``None`` and ``ngrok`` manages it.
:vartype config_path: str
:var auth_token: An authtoken to pass to commands (overrides what is in the config).
:vartype auth_token: str
:var region: The region in which ``ngrok`` should start.
:vartype region: str
:var monitor_thread: Whether ``ngrok`` should continue to be monitored (for logs, etc.) after startup
is complete.
:vartype monitor_thread: bool
:var log_event_callback: A callback that will be invoked each time ``ngrok`` emits a log. ``monitor_thread``
must be set to ``True`` or the function will stop being called after ``ngrok`` finishes starting.
:vartype log_event_callback: types.FunctionType
:var startup_timeout: The max number of seconds to wait for ``ngrok`` to start before timing out.
:vartype startup_timeout: int
:var max_logs: The max number of logs to store in :class:`~pyngrok.process.NgrokProcess`'s ``logs`` variable.
:vartype max_logs: int
:var request_timeout: The max timeout when making requests to ``ngrok``'s API.
:vartype request_timeout: float
:var start_new_session: Passed to :py:class:`subprocess.Popen` when launching ``ngrok``. (Python 3 and POSIX only)
:vartype start_new_session: bool
"""

def __init__(self,
ngrok_path=None,
config_path=None,
auth_token=None,
region=None,
monitor_thread=True,
log_event_callback=None,
startup_timeout=15,
max_logs=100,
request_timeout=4,
start_new_session=False):
self.ngrok_path = DEFAULT_NGROK_PATH if ngrok_path is None else ngrok_path
self.config_path = DEFAULT_CONFIG_PATH if config_path is None else config_path
self.auth_token = auth_token
self.region = region
self.monitor_thread = monitor_thread
self.log_event_callback = log_event_callback
self.startup_timeout = startup_timeout
self.max_logs = max_logs
self.request_timeout = request_timeout
self.start_new_session = start_new_session


def get_default():
"""
Get the default config to be used with methods in the :mod:`~pyngrok.ngrok` module. To override the
default individually, the ``pyngrok_config`` keyword arg can also be passed to most of these methods,
or set a new default config with :func:`~pyngrok.conf.set_default`.

:return: The default ``pyngrok_config``.
:rtype: PyngrokConfig
"""
if _default_pyngrok_config is None:
set_default(PyngrokConfig())

return _default_pyngrok_config


def set_default(pyngrok_config):
"""
Set a new default config to be used with methods in the :mod:`~pyngrok.ngrok` module. To override the
default individually, the ``pyngrok_config`` keyword arg can also be passed to most of these methods.

:param pyngrok_config: The new ``pyngrok_config`` to be used by default.
:type pyngrok_config: PyngrokConfig
"""
global _default_pyngrok_config

_default_pyngrok_config = pyngrok_config
91 changes: 91 additions & 0 deletions metaflow/_vendor/pyngrok/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
__author__ = "Alex Laird"
__copyright__ = "Copyright 2020, Alex Laird"
__version__ = "4.1.0"


class PyngrokError(Exception):
"""
Raised when a general ``pyngrok`` error has occurred.
"""
pass


class PyngrokSecurityError(PyngrokError):
"""
Raised when a ``pyngrok`` security error has occurred.
"""
pass


class PyngrokNgrokInstallError(PyngrokError):
"""
Raised when an error has occurred while downloading and installing the ``ngrok`` binary.
"""
pass


class PyngrokNgrokError(PyngrokError):
"""
Raised when an error occurs interacting directly with the ``ngrok`` binary.

:var error: A description of the error being thrown.
:vartype error: str
:var ngrok_logs: The ``ngrok`` logs, which may be useful for debugging the error.
:vartype ngrok_logs: list[NgrokLog]
:var ngrok_error: The error that caused the ``ngrok`` process to fail.
:vartype ngrok_error: str
"""

def __init__(self, error, ngrok_logs=None, ngrok_error=None):
super(PyngrokNgrokError, self).__init__(error)

if ngrok_logs is None:
ngrok_logs = []

self.ngrok_logs = ngrok_logs
self.ngrok_error = ngrok_error


class PyngrokNgrokHTTPError(PyngrokNgrokError):
"""
Raised when an error occurs making a request to the ``ngrok`` web interface. The ``body``
contains the error response received from ``ngrok``.

:var error: A description of the error being thrown.
:vartype error: str
:var url: The request URL that failed.
:vartype url: str
:var status_code: The response status code from ``ngrok``.
:vartype status_code: int
:var message: The response message from ``ngrok``.
:vartype message: str
:var headers: The request headers sent to ``ngrok``.
:vartype headers: dict[str, str]
:var body: The response body from ``ngrok``.
:vartype body: str
"""

def __init__(self, error, url, status_code, message, headers, body):
super(PyngrokNgrokHTTPError, self).__init__(error)

self.url = url
self.status_code = status_code
self.message = message
self.headers = headers
self.body = body


class PyngrokNgrokURLError(PyngrokNgrokError):
"""
Raised when an error occurs when trying to initiate an API request.

:var error: A description of the error being thrown.
:vartype error: str
:var reason: The reason for the URL error.
:vartype reason: str
"""

def __init__(self, error, reason):
super(PyngrokNgrokURLError, self).__init__(error)

self.reason = reason
Loading