コード例 #1
0
 Muzika backend server generates a random message and give it to user who wants to sign in. The user signs the message
 by the user's wallet and send it back to the server. It checks validation of the signing message and if validated give
 a JWT token to the user.
"""

import hashlib

import jwt
from sqlalchemy import text

from config import AppConfig
from modules import database as db
from modules.secret import load_secret_json

jwt_json = load_secret_json('jwt')
s3_policy = load_secret_json('aws')['s3']

JWT_SECRET_KEY = jwt_json['jwt_secret_key']

PLATFORM_TYPES = ['electron', 'app', 'web']


def generate_jwt_token(connection,
                       web3,
                       address,
                       signature,
                       protocol='eth',
                       **kwargs):
    """
    Validate the user signature and if authenticated, generate a new JWT token for the user.
コード例 #2
0
from sqlalchemy import create_engine
from sqlalchemy.engine import RowProxy, ResultProxy
from sqlalchemy.engine.url import URL

from modules.db_orm.statement import Statement
from modules.db_orm.table import Table, BOARD_TYPE_LIST
from modules.secret import load_secret_json

__all__ = [
    'engine_rdonly', 'engine_rdwr',
    'to_relation_model', 'to_relation_model_list',
    'statement', 'table'
]

db_secret = load_secret_json('database')

try:
    rdonly_db_url = URL(**db_secret['db_rdonly']) if db_secret else None
except KeyError:
    rdonly_db_url = URL(**db_secret['db_rdwr']) if db_secret else None
rdwr_db_url = URL(**db_secret['db_rdwr']) if db_secret else None

# define db engines
engine_rdonly = create_engine(rdonly_db_url, encoding='utf-8', pool_recycle=290)
engine_rdwr = create_engine(rdwr_db_url, encoding='utf-8', pool_recycle=290)


def to_relation_model(row):
    """
    Returns a dict that represents a row in database. Since a row can be related with other table, it can be
コード例 #3
0
from flask import Blueprint, request
from sqlalchemy import text

from modules import database as db
from modules.aws import MuzikaS3Bucket
from modules.login import jwt_check
from modules.response import helper
from modules.response.error import ERR
from modules.secret import load_secret_json

blueprint = Blueprint('file', __name__, url_prefix='/api')

# load S3 policy.
s3_policy = load_secret_json('aws.json')['s3']


@blueprint.route('/file', methods=['POST'])
@jwt_check
def _upload_file():
    """
    uploads a file. (Only one file is allowed at once)
    """
    user_id = request.user['user_id']
    file_type = request.values.get('type')

    # if the number of files uploaded is not one
    if len(request.files) != 1:
        return helper.response_err(ERR.COMMON.INVALID_REQUEST_BODY)

    # if not support file type
    if file_type not in s3_policy:
コード例 #4
0
 the "secret" directory, it uses the configuration in it (credential object in json file), and if not, use aws
 credentials file. If aws credentials file used, the profile name should be "muzika".

 For creating aws credentials file, install AWS CLI and use the command like below.

 > aws configure --profile muzika
 > ...
"""

import boto3
from sqlalchemy import text

from modules import database as db
from modules.secret import load_secret_json

aws_config = load_secret_json('aws')
_credential = aws_config.get('credential')

# if credential is not configured in secret json file
if _credential is None:
    # load credentials from credentials profile
    session = boto3.Session()
else:
    # else, configure from secret json file
    session = boto3.Session(**_credential)


class MuzikaS3Bucket(object):
    """
    This class loads configuration from secret file and helps to put or to get objects from S3 bucket.
    """
コード例 #5
0
 Muzika backend server generates a random message and give it to user who wants to sign in. The user signs the message
 by the user's wallet and send it back to the server. It checks validation of the signing message and if validated give
 a JWT token to the user.
"""

import hashlib

import jwt
from sqlalchemy import text

from config import WebServerConfig
from modules import database as db
from modules.secret import load_secret_json

jwt_json = load_secret_json('jwt')

JWT_SECRET_KEY = jwt_json['jwt_secret_key']


PLATFORM_TYPES = ['electron', 'app']


def generate_jwt_token(connection, web3, address, signature, **kwargs):
    """
    Validate the user signature and if authenticated, generate a new JWT token for the user.

    :param connection: database connection.
    :param web3: web3(ethereum) instance.
    :param address: the wallet address of the user.
    :param signature_version: signature creation type (Trezur, Metamask signature creation type)