Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit b472613

Browse files
add hash_registry kward to hash the body of requests to the registry
1 parent 9ccdabf commit b472613

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

dynata_rex/opportunity_registry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def __init__(self,
2727
access_key: str,
2828
secret_key: str,
2929
base_url: str = _BASE_URL,
30+
# TODO: Hack Alert Remove Hash Registry
31+
hash_registry: bool = False,
32+
# END TODO: Hack Alert
3033
default_ttl: int = 10,
3134
shard_count: int = 1,
3235
current_shard: int = 1):
@@ -43,7 +46,8 @@ def __init__(self,
4346
self.default_ttl = default_ttl
4447
self.make_request = RexRequest(access_key,
4548
secret_key,
46-
default_ttl=default_ttl)
49+
default_ttl=default_ttl,
50+
hash_registry=hash_registry)
4751
self.base_url = base_url
4852

4953
if current_shard > shard_count:

dynata_rex/signer.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,18 @@ def sign_query_parameters_from_ttl(self,
144144
class RexRequest:
145145
"""Wrapper for http calls to include our signature"""
146146

147-
def __init__(self, access_key, secret_key, default_ttl: int = 10):
147+
def __init__(self,
148+
access_key,
149+
secret_key,
150+
default_ttl: int = 10,
151+
hash_registry: bool = False):
148152
self.default_ttl = default_ttl
149153
self.access_key = access_key
150154
self.secret_key = secret_key
155+
# TODO: Hack Alert: Including this for compatability
156+
# Once completed, all refs to the registry hack should be removed
157+
self.hash_registry = hash_registry
158+
# END TODO: Hack Alert
151159
self.signer = Signer(access_key, secret_key)
152160
self.session = make_session()
153161

@@ -161,12 +169,15 @@ def _signature(self, ttl: int = None, signing_string: str = None) -> str:
161169
signing_string=signing_string
162170
)
163171

164-
def _create_auth_headers(self, url, additional_headers={}, body=''):
172+
def _create_auth_headers(self,
173+
url,
174+
additional_headers={},
175+
body=''):
165176
signing_string = self.signer._create_request_body_signing_string(body)
166177

167178
# TODO: Hack alert: Registry doesn't like the sha256 body signing
168179
# string yet
169-
if 'https://registry' in url:
180+
if self.hash_registry is False and 'https://registry' in url:
170181
signing_string = ''
171182
# END Hack alert
172183

@@ -188,7 +199,9 @@ def dispatch(self,
188199
additional_headers = {'Content-type': 'application/json'}
189200
data = json.dumps(data)
190201

191-
headers = self._create_auth_headers(url, additional_headers, body=data)
202+
headers = self._create_auth_headers(url,
203+
additional_headers,
204+
body=data)
192205

193206
if not hasattr(self.session, method.lower()):
194207
raise AttributeError('Invalid http method provided.')

0 commit comments

Comments
 (0)