<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mário Victor Ribeiro Silva on Medium]]></title>
        <description><![CDATA[Stories by Mário Victor Ribeiro Silva on Medium]]></description>
        <link>https://medium.com/@mariovictorrs?source=rss-d165cb608be1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ivjvXThrye9jQ6eZnft36A.jpeg</url>
            <title>Stories by Mário Victor Ribeiro Silva on Medium</title>
            <link>https://medium.com/@mariovictorrs?source=rss-d165cb608be1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 07:59:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mariovictorrs/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Pull private docker images from Docker Hub to EC2 instances]]></title>
            <link>https://mariovictorrs.medium.com/pull-private-docker-images-from-docker-hub-to-ec2-instances-e8a1be2c0baf?source=rss-d165cb608be1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8a1be2c0baf</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[ec2]]></category>
            <dc:creator><![CDATA[Mário Victor Ribeiro Silva]]></dc:creator>
            <pubDate>Wed, 08 Dec 2021 14:53:18 GMT</pubDate>
            <atom:updated>2026-08-16T15:31:29.573Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create everything with one command.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mmvsWVQ-yX4VCWQi" /><figcaption>Photo by <a href="https://unsplash.com/@gezerbatu?utm_source=medium&amp;utm_medium=referral">Batu Gezer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you’re running Docker containers, probably you want to run this container in the cloud, but sometimes you need to deploy a image from a private repository on Docker Hub in many EC2 machines so, typing docker login in all is not exactly a good solution. You could use Ansible for something like that, but it involves private keys, access to all machines through ssh, and it might be not possible depending on your company or application.</p><h4>Authentication File</h4><p>First, you need to login to Docker Hub using docker login, this will create a file in the docker folder ~/.docker/config.json with the auth hashed and your email.</p><blockquote>Note: Be careful when copying and manipulating this file, since anyone with access to this file could access your container registry!</blockquote><p>Upload this file to a private S3 bucket on AWS (your bucket must be in the same region of your EC2 machines).</p><h4>Resource Creation</h4><p>I will create an example using Terraform, this way we can automate creation and configuration of the instances. For your machine get access to your bucket, you must allow your instances to access the bucket you created and copy the docker configuration file. In order to do this, we need to attach an <strong>IAM Profile</strong> to the instance.</p><p>To copy files from S3 to EC2, we will use the user_data to input a script that run on startup of the instances. For the example file, I will use <a href="https://sammeechward.com/s3-and-iam-with-terraform/">this</a> tutorial from Sam with little changes for our use case. Here’s the example code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48b236b4a5662ab0ad7c23a7efb42081/href">https://medium.com/media/48b236b4a5662ab0ad7c23a7efb42081/href</a></iframe><p>This way, the instance have access to the S3 bucket that you’ve created, and will execute your script on instance startup. The last part is to create the script to install the packages and copy the file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f3d6aeda6d3cddf7cd3445f7fb25311/href">https://medium.com/media/6f3d6aeda6d3cddf7cd3445f7fb25311/href</a></iframe><p>And that’s it. If you’ve used the examples, is just run terraform apply and everything should run perfectly, and you will be able to use your docker private images on your EC2 instances.</p><p>Thank you for reading. And thanks to <a href="https://medium.com/u/b4c09758a45">Mylena Rossato</a> for the English review!</p><h4>References</h4><ul><li><a href="https://www.youtube.com/watch?v=pLw6MLqwmew">https://www.youtube.com/watch?v=pLw6MLqwmew</a></li><li><a href="https://stackoverflow.com/questions/34013068/where-are-the-docker-registry-login-files">https://stackoverflow.com/questions/34013068/where-are-the-docker-registry-login-files</a></li><li><a href="https://stackoverflow.com/questions/65256613/terraform-how-to-copy-files-from-s3-to-ec2">https://stackoverflow.com/questions/65256613/terraform-how-to-copy-files-from-s3-to-ec2</a></li><li><a href="https://sammeechward.com/s3-and-iam-with-terraform/">https://sammeechward.com/s3-and-iam-with-terraform/</a></li><li><a href="https://github.com/UmInventorQualquer/curso-aws-pratico-producao/blob/main/docker/production-init.sh">https://github.com/UmInventorQualquer/curso-aws-pratico-producao/blob/main/docker/production-init.sh</a></li></ul><p>You can follow me on GitHub:</p><p><a href="https://github.com/mariovictorrs">mariovictorrs - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8a1be2c0baf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to cache API keys in Python]]></title>
            <link>https://mariovictorrs.medium.com/how-to-cache-api-keys-in-python-4d1fa96f0e95?source=rss-d165cb608be1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d1fa96f0e95</guid>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[api-key]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Mário Victor Ribeiro Silva]]></dc:creator>
            <pubDate>Mon, 06 Sep 2021 11:54:46 GMT</pubDate>
            <atom:updated>2026-08-16T15:32:00.232Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cache API keys in Python</h3><h4>Let’s cache them all!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bNCXvy5RGyk7bwFd" /><figcaption>Photo by <a href="https://unsplash.com/@flyd2069?utm_source=medium&amp;utm_medium=referral">FLY:D</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction</h4><p>There are many ways to cache functions and variables in Python. Usually, you want to cache CPU and IO bound functions depending on your needs, but in this tutorial we want to fetch an API key from an external service, like Auth0 or GitHub, and store this to use in the entire lifespan of the token.</p><p>There are, mainly, 3 ways we can achieve this:</p><ul><li>Cache the entire function that get the API key (using lru_cache decorator);</li><li>Cache the variable that store the key (using config.py for example);</li><li>Use a library to cache the variable or function (It depends on the library);</li></ul><p>The approach we are taking is cache the entire function that request the API key.</p><blockquote>If you didn’t have the API Key, request in a different function. You really should do this!</blockquote><h4>Making a timed LRU cache</h4><p>We’re not going deep in lru_cache in this article. If you want to know more about how the things work under the hood, I suggest two links: <a href="https://docs.python.org/3/library/functools.html#functools.lru_cache">this</a> link to the official docs, and <a href="https://realpython.com/lru-cache-python/">this</a> link for a nice tutorial from Real Python.</p><p>To use lru_cache, you can simply add the decorator in the function, but the cache will never expire, and it is bad for our problem because API keys do expire, they have a lifespan. We need to expire this cache in a certain time. So, we’ll have to override the decorator with our decorator.</p><p>Here is a full code example implementing and showing the decorator in action:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14b68bbf273bbd922052041d2b277770/href">https://medium.com/media/14b68bbf273bbd922052041d2b277770/href</a></iframe><p>And that’s it! It is really simple to implement and reuse.</p><h4>Important observation</h4><p>This method only work for functions outside classes, but there is a way to make it work(like <a href="https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-class-methods-release-object">this</a> link in Stack Overflow shows). It adds a lot of overhead, so I prefer to just separate the function from the class.</p><p>Thank you for reading. I hope this tutorial was useful to you!.</p><p>(And thanks to <a href="https://medium.com/u/b4c09758a45">Mylena Rossato</a> for the English review!)</p><h4>References</h4><ul><li><a href="https://realpython.com/caching-external-api-requests/">https://realpython.com/caching-external-api-requests/</a></li><li><a href="https://medium.com/fintechexplained/advanced-python-how-to-implement-caching-in-python-application-9d0a4136b845">https://medium.com/fintechexplained/advanced-python-how-to-implement-caching-in-python-application-9d0a4136b845</a></li><li><a href="https://realpython.com/lru-cache-python/">https://realpython.com/lru-cache-python/</a></li><li><a href="https://towardsdatascience.com/why-you-should-wrap-decorators-in-python-5ac3676835f9">https://towardsdatascience.com/why-you-should-wrap-decorators-in-python-5ac3676835f9</a></li><li><a href="https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-class-methods-release-object">https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-class-methods-release-object</a></li><li><a href="https://realpython.com/lru-cache-python/#evicting-cache-entries-based-on-both-time-and-space">https://realpython.com/lru-cache-python/#evicting-cache-entries-based-on-both-time-and-space</a></li><li><a href="https://docs.python.org/3/library/functools.html#functools.lru_cache">https://docs.python.org/3/library/functools.html#functools.lru_cache</a></li><li><a href="https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-class-methods-release-object">https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-class-methods-release-object</a></li></ul><p>You can follow me on GitHub:</p><p><a href="https://github.com/mariovictorrs">mariovictorrs - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d1fa96f0e95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple guide of Iptables]]></title>
            <link>https://mariovictorrs.medium.com/simple-guide-of-iptables-ae10387ec075?source=rss-d165cb608be1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae10387ec075</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[iptables]]></category>
            <dc:creator><![CDATA[Mário Victor Ribeiro Silva]]></dc:creator>
            <pubDate>Wed, 19 May 2021 12:49:27 GMT</pubDate>
            <atom:updated>2021-05-19T13:16:50.809Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hH_zVMjKuRb9Sj_3P2Hoow.jpeg" /></figure><h4>How to add and delete rules to your Firewall using Iptables directly</h4><h4>Attention:</h4><blockquote>All the operations will be accomplished considering that you’re logged as “root”, or that you’re running the commands with sudo, therefore, be careful</blockquote><h3>Show the Rules:</h3><p>First, you’ll need to verify all the rules that you already have. To list all the rules,use the following command:</p><pre>iptables -L</pre><p>If you want to see the lines of the rules (this will be important later), you can simply type the following command:</p><pre>iptables -L --line-numbers</pre><p>You can see that the output will show all the rules, of all the chains, but,in this tutorial, I will use only the input chain, never the less the commands should work in all the other chains.</p><p>The chains are a list of rules processed in order. That’s why it is so important to verify all the other rules in the chain, to see where you’ll have to put new rules that you’re creating, or which one to delete.</p><h3>Persist the changes (And backup,of course)</h3><p>Install the package iptables-persistent, so you can save the alterations</p><pre>apt install iptables-persistent</pre><p>After the installation, the configuration will be saved in two places: one for the IPV4 rules, and the other one to IPV6 rules.</p><pre>/etc/iptables/rules.v4<br>/etc/iptables/rules.v6</pre><p>Now you can change whatever you desire on Iptables. Here,we’ll open a port as an example.</p><h3>Adding a Rule</h3><p>To open a port, execute the following command, where your_port is the port that you want:</p><pre>iptables -m comment --comment &quot;New Port&quot; -A INPUT -p tcp --dport your_port -j ACCEPT</pre><p>This will append the rule in the end of the chain (in this case, INPUT chain)</p><h3>Important !</h3><p>The rules inserted on Iptables are verified one by one on a sequence, therefore, if needed, use the following command to insert a new rule before any other rule that you want to add:</p><pre>iptables -m comment --comment &quot;New Port&quot; -I INPUT line_number -p tcp --dport your_port -j ACCEPT</pre><h3>Delete</h3><p>The simplest way to delete one rule is by the line number. You can simply specify which line of the chain to delete:</p><pre>iptables -D INPUT number_of_the_line</pre><p>After that, you’ll execute the following commands to save the configuration that you’ve done.</p><p>To save the IPV4 rules:</p><pre>iptables-save &gt; /etc/iptables/rules.v4</pre><p>And to save the IPV6 rules:</p><pre>iptables-save&gt; /etc/iptables/rules.v6</pre><p>Now, all your configurations will remain after the reboot. And that’s it !!!</p><p>A huge thanks to <a href="https://medium.com/u/b4c09758a45">Mylena Rossato</a> for helping me translate this guide !!!.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae10387ec075" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>