From bc3a8a37b83aa8432630ab85ee8379fc254be45b Mon Sep 17 00:00:00 2001 From: Russ Savage Date: Wed, 28 Apr 2021 14:54:29 -0700 Subject: [PATCH 1/5] feat: add paging to find_buckets function --- influxdb_client/client/bucket_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdb_client/client/bucket_api.py b/influxdb_client/client/bucket_api.py index cd91ef42..7eb8461c 100644 --- a/influxdb_client/client/bucket_api.py +++ b/influxdb_client/client/bucket_api.py @@ -87,6 +87,6 @@ def find_bucket_by_name(self, bucket_name): else: return None - def find_buckets(self): + def find_buckets(self, limit=20, offset=0): """Get all buckets.""" - return self._buckets_service.get_buckets() + return self._buckets_service.get_buckets(limit=limit, offset=offset) From 0aa599d41b30ea1280b02bb25e8f07c705db7f3f Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 29 Apr 2021 12:16:50 +0200 Subject: [PATCH 2/5] feat: use `kwargs` to pass query parameters into API list call --- influxdb_client/client/authorizations_api.py | 8 ++++---- influxdb_client/client/bucket_api.py | 15 ++++++++++++--- influxdb_client/client/labels_api.py | 6 ++++-- influxdb_client/client/organizations_api.py | 15 ++++++++++++--- influxdb_client/client/tasks_api.py | 12 ++++++------ tests/test_BucketsApi.py | 20 ++++++++++++++++++++ 6 files changed, 58 insertions(+), 18 deletions(-) diff --git a/influxdb_client/client/authorizations_api.py b/influxdb_client/client/authorizations_api.py index 32deffae..9c5bfe84 100644 --- a/influxdb_client/client/authorizations_api.py +++ b/influxdb_client/client/authorizations_api.py @@ -42,10 +42,10 @@ def find_authorizations(self, **kwargs): """ Get a list of all authorizations. - :param str user_id: filter authorizations belonging to a user id - :param str user: filter authorizations belonging to a user name - :param str org_id: filter authorizations belonging to a org id - :param str org: filter authorizations belonging to a org name + :key str user_id: filter authorizations belonging to a user id + :key str user: filter authorizations belonging to a user name + :key str org_id: filter authorizations belonging to a org id + :key str org: filter authorizations belonging to a org name :return: Authorizations """ authorizations = self._authorizations_service.get_authorizations(**kwargs) diff --git a/influxdb_client/client/bucket_api.py b/influxdb_client/client/bucket_api.py index 7eb8461c..46826742 100644 --- a/influxdb_client/client/bucket_api.py +++ b/influxdb_client/client/bucket_api.py @@ -87,6 +87,15 @@ def find_bucket_by_name(self, bucket_name): else: return None - def find_buckets(self, limit=20, offset=0): - """Get all buckets.""" - return self._buckets_service.get_buckets(limit=limit, offset=offset) + def find_buckets(self, **kwargs): + """List buckets. + + :key int offset: Offset for pagination + :key int limit: Limit for pagination + :key str after: The last resource ID from which to seek from (but not including). This is to be used instead of `offset`. + :key str org: The organization name. + :key str org_id: The organization ID. + :key str name: Only returns buckets with a specific name. + :return: Buckets + """ + return self._buckets_service.get_buckets(**kwargs) diff --git a/influxdb_client/client/labels_api.py b/influxdb_client/client/labels_api.py index 9cb43c5a..006cb90c 100644 --- a/influxdb_client/client/labels_api.py +++ b/influxdb_client/client/labels_api.py @@ -67,13 +67,15 @@ def clone_label(self, cloned_name: str, label: Label) -> Label: return self.create_label(name=cloned_name, properties=cloned_properties, org_id=label.org_id) - def find_labels(self) -> List['Label']: + def find_labels(self, **kwargs) -> List['Label']: """ Get all available labels. + :key str org_id: The organization ID. + :return: labels """ - return self._service.get_labels().labels + return self._service.get_labels(**kwargs).labels def find_label_by_id(self, label_id: str): """ diff --git a/influxdb_client/client/organizations_api.py b/influxdb_client/client/organizations_api.py index ec59b04f..6c1301e0 100644 --- a/influxdb_client/client/organizations_api.py +++ b/influxdb_client/client/organizations_api.py @@ -26,9 +26,18 @@ def find_organization(self, org_id): """Retrieve an organization.""" return self._organizations_service.get_orgs_id(org_id=org_id) - def find_organizations(self): - """List all organizations.""" - return self._organizations_service.get_orgs().orgs + def find_organizations(self, **kwargs): + """ + List all organizations. + + :key int offset: Offset for pagination + :key int limit: Limit for pagination + :key bool descending: + :key str org: Filter organizations to a specific organization name. + :key str org_id: Filter organizations to a specific organization ID. + :key str user_id: Filter organizations to a specific user ID. + """ + return self._organizations_service.get_orgs(**kwargs).orgs def create_organization(self, name: str = None, organization: Organization = None) -> Organization: """Create an organization.""" diff --git a/influxdb_client/client/tasks_api.py b/influxdb_client/client/tasks_api.py index d67b5d73..d6b318b1 100644 --- a/influxdb_client/client/tasks_api.py +++ b/influxdb_client/client/tasks_api.py @@ -28,12 +28,12 @@ def find_task_by_id(self, task_id) -> Task: def find_tasks(self, **kwargs): """List all tasks. - :param str name: only returns tasks with the specified name - :param str after: returns tasks after specified ID - :param str user: filter tasks to a specific user ID - :param str org: filter tasks to a specific organization name - :param str org_id: filter tasks to a specific organization ID - :param int limit: the number of tasks to return + :key str name: only returns tasks with the specified name + :key str after: returns tasks after specified ID + :key str user: filter tasks to a specific user ID + :key str org: filter tasks to a specific organization name + :key str org_id: filter tasks to a specific organization ID + :key int limit: the number of tasks to return :return: Tasks """ return self._service.get_tasks(**kwargs).tasks diff --git a/tests/test_BucketsApi.py b/tests/test_BucketsApi.py index 768e002d..79e0c458 100644 --- a/tests/test_BucketsApi.py +++ b/tests/test_BucketsApi.py @@ -83,6 +83,26 @@ def test_create_bucket_retention_list(self): self.delete_test_bucket(my_bucket) + def test_pagination(self): + my_org = self.find_my_org() + buckets = self.buckets_api.find_buckets().buckets + size = len(buckets) + + # create 2 buckets + self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id) + self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id) + + buckets = self.buckets_api.find_buckets().buckets + self.assertEqual(size + 2, len(buckets)) + + # offset 1 + buckets = self.buckets_api.find_buckets(offset=1).buckets + self.assertEqual(size + 1, len(buckets)) + + # count 1 + buckets = self.buckets_api.find_buckets(limit=1).buckets + self.assertEqual(1, len(buckets)) + if __name__ == '__main__': unittest.main() From c229f5ceb1d11ea9408604cbafbd56c79ca606dc Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 29 Apr 2021 12:22:13 +0200 Subject: [PATCH 3/5] docs: update CHANGELOG.md --- CHANGELOG.md | 1 + influxdb_client/client/bucket_api.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5bc4403..61556715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features 1. [#203](https://github.com/influxdata/influxdb-client-python/issues/219): Bind query parameters 1. [#225](https://github.com/influxdata/influxdb-client-python/pull/225): Exponential random backoff retry strategy +1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination. ### Bug Fixes 1. [#222](https://github.com/influxdata/influxdb-client-python/pull/222): Pass configured timeout to HTTP client diff --git a/influxdb_client/client/bucket_api.py b/influxdb_client/client/bucket_api.py index 46826742..c20e6c59 100644 --- a/influxdb_client/client/bucket_api.py +++ b/influxdb_client/client/bucket_api.py @@ -92,7 +92,8 @@ def find_buckets(self, **kwargs): :key int offset: Offset for pagination :key int limit: Limit for pagination - :key str after: The last resource ID from which to seek from (but not including). This is to be used instead of `offset`. + :key str after: The last resource ID from which to seek from (but not including). + This is to be used instead of `offset`. :key str org: The organization name. :key str org_id: The organization ID. :key str name: Only returns buckets with a specific name. From 11ae14c0b4d040b2211dd4eb6e83b79f6182917e Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 30 Apr 2021 08:47:22 +0200 Subject: [PATCH 4/5] docs: update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61556715..f6f80e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ ## 1.18.0 [unreleased] +### Features +1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination. + ## 1.17.0 [2021-04-30] ### Features 1. [#203](https://github.com/influxdata/influxdb-client-python/issues/219): Bind query parameters 1. [#225](https://github.com/influxdata/influxdb-client-python/pull/225): Exponential random backoff retry strategy -1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination. ### Bug Fixes 1. [#222](https://github.com/influxdata/influxdb-client-python/pull/222): Pass configured timeout to HTTP client From 96c993ffc19cdde8f49e609af7ecec37612d8dba Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Wed, 5 May 2021 09:25:52 +0200 Subject: [PATCH 5/5] chore: find organization by name --- examples/buckets_management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/buckets_management.py b/examples/buckets_management.py index a26926ee..2ff7966f 100644 --- a/examples/buckets_management.py +++ b/examples/buckets_management.py @@ -17,7 +17,7 @@ The Bucket API uses as a parameter the Organization ID. We have to retrieve ID by Organization API. """ org_name = "my-org" - org = list(filter(lambda it: it.name == org_name, client.organizations_api().find_organizations()))[0] + org = client.organizations_api().find_organizations(org=org_name)[0] """ Create Bucket with retention policy set to 3600 seconds and name "bucket-by-python" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy