Beispiel #1
0
def do_get_request(env):
    body = ""
    fields = parse_formvars(env)
    if fields.has_key('byUser'):
        user = fields['byUser']
        try:
            body = get_priv_by_user(user)
            code = rdserr.CODE_SUCCESS
        except Exception, e:
            log.error("[auth mng][do_get_request] Exception %s" % (e))
            code = rdserr.map_exception_to_code(int(e[0]))
Beispiel #2
0
def do_delete_request(env):
    # params:
    name = None
    fields = parse_formvars(env)
    if fields.has_key('nmDB'):
        name = fields['nmDB']
    if name == None or name.strip() == "":
        code = rdserr.CODE_ERROR_PARAMS
    else:
        try:
            # revoke from dba
            if judge_db_exist(name):
                # Todo...
                pass
            if 0 == drop_db(name):
                code = rdserr.CODE_SUCCESS
        except Exception, e:
            log.error("[db mng][do_delete_request] Exception %s" % (e))
            code = rdserr.map_exception_to_code(int(e[0]))
Beispiel #3
0
def do_get_request(env):
    # params
    islist = False
    fields = parse_formvars(env)
    if fields.has_key('list'):
        islist = True
    else:
        code = rdserr.CODE_ERROR_PARAMS
        dbs = ''

    if islist:
        # list databases:
        try:
            dbs = list_dbs()
            code = rdserr.CODE_SUCCESS
        except Exception, e:
            log.error("[db mng][do_get_request] Exception %s" % (e))
            code = rdserr.map_exception_to_code(int(e[0]))
            dbs = ''
Beispiel #4
0
def do_post_request(env):
    # params:
    fields = parse_formvars(env)
    if fields.has_key('nmDB') and fields.has_key('defCharacterSetDB'):
        name = fields['nmDB']
        charset = fields['defCharacterSetDB']
        if name == None or name.strip(
        ) == "" or charset == None or charset.strip() == "":
            code = rdserr.CODE_ERROR_PARAMS
        else:
            try:
                created_success = False
                # judge db exist
                if judge_db_exist(name):
                    code = rdserr.CODE_SUCCESS_DB_EXISTS
                # judge charset valid
                elif not judge_charset_valid(charset):
                    code = rdserr.CODE_ERROR_DB_CHARSET
                else:
                    # create db
                    if 0 == create_db(name, charset):
                        created_success = True
                        code = rdserr.CODE_SUCCESS
                # grant to dba
                if judge_db_exist(name):
                    #Todo...grant db to dba
                    grant('dba', name, 'RW')
                    pass
                else:
                    code = rdserr.CODE_ERROR_DB_CREATE
            except Exception, e:
                log.error("[db mng][do_post_request] Exception %s" % (e))
                code = rdserr.map_exception_to_code(int(e[0]))
                if created_success:
                    try:
                        dbmng_drop_db(name)
                    except Exception, e:
                        log.warning(
                            "[db mng][do_post_request] Exception Drop db %s" %
                            (e))
Beispiel #5
0
def do_put_request(env):
    body = ""
    req_body = None
    # params:
    fields = parse_formvars(env)
    if fields.has_key('grant') and None != env['wsgi.input']:
        req_body = env['wsgi.input'].read(int(env['CONTENT_LENGTH']))
        if req_body == None or req_body == "":
            code = rdserr.CODE_ERROR_PARAMS
        else:
            # grant operation:
            try:
                log.debug("--------here------------%s, %s" %
                          (type(req_body), req_body))
                ret_data = do_grant_operation(req_body)
                code = ret_data['code']
                body = ret_data['result']
            except Exception, e:
                log.error(
                    "[auth mng][do_put_request] grant operation Exception %s" %
                    (e))
                code = rdserr.map_exception_to_code(int(e[0]))
Beispiel #6
0
                code = rdserr.map_exception_to_code(int(e[0]))
    elif fields.has_key('revoke') and None != env['wsgi.input']:
        req_body = env['wsgi.input'].read(int(env['CONTENT_LENGTH']))
        if req_body == None or req_body == "":
            code = rdserr.CODE_ERROR_PARAMS
        else:
            # revoke operation:
            try:
                ret_data = do_revoke_operation(req_body)
                code = ret_data['code']
                body = ret_data['result']
            except Exception, e:
                log.error(
                    "[auth mng][do_put_request] revoke operation Exception %s"
                    % (e))
                code = rdserr.map_exception_to_code(int(e[0]))
    else:
        code = rdserr.CODE_ERROR_PARAMS
    ret = {u'code': code, u'str': rdserr.get_str_by_code(code), u'body': body}
    return ret


def do_get_request(env):
    body = ""
    fields = parse_formvars(env)
    if fields.has_key('byUser'):
        user = fields['byUser']
        try:
            body = get_priv_by_user(user)
            code = rdserr.CODE_SUCCESS
        except Exception, e: