From b057ca27405bb9bfe02b44d01197ad833294e03a Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 3 Nov 2022 12:59:20 +0100 Subject: [PATCH 01/15] feat: add Explicit bucket schemas API --- influxdb_client/__init__.py | 8 + influxdb_client/client/__init__.py | 1 + influxdb_client/client/write/__init__.py | 1 + influxdb_client/domain/__init__.py | 7 + influxdb_client/domain/column_data_type.py | 91 +++ .../domain/column_semantic_type.py | 89 +++ influxdb_client/domain/measurement_schema.py | 262 ++++++++ .../domain/measurement_schema_column.py | 155 +++++ .../measurement_schema_create_request.py | 140 +++++ .../domain/measurement_schema_list.py | 108 ++++ .../measurement_schema_update_request.py | 112 ++++ influxdb_client/service/__init__.py | 1 + .../service/bucket_schemas_service.py | 569 ++++++++++++++++++ tests/__init__.py | 1 + 14 files changed, 1545 insertions(+) create mode 100644 influxdb_client/domain/column_data_type.py create mode 100644 influxdb_client/domain/column_semantic_type.py create mode 100644 influxdb_client/domain/measurement_schema.py create mode 100644 influxdb_client/domain/measurement_schema_column.py create mode 100644 influxdb_client/domain/measurement_schema_create_request.py create mode 100644 influxdb_client/domain/measurement_schema_list.py create mode 100644 influxdb_client/domain/measurement_schema_update_request.py create mode 100644 influxdb_client/service/bucket_schemas_service.py diff --git a/influxdb_client/__init__.py b/influxdb_client/__init__.py index fbb4d6b8..a1009511 100644 --- a/influxdb_client/__init__.py +++ b/influxdb_client/__init__.py @@ -17,6 +17,7 @@ # import apis into sdk package from influxdb_client.service.authorizations_service import AuthorizationsService from influxdb_client.service.backup_service import BackupService +from influxdb_client.service.bucket_schemas_service import BucketSchemasService from influxdb_client.service.buckets_service import BucketsService from influxdb_client.service.cells_service import CellsService from influxdb_client.service.checks_service import ChecksService @@ -100,6 +101,8 @@ from influxdb_client.domain.check_status_level import CheckStatusLevel from influxdb_client.domain.check_view_properties import CheckViewProperties from influxdb_client.domain.checks import Checks +from influxdb_client.domain.column_data_type import ColumnDataType +from influxdb_client.domain.column_semantic_type import ColumnSemanticType from influxdb_client.domain.conditional_expression import ConditionalExpression from influxdb_client.domain.config import Config from influxdb_client.domain.constant_variable_properties import ConstantVariableProperties @@ -167,6 +170,11 @@ from influxdb_client.domain.logs import Logs from influxdb_client.domain.map_variable_properties import MapVariableProperties from influxdb_client.domain.markdown_view_properties import MarkdownViewProperties +from influxdb_client.domain.measurement_schema import MeasurementSchema +from influxdb_client.domain.measurement_schema_column import MeasurementSchemaColumn +from influxdb_client.domain.measurement_schema_create_request import MeasurementSchemaCreateRequest +from influxdb_client.domain.measurement_schema_list import MeasurementSchemaList +from influxdb_client.domain.measurement_schema_update_request import MeasurementSchemaUpdateRequest from influxdb_client.domain.member_assignment import MemberAssignment from influxdb_client.domain.member_expression import MemberExpression from influxdb_client.domain.metadata_backup import MetadataBackup diff --git a/influxdb_client/client/__init__.py b/influxdb_client/client/__init__.py index 06bcdf84..0d21a438 100644 --- a/influxdb_client/client/__init__.py +++ b/influxdb_client/client/__init__.py @@ -15,6 +15,7 @@ # import apis into api package from influxdb_client.service.authorizations_service import AuthorizationsService from influxdb_client.service.backup_service import BackupService +from influxdb_client.service.bucket_schemas_service import BucketSchemasService from influxdb_client.service.buckets_service import BucketsService from influxdb_client.service.cells_service import CellsService from influxdb_client.service.checks_service import ChecksService diff --git a/influxdb_client/client/write/__init__.py b/influxdb_client/client/write/__init__.py index 06bcdf84..0d21a438 100644 --- a/influxdb_client/client/write/__init__.py +++ b/influxdb_client/client/write/__init__.py @@ -15,6 +15,7 @@ # import apis into api package from influxdb_client.service.authorizations_service import AuthorizationsService from influxdb_client.service.backup_service import BackupService +from influxdb_client.service.bucket_schemas_service import BucketSchemasService from influxdb_client.service.buckets_service import BucketsService from influxdb_client.service.cells_service import CellsService from influxdb_client.service.checks_service import ChecksService diff --git a/influxdb_client/domain/__init__.py b/influxdb_client/domain/__init__.py index 61351d00..e9a69d61 100644 --- a/influxdb_client/domain/__init__.py +++ b/influxdb_client/domain/__init__.py @@ -56,6 +56,8 @@ from influxdb_client.domain.check_status_level import CheckStatusLevel from influxdb_client.domain.check_view_properties import CheckViewProperties from influxdb_client.domain.checks import Checks +from influxdb_client.domain.column_data_type import ColumnDataType +from influxdb_client.domain.column_semantic_type import ColumnSemanticType from influxdb_client.domain.conditional_expression import ConditionalExpression from influxdb_client.domain.config import Config from influxdb_client.domain.constant_variable_properties import ConstantVariableProperties @@ -123,6 +125,11 @@ from influxdb_client.domain.logs import Logs from influxdb_client.domain.map_variable_properties import MapVariableProperties from influxdb_client.domain.markdown_view_properties import MarkdownViewProperties +from influxdb_client.domain.measurement_schema import MeasurementSchema +from influxdb_client.domain.measurement_schema_column import MeasurementSchemaColumn +from influxdb_client.domain.measurement_schema_create_request import MeasurementSchemaCreateRequest +from influxdb_client.domain.measurement_schema_list import MeasurementSchemaList +from influxdb_client.domain.measurement_schema_update_request import MeasurementSchemaUpdateRequest from influxdb_client.domain.member_assignment import MemberAssignment from influxdb_client.domain.member_expression import MemberExpression from influxdb_client.domain.metadata_backup import MetadataBackup diff --git a/influxdb_client/domain/column_data_type.py b/influxdb_client/domain/column_data_type.py new file mode 100644 index 00000000..e2a2f2c3 --- /dev/null +++ b/influxdb_client/domain/column_data_type.py @@ -0,0 +1,91 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class ColumnDataType(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + INTEGER = "integer" + FLOAT = "float" + BOOLEAN = "boolean" + STRING = "string" + UNSIGNED = "unsigned" + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + } + + attribute_map = { + } + + def __init__(self): # noqa: E501,D401,D403 + """ColumnDataType - a model defined in OpenAPI.""" # noqa: E501 self.discriminator = None + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, ColumnDataType): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/domain/column_semantic_type.py b/influxdb_client/domain/column_semantic_type.py new file mode 100644 index 00000000..3f88a133 --- /dev/null +++ b/influxdb_client/domain/column_semantic_type.py @@ -0,0 +1,89 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class ColumnSemanticType(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + TIMESTAMP = "timestamp" + TAG = "tag" + FIELD = "field" + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + } + + attribute_map = { + } + + def __init__(self): # noqa: E501,D401,D403 + """ColumnSemanticType - a model defined in OpenAPI.""" # noqa: E501 self.discriminator = None + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, ColumnSemanticType): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/domain/measurement_schema.py b/influxdb_client/domain/measurement_schema.py new file mode 100644 index 00000000..f2a48faa --- /dev/null +++ b/influxdb_client/domain/measurement_schema.py @@ -0,0 +1,262 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class MeasurementSchema(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'id': 'str', + 'org_id': 'str', + 'bucket_id': 'str', + 'name': 'str', + 'columns': 'list[MeasurementSchemaColumn]', + 'created_at': 'datetime', + 'updated_at': 'datetime' + } + + attribute_map = { + 'id': 'id', + 'org_id': 'orgID', + 'bucket_id': 'bucketID', + 'name': 'name', + 'columns': 'columns', + 'created_at': 'createdAt', + 'updated_at': 'updatedAt' + } + + def __init__(self, id=None, org_id=None, bucket_id=None, name=None, columns=None, created_at=None, updated_at=None): # noqa: E501,D401,D403 + """MeasurementSchema - a model defined in OpenAPI.""" # noqa: E501 + self._id = None + self._org_id = None + self._bucket_id = None + self._name = None + self._columns = None + self._created_at = None + self._updated_at = None + self.discriminator = None + + self.id = id + if org_id is not None: + self.org_id = org_id + if bucket_id is not None: + self.bucket_id = bucket_id + self.name = name + self.columns = columns + self.created_at = created_at + self.updated_at = updated_at + + @property + def id(self): + """Get the id of this MeasurementSchema. + + :return: The id of this MeasurementSchema. + :rtype: str + """ # noqa: E501 + return self._id + + @id.setter + def id(self, id): + """Set the id of this MeasurementSchema. + + :param id: The id of this MeasurementSchema. + :type: str + """ # noqa: E501 + if id is None: + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + self._id = id + + @property + def org_id(self): + """Get the org_id of this MeasurementSchema. + + The ID of the organization. + + :return: The org_id of this MeasurementSchema. + :rtype: str + """ # noqa: E501 + return self._org_id + + @org_id.setter + def org_id(self, org_id): + """Set the org_id of this MeasurementSchema. + + The ID of the organization. + + :param org_id: The org_id of this MeasurementSchema. + :type: str + """ # noqa: E501 + self._org_id = org_id + + @property + def bucket_id(self): + """Get the bucket_id of this MeasurementSchema. + + The ID of the bucket that the measurement schema is associated with. + + :return: The bucket_id of this MeasurementSchema. + :rtype: str + """ # noqa: E501 + return self._bucket_id + + @bucket_id.setter + def bucket_id(self, bucket_id): + """Set the bucket_id of this MeasurementSchema. + + The ID of the bucket that the measurement schema is associated with. + + :param bucket_id: The bucket_id of this MeasurementSchema. + :type: str + """ # noqa: E501 + self._bucket_id = bucket_id + + @property + def name(self): + """Get the name of this MeasurementSchema. + + :return: The name of this MeasurementSchema. + :rtype: str + """ # noqa: E501 + return self._name + + @name.setter + def name(self, name): + """Set the name of this MeasurementSchema. + + :param name: The name of this MeasurementSchema. + :type: str + """ # noqa: E501 + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + self._name = name + + @property + def columns(self): + """Get the columns of this MeasurementSchema. + + Ordered collection of column definitions. + + :return: The columns of this MeasurementSchema. + :rtype: list[MeasurementSchemaColumn] + """ # noqa: E501 + return self._columns + + @columns.setter + def columns(self, columns): + """Set the columns of this MeasurementSchema. + + Ordered collection of column definitions. + + :param columns: The columns of this MeasurementSchema. + :type: list[MeasurementSchemaColumn] + """ # noqa: E501 + if columns is None: + raise ValueError("Invalid value for `columns`, must not be `None`") # noqa: E501 + self._columns = columns + + @property + def created_at(self): + """Get the created_at of this MeasurementSchema. + + :return: The created_at of this MeasurementSchema. + :rtype: datetime + """ # noqa: E501 + return self._created_at + + @created_at.setter + def created_at(self, created_at): + """Set the created_at of this MeasurementSchema. + + :param created_at: The created_at of this MeasurementSchema. + :type: datetime + """ # noqa: E501 + if created_at is None: + raise ValueError("Invalid value for `created_at`, must not be `None`") # noqa: E501 + self._created_at = created_at + + @property + def updated_at(self): + """Get the updated_at of this MeasurementSchema. + + :return: The updated_at of this MeasurementSchema. + :rtype: datetime + """ # noqa: E501 + return self._updated_at + + @updated_at.setter + def updated_at(self, updated_at): + """Set the updated_at of this MeasurementSchema. + + :param updated_at: The updated_at of this MeasurementSchema. + :type: datetime + """ # noqa: E501 + if updated_at is None: + raise ValueError("Invalid value for `updated_at`, must not be `None`") # noqa: E501 + self._updated_at = updated_at + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, MeasurementSchema): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/domain/measurement_schema_column.py b/influxdb_client/domain/measurement_schema_column.py new file mode 100644 index 00000000..79ee3845 --- /dev/null +++ b/influxdb_client/domain/measurement_schema_column.py @@ -0,0 +1,155 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class MeasurementSchemaColumn(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'name': 'str', + 'type': 'ColumnSemanticType', + 'data_type': 'ColumnDataType' + } + + attribute_map = { + 'name': 'name', + 'type': 'type', + 'data_type': 'dataType' + } + + def __init__(self, name=None, type=None, data_type=None): # noqa: E501,D401,D403 + """MeasurementSchemaColumn - a model defined in OpenAPI.""" # noqa: E501 + self._name = None + self._type = None + self._data_type = None + self.discriminator = None + + self.name = name + self.type = type + if data_type is not None: + self.data_type = data_type + + @property + def name(self): + """Get the name of this MeasurementSchemaColumn. + + :return: The name of this MeasurementSchemaColumn. + :rtype: str + """ # noqa: E501 + return self._name + + @name.setter + def name(self, name): + """Set the name of this MeasurementSchemaColumn. + + :param name: The name of this MeasurementSchemaColumn. + :type: str + """ # noqa: E501 + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + self._name = name + + @property + def type(self): + """Get the type of this MeasurementSchemaColumn. + + :return: The type of this MeasurementSchemaColumn. + :rtype: ColumnSemanticType + """ # noqa: E501 + return self._type + + @type.setter + def type(self, type): + """Set the type of this MeasurementSchemaColumn. + + :param type: The type of this MeasurementSchemaColumn. + :type: ColumnSemanticType + """ # noqa: E501 + if type is None: + raise ValueError("Invalid value for `type`, must not be `None`") # noqa: E501 + self._type = type + + @property + def data_type(self): + """Get the data_type of this MeasurementSchemaColumn. + + :return: The data_type of this MeasurementSchemaColumn. + :rtype: ColumnDataType + """ # noqa: E501 + return self._data_type + + @data_type.setter + def data_type(self, data_type): + """Set the data_type of this MeasurementSchemaColumn. + + :param data_type: The data_type of this MeasurementSchemaColumn. + :type: ColumnDataType + """ # noqa: E501 + self._data_type = data_type + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, MeasurementSchemaColumn): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/domain/measurement_schema_create_request.py b/influxdb_client/domain/measurement_schema_create_request.py new file mode 100644 index 00000000..1308a2da --- /dev/null +++ b/influxdb_client/domain/measurement_schema_create_request.py @@ -0,0 +1,140 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class MeasurementSchemaCreateRequest(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'name': 'str', + 'columns': 'list[MeasurementSchemaColumn]' + } + + attribute_map = { + 'name': 'name', + 'columns': 'columns' + } + + def __init__(self, name=None, columns=None): # noqa: E501,D401,D403 + """MeasurementSchemaCreateRequest - a model defined in OpenAPI.""" # noqa: E501 + self._name = None + self._columns = None + self.discriminator = None + + self.name = name + self.columns = columns + + @property + def name(self): + """Get the name of this MeasurementSchemaCreateRequest. + + The [measurement](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#measurement) name. + + :return: The name of this MeasurementSchemaCreateRequest. + :rtype: str + """ # noqa: E501 + return self._name + + @name.setter + def name(self, name): + """Set the name of this MeasurementSchemaCreateRequest. + + The [measurement](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#measurement) name. + + :param name: The name of this MeasurementSchemaCreateRequest. + :type: str + """ # noqa: E501 + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + self._name = name + + @property + def columns(self): + """Get the columns of this MeasurementSchemaCreateRequest. + + Ordered collection of column definitions. + + :return: The columns of this MeasurementSchemaCreateRequest. + :rtype: list[MeasurementSchemaColumn] + """ # noqa: E501 + return self._columns + + @columns.setter + def columns(self, columns): + """Set the columns of this MeasurementSchemaCreateRequest. + + Ordered collection of column definitions. + + :param columns: The columns of this MeasurementSchemaCreateRequest. + :type: list[MeasurementSchemaColumn] + """ # noqa: E501 + if columns is None: + raise ValueError("Invalid value for `columns`, must not be `None`") # noqa: E501 + self._columns = columns + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, MeasurementSchemaCreateRequest): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/domain/measurement_schema_list.py b/influxdb_client/domain/measurement_schema_list.py new file mode 100644 index 00000000..f8a83dda --- /dev/null +++ b/influxdb_client/domain/measurement_schema_list.py @@ -0,0 +1,108 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class MeasurementSchemaList(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'measurement_schemas': 'list[MeasurementSchema]' + } + + attribute_map = { + 'measurement_schemas': 'measurementSchemas' + } + + def __init__(self, measurement_schemas=None): # noqa: E501,D401,D403 + """MeasurementSchemaList - a model defined in OpenAPI.""" # noqa: E501 + self._measurement_schemas = None + self.discriminator = None + + self.measurement_schemas = measurement_schemas + + @property + def measurement_schemas(self): + """Get the measurement_schemas of this MeasurementSchemaList. + + :return: The measurement_schemas of this MeasurementSchemaList. + :rtype: list[MeasurementSchema] + """ # noqa: E501 + return self._measurement_schemas + + @measurement_schemas.setter + def measurement_schemas(self, measurement_schemas): + """Set the measurement_schemas of this MeasurementSchemaList. + + :param measurement_schemas: The measurement_schemas of this MeasurementSchemaList. + :type: list[MeasurementSchema] + """ # noqa: E501 + if measurement_schemas is None: + raise ValueError("Invalid value for `measurement_schemas`, must not be `None`") # noqa: E501 + self._measurement_schemas = measurement_schemas + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, MeasurementSchemaList): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/domain/measurement_schema_update_request.py b/influxdb_client/domain/measurement_schema_update_request.py new file mode 100644 index 00000000..bdfa19c2 --- /dev/null +++ b/influxdb_client/domain/measurement_schema_update_request.py @@ -0,0 +1,112 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + + +class MeasurementSchemaUpdateRequest(object): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + 'columns': 'list[MeasurementSchemaColumn]' + } + + attribute_map = { + 'columns': 'columns' + } + + def __init__(self, columns=None): # noqa: E501,D401,D403 + """MeasurementSchemaUpdateRequest - a model defined in OpenAPI.""" # noqa: E501 + self._columns = None + self.discriminator = None + + self.columns = columns + + @property + def columns(self): + """Get the columns of this MeasurementSchemaUpdateRequest. + + An ordered collection of column definitions + + :return: The columns of this MeasurementSchemaUpdateRequest. + :rtype: list[MeasurementSchemaColumn] + """ # noqa: E501 + return self._columns + + @columns.setter + def columns(self, columns): + """Set the columns of this MeasurementSchemaUpdateRequest. + + An ordered collection of column definitions + + :param columns: The columns of this MeasurementSchemaUpdateRequest. + :type: list[MeasurementSchemaColumn] + """ # noqa: E501 + if columns is None: + raise ValueError("Invalid value for `columns`, must not be `None`") # noqa: E501 + self._columns = columns + + def to_dict(self): + """Return the model properties as a dict.""" + result = {} + + for attr, _ in self.openapi_types.items(): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Return the string representation of the model.""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`.""" + return self.to_str() + + def __eq__(self, other): + """Return true if both objects are equal.""" + if not isinstance(other, MeasurementSchemaUpdateRequest): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Return true if both objects are not equal.""" + return not self == other diff --git a/influxdb_client/service/__init__.py b/influxdb_client/service/__init__.py index 06bcdf84..0d21a438 100644 --- a/influxdb_client/service/__init__.py +++ b/influxdb_client/service/__init__.py @@ -15,6 +15,7 @@ # import apis into api package from influxdb_client.service.authorizations_service import AuthorizationsService from influxdb_client.service.backup_service import BackupService +from influxdb_client.service.bucket_schemas_service import BucketSchemasService from influxdb_client.service.buckets_service import BucketsService from influxdb_client.service.cells_service import CellsService from influxdb_client.service.checks_service import ChecksService diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py new file mode 100644 index 00000000..9c501172 --- /dev/null +++ b/influxdb_client/service/bucket_schemas_service.py @@ -0,0 +1,569 @@ +# coding: utf-8 + +""" +InfluxDB OSS API Service. + +The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint. # noqa: E501 + +OpenAPI spec version: 2.0.0 +Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import re # noqa: F401 + +from influxdb_client.service._base_service import _BaseService + + +class BucketSchemasService(_BaseService): + """NOTE: This class is auto generated by OpenAPI Generator. + + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + def __init__(self, api_client=None): # noqa: E501,D401,D403 + """BucketSchemasService - a operation defined in OpenAPI.""" + if api_client is None: + raise ValueError("Invalid value for `api_client`, must be defined.") + self.api_client = api_client + + def create_measurement_schema(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + """Create a measurement schema for a bucket. + + Creates an _explict_ measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. Use this endpoint to create schemas that prevent non-conforming write requests. #### Limitations - Buckets must be created with the "explict" `schemaType` in order to use schemas. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Create a bucket with an explicit schema](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/create-bucket/#create-a-bucket-with-an-explicit-schema) + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.create_measurement_schema(bucket_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Adds a schema for the specified bucket. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param MeasurementSchemaCreateRequest measurement_schema_create_request: + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.create_measurement_schema_with_http_info(bucket_id, **kwargs) # noqa: E501 + else: + (data) = self.create_measurement_schema_with_http_info(bucket_id, **kwargs) # noqa: E501 + return data + + def create_measurement_schema_with_http_info(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + """Create a measurement schema for a bucket. + + Creates an _explict_ measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. Use this endpoint to create schemas that prevent non-conforming write requests. #### Limitations - Buckets must be created with the "explict" `schemaType` in order to use schemas. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Create a bucket with an explicit schema](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/create-bucket/#create-a-bucket-with-an-explicit-schema) + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.create_measurement_schema_with_http_info(bucket_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Adds a schema for the specified bucket. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param MeasurementSchemaCreateRequest measurement_schema_create_request: + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._create_measurement_schema_prepare(bucket_id, **kwargs) + + return self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchema', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + async def create_measurement_schema_async(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + """Create a measurement schema for a bucket. + + Creates an _explict_ measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. Use this endpoint to create schemas that prevent non-conforming write requests. #### Limitations - Buckets must be created with the "explict" `schemaType` in order to use schemas. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Create a bucket with an explicit schema](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/create-bucket/#create-a-bucket-with-an-explicit-schema) + This method makes an asynchronous HTTP request. + + :param async_req bool + :param str bucket_id: A bucket ID. Adds a schema for the specified bucket. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param MeasurementSchemaCreateRequest measurement_schema_create_request: + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._create_measurement_schema_prepare(bucket_id, **kwargs) + + return await self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchema', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + def _create_measurement_schema_prepare(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + local_var_params = locals() + + all_params = ['bucket_id', 'org', 'org_id', 'measurement_schema_create_request'] # noqa: E501 + self._check_operation_params('create_measurement_schema', all_params, local_var_params) + # verify the required parameter 'bucket_id' is set + if ('bucket_id' not in local_var_params or + local_var_params['bucket_id'] is None): + raise ValueError("Missing the required parameter `bucket_id` when calling `create_measurement_schema`") # noqa: E501 + + path_params = {} + if 'bucket_id' in local_var_params: + path_params['bucketID'] = local_var_params['bucket_id'] # noqa: E501 + + query_params = [] + if 'org' in local_var_params: + query_params.append(('org', local_var_params['org'])) # noqa: E501 + if 'org_id' in local_var_params: + query_params.append(('orgID', local_var_params['org_id'])) # noqa: E501 + + header_params = {} + + body_params = None + if 'measurement_schema_create_request' in local_var_params: + body_params = local_var_params['measurement_schema_create_request'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + return local_var_params, path_params, query_params, header_params, body_params + + def get_measurement_schema(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + """Retrieve a measurement schema. + + Retrieves an explicit measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_measurement_schema(bucket_id, measurement_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Retrieves schemas for the specified bucket. (required) + :param str measurement_id: The measurement schema ID. Specifies the measurement schema to retrieve. (required) + :param str org: Organization name. Specifies the organization that owns the schema. + :param str org_id: Organization ID. Specifies the organization that owns the schema. + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.get_measurement_schema_with_http_info(bucket_id, measurement_id, **kwargs) # noqa: E501 + else: + (data) = self.get_measurement_schema_with_http_info(bucket_id, measurement_id, **kwargs) # noqa: E501 + return data + + def get_measurement_schema_with_http_info(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + """Retrieve a measurement schema. + + Retrieves an explicit measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_measurement_schema_with_http_info(bucket_id, measurement_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Retrieves schemas for the specified bucket. (required) + :param str measurement_id: The measurement schema ID. Specifies the measurement schema to retrieve. (required) + :param str org: Organization name. Specifies the organization that owns the schema. + :param str org_id: Organization ID. Specifies the organization that owns the schema. + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + + return self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchema', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + async def get_measurement_schema_async(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + """Retrieve a measurement schema. + + Retrieves an explicit measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). + This method makes an asynchronous HTTP request. + + :param async_req bool + :param str bucket_id: A bucket ID. Retrieves schemas for the specified bucket. (required) + :param str measurement_id: The measurement schema ID. Specifies the measurement schema to retrieve. (required) + :param str org: Organization name. Specifies the organization that owns the schema. + :param str org_id: Organization ID. Specifies the organization that owns the schema. + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + + return await self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchema', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + def _get_measurement_schema_prepare(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + local_var_params = locals() + + all_params = ['bucket_id', 'measurement_id', 'org', 'org_id'] # noqa: E501 + self._check_operation_params('get_measurement_schema', all_params, local_var_params) + # verify the required parameter 'bucket_id' is set + if ('bucket_id' not in local_var_params or + local_var_params['bucket_id'] is None): + raise ValueError("Missing the required parameter `bucket_id` when calling `get_measurement_schema`") # noqa: E501 + # verify the required parameter 'measurement_id' is set + if ('measurement_id' not in local_var_params or + local_var_params['measurement_id'] is None): + raise ValueError("Missing the required parameter `measurement_id` when calling `get_measurement_schema`") # noqa: E501 + + path_params = {} + if 'bucket_id' in local_var_params: + path_params['bucketID'] = local_var_params['bucket_id'] # noqa: E501 + if 'measurement_id' in local_var_params: + path_params['measurementID'] = local_var_params['measurement_id'] # noqa: E501 + + query_params = [] + if 'org' in local_var_params: + query_params.append(('org', local_var_params['org'])) # noqa: E501 + if 'org_id' in local_var_params: + query_params.append(('orgID', local_var_params['org_id'])) # noqa: E501 + + header_params = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + return local_var_params, path_params, query_params, header_params, body_params + + def get_measurement_schemas(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + """List measurement schemas of a bucket. + + Lists _explicit_ [schemas](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) (`"schemaType": "explicit"`) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. #### Related guides - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/) + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_measurement_schemas(bucket_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Lists measurement schemas for the specified bucket. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param str name: A measurement name. Only returns measurement schemas with the specified name. + :return: MeasurementSchemaList + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.get_measurement_schemas_with_http_info(bucket_id, **kwargs) # noqa: E501 + else: + (data) = self.get_measurement_schemas_with_http_info(bucket_id, **kwargs) # noqa: E501 + return data + + def get_measurement_schemas_with_http_info(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + """List measurement schemas of a bucket. + + Lists _explicit_ [schemas](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) (`"schemaType": "explicit"`) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. #### Related guides - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/) + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_measurement_schemas_with_http_info(bucket_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Lists measurement schemas for the specified bucket. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param str name: A measurement name. Only returns measurement schemas with the specified name. + :return: MeasurementSchemaList + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._get_measurement_schemas_prepare(bucket_id, **kwargs) + + return self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchemaList', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + async def get_measurement_schemas_async(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + """List measurement schemas of a bucket. + + Lists _explicit_ [schemas](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) (`"schemaType": "explicit"`) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. #### Related guides - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/) + This method makes an asynchronous HTTP request. + + :param async_req bool + :param str bucket_id: A bucket ID. Lists measurement schemas for the specified bucket. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param str name: A measurement name. Only returns measurement schemas with the specified name. + :return: MeasurementSchemaList + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._get_measurement_schemas_prepare(bucket_id, **kwargs) + + return await self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchemaList', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + def _get_measurement_schemas_prepare(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + local_var_params = locals() + + all_params = ['bucket_id', 'org', 'org_id', 'name'] # noqa: E501 + self._check_operation_params('get_measurement_schemas', all_params, local_var_params) + # verify the required parameter 'bucket_id' is set + if ('bucket_id' not in local_var_params or + local_var_params['bucket_id'] is None): + raise ValueError("Missing the required parameter `bucket_id` when calling `get_measurement_schemas`") # noqa: E501 + + path_params = {} + if 'bucket_id' in local_var_params: + path_params['bucketID'] = local_var_params['bucket_id'] # noqa: E501 + + query_params = [] + if 'org' in local_var_params: + query_params.append(('org', local_var_params['org'])) # noqa: E501 + if 'org_id' in local_var_params: + query_params.append(('orgID', local_var_params['org_id'])) # noqa: E501 + if 'name' in local_var_params: + query_params.append(('name', local_var_params['name'])) # noqa: E501 + + header_params = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + return local_var_params, path_params, query_params, header_params, body_params + + def update_measurement_schema(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + """Update a measurement schema. + + Updates a measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). Use this endpoint to update the fields (`name`, `type`, and `dataType`) of a measurement schema. #### Limitations - You can't update the `name` of a measurement. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/). + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.update_measurement_schema(bucket_id, measurement_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Specifies the bucket to retrieve schemas for. (required) + :param str measurement_id: A measurement schema ID. Retrieves the specified measurement schema. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param MeasurementSchemaUpdateRequest measurement_schema_update_request: + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.update_measurement_schema_with_http_info(bucket_id, measurement_id, **kwargs) # noqa: E501 + else: + (data) = self.update_measurement_schema_with_http_info(bucket_id, measurement_id, **kwargs) # noqa: E501 + return data + + def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + """Update a measurement schema. + + Updates a measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). Use this endpoint to update the fields (`name`, `type`, and `dataType`) of a measurement schema. #### Limitations - You can't update the `name` of a measurement. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/). + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.update_measurement_schema_with_http_info(bucket_id, measurement_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str bucket_id: A bucket ID. Specifies the bucket to retrieve schemas for. (required) + :param str measurement_id: A measurement schema ID. Retrieves the specified measurement schema. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param MeasurementSchemaUpdateRequest measurement_schema_update_request: + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._update_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + + return self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'PATCH', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchema', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + async def update_measurement_schema_async(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + """Update a measurement schema. + + Updates a measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). Use this endpoint to update the fields (`name`, `type`, and `dataType`) of a measurement schema. #### Limitations - You can't update the `name` of a measurement. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/). + This method makes an asynchronous HTTP request. + + :param async_req bool + :param str bucket_id: A bucket ID. Specifies the bucket to retrieve schemas for. (required) + :param str measurement_id: A measurement schema ID. Retrieves the specified measurement schema. (required) + :param str org: An organization name. Specifies the organization that owns the schema. + :param str org_id: An organization ID. Specifies the organization that owns the schema. + :param MeasurementSchemaUpdateRequest measurement_schema_update_request: + :return: MeasurementSchema + If the method is called asynchronously, + returns the request thread. + """ # noqa: E501 + local_var_params, path_params, query_params, header_params, body_params = \ + self._update_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + + return await self.api_client.call_api( + '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'PATCH', + path_params, + query_params, + header_params, + body=body_params, + post_params=[], + files={}, + response_type='MeasurementSchema', # noqa: E501 + auth_settings=[], + async_req=local_var_params.get('async_req'), + _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=local_var_params.get('_preload_content', True), + _request_timeout=local_var_params.get('_request_timeout'), + collection_formats={}, + urlopen_kw=kwargs.get('urlopen_kw', None)) + + def _update_measurement_schema_prepare(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + local_var_params = locals() + + all_params = ['bucket_id', 'measurement_id', 'org', 'org_id', 'measurement_schema_update_request'] # noqa: E501 + self._check_operation_params('update_measurement_schema', all_params, local_var_params) + # verify the required parameter 'bucket_id' is set + if ('bucket_id' not in local_var_params or + local_var_params['bucket_id'] is None): + raise ValueError("Missing the required parameter `bucket_id` when calling `update_measurement_schema`") # noqa: E501 + # verify the required parameter 'measurement_id' is set + if ('measurement_id' not in local_var_params or + local_var_params['measurement_id'] is None): + raise ValueError("Missing the required parameter `measurement_id` when calling `update_measurement_schema`") # noqa: E501 + + path_params = {} + if 'bucket_id' in local_var_params: + path_params['bucketID'] = local_var_params['bucket_id'] # noqa: E501 + if 'measurement_id' in local_var_params: + path_params['measurementID'] = local_var_params['measurement_id'] # noqa: E501 + + query_params = [] + if 'org' in local_var_params: + query_params.append(('org', local_var_params['org'])) # noqa: E501 + if 'org_id' in local_var_params: + query_params.append(('orgID', local_var_params['org_id'])) # noqa: E501 + + header_params = {} + + body_params = None + if 'measurement_schema_update_request' in local_var_params: + body_params = local_var_params['measurement_schema_update_request'] + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # HTTP header `Content-Type` + header_params['Content-Type'] = self.api_client.select_header_content_type( # noqa: E501 + ['application/json']) # noqa: E501 + + return local_var_params, path_params, query_params, header_params, body_params diff --git a/tests/__init__.py b/tests/__init__.py index 06bcdf84..0d21a438 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,6 +15,7 @@ # import apis into api package from influxdb_client.service.authorizations_service import AuthorizationsService from influxdb_client.service.backup_service import BackupService +from influxdb_client.service.bucket_schemas_service import BucketSchemasService from influxdb_client.service.buckets_service import BucketsService from influxdb_client.service.cells_service import CellsService from influxdb_client.service.checks_service import ChecksService From 9b8e182e278913ff5feec75382135e49331cd3e9 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 3 Nov 2022 15:10:22 +0100 Subject: [PATCH 02/15] feat: add warning about availability only on the InfluxDB Cloud --- influxdb_client/client/warnings.py | 22 +++++++++++++++++++ .../service/bucket_schemas_service.py | 4 ++++ .../service/invokable_scripts_service.py | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/influxdb_client/client/warnings.py b/influxdb_client/client/warnings.py index 066c3307..ecd02472 100644 --- a/influxdb_client/client/warnings.py +++ b/influxdb_client/client/warnings.py @@ -29,3 +29,25 @@ def print_warning(query: str): - https://docs.influxdata.com/flux/latest/stdlib/influxdata/influxdb/schema/fieldsascols/ """ warnings.warn(message, MissingPivotFunction) + + +class CloudOnlyWarning(UserWarning): + """User warning about availability only on the InfluxDB Cloud.""" + + @staticmethod + def print_warning(api_name: str, doc_url: str): + """Print warning about availability only on the InfluxDB Cloud.""" + + message = f"""The '{api_name}' API is available only on the InfluxDB Cloud. + +For more info see: + - {doc_url} + - https://docs.influxdata.com/influxdb/cloud/ + +You can disable this warning by: + import warnings + from influxdb_client.client.warnings import CloudOnlyWarning + + warnings.simplefilter("ignore", CloudOnlyWarning) +""" + warnings.warn(message, CloudOnlyWarning) diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py index 9c501172..bb6f432d 100644 --- a/influxdb_client/service/bucket_schemas_service.py +++ b/influxdb_client/service/bucket_schemas_service.py @@ -31,6 +31,10 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 raise ValueError("Invalid value for `api_client`, must be defined.") self.api_client = api_client + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') + def create_measurement_schema(self, bucket_id, **kwargs): # noqa: E501,D401,D403 """Create a measurement schema for a bucket. diff --git a/influxdb_client/service/invokable_scripts_service.py b/influxdb_client/service/invokable_scripts_service.py index 9b2680f8..72859e0d 100644 --- a/influxdb_client/service/invokable_scripts_service.py +++ b/influxdb_client/service/invokable_scripts_service.py @@ -31,6 +31,10 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 raise ValueError("Invalid value for `api_client`, must be defined.") self.api_client = api_client + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') + def delete_scripts_id(self, script_id, **kwargs): # noqa: E501,D401,D403 """Delete a script. From 6b91b0710e2d155935d01322c301f94d013280f4 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Thu, 3 Nov 2022 15:16:28 +0100 Subject: [PATCH 03/15] feat: add warning about availability only on the InfluxDB Cloud --- influxdb_client/client/warnings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb_client/client/warnings.py b/influxdb_client/client/warnings.py index ecd02472..75524758 100644 --- a/influxdb_client/client/warnings.py +++ b/influxdb_client/client/warnings.py @@ -38,7 +38,7 @@ class CloudOnlyWarning(UserWarning): def print_warning(api_name: str, doc_url: str): """Print warning about availability only on the InfluxDB Cloud.""" - message = f"""The '{api_name}' API is available only on the InfluxDB Cloud. + message = f"""The '{api_name}' is available only on the InfluxDB Cloud. For more info see: - {doc_url} From 9d952dff12fbba3c6bee90b6841b7a73bfb3b5af Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 08:00:37 +0100 Subject: [PATCH 04/15] feat: add test for warnings --- influxdb_client/client/warnings.py | 1 - tests/test_Warnings.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/test_Warnings.py diff --git a/influxdb_client/client/warnings.py b/influxdb_client/client/warnings.py index 75524758..b682ff86 100644 --- a/influxdb_client/client/warnings.py +++ b/influxdb_client/client/warnings.py @@ -37,7 +37,6 @@ class CloudOnlyWarning(UserWarning): @staticmethod def print_warning(api_name: str, doc_url: str): """Print warning about availability only on the InfluxDB Cloud.""" - message = f"""The '{api_name}' is available only on the InfluxDB Cloud. For more info see: diff --git a/tests/test_Warnings.py b/tests/test_Warnings.py new file mode 100644 index 00000000..019b9032 --- /dev/null +++ b/tests/test_Warnings.py @@ -0,0 +1,15 @@ +import unittest + +import pytest + +from influxdb_client import InfluxDBClient, BucketSchemasService +from influxdb_client.client.warnings import CloudOnlyWarning + + +class PointWarnings(unittest.TestCase): + + def test_cloud_only_warning(self): + with pytest.warns(CloudOnlyWarning) as warnings: + with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client: + BucketSchemasService(api_client=client.api_client) + self.assertEqual(1, len(warnings)) From c963e765c6c06b6d63ad243a3bde019284bddfcc Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 08:03:20 +0100 Subject: [PATCH 05/15] fix: code style --- influxdb_client/service/bucket_schemas_service.py | 2 +- influxdb_client/service/invokable_scripts_service.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py index bb6f432d..83292f0e 100644 --- a/influxdb_client/service/bucket_schemas_service.py +++ b/influxdb_client/service/bucket_schemas_service.py @@ -33,7 +33,7 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 from influxdb_client.client.warnings import CloudOnlyWarning CloudOnlyWarning.print_warning('BucketSchemasService', - 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 def create_measurement_schema(self, bucket_id, **kwargs): # noqa: E501,D401,D403 """Create a measurement schema for a bucket. diff --git a/influxdb_client/service/invokable_scripts_service.py b/influxdb_client/service/invokable_scripts_service.py index 72859e0d..e04e7745 100644 --- a/influxdb_client/service/invokable_scripts_service.py +++ b/influxdb_client/service/invokable_scripts_service.py @@ -33,7 +33,7 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 from influxdb_client.client.warnings import CloudOnlyWarning CloudOnlyWarning.print_warning('InvokableScriptsService', - 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 def delete_scripts_id(self, script_id, **kwargs): # noqa: E501,D401,D403 """Delete a script. From cffd55a1e2e0b1d642d494f16d3135adad22d13c Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 08:22:18 +0100 Subject: [PATCH 06/15] docs: clarify Cloud related examples --- examples/README.md | 10 +++++++--- examples/invokable_scripts.py | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/README.md b/examples/README.md index 7254f7a4..3612ea52 100644 --- a/examples/README.md +++ b/examples/README.md @@ -22,18 +22,22 @@ - [query_response_to_json.py](query_response_to_json.py) - How to serialize Query response to JSON - [query_with_profilers.py](query_with_profilers.py) - How to process profilers output by callback - ## Management API - [buckets_management.py](buckets_management.py) - How to create, list and delete Buckets - [monitoring_and_alerting.py](monitoring_and_alerting.py) - How to create the Check with Slack notification. - [task_example.py](task_example.py) - How to create a Task by API - [templates_management.py](templates_management.py) - How to use Templates and Stack API -## Others +## InfluxDB Cloud + +:warning: The following examples are related to [InfluxDB Cloud](https://docs.influxdata.com/influxdb/cloud/) and not available on a local InfluxDB OSS instance. + - [influx_cloud.py](influx_cloud.py) - How to connect to InfluxDB 2 Cloud +- [invokable_scripts.py](invokable_scripts.py) - How to use Invokable scripts Cloud API to create custom endpoints that query data + +## Others - [influxdb_18_example.py](influxdb_18_example.py) - How to connect to InfluxDB 1.8 - [nanosecond_precision.py](nanosecond_precision.py) - How to use nanoseconds precision -- [invokable_scripts.py](invokable_scripts.py) - How to use Invokable scripts Cloud API to create custom endpoints that query data - [connection_check.py](connection_check.py) - How to check connection configuration ## Asynchronous diff --git a/examples/invokable_scripts.py b/examples/invokable_scripts.py index 4648c2c6..09ea7794 100644 --- a/examples/invokable_scripts.py +++ b/examples/invokable_scripts.py @@ -1,4 +1,7 @@ """ +This example is related to `InfluxDB Cloud `_ and not available +on a local InfluxDB OSS instance. + How to use Invokable scripts Cloud API to create custom endpoints that query data """ import datetime From 509cccdd9ed57503390e0504263a8c16da6e4b25 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 13:31:35 +0100 Subject: [PATCH 07/15] feat: add an example `How to manage explicit bucket schemas to enforce column names, tags, fields, and data types for your data.` --- examples/README.md | 1 + examples/bucket_schemas.py | 95 ++++++++++++++++++++++++++++ influxdb_client/client/bucket_api.py | 2 +- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 examples/bucket_schemas.py diff --git a/examples/README.md b/examples/README.md index 3612ea52..1678d00e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -34,6 +34,7 @@ - [influx_cloud.py](influx_cloud.py) - How to connect to InfluxDB 2 Cloud - [invokable_scripts.py](invokable_scripts.py) - How to use Invokable scripts Cloud API to create custom endpoints that query data +- [bucket_schemas.py](bucket_schemas.py) - How to manage explicit bucket schemas to enforce column names, tags, fields, and data types for your data ## Others - [influxdb_18_example.py](influxdb_18_example.py) - How to connect to InfluxDB 1.8 diff --git a/examples/bucket_schemas.py b/examples/bucket_schemas.py new file mode 100644 index 00000000..c7cbc30e --- /dev/null +++ b/examples/bucket_schemas.py @@ -0,0 +1,95 @@ +""" +This example is related to `InfluxDB Cloud `_ and not available +on a local InfluxDB OSS instance. + +How to manage explicit bucket schemas to enforce column names, tags, fields, and data types for your data. +""" +import datetime + +from influxdb_client import InfluxDBClient, BucketSchemasService, PostBucketRequest, SchemaType, \ + MeasurementSchemaCreateRequest, MeasurementSchemaColumn, ColumnSemanticType, ColumnDataType, \ + MeasurementSchemaUpdateRequest + +""" +Define credentials +""" +influx_cloud_url = 'https://us-west-2-1.aws.cloud2.influxdata.com' +influx_cloud_token = '...' +org_name = '...' + +with InfluxDBClient(url=influx_cloud_url, token=influx_cloud_token, org=org_name, debug=False) as client: + uniqueId = str(datetime.datetime.now()) + org_id = client.organizations_api().find_organizations(org=org_name)[0].id + bucket_schemas_api = BucketSchemasService(api_client=client.api_client) + + """ + Create a bucket with the schema_type flag set to explicit + """ + print("------- Create Bucket -------\n") + created_bucket = client \ + .buckets_api() \ + .create_bucket(bucket=PostBucketRequest(name=f"my_schema_bucket_{uniqueId}", + org_id=org_id, + retention_rules=[], + schema_type=SchemaType.EXPLICIT)) + print(created_bucket) + + """ + Sets the schema for a measurement: Usage CPU + + [ + {"name": "time", "type": "timestamp"}, + {"name": "service", "type": "tag"}, + {"name": "host", "type": "tag"}, + {"name": "usage_user", "type": "field", "dataType": "float"}, + {"name": "usage_system", "type": "field", "dataType": "float"} + ] + """ + print("------- Create Schema -------\n") + columns = [ + MeasurementSchemaColumn(name="time", + type=ColumnSemanticType.TIMESTAMP), + MeasurementSchemaColumn(name="service", + type=ColumnSemanticType.TAG), + MeasurementSchemaColumn(name="host", + type=ColumnSemanticType.TAG), + MeasurementSchemaColumn(name="usage_user", + type=ColumnSemanticType.FIELD, + data_type=ColumnDataType.FLOAT), + MeasurementSchemaColumn(name="usage_system", + type=ColumnSemanticType.FIELD, + data_type=ColumnDataType.FLOAT) + ] + create_request = MeasurementSchemaCreateRequest(name="usage_cpu", columns=columns) + created_schema = bucket_schemas_api.create_measurement_schema(bucket_id=created_bucket.id, + org_id=org_id, + measurement_schema_create_request=create_request) + print(created_bucket) + + """ + Lists the Schemas + """ + print("\n------- Lists the Schemas -------\n") + measurement_schemas = bucket_schemas_api.get_measurement_schemas(bucket_id=created_bucket.id).measurement_schemas + print("\n".join([f"---\n ID: {ms.id}\n Name: {ms.name}\n Columns: {ms.columns}" for ms in measurement_schemas])) + print("---") + + """ + Update a bucket schema + """ + print("------- Update a bucket schema -------\n") + columns.append(MeasurementSchemaColumn(name="usage_total", + type=ColumnSemanticType.FIELD, + data_type=ColumnDataType.FLOAT)) + update_request = MeasurementSchemaUpdateRequest(columns=columns) + updated_schema = bucket_schemas_api.update_measurement_schema(bucket_id=created_bucket.id, + measurement_id=created_schema.id, + measurement_schema_update_request=update_request) + print(updated_schema) + + """ + Delete previously created bucket + """ + print("------- Delete Bucket -------\n") + client.buckets_api().delete_bucket(created_bucket) + print(f" successfully deleted bucket: {created_bucket.name}") diff --git a/influxdb_client/client/bucket_api.py b/influxdb_client/client/bucket_api.py index 4a3620cf..47763bee 100644 --- a/influxdb_client/client/bucket_api.py +++ b/influxdb_client/client/bucket_api.py @@ -22,7 +22,7 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru description=None, org=None) -> Bucket: """Create a bucket. - :param Bucket bucket: bucket to create + :param Bucket|PostBucketRequest bucket: bucket to create :param bucket_name: bucket name :param description: bucket description :param org_id: org_id From b102dc3ddc21b905c4e58a5bd6a6f3b113240989 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 13:42:27 +0100 Subject: [PATCH 08/15] docs: update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17bc64d5..6af6a98e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 1.35.0 [unreleased] +### Features +1. [#528](https://github.com/influxdata/influxdb-client-python/pull/528): Add `BucketSchemasService` to manage explicit bucket schemas to enforce column names, tags, fields, and data types for your data + ### Bug Fixes 1. [#526](https://github.com/influxdata/influxdb-client-python/pull/526): Creating client instance from static configuration From 193a4597405f4eec8f09759e04ff1111dd229d52 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 13:51:01 +0100 Subject: [PATCH 09/15] feat: add Explicit bucket schemas API --- .../service/bucket_schemas_service.py | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py index 83292f0e..805d9d50 100644 --- a/influxdb_client/service/bucket_schemas_service.py +++ b/influxdb_client/service/bucket_schemas_service.py @@ -35,51 +35,51 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 CloudOnlyWarning.print_warning('BucketSchemasService', 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 - def create_measurement_schema(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + def create_measurement_schema(self, bucket_id, measurement_schema_create_request, **kwargs): # noqa: E501,D401,D403 """Create a measurement schema for a bucket. Creates an _explict_ measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. Use this endpoint to create schemas that prevent non-conforming write requests. #### Limitations - Buckets must be created with the "explict" `schemaType` in order to use schemas. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Create a bucket with an explicit schema](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/create-bucket/#create-a-bucket-with-an-explicit-schema) This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True - >>> thread = api.create_measurement_schema(bucket_id, async_req=True) + >>> thread = api.create_measurement_schema(bucket_id, measurement_schema_create_request, async_req=True) >>> result = thread.get() :param async_req bool :param str bucket_id: A bucket ID. Adds a schema for the specified bucket. (required) + :param MeasurementSchemaCreateRequest measurement_schema_create_request: (required) :param str org: An organization name. Specifies the organization that owns the schema. :param str org_id: An organization ID. Specifies the organization that owns the schema. - :param MeasurementSchemaCreateRequest measurement_schema_create_request: :return: MeasurementSchema If the method is called asynchronously, returns the request thread. """ # noqa: E501 kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_measurement_schema_with_http_info(bucket_id, **kwargs) # noqa: E501 + return self.create_measurement_schema_with_http_info(bucket_id, measurement_schema_create_request, **kwargs) # noqa: E501 else: - (data) = self.create_measurement_schema_with_http_info(bucket_id, **kwargs) # noqa: E501 + (data) = self.create_measurement_schema_with_http_info(bucket_id, measurement_schema_create_request, **kwargs) # noqa: E501 return data - def create_measurement_schema_with_http_info(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + def create_measurement_schema_with_http_info(self, bucket_id, measurement_schema_create_request, **kwargs): # noqa: E501,D401,D403 """Create a measurement schema for a bucket. Creates an _explict_ measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. Use this endpoint to create schemas that prevent non-conforming write requests. #### Limitations - Buckets must be created with the "explict" `schemaType` in order to use schemas. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Create a bucket with an explicit schema](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/create-bucket/#create-a-bucket-with-an-explicit-schema) This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True - >>> thread = api.create_measurement_schema_with_http_info(bucket_id, async_req=True) + >>> thread = api.create_measurement_schema_with_http_info(bucket_id, measurement_schema_create_request, async_req=True) >>> result = thread.get() :param async_req bool :param str bucket_id: A bucket ID. Adds a schema for the specified bucket. (required) + :param MeasurementSchemaCreateRequest measurement_schema_create_request: (required) :param str org: An organization name. Specifies the organization that owns the schema. :param str org_id: An organization ID. Specifies the organization that owns the schema. - :param MeasurementSchemaCreateRequest measurement_schema_create_request: :return: MeasurementSchema If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._create_measurement_schema_prepare(bucket_id, **kwargs) + self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) return self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements', 'POST', @@ -98,7 +98,7 @@ def create_measurement_schema_with_http_info(self, bucket_id, **kwargs): # noqa collection_formats={}, urlopen_kw=kwargs.get('urlopen_kw', None)) - async def create_measurement_schema_async(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + async def create_measurement_schema_async(self, bucket_id, measurement_schema_create_request, **kwargs): # noqa: E501,D401,D403 """Create a measurement schema for a bucket. Creates an _explict_ measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema) for a bucket. _Explicit_ schemas are used to enforce column names, tags, fields, and data types for your data. By default, buckets have an _implicit_ schema-type (`"schemaType": "implicit"`) that conforms to your data. Use this endpoint to create schemas that prevent non-conforming write requests. #### Limitations - Buckets must be created with the "explict" `schemaType` in order to use schemas. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Create a bucket with an explicit schema](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/create-bucket/#create-a-bucket-with-an-explicit-schema) @@ -106,15 +106,15 @@ async def create_measurement_schema_async(self, bucket_id, **kwargs): # noqa: E :param async_req bool :param str bucket_id: A bucket ID. Adds a schema for the specified bucket. (required) + :param MeasurementSchemaCreateRequest measurement_schema_create_request: (required) :param str org: An organization name. Specifies the organization that owns the schema. :param str org_id: An organization ID. Specifies the organization that owns the schema. - :param MeasurementSchemaCreateRequest measurement_schema_create_request: :return: MeasurementSchema If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._create_measurement_schema_prepare(bucket_id, **kwargs) + self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) return await self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements', 'POST', @@ -133,15 +133,19 @@ async def create_measurement_schema_async(self, bucket_id, **kwargs): # noqa: E collection_formats={}, urlopen_kw=kwargs.get('urlopen_kw', None)) - def _create_measurement_schema_prepare(self, bucket_id, **kwargs): # noqa: E501,D401,D403 + def _create_measurement_schema_prepare(self, bucket_id, measurement_schema_create_request, **kwargs): # noqa: E501,D401,D403 local_var_params = locals() - all_params = ['bucket_id', 'org', 'org_id', 'measurement_schema_create_request'] # noqa: E501 + all_params = ['bucket_id', 'measurement_schema_create_request', 'org', 'org_id'] # noqa: E501 self._check_operation_params('create_measurement_schema', all_params, local_var_params) # verify the required parameter 'bucket_id' is set if ('bucket_id' not in local_var_params or local_var_params['bucket_id'] is None): raise ValueError("Missing the required parameter `bucket_id` when calling `create_measurement_schema`") # noqa: E501 + # verify the required parameter 'measurement_schema_create_request' is set + if ('measurement_schema_create_request' not in local_var_params or + local_var_params['measurement_schema_create_request'] is None): + raise ValueError("Missing the required parameter `measurement_schema_create_request` when calling `create_measurement_schema`") # noqa: E501 path_params = {} if 'bucket_id' in local_var_params: @@ -430,53 +434,53 @@ def _get_measurement_schemas_prepare(self, bucket_id, **kwargs): # noqa: E501,D return local_var_params, path_params, query_params, header_params, body_params - def update_measurement_schema(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + def update_measurement_schema(self, bucket_id, measurement_id, measurement_schema_update_request, **kwargs): # noqa: E501,D401,D403 """Update a measurement schema. Updates a measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). Use this endpoint to update the fields (`name`, `type`, and `dataType`) of a measurement schema. #### Limitations - You can't update the `name` of a measurement. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/). This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True - >>> thread = api.update_measurement_schema(bucket_id, measurement_id, async_req=True) + >>> thread = api.update_measurement_schema(bucket_id, measurement_id, measurement_schema_update_request, async_req=True) >>> result = thread.get() :param async_req bool :param str bucket_id: A bucket ID. Specifies the bucket to retrieve schemas for. (required) :param str measurement_id: A measurement schema ID. Retrieves the specified measurement schema. (required) + :param MeasurementSchemaUpdateRequest measurement_schema_update_request: (required) :param str org: An organization name. Specifies the organization that owns the schema. :param str org_id: An organization ID. Specifies the organization that owns the schema. - :param MeasurementSchemaUpdateRequest measurement_schema_update_request: :return: MeasurementSchema If the method is called asynchronously, returns the request thread. """ # noqa: E501 kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_measurement_schema_with_http_info(bucket_id, measurement_id, **kwargs) # noqa: E501 + return self.update_measurement_schema_with_http_info(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501 else: - (data) = self.update_measurement_schema_with_http_info(bucket_id, measurement_id, **kwargs) # noqa: E501 + (data) = self.update_measurement_schema_with_http_info(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501 return data - def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, measurement_schema_update_request, **kwargs): # noqa: E501,D401,D403 """Update a measurement schema. Updates a measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). Use this endpoint to update the fields (`name`, `type`, and `dataType`) of a measurement schema. #### Limitations - You can't update the `name` of a measurement. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/). This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True - >>> thread = api.update_measurement_schema_with_http_info(bucket_id, measurement_id, async_req=True) + >>> thread = api.update_measurement_schema_with_http_info(bucket_id, measurement_id, measurement_schema_update_request, async_req=True) >>> result = thread.get() :param async_req bool :param str bucket_id: A bucket ID. Specifies the bucket to retrieve schemas for. (required) :param str measurement_id: A measurement schema ID. Retrieves the specified measurement schema. (required) + :param MeasurementSchemaUpdateRequest measurement_schema_update_request: (required) :param str org: An organization name. Specifies the organization that owns the schema. :param str org_id: An organization ID. Specifies the organization that owns the schema. - :param MeasurementSchemaUpdateRequest measurement_schema_update_request: :return: MeasurementSchema If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._update_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) return self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'PATCH', @@ -495,7 +499,7 @@ def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, ** collection_formats={}, urlopen_kw=kwargs.get('urlopen_kw', None)) - async def update_measurement_schema_async(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + async def update_measurement_schema_async(self, bucket_id, measurement_id, measurement_schema_update_request, **kwargs): # noqa: E501,D401,D403 """Update a measurement schema. Updates a measurement [schema](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#schema). Use this endpoint to update the fields (`name`, `type`, and `dataType`) of a measurement schema. #### Limitations - You can't update the `name` of a measurement. #### Related guides - [Manage bucket schemas](https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/). - [Using bucket schemas](https://www.influxdata.com/blog/new-bucket-schema-option-protect-from-unwanted-schema-changes/). @@ -504,15 +508,15 @@ async def update_measurement_schema_async(self, bucket_id, measurement_id, **kwa :param async_req bool :param str bucket_id: A bucket ID. Specifies the bucket to retrieve schemas for. (required) :param str measurement_id: A measurement schema ID. Retrieves the specified measurement schema. (required) + :param MeasurementSchemaUpdateRequest measurement_schema_update_request: (required) :param str org: An organization name. Specifies the organization that owns the schema. :param str org_id: An organization ID. Specifies the organization that owns the schema. - :param MeasurementSchemaUpdateRequest measurement_schema_update_request: :return: MeasurementSchema If the method is called asynchronously, returns the request thread. """ # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._update_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) return await self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'PATCH', @@ -531,10 +535,10 @@ async def update_measurement_schema_async(self, bucket_id, measurement_id, **kwa collection_formats={}, urlopen_kw=kwargs.get('urlopen_kw', None)) - def _update_measurement_schema_prepare(self, bucket_id, measurement_id, **kwargs): # noqa: E501,D401,D403 + def _update_measurement_schema_prepare(self, bucket_id, measurement_id, measurement_schema_update_request, **kwargs): # noqa: E501,D401,D403 local_var_params = locals() - all_params = ['bucket_id', 'measurement_id', 'org', 'org_id', 'measurement_schema_update_request'] # noqa: E501 + all_params = ['bucket_id', 'measurement_id', 'measurement_schema_update_request', 'org', 'org_id'] # noqa: E501 self._check_operation_params('update_measurement_schema', all_params, local_var_params) # verify the required parameter 'bucket_id' is set if ('bucket_id' not in local_var_params or @@ -544,6 +548,10 @@ def _update_measurement_schema_prepare(self, bucket_id, measurement_id, **kwargs if ('measurement_id' not in local_var_params or local_var_params['measurement_id'] is None): raise ValueError("Missing the required parameter `measurement_id` when calling `update_measurement_schema`") # noqa: E501 + # verify the required parameter 'measurement_schema_update_request' is set + if ('measurement_schema_update_request' not in local_var_params or + local_var_params['measurement_schema_update_request'] is None): + raise ValueError("Missing the required parameter `measurement_schema_update_request` when calling `update_measurement_schema`") # noqa: E501 path_params = {} if 'bucket_id' in local_var_params: From d2ab4d7121ceabaaaf3016a49f3f6232617cbfe4 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Fri, 4 Nov 2022 17:27:19 +0100 Subject: [PATCH 10/15] fix: code style --- influxdb_client/service/bucket_schemas_service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py index 805d9d50..fe1b859e 100644 --- a/influxdb_client/service/bucket_schemas_service.py +++ b/influxdb_client/service/bucket_schemas_service.py @@ -480,7 +480,7 @@ def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, me returns the request thread. """ # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) + self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501 return self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'PATCH', @@ -516,7 +516,7 @@ async def update_measurement_schema_async(self, bucket_id, measurement_id, measu returns the request thread. """ # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) + self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501 return await self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'PATCH', From 38fc35c12d852b95c380faa2aa0942f8233f9ab6 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Mon, 7 Nov 2022 09:20:40 +0100 Subject: [PATCH 11/15] feat: add API to check build type of InfluxDB instance --- influxdb_client/client/_base.py | 6 +++--- influxdb_client/client/influxdb_client.py | 14 +++++++++++++- influxdb_client/client/influxdb_client_async.py | 13 ++++++++++++- tests/test_InfluxDBClient.py | 4 ++++ tests/test_InfluxDBClientAsync.py | 5 +++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/influxdb_client/client/_base.py b/influxdb_client/client/_base.py index de2910da..31396178 100644 --- a/influxdb_client/client/_base.py +++ b/influxdb_client/client/_base.py @@ -98,10 +98,10 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or self.profilers = kwargs.get('profilers', None) pass - def _version(self, response) -> str: + def _response_header(self, response, header_name='X-Influxdb-Version') -> str: if response is not None and len(response) >= 3: - if 'X-Influxdb-Version' in response[2]: - return response[2]['X-Influxdb-Version'] + if header_name in response[2]: + return response[2][header_name] return "unknown" diff --git a/influxdb_client/client/influxdb_client.py b/influxdb_client/client/influxdb_client.py index 8b164f67..b180fd25 100644 --- a/influxdb_client/client/influxdb_client.py +++ b/influxdb_client/client/influxdb_client.py @@ -407,7 +407,19 @@ def version(self) -> str: response = ping_service.get_ping_with_http_info(_return_http_data_only=False) - return self._version(response) + return self._response_header(response) + + def build(self) -> str: + """ + Return the build type of the connected InfluxDB Server. + + :return: The type of InfluxDB build. + """ + ping_service = PingService(self.api_client) + + response = ping_service.get_ping_with_http_info(_return_http_data_only=False) + + return self._response_header(response, header_name='X-Influxdb-Build') def ready(self) -> Ready: """ diff --git a/influxdb_client/client/influxdb_client_async.py b/influxdb_client/client/influxdb_client_async.py index 411fad62..eccd1200 100644 --- a/influxdb_client/client/influxdb_client_async.py +++ b/influxdb_client/client/influxdb_client_async.py @@ -251,7 +251,18 @@ async def version(self) -> str: ping_service = PingService(self.api_client) response = await ping_service.get_ping_async(_return_http_data_only=False) - return self._version(response) + return self._response_header(response) + + async def build(self) -> str: + """ + Return the build type of the connected InfluxDB Server. + + :return: The type of InfluxDB build. + """ + ping_service = PingService(self.api_client) + + response = await ping_service.get_ping_async(_return_http_data_only=False) + return self._response_header(response, header_name='X-Influxdb-Build') def query_api(self, query_options: QueryOptions = QueryOptions()) -> QueryApiAsync: """ diff --git a/tests/test_InfluxDBClient.py b/tests/test_InfluxDBClient.py index 741457b4..fdd76390 100644 --- a/tests/test_InfluxDBClient.py +++ b/tests/test_InfluxDBClient.py @@ -316,6 +316,10 @@ def test_version(self): version = self.client.version() self.assertTrue(len(version) > 0) + def test_build(self): + build = self.client.build() + self.assertEqual('oss', build.lower()) + def test_version_not_running_instance(self): client_not_running = InfluxDBClient("http://localhost:8099", token="my-token", debug=True) with self.assertRaises(NewConnectionError): diff --git a/tests/test_InfluxDBClientAsync.py b/tests/test_InfluxDBClientAsync.py index 3283da40..4de8c3fe 100644 --- a/tests/test_InfluxDBClientAsync.py +++ b/tests/test_InfluxDBClientAsync.py @@ -49,6 +49,11 @@ async def test_version(self): version = await self.client.version() self.assertTrue(len(version) > 0) + @async_test + async def test_build(self): + build = await self.client.build() + self.assertEqual('oss', build.lower()) + def test_create_query_api(self): query_api = self.client.query_api() self.assertIsNotNone(query_api) From 62ba5f7d4b95bee034e79a88ab58756f70f84b01 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 8 Nov 2022 10:24:02 +0100 Subject: [PATCH 12/15] feat: prepare to add warning into API call --- influxdb_client/client/_base.py | 7 --- influxdb_client/client/influxdb_client.py | 6 +-- .../client/influxdb_client_async.py | 5 +-- influxdb_client/service/_base_service.py | 44 +++++++++++++++++++ .../service/bucket_schemas_service.py | 8 +--- .../service/invokable_scripts_service.py | 3 +- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/influxdb_client/client/_base.py b/influxdb_client/client/_base.py index 31396178..a3bc05d4 100644 --- a/influxdb_client/client/_base.py +++ b/influxdb_client/client/_base.py @@ -98,13 +98,6 @@ def __init__(self, url, token, debug=None, timeout=10_000, enable_gzip=False, or self.profilers = kwargs.get('profilers', None) pass - def _response_header(self, response, header_name='X-Influxdb-Version') -> str: - if response is not None and len(response) >= 3: - if header_name in response[2]: - return response[2][header_name] - - return "unknown" - @classmethod def _from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gzip=False, **kwargs): config = configparser.ConfigParser() diff --git a/influxdb_client/client/influxdb_client.py b/influxdb_client/client/influxdb_client.py index b180fd25..ca8dcb36 100644 --- a/influxdb_client/client/influxdb_client.py +++ b/influxdb_client/client/influxdb_client.py @@ -407,7 +407,7 @@ def version(self) -> str: response = ping_service.get_ping_with_http_info(_return_http_data_only=False) - return self._response_header(response) + return ping_service.response_header(response) def build(self) -> str: """ @@ -417,9 +417,7 @@ def build(self) -> str: """ ping_service = PingService(self.api_client) - response = ping_service.get_ping_with_http_info(_return_http_data_only=False) - - return self._response_header(response, header_name='X-Influxdb-Build') + return ping_service.build_type() def ready(self) -> Ready: """ diff --git a/influxdb_client/client/influxdb_client_async.py b/influxdb_client/client/influxdb_client_async.py index eccd1200..76f014f3 100644 --- a/influxdb_client/client/influxdb_client_async.py +++ b/influxdb_client/client/influxdb_client_async.py @@ -251,7 +251,7 @@ async def version(self) -> str: ping_service = PingService(self.api_client) response = await ping_service.get_ping_async(_return_http_data_only=False) - return self._response_header(response) + return ping_service.response_header(response) async def build(self) -> str: """ @@ -261,8 +261,7 @@ async def build(self) -> str: """ ping_service = PingService(self.api_client) - response = await ping_service.get_ping_async(_return_http_data_only=False) - return self._response_header(response, header_name='X-Influxdb-Build') + return await ping_service.build_type_async() def query_api(self, query_options: QueryOptions = QueryOptions()) -> QueryApiAsync: """ diff --git a/influxdb_client/service/_base_service.py b/influxdb_client/service/_base_service.py index 0addd6eb..bcc9da32 100644 --- a/influxdb_client/service/_base_service.py +++ b/influxdb_client/service/_base_service.py @@ -2,6 +2,13 @@ # noinspection PyMethodMayBeStatic class _BaseService(object): + + def __init__(self, api_client=None): + """Init common services operation.""" + if api_client is None: + raise ValueError("Invalid value for `api_client`, must be defined.") + self.api_client = api_client + def _check_operation_params(self, operation_id, supported_params, local_params): supported_params.append('async_req') supported_params.append('_return_http_data_only') @@ -16,3 +23,40 @@ def _check_operation_params(self, operation_id, supported_params, local_params): ) local_params[key] = val del local_params['kwargs'] + + def _is_cloud_instance(self) -> bool: + return False + + async def _is_cloud_instance_async(self) -> bool: + return False + + def build_type(self) -> str: + """ + Return the build type of the connected InfluxDB Server. + + :return: The type of InfluxDB build. + """ + from influxdb_client import PingService + ping_service = PingService(self.api_client) + + response = ping_service.get_ping_with_http_info(_return_http_data_only=False) + return self.response_header(response, header_name='X-Influxdb-Build') + + async def build_type_async(self) -> str: + """ + Return the build type of the connected InfluxDB Server. + + :return: The type of InfluxDB build. + """ + from influxdb_client import PingService + ping_service = PingService(self.api_client) + + response = await ping_service.get_ping_async(_return_http_data_only=False) + return self.response_header(response, header_name='X-Influxdb-Build') + + def response_header(self, response, header_name='X-Influxdb-Version') -> str: + if response is not None and len(response) >= 3: + if header_name in response[2]: + return response[2][header_name] + + return "unknown" diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py index fe1b859e..45a5582f 100644 --- a/influxdb_client/service/bucket_schemas_service.py +++ b/influxdb_client/service/bucket_schemas_service.py @@ -27,13 +27,7 @@ class BucketSchemasService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """BucketSchemasService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client - - from influxdb_client.client.warnings import CloudOnlyWarning - CloudOnlyWarning.print_warning('BucketSchemasService', - 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 + super().__init__(api_client) def create_measurement_schema(self, bucket_id, measurement_schema_create_request, **kwargs): # noqa: E501,D401,D403 """Create a measurement schema for a bucket. diff --git a/influxdb_client/service/invokable_scripts_service.py b/influxdb_client/service/invokable_scripts_service.py index e04e7745..6d963445 100644 --- a/influxdb_client/service/invokable_scripts_service.py +++ b/influxdb_client/service/invokable_scripts_service.py @@ -33,7 +33,8 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 from influxdb_client.client.warnings import CloudOnlyWarning CloudOnlyWarning.print_warning('InvokableScriptsService', - 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/', + api_client) # noqa: E501 def delete_scripts_id(self, script_id, **kwargs): # noqa: E501,D401,D403 """Delete a script. From bab51a4e4ab2f3386781cb7f4d27b093a1352f80 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 8 Nov 2022 10:33:48 +0100 Subject: [PATCH 13/15] feat: add init for _BaseServices --- influxdb_client/service/authorizations_service.py | 4 +--- influxdb_client/service/backup_service.py | 4 +--- influxdb_client/service/buckets_service.py | 4 +--- influxdb_client/service/cells_service.py | 4 +--- influxdb_client/service/checks_service.py | 4 +--- influxdb_client/service/config_service.py | 4 +--- influxdb_client/service/dashboards_service.py | 4 +--- influxdb_client/service/dbr_ps_service.py | 4 +--- influxdb_client/service/delete_service.py | 4 +--- influxdb_client/service/health_service.py | 4 +--- influxdb_client/service/invokable_scripts_service.py | 4 +--- influxdb_client/service/labels_service.py | 4 +--- influxdb_client/service/legacy_authorizations_service.py | 4 +--- influxdb_client/service/metrics_service.py | 4 +--- influxdb_client/service/notification_endpoints_service.py | 4 +--- influxdb_client/service/notification_rules_service.py | 4 +--- influxdb_client/service/organizations_service.py | 4 +--- influxdb_client/service/ping_service.py | 4 +--- influxdb_client/service/query_service.py | 4 +--- influxdb_client/service/ready_service.py | 4 +--- influxdb_client/service/remote_connections_service.py | 4 +--- influxdb_client/service/replications_service.py | 4 +--- influxdb_client/service/resources_service.py | 4 +--- influxdb_client/service/restore_service.py | 4 +--- influxdb_client/service/routes_service.py | 4 +--- influxdb_client/service/rules_service.py | 4 +--- influxdb_client/service/scraper_targets_service.py | 4 +--- influxdb_client/service/secrets_service.py | 4 +--- influxdb_client/service/setup_service.py | 4 +--- influxdb_client/service/signin_service.py | 4 +--- influxdb_client/service/signout_service.py | 4 +--- influxdb_client/service/sources_service.py | 4 +--- influxdb_client/service/tasks_service.py | 4 +--- influxdb_client/service/telegraf_plugins_service.py | 4 +--- influxdb_client/service/telegrafs_service.py | 4 +--- influxdb_client/service/templates_service.py | 4 +--- influxdb_client/service/users_service.py | 4 +--- influxdb_client/service/variables_service.py | 4 +--- influxdb_client/service/views_service.py | 4 +--- influxdb_client/service/write_service.py | 4 +--- 40 files changed, 40 insertions(+), 120 deletions(-) diff --git a/influxdb_client/service/authorizations_service.py b/influxdb_client/service/authorizations_service.py index 2bf5b9dc..ed2311a1 100644 --- a/influxdb_client/service/authorizations_service.py +++ b/influxdb_client/service/authorizations_service.py @@ -27,9 +27,7 @@ class AuthorizationsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """AuthorizationsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_authorizations_id(self, auth_id, **kwargs): # noqa: E501,D401,D403 """Delete an authorization. diff --git a/influxdb_client/service/backup_service.py b/influxdb_client/service/backup_service.py index 22ee36d0..324dbca3 100644 --- a/influxdb_client/service/backup_service.py +++ b/influxdb_client/service/backup_service.py @@ -27,9 +27,7 @@ class BackupService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """BackupService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_backup_kv(self, **kwargs): # noqa: E501,D401,D403 """Download snapshot of metadata stored in the server's embedded KV store. Should not be used in versions greater than 2.1.x, as it doesn't include metadata stored in embedded SQL.. diff --git a/influxdb_client/service/buckets_service.py b/influxdb_client/service/buckets_service.py index 1831bbfd..1232f0c1 100644 --- a/influxdb_client/service/buckets_service.py +++ b/influxdb_client/service/buckets_service.py @@ -27,9 +27,7 @@ class BucketsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """BucketsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_buckets_id(self, bucket_id, **kwargs): # noqa: E501,D401,D403 """Delete a bucket. diff --git a/influxdb_client/service/cells_service.py b/influxdb_client/service/cells_service.py index b65ecd69..6a1ae8ce 100644 --- a/influxdb_client/service/cells_service.py +++ b/influxdb_client/service/cells_service.py @@ -27,9 +27,7 @@ class CellsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """CellsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_dashboards_id_cells_id(self, dashboard_id, cell_id, **kwargs): # noqa: E501,D401,D403 """Delete a dashboard cell. diff --git a/influxdb_client/service/checks_service.py b/influxdb_client/service/checks_service.py index 0f20dee6..9af0c361 100644 --- a/influxdb_client/service/checks_service.py +++ b/influxdb_client/service/checks_service.py @@ -27,9 +27,7 @@ class ChecksService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ChecksService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def create_check(self, post_check, **kwargs): # noqa: E501,D401,D403 """Add new check. diff --git a/influxdb_client/service/config_service.py b/influxdb_client/service/config_service.py index 8444f9c3..17c5e6cf 100644 --- a/influxdb_client/service/config_service.py +++ b/influxdb_client/service/config_service.py @@ -27,9 +27,7 @@ class ConfigService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ConfigService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_config(self, **kwargs): # noqa: E501,D401,D403 """Retrieve runtime configuration. diff --git a/influxdb_client/service/dashboards_service.py b/influxdb_client/service/dashboards_service.py index 711c9b5a..4b413de9 100644 --- a/influxdb_client/service/dashboards_service.py +++ b/influxdb_client/service/dashboards_service.py @@ -27,9 +27,7 @@ class DashboardsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """DashboardsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_dashboards_id(self, dashboard_id, **kwargs): # noqa: E501,D401,D403 """Delete a dashboard. diff --git a/influxdb_client/service/dbr_ps_service.py b/influxdb_client/service/dbr_ps_service.py index f87e3315..bc2bb50f 100644 --- a/influxdb_client/service/dbr_ps_service.py +++ b/influxdb_client/service/dbr_ps_service.py @@ -27,9 +27,7 @@ class DBRPsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """DBRPsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_dbrpid(self, dbrp_id, **kwargs): # noqa: E501,D401,D403 """Delete a database retention policy. diff --git a/influxdb_client/service/delete_service.py b/influxdb_client/service/delete_service.py index 3a4c1b81..4ad40dd8 100644 --- a/influxdb_client/service/delete_service.py +++ b/influxdb_client/service/delete_service.py @@ -27,9 +27,7 @@ class DeleteService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """DeleteService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def post_delete(self, delete_predicate_request, **kwargs): # noqa: E501,D401,D403 """Delete data. diff --git a/influxdb_client/service/health_service.py b/influxdb_client/service/health_service.py index f0ac7fc5..b5ff4263 100644 --- a/influxdb_client/service/health_service.py +++ b/influxdb_client/service/health_service.py @@ -27,9 +27,7 @@ class HealthService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """HealthService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_health(self, **kwargs): # noqa: E501,D401,D403 """Retrieve the health of the instance. diff --git a/influxdb_client/service/invokable_scripts_service.py b/influxdb_client/service/invokable_scripts_service.py index 6d963445..75f387a8 100644 --- a/influxdb_client/service/invokable_scripts_service.py +++ b/influxdb_client/service/invokable_scripts_service.py @@ -27,9 +27,7 @@ class InvokableScriptsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """InvokableScriptsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) from influxdb_client.client.warnings import CloudOnlyWarning CloudOnlyWarning.print_warning('InvokableScriptsService', diff --git a/influxdb_client/service/labels_service.py b/influxdb_client/service/labels_service.py index 8b0b29ea..d33a4dbe 100644 --- a/influxdb_client/service/labels_service.py +++ b/influxdb_client/service/labels_service.py @@ -27,9 +27,7 @@ class LabelsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """LabelsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_labels_id(self, label_id, **kwargs): # noqa: E501,D401,D403 """Delete a label. diff --git a/influxdb_client/service/legacy_authorizations_service.py b/influxdb_client/service/legacy_authorizations_service.py index d7436ef9..622ef49c 100644 --- a/influxdb_client/service/legacy_authorizations_service.py +++ b/influxdb_client/service/legacy_authorizations_service.py @@ -27,9 +27,7 @@ class LegacyAuthorizationsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """LegacyAuthorizationsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_legacy_authorizations_id(self, auth_id, **kwargs): # noqa: E501,D401,D403 """Delete a legacy authorization. diff --git a/influxdb_client/service/metrics_service.py b/influxdb_client/service/metrics_service.py index 8dc055e7..fc790d73 100644 --- a/influxdb_client/service/metrics_service.py +++ b/influxdb_client/service/metrics_service.py @@ -27,9 +27,7 @@ class MetricsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """MetricsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_metrics(self, **kwargs): # noqa: E501,D401,D403 """Retrieve workload performance metrics. diff --git a/influxdb_client/service/notification_endpoints_service.py b/influxdb_client/service/notification_endpoints_service.py index 1b13157f..8b9bb174 100644 --- a/influxdb_client/service/notification_endpoints_service.py +++ b/influxdb_client/service/notification_endpoints_service.py @@ -27,9 +27,7 @@ class NotificationEndpointsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """NotificationEndpointsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def create_notification_endpoint(self, post_notification_endpoint, **kwargs): # noqa: E501,D401,D403 """Add a notification endpoint. diff --git a/influxdb_client/service/notification_rules_service.py b/influxdb_client/service/notification_rules_service.py index e92352c0..7af5dd38 100644 --- a/influxdb_client/service/notification_rules_service.py +++ b/influxdb_client/service/notification_rules_service.py @@ -27,9 +27,7 @@ class NotificationRulesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """NotificationRulesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def create_notification_rule(self, post_notification_rule, **kwargs): # noqa: E501,D401,D403 """Add a notification rule. diff --git a/influxdb_client/service/organizations_service.py b/influxdb_client/service/organizations_service.py index 9be1693f..d8bddadb 100644 --- a/influxdb_client/service/organizations_service.py +++ b/influxdb_client/service/organizations_service.py @@ -27,9 +27,7 @@ class OrganizationsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """OrganizationsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_orgs_id(self, org_id, **kwargs): # noqa: E501,D401,D403 """Delete an organization. diff --git a/influxdb_client/service/ping_service.py b/influxdb_client/service/ping_service.py index 7ba06f99..a75854b0 100644 --- a/influxdb_client/service/ping_service.py +++ b/influxdb_client/service/ping_service.py @@ -27,9 +27,7 @@ class PingService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """PingService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_ping(self, **kwargs): # noqa: E501,D401,D403 """Get the status and version of the instance. diff --git a/influxdb_client/service/query_service.py b/influxdb_client/service/query_service.py index 7155a3c8..c0e7351a 100644 --- a/influxdb_client/service/query_service.py +++ b/influxdb_client/service/query_service.py @@ -27,9 +27,7 @@ class QueryService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """QueryService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_query_suggestions(self, **kwargs): # noqa: E501,D401,D403 """Retrieve query suggestions. diff --git a/influxdb_client/service/ready_service.py b/influxdb_client/service/ready_service.py index 4d2a778e..864ebe73 100644 --- a/influxdb_client/service/ready_service.py +++ b/influxdb_client/service/ready_service.py @@ -27,9 +27,7 @@ class ReadyService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ReadyService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_ready(self, **kwargs): # noqa: E501,D401,D403 """Get the readiness of an instance at startup. diff --git a/influxdb_client/service/remote_connections_service.py b/influxdb_client/service/remote_connections_service.py index 912b5b81..9f50bd3c 100644 --- a/influxdb_client/service/remote_connections_service.py +++ b/influxdb_client/service/remote_connections_service.py @@ -27,9 +27,7 @@ class RemoteConnectionsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """RemoteConnectionsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_remote_connection_by_id(self, remote_id, **kwargs): # noqa: E501,D401,D403 """Delete a remote connection. diff --git a/influxdb_client/service/replications_service.py b/influxdb_client/service/replications_service.py index 58bd13f5..de76f24b 100644 --- a/influxdb_client/service/replications_service.py +++ b/influxdb_client/service/replications_service.py @@ -27,9 +27,7 @@ class ReplicationsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ReplicationsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_replication_by_id(self, replication_id, **kwargs): # noqa: E501,D401,D403 """Delete a replication. diff --git a/influxdb_client/service/resources_service.py b/influxdb_client/service/resources_service.py index 496976cb..ac1af1bd 100644 --- a/influxdb_client/service/resources_service.py +++ b/influxdb_client/service/resources_service.py @@ -27,9 +27,7 @@ class ResourcesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ResourcesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_resources(self, **kwargs): # noqa: E501,D401,D403 """List all known resources. diff --git a/influxdb_client/service/restore_service.py b/influxdb_client/service/restore_service.py index ff8ed65f..9c6e5681 100644 --- a/influxdb_client/service/restore_service.py +++ b/influxdb_client/service/restore_service.py @@ -27,9 +27,7 @@ class RestoreService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """RestoreService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def post_restore_bucket_id(self, bucket_id, body, **kwargs): # noqa: E501,D401,D403 """Overwrite storage metadata for a bucket with shard info from a backup.. diff --git a/influxdb_client/service/routes_service.py b/influxdb_client/service/routes_service.py index 6ca7ac39..d29acd85 100644 --- a/influxdb_client/service/routes_service.py +++ b/influxdb_client/service/routes_service.py @@ -27,9 +27,7 @@ class RoutesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """RoutesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_routes(self, **kwargs): # noqa: E501,D401,D403 """List all top level routes. diff --git a/influxdb_client/service/rules_service.py b/influxdb_client/service/rules_service.py index 4678d8f9..884553af 100644 --- a/influxdb_client/service/rules_service.py +++ b/influxdb_client/service/rules_service.py @@ -27,9 +27,7 @@ class RulesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """RulesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_notification_rules_id_query(self, rule_id, **kwargs): # noqa: E501,D401,D403 """Retrieve a notification rule query. diff --git a/influxdb_client/service/scraper_targets_service.py b/influxdb_client/service/scraper_targets_service.py index 1dd2add5..6d6e97c8 100644 --- a/influxdb_client/service/scraper_targets_service.py +++ b/influxdb_client/service/scraper_targets_service.py @@ -27,9 +27,7 @@ class ScraperTargetsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ScraperTargetsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_scrapers_id(self, scraper_target_id, **kwargs): # noqa: E501,D401,D403 """Delete a scraper target. diff --git a/influxdb_client/service/secrets_service.py b/influxdb_client/service/secrets_service.py index 9baf888c..8a7db884 100644 --- a/influxdb_client/service/secrets_service.py +++ b/influxdb_client/service/secrets_service.py @@ -27,9 +27,7 @@ class SecretsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """SecretsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_orgs_id_secrets_id(self, org_id, secret_id, **kwargs): # noqa: E501,D401,D403 """Delete a secret from an organization. diff --git a/influxdb_client/service/setup_service.py b/influxdb_client/service/setup_service.py index 97d7ca2b..8c28a412 100644 --- a/influxdb_client/service/setup_service.py +++ b/influxdb_client/service/setup_service.py @@ -27,9 +27,7 @@ class SetupService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """SetupService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_setup(self, **kwargs): # noqa: E501,D401,D403 """Check if database has default user, org, bucket. diff --git a/influxdb_client/service/signin_service.py b/influxdb_client/service/signin_service.py index b9686d37..91d84c0a 100644 --- a/influxdb_client/service/signin_service.py +++ b/influxdb_client/service/signin_service.py @@ -27,9 +27,7 @@ class SigninService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """SigninService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def post_signin(self, **kwargs): # noqa: E501,D401,D403 """Create a user session.. diff --git a/influxdb_client/service/signout_service.py b/influxdb_client/service/signout_service.py index fefb4094..9c5949ad 100644 --- a/influxdb_client/service/signout_service.py +++ b/influxdb_client/service/signout_service.py @@ -27,9 +27,7 @@ class SignoutService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """SignoutService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def post_signout(self, **kwargs): # noqa: E501,D401,D403 """Expire the current UI session. diff --git a/influxdb_client/service/sources_service.py b/influxdb_client/service/sources_service.py index 6ed6b035..48580ead 100644 --- a/influxdb_client/service/sources_service.py +++ b/influxdb_client/service/sources_service.py @@ -27,9 +27,7 @@ class SourcesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """SourcesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_sources_id(self, source_id, **kwargs): # noqa: E501,D401,D403 """Delete a source. diff --git a/influxdb_client/service/tasks_service.py b/influxdb_client/service/tasks_service.py index b1772bfd..0bc85d42 100644 --- a/influxdb_client/service/tasks_service.py +++ b/influxdb_client/service/tasks_service.py @@ -27,9 +27,7 @@ class TasksService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """TasksService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_tasks_id(self, task_id, **kwargs): # noqa: E501,D401,D403 """Delete a task. diff --git a/influxdb_client/service/telegraf_plugins_service.py b/influxdb_client/service/telegraf_plugins_service.py index b70b1284..4ac4964e 100644 --- a/influxdb_client/service/telegraf_plugins_service.py +++ b/influxdb_client/service/telegraf_plugins_service.py @@ -27,9 +27,7 @@ class TelegrafPluginsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """TelegrafPluginsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_telegraf_plugins(self, **kwargs): # noqa: E501,D401,D403 """List all Telegraf plugins. diff --git a/influxdb_client/service/telegrafs_service.py b/influxdb_client/service/telegrafs_service.py index 2c7ac4a3..113495c8 100644 --- a/influxdb_client/service/telegrafs_service.py +++ b/influxdb_client/service/telegrafs_service.py @@ -27,9 +27,7 @@ class TelegrafsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """TelegrafsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_telegrafs_id(self, telegraf_id, **kwargs): # noqa: E501,D401,D403 """Delete a Telegraf configuration. diff --git a/influxdb_client/service/templates_service.py b/influxdb_client/service/templates_service.py index c2fd6766..11110c43 100644 --- a/influxdb_client/service/templates_service.py +++ b/influxdb_client/service/templates_service.py @@ -27,9 +27,7 @@ class TemplatesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """TemplatesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def apply_template(self, template_apply, **kwargs): # noqa: E501,D401,D403 """Apply or dry-run a template. diff --git a/influxdb_client/service/users_service.py b/influxdb_client/service/users_service.py index 3920dd32..eae1ffe1 100644 --- a/influxdb_client/service/users_service.py +++ b/influxdb_client/service/users_service.py @@ -27,9 +27,7 @@ class UsersService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """UsersService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_users_id(self, user_id, **kwargs): # noqa: E501,D401,D403 """Delete a user. diff --git a/influxdb_client/service/variables_service.py b/influxdb_client/service/variables_service.py index 8bd9c47a..9e7778b1 100644 --- a/influxdb_client/service/variables_service.py +++ b/influxdb_client/service/variables_service.py @@ -27,9 +27,7 @@ class VariablesService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """VariablesService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def delete_variables_id(self, variable_id, **kwargs): # noqa: E501,D401,D403 """Delete a variable. diff --git a/influxdb_client/service/views_service.py b/influxdb_client/service/views_service.py index 4431db11..db17788c 100644 --- a/influxdb_client/service/views_service.py +++ b/influxdb_client/service/views_service.py @@ -27,9 +27,7 @@ class ViewsService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """ViewsService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def get_dashboards_id_cells_id_view(self, dashboard_id, cell_id, **kwargs): # noqa: E501,D401,D403 """Retrieve the view for a cell. diff --git a/influxdb_client/service/write_service.py b/influxdb_client/service/write_service.py index d55dda4e..8c7103bb 100644 --- a/influxdb_client/service/write_service.py +++ b/influxdb_client/service/write_service.py @@ -27,9 +27,7 @@ class WriteService(_BaseService): def __init__(self, api_client=None): # noqa: E501,D401,D403 """WriteService - a operation defined in OpenAPI.""" - if api_client is None: - raise ValueError("Invalid value for `api_client`, must be defined.") - self.api_client = api_client + super().__init__(api_client) def post_write(self, org, bucket, body, **kwargs): # noqa: E501,D401,D403 """Write data. From 9767ef02def0cbbb9be122797791dbb5ee4375e4 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 8 Nov 2022 12:40:23 +0100 Subject: [PATCH 14/15] feat: preparing for not cloud warning --- influxdb_client/service/_base_service.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/influxdb_client/service/_base_service.py b/influxdb_client/service/_base_service.py index bcc9da32..d3e8f995 100644 --- a/influxdb_client/service/_base_service.py +++ b/influxdb_client/service/_base_service.py @@ -8,6 +8,7 @@ def __init__(self, api_client=None): if api_client is None: raise ValueError("Invalid value for `api_client`, must be defined.") self.api_client = api_client + self._build_type = None def _check_operation_params(self, operation_id, supported_params, local_params): supported_params.append('async_req') @@ -25,10 +26,14 @@ def _check_operation_params(self, operation_id, supported_params, local_params): del local_params['kwargs'] def _is_cloud_instance(self) -> bool: - return False + if not self._build_type: + self._build_type = self.build_type() + return 'cloud' in self._build_type.lower() async def _is_cloud_instance_async(self) -> bool: - return False + if not self._build_type: + self._build_type = await self.build_type_async() + return 'cloud' in self._build_type.lower() def build_type(self) -> str: """ From e705ee9cad48651433e7a031d121583bebea02e9 Mon Sep 17 00:00:00 2001 From: Jakub Bednar Date: Tue, 8 Nov 2022 13:43:05 +0100 Subject: [PATCH 15/15] feat: add warning for not Cloud instance --- .../service/bucket_schemas_service.py | 44 ++++++++++++++--- .../service/invokable_scripts_service.py | 49 +++++++++++++++++-- tests/test_Warnings.py | 21 ++++++-- 3 files changed, 100 insertions(+), 14 deletions(-) diff --git a/influxdb_client/service/bucket_schemas_service.py b/influxdb_client/service/bucket_schemas_service.py index 45a5582f..7a25338c 100644 --- a/influxdb_client/service/bucket_schemas_service.py +++ b/influxdb_client/service/bucket_schemas_service.py @@ -72,8 +72,12 @@ def create_measurement_schema_with_http_info(self, bucket_id, measurement_schema If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) + self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) # noqa: E501 return self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements', 'POST', @@ -107,8 +111,12 @@ async def create_measurement_schema_async(self, bucket_id, measurement_schema_cr If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) + self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) # noqa: E501 return await self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements', 'POST', @@ -209,8 +217,12 @@ def get_measurement_schema_with_http_info(self, bucket_id, measurement_id, **kwa If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) # noqa: E501 return self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'GET', @@ -244,8 +256,12 @@ async def get_measurement_schema_async(self, bucket_id, measurement_id, **kwargs If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) + self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) # noqa: E501 return await self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'GET', @@ -342,8 +358,12 @@ def get_measurement_schemas_with_http_info(self, bucket_id, **kwargs): # noqa: If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._get_measurement_schemas_prepare(bucket_id, **kwargs) + self._get_measurement_schemas_prepare(bucket_id, **kwargs) # noqa: E501 return self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements', 'GET', @@ -377,8 +397,12 @@ async def get_measurement_schemas_async(self, bucket_id, **kwargs): # noqa: E50 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ - self._get_measurement_schemas_prepare(bucket_id, **kwargs) + self._get_measurement_schemas_prepare(bucket_id, **kwargs) # noqa: E501 return await self.api_client.call_api( '/api/v2/buckets/{bucketID}/schema/measurements', 'GET', @@ -473,6 +497,10 @@ def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, me If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501 @@ -509,6 +537,10 @@ async def update_measurement_schema_async(self, bucket_id, measurement_id, measu If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('BucketSchemasService', + 'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501 diff --git a/influxdb_client/service/invokable_scripts_service.py b/influxdb_client/service/invokable_scripts_service.py index 75f387a8..7dbfa7ad 100644 --- a/influxdb_client/service/invokable_scripts_service.py +++ b/influxdb_client/service/invokable_scripts_service.py @@ -29,11 +29,6 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403 """InvokableScriptsService - a operation defined in OpenAPI.""" super().__init__(api_client) - from influxdb_client.client.warnings import CloudOnlyWarning - CloudOnlyWarning.print_warning('InvokableScriptsService', - 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/', - api_client) # noqa: E501 - def delete_scripts_id(self, script_id, **kwargs): # noqa: E501,D401,D403 """Delete a script. @@ -103,6 +98,10 @@ async def delete_scripts_id_async(self, script_id, **kwargs): # noqa: E501,D401 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._delete_scripts_id_prepare(script_id, **kwargs) @@ -181,6 +180,10 @@ def get_scripts_with_http_info(self, **kwargs): # noqa: E501,D401,D403 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._get_scripts_prepare(**kwargs) @@ -213,6 +216,10 @@ async def get_scripts_async(self, **kwargs): # noqa: E501,D401,D403 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._get_scripts_prepare(**kwargs) @@ -293,6 +300,10 @@ def get_scripts_id_with_http_info(self, script_id, **kwargs): # noqa: E501,D401 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._get_scripts_id_prepare(script_id, **kwargs) @@ -325,6 +336,10 @@ async def get_scripts_id_async(self, script_id, **kwargs): # noqa: E501,D401,D4 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._get_scripts_id_prepare(script_id, **kwargs) @@ -409,6 +424,10 @@ def patch_scripts_id_with_http_info(self, script_id, script_update_request, **kw If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._patch_scripts_id_prepare(script_id, script_update_request, **kwargs) @@ -442,6 +461,10 @@ async def patch_scripts_id_async(self, script_id, script_update_request, **kwarg If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._patch_scripts_id_prepare(script_id, script_update_request, **kwargs) @@ -532,6 +555,10 @@ def post_scripts_with_http_info(self, script_create_request, **kwargs): # noqa: If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._post_scripts_prepare(script_create_request, **kwargs) @@ -563,6 +590,10 @@ async def post_scripts_async(self, script_create_request, **kwargs): # noqa: E5 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._post_scripts_prepare(script_create_request, **kwargs) @@ -651,6 +682,10 @@ def post_scripts_id_invoke_with_http_info(self, script_id, **kwargs): # noqa: E If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not self._is_cloud_instance(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._post_scripts_id_invoke_prepare(script_id, **kwargs) @@ -684,6 +719,10 @@ async def post_scripts_id_invoke_async(self, script_id, **kwargs): # noqa: E501 If the method is called asynchronously, returns the request thread. """ # noqa: E501 + if not await self._is_cloud_instance_async(): + from influxdb_client.client.warnings import CloudOnlyWarning + CloudOnlyWarning.print_warning('InvokableScriptsService', + 'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501 local_var_params, path_params, query_params, header_params, body_params = \ self._post_scripts_id_invoke_prepare(script_id, **kwargs) diff --git a/tests/test_Warnings.py b/tests/test_Warnings.py index 019b9032..9d32d368 100644 --- a/tests/test_Warnings.py +++ b/tests/test_Warnings.py @@ -1,15 +1,30 @@ +import json import unittest +import httpretty import pytest from influxdb_client import InfluxDBClient, BucketSchemasService from influxdb_client.client.warnings import CloudOnlyWarning -class PointWarnings(unittest.TestCase): +class Warnings(unittest.TestCase): + + def setUp(self) -> None: + httpretty.enable() + httpretty.reset() + + def tearDown(self) -> None: + httpretty.disable() def test_cloud_only_warning(self): + httpretty.register_uri(httpretty.GET, uri="http://localhost/ping", + status=200, body="{}", adding_headers={'X-Influxdb-Build': 'OSS'}) + httpretty.register_uri(httpretty.GET, uri="http://localhost/api/v2/buckets/01010101/schema/measurements", + status=200, body=json.dumps({'measurementSchemas': []})) + with pytest.warns(CloudOnlyWarning) as warnings: - with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client: - BucketSchemasService(api_client=client.api_client) + with InfluxDBClient(url="http://localhost", token="my-token", org="my-org") as client: + service = BucketSchemasService(api_client=client.api_client) + service.get_measurement_schemas(bucket_id="01010101") self.assertEqual(1, len(warnings))