def get_data(endpoint, key=None, tags=None, value=None): headers = auth.get_headers() url = util.get_url(endpoint) try: res = requests.get(url=url, headers=headers['data']) res = res.json() res = res['data'] check = bool(tags) & bool(value) data = list() if key != None and not check: data = list() for i in res: data.append(i[key]) elif key == None and check: data = list() for i in res: if i[tags] == value: data = i elif bool(key) & check: for i in res: if i[tags] == value: data.append(i[key]) else: data = res return util.generate_respons(True, "success", data) except Exception as e: util.log_err(e) return util.generate_respons(False, str(e))
def check_existence(endpoint, var): from libs.auth import get_headers url = get_url(endpoint) key = var_json['key'][endpoint] headers = get_headers() headers = headers['data'] try: result = requests.get(url, headers=headers) result = result.json() msg = result['message'] result = result['data'] except Exception as e: respons = generate_respons(False, str(e)) if result is None: if 'Invalid access token' in msg: respons = generate_respons(False, 'Your token has expired') else: respons = generate_respons(False, "No DNS") else: for i in result: if i[key] == var: respons = generate_respons(True, 'Value already exist', i[key]) break else: respons = generate_respons(False, 'Value doesnt exist') return respons
def send_request(endpoint, data): headers = get_headers() headers = headers['data'] url = get_url(endpoint) try: result = requests.post(url=url, data=json.dumps(data), headers=headers) respons = result.json() except Exception as e: respons = generate_respons(False, str(e)) return respons
def setDefaultDns(name): header = (get_headers())['data'] header['user_id'] = (get_user_id())['data'] res = requests.post("http://103.89.5.121:6968/api/user/dnscreate", data={'domain': str(name)}, headers=header) res = res.json() if 'code' not in res: sys.stderr.write(res['message']) return generate_respons(False, res['message']) tying_zone(header['user_id'], res['data']['data']['id_zone'])
def listing_endpoint(endpoint): with open('libs/templates/var.json', 'r') as f: var_json = json.load(f) url = util.get_url(endpoint) headers = auth.get_headers() result = requests.get(url, headers=headers['data']) result = result.json() result = result['data'] key = var_json['key'][endpoint] st = '' if result: for i in result: st += i[key] + '\t' else: "No value available" return st
def searchId(endpoint, name): data = dict() data = jsonmodel['search'][endpoint]['data'] url = get_url(endpoint) keys = list(data['where']['tags'].keys()) headers = get_headers() headers = headers['data'] for i in keys: if 'id' not in i: key = i data['where']['tags'][key] = str(name) try: res = requests.post(url=url, data=json.dumps(data), headers=headers) res = res.json() res = res['data'] respons = res[0][get_idkey(endpoint, headers=headers)] except Exception as e: return generate_respons(False, str(e)) return generate_respons(True, 'success', respons)
def setDefaultDns(name): header = (get_headers())['data'] header['user_id'] = (get_user_id())['data'] res = requests.post("http://103.89.5.121:6968/api/user/dnscreate", data = {'domain' : str(name)} ,headers=header) print(res) res = res.json() if 'code' not in res : print(res['message']) return False tying_zone(header['user_id'],res['data']['data']['id_zone']) tags = res['data']['data']['id_zone'] syncdat = {"command" : "conf-insert", "tags" : str(tags)} res=sync(syncdat) syncdat = {"command" : "zone-soa-insert", "tags" : str(tags)} res=sync(syncdat) syncdat = {"command" : "zone-ns-insert", "tags" : str(tags)} res=sync(syncdat)
def tying_zone(user_id,id_zone): header = (get_headers())['data'] header['user-id'] = str(user_id) data = {"id_zone" : str(id_zone)} url = get_url('userzone') res = requests.post(url = url, data = data, headers = header)