From 85d2892ec174e53388112395e404463e85d1a055 Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Tue, 4 Mar 2025 12:36:41 +1100 Subject: [PATCH 1/5] Add functionality to passin timestamp --- uid2_client/identity_map_client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/uid2_client/identity_map_client.py b/uid2_client/identity_map_client.py index d050456..f08cb2e 100644 --- a/uid2_client/identity_map_client.py +++ b/uid2_client/identity_map_client.py @@ -34,12 +34,15 @@ def __init__(self, base_url, api_key, client_secret): self._api_key = api_key self._client_secret = base64.b64decode(client_secret) - def generate_identity_map(self, identity_map_input): - req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), + def generate_identity_map(self, identity_map_input, timestamp): + req, nonce = make_v2_request(self._client_secret, timestamp, identity_map_input.get_identity_map_input_as_json_string().encode()) resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req) resp_body = parse_v2_response(self._client_secret, resp.read(), nonce) return IdentityMapResponse(resp_body, identity_map_input) + + def generate_identity_map(self, identity_map_input): + return self.generate_identity_map(identity_map_input, dt.datetime.now(tz=timezone.utc)) def get_identity_buckets(self, since_timestamp): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), From 5a0a16e80e6eb7b683a0eb4ade987c1f7de3a8f8 Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Tue, 4 Mar 2025 12:43:40 +1100 Subject: [PATCH 2/5] Pass in optional param --- uid2_client/identity_map_client.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/uid2_client/identity_map_client.py b/uid2_client/identity_map_client.py index f08cb2e..b85b338 100644 --- a/uid2_client/identity_map_client.py +++ b/uid2_client/identity_map_client.py @@ -34,15 +34,21 @@ def __init__(self, base_url, api_key, client_secret): self._api_key = api_key self._client_secret = base64.b64decode(client_secret) - def generate_identity_map(self, identity_map_input, timestamp): + def generate_identity_map(self, identity_map_input, timestamp=None): + """Generate identity map. + + Args: + identity_map_input: Input for identity map generation. + timestamp: Optional timestamp for the request. If not provided, the current UTC time is used. + """ + if timestamp is None: + timestamp = dt.datetime.now(tz=timezone.utc) + req, nonce = make_v2_request(self._client_secret, timestamp, identity_map_input.get_identity_map_input_as_json_string().encode()) resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req) resp_body = parse_v2_response(self._client_secret, resp.read(), nonce) return IdentityMapResponse(resp_body, identity_map_input) - - def generate_identity_map(self, identity_map_input): - return self.generate_identity_map(identity_map_input, dt.datetime.now(tz=timezone.utc)) def get_identity_buckets(self, since_timestamp): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), From ba45cba124eb9ddcccd9465d601bd6ff3ba94bb3 Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Wed, 5 Mar 2025 11:36:28 +1100 Subject: [PATCH 3/5] Add access to response_json --- uid2_client/identity_map_response.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/uid2_client/identity_map_response.py b/uid2_client/identity_map_response.py index 814cd74..e56512b 100644 --- a/uid2_client/identity_map_response.py +++ b/uid2_client/identity_map_response.py @@ -5,13 +5,13 @@ class IdentityMapResponse: def __init__(self, response, identity_map_input): self._mapped_identities = {} self._unmapped_identities = {} - response_json = json.loads(response) - self._status = response_json["status"] + self.response_json = json.loads(response) + self._status = self.response_json["status"] if not self.is_success(): raise ValueError("Got unexpected identity map status: " + self._status) - body = response_json["body"] + body = self.response_json["body"] for identity in body.get("mapped", []): raw_diis = self._get_raw_diis(identity, identity_map_input) @@ -44,6 +44,9 @@ def unmapped_identities(self): @property def status(self): return self._status + + def response_json(self): + return self.response_json class MappedIdentity: From d48e879ff7420c501597ac4b203214dbad7101f5 Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Wed, 5 Mar 2025 11:37:44 +1100 Subject: [PATCH 4/5] Revert timestamp --- uid2_client/identity_map_client.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/uid2_client/identity_map_client.py b/uid2_client/identity_map_client.py index b85b338..d050456 100644 --- a/uid2_client/identity_map_client.py +++ b/uid2_client/identity_map_client.py @@ -34,17 +34,8 @@ def __init__(self, base_url, api_key, client_secret): self._api_key = api_key self._client_secret = base64.b64decode(client_secret) - def generate_identity_map(self, identity_map_input, timestamp=None): - """Generate identity map. - - Args: - identity_map_input: Input for identity map generation. - timestamp: Optional timestamp for the request. If not provided, the current UTC time is used. - """ - if timestamp is None: - timestamp = dt.datetime.now(tz=timezone.utc) - - req, nonce = make_v2_request(self._client_secret, timestamp, + def generate_identity_map(self, identity_map_input): + req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), identity_map_input.get_identity_map_input_as_json_string().encode()) resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req) resp_body = parse_v2_response(self._client_secret, resp.read(), nonce) From 656a4f2c3803680add8c3cf911714b09b76e06ac Mon Sep 17 00:00:00 2001 From: Katherine Chen Date: Wed, 5 Mar 2025 13:24:10 +1100 Subject: [PATCH 5/5] Add fuctionality to calculate elapsed --- uid2_client/identity_map_client.py | 6 +++++- uid2_client/identity_map_response.py | 23 +++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/uid2_client/identity_map_client.py b/uid2_client/identity_map_client.py index d050456..d77ec9d 100644 --- a/uid2_client/identity_map_client.py +++ b/uid2_client/identity_map_client.py @@ -1,6 +1,7 @@ import base64 import datetime as dt import json +import time from datetime import timezone from .identity_buckets_response import IdentityBucketsResponse @@ -37,9 +38,12 @@ def __init__(self, base_url, api_key, client_secret): def generate_identity_map(self, identity_map_input): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), identity_map_input.get_identity_map_input_as_json_string().encode()) + start_time = time.time() resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req) resp_body = parse_v2_response(self._client_secret, resp.read(), nonce) - return IdentityMapResponse(resp_body, identity_map_input) + end_time = time.time() + elapsed_time = end_time - start_time + return IdentityMapResponse(resp_body, identity_map_input, elapsed_time) def get_identity_buckets(self, since_timestamp): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), diff --git a/uid2_client/identity_map_response.py b/uid2_client/identity_map_response.py index e56512b..5fe9487 100644 --- a/uid2_client/identity_map_response.py +++ b/uid2_client/identity_map_response.py @@ -2,16 +2,21 @@ class IdentityMapResponse: - def __init__(self, response, identity_map_input): + def __init__(self, response, identity_map_input, elapsed_time=None): self._mapped_identities = {} self._unmapped_identities = {} - self.response_json = json.loads(response) - self._status = self.response_json["status"] + self._response = response + self._elapsed_time = None + response_json = json.loads(response) + self._status = response_json["status"] + + if elapsed_time is not None: + self._elapsed_time = elapsed_time if not self.is_success(): raise ValueError("Got unexpected identity map status: " + self._status) - body = self.response_json["body"] + body = response_json["body"] for identity in body.get("mapped", []): raw_diis = self._get_raw_diis(identity, identity_map_input) @@ -44,9 +49,15 @@ def unmapped_identities(self): @property def status(self): return self._status + + @property + def elapsed_time(self): + return self._elapsed_time - def response_json(self): - return self.response_json + + @property + def response(self): + return self._response class MappedIdentity: