Skip to content

Commit 5b77819

Browse files
committed
Documentation updates.
1 parent 620e4bf commit 5b77819

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

docs/index.rst

+32-11
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ and this returned object has a reference to the public URL generated by ``ngrok`
6868
ssh_tunnel = ngrok.connect("22", "tcp")
6969
7070
# Open a named tunnel from the config file
71-
named_tunnel = ngrok.connect(name="my_tunnel_name")
71+
named_tunnel = ngrok.connect(name="my-config-file-tunnel")
7272
7373
The :func:`~pyngrok.ngrok.connect` method takes ``kwargs`` as well, which allows us to pass
74-
additional tunnel configurations that are supported by ngrok,
75-
`as documented here <#tunnel-configurations>`__.
74+
additional tunnel configurations that are supported by ``ngrok`` (or the ``name`` of a tunnel defined in ``ngrok``'s
75+
config file), `as documented here <#tunnel-configurations>`__.
7676

7777
.. note::
7878

@@ -164,7 +164,7 @@ Tunnel Configurations
164164
---------------------
165165

166166
It is possible to configure the tunnel when it is created, for instance adding authentication,
167-
a subdomain, or other additional `tunnel configurations that are supported by ngrok <https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_.
167+
a subdomain, or other additional `tunnel configurations that are supported by ngrok <https://ngrok.com/docs/agent/config/v2/#common-tunnel-configuration-properties>`_.
168168
This is accomplished by passing them as ``kwargs`` to :func:`~pyngrok.ngrok.connect`, then they will be used as
169169
properties for the tunnel when it is created.
170170

@@ -180,6 +180,17 @@ circuit breaker.
180180
auth="username:password",
181181
circuit_breaker=50)
182182
183+
If we have already have a tunnel `defined in ngrok's config file <https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_,
184+
we can start it by its ``name``.
185+
186+
.. code-block:: python
187+
188+
from pyngrok import conf, ngrok
189+
190+
# <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:??">
191+
ngrok_tunnel = ngrok.connect(name="my-config-file-tunnel")
192+
193+
183194
The ``ngrok`` Process
184195
=====================
185196

@@ -308,13 +319,13 @@ set ``ngrok_version`` in :class:`~pyngrok.conf.PyngrokConfig`.
308319
309320
conf.get_default().ngrok_version = "v2"
310321
311-
Setting the ``authtoken``
312-
-------------------------
322+
Setting the ``authtoken`` or ``api_key``
323+
----------------------------------------
313324

314-
Running ``ngrok`` with an auth token enables additional features available on our account (for
315-
instance, the ability to open multiple tunnels concurrently, or use `ngrok's Edges <https://ngrok.com/docs/network-edge/edges/>`_).
316-
We can obtain our auth token from the `ngrok dashboard <https://dashboard.ngrok.com>`_ and install it to ``ngrok``'s
317-
config file.
325+
Running ``ngrok`` with an auth token and/or API key enables additional features available on our account (for
326+
instance, the ability to open multiple tunnels concurrently, custom domains, use of `ngrok's Edges <https://ngrok.com/docs/network-edge/edges/>`_),
327+
etc. We can obtain our auth token from the `ngrok dashboard <https://dashboard.ngrok.com>`_ and install it to
328+
``ngrok``'s config file.
318329

319330
.. code-block:: python
320331
@@ -323,23 +334,33 @@ config file.
323334
# Setting an auth token allows us to open multiple
324335
# tunnels at the same time
325336
ngrok.set_auth_token("<NGROK_AUTHTOKEN>")
337+
# Setting an API key allows us to use labeled tunnels
338+
ngrok.set_api_key("<NGROK_API_KEY>")
326339
327340
# <NgrokTunnel: "https://<public_sub1>.ngrok.io" -> "http://localhost:80">
328341
ngrok_tunnel1 = ngrok.connect()
329342
# <NgrokTunnel: "https://<public_sub2>.ngrok.io" -> "http://localhost:8000">
330343
ngrok_tunnel2 = ngrok.connect("8000")
344+
# <NgrokTunnel: "https://<public_sub3>.ngrok.io" -> "http://localhost:??">
345+
ngrok_tunnel2 = ngrok.connect(name="some-edge-tunnel")
331346
332-
We can also override ``ngrok``'s installed auth token using :class:`~pyngrok.conf.PyngrokConfig`.
347+
For a more complete example of using labeled tunnels with the API key, see `the section on ngrok's Edges <#ngrok-s-edges>`_.
348+
349+
We can also override ``ngrok``'s installed auth token or API key using :class:`~pyngrok.conf.PyngrokConfig`.
333350

334351
.. code-block:: python
335352
336353
from pyngrok import conf, ngrok
337354
338355
conf.get_default().auth_token = "<NGROK_AUTHTOKEN>"
356+
conf.get_default().api_key = "<NGROK_API_KEY>"
339357
340358
# <NgrokTunnel: "https://<public_sub>.ngrok.io" -> "http://localhost:80">
341359
ngrok_tunnel = ngrok.connect()
342360
361+
Lastly, we could instead define ``NGROK_AUTHTOKEN`` or ``NGROK_API_KEY`` as environment variables, if we don't want to
362+
define them in code.
363+
343364
Setting the ``region``
344365
----------------------
345366

pyngrok/ngrok.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def set_auth_token(token: str,
114114
pyngrok_config: Optional[PyngrokConfig] = None) -> None:
115115
"""
116116
Set the ``ngrok`` auth token in the config file, enabling authenticated features (for instance,
117-
more concurrent tunnels, custom subdomains, etc.).
117+
opening multiple tunnels concurrently, custom domains, etc.).
118118
119119
If ``ngrok`` is not installed at :class:`~pyngrok.conf.PyngrokConfig`'s ``ngrok_path``, calling this method
120120
will first download and install ``ngrok``.
@@ -320,7 +320,7 @@ def connect(addr: Optional[str] = None,
320320
:param proto: A valid `tunnel protocol
321321
<https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_, defaults to "http".
322322
:param name: A friendly name for the tunnel, or the name of a `ngrok tunnel definition
323-
<https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_ to be used.
323+
<https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_ defined in ``ngrok``'s config file.
324324
:param pyngrok_config: A ``pyngrok`` configuration to use when interacting with the ``ngrok`` binary,
325325
overriding :func:`~pyngrok.conf.get_default()`.
326326
:param options: Remaining ``kwargs`` are passed as `configuration for the ngrok

0 commit comments

Comments
 (0)