def send_request(uri, payload=None, passwd_file=None, method=None, es_ser=ES_SERVER, ignore_doc=False): header = {"Content-Type": "application/json"} xuri = uri.split("/") if (not ignore_doc) and (xuri[1] != "_doc"): xuri[1] = "_doc" uri = "/".join(xuri) passwd = es_get_passwd(passwd_file) if not passwd: return False url = "%s/%s" % (es_ser, uri) passman = HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, url, 'cmssdt', passwd) auth_handler = HTTPBasicAuthHandler(passman) opener = build_opener(auth_handler) try: install_opener(opener) request = Request(url, payload, header) if method: request.get_method = lambda: method content = urlopen(request) if method in ["POST", None]: print(content.read()) except Exception as e: print("ERROR:", url, str(e)) print(payload) return False print("OK:", url) return True
def build_jobs(jenkins_url, jobs_data, headers={}, user="******"): for rk in ["OIDC_CLAIM_CERN_UPN"]: if rk not in headers: headers[rk] = user install_opener(build_opener(HTTPCookieProcessor(CookieJar()))) for prams, job in jobs_data: if not job: continue headers = update_crumb(jenkins_url, headers) url = jenkins_url + '/job/' + job + '/build' data = {"json": prams, "Submit": "Build"} try: data = urlencode(data) req = Request(url=url, data=data, headers=headers) content = urlopen(req).read() print("ALL_OK") except Exception as e: print("Unable to start jenkins job: %s" % e)
def send_request(uri, payload=None, passwd_file=None, method=None): passwd = es_get_passwd(passwd_file) if not passwd: return False url = "%s/%s" % (ES_SERVER, uri) passman = HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, url, 'cmssdt', passwd) auth_handler = HTTPBasicAuthHandler(passman) opener = build_opener(auth_handler) try: install_opener(opener) request = Request(url, payload) if method: request.get_method = lambda: method content = urlopen(request) except Exception as e: print("ERROR:", url, str(e)) return False return True
def send_request(uri, payload=None, passwd_file=None, method=None): passwd=es_get_passwd(passwd_file) if not passwd: return False url = "%s/%s" % (ES_SERVER,uri) passman = HTTPPasswordMgrWithDefaultRealm() passman.add_password(None,url, 'cmssdt', passwd) auth_handler = HTTPBasicAuthHandler(passman) opener = build_opener(auth_handler) try: install_opener(opener) request = Request(url, payload) if method: request.get_method = lambda: method content = urlopen(request) except Exception as e: print("ERROR:",url,str(e)) return False return True
def send_request(uri, payload=None, passwd_file=None, method=None, es7=False): es_ser = ES7_SERVER header = {"Content-Type": "application/json"} if not es7: send_request(uri, payload, passwd_file, method, True) header = {} es_ser = ES_SERVER passwd=es_get_passwd(passwd_file) if not passwd: return False url = "%s/%s" % (es_ser,uri) passman = HTTPPasswordMgrWithDefaultRealm() passman.add_password(None,url, 'cmssdt', passwd) auth_handler = HTTPBasicAuthHandler(passman) opener = build_opener(auth_handler) try: install_opener(opener) request = Request(url, payload, header) if method: request.get_method = lambda: method content = urlopen(request) except Exception as e: print("ERROR:",url,str(e)) return False if es7: print("OK:",url) return True