Skip to content

Commit

Permalink
Update docs and make isort happy
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Jan 4, 2022
1 parent 795a1fe commit d9fe77c
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 56 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

0.2.9 (01/04/2022)
------------------
- Update docs and make isort happy

0.2.8 (01/04/2022)
------------------
- Move `prefix` function to auxiliary.py
Expand Down
66 changes: 52 additions & 14 deletions docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ <h2>Requirements<a class="headerlink" href="#requirements" title="Permalink to t
<h2>Setup<a class="headerlink" href="#setup" title="Permalink to this headline"></a></h2>
<section id="environment-variables">
<h3>Environment Variables:<a class="headerlink" href="#environment-variables" title="Permalink to this headline"></a></h3>
<p>If a <code class="docutils literal notranslate"><span class="pre">.env</span></code> file is present in current working directory, there is no need for env vars.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">AMI_ID</span></code>: ID of any public AMI with an Ubuntu OS.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PORT</span></code>: Port number on which a localhost <code class="docutils literal notranslate"><span class="pre">service/app/api</span></code> is running.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">AMI_ID</span></code>: ID of any public AMI with an Ubuntu OS.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ACCESS_KEY</span></code>: <strong>[Optional]</strong> Access key to access AWS resources. Defaults to <code class="docutils literal notranslate"><span class="pre">~/.aws/credentials</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">SECRET_KEY</span></code>: <strong>[Optional]</strong> Secret key to access AWS resources. Defaults to <code class="docutils literal notranslate"><span class="pre">~/.aws/credentials</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">REGION_NAME</span></code>: <strong>[Optional]</strong> Region name where the instance should live. Defaults to <code class="docutils literal notranslate"><span class="pre">US-WEST-2</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">DOMAIN</span></code>: <strong>[Optional]</strong> Domain name on <code class="docutils literal notranslate"><span class="pre">route53</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">SUBDOMAIN</span></code>: <strong>[Optional]</strong> Sub domain name to be mapped on <code class="docutils literal notranslate"><span class="pre">route53</span></code></p></li>
</ul>
<p>        :bulb:   Can also be passed as an arg. <em>Example: <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">expose.py</span> <span class="pre">start</span> <span class="pre">2021</span></code></em></p>
<details>
<summary><strong>Setup a custom endpoint</strong></summary><p>The public DNS names for EC2 instances are long and messy. To avoid that, an <code class="docutils literal notranslate"><span class="pre">A</span></code> record can be added to the <code class="docutils literal notranslate"><span class="pre">route53</span></code> hosted zone.</p>
<p>:warning:   Requires an active hosted zone on <code class="docutils literal notranslate"><span class="pre">route53</span></code>.</p>
Expand All @@ -73,10 +78,10 @@ <h3>Environment Variables:<a class="headerlink" href="#environment-variables" ti
<section id="certificate">
<h3>Certificate:<a class="headerlink" href="#certificate" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><p><a class="reference external" href="https://github.com/thevickypedia/expose"><code class="docutils literal notranslate"><span class="pre">expose</span></code></a> uses downloaded certs for SSL handshake.</p></li>
<li><p>Securing the tunnel requires the certificate chain and the key file.</p></li>
<li><p>These two files should be saved as <code class="docutils literal notranslate"><span class="pre">cert.pem</span></code> and <code class="docutils literal notranslate"><span class="pre">key.pem</span></code> in either <code class="docutils literal notranslate"><span class="pre">~.ssh/*.pem</span></code> or within <code class="docutils literal notranslate"><span class="pre">expose</span></code> repository.</p></li>
<li><p>No certs? No problem. <a class="reference external" href="https://github.com/thevickypedia/expose"><code class="docutils literal notranslate"><span class="pre">expose</span></code></a> still works without certificates. The <code class="docutils literal notranslate"><span class="pre">nginx</span></code> sever is configured accordingly.</p></li>
<li><p>No certs? No problem. <a class="reference external" href="https://github.com/thevickypedia/expose/blob/main/expose/helpers/cert.py"><code class="docutils literal notranslate"><span class="pre">expose</span></code></a> will
generate a self-signed certificate and a private key automatically.</p></li>
</ul>
<details>
<summary><strong>Generate private SSL certificate</strong></summary><p>Unfortunately not many SSL certificate providers give the liberty to download key files. But <code class="docutils literal notranslate"><span class="pre">expose</span></code>, can use private certificates.</p>
Expand All @@ -86,21 +91,43 @@ <h3>Certificate:<a class="headerlink" href="#certificate" title="Permalink to th
<div><p><code class="docutils literal notranslate"><span class="pre">openssl</span> <span class="pre">req</span> <span class="pre">-newkey</span> <span class="pre">rsa:2048</span> <span class="pre">-new</span> <span class="pre">-nodes</span> <span class="pre">-x509</span> <span class="pre">-days</span> <span class="pre">3650</span> <span class="pre">-keyout</span> <span class="pre">~/.ssh/key.pem</span> <span class="pre">-out</span> <span class="pre">~/.ssh/cert.pem</span></code></p>
</div></blockquote>
</details></section>
<section id="cli-commands">
<h3>CLI commands<a class="headerlink" href="#cli-commands" title="Permalink to this headline"></a></h3>
<p>Startup tunneling:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">expose.py</span> <span class="pre">start</span> <span class="pre">2021</span></code>: Takes the port number as the second arg.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">expose.py</span> <span class="pre">start</span></code>: Port number can also be stored as an env var <code class="docutils literal notranslate"><span class="pre">PORT</span></code>.</p></li>
</ul>
<p>Stop tunneling:
<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">expose.py</span> <span class="pre">stop</span></code></p>
<section id="installation">
<h3>Installation<a class="headerlink" href="#installation" title="Permalink to this headline"></a></h3>
<p><a class="reference external" href="https://pypi.org/project/expose-localhost/"><code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">-m</span> <span class="pre">pip</span> <span class="pre">install</span> <span class="pre">--upgrade</span> <span class="pre">expose-localhost</span></code></a></p>
<section id="start-tunneling">
<h4>Start tunneling:<a class="headerlink" href="#start-tunneling" title="Permalink to this headline"></a></h4>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">expose.tunnel</span> <span class="kn">import</span> <span class="n">Tunnel</span>

<span class="n">Tunnel</span><span class="p">()</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</pre></div>
</div>
</section>
<section id="stop-tunneling">
<h4>Stop tunneling:<a class="headerlink" href="#stop-tunneling" title="Permalink to this headline"></a></h4>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">expose.tunnel</span> <span class="kn">import</span> <span class="n">Tunnel</span>

<span class="n">Tunnel</span><span class="p">()</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
</div>
</section>
<section id="class-instantiation">
<h4>Class Instantiation<a class="headerlink" href="#class-instantiation" title="Permalink to this headline"></a></h4>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">expose.tunnel</span> <span class="kn">import</span> <span class="n">Tunnel</span>

<span class="n">Tunnel</span><span class="p">(</span><span class="n">port</span><span class="o">=</span><span class="mi">2021</span><span class="p">,</span> <span class="n">image_id</span><span class="o">=</span><span class="s1">&#39;ami-04406fdec0f245050&#39;</span><span class="p">,</span>
<span class="n">domain_name</span><span class="o">=</span><span class="s1">&#39;example.com&#39;</span><span class="p">,</span> <span class="n">subdomain</span><span class="o">=</span><span class="s1">&#39;expose&#39;</span><span class="p">,</span>
<span class="n">aws_access_key</span><span class="o">=</span><span class="s1">&#39;A1YSAIEPAJK1830AB1N&#39;</span><span class="p">,</span>
<span class="n">aws_secret_key</span><span class="o">=</span><span class="s1">&#39;e38409/afjeafjllvi19io90eskqn&#39;</span><span class="p">,</span>
<span class="n">aws_region_name</span><span class="o">=</span><span class="s1">&#39;us-east-2&#39;</span><span class="p">)</span>
</pre></div>
</div>
<details>
<summary><strong>Troubleshooting</strong></summary><blockquote>
<div><p>If <code class="docutils literal notranslate"><span class="pre">E:</span> <span class="pre">Could</span> <span class="pre">not</span> <span class="pre">get</span> <span class="pre">lock</span> <span class="pre">/var/lib/dpkg/lock-frontend</span></code> occurs during startup, simply rerun the script with start command.
This occurs when <code class="docutils literal notranslate"><span class="pre">apt</span></code> hasn’t released the resources yet. Re-running the script with the arg <code class="docutils literal notranslate"><span class="pre">start</span></code> will simply re-configure the instance.</p>
</div></blockquote>
</details></section>
</section>
<section id="linting">
<h3>Linting<a class="headerlink" href="#linting" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">PreCommit</span></code> will ensure linting, and the doc creation are run on every commit.</p>
Expand All @@ -114,6 +141,11 @@ <h3>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">
<p><code class="docutils literal notranslate"><span class="pre">pre-commit</span> <span class="pre">run</span> <span class="pre">--all-files</span></code></p>
</section>
</section>
<section id="pypi-package">
<h2>Pypi Package<a class="headerlink" href="#pypi-package" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="https://packaging.python.org/tutorials/packaging-projects/"><img alt="pypi-module" src="https://img.shields.io/badge/Software%20Repository-pypi-1f425f.svg" /></a></p>
<p><a class="reference external" href="https://pypi.org/project/expose-localhost/">https://pypi.org/project/expose-localhost/</a></p>
</section>
<section id="runbook">
<h2>Runbook<a class="headerlink" href="#runbook" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="https://www.sphinx-doc.org/en/master/man/sphinx-autogen.html"><img alt="made-with-sphinx-doc" src="https://img.shields.io/badge/Code%20Docs-Sphinx-1f425f.svg" /></a></p>
Expand All @@ -140,12 +172,18 @@ <h3><a href="index.html">Table of Contents</a></h3>
<li><a class="reference internal" href="#setup">Setup</a><ul>
<li><a class="reference internal" href="#environment-variables">Environment Variables:</a></li>
<li><a class="reference internal" href="#certificate">Certificate:</a></li>
<li><a class="reference internal" href="#cli-commands">CLI commands</a></li>
<li><a class="reference internal" href="#installation">Installation</a><ul>
<li><a class="reference internal" href="#start-tunneling">Start tunneling:</a></li>
<li><a class="reference internal" href="#stop-tunneling">Stop tunneling:</a></li>
<li><a class="reference internal" href="#class-instantiation">Class Instantiation</a></li>
</ul>
</li>
<li><a class="reference internal" href="#linting">Linting</a></li>
<li><a class="reference internal" href="#requirement">Requirement</a></li>
<li><a class="reference internal" href="#usage">Usage</a></li>
</ul>
</li>
<li><a class="reference internal" href="#pypi-package">Pypi Package</a></li>
<li><a class="reference internal" href="#runbook">Runbook</a></li>
<li><a class="reference internal" href="#license-copyright">License &amp; copyright</a></li>
</ul>
Expand Down
51 changes: 40 additions & 11 deletions docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ Expose an app/api running on local host to public internet using AWS EC2

### Setup
#### Environment Variables:
- `AMI_ID`: ID of any public AMI with an Ubuntu OS.
- `PORT`: Port number on which a localhost `service/app/api` is running.
If a `.env` file is present in current working directory, there is no need for env vars.

&nbsp; &nbsp; &nbsp; &nbsp; :bulb: &nbsp; Can also be passed as an arg. *Example: `python expose.py start 2021`*
- `PORT`: Port number on which a localhost `service/app/api` is running.
- `AMI_ID`: ID of any public AMI with an Ubuntu OS.
- `ACCESS_KEY`: **[Optional]** Access key to access AWS resources. Defaults to `~/.aws/credentials`
- `SECRET_KEY`: **[Optional]** Secret key to access AWS resources. Defaults to `~/.aws/credentials`
- `REGION_NAME`: **[Optional]** Region name where the instance should live. Defaults to `US-WEST-2`
- `DOMAIN`: **[Optional]** Domain name on `route53`
- `SUBDOMAIN`: **[Optional]** Sub domain name to be mapped on `route53`

<details>
<summary><strong>Setup a custom endpoint</strong></summary>
Expand All @@ -28,10 +33,10 @@ The public DNS names for EC2 instances are long and messy. To avoid that, an `A`
</details>

#### Certificate:
- [`expose`](https://github.com/thevickypedia/expose) uses downloaded certs for SSL handshake.
- Securing the tunnel requires the certificate chain and the key file.
- These two files should be saved as `cert.pem` and `key.pem` in either `~.ssh/*.pem` or within `expose` repository.
- No certs? No problem. [`expose`](https://github.com/thevickypedia/expose) still works without certificates. The `nginx` sever is configured accordingly.
- No certs? No problem. [`expose`](https://github.com/thevickypedia/expose/blob/main/expose/helpers/cert.py) will
generate a self-signed certificate and a private key automatically.

<details>
<summary><strong>Generate private SSL certificate</strong></summary>
Expand All @@ -46,14 +51,33 @@ To generate a self-signed cert:

</details>

#### CLI commands
#### Installation
[`python3 -m pip install --upgrade expose-localhost`](https://pypi.org/project/expose-localhost/)

###### Start tunneling:
```python
from expose.tunnel import Tunnel

Startup tunneling:
- `python expose.py start 2021`: Takes the port number as the second arg.
- `python expose.py start`: Port number can also be stored as an env var `PORT`.
Tunnel().start()
```

Stop tunneling:
`python expose.py stop`
###### Stop tunneling:
```python
from expose.tunnel import Tunnel

Tunnel().stop()
```

###### Class Instantiation
```python
from expose.tunnel import Tunnel

Tunnel(port=2021, image_id='ami-04406fdec0f245050',
domain_name='example.com', subdomain='expose',
aws_access_key='A1YSAIEPAJK1830AB1N',
aws_secret_key='e38409/afjeafjllvi19io90eskqn',
aws_region_name='us-east-2')
```

<details>
<summary><strong>Troubleshooting</strong></summary>
Expand All @@ -72,6 +96,11 @@ Stop tunneling:
#### Usage
`pre-commit run --all-files`

### Pypi Package
[![pypi-module](https://img.shields.io/badge/Software%20Repository-pypi-1f425f.svg)](https://packaging.python.org/tutorials/packaging-projects/)

[https://pypi.org/project/expose-localhost/](https://pypi.org/project/expose-localhost/)

### Runbook
[![made-with-sphinx-doc](https://img.shields.io/badge/Code%20Docs-Sphinx-1f425f.svg)](https://www.sphinx-doc.org/en/master/man/sphinx-autogen.html)

Expand Down
2 changes: 1 addition & 1 deletion docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ <h2 id="M">M</h2>
<h2 id="P">P</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#helpers.nginx_server.prefix">prefix() (in module helpers.nginx_server)</a>
<li><a href="index.html#helpers.auxiliary.prefix">prefix() (in module helpers.auxiliary)</a>
</li>
</ul></td>
</tr></table>
Expand Down
Loading

0 comments on commit d9fe77c

Please sign in to comment.