Skip to content

Commit

Permalink
deploy: e5d195f
Browse files Browse the repository at this point in the history
  • Loading branch information
MountainGod2 committed Dec 19, 2024
1 parent fea4f6c commit ed1f0b3
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 20 deletions.
40 changes: 35 additions & 5 deletions _modules/chaturbate_poller/logging_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h1>Source code for chaturbate_poller.logging_config</h1><div class="highlight">
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">logging.config</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span>

<span class="kn">from</span> <span class="nn">dateutil</span> <span class="kn">import</span> <span class="n">tz</span>
Expand All @@ -96,7 +97,14 @@ <h1>Source code for chaturbate_poller.logging_config</h1><div class="highlight">
<div class="viewcode-block" id="sanitize_sensitive_data">
<a class="viewcode-back" href="../../autoapi/chaturbate_poller/logging_config/index.html#chaturbate_poller.logging_config.sanitize_sensitive_data">[docs]</a>
<span class="k">def</span> <span class="nf">sanitize_sensitive_data</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">float</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Sanitize sensitive data like URLs and tokens.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Sanitize sensitive data like URLs and tokens.</span>

<span class="sd"> Args:</span>
<span class="sd"> arg (str | float): The argument to sanitize.</span>

<span class="sd"> Returns:</span>
<span class="sd"> str | int | float: Sanitized data.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">arg</span> <span class="o">=</span> <span class="n">URL_REGEX</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;events/USERNAME/TOKEN&quot;</span><span class="p">,</span> <span class="n">arg</span><span class="p">)</span>
<span class="n">arg</span> <span class="o">=</span> <span class="n">TOKEN_REGEX</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">&quot;token=REDACTED&quot;</span><span class="p">,</span> <span class="n">arg</span><span class="p">)</span>
Expand All @@ -112,7 +120,14 @@ <h1>Source code for chaturbate_poller.logging_config</h1><div class="highlight">
<div class="viewcode-block" id="SanitizeSensitiveDataFilter.filter">
<a class="viewcode-back" href="../../autoapi/chaturbate_poller/logging_config/index.html#chaturbate_poller.logging_config.SanitizeSensitiveDataFilter.filter">[docs]</a>
<span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">:</span> <span class="n">logging</span><span class="o">.</span><span class="n">LogRecord</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Sanitize sensitive data in log messages and arguments.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Sanitize sensitive data in log messages and arguments.</span>

<span class="sd"> Args:</span>
<span class="sd"> record (logging.LogRecord): The log record.</span>

<span class="sd"> Returns:</span>
<span class="sd"> bool: Whether to process the log.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">msg</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">record</span><span class="o">.</span><span class="n">msg</span> <span class="o">=</span> <span class="n">sanitize_sensitive_data</span><span class="p">(</span><span class="n">record</span><span class="o">.</span><span class="n">msg</span><span class="p">)</span>
<span class="k">if</span> <span class="n">record</span><span class="o">.</span><span class="n">args</span><span class="p">:</span>
Expand All @@ -132,7 +147,16 @@ <h1>Source code for chaturbate_poller.logging_config</h1><div class="highlight">
<span class="k">def</span> <span class="nf">json_record</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">extra</span><span class="p">:</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">],</span> <span class="n">record</span><span class="p">:</span> <span class="n">logging</span><span class="o">.</span><span class="n">LogRecord</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add extra fields to the JSON log record.&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Add extra fields to the JSON log record.</span>

<span class="sd"> Args:</span>
<span class="sd"> message (str): The log message.</span>
<span class="sd"> extra (dict[str, Any]): Additional log data.</span>
<span class="sd"> record (logging.LogRecord): The log record.</span>

<span class="sd"> Returns:</span>
<span class="sd"> dict[str, Any]: Enhanced log record.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">extra</span><span class="p">[</span><span class="s2">&quot;message&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">message</span>
<span class="n">extra</span><span class="p">[</span><span class="s2">&quot;level&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">levelname</span>
<span class="n">extra</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">record</span><span class="o">.</span><span class="n">name</span>
Expand All @@ -149,15 +173,21 @@ <h1>Source code for chaturbate_poller.logging_config</h1><div class="highlight">

<span class="sd"> Args:</span>
<span class="sd"> verbose (bool): Enable verbose logging (DEBUG level).</span>
<span class="sd"> json_output (bool): Force JSON output, overrides Docker detection.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">json_logging</span> <span class="o">=</span> <span class="ow">not</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">isatty</span><span class="p">()</span> <span class="c1"># JSON logging for non-TTY output</span>
<span class="n">log_format</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;version&quot;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s2">&quot;disable_existing_loggers&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
<span class="s2">&quot;filters&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">&quot;sanitize&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">&quot;()&quot;</span><span class="p">:</span> <span class="n">SanitizeSensitiveDataFilter</span><span class="p">,</span>
<span class="p">},</span>
<span class="p">},</span>
<span class="s2">&quot;handlers&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">&quot;console&quot;</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">&quot;class&quot;</span><span class="p">:</span> <span class="s2">&quot;logging.StreamHandler&quot;</span><span class="p">,</span>
<span class="s2">&quot;formatter&quot;</span><span class="p">:</span> <span class="s2">&quot;json&quot;</span><span class="p">,</span>
<span class="s2">&quot;formatter&quot;</span><span class="p">:</span> <span class="s2">&quot;json&quot;</span> <span class="k">if</span> <span class="n">json_logging</span> <span class="k">else</span> <span class="s2">&quot;simple&quot;</span><span class="p">,</span>
<span class="s2">&quot;filters&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;sanitize&quot;</span><span class="p">],</span>
<span class="s2">&quot;level&quot;</span><span class="p">:</span> <span class="s2">&quot;DEBUG&quot;</span> <span class="k">if</span> <span class="n">verbose</span> <span class="k">else</span> <span class="s2">&quot;INFO&quot;</span><span class="p">,</span>
<span class="p">},</span>
<span class="p">},</span>
Expand Down
18 changes: 10 additions & 8 deletions _modules/chaturbate_poller/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>
<span class="kn">import</span> <span class="nn">textwrap</span>

<span class="kn">import</span> <span class="nn">rich_click</span> <span class="k">as</span> <span class="nn">click</span>
<span class="kn">from</span> <span class="nn">rich.console</span> <span class="kn">import</span> <span class="n">Console</span>
<span class="kn">from</span> <span class="nn">rich.traceback</span> <span class="kn">import</span> <span class="n">install</span>

<span class="kn">from</span> <span class="nn">chaturbate_poller</span> <span class="kn">import</span> <span class="n">__version__</span>
Expand All @@ -92,8 +93,9 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">chaturbate_poller.logging_config</span> <span class="kn">import</span> <span class="n">setup_logging</span>
<span class="kn">from</span> <span class="nn">chaturbate_poller.signal_handler</span> <span class="kn">import</span> <span class="n">SignalHandler</span>

<span class="c1"># Enable detailed and formatted error handling with Rich</span>
<span class="n">install</span><span class="p">(</span><span class="n">show_locals</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
<span class="n">console</span> <span class="o">=</span> <span class="n">Console</span><span class="p">()</span>
<span class="sd">&quot;&quot;&quot;Console: Rich console for printing messages.&quot;&quot;&quot;</span>


<span class="nd">@click</span><span class="o">.</span><span class="n">group</span><span class="p">()</span>
Expand Down Expand Up @@ -141,7 +143,7 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>
<span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--testbed&quot;</span><span class="p">,</span> <span class="n">is_flag</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Enable testbed mode.&quot;</span><span class="p">)</span>
<span class="nd">@click</span><span class="o">.</span><span class="n">option</span><span class="p">(</span><span class="s2">&quot;--verbose&quot;</span><span class="p">,</span> <span class="n">is_flag</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Enable verbose logging.&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">start</span><span class="p">(</span> <span class="c1"># noqa: PLR0913 # pragma: no cover</span>
<span class="k">def</span> <span class="nf">start</span><span class="p">(</span> <span class="c1"># noqa: PLR0913</span>
<span class="n">username</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">token</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">timeout</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
Expand All @@ -152,7 +154,6 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Start the Chaturbate Poller.&quot;&quot;&quot;</span>
<span class="n">setup_logging</span><span class="p">(</span><span class="n">verbose</span><span class="o">=</span><span class="n">verbose</span><span class="p">)</span>

<span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span>
<span class="n">main</span><span class="p">(</span>
<span class="n">username</span><span class="o">=</span><span class="n">username</span><span class="p">,</span>
Expand All @@ -167,7 +168,7 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>

<div class="viewcode-block" id="main">
<a class="viewcode-back" href="../../autoapi/chaturbate_poller/main/index.html#chaturbate_poller.main.main">[docs]</a>
<span class="k">async</span> <span class="k">def</span> <span class="nf">main</span><span class="p">(</span> <span class="c1"># noqa: PLR0913 # pragma: no cover</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">main</span><span class="p">(</span> <span class="c1"># noqa: PLR0913</span>
<span class="n">username</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">token</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">api_timeout</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
Expand All @@ -192,10 +193,10 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>
<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="n">username</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;A username is required.&quot;</span><span class="p">)</span>
<span class="n">console</span><span class="o">.</span><span class="n">print</span><span class="p">(</span><span class="s2">&quot;[bold red]Error:[/bold red] A username is required.&quot;</span><span class="p">)</span>
<span class="k">return</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">token</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;An API token is required.&quot;</span><span class="p">)</span>
<span class="n">console</span><span class="o">.</span><span class="n">print</span><span class="p">(</span><span class="s2">&quot;[bold red]Error:[/bold red] An API token is required.&quot;</span><span class="p">)</span>
<span class="k">return</span>

<span class="k">if</span> <span class="n">use_database</span><span class="p">:</span>
Expand All @@ -221,14 +222,15 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>
<span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="n">AuthenticationError</span><span class="p">,</span> <span class="n">NotFoundError</span><span class="p">,</span> <span class="n">PollingError</span><span class="p">)</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">exc</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">exc</span><span class="p">)</span> <span class="c1"># noqa: TRY400</span>
<span class="n">console</span><span class="o">.</span><span class="n">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;[bold red]Error:[/bold red] </span><span class="si">{</span><span class="n">exc</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">CancelledError</span><span class="p">,</span> <span class="ne">KeyboardInterrupt</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Polling stopped by user.&quot;</span><span class="p">)</span></div>



<div class="viewcode-block" id="start_polling">
<a class="viewcode-back" href="../../autoapi/chaturbate_poller/main/index.html#chaturbate_poller.main.start_polling">[docs]</a>
<span class="k">async</span> <span class="k">def</span> <span class="nf">start_polling</span><span class="p">(</span> <span class="c1"># noqa: PLR0913 # pragma: no cover</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">start_polling</span><span class="p">(</span> <span class="c1"># noqa: PLR0913</span>
<span class="n">username</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">token</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">api_timeout</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
Expand Down Expand Up @@ -265,7 +267,7 @@ <h1>Source code for chaturbate_poller.main</h1><div class="highlight"><pre>



<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span> <span class="c1"># pragma: no cover</span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="n">cli</span><span class="p">()</span>
</pre></div>

Expand Down
Loading

0 comments on commit ed1f0b3

Please sign in to comment.