Skip to content

Commit e705ee9

Browse files
committed
feat: add warning for not Cloud instance
1 parent 9767ef0 commit e705ee9

File tree

3 files changed

+100
-14
lines changed

3 files changed

+100
-14
lines changed

influxdb_client/service/bucket_schemas_service.py

+38-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ def create_measurement_schema_with_http_info(self, bucket_id, measurement_schema
7272
If the method is called asynchronously,
7373
returns the request thread.
7474
""" # noqa: E501
75+
if not self._is_cloud_instance():
76+
from influxdb_client.client.warnings import CloudOnlyWarning
77+
CloudOnlyWarning.print_warning('BucketSchemasService',
78+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
7579
local_var_params, path_params, query_params, header_params, body_params = \
76-
self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs)
80+
self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) # noqa: E501
7781

7882
return self.api_client.call_api(
7983
'/api/v2/buckets/{bucketID}/schema/measurements', 'POST',
@@ -107,8 +111,12 @@ async def create_measurement_schema_async(self, bucket_id, measurement_schema_cr
107111
If the method is called asynchronously,
108112
returns the request thread.
109113
""" # noqa: E501
114+
if not await self._is_cloud_instance_async():
115+
from influxdb_client.client.warnings import CloudOnlyWarning
116+
CloudOnlyWarning.print_warning('BucketSchemasService',
117+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
110118
local_var_params, path_params, query_params, header_params, body_params = \
111-
self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs)
119+
self._create_measurement_schema_prepare(bucket_id, measurement_schema_create_request, **kwargs) # noqa: E501
112120

113121
return await self.api_client.call_api(
114122
'/api/v2/buckets/{bucketID}/schema/measurements', 'POST',
@@ -209,8 +217,12 @@ def get_measurement_schema_with_http_info(self, bucket_id, measurement_id, **kwa
209217
If the method is called asynchronously,
210218
returns the request thread.
211219
""" # noqa: E501
220+
if not self._is_cloud_instance():
221+
from influxdb_client.client.warnings import CloudOnlyWarning
222+
CloudOnlyWarning.print_warning('BucketSchemasService',
223+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
212224
local_var_params, path_params, query_params, header_params, body_params = \
213-
self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs)
225+
self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) # noqa: E501
214226

215227
return self.api_client.call_api(
216228
'/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'GET',
@@ -244,8 +256,12 @@ async def get_measurement_schema_async(self, bucket_id, measurement_id, **kwargs
244256
If the method is called asynchronously,
245257
returns the request thread.
246258
""" # noqa: E501
259+
if not await self._is_cloud_instance_async():
260+
from influxdb_client.client.warnings import CloudOnlyWarning
261+
CloudOnlyWarning.print_warning('BucketSchemasService',
262+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
247263
local_var_params, path_params, query_params, header_params, body_params = \
248-
self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs)
264+
self._get_measurement_schema_prepare(bucket_id, measurement_id, **kwargs) # noqa: E501
249265

250266
return await self.api_client.call_api(
251267
'/api/v2/buckets/{bucketID}/schema/measurements/{measurementID}', 'GET',
@@ -342,8 +358,12 @@ def get_measurement_schemas_with_http_info(self, bucket_id, **kwargs): # noqa:
342358
If the method is called asynchronously,
343359
returns the request thread.
344360
""" # noqa: E501
361+
if not self._is_cloud_instance():
362+
from influxdb_client.client.warnings import CloudOnlyWarning
363+
CloudOnlyWarning.print_warning('BucketSchemasService',
364+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
345365
local_var_params, path_params, query_params, header_params, body_params = \
346-
self._get_measurement_schemas_prepare(bucket_id, **kwargs)
366+
self._get_measurement_schemas_prepare(bucket_id, **kwargs) # noqa: E501
347367

348368
return self.api_client.call_api(
349369
'/api/v2/buckets/{bucketID}/schema/measurements', 'GET',
@@ -377,8 +397,12 @@ async def get_measurement_schemas_async(self, bucket_id, **kwargs): # noqa: E50
377397
If the method is called asynchronously,
378398
returns the request thread.
379399
""" # noqa: E501
400+
if not await self._is_cloud_instance_async():
401+
from influxdb_client.client.warnings import CloudOnlyWarning
402+
CloudOnlyWarning.print_warning('BucketSchemasService',
403+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
380404
local_var_params, path_params, query_params, header_params, body_params = \
381-
self._get_measurement_schemas_prepare(bucket_id, **kwargs)
405+
self._get_measurement_schemas_prepare(bucket_id, **kwargs) # noqa: E501
382406

383407
return await self.api_client.call_api(
384408
'/api/v2/buckets/{bucketID}/schema/measurements', 'GET',
@@ -473,6 +497,10 @@ def update_measurement_schema_with_http_info(self, bucket_id, measurement_id, me
473497
If the method is called asynchronously,
474498
returns the request thread.
475499
""" # noqa: E501
500+
if not self._is_cloud_instance():
501+
from influxdb_client.client.warnings import CloudOnlyWarning
502+
CloudOnlyWarning.print_warning('BucketSchemasService',
503+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
476504
local_var_params, path_params, query_params, header_params, body_params = \
477505
self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501
478506

@@ -509,6 +537,10 @@ async def update_measurement_schema_async(self, bucket_id, measurement_id, measu
509537
If the method is called asynchronously,
510538
returns the request thread.
511539
""" # noqa: E501
540+
if not await self._is_cloud_instance_async():
541+
from influxdb_client.client.warnings import CloudOnlyWarning
542+
CloudOnlyWarning.print_warning('BucketSchemasService',
543+
'https://docs.influxdata.com/influxdb/cloud/organizations/buckets/bucket-schema/') # noqa: E501
512544
local_var_params, path_params, query_params, header_params, body_params = \
513545
self._update_measurement_schema_prepare(bucket_id, measurement_id, measurement_schema_update_request, **kwargs) # noqa: E501
514546

influxdb_client/service/invokable_scripts_service.py

+44-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ def __init__(self, api_client=None): # noqa: E501,D401,D403
2929
"""InvokableScriptsService - a operation defined in OpenAPI."""
3030
super().__init__(api_client)
3131

32-
from influxdb_client.client.warnings import CloudOnlyWarning
33-
CloudOnlyWarning.print_warning('InvokableScriptsService',
34-
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/',
35-
api_client) # noqa: E501
36-
3732
def delete_scripts_id(self, script_id, **kwargs): # noqa: E501,D401,D403
3833
"""Delete a script.
3934
@@ -103,6 +98,10 @@ async def delete_scripts_id_async(self, script_id, **kwargs): # noqa: E501,D401
10398
If the method is called asynchronously,
10499
returns the request thread.
105100
""" # noqa: E501
101+
if not await self._is_cloud_instance_async():
102+
from influxdb_client.client.warnings import CloudOnlyWarning
103+
CloudOnlyWarning.print_warning('InvokableScriptsService',
104+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
106105
local_var_params, path_params, query_params, header_params, body_params = \
107106
self._delete_scripts_id_prepare(script_id, **kwargs)
108107

@@ -181,6 +180,10 @@ def get_scripts_with_http_info(self, **kwargs): # noqa: E501,D401,D403
181180
If the method is called asynchronously,
182181
returns the request thread.
183182
""" # noqa: E501
183+
if not self._is_cloud_instance():
184+
from influxdb_client.client.warnings import CloudOnlyWarning
185+
CloudOnlyWarning.print_warning('InvokableScriptsService',
186+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
184187
local_var_params, path_params, query_params, header_params, body_params = \
185188
self._get_scripts_prepare(**kwargs)
186189

@@ -213,6 +216,10 @@ async def get_scripts_async(self, **kwargs): # noqa: E501,D401,D403
213216
If the method is called asynchronously,
214217
returns the request thread.
215218
""" # noqa: E501
219+
if not await self._is_cloud_instance_async():
220+
from influxdb_client.client.warnings import CloudOnlyWarning
221+
CloudOnlyWarning.print_warning('InvokableScriptsService',
222+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
216223
local_var_params, path_params, query_params, header_params, body_params = \
217224
self._get_scripts_prepare(**kwargs)
218225

@@ -293,6 +300,10 @@ def get_scripts_id_with_http_info(self, script_id, **kwargs): # noqa: E501,D401
293300
If the method is called asynchronously,
294301
returns the request thread.
295302
""" # noqa: E501
303+
if not self._is_cloud_instance():
304+
from influxdb_client.client.warnings import CloudOnlyWarning
305+
CloudOnlyWarning.print_warning('InvokableScriptsService',
306+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
296307
local_var_params, path_params, query_params, header_params, body_params = \
297308
self._get_scripts_id_prepare(script_id, **kwargs)
298309

@@ -325,6 +336,10 @@ async def get_scripts_id_async(self, script_id, **kwargs): # noqa: E501,D401,D4
325336
If the method is called asynchronously,
326337
returns the request thread.
327338
""" # noqa: E501
339+
if not await self._is_cloud_instance_async():
340+
from influxdb_client.client.warnings import CloudOnlyWarning
341+
CloudOnlyWarning.print_warning('InvokableScriptsService',
342+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
328343
local_var_params, path_params, query_params, header_params, body_params = \
329344
self._get_scripts_id_prepare(script_id, **kwargs)
330345

@@ -409,6 +424,10 @@ def patch_scripts_id_with_http_info(self, script_id, script_update_request, **kw
409424
If the method is called asynchronously,
410425
returns the request thread.
411426
""" # noqa: E501
427+
if not self._is_cloud_instance():
428+
from influxdb_client.client.warnings import CloudOnlyWarning
429+
CloudOnlyWarning.print_warning('InvokableScriptsService',
430+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
412431
local_var_params, path_params, query_params, header_params, body_params = \
413432
self._patch_scripts_id_prepare(script_id, script_update_request, **kwargs)
414433

@@ -442,6 +461,10 @@ async def patch_scripts_id_async(self, script_id, script_update_request, **kwarg
442461
If the method is called asynchronously,
443462
returns the request thread.
444463
""" # noqa: E501
464+
if not await self._is_cloud_instance_async():
465+
from influxdb_client.client.warnings import CloudOnlyWarning
466+
CloudOnlyWarning.print_warning('InvokableScriptsService',
467+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
445468
local_var_params, path_params, query_params, header_params, body_params = \
446469
self._patch_scripts_id_prepare(script_id, script_update_request, **kwargs)
447470

@@ -532,6 +555,10 @@ def post_scripts_with_http_info(self, script_create_request, **kwargs): # noqa:
532555
If the method is called asynchronously,
533556
returns the request thread.
534557
""" # noqa: E501
558+
if not self._is_cloud_instance():
559+
from influxdb_client.client.warnings import CloudOnlyWarning
560+
CloudOnlyWarning.print_warning('InvokableScriptsService',
561+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
535562
local_var_params, path_params, query_params, header_params, body_params = \
536563
self._post_scripts_prepare(script_create_request, **kwargs)
537564

@@ -563,6 +590,10 @@ async def post_scripts_async(self, script_create_request, **kwargs): # noqa: E5
563590
If the method is called asynchronously,
564591
returns the request thread.
565592
""" # noqa: E501
593+
if not await self._is_cloud_instance_async():
594+
from influxdb_client.client.warnings import CloudOnlyWarning
595+
CloudOnlyWarning.print_warning('InvokableScriptsService',
596+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
566597
local_var_params, path_params, query_params, header_params, body_params = \
567598
self._post_scripts_prepare(script_create_request, **kwargs)
568599

@@ -651,6 +682,10 @@ def post_scripts_id_invoke_with_http_info(self, script_id, **kwargs): # noqa: E
651682
If the method is called asynchronously,
652683
returns the request thread.
653684
""" # noqa: E501
685+
if not self._is_cloud_instance():
686+
from influxdb_client.client.warnings import CloudOnlyWarning
687+
CloudOnlyWarning.print_warning('InvokableScriptsService',
688+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
654689
local_var_params, path_params, query_params, header_params, body_params = \
655690
self._post_scripts_id_invoke_prepare(script_id, **kwargs)
656691

@@ -684,6 +719,10 @@ async def post_scripts_id_invoke_async(self, script_id, **kwargs): # noqa: E501
684719
If the method is called asynchronously,
685720
returns the request thread.
686721
""" # noqa: E501
722+
if not await self._is_cloud_instance_async():
723+
from influxdb_client.client.warnings import CloudOnlyWarning
724+
CloudOnlyWarning.print_warning('InvokableScriptsService',
725+
'https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts/') # noqa: E501
687726
local_var_params, path_params, query_params, header_params, body_params = \
688727
self._post_scripts_id_invoke_prepare(script_id, **kwargs)
689728

tests/test_Warnings.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
import json
12
import unittest
23

4+
import httpretty
35
import pytest
46

57
from influxdb_client import InfluxDBClient, BucketSchemasService
68
from influxdb_client.client.warnings import CloudOnlyWarning
79

810

9-
class PointWarnings(unittest.TestCase):
11+
class Warnings(unittest.TestCase):
12+
13+
def setUp(self) -> None:
14+
httpretty.enable()
15+
httpretty.reset()
16+
17+
def tearDown(self) -> None:
18+
httpretty.disable()
1019

1120
def test_cloud_only_warning(self):
21+
httpretty.register_uri(httpretty.GET, uri="http://localhost/ping",
22+
status=200, body="{}", adding_headers={'X-Influxdb-Build': 'OSS'})
23+
httpretty.register_uri(httpretty.GET, uri="http://localhost/api/v2/buckets/01010101/schema/measurements",
24+
status=200, body=json.dumps({'measurementSchemas': []}))
25+
1226
with pytest.warns(CloudOnlyWarning) as warnings:
13-
with InfluxDBClient(url="http://localhost:8086", token="my-token", org="my-org") as client:
14-
BucketSchemasService(api_client=client.api_client)
27+
with InfluxDBClient(url="http://localhost", token="my-token", org="my-org") as client:
28+
service = BucketSchemasService(api_client=client.api_client)
29+
service.get_measurement_schemas(bucket_id="01010101")
1530
self.assertEqual(1, len(warnings))

0 commit comments

Comments
 (0)