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 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 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 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_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 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 __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 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 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 _init_valid_platforms(): global VALID_PLATFORMS size_out = ffi.new("uintptr_t *") strings = rustcall(lib.relay_valid_platforms, size_out) valid_platforms = [] for i in range(int(size_out[0])): valid_platforms.append(decode_str(strings[i], free=True)) VALID_PLATFORMS = frozenset(valid_platforms)
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 create_register_challenge(data, signature, max_age=60 * 15): challenge_json = rustcall( lib.relay_create_register_challenge, make_buf(data), encode_str(signature), max_age, ) challenge = json.loads(decode_str(challenge_json, free=True)) return { "relay_id": uuid.UUID(challenge["relay_id"]), "public_key": PublicKey.parse(challenge["public_key"]), "token": challenge["token"], }
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 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 from_path(cls, path): if isinstance(path, text_type): path = path.encode("utf-8") rv = cls._from_objptr(rustcall(lib.relay_geoip_lookup_new, path)) rv._path = path return rv
def parse_release(release): return json.loads( decode_str(rustcall(lib.relay_parse_release, encode_str(release)), free=True) )
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 get_register_response_relay_id(data): return decode_uuid( rustcall(lib.relay_get_register_response_relay_id, make_buf(data)))
def _encode_raw_event(raw_event): event = encode_str(raw_event, mutable=True) rustcall(lib.relay_translate_legacy_python_json, event) return event
def test_panic(): with pytest.raises(Panic): rustcall(lib.relay_test_panic)
def generate_relay_id(): return decode_uuid(rustcall(lib.relay_generate_relay_id))
def generate_key_pair(): rv = rustcall(lib.relay_generate_key_pair) return ( SecretKey._from_objptr(rv.secret_key), PublicKey._from_objptr(rv.public_key), )
def parse(cls, string): s = encode_str(string) ptr = rustcall(lib.relay_secretkey_parse, s) return cls._from_objptr(ptr)