Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 89d76d9

Browse files
committed
Merge branch 'spew-warning-for-2.20'
2 parents ddbe166 + 2720d21 commit 89d76d9

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

CloudFlare/cloudflare.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .api_extras import api_extras
1919
from .api_decode_from_openapi import api_decode_from_openapi
2020
from .exceptions import CloudFlareAPIError, CloudFlareInternalError
21+
from .warning_2_20 import warning_2_20, print_warning_2_20
2122

2223
BASE_URL = 'https://api.cloudflare.com/client/v4'
2324
OPENAPI_URL = 'https://github.com/cloudflare/api-schemas/raw/main/openapi.json'
@@ -48,7 +49,7 @@ class CloudFlare():
4849
class _v4base():
4950
""" :meta private: """
5051

51-
def __init__(self, config):
52+
def __init__(self, config, warnings=True):
5253
""" :meta private: """
5354

5455
self.network = None
@@ -88,6 +89,15 @@ def __init__(self, config):
8889

8990
self.logger = CFlogger(config['debug']).getLogger() if 'debug' in config and config['debug'] else None
9091

92+
if warnings:
93+
# After 2.20.* there is a warning message posted to handle un-pinned versions
94+
warning = warning_2_20()
95+
if warning:
96+
if self.logger:
97+
self.logger.warning(''.join(['\n ' + v for v in warning.split('\n')]))
98+
else:
99+
print_warning_2_20(warning)
100+
91101
def __del__(self):
92102
if self.network:
93103
del self.network
@@ -1024,7 +1034,7 @@ def api_from_openapi(self, url=None):
10241034

10251035
return self._base.api_from_openapi(url)
10261036

1027-
def __init__(self, email=None, key=None, token=None, certtoken=None, debug=False, raw=False, use_sessions=True, profile=None, base_url=None, global_request_timeout=None, max_request_retries=None, http_headers=None):
1037+
def __init__(self, email=None, key=None, token=None, certtoken=None, debug=False, raw=False, use_sessions=True, profile=None, base_url=None, global_request_timeout=None, max_request_retries=None, http_headers=None, warnings=True):
10281038
""" :meta private: """
10291039

10301040
self._base = None
@@ -1085,7 +1095,7 @@ def __init__(self, email=None, key=None, token=None, certtoken=None, debug=False
10851095
if v == '':
10861096
config[k] = None
10871097

1088-
self._base = self._v4base(config)
1098+
self._base = self._v4base(config, warnings=warnings)
10891099

10901100
# add the API calls
10911101
try:

CloudFlare/warning_2_20.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
""" warning message if version is 2.20 or above (technically, there's no version above 2.20.0) """
2+
3+
import sys
4+
5+
from . import __version__
6+
7+
MAJOR_VERSION_WARNING = """\
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
!! You're seeing this warning because you've upgraded the Python package 'cloudflare' to version !!
10+
!! 2.20.* via an automated upgrade without version pinning. Version 2.20.0 exists to catch any !!
11+
!! of these upgrades before Cloudflare releases a new major release under the release number 3.x. !!
12+
!! !!
13+
!! Should you determine that you need to revert this upgrade and pin to v2.19.* it is recommended !!
14+
!! you do the following: pip install --upgrade cloudflare==2.19.* or equivilant. !!
15+
!! !!
16+
!! Or you can upgrade to v3.x. NOTE: Release 3.x will not be code-compatible or call-compatible !!
17+
!! with previous releases. To see more about upgrading to next major version, please see: !!
18+
!! https://github.com/cloudflare/python-cloudflare/discussions/191 !!
19+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
20+
"""
21+
22+
def warning_2_20():
23+
""" warning_2_20 """
24+
25+
if __version__ < '2.20.0':
26+
return None
27+
return MAJOR_VERSION_WARNING
28+
29+
def print_warning_2_20(warning):
30+
""" print_warning_2_20 """
31+
print(warning, file=sys.stderr)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ $ cli4 [-V|--version] [-h|--help] [-v|--verbose] \
716716
[-b|--binary] \
717717
[-p|--profile profile-name] \
718718
[-h|--header additional-header] \
719+
[-w|--warnings [True|False]] \
719720
[--get|--patch|--post|--put|--delete] \
720721
[item=value|item=@filename|@filename ...] /command ...
721722
```

cli4/cli4.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ def do_it(args):
397397
binary_file = False
398398
profile = None
399399
http_headers = None
400+
warnings = True
400401
method = 'GET'
401402

402403
usage = ('usage: cli4 '
@@ -410,13 +411,14 @@ def do_it(args):
410411
+ '[-b|--binary] '
411412
+ '[-p|--profile profile-name] '
412413
+ '[-h|--header additional-header] '
414+
+ '[-w|--warnings [True|False]] '
413415
+ '[--get|--patch|--post|--put|--delete] '
414416
+ '[item=value|item=@filename|@filename ...] '
415417
+ '/command ...')
416418

417419
try:
418420
opts, args = getopt.getopt(args,
419-
'VhveqjynirdA:bp:h:GPOUD',
421+
'VhveqjynirdA:bp:h:w:GPOUD',
420422
[
421423
'version', 'help', 'verbose',
422424
'examples',
@@ -428,6 +430,7 @@ def do_it(args):
428430
'binary',
429431
'profile=',
430432
'header=',
433+
'warnings=',
431434
'get', 'patch', 'post', 'put', 'delete'
432435
])
433436
except getopt.GetoptError:
@@ -461,6 +464,15 @@ def do_it(args):
461464
if http_headers is None:
462465
http_headers = []
463466
http_headers.append(arg)
467+
elif opt in ('-w', '--warnings'):
468+
if arg is None or arg == '':
469+
warnings = None
470+
elif arg.lower() in ('yes', 'true', '1'):
471+
warnings = True
472+
elif arg.lower() in ('no', 'false', '0'):
473+
warnings = False
474+
else:
475+
sys.exit('cli4: --warnings takes boolean True/False argument')
464476
elif opt in ('-d', '--dump'):
465477
do_dump = True
466478
elif opt in ('-A', '--openapi'):
@@ -487,7 +499,7 @@ def do_it(args):
487499
sys.exit(0)
488500

489501
try:
490-
cf = CloudFlare.CloudFlare(debug=verbose, raw=raw, profile=profile, http_headers=http_headers)
502+
cf = CloudFlare.CloudFlare(debug=verbose, raw=raw, profile=profile, http_headers=http_headers, warnings=warnings)
491503
except Exception as e:
492504
sys.exit(e)
493505

0 commit comments

Comments
 (0)