aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/botocore/py3/patches/02-fix-for-arcadia.patch
blob: 7a10b07030a8b597f0ed8f98d745ceeb421accdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
--- contrib/python/botocore/py3/botocore/data/endpoints.json	(index)
+++ contrib/python/botocore/py3/botocore/data/endpoints.json	(working tree)
@@ -21165,6 +21165,46 @@
     "regionRegex" : "^eu\\-isoe\\-\\w+\\-\\d+$",
     "regions" : { },
     "services" : { }
+  }, {
+    "defaults" : {
+      "hostname" : "{service}.{region}.{dnsSuffix}",
+      "protocols" : [ "https" ],
+      "signatureVersions" : [ "v4" ]
+    },
+    "dnsSuffix" : "yandex.net",
+    "partition" : "yandex",
+    "partitionName" : "Yandex",
+    "regions" : {
+      "yandex" : {
+        "description" : "Yandex"
+      }
+    },
+    "services" : {
+      "s3" : {
+        "defaults" : {
+          "protocols" : [ "http", "https" ],
+          "signatureVersions" : [ "s3", "s3v4" ]
+        },
+        "endpoints" : {
+          "yandex" : {
+            "hostname" : "s3.mds.yandex.net"
+          },
+          "yandex-test" : {
+            "hostname" : "s3.mdst.yandex.net"
+          }
+        }
+      },
+      "sqs" : {
+        "defaults" : {
+          "protocols" : [ "http" ]
+        },
+        "endpoints" : {
+          "yandex" : {
+            "hostname": "sqs.yandex.net:8771"
+          }
+        }
+      }
+    }
   } ],
   "version" : 3
 }
\ No newline at end of file
--- contrib/python/botocore/py3/botocore/__init__.py	(index)
+++ contrib/python/botocore/py3/botocore/__init__.py	(working tree)
@@ -64,1 +64,1 @@ _xform_cache = {
-BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
+BOTOCORE_ROOT = os.path.dirname(__file__)
--- contrib/python/botocore/py3/botocore/configprovider.py	(index)
+++ contrib/python/botocore/py3/botocore/configprovider.py	(working tree)
@@ -52,1 +52,1 @@ logger = logging.getLogger(__name__)
-    'region': ('region', 'AWS_DEFAULT_REGION', None, None),
+    'region': ('region', 'AWS_DEFAULT_REGION', 'yandex', None),
--- contrib/python/botocore/py3/botocore/loaders.py	(index)
+++ contrib/python/botocore/py3/botocore/loaders.py	(working tree)
@@ -101,14 +101,17 @@ information that doesn't quite fit in the original models, but is still needed
 for the sdk. For instance, additional operation parameters might be added here
 which don't represent the actual service api.
 """
+import collections
 import logging
 import os
 
 from botocore import BOTOCORE_ROOT
-from botocore.compat import HAS_GZIP, OrderedDict, json
+from botocore.compat import HAS_GZIP, OrderedDict, json, six
 from botocore.exceptions import DataNotFoundError, UnknownServiceError
 from botocore.utils import deep_merge
 
+from library.python import resource
+
 _JSON_OPEN_METHODS = {
     '.json': open,
 }
@@ -197,6 +200,67 @@ class JSONFileLoader(object):
         return None
 
 
+# SQS-119
+class HybridJsonLoader(JSONFileLoader):
+
+    type_data_cache = collections.defaultdict(lambda: collections.defaultdict(set))
+
+    arcadia_resources_path = (
+        'contrib/python/awscli/awscli/data/',
+        'contrib/python/boto3/py3/boto3/data/',
+        'contrib/python/botocore/py3/botocore/data/',
+    )
+
+    @classmethod
+    def collect_service_data(cls):
+        if cls.type_data_cache:
+            return
+
+        for res in resource.resfs_files():
+            res = six.ensure_str(res)
+            if res.startswith(cls.arcadia_resources_path):
+                splitted_path = res.split('/data/')[1].split('/')
+                if len(splitted_path) >= 3:
+                    service_name, version, type_name = splitted_path[:3]
+                    type_name = type_name.replace('.json.gz', '').replace('.json', '')
+                    cls.type_data_cache[type_name][service_name].add(version)
+
+    @classmethod
+    def read_from_resources(cls, file_path):
+        for ext in _JSON_OPEN_METHODS:
+            for prefix in cls.arcadia_resources_path:
+                path = f'{prefix}{file_path}{ext}'
+                data = resource.resfs_read(path)
+                if data:
+                    return path, ext, data
+        return
+
+    def exists(self, file_path):
+        if self.read_from_resources(file_path):
+            return True
+        return super(HybridJsonLoader, self).exists(file_path)
+
+    def _load_resource(self, full_path, ext, data):
+        # By default the file will be opened with locale encoding on Python 3.
+        # We specify "utf8" here to ensure the correct behavior.
+        if ext == ".json":
+            payload = data.decode('utf-8')
+        elif ext == ".json.gz":
+            import io
+            with gzip_open(io.BytesIO(data)) as fp:
+                payload = fp.read().decode('utf-8')
+        else:
+            raise ValueError(f"Unknown extension {ext}")
+
+        logger.debug("Loading JSON file: %s", full_path)
+        return json.loads(payload, object_pairs_hook=OrderedDict)
+
+    def load_file(self, file_path):
+        if load_args := self.read_from_resources(file_path):
+            return self._load_resource(*load_args)
+        return super(HybridJsonLoader, self).load_file(file_path)
+
+
 def create_loader(search_path_string=None):
     """Create a Loader class.
 
@@ -231,7 +279,7 @@ class Loader(object):
 
     """

-    FILE_LOADER_CLASS = JSONFileLoader
+    FILE_LOADER_CLASS = HybridJsonLoader
     # The included models in botocore/data/ that we ship with botocore.
     BUILTIN_DATA_PATH = os.path.join(BOTOCORE_ROOT, 'data')
     # For convenience we automatically add ~/.aws/models to the data path.
@@ -316,6 +364,11 @@ class Loader(object):
                     if self.file_loader.exists(full_load_path):
                         services.add(service_name)
                         break
+
+        # SQS-119
+        HybridJsonLoader.collect_service_data()
+        services = services.union(HybridJsonLoader.type_data_cache[type_name].keys())
+
         return sorted(services)
 
     @instance_cache
@@ -367,6 +420,11 @@ class Loader(object):
                 # to the type_name passed in.
                 if self.file_loader.exists(full_path):
                     known_api_versions.add(dirname)
+
+        # SQS-119
+        HybridJsonLoader.collect_service_data()
+        known_api_versions = known_api_versions.union(HybridJsonLoader.type_data_cache[type_name][service_name])
+
         if not known_api_versions:
             raise DataNotFoundError(data_path=service_name)
         return sorted(known_api_versions)
@@ -449,6 +507,11 @@ class Loader(object):
             if found is not None:
                 return found, possible_path
 
+        # SQS-119
+        found_by_arcadia_loader = self.file_loader.load_file(name)
+        if found_by_arcadia_loader is not None:
+            return found_by_arcadia_loader, None
+
         # We didn't find anything that matched on any path.
         raise DataNotFoundError(data_path=name)
 
@@ -499,6 +562,8 @@ class Loader:
 
         :return: Whether the given path is within the package's data directory.
         """
+        if path is None:
+            return True
         path = os.path.expanduser(os.path.expandvars(path))
         return path.startswith(self.BUILTIN_DATA_PATH)