Example #1
0
 def post(self, request, format=None):
     result = {'col': '', 'results': ''}
     # inception连接信息
     inception_info = {
         'conn_host': '',
         'conn_port': '',
         'conn_user': '',
         'conn_passwd': ''
     }
     inception_info['conn_host'] = get_conf('inception', 'inc_host')
     inception_info['conn_port'] = get_conf('inception', 'inc_port')
     inception_info['conn_user'] = get_conf('inception', 'inc_user')
     inception_info['conn_passwd'] = get_conf('inception', 'inc_password')
     dbapi = db_api()
     inception_type = request.data['type']
     if (inception_type == 'check'):
         inception_sql_data = request.data['sql_data']
         inst_id = inception_sql_data['dbname'][0]
         dbname = inception_sql_data['dbname'][1]
         instinfo = MySQLInst.objects.get(Q(id=inst_id))
         sql = inception_sql_data['sqltext']
         check_sql = '/*--user=%s;--password=%s;--host=%s;--enable-check;--enable-remote-backup;--port=%d;*/inception_magic_start;use %s;%sinception_magic_commit;' % (
             instinfo.manage_user, instinfo.manage_userpwd,
             instinfo.inst_host, instinfo.inst_port, dbname, sql)
         print(check_sql)
         col, results = dbapi.inception(inception_info, check_sql)
         print(col, results)
         check_info = []
         for info in results:
             if (info['errlevel'] != 0):
                 check_info.append(info)
         result['col'] = col
         result['results'] = check_info
     return Response(result)
Example #2
0
    def inception_exec(self, sqlorderid):
        # inception连接信息
        inception_info = {
            'conn_host': '',
            'conn_port': '',
            'conn_user': '',
            'conn_passwd': ''
        }
        inception_info['conn_host'] = get_conf('inception', 'inc_host')
        inception_info['conn_port'] = get_conf('inception', 'inc_port')
        inception_info['conn_user'] = get_conf('inception', 'inc_user')
        inception_info['conn_passwd'] = get_conf('inception', 'inc_password')
        dbapi = db_api()
        sqlorder = SqlOrder.objects.get(Q(id=sqlorderid))
        sqlordererror = 0
        for sqlinfo in sqlorder.sqlorder_sqltext.all():
            # 执行sql信息
            # 执行数据库
            dbname = sqlinfo.dbname
            instinfo = sqlinfo.instid
            # sql
            sql = sqlinfo.sqltext
            exec_sql = '/*--user=%s;--password=%s;--host=%s;--enable-execute;--enable-remote-backup;--port=%d;*/inception_magic_start;use %s;%sinception_magic_commit;' % (
                instinfo.manage_user, instinfo.manage_userpwd,
                instinfo.inst_host, instinfo.inst_port, dbname, sql)
            col, results = dbapi.inception(inception_info, exec_sql)
            sqlexecstatus = 1

            for info in results:
                if (info['errlevel'] != 0):
                    sqlordererror = sqlordererror + 1
                    sqlexecstatus = -1
            SqlText.objects.filter(Q(id=sqlinfo.id)).update(
                info=results, sqlstatus=sqlexecstatus)
        return sqlordererror
Example #3
0
 def __init__(self):
     # self.gitlab_url = 'http://git.xs.jf'
     # self.gitlab_token = 'vV9F9eFJNcg9jPHkxs_B'
     self.gitlab_url = get_conf('gitlab', 'url')
     self.gitlab_token = get_conf('gitlab', 'token')
     self.gl = gitlab.Gitlab(self.gitlab_url,
                             private_token=self.gitlab_token,
                             api_version=3)
Example #4
0
def get_env():

    env = get_conf('deployment', 'environment')
    return env
Example #5
0
# coding=utf-8
from rest_framework import permissions
from user.utils import init_permissions
from utils.get_config import get_conf

SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')

ENVIRONMENT_LIST = [['alidns:DnsRecords']]

ENVIRONMENT = get_conf('deployment', 'environment')


class CustomerPremission(permissions.DjangoModelPermissions):
    """
    自定义权限
    """
    message = 'No Permission to Access.'

    def has_permission(self, request, view):
        patch_map = 'patch'
        deletel_map = 'deletel'
        post_map = 'post'
        need_perms = ''
        module_perms = view.module_perms
        if (ENVIRONMENT == 'dev'):
            if ((module_perms in ENVIRONMENT_LIST)
                    and (request.method not in SAFE_METHODS)):
                return False
            else:
                user_perms = init_permissions(request.user, 'perms')
                if (request.user.is_superuser):
Example #6
0
    def __init__(self):

        self.gitlab_url = get_conf('gitlab','url')
        self.gitlab_token = get_conf('gitlab','token')
        self.gl = gitlab.Gitlab(self.gitlab_url,private_token=self.gitlab_token,api_version=3)