<?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 Channa Jayamuni on Medium]]></title>
        <description><![CDATA[Stories by Channa Jayamuni on Medium]]></description>
        <link>https://medium.com/@hjchanna?source=rss-802a1ceda6a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-e5YiQFU9wlT-8WF92qJFQ.jpeg</url>
            <title>Stories by Channa Jayamuni on Medium</title>
            <link>https://medium.com/@hjchanna?source=rss-802a1ceda6a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 21:25:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hjchanna/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[React.js docker: A 20 minute weight loss exercise — 1.3GB to 25MB]]></title>
            <link>https://medium.com/@hjchanna/react-js-docker-a-20-minute-weight-loss-exercise-1-3gb-to-25mb-ff10269fc4ff?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff10269fc4ff</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Fri, 06 Sep 2019 08:31:01 GMT</pubDate>
            <atom:updated>2019-09-06T08:31:01.089Z</atom:updated>
            <content:encoded><![CDATA[<h3>React.js docker: A 20 minute weight loss exercise — 1.3GB to 25MB</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSxOOoK-1sTy_fkYD95APA.png" /></figure><p>Recently I was troubleshooting a deployment issue in a <strong>React.js</strong> frontend application, in a shopping cart platform. The shopping cart platform was deployed in a Kubernetes cluster and the docker images were hosted in <strong>DockerHub</strong>. During the investigation of the issue, I noticed that the <strong>React.js</strong> application’s docker images were unusually heavy and it was over 1GB in size, which is not fair for a simple <strong>html</strong> frontend application. It was also an overhead to troubleshoot the issue. This meant taking quite a long time to stream the docker image through the network whenever pulling and pushing from/to the docker registry. I found out that it is important to keep docker images small, which would help to efficiently transfer docker images through the network. And most importantly reduces the spin-up time of docker containers when starting the platform as well as error in resiliency of the platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uGq_efQ3FLb8WqiE" /><figcaption>Figure 01: Docker images built from different approaches</figcaption></figure><p>The shopping cart frontend application was implemented on <strong>Node.js</strong> 10 and <strong>React.js</strong> frontend framework. My first impression was that the shopping cart’s docker image was built on the node:10 base image with similar configurations to that of the development environment. It was exactly 1.29 GB in size (Image ID: 2df0a7352deb).</p><p>I realized that the docker image needed some improvements to make it production ready. Which made me google “How to build <strong>React.js</strong> production docker images”. There were plenty of articles explaining different approaches and steps to build production docker images. Most of them were targeted at using the <strong>Node.js-alpine</strong> docker image as the base image which is the smallest distribution of the <strong>Node.js</strong> 10 (Docker alpine images are built on top of Alpine Linux which is a micro-sized linux distribution, purpose-built for docker images or small container-like uses. Alpine Linux docker image itself is only around 4–5 MB in size). The next steps were copying source files into the docker image, downloading and then installing <strong>Node.js</strong> dependencies through <strong>npm</strong> (<strong>Node.js</strong> Packaging Module). Finally using the “<strong>npm start</strong>” command to start the <strong>Node.js</strong> server. After reading several articles on this same topic, and referring to official documentation, I ended up with the following <strong>Dockerfile</strong>:</p><pre># Use an official node runtime as a parent image<br><strong>FROM node:10-alpine</strong></pre><pre># Set the working directory to /home/app<br><strong>WORKDIR /home/app/</strong></pre><pre># Bundle app source<br><strong>COPY . /home/app/</strong></pre><pre># Install project dependencies<br><strong>RUN npm install</strong></pre><pre># Make port 3000 available to the world outside this container<br><strong>EXPOSE 3000</strong></pre><pre># Start the node server<br><strong>CMD npm run start</strong></pre><p>After all, I was able to reduce the docker image size to 458MB, which is a huge improvement ( over sixty percent (60%)) of memory savings (Image ID: 2344284b5bc6). However, I was still not happy to leave it at nearly 450MB for such a simple <strong>React.js</strong> app. I kept looking for alternative ways to make the docker image smaller and tried with “<strong>npm install — production</strong>” which doesn’t install <strong>Node.js</strong> dev-dependencies. It didn’t do a lot, and just decreased the docker image size to 398MB, saving only 60MB (Image ID: 0196a6a983d7).</p><p>Finally I tried the react-scripts’ built-in build command (<strong>react-scripts build</strong>) which compiles the <strong>React.js</strong> source code into a simple <strong>html-javascript</strong>. However, it doesn’t have the ability to run as a server, and only has the web application. So I had to deploy the <strong>html-javascript</strong> output in a web server. I selected <strong>Nginx</strong> which is my favorite web server and the load balancer as the underlying server of the web application. <strong>Nginx</strong> also distributes an Alpine docker image which is only 21 MB in size, which was a great motivation to go for <strong>nginx-alpine</strong> as the base docker image.</p><pre># Use nginx-alpine as the parent image<br><strong>FROM nginx:alpine</strong></pre><pre># Copy html-javascript output files to nginx<br><strong>COPY ./build /usr/share/nginx/html</strong></pre><pre># Make port 80 available to the world outside this container<br><strong>EXPOSE 80</strong></pre><pre># Start nginx<br><strong>CMD [“nginx”, “-g”, “daemon off;”]</strong></pre><p>I was elated to find that the final docker image was just 25.1 MB (Image ID: 3ae9f41a69f3), just around two percent (2%) of the initial docker image size, which is ninety eight percent (98%) saving!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff10269fc4ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developers’ best friend — How to adopt a pet project]]></title>
            <link>https://medium.com/@hjchanna/developers-best-friend-how-to-adopt-a-pet-project-4fb526bc4274?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fb526bc4274</guid>
            <category><![CDATA[pet-project]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Fri, 23 Aug 2019 12:45:15 GMT</pubDate>
            <atom:updated>2019-08-23T13:18:04.845Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developers’​ best friend; adopting a Pet project (Part — 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ss87SztKPxdv-ulo1_5gLw.jpeg" /></figure><p>It is the dream of every software developer to work on a pet project, in between their regular job. I am sure most of you have <strong>brilliant ideas</strong> for a new project. But, most of those ideas <strong>don’t convert</strong> into anything more. At most times, it is the <strong>motivation</strong> or the “<strong>lack of time</strong>” to engage in such an activity.</p><blockquote>Note: <br>The general idea of a pet project is a leisure time project worked on by a software developer or a group of developers with the intent to create a tangible outcome, which is properly maintained, and also would provide value for a long time.</blockquote><h3>WHY PET PROJECTS ARE SO IMPORTANT?</h3><p>The fact holds true, <em>“software development is the most enjoyable profession until the developer gets his favorite tasks”</em>. If you are not working for Google, or a similar company with fancy projects and low-stress, we can’t expect exciting works. In most cases, it is a mixture of <strong>mundane</strong> and <strong>somewhat fun</strong> to do work <em>(although most would feel that it is all dull, at most times !)</em>. It is also difficult to start <strong>experimenting</strong> whilst working on a professional project. Not everyone is fortunate to work with <strong>cutting-edge technologies</strong> in professional environments, and rarely gets the opportunity to <strong>stay current and updated.</strong></p><p>If you’re not sure when to start a pet project, then the factors I indicated above will signal to you that it’s the right time to buckle and get started. Else, get left behind both technical know-how and also looming under regret. Everyone agrees that information technology is the most <strong>evolving industry</strong>. Software developers and IT professionals should continually <strong>improve</strong> their knowledge to compete with the <strong>challenging job market</strong>. It may seem too much of a burden to keep a track of <strong>evolving technologies</strong> during your leisure time. That is the beauty of starting a pet project as a leisure time activity, it will aid in your software developer career and bring some excitement to an otherwise mundane routine.</p><p>Pet projects can open doors to <strong>experiment and learn</strong> new stuff and most importantly gives control over the project objectives and technologies which support the developer to gain an experience by working on with different <strong>business use-cases</strong> and <strong>technologies</strong>. And also help the developer <strong>stay updated</strong> with the <strong>latest technologies</strong> in a stress-free manner. Pet projects bolds <strong>personal recognition</strong> as a talented software developer and the professional development is not only the benefit of pet projects. They can welcome new <strong>business opportunities</strong> and can help earn some <strong>additional revenue</strong>. I will delve into this aspect more in a later section.</p><h3>HOW TO START A SUSTAINABLE PET PROJECT?</h3><p>Starting a new project is easy — as easy as creating a new project in your favorite IDE. But <strong>starting a sustainable pet project</strong> is quite tricky. A good pet project, just like a solid building has a strong foundation <em>(A software project is not something you should just attempt and throw away. It should consistently provide a long term value).</em></p><p>The first thing is you need to have an <strong>appetite</strong> for the project. Whatever the project objective, or whatever the benefit, you won’t be able to sustain it unless you have an appetite for the project. It is important to pick an idea that will result in something that you, personally will love. Naturally, you will like the process as you progress towards that desired outcome.</p><p>You need to agree; the foundation of any project is the idea (or the project objective or goal). The key idea adds a good value into the project and defines the sustainability. So don’t start a pet project just for the heck of it. It is necessary to spend time <strong>researching</strong> the project objective without just jumping into development. You need to make sure your idea is <strong>unique</strong> and also fits into a <strong>market requirement</strong> in your favorite business domain. And most probably a unique idea leads to new <strong>business opportunities</strong> which could potentially <strong>generate a good income</strong> in future.</p><p>I assume you have been in project planning sessions in your professional environments. It might be days of battle between clients, architects and the development team to agree on one simple use-case. I don’t think it is necessary to put such an effort on the design of your pet project since you are playing the roles of all the stakeholders. But it is important to be clear on several things to make it stronger the <strong>foundation</strong> of your pet project. The first thing is <strong>being clear</strong> on what your pet project should have in both <strong>functional</strong> and <strong>non-functional</strong> aspects. In that case, you need to breakdown the project objective into <strong>smaller pieces</strong> and identify what are the main <strong>components</strong> of the pet project. You can sketch a <strong>high-level design</strong> or a <strong>mind-map</strong> to easily <strong>analyze</strong> your projects’ objectives. Once you have identified the main components, you need to <strong>focus</strong> and <strong>logically think</strong> interactions and behaviour of each component. It is the time to release your hidden architect! Include component interactions, endpoints, protocols, deployment information or whatever you feel is important in the high level design or the mind-map. When your design is logically satisfying, it is the time to <strong>document</strong> your decisions. Documentation are important to <strong>communicate</strong> your ideas with others without losing as well as protecting your valuable ideas getting lost by your day-today busy life. I don’t expect the documentation to be fully descriptive and include end-to-end scenarios, but it is necessary to mention the <strong>important components</strong>, use-cases, and most <strong>important decisions </strong>you made in the design. And make sure to <strong>keep the document valid and updated</strong>. Modify the document to reflect whatever the design change you would make in future.</p><blockquote><em>Note: <br>You can use your favorite document editor for the project documentation. Personally I use </em><strong><em>Google Drive</em></strong><em> with </em><strong><em>Google Docs</em></strong><em> and </em><strong><em>Google Sheets</em></strong><em> more often. Google products are freely available, portable, and gives me the freedom to collaborate with my team. And also I never forget to document the important things in the readme, and wiki section of the projects’ repository.</em></blockquote><blockquote><strong><em>Draw.io</em></strong><em> is an online free tool to compose diagrams, personally I sketch diagrams on paper. But I prefer </em><strong><em>Draw.io</em></strong><em> when I need to share a diagram with someone else.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sthzz5uF2Xxn5GtdNte0wg.jpeg" /></figure><p>Once you completed the high-level design, you can get started on the <strong>skeleton</strong> project. The skeleton project is a <strong>top-down</strong> approach which helps to implement features quickly and makes it easy to dive deep into specific features. It is not necessary to implement everything in the skeleton, but a high-level implementation with placeholders for future add-ons are more than enough. You can leave implementation with <strong>“TODO:”</strong> comments which could easily track with modern IDEs. However it is important to consider several different aspects of the project such as the <strong>build system</strong>, unit and integration <strong>testing</strong>, <strong>logging</strong>, <strong>release</strong>, and important decisions made in the design phase. I will delve into the “why” and the “how” of build system, CI/CD, testing, logging and release in a later section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rClI901DrB9NASRpJZd_nA.png" /></figure><p>Starting a sustainable pet project is tricky! Writing an article on this topic is even worse. I need to cover <strong>“How to maintain a pet project”</strong>, <strong>“How to get the maximum out of time”</strong>, <strong>“How to stay motivated”</strong> and much more in technical, management, and psychological point of view. I would like to continue the rest into the next episode of the series and stop this article being so long for reading <em>(to be honest with you; I didn’t have enough time to work on this since I was busy with a product release in the last week)</em>. Please like and share this article and also I would like to hear from you. Please write your suggestions in the comment section below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fb526bc4274" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developers’ Girlfriend, the terminal -Let’s make her more beautiful and interactive (MacOS)]]></title>
            <link>https://medium.com/@hjchanna/developers-girlfriend-the-terminal-make-it-more-beautiful-and-interactive-macos-68991820d8e7?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/68991820d8e7</guid>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[iterm2]]></category>
            <category><![CDATA[zsh]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Fri, 16 Aug 2019 11:01:26 GMT</pubDate>
            <atom:updated>2019-08-16T11:09:29.345Z</atom:updated>
            <content:encoded><![CDATA[<h3>Developers’ Girlfriend, the terminal —Let’s make her more beautiful and interactive (MacOS)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BH15PUe2RVOlreJXjL3YeA.png" /></figure><p>The ugly truth is mostly I spend the time with the terminal over with my girlfriend. It can’t be hidden; it is my first love and she goes to the second. I am a very good lover of <strong>iTerm.2</strong>, which the best alternative terminal emulator for <strong>MacOS</strong>. But I wanted <strong>iTerm</strong> to be more beautiful and eye-catchy with a minimal design theme, similar to the <strong>Hyper</strong>. Why I don’t say <strong>Hyper</strong> is the best terminal emulator for Mac?, because it doesn’t have the flexibility over configurations which <strong>iTerm.2</strong> offer by default (or even <strong>Terminator</strong> does for <strong>Linux</strong>). Also <strong>Hyper</strong> is bit weighty and not running smoothly since it is developed on top of Electron, a NodeJs desktop application framework which enables web applications to run as desktop applications.</p><blockquote><strong>Every cloud has a silver lining:</strong> I don’t really mean that the <strong>Hyper</strong> is the worse. It could be better in certain ways such as the availability for various operating systems, colorful UI, Javascript like configuration, and etc.</blockquote><p>It was an exciting news, the latest <strong>iTerm.2 </strong>version<strong> </strong>3.3 released incorporating stunning and brand new features including the customizable Status Bar, Minimal theme and also Python scripting facilities. That was something I was waiting for in last few years, and I directly switched to the Minimal theme right after <strong>iTerm2 v3.3</strong> got released.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IK2dStSyRPKDazEdDFDJqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dgeaaPB0FtZuutfLEXjx-A.png" /></figure><p>I have played enough with many of the shell variants, <strong>Bourne Shell (SH)</strong>, <strong>Bourne Again Shell (BASH)</strong>, <strong>Friendly Interactive Shell (FISH)</strong>, and etc. But nothing was even closer to the <strong>“Oh-my-zsh” (ZSH)</strong>, which is a community driven, open-source, and also comes with thousands of functions, helpers, plugins and themes. That’s why I would like to name it as the next generation of the <strong>shell</strong>. <strong>ZSH</strong> has got a massive amount of community developed plugins to make the terminal life more easier. Especially for developers it has nice plugins for git, docker, kubernetes, and syntax highlighting which make developers to die for <strong>ZSH</strong>.</p><p><strong>ZSH</strong> also has over 125 in-built themes and also it is possible to modify or create your own theme and plug into the <strong>ZSH</strong>.</p><blockquote><strong>Oh-my-zsh</strong> is a nice interactive terminal for users. However it comes with in-build plugins and add-ons, which makes the distro comparatively bigger and also <strong>ZSH</strong> is bit weighty in the runtime. So <strong>ZSH</strong> is not recommended as a server-side, or a containerized shell. Please use a light-weight shell alternative (such as Bourne Shell — SH) for such purposes.</blockquote><p>I don’t think it is necessary to introduce <strong>VIM</strong>, the most popular terminal based text editor. You may find it is hard to get stand with <strong>VIM</strong> because its’ tricky behaviour. And also it is very funny, one of the popular <strong>stackoverflow</strong> question was <a href="https://stackoverflow.com/questions/11828270/how-do-i-exit-the-vim-editor">“How do I exit the Vim editor?”</a>. <strong>VIM</strong> is that confusing for first-time users. But I bet, you can’t live without <strong>VIM</strong>, once you got used to it.</p><p><strong>VIM</strong> also got hundreds of plugins such as syntax highlighers, status bars, tabbed bars, file trees, code linters, which make <strong>VIM</strong> more applicable to software development, server administration and dev-ops works.</p><p>In this article, I would like to walk you through the configurations and plugins of <strong>iTerm.2</strong>, <strong>ZSH</strong> and <strong>VIM</strong> to create a colorized and more interactive terminal as displayed in the attched images.</p><h3>TL;DR</h3><h3><strong>1. INSTALLING iTERM.2 LATEST VERSION</strong></h3><p>Download iTerm from the offical release website. You also may find the installation guide on the website.</p><p><a href="https://www.iterm2.com/version3.html">Version 3 - iTerm2 - macOS Terminal Replacement</a></p><h4>1.1. ENABLING THE MATERIAL THEME ON iTERM.2</h4><p>1.1.1. Open iTerm and open the preferences window.</p><pre><strong>iTerm2 -&gt; Preferences</strong></pre><p>1.1.1. Switching to the Minimal theme.</p><pre><strong>Appearance -&gt; Theme -&gt; Select Minimal Theme</strong></pre><h4>1.2. ENABLE AND MODIFY iTERM.2 STATUS BAR</h4><p>1.2.1. Enable status bar through preferences.</p><pre><strong>iTerm2 -&gt; Preferences -&gt; Profiles -&gt; Session</strong></pre><pre>AND THEN</pre><pre><strong>Check the &quot;Status Bar Enabled&quot; checkbox</strong></pre><p>1.2.2. Configure the status bar</p><p>Click the &quot;Configure Status Bar&quot; button in the session window, and it will open a Status Bar Component menu. You can drag-drop available components into the Active Components section. You also can configure the status bar by “Advanced…” dialog and each component by “Configure Component” dialog. The “Auto Rainbow” button colorizes each component match rainbow colors.</p><pre># my favorite status bar component order:<br><strong>[/Users/hjchanna][_master][|~~|][vim&lt;bash][|-|][example.com][hjchanna]</strong></pre><h3>2. INSTALLING AND CONFIGURING Z-SHELL (ZSH)</h3><p>Download and install z-shell from official website and you also will find installation guides in the official website.</p><p><a href="https://ohmyz.sh/">Oh My Zsh - a delightful &amp; open source framework for Zsh</a></p><blockquote>You also can use Homebrew, a handy package manager to install ZSH. Download Homebrew from the release site (<a href="https://brew.sh/">https://brew.sh</a>)and run brew install zsh to install ZSH.</blockquote><h4>2.1. SET ZSH AS iTERM.2 DEFAULT SHELL</h4><p>You may need to set zsh as the default shell for iTerm2.</p><pre><strong>iTerm2 -&gt; Preferences -&gt; Profiles -&gt; General</strong></pre><p>Change the “Command” to:</p><pre><strong>/bin/zsh</strong></pre><p>Now restart the iTerm.2 and it will start with zsh as default shell.</p><h4>2.2. CONFIGURE Z-SHELL</h4><p>2.2.1. Basic ZSH configurations</p><p>Similar to bash’s configuration script (~/.bash_profile), ZSH also has a configuration script at ~/.zshrc which is used to configure the zsh behaviour. Open ~/.zshrc and make following changes.</p><pre># uncomment following line if you recently migrated to zsh from bash<br><strong>export PATH=$HOME/bin:/usr/local/bin:$PATH</strong></pre><pre># add following line into the bottom of the .zshrc. It will keep <br># your shell configuration (like environment variables)<br># in the zsh<strong><br>source ~/.bash_profile</strong></pre><p>2.2.2. ZSH Themes</p><p>ZSH comes with in-built themes by default, and also you can install a custom made themes into ZSH. ZSH themes are located in ~/.oh-my-zsh/themes directory and it is configurable through the ~/.zshrc.</p><pre># set zsh theme by changing following line<br><strong>ZSH_THEME=&quot;jreese&quot;</strong></pre><p>You may find your favorite ZSH theme from ZSH GitHub repository.</p><p><a href="https://github.com/robbyrussell/oh-my-zsh/wiki/Themes">robbyrussell/oh-my-zsh</a></p><p>2.2.3. ZSH Plugins</p><p>ZSH also has installable plugins which extends its’ capability. ZSH plugins are located at ~/.oh-my-zsh/plugins directory and plugins are configurable through ~/.zshrc.</p><pre># add plugins into the plugin section of .zshrc<br><strong>plugins=(<br>    git<br>    zsh-syntax-highlighting<br>    zsh-autosuggestions<br>)</strong></pre><p>zsh-syntax-highlighting and zsh-autosuggestions are some of my favorite zsh plugins which requires to manually install.</p><ul><li><em>zsh-syntax-highlighting</em></li></ul><p><a href="https://github.com/zsh-users/zsh-syntax-highlighting">GitHub - zsh-users/zsh-syntax-highlighting: Fish shell like syntax highlighting for Zsh.</a></p><pre># cloning the zsh-syntax-highliting<strong><br>git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting</strong></pre><pre># enable zsh plugin<br># add zsh-syntax-highliting into .zshrc<br><strong>plugins=(<br>    ...<br>    zsh-syntax-highlighting<br>    ...<br>)</strong></pre><ul><li><em>zsh-autosuggestions</em></li></ul><p><a href="https://github.com/zsh-users/zsh-autosuggestions">GitHub - zsh-users/zsh-autosuggestions: Fish-like autosuggestions for zsh</a></p><pre># cloning the zsh-autosuggestions<br><strong>git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions</strong></pre><pre># enable zsh plugin in the .zshrc<br><strong>plugins=(<br>    ...<br>    zsh-autosuggestions<br>    ...<br>)</strong></pre><h3>3. INSTALLATION AND CONFIGURATION OF VIM</h3><p>You can easily download vim through the Homebrew or alternative distributes are available at https://vim.org</p><pre>brew install vim</pre><h4>3.1. VIM CUSTOMIZATION</h4><p>There are a massive amount of VIM Plugins available to make VIM even better. However it would take days to find, install and configure better plugins for the vim. The Ultimate Vim Configuration repository enables to install and config vim in a snap.</p><pre># clone ultimate vim configuration repository<br><strong>git clone --depth=1 </strong><a href="https://github.com/amix/vimrc.git"><strong>https://github.com/amix/vimrc.git</strong></a><strong> ~/.vim_runtime</strong></pre><pre># install ultimate vim configurations<br><strong>sh ~/.vim_runtime/install_awesome_vimrc.sh</strong></pre><h3>SUMMARY</h3><p>I hope you enjoyed configuring iTerm.2 along with ZSH and VIM and I know it’s fun to work with a beautiful and colorized terminal. Please clap for the article and also I would like to hear to your suggestions and improvements to the article. Please write me hjchanna@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68991820d8e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in WSO2 API Microgateway 3.0]]></title>
            <link>https://medium.com/@hjchanna/whats-new-in-wso2-api-microgateway-3-0-93711d5bf278?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/93711d5bf278</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[api-management]]></category>
            <category><![CDATA[microgateway]]></category>
            <category><![CDATA[wso2-api-manager]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Sun, 11 Aug 2019 04:19:45 GMT</pubDate>
            <atom:updated>2019-08-11T08:57:57.404Z</atom:updated>
            <content:encoded><![CDATA[<h3>What’s new in WSO2 API Microgateway 3.0 — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIcHDPSQimXP6BXneG4aug.png" /></figure><p>The world’s popular open-source middleware giant, WSO2s’ API MicroGateway is an enterprise-grade, cloud native and open source API management solution which is fully optimized for microservice platforms. Most importantly, the API MicroGateway is Developer and Dev-Ops friendly, highly scalable, stateless, decentralized, and it is developed on top of Ballerina, the WSO2s’ latest cloud native programming language who is promised lightweight containers along with fast boot-up times, low memory footprint, and small distribution sizes.</p><p>Most recently, WSO2 has released the latest version of their stunning MicroGateway which is called “WSO2 API MicroGateway 3.0”. The latest release of API MicroGateway accompanied a set of brand new stunning features including <strong>API definition per resource endpoints</strong>, <strong>HTTP2 support</strong>, <strong>Mutual SSL based authentication</strong>, <strong>Config based basic authentication</strong>, <strong>Global throttling, Request/Response transformation</strong> and <strong>schema validation</strong>, <strong>Integration with 3rd party key managers </strong>and much more. The latest MicroGateway has updated its architecture to be more developer friendly and also it has decomposed the distribution of runtime and developer tools (aka. MicroGateway toolkit). The MicroGateway 3.0 standardizes the API definition by open API specifications which makes easier the developer life by collaborate in creating APIs and testing them independently. It would definitely be a developer-first approach as they announced in the release notes.</p><p>The main objective of this article series is to walk you through the installation (including dependencies), introduce latest architectural changes and also to demonstrate the latest features introduced by the WSO2 API MicroGateway 3.0. It will also include practical implementation of each use-cases to demonstrate the latest MicroGateways’ capability by using a customer API of an online store metaphor.</p><h3><strong>01. INSTALLATION GUIDE</strong></h3><h4>1.1. JAVA (JDK 1.8)</h4><p>I don’t think it is necessary introduce Java in in this article. But in short and sweet: Java is a general purpose programming language and it is most commonly used in backend servers. Java facilitates the underlying runtime engine for most of the WSO2 software as well as Ballerina and API MicroGateway. The JDK 1.8 is the most recommended version for Ballerina and MicroGateway. Please download and install your favorite JDK 1.8 compatible java distribution.</p><h4>1.2. BALLERINA</h4><p>As I mentioned earlier, WSO2 API MicroGateway is developed on top of Ballerina. That makes Ballerina is a required dependancy to develop and run MicroGateway projects. Please download and install the latest Ballerina version from the WSO2s’ Ballerina official release page. You may also install the Ballerina plugin into your favourite IDE. Ballerina official release page could be found at <a href="https://ballerina.io/downloads/">https://ballerina.io/downloads/</a></p><p>Please refer to the Ballerina installation guide for more information <a href="https://ballerina.io/learn/getting-started/">https://ballerina.io/learn/getting-started/</a></p><h4>1.3. WSO2 API Microgateway Toolkit and Runtime</h4><p>The WSO2 MicroGateway 3.0 has decomposed the distribution of Toolkit and Runtime. You may download the releases from WSO2 official release page (<a href="https://wso2.com/api-management/api-microgateway/">https://wso2.com/api-management/api-microgateway/</a>) and extract the binaries (I have extracted binaries into /opt directory). Make sure the /bin sub-directory of both MicroGateway Toolkit and Runtime installations are in the PATH variable. It will enable to execute micro-gw and gateway commands directly through the terminal. (Hint: Please make `sure` those executables got the executable permission (+x) if you are using a unix-like operating systems)</p><p>A sample .bash_profile file for unix-like operating systems <em>(you may need manually configure the PATH variable of windows operating systems)</em></p><pre># microgateway toolkit directory<br><strong>export MGW_TOOLKIT_HOME = /opt/wso2-microgateway-toolkit </strong></pre><pre># microgateway runtime directory<br><strong>export MGW_RUNTIME_HOME = /opt/wso2-microgateway-runtime </strong></pre><pre># adding microgateway components into your PATH<br><strong>export PATH=$PATH:$MGW_TOOLKIT_HOME/bin:$MGW_RUNTIME_HOME/bin</strong></pre><p>Please refer to the MicroGateway 3.0 official installation guide for more information.</p><p><a href="https://docs.wso2.com/display/MG301/Installation+Prerequisites">https://docs.wso2.com/display/MG301/Installation+Prerequisites</a></p><blockquote>Note:<br>The WSO2 API MicroGateway Runtime could be deployed in many different patterns. However the MicroGateway deployment patterns are not the interest of this stage of the article series. Please refer to the “<a href="https://medium.com/@chanakaudaya/wso2-api-microgateway-deployment-patterns-8cb8f25a7619"><strong>WSO2 API MicroGateway deployment patterns</strong></a>” article by <a href="https://medium.com/u/b1e98745113d">Chanaka Fernando</a> for more detail on complex deployments. However it’s recommended to keep the deployment simple for the purpose of this article.</blockquote><h3>02. CREATE BUILD AND RUN A MICROGATEWAY PROJECT</h3><h4>2.1. SANDBOX PROJECT</h4><p>The sandbox project contains the required dependencies and code snippets for each scenario of the article. You may start to work on the “sandbox” directory and the final version of each scenario is in the “complete” directory. Please clone the sandbox project from the GitHub repository at <a href="https://github.com/hjchanna/wso2-api-micro-gw3-sandbox">https://github.com/hjchanna/wso2-api-micro-gw3-sandbox</a></p><p><a href="https://github.com/hjchanna/wso2-api-micro-gw3-sandbox">hjchanna/wso2-api-micro-gw3-sandbox</a></p><blockquote><strong>Note: <br></strong>Please DON’T forget to give a <strong>star to the micro-gw3-sandbox project</strong> on GitHub</blockquote><pre><strong>git clone git@github.com:hjchanna/wso2-api-micro-gw3-sandbox.git</strong></pre><p>Sandbox project also contains the ballerina implementation of the customer service for the online store metaphor as mentioned in above sections. The customer service contains following resource endpoints which would use to demonstrate MicroGateway capabilities in later sections.</p><pre># get all customer data<br><strong>request method: GET<br>api context: /customer</strong></pre><pre># get customer data for a given customer id<br><strong>request method: GET<br>api context: /customer/{customerId}</strong></pre><pre># add a new customer<br><strong>request method: POST<br>api context: /customer</strong></pre><p>Please follow the steps below to start the customer API service.</p><ul><li>Locate into the customer_service folder of the sandbox project</li><li>Execute the ballerina run command on the customer_service.bal</li></ul><pre>ballerina run customer_service.bal</pre><ul><li>Now the customer service should have started in the port 8080 and you may test the customer API by curl command (or you may use your favorite API testing tool ie: Postman.)</li></ul><pre># get all customer data<br><strong>curl </strong><a href="http://localhost:8080/customer"><strong>http://localhost:8080/customer</strong></a></pre><pre># get customer data by customer id<br><strong>curl </strong><a href="http://localhost:8080/customer/1"><strong>http://localhost:8080/customer/1</strong></a></pre><pre># add a new customer<br><strong>curl -X POST </strong><a href="http://localhost:8080/customer"><strong>http://localhost:8080/customer</strong></a><strong> -d &#39;{&quot;id&quot;: &quot;6&quot;, &quot;name&quot;: &quot;Harry James Potter&quot;}&#39;</strong></pre><h4>2.2. CREATING A MICROGATEWAY PROJECT</h4><p>The WSO2 MicroGateway toolkit enables to initialize a project easily with all required configurations. Please run the following command to generate a new MicroGateway project.</p><pre>micro-gw init &lt;your-project-name&gt;</pre><p>Now you should have generated a new MicroGateway project with following structure</p><pre>&lt;your-project-name&gt;/<br>├── api_definitions             # open API definition files    <br>├── conf                        # project config<br>│   └── deployment-config.toml<br>├── extensions                 <br>│   ├── extension_filter.bal<br>│   ├── startup_extension.bal<br>│   └── token_revocation_extension.bal<br>├── interceptors                # custom interceptors<br>├── policies.yaml<br>├── services                    # gateway specific services<br>│   ├── authorize_endpoint.bal<br>│   ├── revoke_endpoint.bal<br>│   ├── token_endpoint.bal<br>│   └── user_info_endpoint.bal<br>└── target                      # build output<br>    └── gen</pre><p>Please refer to the <a href="https://docs.wso2.com/display/MG301/API+Microgateway+Project+Directory"><strong>WSO2 official documentation</strong></a> for more information on MicroGateway project structure.</p><blockquote>Note:<br>WSO2 MicroGateway doesn’t successfully build a project which doesn’t contain valid open API definitions. Please copy the customer_api.yaml file into the api_definitions folder of your project. The customer_api.yaml file is provided by the sandbox projects’ sandbox directory.</blockquote><h4>2.3. BUILDING AND RUNNING A MICROGATEWAY PROJECT</h4><p>The WSO2 MicroGateway toolkit also enables to build a project easily through the terminal. Please locate into the parent directory of the project and execute the micro-gw build command to build your microgateway project.</p><pre>micro-gw build &lt;your-project-name&gt;</pre><p>The micro-gw build command translates the open API definition files into ballerina source files and also compiles ballerina source files into ballerina executables. It generates the Dockerfile and docker images as you have configured the project (build output could be configured by the deployment-config.toml file located in the conf directory of a MicroGW project). The build output file should be available in following location after a successful build.</p><pre>&lt;your-project-folder&gt;/target/&lt;project-name&gt;.balx</pre><p>Once the build is successful, you may run the project through the microgateway runtime command as follows.</p><pre>gateway &lt;your-project-folder&gt;/target/&lt;project-name&gt;.balx</pre><p>Now your MicroGateway should have started in port numbers 9090, 9095, and 9096 by default (It is configurable through the micro-gw.conf file of the MicroGW runtime). MicroGateway default ports are utilized as follows.</p><pre>Port 9090 - exposes API through HTTP protocol<br>Port 9095 - exposes API through HTTPS protocol<br>Port 9096 - MicroGateway management API through HTTPS protocol</pre><h4>2.4. PROJECT CONVENTIONS</h4><blockquote><strong>Note:</strong><br>Please note that following project conventions will be used in the later sections of the article.</blockquote><pre>$MGW_TOOLKIT_HOME - microgateway toolkit directory<br>$MGW_RUNTIME_HOME - microgateway runtime directory<br>$PROJECT_HOME - &lt;sandbox project dir&gt;/sandbox directory</pre><h3>03. CONFIG BASED “BASIC AUTHENTICATION”</h3><p>The basic authentication scheme a standard simple authorization scheme which uses base64 encoded authorization header with username and password. Out of the box, WSO2 MicroGateway enables APIs to authorize through basic authentication scheme in both API level as well as the resource level. Following step by step guidance will walk you through both API level and resource level configuration of MicroGW basic authentication. You may test basic authentication in either API level (section A) or resource level (section B) or both separately.</p><h4>3.A. DEFINE BASIC AUTHENTICATION IN OPEN API (API LEVEL)</h4><ul><li>Follow the steps above to initialize a new MicroGateway project with name basic_auth_sample and copy the sample open API definition file (customer_api.yaml is provided by the sandbox project) into the api_definition directory of the project.</li><li>Add following basic authentication configuration into the newly created online_store.yaml</li></ul><pre># enable the basic authentication scheme for the API<br><strong>security:</strong><br><strong>  - online_store_basic_auth: []</strong><br># define the basic authentication scheme<br><strong>components:</strong><br><strong>  securitySchemes:</strong><br><strong>    online_store_basic_auth:</strong><br><strong>      type: http</strong><br><strong>      scheme: basic</strong></pre><h4>3.B. DEFINE BASIC AUTHENTICATION IN OPEN API (RESOURCE LEVEL)</h4><ul><li>Initialize new MicroGateway project with name basic_auth_sample and copy customer_api.yaml open API definition file into the api_definitions directory of the project.</li><li>Add basic authentication configuration into the each resource of the newly created customer_api.yaml files’ each resource section as follows:</li></ul><pre>...<br>  &quot;/customer&quot;:<br>    get:<br>      responses:<br>        &quot;200&quot;:<br>          description: ok, get all customer data<br>     <strong> security:</strong><br><strong>        - online_store_basic_auth: []</strong><br><em>...</em></pre><ul><li>Define the basic authentication scheme under the component section components:</li></ul><pre><strong>securitySchemes:</strong><br><strong>    online_store_basic_auth:</strong><br><strong>      type: http</strong><br><strong>      scheme: basic</strong></pre><h4>3.2. CONFIGURE MICROGATEWAY FOR BASIC AUTHENTICATION</h4><ul><li>Open the MicroGateway runtime configuration file: $MGW_RUNTIME_HOME/conf/micro-gw.conf in your favorite editor</li><li>Locate into [b7a.users] section and add following basic authentication configuration</li></ul><pre>[&quot;b7a.users&quot;]<br>[&quot;b7a.users.<strong>&lt;username&gt;</strong>&quot;]<br>password=&quot;<strong>&lt;SHA1 hash password&gt;</strong>&quot;</pre><pre>Ex: Username: admin, Password: password<br>[&quot;b7a.users&quot;]<br>[&quot;b7a.users.admin&quot;]<br>password=&quot;5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8&quot;</pre><blockquote><strong><em>Note:</em></strong><em><br>The password should be a SHA1 hash value in uppercase. You may use an online tool to generate the hash or generate through the terminal by the following command.</em></blockquote><pre>echo -n &quot;&lt;password&gt;&quot; | openssl sha1 | tr &#39;a-z&#39; &#39;A-Z&#39;</pre><h4>3.3. BUILD, RUN AND TEST THE PROJECT</h4><ul><li>Use MicroGateway toolkit (micro-gw) to build the basic_auth_sample project as mentioned in above sections. Once the project is built successfully, it should generated the customer_api.balx file in the target directory of the project.</li></ul><pre>micro-gw build basic_auth_sample</pre><ul><li>Start the MicroGateway with the newly generated customer_api.balx file. The WSO2 MicroGateway will be started in the ports 9090, 9095, and 9096.</li></ul><pre>gateway $PROJECT_HOME/basic_auth_sample/target/customer_api.balx</pre><ul><li>The micro-gw.conf was configured the basic auth credentials to be “admin” and “password”. According to the basic authentication scheme, the Authorization header needs to be base64-encrypted username and the password separated by a colon. Please generate base64 for the string “admin:password” through the terminal:</li></ul><pre>echo “admin:password” | base64</pre><ul><li>Use curl command or your favorite API testing tool to test the API</li></ul><pre>curl -X GET \<br> <a href="http://localhost:9090/api/v1/customer">http://localhost:9090/api/v1/customer</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39;</pre><p>And also the HTTPS endpoint also available to access and use the curl command to test the HTTPS endpoints. (Note: HTTPS security will be ignored in this stage since the certificates are not properly configured).</p><pre>curl -kX GET \<br> <a href="http://localhost:9095/api/v1/customer">http://localhost:9095/api/v1/customer</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39;</pre><h3>04. REQUEST AND RESPONSE SCHEMA VALIDATION</h3><p>The WSO2 MicroGateway is capable to validate request and response schemas as defined in the open API definition files. It is only required to simply define the request or response schema in the open API document and to enable the schema validation through the MicroGateway runtime configuration.</p><h4>4.1. OPEN API DEFINITION FOR REQUEST/RESPONSE SCHEMA VALIDATION</h4><p>Follow the steps below to tryout schema validation of a WSO2 MicroGateway project.</p><ul><li>Initialize a new WSO2 MicroGateway project through MicroGateway toolkit with the name request_response_validation. And copy the customer_api.yaml into api_definitions directory of the project.</li><li>Configure the request_response_validation project to authorize through basic authentication scheme as described in the above section.</li><li>Define the customer schema in the component section of the open API definition file customer_api.yaml:</li></ul><pre>components:<br>     ...<br><strong>  schemas:</strong><br><strong>    customerSchema:</strong><br><strong>      type: object</strong><br><strong>      required:</strong><br><strong>        - id</strong><br><strong>        - name</strong><br><strong>      properties:</strong><br><strong>        id:</strong><br><strong>          type: integer</strong><br><strong>        name:</strong><br><strong>          type: string</strong></pre><ul><li>Define the open API request body for POST /customer endpoint in the component section of the open API definition file and link to the relevant endpoint.</li></ul><pre>components:<br>     ...<br><strong>  requestBodies:</strong><br><strong>    customerBody:</strong><br><strong>      content:</strong><br><strong>        application/json:</strong><br><strong>          schema:</strong><br><strong>            $ref: &#39;#/components/schemas/customerSchema&#39;</strong><br><strong>      required: true</strong></pre><p>Once you defined the request body for POST /customer endpoint it is need to be linked into the relevant endpoint definition. Add following lines into the post section of the /customer endpoint as follows.</p><pre>post:<br>...<br>  <strong>requestBody:</strong><br><strong>        $ref: &#39;#/components/requestBodies/customerBody&#39;</strong></pre><p>It should have successfully configured schema validation for the request body of POST /customer endpoint. You may jump into the run and test section or continue the next steps to configure the GET /customer/{customerId} and GET /customer endpoints.</p><ul><li>Since the customer schema is already defined in the above step, it is possible to link the customer schema directly into the GET /customer/{customerId} response. Add following config into the response 200 section of the relevant endpoint.</li></ul><pre>&#39;200&#39;:<br>     ...<br><strong>         content:</strong><br><strong>           application/json:</strong><br><strong>              schema:</strong><br><strong>                $ref: &#39;#/components/schemas/customerSchema&#39;</strong></pre><ul><li>A successful response of the GET /customer endpoint returns a json array of customer objects. Therefore it is required to define the response schema to be an array of customer objects. Add following configurations into the GET /customer endpoint in order to define the response schema.</li></ul><pre>get:<br>...<br>       responses:<br>        &#39;200&#39;:<br>          ...<br>          content:<br>            application/json:<br>              <strong>schema:</strong><br><strong>                type: array</strong><br><strong>                items:</strong><br><strong>                  $ref: &#39;#/components/schemas/customerSchema&#39;</strong></pre><ul><li>It is also possible to validate path variables and query parameters of a request using the MicroGateway. In this example we will consider the request validation of GET /customer/{customerId} endpoint. The expect the customerId to be an integer path variable and it could be defined as follows.</li></ul><pre>get:<br>...<br><strong>  parameters:</strong><br><strong>        - in: path</strong><br><strong>          name: customerId</strong><br><strong>          required: true</strong><br><strong>          schema:</strong><br><strong>            type: integer</strong><br><strong>            format: int32</strong></pre><h4>4.2. MICROGATEWAY RUNTIME CONFIGURATION</h4><p>You may need to enable request and response schema validation in the MicroGateway runtime. Please open the MicroGateway config file (micro-gw.conf) and locate into [validationConfig] section. Update enableRequestValidation and enableResponseValidation configurations as follows.</p><pre>[validationConfig]<br><strong>enableRequestValidation = true</strong><br><strong>enableResponseValidation = true</strong></pre><h4>4.3. BUILD, RUN AND TEST THE PROJECT</h4><ul><li>Build the project using MicroGateway toolkit as follows (Please refer to the build, run and test section of the above examples for more detailed information)</li></ul><pre>micro-gw build request_response_validation</pre><ul><li>Start the MicroGateway with the newly generated ballerina executable file</li></ul><pre>gateway \<br>$PROJECT_HOME/target/request_response_validation.balx</pre><p>MicroGateway should have started in default ports and continue to the next step to test each scenario of the use-case.</p><ul><li>Test each scenario of schema validation by modifying the values of request params and the request body.</li></ul><p>request parameter validation of GET /customer/{customerId} endpoint</p><pre>curl -X GET \<br> <a href="http://localhost:9090/api/v1/customer/%7Binteger-customer-id%7D">http://localhost:9090/api/v1/customer/{integer-customer-id}</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39;</pre><p>request body validation for the customer schema</p><pre>curl -X POST \<br> <a href="http://localhost:9090/api/v1/customer">http://localhost:9090/api/v1/customer</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39; \<br> -d &#39;{&quot;id&quot;:1,&quot;name&quot;: &quot;Harry James Potter&quot;}&#39;</pre><h3>05. REQUEST AND RESPONSE TRANSFORMATION</h3><p>WSO2 API MicroGateways enables the interceptor pattern which is supportive to extend MicroGateways’ functionality. MicroGateway interceptors will be defined as ballerina functions and it is used to carry out mediations and transformations. There are two types of interceptors available in the MicroGateway which are request interceptors and respond interceptors. Request interceptors are gets triggered before sending the request to the backend service while response interceptors are gets triggered before sending response to the API client.</p><p>As mentioned earlier, interceptors should be defined in ballerina language and respective ballerina file has to be placed in the interceptors directory of a MicroGateway project. And also, interceptor should be linked into the API in open API definition file either in API level or resource level through the WSO2 specific open API extensions as follows.</p><pre>#request interceptor<br><strong>x-wso2-request-interceptor: &lt;your-request-interceptor&gt;</strong></pre><pre>#response interceptor<br><strong>x-wso2-response-interceptor: &lt;your-response-interceptor&gt;</strong></pre><h4>5.1. REQUEST INTERCEPTOR SAMPLE</h4><p>According the sandbox customer API, POST /customer endpoint is used to add a new customer. However the request body has to have the customer id defined, which is unpredictable from the clients’ point of view and also the customer id is hard to maintain in a sequence order. In this use-case will walk you through the automated customer id generation and transform the request payload into accepted format by the backend service.</p><ul><li>Initialize a new MicroGateway project with and copy provided open API definitions into the project. The project name would be request_response_validation</li><li>Configure the newly created MicroGateway project to enable basic authentication scheme.</li><li>Create a new ballerina file with name transform_post_request.bal in the interceptors directory of the MicroGateway project and add following ballerina code into the transform_post_request.bal</li></ul><pre>import ballerina/log;<br>import ballerina/http;</pre><pre>//customer API client<br>http:Client httpClient = new(&quot;http://localhost:8080&quot;);</pre><pre>public function transformPostRequest (http:Caller outboundEp, http:Request req) {</pre><pre>    //get all customers to calculate next customer id<br>    var response = httpClient-&gt;get(&quot;/customer&quot;);<br>    var id = -1;</pre><pre>    if (response is http:Response) {<br>        json | error customers = response.getJsonPayload();</pre><pre>        if (customers is json) {<br>            //calculate next customer id<br>            id = customers.length() + 1;<br>        }<br>    }</pre><pre>    log:printInfo(&quot;Generated a new id for the customer :&quot; + id);</pre><pre>    //set the calculated customer id to the request payload<br>    var requestPayload = req.getJsonPayload();<br>    if (requestPayload is json) {<br>        requestPayload.id = id;<br>        req.setJsonPayload(untaint requestPayload, contentType = &quot;application/json&quot;);<br>    }<br>}</pre><p>Above ballerina code will talk to the GET /customer endpoint of the backend customer service and gets all customers. And it will generate the next customer id by adding one integer into the number of customers returned. After all, it will add or update the customer id in the request body and will pass into the backend.</p><blockquote><strong>Note:</strong><br>It is not really recommended to call the backend service bypassing the API gateway and it is implemented just for demonstration purposes only.</blockquote><ul><li>Link the request interceptor to the relevant resource of the API definition file using WSO2 specific open API extension as follows and it is ready to build and test.</li></ul><pre>post:<br>  ...<br><strong>  x-wso2-request-interceptor: transformPostRequest</strong></pre><h4>5.2. RESPONSE INTERCEPTOR SAMPLE</h4><p>You might have noticed the customer backend service returns an error message in json format when it is in error scenarios. For an example GET /customer/{customerId} endpoint will return following response if there is not a customer available for the customer id provided.</p><pre>{<br>     “message” : ”Customer not found for id: &lt;customer-id&gt;”<br>}</pre><p>This section will walk you through the transforming such responses into the standard error message format of the API MicroGateway with the following format.</p><pre>{<br>    &quot;fault&quot;: {<br>        &quot;code&quot;: 900000,<br>        &quot;message&quot;: &quot;Customer not found for the id: &lt;customer-id&gt;&quot;,<br>        &quot;description&quot;: &quot;An error returned from the customer backend&quot;<br>    }<br>}</pre><p>Let’s continue to implement a new ballerina response interceptor on top the of request_response_transformation project.</p><ul><li>Create a new ballerina file with the name transform_message_response.bal in the interceptors folder and add following ballerina code into the newly created ballerina file.</li></ul><pre>import ballerina/http;</pre><pre>public function transformMessageResponse (http:Caller inboundEp, http:Response res) {<br>    //get and check the response code from the backend<br>    int statusCode = res.statusCode;</pre><pre>    if (404 == statusCode || 500 == statusCode) {<br>        //create a new json response payload to return to the client<br>        json responsePayload = {</pre><pre>        };</pre><pre>        json | error backendPayload = res.getJsonPayload();<br>        //transform the payload into the required format</pre><pre>        if (backendPayload is json) {<br>            responsePayload.fault = {};<br>            responsePayload.fault.code = 900000;<br>            responsePayload.fault.message = backendPayload.message;<br>            responsePayload.fault.description = &quot;An error returned from the customer backend&quot;;</pre><pre>            //set the response payload<br>            res.setJsonPayload(untaint responsePayload, contentType = &quot;application/json&quot;);<br>        }<br>    }<br>}</pre><p>Above ballerina code will check the response code returned from the backend service and will transform the response payload into required format if the response code is equal to 404 or 500.</p><ul><li>Link the response interceptor in the open API definition in API level which will be applied to all responses as follows.</li></ul><pre>#add following line into the root level of the open API def<br><strong>x-wso2-response-interceptor: transformMessageResponse</strong></pre><h4>5.3. BUILD, RUN AND TEST THE PROJECT</h4><ul><li>Build the project using MicroGateway toolkit as follows (Please refer to the build, run and test section of basic authentication example for more detailed information)</li></ul><pre>micro-gw build request_response_transformation</pre><ul><li>Start the MicroGateway with the newly generated ballerina executable file</li></ul><pre>gateway \<br>$PROJECT_HOME/target/request_response_tranformation.balx</pre><ul><li>MicroGateway should have started in default ports and continue to the next step to test each scenario of the use-case.</li><li>Test the add new customer endpoint without customer id in the request body. The customer id suppose to automatically generate by the MicroGateway interceptor itself.</li></ul><pre>curl -X POST \<br> <a href="http://localhost:9090/api/v1/customer">http://localhost:9090/api/v1/customer</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39; \<br> -d &#39;{&quot;name&quot;: &quot;Harry James Potter&quot;}&#39;</pre><p>Once above request successfully completed, call GET /customer endpoint to verify the result.</p><pre>curl -X GET \<br> <a href="http://localhost:9090/api/v1/customer">http://localhost:9090/api/v1/customer</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39;</pre><p>Verify that the newly added customer should have added to the backend with the next available customer id.</p><ul><li>Test GET /customer/{customerId} endpoint for a not existing customer id and it should return an error message with the expected error format.</li></ul><pre>curl -X GET \<br> <a href="http://localhost:9090/api/v1/customer/100">http://localhost:9090/api/v1/customer/100</a> \<br> -H &#39;Authorization: Basic YWRtaW46cGFzc3dvcmQ=&#39;</pre><h3>SUMMARY</h3><p>I hope this article will help you to get stand with the WSO2 API MicroGateway 3.0 including installation, latest architectural style, and also to try out several new features introduced by the latest version of API MicroGateway. As I have demonstrated some of the newly introduced MicroGateway features in a very simple deployment of the MicroGateway runtime, there are much more to present you including Key manager configuration, Throttling, SSL Configuration, HTTP/2 support, Docker/Kubernetes deployments, Runtime service discovery, and Composing multiple microservices which requires a complex MicroGateway deployment to demonstrate. I will leave such use-cases into the next episodes of the article series to prevent the article getting more lengthy and complicated.</p><p>I think you enjoyed the first episode of the article series and don’t forget to leave your kind response. Please contact me if you have any queries which regards to the WSO2 API MicroGateway, I am happy to hear from you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93711d5bf278" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Released: Desktop Edition of Talend ETL Code Quality Tool]]></title>
            <link>https://medium.com/@hjchanna/released-desktop-edition-of-talend-etl-code-quality-tool-ecbe7667ada1?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecbe7667ada1</guid>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[talend]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Fri, 02 Nov 2018 06:54:51 GMT</pubDate>
            <atom:updated>2018-11-02T06:57:01.211Z</atom:updated>
            <content:encoded><![CDATA[<p>It has been several days since I officially announced the Talend code quality tool called “Talend Validation Toolkit”. The Talend Validation Toolkit is used to ensure that a Talend ETL project is according to the development standards. It validates Talend projects against rules or standards defined by the Talend company itself or industry experts. Please refer to my previous blog post[1] where I announced the tool and to the GitHub repository[2] for technical details.</p><p><strong>[1] Announcement of the Talend Validation Toolkit:</strong> <a href="https://medium.com/@hjchanna/a-code-quality-tool-for-talend-etl-576611e854e1">https://medium.com/@hjchanna/a-code-quality-tool-for-talend-etl-576611e854e1</a></p><p><strong>[2] GitHub Repo of the Talend Validation Toolkit: </strong><a href="https://github.com/hjchanna/talend-validation-toolkit">https://github.com/hjchanna/talend-validation-toolkit</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ea6-kVQbHnUML9AO9xYtDw.png" /><figcaption>Talend Validation Tool</figcaption></figure><p>The release phase 02 of the Talend Validation Toolkit is completed and it is publicly available including a desktop application to validate code quality of Talend projects. Please refer to the releases section of the GitHub repository[3] for latest releases.</p><p><strong>[3] Releases of the Talend Validation Toolkit:</strong> <a href="https://github.com/hjchanna/talend-validation-toolkit/releases">https://github.com/hjchanna/talend-validation-toolkit/releases</a></p><p>The desktop version of the Talend Validation Toolkit is called “Talend Validation Tool”. The Talend Validation Tool enables to validate the code quality of a Talend ETL project, by locating to a Talend project from the file tree in the left hand side. The validation results will appear in the right hand side including the project information and validation summary. The refresh button in the bottom is used to refresh or revalidate the selected Talend ETL project.</p><p>The Talend Validation Toolkit could be extended by adding more validation rules and by improving its features. I expect your contribution to identify Talend coding standards which I could not add to the tool. I also welcome code contributors to the project. Please contact me through email for any query of this project.</p><p><strong>Personal email address:</strong> hjchanna@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecbe7667ada1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Code Quality Tool for Talend ETL]]></title>
            <link>https://medium.com/@hjchanna/a-code-quality-tool-for-talend-etl-576611e854e1?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/576611e854e1</guid>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[talend]]></category>
            <category><![CDATA[data-integration]]></category>
            <category><![CDATA[etl]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Sat, 18 Aug 2018 20:23:08 GMT</pubDate>
            <atom:updated>2018-08-19T06:56:31.126Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>I believe that your are a Talend ETL developer and you want to adopt something to your Talend projects improve and maintain its quality. Please jump to the 2nd chapter, if you already familiar about Code Quality Standards and Code Quality Tools.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*QJVzhB9-EVXNXsne_-afWQ.png" /></figure><p><em>Code Quality</em> is an important non-functional requirement of a software product over other software quality attributes. <em>Code Quality </em>could lead to <em>financial losses</em> or <em>waste of time</em> which needed for further maintenance, modification or adjustment, if code quality is not good enough. The code quality of a software product is defined by set of attributes such as Readability, Maintainability, Extensibility, Language’s specific conventions, Testability and Documentation. I encourage you to read the book “<em>Clean Code” </em>by Uncle Bob (Robert Cecil Martin), if you interested in improving your coding quality and to learn more about the code quality.</p><p>Most of the time, the code quality of a product is determined by code reviewing sessions. In general, code review sessions are done in different forms such as <em>self-reviews</em>, <em>peer-reviews</em>, <em>panel review </em>and etc. Therefor code reviews tend to be high costly in respective time and the effort. There are several approaches to automate the assure quality of a code by automation tools called <em>Code Quality Tools</em> such as <em>SonarQube</em>, <em>Checkstyle</em> and several other Lint tools (JsLint, PyList, ESLint and etc).</p><p>Talend ETL is an open source and data integration tool, which enables to perform ETL (Extract, Transform, Load) transactions easily. Unlike other general purpose programming and scripting languages, design view is Talends default development perspective. According to Talend documentation, It also suggests some standards and best practices to keep the projects good shape in quality. But it became a nightmare to ensure code quality or design quality of a Talend project without human attention because of the fluid nature of design view platforms.</p><p>I consider Coding Quality as one of my principles of life as a software engineer. I have installed code quality tools to my development environment to automate code quality review of my coding. Unfortunately, when I work with Talend it was a headache to review code quality manually. I came up with a solution to automate code quality review by a tool and I named it as “Talend Validation Toolkit”.</p><p>The “Talend Validation Toolkit” is an open source project hosted in GitHub which automates code quality review of a Talend project. It can be used in several different forms as follows;</p><ul><li>As Java Library</li><li>As a Maven Plugin for a Talend Project</li><li>As a plugin for your build system</li></ul><p>The Talend Validation Toolkit is configurable through JSON in order to add or modify new validation rules. Please visit the GitHub page (<a href="https://github.com/hjchanna/talend-validation-toolkit">https://github.com/hjchanna/talend-validation-toolkit</a>) for installation and development guidelines. I expect your suggestions and contribution to extend the Talend Validation Toolkit.</p><p>I will discuss implementation details and technical stuff in my next posts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=576611e854e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Samba-Poke: Testing Samba Connections With Java]]></title>
            <link>https://medium.com/@hjchanna/samba-poke-testing-samba-connections-with-java-823ebd454c72?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/823ebd454c72</guid>
            <category><![CDATA[jcifs]]></category>
            <category><![CDATA[samba-poke]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[samba]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 14:20:57 GMT</pubDate>
            <atom:updated>2018-08-17T14:48:30.730Z</atom:updated>
            <content:encoded><![CDATA[<p>You may have experience working with samba connections <em>(smb://)</em> with the <em>smbclient </em>tool and its doing its job really well. In general, the <em>smbclient</em> could be used as follows.</p><pre>#smbclient command<br>smbclient &lt;host&gt; -U &lt;domain&gt;\&lt;username&gt;<br>- or -<br>smbclient &lt;host&gt; -U &lt;domain&gt;\&lt;username&gt;%password</pre><pre>#example<br>smbclient smb://localhost/test-samba/ WORKGROUP\hjchanna%password</pre><pre>Note: you may have to install smbclient if you haven&#39;t already installed</pre><p>But the real pain comes when you working with samba connections with Java. <em>JCIFS </em>is a popular java samba library that could be used to connect samba hosts though a java code. You may find installation information and code samples in <a href="https://jcifs.samba.org/">https://jcifs.samba.org</a> which is the original author of the <em>JCIFS</em>.</p><p>But still you may struggle to tweak and test different configurations for your samba connections, so I came up with a solution <em>(thanks to Mr. Simon Boyce)</em> to test samba connections with a small tool called <em>samba-poke</em>. It overlays the standard <em>JCIFS </em>library and enables us to troubleshoot samba through the command line.</p><p><em>Samba-Poke</em> is distributed through <em>GitHub</em> and it could be downloaded using <em>wget</em>. Follow steps below to download and work with the <em>Samba-Poke</em>.</p><pre># download samba-poke<br>wget https://github.com/hjchanna/samba-poke/raw/master/release/samba-poke.jar<br><br># run samba-poke<br>java -jar samba-poke.jar smb://whatever/your/path/ &lt;domain&gt; &lt;username&gt; &lt;password&gt; <br>- or - <br>java -jar samba-poke.jar smb://whatever/your/path/ &lt;domain&gt; &lt;username&gt;</pre><p>Please visit the <em>GitHub </em>repository of the <em>samba-poke</em> for more information. And give me a star for this simple tool.</p><p><a href="https://github.com/hjchanna/samba-poke">https://github.com/hjchanna/samba-poke</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=823ebd454c72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most Wanted Unix Commands]]></title>
            <link>https://medium.com/series/most-wanted-unix-commands-173f2cf9f2d3?source=rss-802a1ceda6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/173f2cf9f2d3</guid>
            <dc:creator><![CDATA[Channa Jayamuni]]></dc:creator>
            <pubDate>Sun, 11 Feb 2018 12:02:40 GMT</pubDate>
            <atom:updated>2018-02-11T12:05:19.159Z</atom:updated>
            <content:encoded><![CDATA[<p>The quick brown fox jump over the lazy dogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=173f2cf9f2d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>