def get_project_token_and_catalog(project_id): resp = global_config.get_http().get('/api/project/token', project_id=project_id) resp = Bunch(resp) project_token = resp.data resp = global_config.get_http().get('/api/interface/getCatMenu', True, False, project_id=project_id, token=project_token) resp = Bunch(resp) return {d['name']: d['_id'] for d in resp.data}
def get_total_apis(project_id, catalog_id, page=1, limit=100): """ 根据项目id获取该项目的所有接口 :param project_id: 项目id :param catalog_id: 项目下的某个分组 :param page: 分页 :param limit: 每页条数 :return: """ resp = global_config.get_http().get('/api/project/token', project_id=project_id) resp = Bunch(resp) project_token = resp.data apis = [] resp = global_config.get_http().get('/api/interface/list_cat', True, False, catid=catalog_id, token=project_token, page=page, limit=limit) for _, data in enumerate(resp['data']['list']): apis.append(data['_id']) return apis, project_token
def get_project_by_signal_group(group_id, page=1, limit=100): resp = global_config.get_http().get('/api/project/list', group_id=group_id, page=page, limit=limit) resp = Bunch(resp) return {d['name']: d['_id'] for d in resp.data.list}
def get_project_groups(): resp = global_config.get_http().get('/api/group/list', flag=False) resp = Bunch(resp) return {d['group_name']: d['_id'] for d in resp.data}
def get_singal_api(func, project_id, catalog_id): """ 获取详细接口数据 :param func: :param project_id: :param catalog_id :return: """ apis, token = func(project_id, catalog_id) for api in apis: resp = global_config.get_http().get('/api/interface/get', cookie_need_flag=False, id=api, token=token) resp = Bunch(resp) # 详细接口数据 path = resp.data.path # 请求路径 http_method = resp.data.method # 请求方法 if "rpc" not in path: method = path.split('/')[-1] raw_req_body = {} if "GET" == http_method: query_strings = {query['name']: query['example'] for query in resp.data.req_query} raw_req_body.update(query_strings) else: if 'req_body_other' in resp.data: # 请求参数写的是json格式 # req_body_other = re.sub(r'//.*', '', resp.data.req_body_other) # 如果有注释先过滤掉 # req_body_temp = req_body_other.replace('\n', '').replace(' ', '') # 请求body(过滤掉所有\n,空格) req_body_temp = re.sub(r'(//.*)|(\s)', '', resp.data.req_body_other) req_body_dict = json.loads(req_body_temp) elif 'req_body_form' in resp.data: # 请求参数写在form里 req_body_dict = {req_body['name']: req_body['example'] for req_body in resp.data.req_body_form} raw_req_body.update(req_body_dict) req_body = _template_method(method, **raw_req_body) else: if 'req_body_other' in resp.data: # req_body_other = re.sub(r'//.*', '', resp.data.req_body_other) # req_body_temp = req_body_other.replace('\n', '').replace(' ', '') req_body_temp = re.sub(r'(//.*)|(\s)', '', resp.data.req_body_other) try: req_body_dict = json.loads(req_body_temp) method = req_body_dict['method'] if isinstance(req_body_dict['params'][0], dict): rpc_params = req_body_dict['params'][0] req_body = _template_method(method, **rpc_params) else: rpc_params = req_body_dict['params'] req_body = _template_method(method, *rpc_params) except: method, req_body = None, None # if resp.data.title.isalpha(): # rpc_method = came_case_to_lower_case(resp.data.title) # else: # rpc_method = None yield req_body
def do_login(username, password): global_config.get_http().login('/api/user/login_by_ldap', user=username, password=password)