Beispiel #1
0
    def __init__(self):
        db_name = env("MONGODB_NAME")
        mongo_url = env("MONGODB_URI")

        if 'IS_DOCKER' in os.environ:
            client = MongoClient(27017)
        else:
            client = MongoClient(mongo_url)

        self.mongo_db = client[db_name]
Beispiel #2
0
def check_auth(username, password):
    is_valid_username = username == env('AUTH_USERNAME')
    is_valid_password = password == env('AUTH_PASSWORD')

    return is_valid_username and is_valid_password
Beispiel #3
0
import logging
import sys

from app.utils.env import env

default_level = env('DEFAULT_LOGGING_LEVEL', default=logging.INFO)
default_logging_format = env(
    'DEFAULT_LOGGING_FORMAT',
    default='%(asctime)s - %(name)s - %(levelname)s - %(message)s')


class LoggingService:
    def __init__(self,
                 name: str,
                 *,
                 logging_format: str = default_logging_format,
                 level: int = default_level):
        self.name = name
        self.logging_format = logging_format
        self.level = level

        self._logger = None

    @property
    def logger(self):
        if self._logger:
            return self._logger

        self._logger = self._build_logger()
        return self._logger
Beispiel #4
0
from app.utils.env import env

MONGO_URI = env('MONGODB_URI')

IF_MATCH = False
PAGINATION_LIMIT = 5000
PAGINATION_DEFAULT = 5000

# Enable reads (GET), inserts (POST) and DELETE for resources/collections
# (if you omit this line, the API will default to ['GET'] and provide read-only access to the endpoint).
RESOURCE_METHODS = ['GET', 'POST']  # DELETE

# Enable reads (GET), edits (PATCH) and deletes of individual items (defaults to read-only item access).
ITEM_METHODS = ['GET', 'PATCH', 'DELETE']  # PUT

# Client cache directives for all resources exposed
CACHE_CONTROL = 'max-age=20'
CACHE_EXPIRES = 20

# Cross-Origin Resource Sharing (CORS) => '*'
X_DOMAINS = '*'
X_HEADERS = ['Authorization', 'Content-type']
X_ALLOW_CREDENTIALS = True

github_commits = {
    'schema': {
        'repository': {
            'type': 'string'
        },
        'commit_date': {
            'type': 'string',
Beispiel #5
0
import os

from eve import Eve

from app.controllers.github_controller import register_github_controllers
from app.controllers.school_controller import register_school_controllers
from app.services.logging_service import LoggingService
from app.utils.env import env

logger = LoggingService('app').logger
logger.info("Start Brain-Bit API Application!")

port = int(env('PORT'))
host = env('HOST')

template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')

app = Eve(template_folder=template_dir,
          static_folder=static_dir)

if __name__ == '__main__':
    logger.info("Running Brain-Bit Application!")
    register_github_controllers(app)
    register_school_controllers(app)
    app.run(host=host, port=port, debug=env('DEBUG', default=False))