def split_chunks(string, remarks): json_chunks = rustcall( lib.relay_split_chunks, encode_str(string), encode_str(json.dumps(remarks)), ) return json.loads(decode_str(json_chunks, free=True))
def pii_strip_event(config, event): """ Scrub an event using new PII stripping config. """ raw_config = encode_str(json.dumps(config)) raw_event = encode_str(json.dumps(event)) raw_rv = rustcall(lib.relay_pii_strip_event, raw_config, raw_event) return json.loads(decode_str(raw_rv, free=True))
def create_register_challenge(data, signature, secret, max_age=60): challenge_json = rustcall( lib.relay_create_register_challenge, make_buf(data), encode_str(signature), encode_str(secret), max_age, ) challenge = json.loads(decode_str(challenge_json, free=True)) return { "relay_id": uuid.UUID(challenge["relay_id"]), "token": challenge["token"], }
def is_glob_match( value, pat, double_star=False, case_insensitive=False, path_normalize=False, allow_newline=False, ): flags = 0 if double_star: flags |= lib.GLOB_FLAGS_DOUBLE_STAR if case_insensitive: flags |= lib.GLOB_FLAGS_CASE_INSENSITIVE # Since on the C side we're only working with bytes we need to lowercase the pattern # and value here. This works with both bytes and unicode strings. value = value.lower() pat = pat.lower() if path_normalize: flags |= lib.GLOB_FLAGS_PATH_NORMALIZE if allow_newline: flags |= lib.GLOB_FLAGS_ALLOW_NEWLINE if isinstance(value, text_type): value = value.encode("utf-8") return rustcall(lib.relay_is_glob_match, make_buf(value), encode_str(pat), flags)
def pii_selectors_from_event(event): """ DEPRECATED: Use relay_pii_selector_suggestions_from_event """ raw_event = encode_str(json.dumps(event)) raw_rv = rustcall(lib.relay_pii_selectors_from_event, raw_event) return json.loads(decode_str(raw_rv, free=True))
def convert_datascrubbing_config(config): """ Convert an old datascrubbing config to the new PII config format. """ raw_config = encode_str(json.dumps(config)) raw_rv = rustcall(lib.relay_convert_datascrubbing_config, raw_config) return json.loads(decode_str(raw_rv, free=True))
def validate_register_response(data, signature, secret, max_age=60): response_json = rustcall( lib.relay_validate_register_response, make_buf(data), encode_str(signature), encode_str(secret), max_age, ) response = json.loads(decode_str(response_json, free=True)) return { "relay_id": uuid.UUID(response["relay_id"]), "token": response["token"], "public_key": response["public_key"], "version": response["version"], }
def verify(self, buf, sig, max_age=None): buf = make_buf(buf) sig = encode_str(sig) if max_age is None: return self._methodcall(lib.relay_publickey_verify, buf, sig) return self._methodcall(lib.relay_publickey_verify_timestamp, buf, sig, max_age)
def pii_selector_suggestions_from_event(event): """ Walk through the event and collect selectors that can be applied to it in a PII config. This function is used in the UI to provide auto-completion of selectors. """ raw_event = encode_str(json.dumps(event)) raw_rv = rustcall(lib.relay_pii_selector_suggestions_from_event, raw_event) return json.loads(decode_str(raw_rv, free=True))
def parse(cls, name): """ Parses a `DataCategory` from its API name. """ category = DataCategory( lib.relay_data_category_parse(encode_str(name or ""))) if category == DataCategory.UNKNOWN: return None # Unknown is a Rust-only value, replace with None return category
def __new__(cls, geoip_lookup=None, **config): config = json.dumps(config) geoptr = geoip_lookup._get_objptr() if geoip_lookup is not None else ffi.NULL rv = cls._from_objptr( rustcall(lib.relay_store_normalizer_new, encode_str(config), geoptr) ) if geoip_lookup is not None: attached_refs[rv] = geoip_lookup return rv
def scrub_event(config, data): if not config: return data config = json.dumps(config) raw_event = _serialize_event(data) event = _encode_raw_event(raw_event) rv = rustcall(lib.relay_scrub_event, encode_str(config), event) return json.loads(decode_str(rv, free=True))
def validate_sampling_configuration(condition): """ Validate the whole sampling configuration. Used in dynamic sampling serializer. The parameter is a string containing the rules configuration as JSON. """ assert isinstance(condition, string_types) raw_error = rustcall(lib.relay_validate_sampling_configuration, encode_str(condition)) error = decode_str(raw_error, free=True) if error: raise ValueError(error)
def validate_pii_config(config): """ Validate a PII config against the schema. Used in project options UI. The parameter is a JSON-encoded string. We should pass the config through as a string such that line numbers from the error message match with what the user typed in. """ assert isinstance(config, string_types) raw_error = rustcall(lib.relay_validate_pii_config, encode_str(config)) error = decode_str(raw_error, free=True) if error: raise ValueError(error)
def validate_register_response(public_key, data, signature, max_age=60 * 15): response_json = rustcall( lib.relay_validate_register_response, public_key._objptr, make_buf(data), encode_str(signature), max_age, ) response = json.loads(decode_str(response_json, free=True)) return { "relay_id": uuid.UUID(response["relay_id"]), "token": response["token"] }
def parse_release(release): return json.loads( decode_str(rustcall(lib.relay_parse_release, encode_str(release)), free=True) )
def from_event_type(cls, event_type): """ Parses a `DataCategory` from an event type. """ s = encode_str(event_type or "") return DataCategory(lib.relay_data_category_from_event_type(s))
def is_version_supported(version): """ Checks if the provided Relay version is still compatible with this library. The version can be ``None``, in which case a legacy Relay is assumed. """ return rustcall(lib.relay_version_supported, encode_str(version or ""))
def _encode_raw_event(raw_event): event = encode_str(raw_event, mutable=True) rustcall(lib.relay_translate_legacy_python_json, event) return event
def parse(cls, string): s = encode_str(string) ptr = rustcall(lib.relay_secretkey_parse, s) return cls._from_objptr(ptr)