Skip to content

Commit 9e850db

Browse files
committed
Added Python3.x documentation. Renamed files with dashes to underscores.
1 parent 2e2f856 commit 9e850db

14 files changed

+134
-106
lines changed

README.md

Lines changed: 102 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@
22

33
## Installation
44

5-
Two methods are provided to install this software. Use PyPi (see [package](https://pypi.python.org/pypi/cloudflare) details) or GitHub (see [package](https://github.com/cloudflare/python-cloudflare) details).
5+
Two methods are provided to install this software.
6+
Use PyPi (see [package](https://pypi.python.org/pypi/cloudflare) details) or GitHub (see [package](https://github.com/cloudflare/python-cloudflare) details).
67

78
### Via PyPI
89

910
```bash
10-
$ sudo pip install cloudflare
11-
$
11+
$ sudo pip install cloudflare
12+
$
1213
```
1314

1415
Yes - that simple! (the sudo may not be needed in some cases).
1516

1617
### Via github
1718

1819
```bash
19-
$ git clone https://github.com/cloudflare/python-cloudflare
20-
$ cd python-cloudflare
21-
$ ./setup.py build
22-
$ sudo ./setup.py install
23-
$
20+
$ git clone https://github.com/cloudflare/python-cloudflare
21+
$ cd python-cloudflare
22+
$ ./setup.py build
23+
$ sudo ./setup.py install
24+
$
2425
```
2526

2627
Or whatever variance of that you want to use.
28+
There is a Makefile included.
2729

2830
## CloudFlare API version 4
2931

30-
The CloudFlare API can be found [here](https://api.cloudflare.com/). Each API call is provided via a similarly named function within the _CloudFlare_ class. A full list is provided below.
32+
The CloudFlare API can be found [here](https://api.cloudflare.com/).
33+
Each API call is provided via a similarly named function within the _CloudFlare_ class.
34+
A full list is provided below.
3135

3236
## Getting Started
3337

@@ -37,19 +41,19 @@ A very simple listing of zones within your account; including the IPv6 status of
3741
import CloudFlare
3842

3943
def main():
40-
cf = CloudFlare.CloudFlare()
41-
zones = cf.zones.get(params = {'per_page':50})
42-
for zone in zones:
43-
zone_name = zone['name']
44-
zone_id = zone['id']
45-
settings_ipv6 = cf.zones.settings.ipv6.get(zone_id)
46-
ipv6_status = settings_ipv6['value']
47-
settings_ssl = cf.zones.settings.ssl.get(zone_id)
48-
ssl_status = settings_ssl['value']
49-
print zone_id, ssl_status, ipv6_status, zone_name
44+
cf = CloudFlare.CloudFlare()
45+
zones = cf.zones.get(params = {'per_page':50})
46+
for zone in zones:
47+
zone_name = zone['name']
48+
zone_id = zone['id']
49+
settings_ipv6 = cf.zones.settings.ipv6.get(zone_id)
50+
ipv6_status = settings_ipv6['value']
51+
settings_ssl = cf.zones.settings.ssl.get(zone_id)
52+
ssl_status = settings_ssl['value']
53+
print zone_id, ssl_status, ipv6_status, zone_name
5054

5155
if __name__ == '__main__':
52-
main()
56+
main()
5357
```
5458

5559
A more complex example follows.
@@ -59,43 +63,43 @@ import sys
5963
import CloudFlare
6064

6165
def main():
62-
zone_name = 'example.com'
66+
zone_name = 'example.com'
6367

64-
cf = CloudFlare.CloudFlare()
68+
cf = CloudFlare.CloudFlare()
6569

66-
# query for the zone name and expect only one value back
67-
try:
68-
zones = cf.zones.get(params = {'name':zone_name,'per_page':1})
69-
except CloudFlare.CloudFlareAPIError as e:
70-
exit('/zones.get %d %s - api call failed' % (e, e))
71-
except Exception as e:
72-
exit('/zones.get - %s - api call failed' % (e))
70+
# query for the zone name and expect only one value back
71+
try:
72+
zones = cf.zones.get(params = {'name':zone_name,'per_page':1})
73+
except CloudFlare.CloudFlareAPIError as e:
74+
exit('/zones.get %d %s - api call failed' % (e, e))
75+
except Exception as e:
76+
exit('/zones.get - %s - api call failed' % (e))
7377

74-
# extract the zone_id which is needed to process that zone
75-
zone = zones[0]
76-
zone_id = zone['id']
78+
# extract the zone_id which is needed to process that zone
79+
zone = zones[0]
80+
zone_id = zone['id']
7781

78-
# request the DNS records from that zone
79-
try:
80-
dns_records = cf.zones.dns_records.get(zone_id)
81-
except CloudFlare.CloudFlareAPIError as e:
82-
exit('/zones/dns_records.get %d %s - api call failed' % (e, e))
82+
# request the DNS records from that zone
83+
try:
84+
dns_records = cf.zones.dns_records.get(zone_id)
85+
except CloudFlare.CloudFlareAPIError as e:
86+
exit('/zones/dns_records.get %d %s - api call failed' % (e, e))
8387

84-
# print the results - first the zone name
85-
print zone_id, zone_name
88+
# print the results - first the zone name
89+
print zone_id, zone_name
8690

87-
# then all the DNS records for that zone
88-
for dns_record in dns_records:
89-
r_name = dns_record['name']
90-
r_type = dns_record['type']
91-
r_value = dns_record['content']
92-
r_id = dns_record['id']
93-
print '\t', r_id, r_name, r_type, r_value
91+
# then all the DNS records for that zone
92+
for dns_record in dns_records:
93+
r_name = dns_record['name']
94+
r_type = dns_record['type']
95+
r_value = dns_record['content']
96+
r_id = dns_record['id']
97+
print '\t', r_id, r_name, r_type, r_value
9498

95-
exit(0)
99+
exit(0)
96100

97101
if __name__ == '__main__':
98-
main()
102+
main()
99103
```
100104

101105
## Providing CloudFlare Username and API Key
@@ -121,7 +125,7 @@ $
121125
### Using configuration file to store email and keys
122126

123127
```bash
124-
$ cat ~/.cloudflare/cloudflare.cfg
128+
$ cat ~/.cloudflare/cloudflare.cfg
125129
[CloudFlare]
126130
email = user@example.com
127131
token = 00000000000000000000000000000000
@@ -144,30 +148,31 @@ import sys
144148
import CloudFlare
145149

146150
def main():
147-
zone_name = sys.argv[1]
148-
cf = CloudFlare.CloudFlare()
149-
zone_info = cf.zones.post(data={'jump_start':False, 'name': zone_name})
150-
zone_id = zone_info['id']
151-
152-
dns_records = [
153-
{'name':'foo', 'type':'AAAA', 'content':'2001:d8b::1'},
154-
{'name':'foo', 'type':'A', 'content':'192.168.0.1'},
155-
{'name':'duh', 'type':'A', 'content':'10.0.0.1', 'ttl':120},
156-
{'name':'bar', 'type':'CNAME', 'content':'foo'},
157-
{'name':'shakespeare', 'type':'TXT', 'content':"What's in a name? That which we call a rose by any other name ..."}
158-
]
159-
160-
for dns_record in dns_records:
161-
r = cf.zones.dns_records.post(zone_id, data=dns_record)
162-
exit(0)
151+
zone_name = sys.argv[1]
152+
cf = CloudFlare.CloudFlare()
153+
zone_info = cf.zones.post(data={'jump_start':False, 'name': zone_name})
154+
zone_id = zone_info['id']
155+
156+
dns_records = [
157+
{'name':'foo', 'type':'AAAA', 'content':'2001:d8b::1'},
158+
{'name':'foo', 'type':'A', 'content':'192.168.0.1'},
159+
{'name':'duh', 'type':'A', 'content':'10.0.0.1', 'ttl':120},
160+
{'name':'bar', 'type':'CNAME', 'content':'foo'},
161+
{'name':'shakespeare', 'type':'TXT', 'content':"What's in a name? That which we call a rose by any other name ..."}
162+
]
163+
164+
for dns_record in dns_records:
165+
r = cf.zones.dns_records.post(zone_id, data=dns_record)
166+
exit(0)
163167

164168
if __name__ == '__main__':
165-
main()
169+
main()
166170
```
167171

168172
## CLI
169173

170-
All API calls can be called from the command line. The command will convert domain names on-the-fly into zone_identifier's.
174+
All API calls can be called from the command line.
175+
The command will convert domain names on-the-fly into zone_identifier's.
171176

172177
```bash
173178
$ cli4 [-h|--help] [-v|--verbose] [-q|--quiet] [--get|--patch|--post|-put|--delete] [item=value ...] /command...
@@ -219,7 +224,8 @@ $ cli4 --delete /zones/:example.com/dns_records/:test.example.com | jq -c .
219224
$
220225
```
221226

222-
There's the ability to handle dns entries with multiple values. This produces more than one API call within the command.
227+
There's the ability to handle dns entries with multiple values.
228+
This produces more than one API call within the command.
223229

224230
```
225231
$ cli4 /zones/:example.com/dns_records/:test.example.com | jq -c '.[]|{"id":.id,"name":.name,"type":.type,"content":.content}'
@@ -256,7 +262,7 @@ $ cli4 /zones/:example.com/available_plans | jq -c '.[]|{"id":.id,"name":.name}'
256262
{"id":"1ac039f6c29b691475c3d74fe588d1ae","name":"Business Website"}
257263
{"id":"94f3b7b768b0458b56d2cac4fe5ec0f9","name":"Enterprise Website"}
258264
{"id":"0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee","name":"Free Website"}
259-
$
265+
$
260266
```
261267

262268
### DNSSEC CLI examples
@@ -270,21 +276,21 @@ $ cli4 --patch status=active /zones/:example.com/dnssec | jq -c '{"status":.stat
270276
{"status":"pending"}
271277
$
272278

273-
$ cli4 /zones/:example.com/dnssec
279+
$ cli4 /zones/:example.com/dnssec
274280
{
275-
"algorithm": "13",
276-
"digest": "41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
277-
"digest_algorithm": "SHA256",
278-
"digest_type": "2",
279-
"ds": "example.com. 3600 IN DS 2371 13 2 41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
280-
"flags": 257,
281-
"key_tag": 2371,
282-
"key_type": "ECDSAP256SHA256",
283-
"modified_on": "2016-05-01T22:42:15.591158Z",
284-
"public_key": "mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==",
281+
"algorithm": "13",
282+
"digest": "41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
283+
"digest_algorithm": "SHA256",
284+
"digest_type": "2",
285+
"ds": "example.com. 3600 IN DS 2371 13 2 41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
286+
"flags": 257,
287+
"key_tag": 2371,
288+
"key_type": "ECDSAP256SHA256",
289+
"modified_on": "2016-05-01T22:42:15.591158Z",
290+
"public_key": "mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==",
285291
"status": "pending"
286292
}
287-
$
293+
$
288294
```
289295

290296
## Implemented API calls
@@ -365,12 +371,12 @@ $
365371

366372
Extra API calls can be added via the configuration file
367373
```bash
368-
$ cat ~/.cloudflare/cloudflare.cfg
374+
$ cat ~/.cloudflare/cloudflare.cfg
369375
[CloudFlare]
370376
extras=
371-
/client/v4/command
372-
/client/v4/command/:command_identifier
373-
/client/v4/command/:command_identifier/settings
377+
/client/v4/command
378+
/client/v4/command/:command_identifier
379+
/client/v4/command/:command_identifier/settings
374380
$
375381
```
376382

@@ -390,11 +396,20 @@ The following error can be caused by an out of date SSL/TLS library and/or out o
390396

391397
The solution can be found [here](https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning) and/or [here](http://stackoverflow.com/questions/35144550/how-to-install-cryptography-on-ubuntu).
392398

399+
## Python 2.x vs 3.x support
400+
401+
As of May/June 2016 the code is now tested againt pylint.
402+
This was required in order to move the codebase into Python 3.x.
403+
The motivation for this came from [Danielle Madeley (danni)](https://github.com/danni).
404+
405+
While the codebase has been edited to run on Python 3.x, there's not been enough Python 3.x testing performed.
406+
If you can help in this regard; please contact the maintainers.
407+
393408
## Credit
394409

395-
This is based on work by [Felix Wong (gnowxilef)](https://github.com/gnowxilef) found [here](https://github.com/cloudflare-api/python-cloudflare-v4). It has been seriously expanded upon.
410+
This is based on work by [Felix Wong (gnowxilef)](https://github.com/gnowxilef) found [here](https://github.com/cloudflare-api/python-cloudflare-v4).
411+
It has been seriously expanded upon.
396412

397413
## Copyright
398414

399415
Portions copyright [Felix Wong (gnowxilef)](https://github.com/gnowxilef) 2015 and CloudFlare 2016.
400-

README.rst

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Via github
3030
$ sudo ./setup.py install
3131
$
3232
33-
Or whatever variance of that you want to use.
33+
Or whatever variance of that you want to use. There is a Makefile
34+
included.
3435

3536
CloudFlare API version 4
3637
------------------------
@@ -144,7 +145,7 @@ Using configuration file to store email and keys
144145

145146
.. code:: bash
146147
147-
$ cat ~/.cloudflare/cloudflare.cfg
148+
$ cat ~/.cloudflare/cloudflare.cfg
148149
[CloudFlare]
149150
email = user@example.com
150151
token = 00000000000000000000000000000000
@@ -290,7 +291,7 @@ A somewhat useful listing of available plans for a specific zone.
290291
{"id":"1ac039f6c29b691475c3d74fe588d1ae","name":"Business Website"}
291292
{"id":"94f3b7b768b0458b56d2cac4fe5ec0f9","name":"Enterprise Website"}
292293
{"id":"0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee","name":"Free Website"}
293-
$
294+
$
294295
295296
DNSSEC CLI examples
296297
~~~~~~~~~~~~~~~~~~~
@@ -305,21 +306,21 @@ DNSSEC CLI examples
305306
{"status":"pending"}
306307
$
307308
308-
$ cli4 /zones/:example.com/dnssec
309+
$ cli4 /zones/:example.com/dnssec
309310
{
310-
"algorithm": "13",
311-
"digest": "41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
312-
"digest_algorithm": "SHA256",
313-
"digest_type": "2",
314-
"ds": "example.com. 3600 IN DS 2371 13 2 41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
315-
"flags": 257,
316-
"key_tag": 2371,
317-
"key_type": "ECDSAP256SHA256",
318-
"modified_on": "2016-05-01T22:42:15.591158Z",
319-
"public_key": "mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==",
311+
"algorithm": "13",
312+
"digest": "41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
313+
"digest_algorithm": "SHA256",
314+
"digest_type": "2",
315+
"ds": "example.com. 3600 IN DS 2371 13 2 41600621c65065b09230ebc9556ced937eb7fd86e31635d0025326ccf09a7194",
316+
"flags": 257,
317+
"key_tag": 2371,
318+
"key_type": "ECDSAP256SHA256",
319+
"modified_on": "2016-05-01T22:42:15.591158Z",
320+
"public_key": "mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ==",
320321
"status": "pending"
321322
}
322-
$
323+
$
323324
324325
Implemented API calls
325326
---------------------
@@ -473,12 +474,12 @@ Extra API calls can be added via the configuration file
473474

474475
.. code:: bash
475476
476-
$ cat ~/.cloudflare/cloudflare.cfg
477+
$ cat ~/.cloudflare/cloudflare.cfg
477478
[CloudFlare]
478479
extras=
479-
/client/v4/command
480-
/client/v4/command/:command_identifier
481-
/client/v4/command/:command_identifier/settings
480+
/client/v4/command
481+
/client/v4/command/:command_identifier
482+
/client/v4/command/:command_identifier/settings
482483
$
483484
484485
While it's easy to call anything within CloudFlare's API, it's not very
@@ -503,6 +504,18 @@ The solution can be found
503504
and/or
504505
`here <http://stackoverflow.com/questions/35144550/how-to-install-cryptography-on-ubuntu>`__.
505506

507+
Python 2.x vs 3.x support
508+
-------------------------
509+
510+
As of May/June 2016 the code is now tested againt pylint. This was
511+
required in order to move the codebase into Python 3.x. The motivation
512+
for this came from `Danielle Madeley
513+
(danni) <https://github.com/danni>`__.
514+
515+
While the codebase has been edited to run on Python 3.x, there's not
516+
been enough Python 3.x testing performed. If you can help in this
517+
regard; please contact the maintainers.
518+
506519
Credit
507520
------
508521

File renamed without changes.

0 commit comments

Comments
 (0)