02-fix-for-arcadia.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. --- contrib/python/botocore/py2/botocore/data/endpoints.json (index)
  2. +++ contrib/python/botocore/py2/botocore/data/endpoints.json (working tree)
  3. @@ -10656,6 +10656,46 @@
  4. }
  5. }
  6. }
  7. + }, {
  8. + "defaults" : {
  9. + "hostname" : "{service}.{region}.{dnsSuffix}",
  10. + "protocols" : [ "https" ],
  11. + "signatureVersions" : [ "v4" ]
  12. + },
  13. + "dnsSuffix" : "yandex.net",
  14. + "partition" : "yandex",
  15. + "partitionName" : "Yandex",
  16. + "regions" : {
  17. + "yandex" : {
  18. + "description" : "Yandex"
  19. + }
  20. + },
  21. + "services" : {
  22. + "s3" : {
  23. + "defaults" : {
  24. + "protocols" : [ "http", "https" ],
  25. + "signatureVersions" : [ "s3", "s3v4" ]
  26. + },
  27. + "endpoints" : {
  28. + "yandex" : {
  29. + "hostname" : "s3.mds.yandex.net"
  30. + },
  31. + "yandex-test" : {
  32. + "hostname" : "s3.mdst.yandex.net"
  33. + }
  34. + }
  35. + },
  36. + "sqs" : {
  37. + "defaults" : {
  38. + "protocols" : [ "http" ]
  39. + },
  40. + "endpoints" : {
  41. + "yandex" : {
  42. + "hostname": "sqs.yandex.net:8771"
  43. + }
  44. + }
  45. + }
  46. + }
  47. } ],
  48. "version" : 3
  49. }
  50. \ No newline at end of file
  51. --- contrib/python/botocore/py2/botocore/__init__.py (index)
  52. +++ contrib/python/botocore/py2/botocore/__init__.py (working tree)
  53. @@ -59,7 +59,7 @@ _xform_cache = {
  54. # individual case.
  55. ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double')
  56. -BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
  57. +BOTOCORE_ROOT = os.path.dirname(__file__)
  58. # Used to specify anonymous (unsigned) request signature
  59. --- contrib/python/botocore/py2/botocore/configprovider.py (index)
  60. +++ contrib/python/botocore/py2/botocore/configprovider.py (working tree)
  61. @@ -49,7 +49,7 @@ logger = logging.getLogger(__name__)
  62. BOTOCORE_DEFAUT_SESSION_VARIABLES = {
  63. # logical: config_file, env_var, default_value, conversion_func
  64. 'profile': (None, ['AWS_DEFAULT_PROFILE', 'AWS_PROFILE'], None, None),
  65. - 'region': ('region', 'AWS_DEFAULT_REGION', None, None),
  66. + 'region': ('region', 'AWS_DEFAULT_REGION', 'yandex', None),
  67. 'data_path': ('data_path', 'AWS_DATA_PATH', None, None),
  68. 'config_file': (None, 'AWS_CONFIG_FILE', '~/.aws/config', None),
  69. 'ca_bundle': ('ca_bundle', 'AWS_CA_BUNDLE', None, None),
  70. --- contrib/python/botocore/py2/botocore/loaders.py (index)
  71. +++ contrib/python/botocore/py2/botocore/loaders.py (working tree)
  72. @@ -101,15 +101,19 @@ information that doesn't quite fit in the original models, but is still needed
  73. for the sdk. For instance, additional operation parameters might be added here
  74. which don't represent the actual service api.
  75. """
  76. +import collections
  77. import os
  78. import logging
  79. from botocore import BOTOCORE_ROOT
  80. from botocore.compat import json
  81. +from botocore.compat import six
  82. from botocore.compat import OrderedDict
  83. from botocore.exceptions import DataNotFoundError, UnknownServiceError
  84. from botocore.utils import deep_merge
  85. +from library.python import resource
  86. +
  87. logger = logging.getLogger(__name__)
  88. @@ -175,6 +179,51 @@ class JSONFileLoader(object):
  89. return json.loads(payload, object_pairs_hook=OrderedDict)
  90. +# SQS-119
  91. +class HybridJsonLoader(JSONFileLoader):
  92. +
  93. + type_data_cache = collections.defaultdict(lambda: collections.defaultdict(set))
  94. +
  95. + arcadia_resources_path = (
  96. + 'contrib/python/awscli/awscli/data/',
  97. + 'contrib/python/boto3/py2/boto3/data/',
  98. + 'contrib/python/botocore/py2/botocore/data/',
  99. + )
  100. +
  101. + @classmethod
  102. + def collect_service_data(cls):
  103. + if cls.type_data_cache:
  104. + return
  105. +
  106. + for res in resource.resfs_files():
  107. + res = six.ensure_str(res)
  108. + if res.startswith(cls.arcadia_resources_path):
  109. + splitted_path = res.split('/data/')[1].split('/')
  110. + if len(splitted_path) >= 3:
  111. + service_name, version, type_name = splitted_path[:3]
  112. + type_name = type_name.replace('.json', '')
  113. + cls.type_data_cache[type_name][service_name].add(version)
  114. +
  115. + @classmethod
  116. + def path_in_arcadia_resources(cls, file_path):
  117. + for prefix in cls.arcadia_resources_path:
  118. + path = '{}{}.json'.format(prefix, file_path)
  119. + if path in resource.resfs_files():
  120. + return path
  121. + return
  122. +
  123. + def exists(self, file_path):
  124. + if self.path_in_arcadia_resources(file_path):
  125. + return True
  126. + return super(HybridJsonLoader, self).exists(file_path)
  127. +
  128. + def load_file(self, file_path):
  129. + path = self.path_in_arcadia_resources(file_path)
  130. + if path:
  131. + return json.loads(resource.resfs_read(path).decode(encoding='utf-8'))
  132. + return super(HybridJsonLoader, self).load_file(file_path)
  133. +
  134. +
  135. def create_loader(search_path_string=None):
  136. """Create a Loader class.
  137. @@ -208,7 +257,7 @@ class Loader(object):
  138. convenience method over ``load_data`` and ``determine_latest_version``.
  139. """
  140. - FILE_LOADER_CLASS = JSONFileLoader
  141. + FILE_LOADER_CLASS = HybridJsonLoader
  142. # The included models in botocore/data/ that we ship with botocore.
  143. BUILTIN_DATA_PATH = os.path.join(BOTOCORE_ROOT, 'data')
  144. # For convenience we automatically add ~/.aws/models to the data path.
  145. @@ -284,6 +333,11 @@ class Loader(object):
  146. if self.file_loader.exists(full_load_path):
  147. services.add(service_name)
  148. break
  149. +
  150. + # SQS-119
  151. + HybridJsonLoader.collect_service_data()
  152. + services = services.union(HybridJsonLoader.type_data_cache[type_name].keys())
  153. +
  154. return sorted(services)
  155. @instance_cache
  156. @@ -335,6 +389,11 @@ class Loader(object):
  157. # to the type_name passed in.
  158. if self.file_loader.exists(full_path):
  159. known_api_versions.add(dirname)
  160. +
  161. + # SQS-119
  162. + HybridJsonLoader.collect_service_data()
  163. + known_api_versions = known_api_versions.union(HybridJsonLoader.type_data_cache[type_name][service_name])
  164. +
  165. if not known_api_versions:
  166. raise DataNotFoundError(data_path=service_name)
  167. return sorted(known_api_versions)
  168. @@ -420,6 +479,12 @@ class Loader(object):
  169. found = self.file_loader.load_file(possible_path)
  170. if found is not None:
  171. return found
  172. +
  173. + # SQS-119
  174. + found_by_arcadia_loader = self.file_loader.load_file(name)
  175. + if found_by_arcadia_loader is not None:
  176. + return found_by_arcadia_loader
  177. +
  178. # We didn't find anything that matched on any path.
  179. raise DataNotFoundError(data_path=name)