Skip to content

Commit

Permalink
Deprecate API version 1.0
Browse files Browse the repository at this point in the history
Adding new capability to mark API versions as "deprecated" which will
be displayed when verifier and registrar start and a warning is issued
anytime a client (agent or tenant) uses a deprecated API.

This will allow us to mark APIs as deprecated before they are fully removed.

Signed-off-by: Michael Peters <[email protected]>
  • Loading branch information
mpeters authored and THS-on committed Apr 18, 2022
1 parent 93d1e65 commit ce0fc0a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
7 changes: 7 additions & 0 deletions keylime/api_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"1": "1.0",
"2": "2.0"
}
DEPRECATED_VERSIONS = ["1.0"]

def current_version():
return CURRENT_VERSION
Expand All @@ -36,6 +37,10 @@ def is_supported_version(v):
v_obj = version.parse(str(v))
return v_obj.base_version in VERSIONS

def is_deprecated_version(v):
v_obj = version.parse(str(v))
return is_supported_version(v) and v_obj.base_version in DEPRECATED_VERSIONS

def normalize_version(v):
v = str(v)
v = v.strip('/')
Expand All @@ -59,6 +64,8 @@ def log_api_versions(logger):
versions.remove(CURRENT_VERSION)
if versions:
logger.info('Supported older API versions: ' + ", ".join(versions))
if DEPRECATED_VERSIONS:
logger.info("Deprecated API versions (soon to be removed): " + ", ".join(DEPRECATED_VERSIONS))


def validate_version(v: str) -> bool:
Expand Down
21 changes: 7 additions & 14 deletions keylime/cloud_verifier_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ def get(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -329,8 +328,7 @@ def delete(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -405,8 +403,7 @@ def post(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -547,8 +544,7 @@ def put(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -633,8 +629,7 @@ def get(self):
web_util.echo_json_response(self, 400, "Invalid URL")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

allowlist_name = rest_params['allowlists']
Expand Down Expand Up @@ -672,8 +667,7 @@ def delete(self):
web_util.echo_json_response(self, 400, "Invalid URL")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

allowlist_name = rest_params['allowlists']
Expand Down Expand Up @@ -724,8 +718,7 @@ def post(self):
web_util.echo_json_response(self, 400, "Invalid URL")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

allowlist_name = rest_params['allowlists']
Expand Down
12 changes: 4 additions & 8 deletions keylime/registrar_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def do_GET(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -146,8 +145,7 @@ def do_DELETE(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -232,8 +230,7 @@ def do_POST(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down Expand Up @@ -419,8 +416,7 @@ def do_PUT(self):
self, 405, "Not Implemented: Use /agents/ interface")
return

if not rest_params["api_version"]:
web_util.echo_json_response(self, 400, "API Version not supported")
if not web_util.validate_api_version(self, rest_params["api_version"], logger):
return

if "agents" not in rest_params:
Expand Down
10 changes: 10 additions & 0 deletions keylime/web_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ def get_restful_params(urlstring):
return path_params


def validate_api_version(handler, version, logger):
if not version or not keylime_api_version.is_supported_version(version):
echo_json_response(handler, 400, "API Version not supported")
return False

if keylime_api_version.is_deprecated_version(version):
logger.warning('Client request to API version %s is deprecated and will be removed in future versions.', version)
return True


def _list_to_dict(alist):
"""Convert list into dictionary via grouping [k0,v0,k1,v1,...]"""
params = {}
Expand Down

0 comments on commit ce0fc0a

Please sign in to comment.