Skip to content

Commit

Permalink
Display a warning page for unsupported browsers
Browse files Browse the repository at this point in the history
Add .env files support for GitHub env vars
Replace env_prefix with AliasChoices
Add CLI compatibility
  • Loading branch information
vsivanandharao committed Jun 13, 2024
1 parent 12f60d9 commit 09c3ad8
Show file tree
Hide file tree
Showing 20 changed files with 420 additions and 306 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ way of handling the configuration and initialization.
<summary><strong>Download custom-built executables</strong></summary>
<br>

Additionally, custom source _(to download binaries)_ can be configured by specifying the environment variables,
`GIT_OWNER` and `GIT_REPO`<br>
Additionally, custom source _(to download binaries)_ can be configured by specifying the following environment variables

- **OWNER** - Owner of the GitHub repo.
- **REPO** - Repository name.
- **TOKEN** - GitHub repository token.
- **VERSION** - Version of the release.

> _also supports the dotenv file `.github.env`, and prefixes like `github`, `git` and `filebrowser`_
For this custom source feature to work, the executable should be uploaded to releases as assets,
and follow the naming convention below.

Expand All @@ -43,7 +50,7 @@ and follow the naming convention below.
python -m pip install pyfilebrowser
```

**Initiate**
**Initiate [programmatically]**
```python
import pyfilebrowser

Expand All @@ -53,6 +60,11 @@ if __name__ == '__main__':
browser.start()
```

**Initiate [CLI]**
```shell
pyfilebrowser
```

## Environment Variables
Env vars can either be loaded from `.env` files or directly passed during object init.

Expand All @@ -68,10 +80,11 @@ Env vars can either be loaded from `.env` files or directly passed during object
- **workers** `int` - Number of workers used to run the proxy server. _Defaults to `1`_
- **debug** `bool` - Boolean flag to enable debug level logging. _Defaults to `False`_
- **origins** `List[str]` - Origins to allow connections through proxy server. _Defaults to `host`_
- **public_ip** `bool` - Boolean flag to allow public IP address of the host. _Defaults to `False`_
- **private_ip** `bool` - Boolean flag to allow private IP address of the host. _Defaults to `False`_
- **allow_public_ip** `bool` - Boolean flag to allow public IP address of the host. _Defaults to `False`_
- **allow_private_ip** `bool` - Boolean flag to allow private IP address of the host. _Defaults to `False`_
- **origin_refresh** `int` - Interval in seconds to refresh all the allowed origins. _Defaults to `None`_
- **error_page** `FilePath` - Error page to serve when filebrowser API is down. _Defaults to_ [error.html]
- **warn_page** `FilePath` - Warning page to serve when accessed from Unsupported browsers. _Defaults to_ [warn.html]
- **rate_limit** - `Dict/List[Dict]` with the rate limit for the proxy server. _Defaults to `None`_

> `origin_refresh` allows users to set a custom interval to update the public and private IP address of the host,
Expand Down Expand Up @@ -216,6 +229,7 @@ Licensed under the [MIT License][license]
[pep8]: https://www.python.org/dev/peps/pep-0008/
[isort]: https://pycqa.github.io/isort/
[error.html]: https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/error.html
[warn.html]: https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/warn.html
[Rate limiting]: https://www.cloudflare.com/learning/bots/what-is-rate-limiting/
[DDoS]: https://www.cloudflare.com/learning/ddos/glossary/denial-of-service/
[Rate Limiter]: https://builtin.com/software-engineering-perspectives/rate-limiter
Expand Down
20 changes: 2 additions & 18 deletions doc_gen/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,29 +174,13 @@ Download

====

.. autoclass:: pyfilebrowser.squire.download.ExtendedEnvSettingsSource(pydantic_settings.EnvSettingsSource)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. autoclass:: pyfilebrowser.squire.download.ExtendedSettingsConfigDict(pydantic_settings.SettingsConfigDict)
:exclude-members: _abc_impl, model_computed_fields, model_config, model_fields, env_prefixes, title, str_to_lower, str_to_upper, str_strip_whitespace, str_min_length, str_max_length, extra, frozen, populate_by_name, use_enum_values, validate_assignment, arbitrary_types_allowed, from_attributes, loc_by_alias, alias_generator, ignored_types, allow_inf_nan, json_schema_extra, json_encoders, strict, revalidate_instances, ser_json_timedelta, ser_json_bytes, ser_json_inf_nan, validate_default, validate_return, protected_namespaces, hide_input_in_errors, defer_build, plugin_settings, schema_generator, json_schema_serialization_defaults_required, json_schema_mode_override, coerce_numbers_to_str, regex_engine, validation_error_cause, case_sensitive, env_prefix, env_file, env_file_encoding, env_ignore_empty, env_nested_delimiter, env_parse_none_str, secrets_dir, json_file, json_file_encoding, yaml_file, yaml_file_encoding, toml_file

====

.. autoclass:: pyfilebrowser.squire.download.ExtendedBaseSettings(pydantic_settings.BaseSettings)
:exclude-members: _abc_impl, model_computed_fields, model_config, model_fields, env_prefixes, title, str_to_lower, str_to_upper, str_strip_whitespace, str_min_length, str_max_length, extra, frozen, populate_by_name, use_enum_values, validate_assignment, arbitrary_types_allowed, from_attributes, loc_by_alias, alias_generator, ignored_types, allow_inf_nan, json_schema_extra, json_encoders, strict, revalidate_instances, ser_json_timedelta, ser_json_bytes, ser_json_inf_nan, validate_default, validate_return, protected_namespaces, hide_input_in_errors, defer_build, plugin_settings, schema_generator, json_schema_serialization_defaults_required, json_schema_mode_override, coerce_numbers_to_str, regex_engine, validation_error_cause, case_sensitive, env_prefix, env_file, env_file_encoding, env_ignore_empty, env_nested_delimiter, env_parse_none_str, secrets_dir, json_file, json_file_encoding, yaml_file, yaml_file_encoding, toml_file
:noindex:

====

.. autoclass:: pyfilebrowser.squire.download.GitHub(ExtendedBaseSettings)
.. autoclass:: pyfilebrowser.squire.download.GitHub(pydantic.BaseSettings)
:exclude-members: _abc_impl, model_config, model_fields, model_computed_fields

====

.. automodule:: pyfilebrowser.squire.download
:exclude-members: ExtendedEnvSettingsSource, ExtendedSettingsConfigDict, ExtendedBaseSettings, GitHub, Executable
:exclude-members: GitHub, Executable

Steward
=======
Expand Down
25 changes: 19 additions & 6 deletions docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ <h1>PyFileBrowser<a class="headerlink" href="#pyfilebrowser" title="Permalink to
<p><a class="reference external" href="https://github.com/thevickypedia/pyfilebrowser"><code class="docutils literal notranslate"><span class="pre">pyfilebrowser</span></code></a> automatically downloads the system specific executable during startup.</p>
<details>
<summary><strong>Download custom-built executables</strong></summary>
<br><p>Additionally, custom source <em>(to download binaries)</em> can be configured by specifying the environment variables,
<code class="docutils literal notranslate"><span class="pre">GIT_OWNER</span></code> and <code class="docutils literal notranslate"><span class="pre">GIT_REPO</span></code><br>
For this custom source feature to work, the executable should be uploaded to releases as assets,
<br><p>Additionally, custom source <em>(to download binaries)</em> can be configured by specifying the following environment variables</p>
<ul class="simple">
<li><p><strong>OWNER</strong> - Owner of the GitHub repo.</p></li>
<li><p><strong>REPO</strong> - Repository name.</p></li>
<li><p><strong>TOKEN</strong> - GitHub repository token.</p></li>
<li><p><strong>VERSION</strong> - Version of the release.</p></li>
</ul>
<blockquote>
<div><p><em>also supports the dotenv file <code class="docutils literal notranslate"><span class="pre">.github.env</span></code>, and prefixes like <code class="docutils literal notranslate"><span class="pre">github</span></code>, <code class="docutils literal notranslate"><span class="pre">git</span></code> and <code class="docutils literal notranslate"><span class="pre">filebrowser</span></code></em></p>
</div></blockquote>
<p>For this custom source feature to work, the executable should be uploaded to releases as assets,
and follow the naming convention below.</p>
<blockquote>
<div><p><strong>asset naming convention:</strong> <code class="docutils literal notranslate"><span class="pre">${operating</span> <span class="pre">system}-{architecture}-filebrowser-{extension}</span></code><br>
Expand All @@ -76,7 +84,7 @@ <h2>Kick Off<a class="headerlink" href="#kick-off" title="Permalink to this head
<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>pyfilebrowser
</pre></div>
</div>
<p><strong>Initiate</strong></p>
<p><strong>Initiate [programmatically]</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pyfilebrowser</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
Expand All @@ -85,6 +93,10 @@ <h2>Kick Off<a class="headerlink" href="#kick-off" title="Permalink to this head
<span class="n">browser</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Initiate [CLI]</strong></p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>pyfilebrowser
</pre></div>
</div>
</section>
<section id="environment-variables">
<h2>Environment Variables<a class="headerlink" href="#environment-variables" title="Permalink to this heading"></a></h2>
Expand All @@ -101,10 +113,11 @@ <h3><code class="docutils literal notranslate"><span class="pre">.env</span></co
<li><p><strong>workers</strong> <code class="docutils literal notranslate"><span class="pre">int</span></code> - Number of workers used to run the proxy server. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">1</span></code></em></p></li>
<li><p><strong>debug</strong> <code class="docutils literal notranslate"><span class="pre">bool</span></code> - Boolean flag to enable debug level logging. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code></em></p></li>
<li><p><strong>origins</strong> <code class="docutils literal notranslate"><span class="pre">List[str]</span></code> - Origins to allow connections through proxy server. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">host</span></code></em></p></li>
<li><p><strong>public_ip</strong> <code class="docutils literal notranslate"><span class="pre">bool</span></code> - Boolean flag to allow public IP address of the host. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code></em></p></li>
<li><p><strong>private_ip</strong> <code class="docutils literal notranslate"><span class="pre">bool</span></code> - Boolean flag to allow private IP address of the host. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code></em></p></li>
<li><p><strong>allow_public_ip</strong> <code class="docutils literal notranslate"><span class="pre">bool</span></code> - Boolean flag to allow public IP address of the host. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code></em></p></li>
<li><p><strong>allow_private_ip</strong> <code class="docutils literal notranslate"><span class="pre">bool</span></code> - Boolean flag to allow private IP address of the host. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code></em></p></li>
<li><p><strong>origin_refresh</strong> <code class="docutils literal notranslate"><span class="pre">int</span></code> - Interval in seconds to refresh all the allowed origins. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code></em></p></li>
<li><p><strong>error_page</strong> <code class="docutils literal notranslate"><span class="pre">FilePath</span></code> - Error page to serve when filebrowser API is down. <em>Defaults to</em> <a class="reference external" href="https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/error.html">error.html</a></p></li>
<li><p><strong>warn_page</strong> <code class="docutils literal notranslate"><span class="pre">FilePath</span></code> - Warning page to serve when accessed from Unsupported browsers. <em>Defaults to</em> <a class="reference external" href="https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/warn.html">warn.html</a></p></li>
<li><p><strong>rate_limit</strong> - <code class="docutils literal notranslate"><span class="pre">Dict/List[Dict]</span></code> with the rate limit for the proxy server. <em>Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code></em></p></li>
</ul>
<blockquote>
Expand Down
24 changes: 19 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ way of handling the configuration and initialization.
<summary><strong>Download custom-built executables</strong></summary>
<br>

Additionally, custom source _(to download binaries)_ can be configured by specifying the environment variables,
`GIT_OWNER` and `GIT_REPO`<br>
Additionally, custom source _(to download binaries)_ can be configured by specifying the following environment variables

- **OWNER** - Owner of the GitHub repo.
- **REPO** - Repository name.
- **TOKEN** - GitHub repository token.
- **VERSION** - Version of the release.

> _also supports the dotenv file `.github.env`, and prefixes like `github`, `git` and `filebrowser`_
For this custom source feature to work, the executable should be uploaded to releases as assets,
and follow the naming convention below.

Expand All @@ -43,7 +50,7 @@ and follow the naming convention below.
python -m pip install pyfilebrowser
```

**Initiate**
**Initiate [programmatically]**
```python
import pyfilebrowser

Expand All @@ -53,6 +60,11 @@ if __name__ == '__main__':
browser.start()
```

**Initiate [CLI]**
```shell
pyfilebrowser
```

## Environment Variables
Env vars can either be loaded from `.env` files or directly passed during object init.

Expand All @@ -68,10 +80,11 @@ Env vars can either be loaded from `.env` files or directly passed during object
- **workers** `int` - Number of workers used to run the proxy server. _Defaults to `1`_
- **debug** `bool` - Boolean flag to enable debug level logging. _Defaults to `False`_
- **origins** `List[str]` - Origins to allow connections through proxy server. _Defaults to `host`_
- **public_ip** `bool` - Boolean flag to allow public IP address of the host. _Defaults to `False`_
- **private_ip** `bool` - Boolean flag to allow private IP address of the host. _Defaults to `False`_
- **allow_public_ip** `bool` - Boolean flag to allow public IP address of the host. _Defaults to `False`_
- **allow_private_ip** `bool` - Boolean flag to allow private IP address of the host. _Defaults to `False`_
- **origin_refresh** `int` - Interval in seconds to refresh all the allowed origins. _Defaults to `None`_
- **error_page** `FilePath` - Error page to serve when filebrowser API is down. _Defaults to_ [error.html]
- **warn_page** `FilePath` - Warning page to serve when accessed from Unsupported browsers. _Defaults to_ [warn.html]
- **rate_limit** - `Dict/List[Dict]` with the rate limit for the proxy server. _Defaults to `None`_

> `origin_refresh` allows users to set a custom interval to update the public and private IP address of the host,
Expand Down Expand Up @@ -216,6 +229,7 @@ Licensed under the [MIT License][license]
[pep8]: https://www.python.org/dev/peps/pep-0008/
[isort]: https://pycqa.github.io/isort/
[error.html]: https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/error.html
[warn.html]: https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/warn.html
[Rate limiting]: https://www.cloudflare.com/learning/bots/what-is-rate-limiting/
[DDoS]: https://www.cloudflare.com/learning/ddos/glossary/denial-of-service/
[Rate Limiter]: https://builtin.com/software-engineering-perspectives/rate-limiter
Expand Down
24 changes: 19 additions & 5 deletions docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ way of handling the configuration and initialization.
<summary><strong>Download custom-built executables</strong></summary>
<br>

Additionally, custom source _(to download binaries)_ can be configured by specifying the environment variables,
`GIT_OWNER` and `GIT_REPO`<br>
Additionally, custom source _(to download binaries)_ can be configured by specifying the following environment variables

- **OWNER** - Owner of the GitHub repo.
- **REPO** - Repository name.
- **TOKEN** - GitHub repository token.
- **VERSION** - Version of the release.

> _also supports the dotenv file `.github.env`, and prefixes like `github`, `git` and `filebrowser`_

For this custom source feature to work, the executable should be uploaded to releases as assets,
and follow the naming convention below.

Expand All @@ -43,7 +50,7 @@ and follow the naming convention below.
python -m pip install pyfilebrowser
```

**Initiate**
**Initiate [programmatically]**
```python
import pyfilebrowser

Expand All @@ -53,6 +60,11 @@ if __name__ == '__main__':
browser.start()
```

**Initiate [CLI]**
```shell
pyfilebrowser
```

## Environment Variables
Env vars can either be loaded from `.env` files or directly passed during object init.

Expand All @@ -68,10 +80,11 @@ Env vars can either be loaded from `.env` files or directly passed during object
- **workers** `int` - Number of workers used to run the proxy server. _Defaults to `1`_
- **debug** `bool` - Boolean flag to enable debug level logging. _Defaults to `False`_
- **origins** `List[str]` - Origins to allow connections through proxy server. _Defaults to `host`_
- **public_ip** `bool` - Boolean flag to allow public IP address of the host. _Defaults to `False`_
- **private_ip** `bool` - Boolean flag to allow private IP address of the host. _Defaults to `False`_
- **allow_public_ip** `bool` - Boolean flag to allow public IP address of the host. _Defaults to `False`_
- **allow_private_ip** `bool` - Boolean flag to allow private IP address of the host. _Defaults to `False`_
- **origin_refresh** `int` - Interval in seconds to refresh all the allowed origins. _Defaults to `None`_
- **error_page** `FilePath` - Error page to serve when filebrowser API is down. _Defaults to_ [error.html]
- **warn_page** `FilePath` - Warning page to serve when accessed from Unsupported browsers. _Defaults to_ [warn.html]
- **rate_limit** - `Dict/List[Dict]` with the rate limit for the proxy server. _Defaults to `None`_

> `origin_refresh` allows users to set a custom interval to update the public and private IP address of the host,
Expand Down Expand Up @@ -216,6 +229,7 @@ Licensed under the [MIT License][license]
[pep8]: https://www.python.org/dev/peps/pep-0008/
[isort]: https://pycqa.github.io/isort/
[error.html]: https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/error.html
[warn.html]: https://github.com/thevickypedia/pyfilebrowser/blob/main/pyfilebrowser/proxy/warn.html
[Rate limiting]: https://www.cloudflare.com/learning/bots/what-is-rate-limiting/
[DDoS]: https://www.cloudflare.com/learning/ddos/glossary/denial-of-service/
[Rate Limiter]: https://builtin.com/software-engineering-perspectives/rate-limiter
Expand Down
Loading

0 comments on commit 09c3ad8

Please sign in to comment.