sentry-relay 0.8.57__zip → 0.8.58__zip

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sentry-relay
3
- Version: 0.8.57
3
+ Version: 0.8.58
4
4
  Summary: A python library to access sentry relay functionality.
5
5
  Author: Sentry
6
6
  Author-email: hello@sentry.io
@@ -1,5 +1,7 @@
1
1
  import json
2
2
  import uuid
3
+ from typing import Callable, Any
4
+
3
5
  from sentry_relay._lowlevel import lib
4
6
  from sentry_relay.utils import (
5
7
  RustObject,
@@ -38,10 +40,16 @@ class PublicKey(RustObject):
38
40
  return self._methodcall(lib.relay_publickey_verify, buf, sig)
39
41
  return self._methodcall(lib.relay_publickey_verify_timestamp, buf, sig, max_age)
40
42
 
41
- def unpack(self, buf, sig, max_age=None):
43
+ def unpack(
44
+ self,
45
+ buf,
46
+ sig,
47
+ max_age=None,
48
+ json_loads: Callable[[str | bytes], Any] = json.loads,
49
+ ):
42
50
  if not self.verify(buf, sig, max_age):
43
51
  raise UnpackErrorBadSignature("invalid signature")
44
- return json.loads(buf)
52
+ return json_loads(buf)
45
53
 
46
54
  def __str__(self):
47
55
  return decode_str(self._methodcall(lib.relay_publickey_to_string), free=True)
@@ -64,7 +72,8 @@ class SecretKey(RustObject):
64
72
  return decode_str(self._methodcall(lib.relay_secretkey_sign, buf), free=True)
65
73
 
66
74
  def pack(self, data):
67
- packed = json.dumps(data, separators=(",", ":")).encode("utf8")
75
+ # TODO(@anonrig): Look into separators requirement
76
+ packed = json.dumps(data, separators=(",", ":")).encode()
68
77
  return packed, self.sign(packed)
69
78
 
70
79
  def __str__(self):
@@ -86,7 +95,13 @@ def generate_relay_id():
86
95
  return decode_uuid(rustcall(lib.relay_generate_relay_id))
87
96
 
88
97
 
89
- def create_register_challenge(data, signature, secret, max_age=60):
98
+ def create_register_challenge(
99
+ data,
100
+ signature,
101
+ secret,
102
+ max_age=60,
103
+ json_loads: Callable[[str | bytes], Any] = json.loads,
104
+ ):
90
105
  challenge_json = rustcall(
91
106
  lib.relay_create_register_challenge,
92
107
  make_buf(data),
@@ -95,14 +110,20 @@ def create_register_challenge(data, signature, secret, max_age=60):
95
110
  max_age,
96
111
  )
97
112
 
98
- challenge = json.loads(decode_str(challenge_json, free=True))
113
+ challenge = json_loads(decode_str(challenge_json, free=True))
99
114
  return {
100
115
  "relay_id": uuid.UUID(challenge["relay_id"]),
101
116
  "token": challenge["token"],
102
117
  }
103
118
 
104
119
 
105
- def validate_register_response(data, signature, secret, max_age=60):
120
+ def validate_register_response(
121
+ data,
122
+ signature,
123
+ secret,
124
+ max_age=60,
125
+ json_loads: Callable[[str | bytes], Any] = json.loads,
126
+ ):
106
127
  response_json = rustcall(
107
128
  lib.relay_validate_register_response,
108
129
  make_buf(data),
@@ -111,7 +132,7 @@ def validate_register_response(data, signature, secret, max_age=60):
111
132
  max_age,
112
133
  )
113
134
 
114
- response = json.loads(decode_str(response_json, free=True))
135
+ response = json_loads(decode_str(response_json, free=True))
115
136
  return {
116
137
  "relay_id": uuid.UUID(response["relay_id"]),
117
138
  "token": response["token"],
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ from typing import Callable, Any
4
5
 
5
6
  from sentry_relay._lowlevel import lib, ffi
6
7
  from sentry_relay.utils import (
@@ -12,7 +13,6 @@ from sentry_relay.utils import (
12
13
  make_buf,
13
14
  )
14
15
 
15
-
16
16
  __all__ = [
17
17
  "split_chunks",
18
18
  "meta_with_chunks",
@@ -49,13 +49,18 @@ def _init_valid_platforms() -> frozenset[str]:
49
49
  VALID_PLATFORMS = _init_valid_platforms()
50
50
 
51
51
 
52
- def split_chunks(string, remarks):
52
+ def split_chunks(
53
+ string,
54
+ remarks,
55
+ json_dumps: Callable[[Any], Any] = json.dumps,
56
+ json_loads: Callable[[str | bytes], Any] = json.loads,
57
+ ):
53
58
  json_chunks = rustcall(
54
59
  lib.relay_split_chunks,
55
60
  encode_str(string),
56
- encode_str(json.dumps(remarks)),
61
+ encode_str(json_dumps(remarks)),
57
62
  )
58
- return json.loads(decode_str(json_chunks, free=True))
63
+ return json_loads(decode_str(json_chunks, free=True))
59
64
 
60
65
 
61
66
  def meta_with_chunks(data, meta):
@@ -101,8 +106,10 @@ class StoreNormalizer(RustObject):
101
106
  __init__ = object.__init__
102
107
  __slots__ = ("__weakref__",)
103
108
 
104
- def __new__(cls, geoip_lookup=None, **config):
105
- config = json.dumps(config)
109
+ def __new__(
110
+ cls, geoip_lookup=None, json_dumps: Callable[[Any], Any] = json.dumps, **config
111
+ ):
112
+ config = json_dumps(config)
106
113
  geoptr = geoip_lookup._get_objptr() if geoip_lookup is not None else ffi.NULL
107
114
  rv = cls._from_objptr(
108
115
  rustcall(lib.relay_store_normalizer_new, encode_str(config), geoptr)
@@ -111,16 +118,22 @@ class StoreNormalizer(RustObject):
111
118
  attached_refs[rv] = geoip_lookup
112
119
  return rv
113
120
 
114
- def normalize_event(self, event=None, raw_event=None):
121
+ def normalize_event(
122
+ self,
123
+ event=None,
124
+ raw_event=None,
125
+ json_loads: Callable[[str | bytes], Any] = json.loads,
126
+ ):
115
127
  if raw_event is None:
116
128
  raw_event = _serialize_event(event)
117
129
 
118
130
  event = _encode_raw_event(raw_event)
119
131
  rv = self._methodcall(lib.relay_store_normalizer_normalize_event, event)
120
- return json.loads(decode_str(rv, free=True))
132
+ return json_loads(decode_str(rv, free=True))
121
133
 
122
134
 
123
135
  def _serialize_event(event):
136
+ # TODO(@anonrig): Look into ensure_ascii requirement
124
137
  raw_event = json.dumps(event, ensure_ascii=False)
125
138
  if isinstance(raw_event, str):
126
139
  raw_event = raw_event.encode("utf-8", errors="replace")
@@ -194,39 +207,52 @@ def validate_pii_config(config):
194
207
  raise ValueError(error)
195
208
 
196
209
 
197
- def convert_datascrubbing_config(config):
210
+ def convert_datascrubbing_config(
211
+ config,
212
+ json_dumps: Callable[[Any], Any] = json.dumps,
213
+ json_loads: Callable[[str | bytes], Any] = json.loads,
214
+ ):
198
215
  """
199
216
  Convert an old datascrubbing config to the new PII config format.
200
217
  """
201
- raw_config = encode_str(json.dumps(config))
218
+ raw_config = encode_str(json_dumps(config))
202
219
  raw_rv = rustcall(lib.relay_convert_datascrubbing_config, raw_config)
203
- return json.loads(decode_str(raw_rv, free=True))
220
+ return json_loads(decode_str(raw_rv, free=True))
204
221
 
205
222
 
206
- def pii_strip_event(config, event):
223
+ def pii_strip_event(
224
+ config,
225
+ event,
226
+ json_dumps: Callable[[Any], Any] = json.dumps,
227
+ json_loads: Callable[[str | bytes], Any] = json.loads,
228
+ ):
207
229
  """
208
230
  Scrub an event using new PII stripping config.
209
231
  """
210
- raw_config = encode_str(json.dumps(config))
211
- raw_event = encode_str(json.dumps(event))
232
+ raw_config = encode_str(json_dumps(config))
233
+ raw_event = encode_str(json_dumps(event))
212
234
  raw_rv = rustcall(lib.relay_pii_strip_event, raw_config, raw_event)
213
- return json.loads(decode_str(raw_rv, free=True))
235
+ return json_loads(decode_str(raw_rv, free=True))
214
236
 
215
237
 
216
- def pii_selector_suggestions_from_event(event):
238
+ def pii_selector_suggestions_from_event(
239
+ event,
240
+ json_dumps: Callable[[Any], Any] = json.dumps,
241
+ json_loads: Callable[[str | bytes], Any] = json.loads,
242
+ ):
217
243
  """
218
244
  Walk through the event and collect selectors that can be applied to it in a
219
245
  PII config. This function is used in the UI to provide auto-completion of
220
246
  selectors.
221
247
  """
222
- raw_event = encode_str(json.dumps(event))
248
+ raw_event = encode_str(json_dumps(event))
223
249
  raw_rv = rustcall(lib.relay_pii_selector_suggestions_from_event, raw_event)
224
- return json.loads(decode_str(raw_rv, free=True))
250
+ return json_loads(decode_str(raw_rv, free=True))
225
251
 
226
252
 
227
- def parse_release(release):
253
+ def parse_release(release, json_loads: Callable[[str | bytes], Any] = json.loads):
228
254
  """Parses a release string into a dictionary of its components."""
229
- return json.loads(
255
+ return json_loads(
230
256
  decode_str(rustcall(lib.relay_parse_release, encode_str(release)), free=True)
231
257
  )
232
258
 
@@ -283,7 +309,11 @@ def validate_project_config(config, strict: bool):
283
309
  raise ValueError(error)
284
310
 
285
311
 
286
- def normalize_global_config(config):
312
+ def normalize_global_config(
313
+ config,
314
+ json_dumps: Callable[[Any], Any] = json.dumps,
315
+ json_loads: Callable[[str | bytes], Any] = json.loads,
316
+ ):
287
317
  """Normalize the global config.
288
318
 
289
319
  Normalization consists of deserializing and serializing back the given
@@ -292,11 +322,14 @@ def normalize_global_config(config):
292
322
  normalized one.
293
323
 
294
324
  :param config: the global config to validate.
325
+ :param json_dumps: a function that stringifies python objects
326
+ :param json_loads: a function that parses and converts JSON strings
295
327
  """
296
- serialized = json.dumps(config)
328
+ serialized = json_dumps(config)
297
329
  normalized = rustcall(lib.normalize_global_config, encode_str(serialized))
298
330
  rv = decode_str(normalized, free=True)
299
331
  try:
300
- return json.loads(rv)
301
- except json.JSONDecodeError:
332
+ return json_loads(rv)
333
+ except Exception:
334
+ # Catch all errors since json.loads implementation can change.
302
335
  raise ValueError(rv)
@@ -0,0 +1 @@
1
+ 0.8.58
@@ -1 +0,0 @@
1
- 0.8.57
File without changes
File without changes