From bf12a5ebf490a11841aeaf6929fc9259bea3aa61 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Thu, 19 Dec 2024 13:03:14 +0100 Subject: [PATCH 1/4] Add functions to work with encoded API IDs --- src/xurrent/core.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/xurrent/core.py b/src/xurrent/core.py index 34aeefc..641d131 100644 --- a/src/xurrent/core.py +++ b/src/xurrent/core.py @@ -6,6 +6,7 @@ import logging import json import re +import base64 class LogLevel(Enum): DEBUG = logging.DEBUG @@ -245,3 +246,29 @@ def create_filter_string(self, filter: dict): for key, value in filter.items(): filter_string += f'{key}={value}&' return filter_string[:-1] + + def decode_api_id(self, id: str): + """ + API resource IDs are base64-encoded strings with the padding bytes stripped off. + Ensure approproate padding and decode. + :param id: Encoded Xurrent resource ID + :return: String containing the decoded ID + >>> helper.decode_api_id('SGVsbG8sIHdvcmxkIQ') + 'Hello, world!' + """ + #Get the length remainder of 4, fill the remainder to be a power of 4, but only if it is not already 4 + padding_count = (4 - (len(id) % 4)) % 4 + padding = "=" * padding_count + value = id + padding + return base64.decodebytes(value.encode()).decode() + + def encode_api_id(self, id: str): + """ + API resource IDs are base64-encoded strings with the padding bytes stripped off. + Encode and strip padding. + :param id: Xurrent resource ID to encode + :return: String containing the encoded ID + >>> helper.encode_api_id('Hello, world!') + 'SGVsbG8sIHdvcmxkIQ' + """ + return base64.encodebytes(id.encode()).decode().strip().rstrip("=") From 1fd1898f753ba0c765197817f6e78690ac2e4b45 Mon Sep 17 00:00:00 2001 From: Fabian Franz Steiner <75947402+fasteiner@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:36:25 +0100 Subject: [PATCH 2/4] Update core.py fix python tests --- src/xurrent/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xurrent/core.py b/src/xurrent/core.py index 641d131..28449e1 100644 --- a/src/xurrent/core.py +++ b/src/xurrent/core.py @@ -253,6 +253,7 @@ def decode_api_id(self, id: str): Ensure approproate padding and decode. :param id: Encoded Xurrent resource ID :return: String containing the decoded ID + >>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False) >>> helper.decode_api_id('SGVsbG8sIHdvcmxkIQ') 'Hello, world!' """ @@ -268,6 +269,7 @@ def encode_api_id(self, id: str): Encode and strip padding. :param id: Xurrent resource ID to encode :return: String containing the encoded ID + >>> helper = XurrentApiHelper('https://api.example.com', 'api_key', 'account', False) >>> helper.encode_api_id('Hello, world!') 'SGVsbG8sIHdvcmxkIQ' """ From e42d9a07f089f38e4f18066e11c5417778d135e9 Mon Sep 17 00:00:00 2001 From: Fabian Franz Steiner <75947402+fasteiner@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:01:31 +0100 Subject: [PATCH 3/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9759f5d..1ee24c2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ This module is used to interact with the Xurrent API. It provides a set of class uri = "/requests?subject=Example Subject" connection_object.api_call(uri, 'GET') + # Convert node ID + helper.decode_api_id('ZmFiaWFuc3RlaW5lci4yNDEyMTAxMDE0MTJANG1lLWRlbW8uY29tL1JlcS83MDU3NTU') # fabiansteiner.241210101412@4me-demo.com/Req/705755 + # this can be used to derive the ID from the nodeID + ``` #### People From 20a36d36d11fbd3a3dccf50360274db3fec809bb Mon Sep 17 00:00:00 2001 From: "Ing. Fabian Franz Steiner BSc." Date: Wed, 8 Jan 2025 21:19:13 +0100 Subject: [PATCH 4/4] Update ChangeLog and version to 0.0.2.11; add encode_api_id and decode_api_id functions --- ChangeLog.md | 6 ++++++ pyproject.toml | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 0a5b597..ea40d82 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # Change Log +## v0.0.2.11 + +### New Features + +- Core: add function decode_api_id and encode_api_id to convert between nodeID and normal ID + ## v0.0.2.10 ### New Features diff --git a/pyproject.toml b/pyproject.toml index f832ae7..045c819 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "xurrent" -version = "0.0.2.10" +version = "0.0.2.11" authors = [ { name="Fabian Steiner", email="fabian@stei-ner.net" }, ] @@ -18,7 +18,7 @@ Homepage = "https://github.com/fasteiner/xurrent-python" Issues = "https://github.com/fasteiner/xurrent-python/issues" [tool.poetry] name = "xurrent" -version = "0.0.2.10" +version = "0.0.2.11" description = "A python module to interact with the Xurrent API." authors = ["Ing. Fabian Franz Steiner BSc. "] readme = "README.md"