Coder Social home page Coder Social logo

centos-paas-sig / restylinchpin Goto Github PK

View Code? Open in Web Editor NEW
5.0 7.0 4.0 4.77 MB

flask based RESTful API wrapper around project linchpin

License: GNU General Public License v3.0

Dockerfile 0.38% Python 99.62%
linchpin cloud provisioning ansible python flask rest-api

restylinchpin's Introduction

restylinchpin

flask based RESTful API wrapper built around project linchpin

Table Of Contents

Overview

HTTP RESTful API.

Requests pass data via JSON encoded bodies except for GET requests where data will be passed via URL and excecute them on linchpin Command Line Interface to provision workspaces and return a JSON response to the user.

A user can currently make use of following supported features:

  • Create Workspaces : Users can create a new worskpace locally.
  • List Workspaces : Users can list all existing workspace within a config directory.
  • Delete Workspaces : Users can delete workspace by name.
  • Fetch Workspaces from a remote URL : Users can fetch remote workspaces from git or web directory locally.
  • Provision workspaces : Users can provision workspaces across multiple cloud providers.
  • Destroy Workspaces : Users can teardown the resources provisioned after using them.

User Management

api_key based authentication for user operations

creating users
endpoint:
/users
methodtype: POST
request:
{
"username":"username",
"password":"password",
"email":"email"
}
response:
{
username=username,
admin=boolean indicating created as admin user or not
email=email,
status="username created successfully"
}

Login
endpoint:
/login
User has to send a basic authentication header with username and password generated above, an autogenerated (hashed) api_key will be returned to the user for resource access.
Response:
{
"api_key":"api_key value"
}
This api_key will be verified by passing a key:api_key and value: api_key value obtained above,in the request headers during each of the API calls including user and workspace actions to grant resource access by determining the access rights of the current user. Admin users can access all resources whereas other resources are only accessible to the owner of that resource.

Reset api key
methodType: POST
endpoint:
/api/v1.0/users/username/reset
Response: {api_key= value, message = "reset successfully"}

listing users
One user:
(Admin user only)
endpoint:
/users/username
methodType: GET
response:
{
username=username,
api_key=api_key,
admin=boolean indicating created as admin user or not
}

All users:
(Admin user only)
endpoint:
/users
methodType: GET
response:
{
[user1: {username: username, password: password(hashed), api_key:api_key} ]
status=200 OK
}

Promote users to admin status
(Admin user only)
endpoint:
methodType: PUT
/api/v1.0/users/username/promote
Response: {user has been promoted as an admin}

Update user fields
endpoint:
methodType: PUT
/api/v1.0/users/username
request:
{ "username":"username",
"password":"password",
"email":"email"
}
response:
{ username=username,
password= hashed_password,
email=email,
status=OK
}

Upload/create credentials
POST /users/username/credentials
RequestBody:
{ file : text or attached file
file_name : name,
encrypted: boolean,
vault_pass: ansible vault password
}
return : response with successful credential upload status

List credentials
GET /users/username/credentials/file_name
return : response with encrypted credentials from file

Delete credentials
DELETE /users/username/credentials/file-name
return : response with successful delete status

Update credentials
PUT /users/username/credentials/file_name
RequestBody: { file : updated text or updated attached file
encrypted: boolean,
vault_pass: ansible vault password
}
return : response with successful credential update status

Linchpin Project

LinchPin is a simple cloud orchestration tool. Its intended purpose is managing cloud resources across multiple infrastructures. These resources can be provisioned, decommissioned, and configured all using declarative data and a simple command-line interface.

Refer to Linchpin Repository for detailed information: https://github.com/CentOS-PaaS-SIG/linchpin

Deployment

restylinchpin will be deployed and available on Openshift.
Start using restylicnhpin with pypi: pip install restylinchpin

Documenation (In progress)

Swagger
ReadTheDocs

restylinchpin's People

Contributors

mansi1996 avatar mansikulkarni96 avatar samvarankashyap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

restylinchpin's Issues

Credential management with CRUD operations

Upload/create credentials
POST /users/username/credentials
RequestBody:
{ file : text or attached file
file_name : name,
encrypted: boolean,
vault_pass: ansible vault password
}
return : response with successful credential upload status
List credentials

GET /users/username/credentials/file_name
return : response with encrypted credentials from file

Delete credentials
DELETE /users/username/credentials/file-name
return : response with successful delete status

Update credentials
PUT /users/username/credentials/file_name
RequestBody: { file : updated text or updated attached file
encrypted: boolean,
vault_pass: ansible vault password
}
return : response with successful credential update status

Add REST endpoint for linchpin fetch

The current issues concern itself deleting workspaces created by linchpin
Linchpin has a command line option fetch which helps us importing workspaces from external urls given a root folder. Options of linchpin workspace are as follows

  -t, --type TYPE  Which component of a workspace to fetch. (Default:
                   workspace)
  -r, --root ROOT  Use this to specify the location of the workspace within
                   the root url. If root is not set, the root of the given
                   remote will be used.
  --dest DEST      Workspaces destination, the fetched workspace will be
                   relative to this location. (Overrides -w/--workspace)
  --branch REF     Specify the git branch. Used only with git protocol (eg.
                   master).
  --git            Remote is a git repository (default)
  --web            Remote is a web directory
  --nocache        Do not check the cached time, just copy the data to the
                   destination
  -h, --help       Show this message and exit.

an example request is as follows:

endpoint:
/workspace/fetch
methodtype: POST

request:
{"name": "workspacename", "url": "www.github.com/someurl", rootfolder:"/path/to/folder"}

in addition to existing parameters make sure your support other command line options.
please make sure you support other command line options except destination. Since destination is currently pre-configured


response:
{name: "nameofworkspace1", "status": "Workspace created successfully"}

if workspaces already exist it should be responding with "workspace with the same name found try again by renaming"

Linchpin provisioning using up restendpoint

The current issues concern itself provisioning workspaces created by linchpin
command line for provisioning is

 linchpin up 

an example request is as follows:

note: This API spec is subjected to change due to the fact that it would be eventually replaced by linchpin API. Further, it is subjected to changes when database integration happens.

endpoint:
/up/
methodtype: POST

request:
{
"name": "workspacename/pinfilename",
provision_type: "workspace",
--> value can be either pinfile or workspace
}

in addition to existing parameters make sure your support other command line options.
please make sure you support other command line options except for destination. Since the destination is currently pre-configured

  -r, --run-id run_id             Idempotently provision using `run-id` data
                                  NOTE: This argument is mutually exclusive
                                  with  arguments: [tx_id].
  -t, --tx-id tx_id               Provision resources using the Transaction ID
                                  (tx-id) NOTE: This argument is mutually
                                  exclusive with  arguments: [run_id].
  --inventory-format, --if INVENTORY_FORMAT
                                  Inventory format cfg/json
  --ignore-failed-hooks, --ifh    Ignores failed hooks
  --no-hooks, --nh                Do not run hooks
  -h, --help                      Show this message and exit.

response:
{
id: "idofworkspace",
"status": "workspace provisioned successfully"
"inventory": "contents_of_latest_inventory_generated_in_inventoryfolder",
"latest": "contents_of_linchpin.latest_file_in_resource_folder"}
}

If the workspace does not exist we need to return a message "workspace does not exist".

RFE: Provide a REST API for Linchpin

Linchpin is positioning itself as the 'de facto' cloud provisioning tool. The tool offers lots of different ways for users to be able to use and execute the application - native/virtualenv install, container, AppImage, etc. but this is all CLI based.

It would be great to wrap the LinchpinAPI in a Flask app that would provide an equivalent RESTful interface to the CLI that developers can develop against. Allowing it to be easier integrated and consumed as a service in modular and loosely coupled fashion.

Integrate database into restylinchpin

Currently, there is no way to store multiple workspaces in restylinchpin.
It would be very difficult in the future to keep track of multiple workspaces.

We need to implement database integrations as a driver based approach such that
we can replace the underlying database.

The current choice of the database would be "TinyDb" since its already included as a dependency.

Add restendpoint to list out existing workspaces created

The current issues concern itself listing workspaces created by linchpin
example request is as follows:

endpoint:
/workspace/list
methodtype: GET

response:
[{name: "nameofworkspace1"}, {name: "name of workspace2"}]

if workspaces are not created the response should be empty
Note: make sure that all workspaces are created in a configurable folder.
For that, there should be a conf file needs to be created and loaded at the time of the server start.

Host restylinchpin on openshift

Linchpin has a multitude of features from provisioning deployments to configuring them on the run using ansible playbooks.
However, it is currently available for deploying on a single machine or as a simple server with restylinchpin. With the capability of linchpin to manage multiple cloud-based accounts/credentials with encrypted vaults. Linchpin can be very useful to all the teams across redhat as a simple provisioned if it is hosted as a service on Openshift.
Hosting linchpin gives the users the flexibility to provision workspaces on the go without going on a hassle to pull down a linchpin container or setup an environment with all dependencies for project linchpin.

Add API routes for additional functionality with pinfile, inventories and linchpin.latest

  1. Users should be able to update their Pinfile within a workspace
    method: POST
    Endpoint:
    /api/v1.0/workspaces/<workspace_id>
    request:
    {
    pinfile_content:{json file contents},
    pinfile_name:name,
    pinfile_path:/dummy/
    }
    response:{pinfile updated}
  2. Users should be able to get inventory from inventory folder →
    if multiple files are found multiple inventories are to be returned,
    [“filename”: {“content”: “all content of inventory ”}]
    method: POST
    Endpoint:
    /api/v1.0/workspaces/<workspace_id>/linchpin_inventory
    request:
    {
    linchpin_inventory_path:/dummy/inventories
    }
    response:{id: workpsace_id, [inventory file1 content, inventory file2 content..]}
  3. Users should be able to get linchpin.latest from a provisioned workspace.
    method: POST
    Endpoint:
    /api/v1.0/workspaces/<workspace_id>/linchpin_latest
    request:
    {
    linchpin_latest_path:/dummy/resources
    }
    response:{id: workpsace_id, "latest": {contents of linchpin.latest file}}

If any users tires to access a workspace which user has not created they should be notified unauthorized request error

Add flake8 tests to code in travis-ci

Flake8 is a good standard to follow when it comes to python based project.
We would like to add tests flak8 tests to travis-ci and enable them for every PR.

Integrate swagger with application

Swagger aides in development across the entire API lifecycle, from design and documentation.
The request is about integrating the existing application with Swagger

Add rest endpoint to destroy workspaces in linchpin.

The current issues concern itself destroy workspaces created by linchpin
command line for provisioning is

 linchpin destroy 

an example request is as follows:

note: This API spec is subjected to change due to the fact that it would be eventually replaced by linchpin API. Further, it is subjected to changes when database integration happens.

endpoint:
/destroy/
methodtype: POST

request:
{
"id": "workspace_id"
}

in addition to existing parameters make sure your support other command line options.
please make sure you support other command line options except for destination. Since the destination is currently pre-configured

  -r, --run-id run_id             Idempotently provision using `run-id` data
                                  NOTE: This argument is mutually exclusive
                                  with  arguments: [tx_id].
  -t, --tx-id tx_id               Provision resources using the Transaction ID
                                  (tx-id) NOTE: This argument is mutually
                                  exclusive with  arguments: [run_id].
  --ignore-failed-hooks, --ifh    Ignores failed hooks
  --no-hooks, --nh                Do not run hooks
  -h, --help                      Show this message and exit.

response:
{
"id": "idofworkspace1",
"status": "workspace/resources destroyed successfully"
}

If the workspace does not exist we need to return a message "workspace does not exist".

Add usermanagement to restylinchpin

Resty linchpin currently does not have any options for

  • creating users
    endpoint:
    /users
    methodtype: POST
    request:
    {
    "username":"username",
    "password":"password",
    "email":"email"
    }
    response:
    {
    username=username,
    admin=boolean indicating created as admin user or not
    email=email,
    status="username created successfully"
    }

  • deleting users
    (Admin users only)
    endpoint:
    /users/username
    methodtype: DELETE
    response:
    {
    status="User username deleted successfully"
    }

  • listing users
    One user:
    (Admin user only)
    endpoint:
    /users/username
    methodType: GET
    response:
    {
    username=username,
    api_key=api_key,
    admin=boolean indicating created as admin user or not
    }

  • All users:
    (Admin user only)
    endpoint:
    /users
    methodType: GET
    response:
    {
    [user1: {username: username, password: password(hashed), api_key:api_key} ]
    status=200 OK
    }

  • Promote users to admin status
    (Admin user only)
    endpoint:
    methodType: PUT
    /api/v1.0/users/username/promote
    Response: {user has been promoted as an admin}

  • Update user fields
    endpoint:
    methodType: PUT
    /api/v1.0/users/username
    request:
    {
    "username":"username",
    "password":"password",
    "email":"email"
    }
    response:
    {
    username=username,
    password= hashed_password,
    email=email,
    status=OK
    }

  • Delete api key
    methodType: DELETE
    endpoint:
    /api/v1.0/users?api_key=value
    Response: {message="api key deleted"}

  • Reset api key
    methodType: POST
    endpoint:
    /api/v1.0/users/username/reset
    Response: {api_key= value, message = "reset successfully"}

  • api_key based authentication for user operations
    Login
    endpoint:
    /login
    User has to send a basic authentication header with username and password, an autogenerated (hashed) token will be returned to the user
    Response:
    {
    "api_key":"api_key value"
    }
    This token will be verified by passing token as an API key in the request headers during each of the API calls for above mentioned user actions as well as workspace actions to grant resource access by determining the access rights of the current user.
    We would like to have the above functionality implemented in the project.

Add rest endpoint to create workspaces

By default, linchpin operates on workspaces.
Linchpin command line has an operation

# creates a workspace in current working directory 
linchpin init
# for more command line options refer to linchpin init --help 

By which one can create linchpin workspaces.
The current issues concern itself creating workspaces using an endpoint.
example request is as follows:

endpoint:
/workspace/create
methodtype: POST
request:
{"name": "workspacename"}
response:
{"name": "workspacename", "status": "Workspace created successfully/ or the status"}

Note: make sure that all workspaces are created in a configurable folder.
For that, there should be a conf file needs to be created and loaded at the time of the server start.

Add REST endpoint Delete workspaces

The current issues concern itself deleting workspaces created by linchpin
example request is as follows:

endpoint:
/workspace/delete
methodtype: POST

request:
[{"name": "workspacename"}]

response:
[{name: "nameofworkspace1", "status": "Workspace deleted successfully"}]

if workspaces do not exist it should be responding with "workspace not found message

Note: There can be multiple workspaces in the request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.