<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Payam Mousavi</title>
    <description>The latest articles on Forem by Payam Mousavi (@pamit).</description>
    <link>https://forem.com/pamit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F362171%2F04985593-a87b-4a2e-bdcf-a9d28c97ebe5.png</url>
      <title>Forem: Payam Mousavi</title>
      <link>https://forem.com/pamit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pamit"/>
    <language>en</language>
    <item>
      <title>Building a RESTful API Backend with Authentication using Elixir Phoenix</title>
      <dc:creator>Payam Mousavi</dc:creator>
      <pubDate>Thu, 13 Aug 2020 03:32:55 +0000</pubDate>
      <link>https://forem.com/pamit/building-a-restful-api-backend-with-authentication-using-elixir-phoenix-3l8k</link>
      <guid>https://forem.com/pamit/building-a-restful-api-backend-with-authentication-using-elixir-phoenix-3l8k</guid>
      <description>&lt;p&gt;Two years ago, I wrote an article on how to build a RESTful backend using &lt;code&gt;Elixir&lt;/code&gt; and the &lt;code&gt;Phoenix&lt;/code&gt; framework. I really enjoyed that project, specially after working with &lt;code&gt;Ruby&lt;/code&gt; and &lt;code&gt;Ruby on Rails&lt;/code&gt; for a couple of years. &lt;/p&gt;

&lt;p&gt;I intent to upgrade that project and explain possible challenges during the upgrade, and also want to add more features to explore recent amazing features of Phoenix such as &lt;code&gt;LiveView&lt;/code&gt;! Of course, some spec tests would be appreciated!&lt;/p&gt;

&lt;p&gt;This is the link to that article: &lt;a href="https://medium.com/@pamit/building-a-restful-backend-with-elixir-phoenix-84fe390975c"&gt;Building a RESTful API Backend with Authentication using Elixir Phoenix&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is the Github repo of the project: &lt;a href="https://github.com/pamit/elixir-phoenix-json-api"&gt;Phoenix REST backend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
      <category>restful</category>
      <category>authentication</category>
    </item>
    <item>
      <title>Resolve NPM security vulnerabilities</title>
      <dc:creator>Payam Mousavi</dc:creator>
      <pubDate>Thu, 13 Aug 2020 03:22:50 +0000</pubDate>
      <link>https://forem.com/pamit/resolve-npm-security-vulnerabilities-dnn</link>
      <guid>https://forem.com/pamit/resolve-npm-security-vulnerabilities-dnn</guid>
      <description>&lt;p&gt;If you have seen your CI pipeline builds failed due to security vulnerabilities in some NPM packages, you have probably tried &lt;code&gt;npm audit fix&lt;/code&gt; and boom! No sign of those &lt;code&gt;found N high severity vulnerabilities in scanned packages&lt;/code&gt; messages!&lt;/p&gt;

&lt;p&gt;In some cases, that command won’t solve your issue; sometimes the issue is caused by a transitive dependency (sub-dependency) and you can’t or don’t want to wait for a version patch for the package.&lt;/p&gt;

&lt;p&gt;For instance, consider the following security vulnerability (&lt;a href="https://www.npmjs.com/advisories/1213"&gt;https://www.npmjs.com/advisories/1213&lt;/a&gt;):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WnxtXZIz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AqE60s1JqtKaA4GBZL5jWwQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WnxtXZIz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AqE60s1JqtKaA4GBZL5jWwQ.png" alt="NPM Audit issue"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It says, the &lt;code&gt;dot-prop&lt;/code&gt; package has a security issue which needs to get fixed, and &lt;code&gt;serverless-apigateway-service-proxy&lt;/code&gt; and &lt;code&gt;serverless&lt;/code&gt; depend on it. But if you run &lt;code&gt;npm audit fix&lt;/code&gt; you’ll probably see a similar message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fixed 0 of N vulnerabilities in X scanned packages
  N vulnerabilities required manual review and could not be updated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have some options here! One option is to ignore that specific vulnerability in your CI pipeline using another NPM package like &lt;a href="https://github.com/IBM/audit-ci"&gt;audit-ci&lt;/a&gt; which is basically something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx audit-ci --allowlist 1213
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a good way of skip security issues temporarily, however, &lt;strong&gt;this approach is not always recommended&lt;/strong&gt; as your project may still be vulnerable even if it is a &lt;code&gt;dev&lt;/code&gt; package.&lt;/p&gt;

&lt;p&gt;The second option is to &lt;a href="https://github.com/rogeriochaves/npm-force-resolutions#readme"&gt;force a specific unaffected version&lt;/a&gt; of that package. This means we need to change our &lt;code&gt;packahe.json&lt;/code&gt; and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "project-x",
  ...  "scripts": {
    "preinstall": "npx npm-force-resolutions"
  },
  ...   "resolutions": {
    "dot-prop": "5.1.1"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will override the affected versions with the specified version. Again, &lt;strong&gt;this is not always recommended&lt;/strong&gt; and should be used carefully and only if you have no other option! Normally, we need to wait for a version patch from the package maintainers to fix a vulnerability.&lt;/p&gt;

&lt;p&gt;That’s it! Happy coding!&lt;/p&gt;

</description>
      <category>npm</category>
      <category>security</category>
      <category>audit</category>
    </item>
    <item>
      <title>Git: Rewriting history</title>
      <dc:creator>Payam Mousavi</dc:creator>
      <pubDate>Sun, 19 Jul 2020 05:30:41 +0000</pubDate>
      <link>https://forem.com/pamit/git-rewriting-history-1jak</link>
      <guid>https://forem.com/pamit/git-rewriting-history-1jak</guid>
      <description>&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;As software engineers, we have always been looking for better ways to manage our codebases. We have used different source control systems like &lt;strong&gt;Git&lt;/strong&gt;, and we may need advanced techniques from time to time to resolve some new issues we face, specially when working on bigger software solutions with huge codebases. &lt;/p&gt;

&lt;p&gt;One such situation is when we need to re-write Git history of a repository for any reason including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;update (&lt;strong&gt;amend&lt;/strong&gt;) a commit message &lt;/li&gt;
&lt;li&gt;remove (&lt;strong&gt;drop&lt;/strong&gt;) a specific commit&lt;/li&gt;
&lt;li&gt;combine (&lt;strong&gt;squash&lt;/strong&gt;) some commits with a specific commit&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;re-order&lt;/strong&gt; commits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's do it!&lt;/p&gt;

&lt;h1&gt;
  
  
  Hands on terminal
&lt;/h1&gt;

&lt;p&gt;We can create a new Git repository and add some files and make some changes in those files and then make some commits. Suppose we need to update the last 7 commits (crazy I know!). Let's run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open an interactive window where we can choose the proper action to apply to the repository history. Note that Git adds the commit messages in reverse order, so commit &lt;code&gt;11454df test something!&lt;/code&gt; is actually our last commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pick 58bc9d0 file.txt created
pick 121c507 file2.txt created
pick 64a2c99 file2.txt updated
pick 2ef342a file2.txt updated step 1!
pick e84f687 file2.txt updated step 2!
pick 16c8448 file2.txt updated step 3!
pick 11454df &lt;span class="nb"&gt;test &lt;/span&gt;something!

&lt;span class="c"&gt;# Rebase e84f687..11454df onto e84f687 (7 commands)&lt;/span&gt;
&lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="c"&gt;# Commands:&lt;/span&gt;
&lt;span class="c"&gt;# p, pick &amp;lt;commit&amp;gt; = use commit&lt;/span&gt;
&lt;span class="c"&gt;# r, reword &amp;lt;commit&amp;gt; = use commit, but edit the commit message&lt;/span&gt;
&lt;span class="c"&gt;# e, edit &amp;lt;commit&amp;gt; = use commit, but stop for amending&lt;/span&gt;
&lt;span class="c"&gt;# s, squash &amp;lt;commit&amp;gt; = use commit, but meld into previous commit&lt;/span&gt;
&lt;span class="c"&gt;# d, drop &amp;lt;commit&amp;gt; = remove commit&lt;/span&gt;
&lt;span class="c"&gt;# &lt;/span&gt;
&lt;span class="c"&gt;# REMOVED FOR BREVITY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see we have a couple of options to choose including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;select (&lt;strong&gt;pick&lt;/strong&gt;) the same commit&lt;/li&gt;
&lt;li&gt;update (&lt;strong&gt;reword&lt;/strong&gt;) a commit message in-place&lt;/li&gt;
&lt;li&gt;update (&lt;strong&gt;edit&lt;/strong&gt;) a commit message (This will open another window to edit the commit message)&lt;/li&gt;
&lt;li&gt;combine (&lt;strong&gt;squash&lt;/strong&gt;) commit messages&lt;/li&gt;
&lt;li&gt;remove (&lt;strong&gt;drop&lt;/strong&gt;) a commit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All we need to do is select the required action (e.g. &lt;code&gt;pick&lt;/code&gt; or &lt;code&gt;squash&lt;/code&gt;) and replace the current &lt;code&gt;pick&lt;/code&gt; actions with the new action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;reword 58bc9d0 file.txt created and updated
pick 121c507 file2.txt created
pick 64a2c99 file2.txt updated
squash 2ef342a file2.txt updated step 1!
squash e84f687 file2.txt updated step 2!
squash 16c8448 file2.txt updated step 3!
drop 11454df &lt;span class="nb"&gt;test &lt;/span&gt;something!

&lt;span class="c"&gt;# &lt;/span&gt;
&lt;span class="c"&gt;# REMOVED FOR BREVITY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After saving the above (e.g. using &lt;code&gt;:wq&lt;/code&gt; in &lt;code&gt;vi&lt;/code&gt;), as we asked Git to squash some of our commits, it will open another window so we can finalize the commit message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# This is a combination of 4 commits.&lt;/span&gt;
&lt;span class="c"&gt;# This is the 1st commit message:&lt;/span&gt;

file2.txt updated

&lt;span class="c"&gt;# This is the commit message #2:&lt;/span&gt;

file2.txt updated step 1!

&lt;span class="c"&gt;# This is the commit message #3:&lt;/span&gt;

file2.txt updated step 2!

&lt;span class="c"&gt;# This is the commit message #4:&lt;/span&gt;

file2.txt updated step 3!

&lt;span class="c"&gt;# Please enter the commit message for your changes.&lt;/span&gt;
&lt;span class="c"&gt;# &lt;/span&gt;
&lt;span class="c"&gt;# REMOVED FOR BREVITY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can update this to have our desired message (e.g. remove all except &lt;code&gt;file2.txt updated&lt;/code&gt;) or we can save it just as it is. Note that lines starting with a hash &lt;code&gt;#&lt;/code&gt; will not be added to the final commit message. &lt;/p&gt;

&lt;p&gt;Now if you run &lt;code&gt;git log&lt;/code&gt;, you will see the applied changes which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;update the message of the 1st commit&lt;/li&gt;
&lt;li&gt;retain the 2nd and the 3rd commits&lt;/li&gt;
&lt;li&gt;squash the 4th, 5th and the 6th commits into the 3rd commit (This opens another window so we can make the final change)&lt;/li&gt;
&lt;li&gt;remove the 7th commit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that instead of &lt;code&gt;squash&lt;/code&gt; we could choose &lt;code&gt;fixup&lt;/code&gt; for commits we want to combine and Git would choose the message of the &lt;code&gt;pick&lt;/code&gt; commit before those commits (i.e. &lt;code&gt;64a2c99&lt;/code&gt;) as the final commit message for the combined commits.&lt;/p&gt;

&lt;p&gt;Also, for &lt;strong&gt;re-ordering&lt;/strong&gt; commits, we can simply change the line arrangement of the commits and put a specific commit before or after another commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pick 121c507 file2.txt created
pick 58bc9d0 file.txt created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>git</category>
      <category>history</category>
      <category>squash</category>
    </item>
  </channel>
</rss>
