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

Commit 6eed220

Browse files
committed
cli4 has --header flag, plus http_headers needed some more syntax checking
1 parent dec9835 commit 6eed220

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CloudFlare/cloudflare.py

+8
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,14 @@ def __init__(self, email=None, key=None, token=None, certtoken=None, debug=False
10321032
if http_headers is not None:
10331033
if not isinstance(http_headers, list):
10341034
raise TypeError('http_headers is not a list')
1035+
for h in http_headers:
1036+
try:
1037+
t, v = h.split(':', 1)
1038+
except ValueError:
1039+
# clearly a bad header syntax
1040+
raise TypeError('http_headers bad syntax') from None
1041+
if len(t.strip()) == 0:
1042+
raise TypeError('http_headers bad syntax') from None
10351043
config['http_headers'] = http_headers
10361044

10371045
# we do not need to handle item.call values - they pass straight thru

CloudFlare/read_configs.py

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def read_configs(profile=None):
9797
config['extras'] = config['extras'].strip().split(' ')
9898
if 'http_headers' in config and config['http_headers'] is not None:
9999
config['http_headers'] = [h for h in config['http_headers'].split('\n') if len(h) > 0]
100+
for h in config['http_headers']:
101+
try:
102+
t, v = h.split(':', 1)
103+
except ValueError:
104+
# clearly a bad header syntax
105+
raise ReadConfigError('%s: header syntax error' % (h)) from None
106+
if len(t.strip()) == 0:
107+
raise ReadConfigError('%s: header syntax error' % (h)) from None
100108

101109
# remove blank entries
102110
for x in sorted(config.keys()):

cli4/cli4.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ def do_it(args):
396396
openapi_url = None
397397
binary_file = False
398398
profile = None
399+
http_headers = None
399400
method = 'GET'
400401

401402
usage = ('usage: cli4 '
@@ -408,13 +409,14 @@ def do_it(args):
408409
+ '[-A|--openapi url] '
409410
+ '[-b|--binary] '
410411
+ '[-p|--profile profile-name] '
412+
+ '[-h|--header additional-header] '
411413
+ '[--get|--patch|--post|--put|--delete] '
412414
+ '[item=value|item=@filename|@filename ...] '
413415
+ '/command ...')
414416

415417
try:
416418
opts, args = getopt.getopt(args,
417-
'VhveqjynirdA:bp:GPOUD',
419+
'VhveqjynirdA:bp:h:GPOUD',
418420
[
419421
'version', 'help', 'verbose',
420422
'examples',
@@ -425,6 +427,7 @@ def do_it(args):
425427
'openapi=',
426428
'binary',
427429
'profile=',
430+
'header=',
428431
'get', 'patch', 'post', 'put', 'delete'
429432
])
430433
except getopt.GetoptError:
@@ -454,6 +457,10 @@ def do_it(args):
454457
raw = True
455458
elif opt in ('-p', '--profile'):
456459
profile = arg
460+
elif opt in ('-h', '--header'):
461+
if http_headers is None:
462+
http_headers = []
463+
http_headers.append(arg)
457464
elif opt in ('-d', '--dump'):
458465
do_dump = True
459466
elif opt in ('-A', '--openapi'):
@@ -480,7 +487,7 @@ def do_it(args):
480487
sys.exit(0)
481488

482489
try:
483-
cf = CloudFlare.CloudFlare(debug=verbose, raw=raw, profile=profile)
490+
cf = CloudFlare.CloudFlare(debug=verbose, raw=raw, profile=profile, http_headers=http_headers)
484491
except Exception as e:
485492
sys.exit(e)
486493

0 commit comments

Comments
 (0)