├── .gitignore ├── CHANGELOG.md ├── README.md ├── app.py ├── config.py ├── manage.py ├── om_core ├── __init__.py ├── api │ └── user │ │ ├── __init__.py │ │ └── controllers.py └── data │ ├── README.md │ ├── __init__.py │ └── models.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .sonarlint 3 | bin 4 | include 5 | lib 6 | migrations -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### 22.06.2019 2 | 3 | - User login, register, update and remove endpoints added [https://github.com/foss-dev/open-monitoring/issues/6](https://github.com/foss-dev/open-monitoring/issues/6) 4 | 5 | ### 17.06.2019 6 | 7 | - User API layer added 8 | - User blueprint registered 9 | 10 | ### 16.06.2019 11 | 12 | - om_run.py file's name changed as app.py 13 | - manage.py file added to manage migrations 14 | - flask_migrate and flask_script added to migrations 15 | 16 | ### 15.06.2019 17 | 18 | - Flask CORS added 19 | - config file added 20 | - **.gitignore** file added 21 | - models added -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Open Monitoring 2 | 3 | Free & Open Source Server Monitoring and Management Tool 4 | 5 | ## Motivation 6 | 7 | We are a group of people who develop free and open source applications. Our aim is developing free and open source server monitoring and management tool. 8 | 9 | ## Contributing 10 | 11 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 12 | 13 | Please make sure to update tests as appropriate. 14 | 15 | Your pull requests are should be clear. You should create a branch for your changes. For example; 16 | 17 | **Bug fix** 18 | 19 | `git checkout -b bug-fix-user-login-session-problem` 20 | 21 | **New Feature** 22 | 23 | `git checkout -b new-feature-system-ram-usage` 24 | 25 | **Refactoring** 26 | 27 | `git checkout -b refactoring-optimize-system-user-list-query` 28 | 29 | As you understand, your branch's name should explain what have you done. 30 | 31 | **Commits** 32 | 33 | Your commits are should be clear. Your commits shouldn't be inconsistent. For example, these are the files you've changed. 34 | 35 | ```bash 36 | system_users.py 37 | 38 | installed_apps.py 39 | ``` 40 | 41 | You should add commit message for each one. 42 | 43 | **Do** 44 | 45 | ```bash 46 | git add system_users.py 47 | 48 | git commit -m "System users changed" 49 | 50 | git add installed_apps.py 51 | 52 | git commit -m "Installed apps changed" 53 | ``` 54 | 55 | **Don't** 56 | 57 | ```bash 58 | git add system_users.py installed_apps.py 59 | 60 | git commit -m "System users changed" 61 | 62 | # or 63 | 64 | git commit -m "System users and installed apps changed" 65 | ``` 66 | 67 | **Don't Forget** 68 | 69 | - Don't be shy to open an issue or send a pull request. No one will judge you. 70 | - You're responsible for your commits. If someone opens an issue about your commit, try to solve. 71 | - Try to write tests for your changes. 72 | - Try to add changelog entry for your changes. 73 | - Try to write a document for your codes. -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from om_core import create_app 2 | 3 | # To do: This place will change later 4 | config = { 5 | "dev": "config.Development", 6 | "prod": "config.Production" 7 | } 8 | 9 | if __name__ == "__main__": 10 | app = create_app(config) 11 | app.run() 12 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | 2 | class BaseConfig(object): 3 | """ Base config class. This fields will use by production and development server """ 4 | 5 | ORIGINS = ["*"] 6 | SECRET_KEY = '4)-.W\xad\x80\x97`\x8e\xc1\xcd\x10\xd7\x11\xd6\x00\xf7M\x89\x18\xceCg' 7 | 8 | 9 | class Development(BaseConfig): 10 | """ Development config. We use Debug mode """ 11 | 12 | PORT = 5000 13 | DEBUG = True 14 | TESTING = False 15 | ENV = 'dev' 16 | APPNAME = "OpenMonitoringDev" 17 | 18 | class Production(BaseConfig): 19 | """ Production config. We use Debug mode false """ 20 | 21 | PORT = 8080 22 | DEBUG = False 23 | TESTING = False 24 | ENV = 'production' 25 | APPNAME = "OpenMonitoringProd" 26 | 27 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | """ 2 | https://flask-migrate.readthedocs.io/en/latest/ 3 | 4 | We use Flask-Migrate to database migrations. 5 | 6 | These are commands to flask-migrate 7 | 8 | python manage.py db init --> init migrations 9 | 10 | python manage.py db migrate --> migrate models 11 | 12 | python manage.py db upgrade --> apply changes 13 | 14 | python manage.py db --help --> :) 15 | """ 16 | from werkzeug import generate_password_hash 17 | 18 | from om_core.data.models import db, User 19 | from om_core import app 20 | from flask_script import Manager 21 | from flask_migrate import Migrate, MigrateCommand 22 | 23 | db.init_app(app) 24 | migrate = Migrate(app, db) 25 | manager = Manager(app) 26 | 27 | manager.add_command('db', MigrateCommand) 28 | 29 | 30 | if __name__ == "__main__": 31 | manager.run() 32 | -------------------------------------------------------------------------------- /om_core/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from flask import Flask 4 | from flask_cors import CORS 5 | from dotenv import load_dotenv 6 | 7 | from config import BaseConfig 8 | 9 | APP_ROOT = os.path.join(os.path.dirname(__file__)) 10 | dotenv_path = os.path.join(APP_ROOT, '.env') 11 | load_dotenv(dotenv_path) 12 | 13 | def create_app(environment): 14 | app = Flask(__name__) 15 | 16 | env = os.getenv("ENV") 17 | 18 | app.config.from_object(environment.get(env)) 19 | 20 | from om_core.api.user.controllers import user 21 | 22 | """ Cors settings will be here. We maybe use this endpoint later. """ 23 | cors = CORS(app, resources={ 24 | r'/api/*': { 25 | 'origins': BaseConfig.ORIGINS 26 | } 27 | }) 28 | 29 | 30 | app.url_map.strict_slashes = False 31 | 32 | 33 | app.register_blueprint(user, url_prefix='/api/users') 34 | 35 | return app 36 | -------------------------------------------------------------------------------- /om_core/api/user/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foss-dev/open-monitoring/4d9112f8f530dd3a6c2bb1341947a71a41a52a31/om_core/api/user/__init__.py -------------------------------------------------------------------------------- /om_core/api/user/controllers.py: -------------------------------------------------------------------------------- 1 | from flask import Blueprint, jsonify, request, current_app 2 | 3 | from om_core.data.models import db, User 4 | 5 | user = Blueprint('user', __name__) 6 | 7 | @user.route('/', methods=['GET']) 8 | def get_users(): 9 | 10 | return jsonify({ "hello": "user" }) 11 | 12 | @user.route('/', methods=['GET']) 13 | def users(id): 14 | 15 | return jsonify({ "id": id }) 16 | 17 | @user.route('/login/', methods=['POST']) 18 | def login(id): 19 | 20 | return jsonify({ "id": id }) 21 | 22 | @user.route('/register/', methods=['POST']) 23 | def register(id): 24 | 25 | return jsonify({ "id": id }) 26 | 27 | @user.route('/update/', methods=['PUT']) 28 | def update(id): 29 | 30 | return jsonify({ "id": id }) 31 | 32 | @user.route('/remove/', methods=['DELETE']) 33 | def delete(id): 34 | 35 | return jsonify({ "id": id }) 36 | -------------------------------------------------------------------------------- /om_core/data/README.md: -------------------------------------------------------------------------------- 1 | # Models 2 | 3 | All data fields will store in the **models.py** file. 4 | 5 | ## Current Model Classes 6 | 7 | These are the current model classes; 8 | 9 | **User** 10 | 11 | This model will work for user operations. -------------------------------------------------------------------------------- /om_core/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foss-dev/open-monitoring/4d9112f8f530dd3a6c2bb1341947a71a41a52a31/om_core/data/__init__.py -------------------------------------------------------------------------------- /om_core/data/models.py: -------------------------------------------------------------------------------- 1 | from flask_sqlalchemy import SQLAlchemy 2 | from om_core import create_app 3 | 4 | # We didn't pass app instance here. 5 | db = SQLAlchemy() 6 | 7 | class User(db.Model): 8 | """ Model for user management """ 9 | 10 | id = db.Column(db.Integer, primary_key=True) 11 | email = db.Column(db.String(100), unique=True) 12 | password = db.Column(db.String(100)) 13 | name = db.Column(db.String(100)) 14 | surname = db.Column(db.String(100)) 15 | active = db.Column(db.Boolean(), default=True) 16 | created_at = db.Column(db.DateTime, default=db.func.now()) 17 | updated_at = db.Column(db.DateTime, default=db.func.now()) 18 | 19 | def __init__(self, email, password, name, surname, active, created_at, updated_at): 20 | self.email = email 21 | self.password = password 22 | self.name = name 23 | self.surname = surname 24 | self.active = active 25 | self.created_at = created_at 26 | self.updated_at = updated_at 27 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | alembic==1.0.10 2 | Click==7.0 3 | Flask==1.0.3 4 | Flask-Cors==3.0.8 5 | Flask-Migrate==2.5.2 6 | Flask-Script==2.0.6 7 | Flask-SQLAlchemy==2.4.0 8 | itsdangerous==1.1.0 9 | Jinja2==2.10.1 10 | Mako==1.0.12 11 | MarkupSafe==1.1.1 12 | python-dateutil==2.8.0 13 | python-dotenv==0.10.3 14 | python-editor==1.0.4 15 | six==1.12.0 16 | SQLAlchemy==1.3.4 17 | Werkzeug==0.15.4 18 | --------------------------------------------------------------------------------