Skip to content

Commit

Permalink
Allow server to run on HTTPS with SSL certificates
Browse files Browse the repository at this point in the history
Set a background process to redirect HTTP to HTTPS
Gracefully shutdown server on SSL errors
  • Loading branch information
dormant-user committed Feb 16, 2024
1 parent a13ed70 commit 19d89fd
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 22 deletions.
17 changes: 14 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
__pycache__/

# Jetbrains
.idea

# Python venv
venv

# Default env file
.env
temp.py
test.py

# Sphinx docs
source
doc_gen/_build
doc_gen/_static
__pycache__/

# Temporary scratch pads
temp*.py
test.py
*.json
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Python module to, stream videos via authenticated sessions using FastAPI

## Install
```shell
python -m pip install stream-localhost
pip install stream-localhost
```

## Sample Usage
Expand Down Expand Up @@ -48,6 +48,9 @@ if __name__ == '__main__':
- **WORKERS**: Number of workers to spin up the `uvicorn` server. Defaults to `1`
- **WEBSITE**: List of websites (_supports regex_) to add to CORS configuration. _Required only if tunneled via CDN_
- **AUTO_THUMBNAIL**: Boolean flag to auto generate thumbnail images for preview. Defaults to `True`
- **KEY_FILE**: Path to the private key file for SSL certificate. Defaults to `None`
- **CERT_FILE**: Path to the full chain file for SSL certificate. Defaults to `None`
> :bulb:   `KEY_FILE` and `CERT_FILE` becomes mandatory when `VIDEO_PORT` is set to `443`
## Coding Standards
Docstring format: [`Google`][google-docs] <br>
Expand All @@ -56,7 +59,7 @@ Styling conventions: [`PEP 8`][pep8] and [`isort`][isort]
## [Release Notes][release-notes]
**Requirement**
```shell
python -m pip install gitverse
pip install gitverse
```

**Usage**
Expand Down
7 changes: 7 additions & 0 deletions doc_gen/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ Basics
:members:
:undoc-members:

Secure
======

.. automodule:: pystream.routers.secure
:members:
:undoc-members:

Video
=====

Expand Down
9 changes: 7 additions & 2 deletions docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h1>PyStream<a class="headerlink" href="#pystream" title="Permalink to this head
<p>Python module to, stream videos via authenticated sessions using FastAPI</p>
<section id="install">
<h2>Install<a class="headerlink" href="#install" title="Permalink to this heading"></a></h2>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>stream-localhost
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>pip<span class="w"> </span>install<span class="w"> </span>stream-localhost
</pre></div>
</div>
</section>
Expand Down Expand Up @@ -96,7 +96,12 @@ <h3>Env Variables<a class="headerlink" href="#env-variables" title="Permalink to
<li><p><strong>WORKERS</strong>: Number of workers to spin up the <code class="docutils literal notranslate"><span class="pre">uvicorn</span></code> server. Defaults to <code class="docutils literal notranslate"><span class="pre">1</span></code></p></li>
<li><p><strong>WEBSITE</strong>: List of websites (<em>supports regex</em>) to add to CORS configuration. <em>Required only if tunneled via CDN</em></p></li>
<li><p><strong>AUTO_THUMBNAIL</strong>: Boolean flag to auto generate thumbnail images for preview. Defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code></p></li>
<li><p><strong>KEY_FILE</strong>: Path to the private key file for SSL certificate. Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
<li><p><strong>CERT_FILE</strong>: Path to the full chain file for SSL certificate. Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
</ul>
<blockquote>
<div><p>:bulb:   <code class="docutils literal notranslate"><span class="pre">KEY_FILE</span></code> and <code class="docutils literal notranslate"><span class="pre">CERT_FILE</span></code> becomes mandatory when <code class="docutils literal notranslate"><span class="pre">VIDEO_PORT</span></code> is set to <code class="docutils literal notranslate"><span class="pre">443</span></code></p>
</div></blockquote>
</section>
</section>
<section id="coding-standards">
Expand All @@ -107,7 +112,7 @@ <h2>Coding Standards<a class="headerlink" href="#coding-standards" title="Permal
<section id="release-notes">
<h2><a class="reference external" href="https://github.com/thevickypedia/pystream/blob/master/release_notes.rst">Release Notes</a><a class="headerlink" href="#release-notes" title="Permalink to this heading"></a></h2>
<p><strong>Requirement</strong></p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>gitverse
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>pip<span class="w"> </span>install<span class="w"> </span>gitverse
</pre></div>
</div>
<p><strong>Usage</strong></p>
Expand Down
7 changes: 5 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Python module to, stream videos via authenticated sessions using FastAPI

## Install
```shell
python -m pip install stream-localhost
pip install stream-localhost
```

## Sample Usage
Expand Down Expand Up @@ -48,6 +48,9 @@ if __name__ == '__main__':
- **WORKERS**: Number of workers to spin up the `uvicorn` server. Defaults to `1`
- **WEBSITE**: List of websites (_supports regex_) to add to CORS configuration. _Required only if tunneled via CDN_
- **AUTO_THUMBNAIL**: Boolean flag to auto generate thumbnail images for preview. Defaults to `True`
- **KEY_FILE**: Path to the private key file for SSL certificate. Defaults to `None`
- **CERT_FILE**: Path to the full chain file for SSL certificate. Defaults to `None`
> :bulb: &nbsp; `KEY_FILE` and `CERT_FILE` becomes mandatory when `VIDEO_PORT` is set to `443`
## Coding Standards
Docstring format: [`Google`][google-docs] <br>
Expand All @@ -56,7 +59,7 @@ Styling conventions: [`PEP 8`][pep8] and [`isort`][isort]
## [Release Notes][release-notes]
**Requirement**
```shell
python -m pip install gitverse
pip install gitverse
```

**Usage**
Expand Down
7 changes: 5 additions & 2 deletions docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Python module to, stream videos via authenticated sessions using FastAPI

## Install
```shell
python -m pip install stream-localhost
pip install stream-localhost
```

## Sample Usage
Expand Down Expand Up @@ -48,6 +48,9 @@ if __name__ == '__main__':
- **WORKERS**: Number of workers to spin up the `uvicorn` server. Defaults to `1`
- **WEBSITE**: List of websites (_supports regex_) to add to CORS configuration. _Required only if tunneled via CDN_
- **AUTO_THUMBNAIL**: Boolean flag to auto generate thumbnail images for preview. Defaults to `True`
- **KEY_FILE**: Path to the private key file for SSL certificate. Defaults to `None`
- **CERT_FILE**: Path to the full chain file for SSL certificate. Defaults to `None`
> :bulb: &nbsp; `KEY_FILE` and `CERT_FILE` becomes mandatory when `VIDEO_PORT` is set to `443`

## Coding Standards
Docstring format: [`Google`][google-docs] <br>
Expand All @@ -56,7 +59,7 @@ Styling conventions: [`PEP 8`][pep8] and [`isort`][isort]
## [Release Notes][release-notes]
**Requirement**
```shell
python -m pip install gitverse
pip install gitverse
```

**Usage**
Expand Down
7 changes: 7 additions & 0 deletions docs/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ Basics
:members:
:undoc-members:

Secure
======

.. automodule:: pystream.routers.secure
:members:
:undoc-members:

Video
=====

Expand Down
25 changes: 21 additions & 4 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ <h2 id="C">C</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pystream.models.secure.calculate_hash">calculate_hash() (in module pystream.models.secure)</a>
</li>
<li><a href="index.html#pystream.models.config.EnvConfig.cert_file">cert_file (pystream.models.config.EnvConfig attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
Expand Down Expand Up @@ -191,13 +193,15 @@ <h2 id="H">H</h2>
</li>
<li><a href="index.html#pystream.models.secure.hex_encode">hex_encode() (in module pystream.models.secure)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pystream.models.config.EnvConfig.Config.hide_input_in_errors">hide_input_in_errors (pystream.models.config.EnvConfig.Config attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pystream.models.config.Static.home_endpoint">home_endpoint (pystream.models.config.Static attribute)</a>
</li>
<li><a href="index.html#pystream.routers.auth.home_page">home_page() (in module pystream.routers.auth)</a>
</li>
<li><a href="index.html#pystream.routers.secure.https_redirect">https_redirect() (in module pystream.routers.secure)</a>
</li>
</ul></td>
</tr></table>
Expand All @@ -220,6 +224,10 @@ <h2 id="I">I</h2>

<h2 id="K">K</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pystream.models.config.EnvConfig.key_file">key_file (pystream.models.config.EnvConfig attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#pystream.models.squire.keygen">keygen() (in module pystream.models.squire)</a>
</li>
Expand Down Expand Up @@ -278,6 +286,8 @@ <h2 id="M">M</h2>
<li><a href="index.html#module-pystream.routers.auth">pystream.routers.auth</a>
</li>
<li><a href="index.html#module-pystream.routers.basics">pystream.routers.basics</a>
</li>
<li><a href="index.html#module-pystream.routers.secure">pystream.routers.secure</a>
</li>
<li><a href="index.html#module-pystream.routers.video">pystream.routers.video</a>
</li>
Expand Down Expand Up @@ -343,15 +353,15 @@ <h2 id="P">P</h2>
<li><a href="index.html#module-pystream.models.images">module</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li>
pystream.models.secure

<ul>
<li><a href="index.html#module-pystream.models.secure">module</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li>
pystream.models.squire

Expand Down Expand Up @@ -385,6 +395,13 @@ <h2 id="P">P</h2>

<ul>
<li><a href="index.html#module-pystream.routers.basics">module</a>
</li>
</ul></li>
<li>
pystream.routers.secure

<ul>
<li><a href="index.html#module-pystream.routers.secure">module</a>
</li>
</ul></li>
<li>
Expand Down
Loading

0 comments on commit 19d89fd

Please sign in to comment.