Skip to content

This project is a technical challenge project which is powered by flask and docker.

Notifications You must be signed in to change notification settings

mohammadmasoumi/object-challenge

Repository files navigation

Object Challenge

ci

This project is a technical challenge project which is powered by flask, docker and openresty.

important libraries

project structure

├── config.py
├── bucket
│   ├── fixtures
│   │   ├── user_prefixes.json
│   │   ├── users.json
│   │   └── prefixes.json
│   ├── services
│   │   ├── bucket.py
│   │   ├── __init__.py
│   ├── mongo_models
│   │   ├── user.py
│   │   ├── prefix.py
│   │   ├── user_prefix.py
│   │   ├── __init__.py
│   ├── views
│   │   ├── bucket.py
│   │   ├── __init__.py
│   ├── __init__.py
│   ├── tests
│   │   ├── test_config.py
│   │   ├── test_bucket.py
│   │   ├── base.py
│   │   └── __init__.py
├── __init__.py
├── tree.py
├── base
│   ├── namedtuples.py
│   ├── mixins.py
│   ├── data_loader.py
│   ├── __init__.py
└── helper.py

flask app is defined under object_challenge/__init__.py

flask app is defined under object_challenge/config.py

  • DevelopmentConfig
  • TestingConfig
  • ProductionConfig

mongo models are defined under object_challenge/mongo_models directory.

  • prefixes
  • users
  • user_prefixes
endpoint action payloads
/bucket 'POST' {'bucket':'bucket_name'}
/arvan 'POST' {'bucket':'bucket_name'}

a lua middleware that first send request to the flask app and then based on the response will decide whether send the response to the user or proxy pass the request to the arvan's endpoints

  • prefixes.json
    {"prefix_id": 1, "prefix":  "arvan"}
    {"prefix_id": 2, "prefix":  "pushe"}
    
  • users.json
    {"user_id": 1, "name":  "a", "auth_token":  "token_1"}
    {"user_id": 2, "name":  "b", "auth_token":  "token_2"}
    {"user_id": 3, "name":  "c", "auth_token":  "token_3"}
    
  • user_prefixes.json
    {"user_id": 1, "prefix_id": 1,  "is_allowed":  true}
    {"user_id": 1, "prefix_id": 2,  "is_allowed":  false}
    {"user_id": 2, "prefix_id": 1,  "is_allowed":  true}
    {"user_id": 2, "prefix_id": 2,  "is_allowed":  true}
    

sample request

curl -X POST \
  http://185.239.107.132/bucket \
  -H 'authorization: Token token_1' \
  -H 'content-type: application/json' \
  -d '{
	"bucket": "pushe3"
}'

project diagram

diagram

local setup

  • install requirements
    pip install -r requirements/development.txt
  • load env
    export  $(cat deployment/env_dir/flask.env | xargs)
  • runserver
    python manage.py runserver

server setup

  • install docker and setup github ssh keys
  •  git clone git@github.com:mohammadmasoumi/object_challenge.git
    
  •  cd /deployment
    
  •  docker-compose up -d 
    

flask shell

This project use flask-shell-ipython as an interactive flask shell.

python manage.py shell

Commands

  • run server command
    python manage.py runserver
  • run server command
    python manage.py shell
  • load initial data command. object_challenge/object_challenge/fixtures
    python manage.py init

Resources