def api_coprs_by_owner_detail(copr): """ Return detail of one project. :arg username: the username of the person one would like to the coprs of. :arg coprname: the name of project. """ release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" output = {"output": "ok", "detail": {}} yum_repos = {} build = models.Build.query.filter(models.Build.copr_id == copr.id).first() if build: for chroot in copr.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( os.path.join(build.copr.repo_url, release + '/')) output["detail"] = { "name": copr.name, "additional_repos": copr.repos, "yum_repos": yum_repos, "description": copr.description, "instructions": copr.instructions, "last_modified": builds_logic.BuildsLogic.last_modified(copr), "auto_createrepo": copr.auto_createrepo, "persistent": copr.persistent, "unlisted_on_hp": copr.unlisted_on_hp, "auto_prune": copr.auto_prune, "use_bootstrap_container": copr.use_bootstrap_container, } return flask.jsonify(output)
def api_coprs_by_owner_detail(copr): """ Return detail of one project. :arg username: the username of the person one would like to the coprs of. :arg coprname: the name of project. """ release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" output = {"output": "ok", "detail": {}} yum_repos = {} for build in copr.builds: if build.results: for chroot in copr.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( os.path.join(build.results, release + '/')) break output["detail"] = { "name": copr.name, "additional_repos": copr.repos, "yum_repos": yum_repos, "description": copr.description, "instructions": copr.instructions, "last_modified": builds_logic.BuildsLogic.last_modified(copr), "auto_createrepo": copr.auto_createrepo, } return flask.jsonify(output)
def get_yum_repos(cls, copr, empty=False): repos = {} release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" build = models.Build.query.filter( models.Build.copr_id == copr.id).first() if build or empty: for chroot in copr.active_chroots: release = release_tmpl.format(chroot=chroot) repos[release] = fix_protocol_for_backend( os.path.join(copr.repo_url, release + '/')) return repos
def api_coprs_by_owner(username=None): """ Return the list of coprs owned by the given user. username is taken either from GET params or from the URL itself (in this order). :arg username: the username of the person one would like to the coprs of. """ username = flask.request.args.get("username", None) or username if username is None: raise LegacyApiError("Invalid request: missing `username` ") release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" if username.startswith("@"): group_name = username[1:] query = CoprsLogic.get_multiple() query = CoprsLogic.filter_by_group_name(query, group_name) else: query = CoprsLogic.get_multiple_owned_by_username(username) query = CoprsLogic.join_builds(query) query = CoprsLogic.set_query_order(query) repos = query.all() output = {"output": "ok", "repos": []} for repo in repos: yum_repos = {} for build in repo.builds: # FIXME in new api! for chroot in repo.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( os.path.join(build.copr.repo_url, release + '/')) break output["repos"].append({ "name": repo.name, "additional_repos": repo.repos, "yum_repos": yum_repos, "description": repo.description, "instructions": repo.instructions, "persistent": repo.persistent, "unlisted_on_hp": repo.unlisted_on_hp, "auto_prune": repo.auto_prune, }) return flask.jsonify(output)
def api_coprs_by_owner(username=None): """ Return the list of coprs owned by the given user. username is taken either from GET params or from the URL itself (in this order). :arg username: the username of the person one would like to the coprs of. """ username = flask.request.args.get("username", None) or username if username is None: raise LegacyApiError("Invalid request: missing `username` ") release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" if username.startswith("@"): group_name = username[1:] query = CoprsLogic.get_multiple() query = CoprsLogic.filter_by_group_name(query, group_name) else: query = CoprsLogic.get_multiple_owned_by_username(username) query = CoprsLogic.join_builds(query) query = CoprsLogic.set_query_order(query) repos = query.all() output = {"output": "ok", "repos": []} for repo in repos: yum_repos = {} for build in repo.builds: if build.results: for chroot in repo.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( os.path.join(build.results, release + '/')) break output["repos"].append({"name": repo.name, "additional_repos": repo.repos, "yum_repos": yum_repos, "description": repo.description, "instructions": repo.instructions}) return flask.jsonify(output)
def api_coprs_by_owner(username=None): """ Return the list of coprs owned by the given user. username is taken either from GET params or from the URL itself (in this order). :arg username: the username of the person one would like to the coprs of. """ username = flask.request.args.get("username", None) or username release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" httpcode = 200 if username: query = coprs_logic.CoprsLogic.get_multiple(flask.g.user, user_relation="owned", username=username, with_builds=True) repos = query.all() output = {"output": "ok", "repos": []} for repo in repos: yum_repos = {} for build in repo.builds: if build.results: for chroot in repo.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( urlparse.urljoin(build.results, release + '/')) break output["repos"].append({ "name": repo.name, "additional_repos": repo.repos, "yum_repos": yum_repos, "description": repo.description, "instructions": repo.instructions }) else: output = {"output": "notok", "error": "Invalid request"} httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout
def api_coprs_by_owner(username=None): """ Return the list of coprs owned by the given user. username is taken either from GET params or from the URL itself (in this order). :arg username: the username of the person one would like to the coprs of. """ username = flask.request.args.get("username", None) or username release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" httpcode = 200 if username: query = coprs_logic.CoprsLogic.get_multiple( flask.g.user, user_relation="owned", username=username, with_builds=True) repos = query.all() output = {"output": "ok", "repos": []} for repo in repos: yum_repos = {} for build in repo.builds: if build.results: for chroot in repo.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( urlparse.urljoin(build.results, release + '/')) break output["repos"].append({"name": repo.name, "additional_repos": repo.repos, "yum_repos": yum_repos, "description": repo.description, "instructions": repo.instructions}) else: output = {"output": "notok", "error": "Invalid request"} httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout
def api_coprs_by_owner_detail(username, coprname): """ Return detail of one project. :arg username: the username of the person one would like to the coprs of. :arg coprname: the name of project. """ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" httpcode = 200 if username and copr: output = {"output": "ok", "detail": {}} yum_repos = {} for build in copr.builds: if build.results: for chroot in copr.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( urlparse.urljoin(build.results, release + '/')) break output["detail"] = { "name": copr.name, "additional_repos": copr.repos, "yum_repos": yum_repos, "description": copr.description, "instructions": copr.instructions, "last_modified": builds_logic.BuildsLogic.last_modified(copr), "auto_createrepo": copr.auto_createrepo, } else: output = { "output": "notok", "error": "Copr with name {0} does not exist.".format(coprname) } httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout
def api_coprs_by_owner_detail(username, coprname): """ Return detail of one project. :arg username: the username of the person one would like to the coprs of. :arg coprname: the name of project. """ copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() release_tmpl = "{chroot.os_release}-{chroot.os_version}-{chroot.arch}" httpcode = 200 if username and copr: output = {"output": "ok", "detail": {}} yum_repos = {} for build in copr.builds: if build.results: for chroot in copr.active_chroots: release = release_tmpl.format(chroot=chroot) yum_repos[release] = fix_protocol_for_backend( urlparse.urljoin(build.results, release + '/')) break output["detail"] = { "name": copr.name, "additional_repos": copr.repos, "yum_repos": yum_repos, "description": copr.description, "instructions": copr.instructions, "last_modified": builds_logic.BuildsLogic.last_modified(copr), "auto_createrepo": copr.auto_createrepo, } else: output = {"output": "notok", "error": "Copr with name {0} does not exist.".format(coprname)} httpcode = 500 jsonout = flask.jsonify(output) jsonout.status_code = httpcode return jsonout
def test_fix_protocol_for_backend(self): http_url = "http://example.com/repo" https_url = "https://example.com/repo" orig = app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] try: app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = "https" assert fix_protocol_for_backend(https_url) == https_url assert fix_protocol_for_backend(http_url) == https_url app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = "http" assert fix_protocol_for_backend(https_url) == http_url assert fix_protocol_for_backend(http_url) == http_url app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = None assert fix_protocol_for_backend(https_url) == https_url assert fix_protocol_for_backend(http_url) == http_url except Exception as e: app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig raise e app.config["ENFORCE_PROTOCOL_FOR_BACKEND_URL"] = orig
def fix_url_https_backend(url): return helpers.fix_protocol_for_backend(url)
def fix_url_https_backend(url): if app.config.get('REPO_NO_SSL', False): return url.replace('https://', 'http://') return helpers.fix_protocol_for_backend(url)