<?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 Banujan Balendrakumar on Medium]]></title>
        <description><![CDATA[Stories by Banujan Balendrakumar on Medium]]></description>
        <link>https://medium.com/@badpiggie?source=rss-4241558f7e5f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Doyn6n0zTC2upZ27MdY7eg.jpeg</url>
            <title>Stories by Banujan Balendrakumar on Medium</title>
            <link>https://medium.com/@badpiggie?source=rss-4241558f7e5f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 19:38:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@badpiggie/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[Javascript: Async/Await Error-Handling in an elegant way]]></title>
            <link>https://javascript.plainenglish.io/javascript-async-await-error-handling-in-an-elegant-way-26735ec8940e?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/26735ec8940e</guid>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[readability]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Wed, 31 Jul 2024 20:51:00 GMT</pubDate>
            <atom:updated>2024-08-01T00:17:12.983Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*9GmAsjHzRfBq1fKppkSW_w.jpeg" /><figcaption>Image Source: <a href="https://ruben.verborgh.org/blog/2012/12/31/asynchronous-error-handling-in-javascript/">https://ruben.verborgh.org/blog/2012/12/31/asynchronous-error-handling-in-javascript/</a></figcaption></figure><p>In Javascript, The <strong>Async/Await</strong> made the asynchronous programming much easier and cleaner. But still handling errors gives us headaches in more complex real-world scenarios. In certain scenarios <strong>try/catch</strong> gives more flexibility, in others <strong>then()/catch()</strong> gives more flexibility. But the problem is people often use both <strong>then()</strong> and <strong>await</strong> together in the codebase which makes the code uglier. In this story, we are going to see how to write elegant error handlers in the await codebase <strong>NOT</strong> <strong>then()</strong>.</p><h3>The Scenario….</h3><p>Let’s take a simple scenario, we have a simple <strong>async function run()</strong>. It has a bunch of async function calls using the <strong>await</strong> keyword.</p><ol><li>Get the data from the cache.</li><li>If it does not exist in the cache, then get it from the database.</li><li>Once fetched the data, process the data.</li></ol><pre>async function getFromCache( key ) {<br>  // If key &quot;foo&quot; only return data<br>  return key === &quot;foo&quot; ? [&quot;🍐&quot;, &quot;🍒&quot;, &quot;🍉&quot;] : null;<br>}<br><br>async function getFromDatabase() {<br>  return [&quot;🥑&quot;, &quot;🍑&quot;, &quot;🌽&quot;];<br>}<br><br>async function processData( data ) {<br>  console.log(`Processing ${data.join(&#39;,&#39;)}`);<br>}<br><br>async function run() {<br>  let data;<br><br>  data = await getFromCache(&quot;foo&quot;);<br>  console.log(&quot;Cache result:&quot;, data );<br><br>  // If Data is NULL, Assume key not exist and get from Database<br>  if ( !data ) {<br>    data = await getFromDatabase();<br>    console.log(&quot;DB result:&quot;, data );<br>  }<br><br>  await processData( data );<br>}<br><br>run();</pre><p>Let’s see the result first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h62n-8VtedoK7I0uePcThA.png" /><figcaption>Results when key = “foo”</figcaption></figure><p>Let’s change <strong>getFromCache(“foo”);</strong> to <strong>getFromCache(“bar”);</strong> and check:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DDIIk7kfvpMOjP1R1xl2Eg.png" /><figcaption>Result when key = “bar”</figcaption></figure><p>It is just working as expected at this moment. But what if any of the above function calls throws an error? We have to handle it right? So let’s handle the errors.</p><h3>The Try / Catch</h3><p>The most common way of handling errors in Javascript is wrapping the logic using <strong>try/catch</strong>. If the execution flow meets any exception in the middle, the entire try block stops executing and moves to the catch block.</p><pre>async function run() {<br>  try {<br>    let data;<br><br>    data = await getFromCache(&quot;foo&quot;);<br>    console.log(&quot;Cache result:&quot;, data );<br>  <br>    // If Data is NULL, Assume key not exist and get from Database<br>    if ( !data ) {<br>      data = await getFromDatabase();<br>      console.log(&quot;DB result:&quot;, data );<br>    }<br>  <br>    await processData( data );<br>  } catch (err) {<br>    console.log(&quot;Handled&quot;, err.message);<br>  }<br>}</pre><p>I have modified the <strong>getFromCache</strong> function to throw an <strong>error</strong> instead of returning <strong>null</strong> if the key is not found.</p><pre>async function getFromCache( key ) {<br>  if ( key !== &quot;foo&quot; ) {<br>    throw new Error(&quot;KEY_NOT_EXIST&quot;);<br>  }<br>  return [&quot;🍐&quot;, &quot;🍒&quot;, &quot;🍉&quot;];<br>}</pre><p>Now the error will be handled by the catch block and the rest of the execution in the <strong>try block</strong> will be stopped.</p><h3>Continue; even on Error</h3><p>Now I slightly modify the requirement. The cache <strong>is not compulsory</strong> for the execution since we can fetch data from the database anyway. So, The execution <strong>should continue</strong> using the database if the cache key is not found.</p><p>But we have a problem! Since we have used the <strong>try/catch</strong> in the top level of the function, as soon as it catches the error it will stop the rest of the execution. So how to fix this?</p><h4>Nested Try/Catch</h4><p>We can narrow down the scope of <strong>try/catch</strong> blocks by using <strong>nested try/catch</strong> blocks as follows.</p><pre>async function run() {<br>  try {<br>    let data;<br><br>    // Nested try/catch<br>    try {<br>      data = await getFromCache(&quot;bar&quot;);<br>      console.log(&quot;Cache result:&quot;, data );<br>    } catch (err) {<br>      console.log(&quot;Cache not exist, It&#39;s okay :)&quot;);<br>    }<br><br>    if ( !data ) {<br>      data = await getFromDatabase();<br>      console.log(&quot;DB result:&quot;, data );<br>    }<br><br>    await processData( data );<br>  } catch (err) {<br>    console.log(&quot;Handled&quot;, err.message);<br>  }<br>}</pre><p>Now the error from <strong>getFromCache</strong> will be caught by the nested catch block and the rest of the execution will continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5uuxXmup9wIrmJrkcN78xg.png" /><figcaption>Output of nested try/catch</figcaption></figure><h3>But, I hate it!</h3><p>Even though the <strong>nested try/catch</strong> blocks give a way to handle errors as smaller segments, In larger projects with complex code too many nested blocks make the code uglier.</p><h4>So, What do I do?</h4><p>I use a wrapper function to do the job. In most of my projects, I write a helper function that accepts the function as an argument and handles the error for us.</p><p><strong>WAIT: </strong><em>I know. Before you guys kick my 🍑, This is a very opinionated approach. But I strongly recommend you try, that saves the struggle in most cases.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9VOU4JnFQnMk1y8kH9mxoQ.jpeg" /><figcaption>People get offended when they get to know that the Captain is a JS dev.</figcaption></figure><p>The wrapper function:</p><pre>async function ignorable(func) {<br>  // keep the error status<br>  let err = false;<br><br>  try {<br>    // SHOULD use await to avoid jumping to parent scope<br>    return await func();<br>  } catch (e) {<br>    // mark error status<br>    err = true;<br>  } finally {<br>    // return error response -1,<br>    // or NULL or undefined, whatever that works for you<br>    // SHOULD check err status. Otherwise it will overwrite<br>    // - the original return from the try block<br>    if ( err ) {<br>      return -1;<br>    }<br>  }<br>}</pre><p>Now use can use the above function as follows:</p><pre>async function run() {<br>  try {<br>    let data;<br><br>    // Pass the function as arg to ignorable function<br>    data = await ignorable(() =&gt; getFromCache(&quot;bar&quot;))<br>    console.log(&quot;Cache result:&quot;, data );<br><br>    // If error, Then fetch from DB<br>    if ( data === -1 ) {<br>      data = await getFromDatabase();<br>      console.log(&quot;DB result:&quot;, data );<br>    }<br><br>    await processData( data );<br>  } catch (err) {<br>    console.log(&quot;Handled&quot;, err.message);<br>  }<br>}</pre><p>And the result would be the same:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVAeSKFybW8UXsbau86d3Q.png" /><figcaption>Response after using ignorable</figcaption></figure><h4>What about sync functions?</h4><p>You can still pass <strong>synchronous functions</strong> into <strong>ignorable</strong> it will work just fine since the await has no power.</p><h3>Conclusion</h3><p>Using nested try/catch blocks will give the ability to handle errors individually in an isolated manner. However, using too many nested try/catch blocks will lead to readability issues. So, I have suggested an alternative way to handle it using a wrapper function. It will make less readability issues and make the code cleaner. Anyway, This is very opinionated and always do your experiments and pick the solution that works for you.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26735ec8940e" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/javascript-async-await-error-handling-in-an-elegant-way-26735ec8940e">Javascript: Async/Await Error-Handling in an elegant way</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OAuth2.0 — For Absolute Beginners (Part 1)]]></title>
            <link>https://medium.com/sliit-foss/oauth2-0-for-absolute-beginners-part-1-619e92e6e40b?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/619e92e6e40b</guid>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[auth0]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[open-authorization]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Thu, 02 Jun 2022 19:55:04 GMT</pubDate>
            <atom:updated>2022-06-03T03:09:40.004Z</atom:updated>
            <content:encoded><![CDATA[<h3>OAuth2.0 — For Absolute Beginners (Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*WI30JRDUNGuDDKWXrIvu7A.jpeg" /><figcaption>OAuth Logo | Source:- https://oroinc.com</figcaption></figure><h3><strong>Introduction 😊</strong></h3><p><strong>OAuth</strong> stands for <strong>Open Authorization</strong>, Which is an open standard to provide <strong>Delegated Access</strong> to client applications without giving the password. <strong>OAuth</strong> is not an application or service that you can install and use. It is just an open standard, By following it you can implement <strong>OAuth</strong> in your application.</p><p>There are 2 versions, <strong>OAuth1.0</strong> and <strong>OAuth2.0</strong>. Both are completely different, and <strong>cannot be</strong> used together. <strong>OAuth2.0 is the widely used version</strong>. Before diving into the topic, Let’s understand the problem that <strong>OAuth2.0</strong> solves. In this story, I will explain the basic concept of <strong>OAuth2.0.</strong></p><h3><strong>The Real Problem ⚠️</strong></h3><p>Before OAuth, Allowing apps to access particular data from another app was extremely difficult. Applications were using terrible methods to accomplish this.</p><p><strong><em>Imagine the following scenario:</em></strong></p><p><em>You are using a photo editor and that app wants to import photos from your google photos account directly. How can you permit the photo editor app to access your google photos?</em></p><p>The only way is to share your login <strong>credentials</strong>, So the photo editor logs into google photos for you and gets photos from your account. Of course, This is a stupid idea. The password <strong>should no</strong>t be shared with anyone else. But before OAuth, 3rd party applications asked for the user’s password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*cS0UJmtc7kR9teqeVrN9vg.png" /><figcaption>Before OAuth, Facebook was asking for the Gmail password to access friends’ email addresses.</figcaption></figure><p>So before <strong>OAuth</strong>, we had <strong>3 major problems</strong>.</p><ol><li><strong>Trust Issues 😒</strong><br>Even though 3rd party apps say <em>“We don’t store your password”</em>, We cannot trust them. We don’t know if they do anything else using our credentials.</li><li><strong>Credential Leakage 💧</strong><br>If those 3rd party apps store our Gmail or any other application credentials insecurely, A single security breach will expose all the connected app credentials.</li><li><strong>No Delegated Access ❌</strong><br>Once you gave your credentials, They can access everything in the application. We cannot restrict them to access only the particular data. <br><em>Eg:- Facebook may say We only access emails, but what if they access the inbox messages?</em></li></ol><p>To solve the issues mentioned above, The new <strong>Authorization Framework</strong> <strong>OAuth2.0</strong> [<a href="https://datatracker.ietf.org/doc/html/rfc6749">RFC6749</a>] was implemented.</p><h3>OAuth 2.0 🛡</h3><p><strong>OAuth 2.0</strong> obtains <strong>Limited Access</strong> to 3rd party applications <strong>without providing the password</strong>. Instead of validating the password, it validates special tokens called <strong>AccessToken</strong> and <strong>RefreshToken</strong>.</p><h4>How does it work?</h4><p>Well, I am pretty sure that everyone has seen this without knowing what it is 😂. Let me show you a quick demo.</p><p>Let’s say I want to allow <strong>Shutterfly</strong> to access my <strong>Google Photos</strong>, So it can access and show those in <strong>Shutterfly</strong>.</p><figure><img alt="Connect Google Photos + Shutterfly" src="https://cdn-images-1.medium.com/max/1024/1*OudIAlJhSAZjFZVyl1lj_w.png" /><figcaption>Connect Google Photos + Shutterfly</figcaption></figure><p>Now, I am gonna click on the “<strong>Connect</strong>” button to connect to my <strong>Google Account</strong>.</p><figure><img alt="Google OAuth Login Screen for Shutterfly" src="https://cdn-images-1.medium.com/max/1024/1*IPiSjuqMGY5-XBz6FNKzbg.png" /><figcaption>Google OAuth Login Screen for Shutterfly</figcaption></figure><p>Now you can see, Instead of asking for my Email and Password, <strong>Shutterfly</strong> takes me to <strong>Google</strong> to log in. So, The <strong>Shutterfly</strong> <strong>never knows</strong> my <strong>Google credentials.</strong> I can securely log into <strong>Google</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6Muoz3W-1X1YRyBQbKjXA.jpeg" /><figcaption>Google OAuth Permission Request</figcaption></figure><p>Once you are logged into your google account, It will ask you <strong>“Hey, Shutterfly asking for these permissions. Can I allow it?”</strong>. Once you allowed it, <strong>Google</strong> sends the <strong>AccessToken</strong> and <strong>RefreshToken</strong> to <strong>Shutterfly</strong>.</p><p>Every time, when <strong>Shutterfly</strong> needs to do anything in my <strong>Google Photos </strong>account, It should submit the <strong>Access Token</strong> along with the request. <strong>Google Photos </strong>will validate this <strong>Access Token</strong> and check the permissions it has. If the <strong>Access Token</strong> is valid and the requested operation is granted, <strong>Google Photos</strong> will <strong>allow</strong> it. Otherwise, it will <strong>deny</strong>. The <strong>Access Token</strong> has an <strong>expiry date</strong>. If it is expired, <strong>Shutterfly</strong> needs to get a new <strong>Access Token</strong> using the <strong>Refresh Token</strong>.</p><p>As you can see We granted <strong>Limited Permissions</strong> <em>(See, upload, and organize photos)</em> to <strong>Shutterfly</strong>. That means, <strong>Shutterfly</strong> can’t do any other operations in my <strong>Google</strong> account except the scopes I allowed. This is called <strong>Delegated Access</strong>.</p><h4>Before we move, Let’s see some terminologies.</h4><ol><li><strong>Authorization Server</strong><br>The party that authenticates the user and authorizes the scopes requested by the 3rd-party application. <em>In the above example, it’s Google (https://accounts.google.com)</em></li><li><strong>Resource Server</strong><br>The party that has the resources. <em>In the above example, The resource is your photos, and the resource server is Google Photos. (https://photos.google.com)</em></li><li><strong>Resource Owner</strong><br>The party that owns the resources. <em>In the above scenario, You own your photos. So, The resource owner is You.</em></li><li><strong>Scopes</strong><br>Scopes are nothing, It is just the permissions requested by the 3rd-party application. <em>Eg: — Read Emails, Access Contacts, and See Photos.</em></li><li><strong>Access Token</strong><br>A Token that is given by the Authorization Server to the 3rd-party app to access resources. When a 3rd-party app requests resources from the resource server, It Should submit this AccessToken. The resource server will verify the token and allow or deny based on the verification result.<br><em>Eg:- 3MiOiJodHRwczovL2V4YW1wbGUuYXV0aDAuY29tLyIsImF1ZCI6Imh0dHBzOi8vYXBpLmV4YW1wbGUuY29tL2NhbGFuZGFyL3YxLyIsInN1YiI6InVzcl8xMjMiLCJpYXQiOjE0NTg3ODU3OTYsImV4cCI6MTQ1ODg3MjE5</em></li><li><strong>Refresh Token</strong><br>An Optional Token that is given by Authorization Server to the 3rd-party application to renew the expired access token.</li></ol><p>The above terms are really important to understand the upcoming stories because we will be deep diving into <strong>OAuth2.0</strong>.</p><p>So, These are the basic concept of <strong>OAuth2.0</strong>. It provides a way to obtain limited access to 3rd-party applications to access particular resources only without exposing our credentials. It <strong>solves the 3 major issues</strong> that we saw earlier.</p><ol><li><strong>Trustable</strong> 🤝 <br>Because We don’t submit credentials through the 3rd-party application. Instead, We directly log in from the application that the account belongs to.</li><li><strong>No Credential Leakage</strong> 💪 <br>Since the 3rd-party doesn’t know the credentials, We don’t need to worry about it. The Access Tokens are short-lived, So even if the 3rd-party application leak the Access Token, The attacker will have access for short time only.</li><li><strong>Delegated Access</strong> 🔒 <br>Since the Access Tokens are attached to the specific scopes, The 3rd-party application cannot perform any unauthorized operation.</li></ol><h3>Summery</h3><p>I hope you understand the basic concept of <strong>OAuth2.0</strong>, In the upcoming stories, I will be deep-diving into <strong>OAuth2.0</strong>. We will be discussing some advanced topics such as <strong>Grant Types</strong>, <strong>Opaque and JWT Access Tokens</strong>, <strong>Securing Tokens</strong> &amp; etc. So, Stay tuned and follow for more.</p><p><strong>Thank you</strong> 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=619e92e6e40b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/oauth2-0-for-absolute-beginners-part-1-619e92e6e40b">OAuth2.0 — For Absolute Beginners (Part 1)</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Send Logged-In Email Alerts Using Auth0 Actions]]></title>
            <link>https://medium.com/sliit-foss/send-logged-in-email-alerts-using-auth0-actions-7518e516021b?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7518e516021b</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[auth0]]></category>
            <category><![CDATA[sendgrid]]></category>
            <category><![CDATA[auth0-ambassador]]></category>
            <category><![CDATA[auth0-action]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Fri, 31 Dec 2021 07:54:34 GMT</pubDate>
            <atom:updated>2022-01-08T06:07:46.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*tA4Vy428JtvFWzbrfIF1hQ.png" /><figcaption>Auth0 Logo</figcaption></figure><p>Heyo ✋</p><p><strong>Auth0</strong> recently rolled out a new feature called <strong>Actions</strong>. Actions are <strong>Node.Js</strong> functions that allow you to build your custom plug and playable logics that are running on <strong>Auth0 runtime</strong>. Actions currently support NodeJs only but we can expect other language support in future.</p><p>In this story, We are going to see how to implement a custom logic that automatically sends an <strong>account logged-in alert</strong> email with some data such as <strong>Ip-Address</strong>, <strong>Geo Locations</strong> and <strong>Timestamp</strong>.</p><h3>1. Jump into the Auth0 Dashboard</h3><p>In this story, I use the <strong>default database username-password authentication</strong>. This is a default authentication you can see after creating your Auth0 Account.</p><p>Once you navigated to the dashboard, Go to the <strong>Actions</strong> page and select <strong>Login</strong> <strong>Flow</strong>. Because we need to send the email when your log into the account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BltqPO1Ibds6rfx5gnnCMA.png" /><figcaption>Choose Login Flow</figcaption></figure><h3>2. Create New Custom Action</h3><p>Auth0 provides a lot of actions you can easily install into your flows. But in this case, we are going to develop our custom action. So let’s navigate to the <strong>Custom</strong> tab and create a <strong>New Action</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwWeqq264S61TLeES3mUHw.png" /></figure><p>Name your action and select the trigger. Login flow only supports <strong>Login / Post Login trigger</strong>, But Auth0 Action has some other useful triggers too.</p><p><strong><em>⭐️ Find more about triggers:</em></strong> <a href="https://auth0.com/docs/actions/triggers">https://auth0.com/docs/actions/triggers</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-m4YE-XwKqFDzG5x_VHxKA.png" /></figure><p>Once you created the action, You can see the code editor where you can <strong>develop</strong>, <strong>test</strong> and <strong>deploy</strong> your action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DM1xNKwQvr2OGP2XF3NJMg.png" /></figure><h3>3. Setup Email Account</h3><p>Before jumping into the code, Set up your email account. I am using <strong>SendGrid</strong> here, But it’s totally your choice you can use any email service provider.</p><h3>4. Setup Node Modules &amp; Secrets</h3><p>Also, actions allow us to add <strong>node modules</strong> that we can use in code. Since I am using <strong>SendGrid</strong>, I need to add the <strong>SendGrid/mail</strong> package to send emails. You can use any <strong>npm packages up to 10</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TbY9Rx0WTLu269MnRdNbrQ.png" /></figure><p>Apart from node modules, We can define our <strong>secrets</strong> in action as <strong>key-value</strong> pairs. Here I added my <strong>Sendgrid_API_Key</strong>. Secrets have some limitations too. Each <strong>secret key</strong> may have a <strong>maximum length of 128</strong> characters and the <strong>value</strong> may have a <strong>maximum length of 2048</strong> characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2Y2VZhujR45wT9-80cXLg.png" /></figure><h3>5. Write The Action Logic</h3><p>The action code will be executed based on the trigger. In our case, It is the <strong>Login / Post Login trigger</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f19e63fe1dd251c027d2c876e018cb6e/href">https://medium.com/media/f19e63fe1dd251c027d2c876e018cb6e/href</a></iframe><p>The trigger handler methods will receive <strong>2 objects</strong> called <strong>event</strong> and <strong>api</strong>. The <strong>event</strong> object will contain all the information regarding the triggered event.</p><p><strong><em>⭐️ More about event object:</em></strong> <a href="https://auth0.com/docs/actions/triggers/post-login/event-object">https://auth0.com/docs/actions/triggers/post-login/event-object</a></p><p><strong><em>Example event object:-</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92f830b0805f33e338d22e72771548bd/href">https://medium.com/media/92f830b0805f33e338d22e72771548bd/href</a></iframe><p>The <strong>api</strong> object provides <strong>methods</strong> to <strong>change the behaviour</strong> of the flow like <strong>denying login process</strong>, <strong>enforcing MFA</strong> and etc. These <strong>event</strong> and <strong>api</strong> objects will contain different data and methods based on trigger type.</p><p><strong><em>⭐️ More about api object:</em></strong> <a href="https://auth0.com/docs/actions/triggers/post-login/api-object">https://auth0.com/docs/actions/triggers/post-login/api-object</a></p><p>Okay, Let’s implement our logic. First of all, we need to collect the necessary information about the login from the event object.</p><p><em>See the above event object example for reference.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab45bcb72db5b50913aa089b18d1047e/href">https://medium.com/media/ab45bcb72db5b50913aa089b18d1047e/href</a></iframe><p>Since we are using <strong>SendGrid</strong> here, We need to import the <strong>SendGrid</strong> package and initialize it using our <strong>api</strong> <strong>key</strong>. We already added the <strong>SENDGRID_API_KEY</strong> in <strong>step 4</strong>. We can access it in code from the <strong>event</strong> object like <strong>event.secrets.SENDGRID_API_KEY</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc72840a308a9aeed0d8c75b378fb05a/href">https://medium.com/media/bc72840a308a9aeed0d8c75b378fb05a/href</a></iframe><p>Now, all we have to do is implement another function to send an email to the user. In this function, We should create a good looking email template and bind data to it. Then send the email to the email address of the user.</p><blockquote><strong>Note:</strong> This email function implementation <strong>fully depends on your email service provider</strong>. You might need to change something according to that.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfdeebc3e11b325db956b0e1ff2e9c3d/href">https://medium.com/media/bfdeebc3e11b325db956b0e1ff2e9c3d/href</a></iframe><p>Once the <strong>sendMail</strong> function is ready, We need to call it from <strong>onExecutePostLogin</strong> to send emails. The final code is given below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c63329182a40c88e1e0cc25a13304f0/href">https://medium.com/media/8c63329182a40c88e1e0cc25a13304f0/href</a></iframe><p>Once you are done with the implementation, You can <strong>run</strong> the action for <strong>testing purposes</strong>, But once you have done with your testing <strong>don’t forge</strong>t to <strong>deploy</strong> it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8kySdEP5iitGcf-V8aOZg.png" /></figure><h3>6. Add the action to the flow</h3><p>Once you deploy you need to add the action to the flow by just <strong>dragging and dropping</strong> it. You can <strong>multiple actions</strong>, Which will be executed according to the <strong>order</strong> <strong>sequence</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJsMGh2q6RRD_m4KZfC7yQ.png" /></figure><h3>DONE! It’s testing time 🙄</h3><p>Let’s try to log into the <strong>Auth-0 default application authentication</strong> and see whether do we receive emails or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDBNEBKPFFxZVp2-n1G6eQ.png" /></figure><p>I logged into the account, Let’s check the email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9TXH2em4gEF7kSAWXShiA.png" /></figure><h4>Wahooo! Works like a charm 😍✨</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4kwH2B0p64M7QZND" /><figcaption>Photo by <a href="https://unsplash.com/@mioitophotography?utm_source=medium&amp;utm_medium=referral">MIO ITO</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Conclusion</h3><p>Auth0 actions allow us to customize and extend the authentication and authorization behaviour with custom logic. One of the beautiful things about Actions is, It allows to drag and drop actions anywhere into the flows that give clean visuals of the entire flow and actions used.</p><p><strong>And,</strong><br>This is my last story of 2021, Will meet you with another story in 2022. Wish you all a very happy new year. 🎉🍾</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7518e516021b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/send-logged-in-email-alerts-using-auth0-actions-7518e516021b">Send Logged-In Email Alerts Using Auth0 Actions</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protobuf : What? and Why?]]></title>
            <link>https://medium.com/sliit-foss/protobuf-over-json-to-interchange-data-efficiently-5e69c296583c?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e69c296583c</guid>
            <category><![CDATA[data-interchange]]></category>
            <category><![CDATA[protobuf]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[protocol-buffers]]></category>
            <category><![CDATA[serialization]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Sun, 07 Nov 2021 19:52:27 GMT</pubDate>
            <atom:updated>2022-04-16T09:22:50.278Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngUw-q0_3OaJQVBawDoipw.png" /><figcaption>Protobuf</figcaption></figure><p><strong>Heyo</strong> ✋,</p><p>After the <strong>JSON,</strong> The data representation and interchange became pretty easy and clean. Even though we had <strong>XML</strong> before, <strong>JSON</strong> lets us get rid of tag names, which reduces the file size significantly when comes to large data sets. But today we are going to have a new thing called <strong>Protocol Buffers</strong> <em>aka</em> <strong>Protobuff</strong> that beats <strong>JSON</strong> in a lot of places.</p><p>In this story, I am going to give an intro to <strong>Protobuf</strong> and We will be generating and comparing the <strong>JSON</strong> and <strong>Protobuf</strong> data in a simple <strong>Python</strong> app. Let’s jump into the topic 🚀.</p><h3>⚡️ What are Protocol Buffers?</h3><p><strong>Protobuf</strong> is a mechanism to serialize structured data developed by <strong>Google</strong>. Unlike <strong>XML</strong>/<strong>JSON</strong>, <strong>Protobuf</strong> stores data in binary that is small, fast and simple. Also, it’s <strong>language-neutral </strong>and <strong>platform-neutral</strong>. That means you can use it across any language/platform.</p><p><a href="https://developers.google.com/protocol-buffers">Protocol Buffers</a></p><h3>🙄 How does Protobuf work?</h3><p>As I mentioned before, <strong>Protobuf</strong> stores serialized data in binary format. So, Obviously, it needs a compiler to do that. <strong>Protobuf</strong> compiler is written in <strong>C++</strong> and <strong>platform-independent</strong> so you can install it on any platform.</p><p><a href="https://github.com/protocolbuffers/protobuf/releases">Releases · protocolbuffers/protobuf</a></p><p>Once you installed the compiler, You need to define <strong>messages</strong>. Basically, messages are the definition that describes what data and which format we are going to store <em>(Think a class in OOP)</em>. These <strong>messages</strong> should be stored in a file with the extension <strong>.proto</strong></p><p><strong>Example: format</strong></p><pre>message &lt;name&gt; {<br>   &lt;type&gt; &lt;field_name&gt; = &lt;field_number&gt;;<br>}</pre><p><strong>.proto</strong> files have special syntax to define messages. It has 2 versions <strong>proto2</strong> and <strong>proto3</strong>. For now, <strong>proto2</strong> is the <strong>default</strong> syntax but if you want to use <strong>proto3</strong> you need to define it explicitly.</p><p><strong>Example: proto2</strong></p><pre>message User {<br>    int32 id = 1;<br>    string name = 2;<br>}</pre><p><strong>Example: proto3</strong></p><pre>syntax = &quot;proto3&quot;;</pre><pre>message User {<br>    int32 id = 1;<br>    string name = 2;<br>}</pre><blockquote>proto3 still looks the same as proto2 but there are some differences, See the link below.</blockquote><p><a href="https://cloud.google.com/apis/design/proto3">Protocol Buffers v3 | Cloud APIs | Google Cloud</a></p><p>Once you have defined all <strong>messages</strong> in <strong>proto</strong> files, You need to compile them. When you compile proto files, The compiler will <strong>generate</strong> some <strong>class files</strong> for the specified language that handles the rest of the operations in your code such as <strong>serializing</strong> and <strong>deserializing</strong> data.</p><p><strong>Example:</strong> compile command</p><pre>protoc --proto_path={IMPORT_PATH} --java_out={DST_DIR} path/to/file.proto</pre><p><strong>proto_path</strong> = The directory of the <strong>.proto</strong> files that the compiler needs to look at when trying to resolve the <strong>import</strong> statement.</p><p><strong>java_out</strong> = The directory to generate class files for <strong>java</strong>. If you are using a different language you can use something like <strong>cpp_out</strong>/<strong>java_out</strong>/<strong>python_out</strong>.</p><h3>⚖️ Comparing JSON and Protobuf</h3><p>This is a practical part. I am going to create a simple python script to store <strong>100 User Records</strong> with <strong>id</strong>, <strong>firstName</strong>, <strong>lastName</strong>, <strong>username</strong>, and <strong>email</strong> details. We will be storing data in both <strong>Protobuf</strong> and <strong>JSON</strong> format and let’s compare the size it consumes.</p><h4>Project Structure</h4><pre>|- proto/<br>    |- User.proto<br>|- proto_code/<br>|- main.py</pre><p><strong>proto/ — </strong>Directory that contains <strong><em>.proto</em></strong> file(s).<br><strong>proto_code/ —</strong> Directory that contains the generated class files.<br><strong>main.py — </strong>The main python script to execute</p><h4>1. Create .proto file and define messages</h4><p>Let’s create the <strong>User.proto</strong> file inside the <strong>proto/</strong> directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28e7d8cd845d23b470a101d758d1f14d/href">https://medium.com/media/28e7d8cd845d23b470a101d758d1f14d/href</a></iframe><h4>2. Compile the <strong>User.proto</strong> file</h4><pre>$ rotoc proto_path=proto --python_out=proto_code proto/User.proto</pre><p>About command will generate a class file for python which will look like the below,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48dc8be482dbfd73769657e73cd1275f/href">https://medium.com/media/48dc8be482dbfd73769657e73cd1275f/href</a></iframe><h4>3. Create Python Programme</h4><p>This is the main python program. If you don’t know python it’s okay because I am not going to explain everything here, It’s just for giving an idea of how to use <strong>Protobuf</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fa23a223e392e48ad6013754330a070/href">https://medium.com/media/3fa23a223e392e48ad6013754330a070/href</a></iframe><h4>4. Execute and Observe the results</h4><p>Once I executed the above script. I got 2 new files, One contains <strong>Protobuf</strong> binary data and another file contains <strong>JSON</strong> data. Let’s have a side-by-side view of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3GrPPQAOxH_VgHSPBb7caw.png" /><figcaption>Protobuf vs JSON</figcaption></figure><p>Let’s see how much disk space these 2 files consumed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_qxy3A01fd_NshPoClQqA.png" /><figcaption>File Size | Protobuf vs JSON</figcaption></figure><p>As you can see, The <strong>Protobuf</strong> got almost <strong>half</strong> of the disc space that took by <strong>JSON</strong>. Researchers say sometimes they could achieve <strong>6 times</strong> smaller space than <strong>JSON</strong>. Because of this, <strong>Protobuf</strong> binaries can be interchanged over the network faster than <strong>JSON</strong>. Anyways, now you understood that <strong>Protobuf</strong> is the really good and best way to store and transfer the data than <strong>JSON</strong>.</p><h3>Pros &amp; Cons of Protocol Buffers</h3><h4>Pros</h4><ul><li>Very smaller size</li><li>Fast Serialization/Deserialization</li><li>Supports RPC</li><li>Structure and Type validation</li></ul><p><strong>Cons</strong></p><ul><li>Smaller Community (for now)</li><li>Lack of Resources (for now)</li><li>Not human-readable format</li></ul><h3>Conclusion</h3><p><strong>Protobuf</strong> will really boost applications that handle large data flow. Because of its awesome size compression, It will take less time to exchange over the network. Also, <strong>Protobuf</strong> data can be shared across any platform and used in any language application.</p><p>But, It stores data as a binary. So humans cannot interact with it directly. Because of that, If you want to store any data that can be directly managed by the user such as <strong>configurations</strong>, <strong>settings</strong> and etc, You should pick <strong>JSON</strong>/<strong>XML</strong> over <strong>Protobuf</strong>.</p><p>Hope you got an idea about <strong>Protocol Buffers</strong>, Play with <strong>Protobuf</strong> in your favourite language.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e69c296583c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/protobuf-over-json-to-interchange-data-efficiently-5e69c296583c">Protobuf : What? and Why?</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 6 HTTP Headers that improve your site security.]]></title>
            <link>https://medium.com/sliit-foss/top-6-headers-that-improve-your-site-security-d1c068f0312c?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1c068f0312c</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[http-headers]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[build-secure-apps]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Sat, 16 Oct 2021 13:41:06 GMT</pubDate>
            <atom:updated>2021-10-31T16:26:26.377Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pclZNwtiUPEAC9POL1gAWQ.jpeg" /><figcaption>Web Security (Source: <a href="https://brandreachers.com/wp-content/uploads/2020/06/web-security-img.jpg">https://brandreachers.com</a>)</figcaption></figure><p>Security is a really important thing but almost we don’t care when building applications. There are a lot of essential security practices, But in this story, I am going to talk about <strong>HTTP Security Headers.</strong></p><p>In <strong>HTTP requests</strong>, Headers hold the metadata about the request/response. Apart from that, Some <strong>HTTP Headers</strong> are used to enforce some security mechanisms.</p><p>Okay, Let’s jump into the topic…</p><h3>HTTP Strict Transport Security (HSTS)</h3><p>Most websites use <strong>HTTPS</strong> nowadays. That’s really good. But some sites don’t force users to communicate via <strong>HTTPS</strong>. Instead, they work on both <strong>HTTP</strong> and <strong>HTTPS</strong>. This is really bad. Because Still, they are giving an option to communicate non-securely.</p><p><strong>HSTS header</strong> helps us to force users to access the site via <strong>HTTPS</strong> only. So basically, When the browser finds this header, It will change the connection to <strong>HTTPS</strong> even if the user tries to access it via <strong>HTTP</strong>.</p><pre>Strict-Transport-Security: max-age=&lt;expire-time&gt;<br>Strict-Transport-Security: max-age=&lt;expire-time&gt;; includeSubDomains<br>Strict-Transport-Security: max-age=&lt;expire-time&gt;; preload</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security">Strict-Transport-Security - HTTP | MDN</a></p><h3>Content Security Policy (CSP)</h3><p><strong>CSP headers</strong> will allow us to define what kind of resources can be loaded into the site. So we can have more control over the resources such as <strong>JavaScript</strong>, <strong>Images</strong>, <strong>CSS</strong>, <strong>Fonts</strong>, <strong>AJAX requests</strong>, <strong>Frames</strong>, <strong>HTML5 Media.</strong></p><p>We can whitelist what contents from which origin the browser can load into the webpage. Because of this restriction, we can mitigate a lot of attacks including <strong>XSS</strong>, <strong>Data Injection</strong> and <strong>ClickJacking</strong>.</p><pre>Content-Security-Policy: &lt;policy-directive&gt;; &lt;policy-directive&gt;</pre><p>Can specify in <strong>Meta Tag</strong> too</p><pre>&lt;meta http-equiv=&quot;Content-Security-Policy&quot;<br>      content=&quot;default-src &#39;self&#39;; img-src https://*;&quot;&gt;</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy">Content-Security-Policy - HTTP | MDN</a></p><h3>Cross-Site Scripting Protection (X-XSS)</h3><p><strong>X-XSS-Protection headers</strong> are preventing the execution of malicious javascript code. If the <strong>X-XSS-protection header</strong> is enabled and the browser finds an <strong>XSS Attack</strong>, It will stop loading the site.</p><p>This header will be added automatically on modern browsers such as <strong>Chrome</strong>, <strong>Safari</strong>. But, I recommend you to enable it on your application side too.</p><pre>X-XSS-Protection: 0 <br>X-XSS-Protection: 1 <br>X-XSS-Protection: 1; mode=block <br>X-XSS-Protection: 1; report=&lt;reporting-uri&gt;</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection">X-XSS-Protection - HTTP | MDN</a></p><h3>iFrame Protection (X-Frame-Options)</h3><p><strong>X-Frame-Options</strong> header is used to tell the browser whether the website should be allowed to load inside <strong>&lt;frame&gt;</strong>, <strong>&lt;iframe&gt;</strong>, <strong>&lt;embed&gt;</strong> or <strong>&lt;object&gt;.</strong></p><p>This header helps us to mitigate <strong>Click-Jacking</strong> Attacks. That means, Attackers uses the <strong>iFrame</strong> to load any website and reduces the opacity. So users can’t see it, But when users click, They are actually clicking on the website which is already loaded in the <strong>iframe</strong>.</p><pre>X-Frame-Options: DENY <br>X-Frame-Options: SAMEORIGIN</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options">X-Frame-Options - HTTP | MDN</a></p><h3>MIME Sniffing Prevention (X-Content-Type-Options)</h3><p><strong>MIME Sniffing</strong> is an attack that enables attackers to sniff the response from the server and change the content type then injecting malicious code/scripts. So the browser will be tricked to execute the code/script.</p><p>Using <strong>X-Content-Type-Options </strong>solves this problem. You should specify this header in the response with value <strong>nosniff.</strong></p><pre>X-Content-Type-Options: nosniff</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options">X-Content-Type-Options - HTTP | MDN</a></p><h3>Cross-Origin Resource Sharing (CORS)</h3><p>As a developer, We all are familiar with this term <strong>CORS</strong>. We get <strong>CORS</strong> errors when we want to access resources from other services. To fix this issue, Most of the time developers disable this <strong>CORS</strong> completely or allow all resources for all origins. This is a really bad idea.</p><p>Basically, <strong>CORS</strong> gives us the ability to control who can access which resources from our server/origin. We should allow necessary <strong>resources</strong>, <strong>methods</strong>, <strong>headers</strong> and <strong>origins</strong> instead of allowing everything to everyone.</p><pre>Access-Control-Allow-Origin: https://foo.example<br>Access-Control-Allow-Methods: POST, GET, OPTIONS<br>Access-Control-Allow-Headers: X-PINGOTHER, Content-Type</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">Cross-Origin Resource Sharing (CORS) - HTTP | MDN</a></p><h3>Conclusion</h3><p>Nowadays, We use a lot of <strong>frameworks</strong> and <strong>libraries</strong> to build applications. Most of the frameworks have <strong>built-in security</strong> features and some of them are enabled by default. But it doesn&#39;t mean we should not worry about it.</p><p>Make sure your site has the necessary common security implementations. Run penetration testing on your site to inspect the security level.</p><p>Give some 👏 if you like this story. Will see you in another blog.</p><p><strong>Happy Coding…</strong> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1c068f0312c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/top-6-headers-that-improve-your-site-security-d1c068f0312c">Top 6 HTTP Headers that improve your site security.</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rx.JS — Things you should understand before start.]]></title>
            <link>https://medium.com/sliit-foss/rx-js-things-you-should-understand-before-start-d9d780f85a7d?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9d780f85a7d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactivex]]></category>
            <category><![CDATA[event-driven-programming]]></category>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[observables]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Sun, 05 Sep 2021 10:48:52 GMT</pubDate>
            <atom:updated>2021-09-05T11:34:43.006Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rx.JS — Things that you should understand before start.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VWEHYp0L23M5wUN-mc3gyQ.jpeg" /></figure><p>If you have ever worked with <strong>Angular</strong>, You probably might have seen something like <strong>Observables</strong>, <strong>Subscribe()</strong>, <strong>Subject</strong> and a few more. Sometimes we may be using it without knowing what it is. If you haven’t familiar with those terms. Don’t worry, This is <strong>not</strong> something about <strong>Angular</strong>. This is all about an <strong>awesome</strong> and <strong>powerful</strong> Javascript library that you should learn.</p><p><strong>Let&#39;s jump into the topic</strong> 🚀</p><h3>Observer Pattern 🧐</h3><p><strong>Observer Pattern</strong> is one of the <strong>Software Design Patterns</strong>. If you don’t have any idea about this <strong>Observer Pattern</strong>, I highly recommend you to have a look and come back for a better understanding. Because I am not going to drag this story by explaining it. Anyway, Let me give a quick introduction.</p><p><strong>Observer Pattern</strong> is a Design Pattern that enforces <strong>Event-Driven Application Development</strong>. This pattern mainly has two objects, One is “<strong>Subject”</strong> and another one is “<strong>Observer”</strong>. Basically <strong>Subject</strong> maintains a list of <strong>Observers</strong>. It will notify them when the state changes.</p><blockquote><strong>High-Level Example</strong></blockquote><blockquote>The <strong>YouTube</strong> (<strong>Application</strong>), Has more <strong>channels</strong> (<strong>Subjects</strong>). <br><strong>We</strong> (<strong>Observers</strong>) subscribe to one of our favourite <strong>channels</strong> (<strong>Subject</strong>). <br>So, Whenever the <strong>channel</strong> (<strong>Subject</strong>) publishes new <strong>content</strong> (<strong>Data</strong>/<strong>State</strong>), It will notify <strong>us</strong> (<strong>Observer</strong>).</blockquote><p>As simple as that. 😉</p><h3>Reactive X ⚡️</h3><blockquote>ReactiveX is a library for composing asynchronous and event-based programs by using observable sequences.</blockquote><p><strong>ReactiveX</strong> is a library that allows us to extend above <strong>Observable Pattern</strong> and build <strong>Reactive</strong>, <strong>Asynchronous</strong> and <strong>Even-Based Applications</strong>. ReactiveX provides wide languages support. <strong>RxJS</strong> is the javascript version of it. You can find all <strong>other language</strong> support here.👇</p><p><a href="http://reactivex.io/languages.html">ReactiveX - Languages</a></p><h3>Rx.JS 🔥</h3><p>As I mentioned, <strong>RxJS</strong> is the Javascript library that extends <strong>ReactiveX</strong>. Before we getting started to code with <strong>RxJS</strong>, We should clearly understand its key objects. Otherwise, we cannot use it efficiently. <strong>RxJs</strong> is all about these <strong>3O</strong>s and <strong>3S</strong>s,</p><ol><li><strong>O</strong>bservable 🔊</li><li><strong>O</strong>bserver 🕵🏻‍♂️</li><li><strong>O</strong>perators 🛠</li><li><strong>S</strong>ubscription 🔔</li><li><strong>S</strong>ubject 🗃</li><li><strong>S</strong>cheduler ⏰</li></ol><h4>1. Observable</h4><p><strong>Observables</strong> are the object that <strong>push/stream </strong>the data to their <strong>Observer</strong>.</p><blockquote>We can <strong>eat</strong> only <strong>eatable</strong> objects. Also, we can <strong>move</strong> only <strong>movable</strong> objects. Like that, We can only <strong>Observe</strong>, The <strong>Observable</strong> objects.</blockquote><p>So in <strong>Rx.JS</strong>, If we want to <strong>Observe</strong> an object’s changes, The object should be <strong>Observable</strong>. In order to execute the <strong>Observable</strong>, It needs at least one <strong>Subscriber</strong>.</p><p><strong>Observables</strong> are <strong>unicast</strong>. That means it can only send data to <strong>One Observer</strong>. If you subscribe <strong>Multiple Observers </strong>to<strong> Observable</strong>, It will be invoked multiple times for each <strong>Observer</strong>.</p><p><strong>Observables</strong> are <strong>uni-directional</strong>. That means It can only pass data from <strong>Observable</strong> to <strong>Observer</strong>. We cannot feed data into <strong>Observer</strong> from the outside.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44a8a687efa72357762de28e7878e9ef/href">https://medium.com/media/44a8a687efa72357762de28e7878e9ef/href</a></iframe><h4>2. Observer</h4><p>An <strong>Observer</strong> is an object that subscribes to <strong>Observables</strong> so it can be called by <strong>Observables</strong> to emit the data.</p><blockquote>We subscribe to <strong>Newsletters</strong>, So we can get updates. In this case, We are <strong>Observers</strong> and Newsletter is <strong>Observable</strong>.</blockquote><p>An <strong>Observer</strong> object will have 3 methods <strong>next()</strong>, <strong>error()</strong> and <strong>complete()</strong>. These methods will be called by the <strong>Observable</strong> that it subscribes.</p><p><strong>next(param)</strong></p><p>This method will be called by the <strong>Observable</strong> to send new data. It accepts one <strong>parameter</strong> as the <strong>data</strong> sent by the <strong>Observable</strong>. The data can be anything such as <strong><em>Number</em></strong>, <strong><em>String</em></strong>, <strong><em>Array</em></strong>, <strong><em>Object</em></strong> &amp; etc.</p><p><strong>error(param)</strong></p><p>Same as <strong>next()</strong>, But here <strong>Observable</strong> calls this method in order to notify any <strong>error</strong>. This method also accepts one <strong>parameter</strong> that is an <strong>error</strong> message from the <strong>Observable</strong>.</p><p><strong>complete()</strong></p><p>When the <strong>Observable</strong> is done with notifying and if there are no events left, It will call this method to notify that there is nothing to emit. This method doesn’t accept any parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3aaeef20b6198ca7d375be39df390fe1/href">https://medium.com/media/3aaeef20b6198ca7d375be39df390fe1/href</a></iframe><h4><em>3. Operators</em></h4><p><em>Let’s talk about this at the end of this story. 😋</em></p><h4>4. Subscription</h4><p>An <strong>Observer</strong> or <strong>Observable</strong> cannot do anything by itself. In order to work with the <strong>Observable</strong>, An <strong>Observer</strong> should subscribe to it. A <strong>subscription</strong> is an object that holds the execution of an <strong>Observable</strong>. This subscriber has one method called <strong>unsubscribe()</strong>. This method just cancels the existing subscription. So the <strong>Observable</strong> will not execute the <strong>Observer</strong> anymore.</p><p>Also, A <strong>subscription</strong> may have another <strong>child subscription</strong>. In that case, If you <strong>unsubscribe</strong> the parent one, Then the child will be unsubscribed too.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a65dca915d555f1921da786df2381bb7/href">https://medium.com/media/a65dca915d555f1921da786df2381bb7/href</a></iframe><h4>5. Subject</h4><p><strong>Subjects</strong> are a special type of <strong>Observable</strong>. It can act as both <strong>Observable</strong> and <strong>Observer</strong>. That means you can use a <strong>Subject</strong> as <strong>Observable</strong> as well as <strong>Observer</strong>.</p><p><strong>Subject as an Observable</strong></p><p>Unlike the normal <strong>Observable</strong>, <strong>Subjects</strong> are <strong>Multicast</strong>. It can stream the data to multiple <strong>Observers</strong> without maintaining separate executions.</p><p><strong>Subjects as an Observer</strong></p><p><strong>Subjects</strong> are <strong>bi-directional</strong>. You can pass data from <strong>Subject</strong> to <strong>Observer</strong> as well as <strong>Observer</strong> to <strong>Subject</strong>. You can simply feed data into the Subject by calling the <strong>next()</strong> method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea066a0d3e50a1f7ef2ba6597a45c0fc/href">https://medium.com/media/ea066a0d3e50a1f7ef2ba6597a45c0fc/href</a></iframe><p><strong>Subject</strong> vs <strong>Observable</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6db8a61bdd70042eaebde8a8ca09b9ea/href">https://medium.com/media/6db8a61bdd70042eaebde8a8ca09b9ea/href</a></iframe><h4>Operators</h4><blockquote>Let’s discuss the skipped part Operators.</blockquote><p><strong>Operators</strong> are very important and helpful. These are just helper functions that make the complex async to be easily composed.</p><p>There are 2 types of <strong>Operators</strong>.</p><ol><li><strong>Pipeable Operators</strong></li><li><strong>Creation Operators</strong></li></ol><p><strong>Pipeable Operators</strong> can be attached to an <strong>Observable</strong> using <strong>pipe()</strong> method. It will not change the existing <strong>Observable Object</strong>. Instead, It takes the existing <strong>Observable</strong> and outputs a <strong>new Observable</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9730862ed08c90515b3c06906aaa2d1e/href">https://medium.com/media/9730862ed08c90515b3c06906aaa2d1e/href</a></iframe><p><strong>Creation Operators</strong> are standalone functions that can create <strong>Observables</strong> from standard predefined behaviours or by combining other <strong>Observables</strong>. These operators <strong>cannot</strong> be <strong>piped</strong> with <strong>Observables</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9faa4cb8bc68050d1048508b247c1df/href">https://medium.com/media/f9faa4cb8bc68050d1048508b247c1df/href</a></iframe><p>Apart from <strong>Of()</strong> and <strong>First(),</strong> there are a lot of <strong>Operators</strong> that I can’t explain in this story. But I am pretty sure that If you understand this basics, Then you can easily understand others as well. Find more useful <strong>Operators</strong> below.</p><p><strong>RxJS Operators:</strong> <a href="https://rxjs.dev/guide/operators">https://rxjs.dev/guide/operators</a></p><h4>5. Scheduler</h4><p>The <strong>scheduler</strong> is a control mechanism that takes care of, when a <strong>subscription</strong> starts and when the <strong>subscriber</strong> gets notified.</p><p>A <strong>Scheduler</strong> consists of the following components:</p><ol><li><strong>Data Structure</strong>: The scheduler knows how to store, arrange and queue the tasks based on their priority or any other ruleset.</li><li><strong>Execution Context</strong>: The scheduler can control whether the task should be executed immediately or should be passed into another mechanism as a callback.</li><li><strong>Virtual Clock</strong>: The tasks beings scheduled on a scheduler will follow the time that is denoted by the clock.</li></ol><p>If you don’t understand the <strong>Scheduler</strong> concept. Don’t worry, It is not that necessary to start <strong>Rx.JS</strong>. I am stopping here because I want to make this story as basic and clear as possible. Just have look at this code so you will have a basic idea of how the scheduler works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d51a40ddc6b477948c3df2e1235fdb1/href">https://medium.com/media/3d51a40ddc6b477948c3df2e1235fdb1/href</a></iframe><p><strong>RxJS Scheduler:</strong> <a href="https://rxjs.dev/guide/scheduler">https://rxjs.dev/guide/scheduler</a></p><h3>Conclusion</h3><p><strong>Rx.JS</strong> is the best library to build <strong>Asynchronous</strong> and <strong>Event-Driven</strong> Applications on Javascript. It is a standalone library so you can directly use it with any javascript framework or library. <strong>Rx.JS</strong> comes with Angular by default. In Angular, <strong>Rx.JS</strong> is very helpful to stream notifications and states across components.</p><p>I tried my best to keep this story <strong>beginner-friendly</strong>. I ignored the most confusing and advanced concepts. It is totally fine, If you understand what we discuss so far then you can start working on<strong> Rx.JS</strong> also you are capable of understanding advanced topics. Hope you find this useful.</p><p>Give few claps 👏, If you really like this.</p><p><strong>Happy Coding…</strong> ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9d780f85a7d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/rx-js-things-you-should-understand-before-start-d9d780f85a7d">Rx.JS — Things you should understand before start.</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[S3 Server Access Logging and Analyzing it on Athena (Part 2).]]></title>
            <link>https://medium.com/sliit-foss/s3-server-access-logging-and-analyzing-it-on-athena-part-2-578994a25dfc?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/578994a25dfc</guid>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[athena]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 17:16:47 GMT</pubDate>
            <atom:updated>2021-08-01T09:03:23.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QdCScFUekFUIUv3dnvCoQ.png" /><figcaption>AWS Athena(Source: <a href="https://miro.medium.com/">https://miro.medium.com/</a>)</figcaption></figure><p><strong>Heyo ✋,</strong></p><p>In <strong>part 1</strong>, We enabled <strong>Server Access Logging</strong> to our <strong>S3 bucket</strong>. In this story (part 2), We going to analyze/query the log information using <strong>Athena</strong>. Alright, Let’s start.</p><p><strong>Part1</strong><br><a href="https://badpiggie.medium.com/s3-server-access-logging-and-analyzing-it-on-athena-part-1-2eedad474afe">https://badpiggie.medium.com/s3-server-access-logging-and-analyzing-it-on-athena-part-1-2eedad474afe</a></p><h3>What is Athena?</h3><blockquote>Amazon Athena is an interactive query service that makes it easy to analyze data in Amazon S3 using standard SQL. Athena is serverless, so there is no infrastructure to manage, and you pay only for the queries that you run.<br> — AWS —</blockquote><p>In the last story, We just downloaded and opened a log file. The log has a lot of data, Therefor it’s really hard to filter or search for some details in a log file. Even if we successfully filtered data from a log file, We can’t do the same in all the log files. It’s really really hard to do.</p><p><strong>Athena</strong> helps use to fetch all the logs from <strong>S3</strong>, And query them using the well known and famous query language “<strong>SQL</strong>”.</p><p><strong>Yes, you read it right… It’s SQL.</strong></p><p>Basically, Athena greps the log data from the <strong>S3 Bucket</strong> and imports that information as a <strong>Table</strong>. After that, you can query that table using <strong>SQL</strong>.</p><h3>Getting Started with Athena</h3><p>Okay, Now go to <strong>Athena Console </strong>and set up it to query the <strong>S3</strong> logs that we created earlier in <strong>part 1</strong>.</p><h4>Create Query Result Location</h4><p>When you open Athena for the first time, You will see a notification that says to set up a <strong>query result location</strong>. Athena <strong>automatically saves</strong> the <strong>results</strong> and <strong>meta information</strong> of the queries that we execute. So basically we need to set up an <strong>S3 Bucket</strong> to store those details. That’s all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuIv8vBpuHeF31mvMuc5Hg.png" /><figcaption>Athena Query Screen</figcaption></figure><p>Just click on the link, It will open a popup. You can create a <strong>New</strong> <strong>S3 Bucket</strong> or <strong>Use an existing one</strong>. It’s totally up to you. <strong>But do not use any buckets that enabled access logging</strong>. Here I use a directory in the same bucket where I store logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5BRxcHLXsNP5qNAlRv-hxQ.png" /><figcaption>Set Up Query Result Location</figcaption></figure><p>Once you added the <strong>Query Result Location</strong>, We good to go. Just save it.</p><h3>Create Database</h3><p>In order to create tables to store logs, Obviously, we need a <strong>database</strong>. So let’s create a database. You just need to execute the regular <strong>SQL</strong> command to create the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W1H8JJ0hu0v-JPZZhUE3tg.png" /><figcaption>Create Database</figcaption></figure><p>Once your query is executed successfully. You can see the database on the left side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-HGIxqo5ghmrHKv7G8I8qw.png" /><figcaption>Database Selection Drop Down</figcaption></figure><h3>Create Table</h3><p>Now we have the database, All we need to do is, create a <strong>table</strong> to store the <strong>Log data</strong>. It’s a pretty <strong>huge SQL Command</strong>.</p><p><strong>Don’t worry you can find it here. </strong><br><a href="https://aws.amazon.com/premiumsupport/knowledge-center/analyze-logs-athena/">https://aws.amazon.com/premiumsupport/knowledge-center/analyze-logs-athena/</a></p><p>When you <strong>copy-paste</strong>, <strong>Don’t forget</strong> to change the <strong>table nam</strong>e and <strong>s3 bucket name</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mwk9cLf2_JTRqd78E9SrOw.png" /><figcaption>Create Table Query</figcaption></figure><p>At the end of this code, please make sure you specified the bucket where your logs are stored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlSV7CDbuN21U_rbp76xVQ.png" /><figcaption>Specify The Log Location</figcaption></figure><p>When you run this query, Athena will fetch all the logs from the location and put them on the table. You can see the is created with all the columns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1t1FmD3UeLoMr4EV5dVPGQ.png" /><figcaption>Table Structure</figcaption></figure><h3>Query The Log Data</h3><p>That’s all guys, Now all you have to do is just querying the data using <strong>SQL</strong>.</p><p><strong>Get all log data</strong></p><pre>SELECT * FROM my_bucket_logs;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OGhLpw1UAhJw8NdWZ3OTHQ.png" /><figcaption>Query Result | SELECT * FROM table</figcaption></figure><p><strong>Get all data that has 404 as the HttpStatus</strong></p><pre>SELECT * FROM my_bucket_logs WHERE httpstatus = &#39;404&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lum_8OC2knU7lSNyovuJbw.png" /><figcaption>Query Result | SELECT * FROM my_bucket_logs WHERE httpstatus = ‘404’;</figcaption></figure><p>That’s all, Now you can analyze the <strong>entire log information</strong> using <strong>SQL</strong>.</p><h3>Conclusion</h3><p><strong>Athena</strong> has a lot of features that we <strong>did not</strong> discuss here. Maybe in future, I will try to write some depth stories on <strong>Athena</strong>. One of the best features is, Importing data directly from S3 Bucket. Otherwise, we have to download whole logs and import them to analysis software.</p><p>Hope you guys learned something new here. Meet you guys soon with another story. If you like this story, Give a few 👏.</p><p><strong>With ❤️, Thank You!</strong></p><p><strong>Part1:</strong> <a href="https://badpiggie.medium.com/s3-server-access-logging-and-analyzing-it-on-athena-part-1-2eedad474afe">https://badpiggie.medium.com/s3-server-access-logging-and-analyzing-it-on-athena-part-1-2eedad474afe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=578994a25dfc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/s3-server-access-logging-and-analyzing-it-on-athena-part-2-578994a25dfc">S3 Server Access Logging and Analyzing it on Athena (Part 2).</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[S3 Server Access Logging and Analyzing it on Athena (Part 1).]]></title>
            <link>https://badpiggie.medium.com/s3-server-access-logging-and-analyzing-it-on-athena-part-1-2eedad474afe?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eedad474afe</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[athena]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Sat, 31 Jul 2021 17:16:17 GMT</pubDate>
            <atom:updated>2021-08-01T09:02:59.811Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oj4TtC6HWAvGWttTtKZsxg.jpeg" /><figcaption>AWS S3 Bucket (Source: <a href="https://miro.medium.com/">https://miro.medium.com/</a>)</figcaption></figure><p><strong>Heyo</strong> ✋,</p><p><strong>S3</strong> is one of the best services of <strong>AWS</strong>. When we talk about the <strong>S3 bucket</strong>, Most of us think that the <strong>S3</strong> is just a <strong>storage service</strong>. But it provides a lot of features such as <strong>Encryption</strong>, <strong>Multi-Part Upload</strong>, <strong>Logging</strong>, <strong>Versioning</strong>, Etc.</p><p>In this story, I am going to talking about <strong>S3 Server Access Logging</strong>. In <strong>part 2</strong> we will talk about “<strong>how to analyze s3 logs using Athena</strong>”.</p><h3>What is Access Logging &amp; Why?</h3><p><strong>Access Logs</strong> are keeping the track of the <strong>actions</strong>/<strong>requests</strong> that are made to your <strong>s3 bucket</strong>. When we use s3 buckets, The bucket will be facing a lot of actions.</p><p><em>For example:</em></p><ol><li>Some users will put an object.</li><li>Some users will access an object.</li><li>Some users will delete an object.</li><li>Some requests may be denied.</li><li>Some unauthorized users will try to get access into the bucket.</li></ol><p>Those actions are will be logged in detail when you use the access log. These logs are very very helpful to <strong>analyze</strong> the bucket <strong>behaviour</strong>, <strong>customer base</strong> also <strong>security audit</strong>.</p><h3>Enabling Access Logs</h3><p><strong>Enabling Access Logs</strong> is pretty straightforward in <strong>AWS</strong>. An Access Log file will be named in the following format.</p><pre><em>TargetPrefix</em>YYYY-mm-DD-HH-MM-SS-<em>UniqueString</em></pre><p><em>Example:</em></p><pre>logs/2013-11-01-21-32-16-E568B2907131C0C0</pre><p>Here <strong>logs/</strong> is the prefix (acting like a sub-directory). <strong>2013–11–01–21–32–16</strong> is the timestamp and <strong>E568B2907131C0C0 </strong>is a unique string.</p><p>Ok, Let’s enable Access Logging to an S3 Bucket.</p><h4><strong>Create a new bucket to store Logs.</strong></h4><blockquote><strong>This is very very important to note</strong>. You <strong>should not</strong> use the same bucket to store access logs. Because it may cause an <strong>infinite logging loop</strong> and cause <strong>massive data size</strong> and <strong>AWS billing</strong>. Then you need to sell your kidneys to settle the bill. LoL. 😜</blockquote><p><em>For example:</em></p><p>Let’s say you store <strong>access logs</strong> of <strong>Bucket A</strong> in the same bucket. Now, what will happen is, When a user put an image to <strong>Bucket A</strong>. It will create a <strong>new Log</strong>, But the Log file is also a <strong>new object</strong>, right? So <strong>S3</strong> will create <strong>another log</strong> for it. This will continue for each log file again and again. This is what we call an <strong>infinite logging loop</strong>.</p><p>So always store logs in different buckets and make sure the Bucket you store logs are <strong>not enabled</strong> the <strong>Server Logging. </strong>I have 2 buckets,</p><p><strong>codepiggie-bucket-a</strong> to store objects.<br><strong>codepiggie-bucket-a-logs</strong> to store the logs of <strong>codepiggie-bucket-a</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4oaf43UuK3Oq1rT3FDdExg.png" /><figcaption>S3 Bucket List</figcaption></figure><h4>Enable The Server Access Logging</h4><p>Now, <strong>select the bucket</strong> you need to enable server access logging and go to the <strong>properties</strong> tab. Then scroll down, You will find the section “<strong>Server Access Logging</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYjzM9_4wPZJ_r8dHLSTiQ.png" /><figcaption>Server Access Logging Section</figcaption></figure><p>Now, <strong>Click on Edit</strong>, And <strong>enable</strong> it. It will ask the <strong>Target Bucket</strong> to store the log file, Just click on the <strong>Browse S3</strong> button and select the bucket you created to store the logs. Then save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SqlAIzXroR_Cl2OBvhg2jA.png" /><figcaption>Serve Access Logging Set Up</figcaption></figure><blockquote><strong>NOTE:</strong> The <strong>Logs/</strong> prefix is optional. But <strong>don’t forget</strong> put <strong>trailing slash</strong> at the end</blockquote><p><strong>Done!</strong> That’s all, We <strong>enabled</strong> the <strong>Server Access Logging</strong> to our bucket. Now, Let’s check whether it’s working fine or not.</p><p>I’m going to upload an image file to my bucket and see whether the log is created or not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebpmhtLJZpNclhTRFkaaxQ.png" /></figure><p>I uploaded an image. Let’s check the log in the bucket that we configured to store logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uIb4ZLeK_gBcsJ5aiMfkAw.png" /></figure><p>As you can see, We found the logs in the log bucket. But you <strong>can’t see these logs immediately</strong>. It takes time to write logs. For me, <strong>it took 1 hour</strong>. But it’s not a problem, Because in most cases we won’t analyse s3 access logs in real-time.</p><h4>Log File Content</h4><p>These log files are just <strong>.txt</strong> files. So you can download and view any text editor. If you open a log file, It will look like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RtrtiDBKQ1q60_81Me0EwA.png" /></figure><p>A lot of details are there such as <strong>Bucket Name</strong>, <strong>Timestamp</strong>, <strong>Operation Type</strong>, <strong>HTTP Method</strong>, <strong>ARN</strong>, etc. Of course, It’s pretty much hard to read. But anyways, We will have a look at <strong>How to analyze these logs using Athena</strong> in <strong>part 2</strong>.</p><h3>Part 2</h3><p><a href="https://badpiggie.medium.com/s3-server-access-logging-and-analyzing-it-on-athena-part-2-578994a25dfc">S3 Server Access Logging and Analyzing it on Athena (Part 2).</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eedad474afe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JS: Async/Await in Array Methods]]></title>
            <link>https://medium.com/sliit-foss/js-async-await-in-array-methods-9142a35c6d6f?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9142a35c6d6f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[array-methods]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[async-functions]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Fri, 23 Jul 2021 09:28:30 GMT</pubDate>
            <atom:updated>2021-07-23T11:27:28.739Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jM0JJsrc2tw9NjX871xHhg.png" /><figcaption>Javascript Async Await</figcaption></figure><p><strong>Asynchronous Programming</strong> is one of the great features in Javascript. Before <strong>ES8</strong> we had <strong>Callbacks</strong>, <strong>Promises</strong> and <strong>Generators</strong> to handle it. But in <strong>ES8</strong>, Javascript introduced very short keywords called <strong>Async</strong> and <strong>Await</strong> to handle <strong>Asynchronous Executions</strong>.</p><p>In this story, I am going to explain the strange behaviour of <strong>Async</strong>/<strong>Await</strong> inside the <strong>Array Methods</strong> such as <strong>Map</strong>, <strong>Reduce</strong>, <strong>Filter, etc</strong>. I got the idea to write this article when I was answering a <a href="https://stackoverflow.com/questions/68479443/how-to-make-an-asynchronous-request-selectively-for-a-part-of-elements-when-walk/68479545#68479545">Stackoverflow Question</a>. Because Still, beginners are struggling to understand this concept.</p><p>Before start, I <strong>assume</strong> that you know the basics of <strong>Async/Await</strong>. Because In this story I will <strong>only</strong> talk about that particular strange behaviour. Okay, enough talking let’s move into the topic. 🚀</p><h3>The Basic Async/Await</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-XWXqEDITH_1s_Qx10AMQ.png" /><figcaption>Basic Async Await Usage</figcaption></figure><p>In the above code, You all can understand that we have an <strong>async function</strong> to convert a string to uppercase. The <strong>main</strong> function will call the function <strong>convertToUpperCase</strong> with the <strong>await</strong> keyword. Because we are waiting for the function to convert it so we can print it in the console. It will print output as you expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ugdTRujV8rk2v-s0TmYBw.png" /><figcaption>Basic Async Await Usage Response</figcaption></figure><p>All fine so far right. But what If we do the same thing inside an array method <strong>map()</strong> or <strong>forEach()</strong>?</p><h3><strong>Async / Await in Map()</strong></h3><p>Now we have an <strong>Array</strong> of words <strong>[“orange”, “apple”, “mango”]</strong>. Now we need to convert all the words to <strong>uppercase</strong>. So we need to take each word from an array using <strong>map()</strong> then update each word by passing it to the <strong>convertToUpperCase()</strong> method with the <strong>await</strong> keyword. So it will convert all the words <strong>one by one</strong>. Finally, we will have an <strong>Array</strong> of <strong>uppercased words</strong>.</p><p>Ok, Let’s do it and see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNLeXh4KkwZ71Mjo5i3JjA.png" /><figcaption>Async Await in Map()</figcaption></figure><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ompht2THKg2bma1Q94_Blw.png" /><figcaption>Array of Promises</figcaption></figure><p>But if you see the output, We <strong>did not</strong> receive the expected results. The <strong>map()</strong> method returned an <strong>Array of Promises</strong> instead of an <strong>Array of Strings</strong>. <br><strong><em>Why? </em></strong>🙄</p><p>You may say that we passed an <strong>async</strong> method inside the <strong>map()</strong>, So we need to use <strong>await</strong> in front of it like below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5yNJx89w47rbQvggAAUchw.png" /><figcaption>map() with the await keyword</figcaption></figure><p>But <strong>nope</strong>. Still, the Same result. 😞</p><p><strong>Then what is the exact problem? <br>Why is this returning Promise even if we use await?</strong></p><h3>The Reason</h3><p>First, remember these 2 key points about <strong>Async</strong>/<strong>Await</strong></p><ol><li>The<strong> async function</strong> will return a <strong>Promise</strong> itself.</li><li>You <strong>cannot</strong> use <strong>await</strong> inside a <strong>normal function</strong>.</li></ol><p>As we saw above, The <strong>async functions</strong> always return <strong>promise</strong> unless you call it with the <strong>await</strong> keyword. But to use <strong>await</strong> keyword, The <strong>parent function</strong> also should be an <strong>async function</strong>.</p><p>Let’s have look at our scenario. The function <strong>convertToUpperCase()</strong> is an <strong>async function</strong>. So it will return a <strong>Promise</strong>. But we want an final string value, So we are using <strong>await</strong> when calling the <strong>convertToUpperCase()</strong> method. Also, We <strong>cannot use await</strong> inside a <strong>normal function</strong>. So our <strong>callback function</strong> should be an <strong>async function</strong>.</p><p>Now take the <strong>map()</strong> method. The <strong>array methods are not async functions</strong>. They are <strong>normal functions</strong>. So when we pass an <strong>async function</strong> as a <strong>callback</strong>, It <strong>will not invoke</strong> the <strong>async callback</strong> function with <strong>await</strong>. So the output result will be a <strong>Promise</strong>.</p><p>This is why we are getting <strong>3 Promises</strong> instead of <strong>3 string values</strong>.</p><h4>So what is the solution? Can’t we use async/await inside Array Methods?</h4><p>Don’t worry you can. 😋</p><h3>Promise.all()</h3><p>The job of <strong>Promise.all()</strong> is taking an <strong>Array of Promises</strong> and return values after all the promises are resolved.</p><p>In our case, We got an <strong>Array of Promises</strong> right? So here <strong>Promise.all()</strong> will help us to extract the resolved values from the <strong>Array of Promises</strong>.</p><p><strong>NOTE:</strong> <em>Please remember that the </em><strong><em>Promise.All()</em></strong><em> will return a single </em><strong><em>Promise</em></strong><em>. So we need to use </em><strong><em>await</em></strong><em> to get the actual value.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VxqmVDDzo2h4icArVo8OwA.png" /><figcaption>Promise.all() solution for array of promises</figcaption></figure><p><strong>The Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPOFkNBVzBjlKG1YQpN3PQ.png" /><figcaption>The array of string | The final expected output</figcaption></figure><p><strong>Oh, yeah!</strong> Now we got the exact output that we wanted. 🥳</p><h3>Conclusion</h3><p>Not only for the <strong>map()</strong> method. You can apply the above way to solve these kinds of issues in <strong>all array methods</strong> and other functions that do not handle <strong>async callbacks </strong>with<strong> await</strong>.</p><p>If you are new to <strong>Promise</strong>, <strong>Async</strong> and <strong>Await</strong>. I am pretty sure it might be so confusing. But don’t worry, It happens. I strongly recommend you to study some basics of <strong>asynchronous javascript</strong> and do some <strong>hands-on</strong>. I will provide some useful links below.</p><p>If you find this story helpful, Please give some 👏 and feel free to correct me if I did any mistakes.</p><p>Thank you.</p><ul><li><a href="https://javascript.info/promise-basics">Promise</a></li><li><a href="https://javascript.info/async-await">Async/await</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9142a35c6d6f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/js-async-await-in-array-methods-9142a35c6d6f">JS: Async/Await in Array Methods</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript: Is “ES-6 Class” a lie? ]]></title>
            <link>https://medium.com/sliit-foss/javascript-is-es-6-class-a-lie-4c28f5db22d?source=rss-4241558f7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c28f5db22d</guid>
            <category><![CDATA[prototyping]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[class]]></category>
            <dc:creator><![CDATA[Banujan Balendrakumar]]></dc:creator>
            <pubDate>Mon, 19 Jul 2021 20:51:53 GMT</pubDate>
            <atom:updated>2021-07-19T21:35:51.186Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dmdr9kc0T5LDSpTj3MEdOA.jpeg" /><figcaption>Javascript: (source: <a href="https://www.creative-tim.com/blog/content/images/wordpress/2019/10/The-Top-10-Javascript-Frameworks.jpg">https://www.creative-tim.com</a>)</figcaption></figure><p>We all know that Javascript is awesome. But also it is weird. When we compare some concepts, In javascript those are useless just like “Infinity Stones 💎 in Sacred Timeline 🪄”.</p><p>Okay! So in this story, I am going a talk about one of the strangest things in javascript called “<strong>Classes</strong>”.</p><h3>Objects in Javascript</h3><p>Javascript is not like other languages, It treats pretty much everything as an <strong>object</strong>. Let’s create a simple object and inspect it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HNV8RZVu-X2mxnyRPZXGTg.png" /></figure><p>As you can see, We just created an object with a simple method. But when we inspect it, We can see some strange things are there. Especially the property <strong>__proto__</strong>.</p><p><strong><em>What the hell is that? </em>🤨<em> Where does it come from? </em>🙄</strong></p><h3>Prototypes</h3><p>Javascript is <strong>not</strong> a <strong>class-based object-oriented</strong> language. Instead, it’s a <strong>prototype-based</strong> language. This means Javascript uses a mechanism called <strong>Prototype</strong> to provide the <strong>inheritance</strong> between objects.</p><p>Let’s create an object using Prototypes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VoiUsfN-_hk_uKZCTiltpQ.png" /></figure><p>Look at the image. This time we did not define a method <strong>tap()</strong> inside the object. Instead, We define it inside the <strong>__proto__</strong> property. But still, we can call it in the usual way.</p><p><em>Basically, Prototypes are templates of an object which describe the properties and abilities of the object.</em></p><h4>Why Prototypes?</h4><p>OK. If the <strong>prototype</strong> does the same thing as the <strong>basic literal</strong>, Then why should we use the prototype?</p><p>Well, The answers are,</p><ol><li><strong>Keep the object definitions in the centralized position.</strong></li><li><strong>Share methods between objects via inheritance.</strong></li></ol><p><strong>Centralized Position</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FfjXsZ0_Fa8zsfhGy61dKQ.png" /></figure><p>See the above image. We created a “<strong>Dog</strong>” constructor method. Then prototyped a method “<strong>bark</strong>” which prints “<strong>Woaw, Woaw</strong>”. So when we called the method on both objects “<strong>jimmy</strong>” and “<strong>puppy</strong>”, It printed the message as we expected.</p><p>After we update the <strong>bark</strong> method to print “<strong>Meow, Meow</strong>”, We <strong>did not re-initialize</strong> objects from the ‘<strong>Dog</strong>’. But the method of both objects got updated automatically. <em>Why is that?</em></p><p>Because <strong>Prototypes</strong> are keeping definitions in the <strong>common space</strong> and give access to its objects. So when we change the prototyped methods, It will affect the existing objects instantly. So even if we create <strong>10000 objects</strong>, Those will not get any dedicated method. This behaviour saves <strong>memory</strong> in the <strong>run-time</strong>.</p><p><strong>Inheritance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ZuXE3STmGBZwXZYuDxc0w.png" /></figure><p>In the above image, You can see that we created <strong>Dog’s</strong> <strong>prototype</strong> object from the <strong>Animal’s prototype</strong> object. So now the <strong>Dog</strong> has all the power of the <strong>Animal</strong>. In other words <strong>Parent-Child </strong>behaviour.</p><p>If we inspect the <strong>puppy</strong> object, It will look like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pgZelaRnbqEjBXwH8C6Pcw.png" /></figure><p>As you can see, The <strong>Dog</strong> has a <strong>__proto__</strong> of <strong>Animal</strong>, And it has another <strong>__proto__</strong>. Inside the second <strong>__proto__</strong> there is another <strong>__proto__</strong> of <strong>Object</strong>.</p><p>This is how the prototypes are being inherited through the objects. This is called the “<strong>prototype chain</strong>”.</p><p><strong><em>I hope, Now you got an idea about Prototypes. Let’s move to Classes.<br>🏃‍♀️️️️🏃‍♀️🏃‍♀️</em></strong></p><h3>Classes</h3><p>The <strong>Class</strong> was introduced in <strong>ECMA Script 2015</strong> aka <strong>ES6</strong>. Before talking further about classes, let’s have a hands-on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sV7Ttqsr2_5zTJJ4O-tB8g.png" /></figure><p>I just created a simple class and its object. But still, it has property <strong>__proto__</strong>. It looks exactly the same as the object that we created using the <strong>prototype</strong>.</p><p>OK, One more test. 🧪</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0FWwfzNEO4UG3Ev50GIpw.png" /></figure><p><strong>WTF</strong>! 😱😱😱😱 It looks exactly the <strong>same as prototyping</strong>.</p><p>That’s true. Classes are not giving anything new to javascript. <strong>It is just a syntactic sugar built on top of the existing prototyping mechanism</strong>. So There is <strong>no difference between Classes and Prototypes</strong>. Classes are just a modern syntax to do the exact same thing but it gives the look that javascript is more <strong>object-oriented</strong>.</p><h3>Conclusion</h3><p>When someone learns javascript with other language backgrounds, They really mess with <strong>Prototypes</strong>. Because they are much familiar with <strong>classes</strong>, <strong>interfaces</strong> and etc. So the Javascript introduced Classes to give familiar syntaxes. But it <strong>did not </strong>change any mechanism. It still uses <strong>prototyping</strong>.</p><p>You can take <strong>prototypes</strong> and <strong>classes</strong> like <strong>girls</strong> and <strong>girls with makeup</strong>. <br>Lol…. 😂😂</p><p>In other words, What javascript says is <strong>“Hey bruh, I don’t care whatever you do with Classes. But I still use the same sh💩t behind the scenes.”</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c28f5db22d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sliit-foss/javascript-is-es-6-class-a-lie-4c28f5db22d">Javascript: Is “ES-6 Class” a lie? 🤔</a> was originally published in <a href="https://medium.com/sliit-foss">SLIIT FOSS Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>