From 93d084b30a75b3f888a55ab4a910a750dd5d7e15 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 8 Aug 2018 17:52:21 -0400 Subject: [PATCH] Add error IDs for common source-related errors. (cherry picked from commit e43adfc7afb5d89bd062ac9d0f06586b60b271c7) --- src/pylorax/api/errors.py | 6 ++++++ src/pylorax/api/v0.py | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pylorax/api/errors.py b/src/pylorax/api/errors.py index d1296240..7509a25e 100644 --- a/src/pylorax/api/errors.py +++ b/src/pylorax/api/errors.py @@ -29,6 +29,9 @@ BUILD_IN_WRONG_STATE = "BuildInWrongState" # given that contains invalid characters. INVALID_NAME = "InvalidName" +# Returned from the API when someone tries to modify an immutable system source. +SYSTEM_SOURCE = "SystemSource" + # Returned from the API when a blueprint that was requested does not exist. UNKNOWN_BLUEPRINT = "UnknownBlueprint" @@ -41,5 +44,8 @@ UNKNOWN_MODULE = "UnknownModule" # Returned from the API when a project that was requested does not exist. UNKNOWN_PROJECT = "UnknownProject" +# Returned from the API when a source that was requested does not exist. +UNKNOWN_SOURCE = "UnknownSource" + # Returned from the API when a UUID that was requested does not exist. UNKNOWN_UUID = "UnknownUUID" diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index d07ed716..502f42b5 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -1572,7 +1572,7 @@ def v0_api(api): with api.config["DNFLOCK"].lock: repo = api.config["DNFLOCK"].dbo.repos.get(source, None) if not repo: - errors.append("%s is not a valid source" % source) + errors.append({"id": UNKNOWN_SOURCE, "msg": "%s is not a valid source" % source}) continue sources[repo.id] = repo_to_source(repo, repo.id in system_sources) @@ -1596,7 +1596,7 @@ def v0_api(api): system_sources = get_repo_sources("/etc/yum.repos.d/*.repo") if source["name"] in system_sources: - return jsonify(status=False, errors=["%s is a system source, it cannot be changed." % source["name"]]), 400 + return jsonify(status=False, errors=[{"id": SYSTEM_SOURCE, "msg": "%s is a system source, it cannot be changed." % source["name"]}]), 400 try: # Remove it from the RepoDict (NOTE that this isn't explicitly supported by the DNF API) @@ -1656,7 +1656,7 @@ def v0_api(api): system_sources = get_repo_sources("/etc/yum.repos.d/*.repo") if source_name in system_sources: - return jsonify(status=False, errors=["%s is a system source, it cannot be deleted." % source_name]), 400 + return jsonify(status=False, errors=[{"id": SYSTEM_SOURCE, "msg": "%s is a system source, it cannot be deleted." % source_name}]), 400 share_dir = api.config["COMPOSER_CFG"].get("composer", "repo_dir") try: # Remove the file entry for the source @@ -1672,7 +1672,7 @@ def v0_api(api): except ProjectsError as e: log.error("(v0_projects_source_delete) %s", str(e)) - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": UNKNOWN_SOURCE, "msg": str(e)}]), 400 return jsonify(status=True)