1 # -------------------------------------------------------------------------
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
19 from collections import defaultdict
20 from osdf.logging.osdf_logging import debug_log
21 from osdf.config.base import osdf_config
24 def retrieve_version_info(request, request_id):
25 version_info_dict = defaultdict(dict)
26 config = osdf_config.deployment
27 placement_ver_enabled = config.get('placementVersioningEnabled', False)
29 if placement_ver_enabled:
30 placement_major_version = config.get('placementMajorVersion', None)
31 placement_minor_version = config.get('placementMinorVersion', None)
32 placement_patch_version = config.get('placementPatchVersion', None)
34 http_header = request.headers.environ
35 http_x_minorversion = http_header.get("HTTP_X_MINORVERSION")
36 http_x_patchversion = http_header.get("HTTP_X_PATCHVERSION")
37 http_x_latestversion = http_header.get("HTTP_X_LATESTVERSION")
39 debug_log.debug("Versions sent in HTTP header for request ID {} are: X-MinorVersion: {} X-PatchVersion: {} X-LatestVersion: {}"
40 .format(request_id, http_x_minorversion, http_x_patchversion, http_x_latestversion))
41 debug_log.debug("latest versions specified in osdf config file are: placementMajorVersion: {} placementMinorVersion: {} placementPatchVersion: {}"
42 .format(placement_major_version, placement_minor_version, placement_patch_version))
44 placement_major_version = config.get('placementDefaultMajorVersion', "1")
45 placement_minor_version = config.get('placementDefaultMinorVersion', "0")
46 placement_patch_version = config.get('placementDefaultPatchVersion', "0")
48 debug_log.debug("Default versions specified in osdf config file are: placementDefaultMajorVersion: {} placementDefaultMinorVersion: {} placementDefaultPatchVersion: {}"
49 .format(placement_major_version, placement_minor_version, placement_patch_version))
51 version_info_dict.update({
52 'placementVersioningEnabled': placement_ver_enabled,
53 'placementMajorVersion': str(placement_major_version),
54 'placementMinorVersion': str(placement_minor_version),
55 'placementPatchVersion': str( placement_patch_version)
58 return version_info_dict