diff --git a/CHANGELOG.md b/CHANGELOG.md index eaef1890..595852cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 0.0.3 [unreleased] +### API +1. [#28](https://github.com/bonitoo-io/influxdb-client-python/pull/28): Updated swagger to latest version + ### Features 1. [#24](https://github.com/influxdata/influxdb-client-python/issues/24): Added possibility to write dictionary-style object diff --git a/influxdb_client/__init__.py b/influxdb_client/__init__.py index 720bfb60..a2895e90 100644 --- a/influxdb_client/__init__.py +++ b/influxdb_client/__init__.py @@ -93,6 +93,7 @@ from influxdb_client.domain.date_time_literal import DateTimeLiteral from influxdb_client.domain.deadman_check import DeadmanCheck from influxdb_client.domain.decimal_places import DecimalPlaces +from influxdb_client.domain.delete_predicate_request import DeletePredicateRequest from influxdb_client.domain.dialect import Dialect from influxdb_client.domain.document import Document from influxdb_client.domain.document_create import DocumentCreate diff --git a/influxdb_client/domain/__init__.py b/influxdb_client/domain/__init__.py index 0f0a37b1..c78a591c 100644 --- a/influxdb_client/domain/__init__.py +++ b/influxdb_client/domain/__init__.py @@ -61,6 +61,7 @@ from influxdb_client.domain.date_time_literal import DateTimeLiteral from influxdb_client.domain.deadman_check import DeadmanCheck from influxdb_client.domain.decimal_places import DecimalPlaces +from influxdb_client.domain.delete_predicate_request import DeletePredicateRequest from influxdb_client.domain.dialect import Dialect from influxdb_client.domain.document import Document from influxdb_client.domain.document_create import DocumentCreate diff --git a/influxdb_client/domain/delete_predicate_request.py b/influxdb_client/domain/delete_predicate_request.py new file mode 100644 index 00000000..7b83faa3 --- /dev/null +++ b/influxdb_client/domain/delete_predicate_request.py @@ -0,0 +1,172 @@ +# coding: utf-8 + +""" + Influx API Service + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 + + OpenAPI spec version: 0.1.0 + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + + +class DeletePredicateRequest(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 = { + 'start': 'datetime', + 'stop': 'datetime', + 'predicate': 'str' + } + + attribute_map = { + 'start': 'start', + 'stop': 'stop', + 'predicate': 'predicate' + } + + def __init__(self, start=None, stop=None, predicate=None): # noqa: E501 + """DeletePredicateRequest - a model defined in OpenAPI""" # noqa: E501 + + self._start = None + self._stop = None + self._predicate = None + self.discriminator = None + + self.start = start + self.stop = stop + if predicate is not None: + self.predicate = predicate + + @property + def start(self): + """Gets the start of this DeletePredicateRequest. # noqa: E501 + + RFC3339Nano. # noqa: E501 + + :return: The start of this DeletePredicateRequest. # noqa: E501 + :rtype: datetime + """ + return self._start + + @start.setter + def start(self, start): + """Sets the start of this DeletePredicateRequest. + + RFC3339Nano. # noqa: E501 + + :param start: The start of this DeletePredicateRequest. # noqa: E501 + :type: datetime + """ + if start is None: + raise ValueError("Invalid value for `start`, must not be `None`") # noqa: E501 + + self._start = start + + @property + def stop(self): + """Gets the stop of this DeletePredicateRequest. # noqa: E501 + + RFC3339Nano. # noqa: E501 + + :return: The stop of this DeletePredicateRequest. # noqa: E501 + :rtype: datetime + """ + return self._stop + + @stop.setter + def stop(self, stop): + """Sets the stop of this DeletePredicateRequest. + + RFC3339Nano. # noqa: E501 + + :param stop: The stop of this DeletePredicateRequest. # noqa: E501 + :type: datetime + """ + if stop is None: + raise ValueError("Invalid value for `stop`, must not be `None`") # noqa: E501 + + self._stop = stop + + @property + def predicate(self): + """Gets the predicate of this DeletePredicateRequest. # noqa: E501 + + sql where like delete statement # noqa: E501 + + :return: The predicate of this DeletePredicateRequest. # noqa: E501 + :rtype: str + """ + return self._predicate + + @predicate.setter + def predicate(self, predicate): + """Sets the predicate of this DeletePredicateRequest. + + sql where like delete statement # noqa: E501 + + :param predicate: The predicate of this DeletePredicateRequest. # noqa: E501 + :type: str + """ + + self._predicate = predicate + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + 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): + """Returns 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): + """Returns true if both objects are equal""" + if not isinstance(other, DeletePredicateRequest): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/influxdb_client/domain/http_notification_rule_base.py b/influxdb_client/domain/http_notification_rule_base.py index 31312a85..483b6c6a 100644 --- a/influxdb_client/domain/http_notification_rule_base.py +++ b/influxdb_client/domain/http_notification_rule_base.py @@ -48,7 +48,8 @@ def __init__(self, type=None, url=None): # noqa: E501 self.discriminator = None self.type = type - self.url = url + if url is not None: + self.url = url @property def type(self): @@ -91,8 +92,6 @@ def url(self, url): :param url: The url of this HTTPNotificationRuleBase. # noqa: E501 :type: str """ - if url is None: - raise ValueError("Invalid value for `url`, must not be `None`") # noqa: E501 self._url = url diff --git a/influxdb_client/service/default_service.py b/influxdb_client/service/default_service.py index b1dc48f1..8599c752 100644 --- a/influxdb_client/service/default_service.py +++ b/influxdb_client/service/default_service.py @@ -32,6 +32,124 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client + def delete_post(self, delete_predicate_request, **kwargs): # noqa: E501 + """delete Time series data from InfluxDB # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.delete_post(delete_predicate_request, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param DeletePredicateRequest delete_predicate_request: predicate delete request (required) + :param str zap_trace_span: OpenTracing span context + :param str org: specifies the destination organization for writes + :param str bucket: specifies the destination bucket for writes + :param str org_id: specifies the organization ID of the resource + :param str bucket_id: specifies the destination bucket ID for writes + :return: None + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.delete_post_with_http_info(delete_predicate_request, **kwargs) # noqa: E501 + else: + (data) = self.delete_post_with_http_info(delete_predicate_request, **kwargs) # noqa: E501 + return data + + def delete_post_with_http_info(self, delete_predicate_request, **kwargs): # noqa: E501 + """delete Time series data from InfluxDB # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.delete_post_with_http_info(delete_predicate_request, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param DeletePredicateRequest delete_predicate_request: predicate delete request (required) + :param str zap_trace_span: OpenTracing span context + :param str org: specifies the destination organization for writes + :param str bucket: specifies the destination bucket for writes + :param str org_id: specifies the organization ID of the resource + :param str bucket_id: specifies the destination bucket ID for writes + :return: None + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ['delete_predicate_request', 'zap_trace_span', 'org', 'bucket', 'org_id', 'bucket_id'] # noqa: E501 + all_params.append('async_req') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + for key, val in six.iteritems(local_var_params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method delete_post" % key + ) + local_var_params[key] = val + del local_var_params['kwargs'] + # verify the required parameter 'delete_predicate_request' is set + if ('delete_predicate_request' not in local_var_params or + local_var_params['delete_predicate_request'] is None): + raise ValueError("Missing the required parameter `delete_predicate_request` when calling `delete_post`") # noqa: E501 + + collection_formats = {} + + path_params = {} + + query_params = [] + if 'org' in local_var_params: + query_params.append(('org', local_var_params['org'])) # noqa: E501 + if 'bucket' in local_var_params: + query_params.append(('bucket', local_var_params['bucket'])) # noqa: E501 + if 'org_id' in local_var_params: + query_params.append(('orgID', local_var_params['org_id'])) # noqa: E501 + if 'bucket_id' in local_var_params: + query_params.append(('bucketID', local_var_params['bucket_id'])) # noqa: E501 + + header_params = {} + if 'zap_trace_span' in local_var_params: + header_params['Zap-Trace-Span'] = local_var_params['zap_trace_span'] # noqa: E501 + + form_params = [] + local_var_files = {} + + body_params = None + if 'delete_predicate_request' in local_var_params: + body_params = local_var_params['delete_predicate_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 + + # Authentication setting + auth_settings = [] # noqa: E501 + + return self.api_client.call_api( + '/api/v2/delete', 'POST', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type=None, # noqa: E501 + auth_settings=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=collection_formats) + def get_routes(self, **kwargs): # noqa: E501 """Map of all top level routes available # noqa: E501 diff --git a/scripts/swagger.yml b/scripts/swagger.yml index a7455593..0b892ad1 100644 --- a/scripts/swagger.yml +++ b/scripts/swagger.yml @@ -1640,6 +1640,68 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + /delete: + post: + summary: delete Time series data from InfluxDB + requestBody: + description: predicate delete request + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/DeletePredicateRequest" + parameters: + - $ref: '#/components/parameters/TraceSpan' + - in: query + name: org + description: specifies the destination organization for writes + schema: + type: string + description: all points within batch are written to this organization. + - in: query + name: bucket + description: specifies the destination bucket for writes + schema: + type: string + description: all points within batch are written to this bucket. + - in: query + name: orgID + description: specifies the organization ID of the resource + schema: + type: string + - in: query + name: bucketID + description: specifies the destination bucket ID for writes + schema: + type: string + description: all points within batch are written to this bucket. + responses: + '204': + description: delete has been accepted + '400': + description: invalid request. + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + '404': + description: the bucket or organization is not found. + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + '403': + description: no token was sent or does not have sufficient permissions. + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + default: + description: internal server error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" /ready: servers: - url: / @@ -3975,6 +4037,12 @@ paths: application/json: schema: $ref: "#/components/schemas/ResourceMembers" + '404': + description: Organization not found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" default: description: Unexpected error content: @@ -4067,6 +4135,12 @@ paths: application/json: schema: $ref: "#/components/schemas/ResourceOwners" + '404': + description: Organization not found + content: + application/json: + schema: + $ref: "#/components/schemas/Error" default: description: Unexpected error content: @@ -6160,6 +6234,23 @@ components: $ref: "#/components/schemas/Identifier" path: $ref: "#/components/schemas/StringLiteral" + DeletePredicateRequest: + description: the delete predicate request + type: object + required: [start, stop] + properties: + start: + description: RFC3339Nano. + type: string + format: date-time + stop: + description: RFC3339Nano. + type: string + format: date-time + predicate: + description: sql where like delete statement + example: tag1="value1" and (tag2="value2" and tag3="value3") + type: string Node: oneOf: - $ref: "#/components/schemas/Expression" @@ -9651,7 +9742,7 @@ components: type: string HTTPNotificationRuleBase: type: object - required: [type, url] + required: [type] properties: type: type: string diff --git a/tests/test_TasksApi.py b/tests/test_TasksApi.py index acab4d90..cbcc80a1 100644 --- a/tests/test_TasksApi.py +++ b/tests/test_TasksApi.py @@ -282,7 +282,7 @@ def test_runs(self): self.assertLess(run.scheduled_for, now.astimezone(tz=datetime.timezone.utc)) self.assertLess(run.started_at, now.astimezone(tz=datetime.timezone.utc)) self.assertLess(run.finished_at, now.astimezone(tz=datetime.timezone.utc)) - self.assertEqual(run.requested_at, datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)) + self.assertIsNone(run.requested_at) self.assertIsNotNone(run.links) self.assertEqual(run.links.logs, "/api/v2/tasks/" + task.id + "/runs/" + run.id + "/logs")