Commit bcb940ce authored by Grant's avatar Grant
Browse files

add aability to list all buckets

parent 67c9d9ca
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -50,3 +50,21 @@ class InfluxMixin:
        except Exception as error:
            self.logger.error(f"Error during query execution: {error}")
        return None

    def list_buckets(self):
        """List all buckets in the InfluxDB instance.

        :return: List of bucket names or None if an error occurs.
        """
        if not self.client:
            self.logger.info('InfluxDB client not created, creating now.')
            if not self.open():
                return None
        self.logger.debug('Fetching list of buckets.')
        try:
            buckets_api = self.client.buckets_api()
            buckets = buckets_api.find_buckets()
            return [bucket.name for bucket in buckets.buckets]
        except Exception as error:
            self.logger.error(f'Error fetching buckets: {error}')
            return None