Sunday, 12 July 2020

OAUTH2 flow types


Oauth2 flow types or grant types:
  1. Authorization code flow
  2. Implicit flow
  3. Resource owner flow
  4. Client credential flow

1. Authorization code flow

                    If a third party web or mobile application wants access the resources from your server, we should choose this flow.


2. Implicit flow

                    If the application is a purely a client side application(ex: written only in Javascript) and no server side code, then we can use this flow. EX : Outlook or other Mail applications, where it depends only on the resource server and it’s doesn’t own anything in the backend.


3. Resource owner flow

                    If there’s a high level of trust between user and application or application and oauth provider, we can choose this application. If the application is the owner of the resource, we can use this flow.
                    Ex: if your company have webapp, mobile app and any other application and all needs to access the same resource and your company owns the oauth server, we can go and use this flow. Here, there’s a complete trust between the app and auth server or the app and user.


4. Client credential flow

                     If the client is also a backend server, we can go & use this flow.




Please read the below terminologies used in oauth
1. Scope
2. Claims
3. Client_id
4. Client_secret
5. Redirect_URI
6. Authorization_code
7. Grant type
8. Access Token
9. Refresh Token
10. Transfer Token

Claims can be anything that can allow the service to make a well informed authorization decision.

Thursday, 26 September 2019

Redis - Getting Started

Install redis in mac


Install redis 
$ brew install redis

To start the server, just type 'redis-server'
$ redis-server

Go to redis-cli & test the installation by store & get a key-value pair,
$ redis-cli

127.0.0.1:6379> set mykey myvalue-for-the-key
OK
127.0.0.1:6379> get mykey
"myvalue-for-the-key"
127.0.0.1:6379>

Monday, 1 July 2019

Katharsis (JsonAPI)

Katharsis

What’s katharsis? 
Elegant and powerful HATEOAS for Java based on JSON API standard. (from http://katharsis.io/)

What’s HATEOAS?
HATEOAS stands for Hypermedia as the Engine of Application State. It’s a very common concept in browser which we use daily without knowing. HATEOS is, Using Hyperlinks to change the state of an application. For example, our browser will load a web page with plenty of hyperlinks. When you click on the hyperlink it will take us to different webpage or change the state of the same web page. Yes, it’s that much simple.

Coming Back to Katharsis:
Katharsis is a JSON api standard using this HATEOAS concept, that will give you a response along with link you want to use further. And this also enforce the developers to follow the standards in rest url and rest methods. Let’s see an example json,

{
  "data": [
    {
      "id": "1",
      "type": "students",
      "attributes": {
        "student-name": "Arun",
        "gender": "M"
      },
      "relationships": {
        "courses": {
          "data": [
            {
              "id": "1",
              "type": "courses"
            },
            {
              "id": "2",
              "type": "courses"
            }
          ],
          "links": {
            "self": "http://localhost:8080/api/students/1/relationships/courses",
            "related": "http://localhost:8080/api/students/1/courses"
          }
        }
      },
      "links": {
        "self": "http://localhost:8080/api/students/1"
      }
    },
    {
      "id": "2",
      "type": "students",
      "attributes": {
        "student-name": "Ashok",
        "gender": "M"
      },
      "relationships": {
        "courses": {
          "data": [
            {
              "id": "1",
              "type": "courses"
            },
            {
              "id": "2",
              "type": "courses"
            }
          ],
          "links": {
            "self": "http://localhost:8080/api/students/2/relationships/courses",
            "related": "http://localhost:8080/api/students/2/courses"
          }
        }
      },
      "links": {
        "self": "http://localhost:8080/api/students/2"
      }
    }
  ],
  "included": [
    {
      "id": "1",
      "type": "courses",
      "attributes": {
        "course-name": "AWS"
      },
      "links": {
        "self": "http://localhost:8080/api/courses/1"
      }
    },
    {
      "id": "2",
      "type": "courses",
      "attributes": {
        "course-name": "Data Science"
      },
      "links": {
        "self": "http://localhost:8080/api/courses/2"
      }
    }
  ]
}

Please click here for the katharsis example application.

Tuesday, 11 June 2019

Cassandra Database Setup

Cassandra Database Setup

Cassandra DB can be set up easily by using the docker image. If you do not have docker installed in your machine, please do it and follow the steps.

 #Pull the docker image
docker pull cassandra
 #Run the docker image in a container
docker run -p 9042:9042 --name my-cassandra -d cassandra:latest

 #Stop the docker container
docker stop my-cassandra
 #Start the docker container
docker start my-cassandra
 #Stop & remove the container
docker stop my-cassandra
docker rm my-cassandra

The docker exec command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your cassandra container.

docker exec -it my-cassandra bash  

Now you your inside the container. Type cqlsh which will allow you enter into the cassandra query language shell Where you can execute the below queries.

 #This will list the available keyspaces
describe keyspaces;

 #Create a new namespace with the name arun_keyspace.
CREATE KEYSPACE arun_keyspace
WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};

 #If list the keyspaces again, you can see newly created keyspace arun_keyspace
describe keyspaces;
 #Command to Use the keyspace to create/update & manage tables
use arun_keyspace;


 #Create a new table, products
create table products (
          productid uuid ,
          productname text,
          productdescription text,
          PRIMARY KEY(productid)
      );

 #Insert
insert into products(productid, productname, productdescription)
values (now() , 'Fitbit' , 'Fitbit versa');

 #Select the table
select * from products;


Thursday, 23 May 2019

PostgreSQL Overview

Setting up the server

To get start with postgreSQL, download the Postgres.app & pgadmin 4(for macOS).
Postgres.app is a simple, native macOS app that runs in the menubar without the need of an installer.
pgAdmin 4 is a feature rich open source PostgreSQL client.

Open Postgres.app > Click on Start - This will start the postgres server

Open pgadmin 4 - This will start the server & opens http://127.0.0.1:56791/browser/ in the browser.
Right Click on server > Create > Server > Fill the details as below & Save,



You will be connected to the server which was started by Postgres.app. You will see the below hierarchy on the right side.

Right click on Databases > Create > Database > enter any name for database (ex : employee_db)
Select Tools > Query Tool - This will open a Query Editor.

Hands on

Run the below queries one by one and watch what it does,
create table employee(employee_id integer not null,
   employee_name text not null,
   education_qualification text not null,
   gender varchar(6) not null,
   employee_role text not null,
   payload text);
      
--- INSERTING VALUES ---
insert into employee
values('1001', 'Arun Velusamy', 'Engineering', 'male', 'application developer');

insert into employee
values('1002','Ashok Subburaj', 'Engineering', 'male', 'application developer');

insert into employee
values('1003','Lakshmi Velan', 'PHD', 'female', 'Lead Engineer');

insert into employee
values('1004','Veerammal Ramasamy', 'MBA', 'female', 'Product designer');

insert into employee
values('1005','Gautham Kumarasamy', 'Not Available', 'male', 'Cheif Executive');

--- SELECT THE EMPLOYEE TABLE ---
select * from employee;


select to_jsonb(emp)
from
 (
  select employee_id,employee_name,education_qualification,gender,employee_role
  from employee
 ) emp;

--- UPDATE THE PAYLOAD ---
update employee
set payload = 
 (
  select to_jsonb(emp)
  from (
   select employee_id,employee_name,education_qualification,gender,employee_role
   from employee
  ) emp
where employee.employee_id = emp.employee_id);

--- SELECT THE EMPLOYEE TABLE ---
select * from employee;



--- ALTER TABLE TO DROP 2 COLUMNS ---
alter table employee
drop column education_qualification;

alter table employee
drop column gender;

select * from employee;

--- SELECT VALUES FROM JSON PAYLOAD COLUMN ---
select employee.employee_id, employee.employee_name, employee.employee_role,
 emp_payload.education_qualification, emp_payload.gender
from employee, jsonb_to_record(employee.payload::jsonb) as emp_payload (
 education_qualification text,
 gender varchar(6)
);

Saturday, 11 May 2019

Openshift


Openshift is the platform offered as software as service. It is developed by Redhat. It is built around Docker containers orchestrated and managed by kubernetes. Openshift automates the build, deployment and management of application.

Core Concepts of Openshift:

  1. Containers and images
  2. Pods and Users
  3. Projects and Users
  4. Builds and Image Streams
  5. Deployments
  6. Routes
  7. Templates
  8. Orchestration

Containers

(basic units of openshift)
Containers aims to create portable software which should run from local environment to production in a same way.
Containers wrap the software in a customised operating system. This minimizes the chance of saying that application works in local & not working in UAT or works in non-prod & not working in production
So containers are actually a light weight operating system which host one or more software applications. But typically each container will host only one application which we used to call "Micro Service"


Images

It is a binary includes all requirements to run a single container. Metadata describing its needs and capabilities. You can think of war/jar packaging.
Containers are create from images that specify their precise contents. Image is a definition of the container where it used to run.
On a simple note, image is just a war/jar + Some Infra details(like os details, jdk version etc)


Orchestration

It is about how you manage the containers & automate the management. Below are the few process to manage the containers
Spin up the number of containers from three to five & scale down to two. You can spin up five containers on five five different hosts.
Zero down time deployments. Spin up the containers running the new code. Once it is fully up, redirect the user traffic from old container to this new container. So it is zero or near to zero down time deployment.


Sunday, 16 April 2017

Installing NOOBS in SD card

To use Raspberry device, we need NOOBS boot loader to install any IoT Operating system such as Raspbian or Ubuntu mate.

Following are the steps to install the NOOBS in SD card.

1. Insert an SD card that is 4GB or greater in size into your computer.
(Preferred to use SD card adapter or SD Card reader).

2. Format the SD card using the platform-specific instructions below:  (Formatting tool might have only less than 500kb.)
   a. Windows
      i. Download the SD Association's Formatting Tool from SDFormatter windows
      ii. Install and run the Formatting Tool on your machine
      iii. Set "FORMAT SIZE ADJUSTMENT" option to "ON" in the "Options" menu
      iv. Check that the SD card you inserted matches the one selected by the Tool
      v. Click the "Format" button
   b. Mac
      i. Download the SD Association's Formatting Tool from SDFormatter Mac
      ii. Install and run the Formatting Tool on your machine
      iii. Select "Overwrite Format"
      iv. Check that the SD card you inserted matches the one selected by the Tool
      v. Click the "Format" button
   c. Linux
      i. We recommend using gparted (or the command line version parted)
      ii. Format the entire disk as FAT

3. Extract the files contained in this NOOBS zip file.
(You can download NOOBS.zip from the following link.
  NOOBS Latest )

4. Copy the extracted files onto the SD card that you just formatted so that this file is at the root directory of the SD card. Please note that in some cases it may extract the files into a folder, if this is the case then please copy across the files from inside the folder rather than the folder itself.
(You can find these instructions in readme.txt in extracted files)

5. Insert the SD card into your Pi and connect the power supply.


Post Installation instructions :



Your Pi will now boot into NOOBS and should display a list of operating systems that you can choose to install.
(You need to connect to internet to download the Operating system by NOOBS)
If your display remains blank, you should select the correct output mode for your display by pressing one of the following number keys on your keyboard:

1. HDMI mode - this is the default display mode.
2. HDMI safe mode - select this mode if you are using the HDMI connector and cannot see anything on screen when the Pi has booted.
3. Composite PAL mode - select either this mode or composite NTSC mode if you are using the composite RCA video connector.
4. Composite NTSC mode