def decorated_function(*args, **kwargs): token = None apt_login = None if "Authorization" in flask.request.headers: base64string = flask.request.headers["Authorization"] base64string = base64string.split()[1].strip() userstring = base64.b64decode(base64string) (apt_login, token) = userstring.decode("utf-8").split(":") token_auth = False if token and apt_login: user = UsersLogic.get_by_api_login(apt_login).first() if (user and user.api_token == token and user.api_token_expiration >= datetime.date.today()): if user.proxy and "username" in flask.request.form: user = UsersLogic.get( flask.request.form["username"]).first() token_auth = True flask.g.user = user if not token_auth: url = 'https://' + app.config["PUBLIC_COPR_HOSTNAME"] url = helpers.fix_protocol_for_frontend(url) output = { "output": "notok", "error": "Login invalid/expired. Please visit {0}/api to get or renew your API token." .format(url), } jsonout = flask.jsonify(output) jsonout.status_code = 401 return jsonout return f(*args, **kwargs)
def __init__(self, copr_chroots): """ :param models.Copr copr: :param list copr_chroots: list of models.CoprChroot instances """ self.subject = "[Copr] upcoming deletion of outdated chroots in your projects" self.text = ( "You have been notified because you are an admin of projects, " "that have some builds in outdated chroots\n\n" "According to the 'Copr outdated chroots removal policy'\n" "https://docs.pagure.org/copr.copr/copr_outdated_chroots_removal_policy.html\n" "data are going to be preserved {0} days after the chroot is EOL " "and then automatically deleted, unless you decide to prolong the expiration period.\n\n" "Please, visit the projects settings if you want to extend the time.\n\n" .format(app.config["DELETE_EOL_CHROOTS_AFTER"])) if not copr_chroots: raise AttributeError("No outdated chroots to notify about") for chroot in copr_chroots: url = helpers.fix_protocol_for_frontend( helpers.copr_url('coprs_ns.copr_repositories', chroot.copr, _external=True)) self.text += ("Project: {0}\n" "Chroot: {1}\n" "Remaining: {2} days\n" "{3}\n\n".format(chroot.copr.full_name, chroot.name, chroot.delete_after_days, url))
def repo_url(url): """ render copr://<user>/prj to be rendered as copr projects pages """ parsed = urlparse(url) if parsed.scheme == "copr": user = parsed.netloc prj = parsed.path.split("/")[1] url = url_for("coprs_ns.copr_detail", username=user, coprname=prj) return helpers.fix_protocol_for_frontend(url)
def repo_url(url): """ render copr://<user>/prj to be rendered as copr projects pages """ parsed = urlparse(url) if parsed.scheme == "copr": user = parsed.netloc prj = parsed.path.split("/")[1] url = url_for("coprs_ns.copr_detail", username=user, coprname=prj) return helpers.fix_protocol_for_frontend(url)
def repo_url(url): """ render copr://<user>/<prj> or copr://g/<group>/<prj> to be rendered as copr projects pages """ parsed = urlparse(url) if parsed.scheme == "copr": owner = parsed.netloc prj = parsed.path.split("/")[1] if owner[0] == '@': url = url_for("coprs_ns.copr_detail", group_name=owner[1:], coprname=prj) else: url = url_for("coprs_ns.copr_detail", username=owner, coprname=prj) return helpers.fix_protocol_for_frontend(url)
def test_fix_protocol_for_frontend(self): http_url = "http://example.com/repo" https_url = "https://example.com/repo" orig = app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] try: app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = "https" assert fix_protocol_for_frontend(https_url) == https_url assert fix_protocol_for_frontend(http_url) == https_url app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = "http" assert fix_protocol_for_frontend(https_url) == http_url assert fix_protocol_for_frontend(http_url) == http_url app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = None assert fix_protocol_for_frontend(https_url) == https_url assert fix_protocol_for_frontend(http_url) == http_url except Exception as e: app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = orig raise e app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
def test_fix_protocol_for_frontend(self): http_url = "http://example.com/repo" https_url = "https://example.com/repo" orig = app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] try: app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = "https" assert fix_protocol_for_frontend(https_url) == https_url assert fix_protocol_for_frontend(http_url) == https_url app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = "http" assert fix_protocol_for_frontend(https_url) == http_url assert fix_protocol_for_frontend(http_url) == http_url app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = None assert fix_protocol_for_frontend(https_url) == https_url assert fix_protocol_for_frontend(http_url) == http_url except Exception as e: app.config["ENFORCE_PROTOCOL_FOR_FRONTEND_URL"] = orig raise e app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
def fix_url_https_frontend(url): return helpers.fix_protocol_for_frontend(url)
def fix_url_https_frontend(url): return helpers.fix_protocol_for_frontend(url)