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

Commit 0523914

Browse files
committed
updated docs to handle key vs token becuase of issue-114
1 parent 3ba3fe3 commit 0523914

2 files changed

Lines changed: 97 additions & 32 deletions

File tree

README.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,33 @@ if __name__ == '__main__':
171171

172172
## Providing Cloudflare Username and API Key
173173

174-
When you create a **CloudFlare** class you can pass up to four parameters.
174+
When you create a **CloudFlare** class you can pass some combination of these four core parameters.
175175

176-
* API Token or API Key
177-
* Account email (only if an API Key is being used)
178-
* Optional Origin-CA Certificate Token
179-
* Optional Debug flag (True/False)
180-
* Optional Profile name (the default is `Cloudflare`)
176+
* `email` - The account email (only if an API Key is being used)
177+
* `api` - The API Key (if coding prior to Issue-114 being merged)
178+
* `token` - The API Token (if coding after to Issue-114)
179+
* `certtoken` - Optional Origin-CA Certificate Token
180+
181+
This parameter controls how the data is returned from a successful call (see notes below).
182+
183+
* `raw - An optional Raw flag (True/False) - defaults to False
184+
185+
The following paramaters are for debug and/or development usage
186+
187+
* `debug` - An optional Debug flag (True/False) - defaults to False
188+
* `use_sessions` - An optional Use-Sessions flag (True/False) - defaults to True
189+
* `profile` - An optional Profile name (the default is `Cloudflare`)
190+
* `base_url` - An optional Base URL (only used for development)
191+
192+
email=None, key=None, token=None, certtoken=None, debug=False, raw=False, use_sessions=True, profile=None, base_url=None):
193+
194+
### Issue-114
195+
196+
After [Issue-114](https://github.com/cloudflare/python-cloudflare/issues/114) was coded and merged, the use of `token` and `key` changed; however, is backward compatible (amazingly!).
197+
198+
If you are using only the API Token, then don't include the API Email. If you are coding prior to Issue-114, then the API Key can also be used as an API Token if the API Email is not used.
199+
200+
### Python code to create class
181201

182202
```python
183203
import CloudFlare
@@ -191,28 +211,32 @@ import CloudFlare
191211
# An authenticated call using an API Token (note the missing email)
192212
cf = CloudFlare.CloudFlare(token='00000000000000000000000000000000')
193213

194-
# An authenticated call using an API Key
195-
cf = CloudFlare.CloudFlare(email='user@example.com', token='00000000000000000000000000000000')
214+
# An authenticated call using an API Email and API Key
215+
cf = CloudFlare.CloudFlare(email='user@example.com', key='00000000000000000000000000000000')
196216

197-
# An authenticated call using an API Key and CA-Origin info
198-
cf = CloudFlare.CloudFlare(email='user@example.com', token='00000000000000000000000000000000', certtoken='v1.0-...')
217+
# An authenticated call using an API Token and CA-Origin info
218+
cf = CloudFlare.CloudFlare(token='00000000000000000000000000000000', certtoken='v1.0-...')
219+
220+
# An authenticated call using an API Email, API Key, and CA-Origin info
221+
cf = CloudFlare.CloudFlare(email='user@example.com', key='00000000000000000000000000000000', certtoken='v1.0-...')
199222

200223
# An authenticated call using using a stored profile (see below)
201224
cf = CloudFlare.CloudFlare(profile="CompanyX"))
202225
```
203226

204227
If the account email and API key are not passed when you create the class, then they are retrieved from either the users exported shell environment variables or the .cloudflare.cfg or ~/.cloudflare.cfg or ~/.cloudflare/cloudflare.cfg files, in that order.
205228

206-
If you're using an API Token, any `cloudflare.cfg` file must either not contain an `email` attribute or be a zero length string and the `CLOUDFLARE_EMAIL` environment variable must be unset or be a zero length string, otherwise the token will be treated as a key and will throw an error.
229+
If you're using an API Token, any `cloudflare.cfg` file must either not contain an `email` and `key` attribute (or they can be zero length strings) and the `CLOUDFLARE_EMAIL` `CLOUDFLARE_API_KEY` environment variable must be unset (or zero length strings), otherwise the token (`CLOUDFLARE_API_TOKEN` or `token` attribute) will not be used.
207230

208231
There is one call that presently doesn't need any email or token certification (the */ips* call); hence you can test without any values saved away.
209232

210233
### Using shell environment variables
211234

212-
Note (for latest vewrsion of code):
235+
Note (for latest version of code):
213236

214237
* `CLOUDFLARE_EMAIL` has replaced `CF_API_EMAIL`.
215238
* `CLOUDFLARE_API_KEY` has replaced `CF_API_KEY`.
239+
* `CLOUDFLARE_API_TOKEN` has replaced `CF_API_TOKEN`.
216240
* `CLOUDFLARE_API_CERTKEY` has replaced `CF_API_CERTKEY`.
217241

218242
Additionally, these two variables are available for testing purposes:
@@ -223,12 +247,19 @@ Additionally, these two variables are available for testing purposes:
223247
The older environment variable names can still be used.
224248

225249
```bash
226-
$ export CLOUDFLARE_EMAIL='user@example.com' # Do not set if using an API Token
250+
$ export CLOUDFLARE_EMAIL='user@example.com'
227251
$ export CLOUDFLARE_API_KEY='00000000000000000000000000000000'
228252
$ export CLOUDFLARE_API_CERTKEY='v1.0-...'
229253
$
230254
```
231255

256+
Or if using API Token.
257+
258+
```bash
259+
$ export CLOUDFLARE_API_TOKEN='00000000000000000000000000000000'
260+
$ export CLOUDFLARE_API_CERTKEY='v1.0-...'
261+
$
262+
```
232263
These are optional environment variables; however, they do override the values set within a configuration file.
233264

234265
### Using configuration file to store email and keys
@@ -239,22 +270,22 @@ The default profile name is `Cloudflare` for obvious reasons.
239270
$ cat ~/.cloudflare/cloudflare.cfg
240271
[Cloudflare]
241272
email = user@example.com # Do not set if using an API Token
242-
token = 00000000000000000000000000000000
273+
key = 00000000000000000000000000000000
243274
certtoken = v1.0-...
244275
extras =
245276
$
246277
```
247278

248279
More than one profile can be stored within that file.
249-
Here's an example for a work and home setup (in this example work has an API Token and home uses email/token).
280+
Here's an example for a work and home setup (in this example work has an API Token and home uses email/key).
250281

251282
```bash
252283
$ cat ~/.cloudflare/cloudflare.cfg
253284
[Work]
254285
token = 00000000000000000000000000000000
255286
[Home]
256287
email = home@example.com
257-
token = 00000000000000000000000000000000
288+
key = 00000000000000000000000000000000
258289
$
259290
```
260291

README.rst

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,35 @@ A more complex example follows.
175175
Providing Cloudflare Username and API Key
176176
-----------------------------------------
177177

178-
When you create a **CloudFlare** class you can pass up to four parameters.
178+
When you create a **CloudFlare** class you can pass some combination of these four core parameters.
179179

180-
- API Token or API Key
181-
- Account email (only if an API Key is being used)
182-
- Optional Origin-CA Certificate Token
183-
- Optional Debug flag (True/False)
184-
- Optional Profile name (the default is ``Cloudflare``)
180+
- ``email`` - The account email (only if an API Key is being used)
181+
- ``api`` - The API Key (if coding prior to Issue-114 being merged)
182+
- ``token`` - The API Token (if coding after to Issue-114)
183+
- ``certtoken`` - Optional Origin-CA Certificate Token
184+
185+
This parameter controls how the data is returned from a successful call (see notes below).
186+
187+
- \`raw - An optional Raw flag (True/False) - defaults to False
188+
189+
The following paramaters are for debug and/or development usage
190+
191+
- ``debug`` - An optional Debug flag (True/False) - defaults to False
192+
- ``use_sessions`` - An optional Use-Sessions flag (True/False) - defaults to True
193+
- ``profile`` - An optional Profile name (the default is ``Cloudflare``)
194+
- ``base_url`` - An optional Base URL (only used for development)
195+
196+
email=None, key=None, token=None, certtoken=None, debug=False, raw=False, use_sessions=True, profile=None, base_url=None):
197+
198+
Issue-114
199+
~~~~~~~~~
200+
201+
After `Issue-114 <https://github.com/cloudflare/python-cloudflare/issues/114>`__ was coded and merged, the use of ``token`` and ``key`` changed; however, is backward compatible (amazingly!).
202+
203+
If you are using only the API Token, then don’t include the API Email. If you are coding prior to Issue-114, then the API Key can also be used as an API Token if the API Email is not used.
204+
205+
Python code to create class
206+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
185207

186208
.. code:: python
187209
@@ -196,28 +218,32 @@ When you create a **CloudFlare** class you can pass up to four parameters.
196218
# An authenticated call using an API Token (note the missing email)
197219
cf = CloudFlare.CloudFlare(token='00000000000000000000000000000000')
198220
199-
# An authenticated call using an API Key
200-
cf = CloudFlare.CloudFlare(email='user@example.com', token='00000000000000000000000000000000')
221+
# An authenticated call using an API Email and API Key
222+
cf = CloudFlare.CloudFlare(email='user@example.com', key='00000000000000000000000000000000')
201223
202-
# An authenticated call using an API Key and CA-Origin info
203-
cf = CloudFlare.CloudFlare(email='user@example.com', token='00000000000000000000000000000000', certtoken='v1.0-...')
224+
# An authenticated call using an API Token and CA-Origin info
225+
cf = CloudFlare.CloudFlare(token='00000000000000000000000000000000', certtoken='v1.0-...')
226+
227+
# An authenticated call using an API Email, API Key, and CA-Origin info
228+
cf = CloudFlare.CloudFlare(email='user@example.com', key='00000000000000000000000000000000', certtoken='v1.0-...')
204229
205230
# An authenticated call using using a stored profile (see below)
206231
cf = CloudFlare.CloudFlare(profile="CompanyX"))
207232
208233
If the account email and API key are not passed when you create the class, then they are retrieved from either the users exported shell environment variables or the .cloudflare.cfg or ~/.cloudflare.cfg or ~/.cloudflare/cloudflare.cfg files, in that order.
209234

210-
If you’re using an API Token, any ``cloudflare.cfg`` file must either not contain an ``email`` attribute or be a zero length string and the ``CLOUDFLARE_EMAIL`` environment variable must be unset or be a zero length string, otherwise the token will be treated as a key and will throw an error.
235+
If you’re using an API Token, any ``cloudflare.cfg`` file must either not contain an ``email`` and ``key`` attribute (or they can be zero length strings) and the ``CLOUDFLARE_EMAIL`` ``CLOUDFLARE_API_KEY`` environment variable must be unset (or zero length strings), otherwise the token (``CLOUDFLARE_API_TOKEN`` or ``token`` attribute) will not be used.
211236

212237
There is one call that presently doesn’t need any email or token certification (the */ips* call); hence you can test without any values saved away.
213238

214239
Using shell environment variables
215240
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216241

217-
Note (for latest vewrsion of code):
242+
Note (for latest version of code):
218243

219244
- ``CLOUDFLARE_EMAIL`` has replaced ``CF_API_EMAIL``.
220245
- ``CLOUDFLARE_API_KEY`` has replaced ``CF_API_KEY``.
246+
- ``CLOUDFLARE_API_TOKEN`` has replaced ``CF_API_TOKEN``.
221247
- ``CLOUDFLARE_API_CERTKEY`` has replaced ``CF_API_CERTKEY``.
222248

223249
Additionally, these two variables are available for testing purposes:
@@ -229,11 +255,19 @@ The older environment variable names can still be used.
229255

230256
.. code:: bash
231257
232-
$ export CLOUDFLARE_EMAIL='user@example.com' # Do not set if using an API Token
258+
$ export CLOUDFLARE_EMAIL='user@example.com'
233259
$ export CLOUDFLARE_API_KEY='00000000000000000000000000000000'
234260
$ export CLOUDFLARE_API_CERTKEY='v1.0-...'
235261
$
236262
263+
Or if using API Token.
264+
265+
.. code:: bash
266+
267+
$ export CLOUDFLARE_API_TOKEN='00000000000000000000000000000000'
268+
$ export CLOUDFLARE_API_CERTKEY='v1.0-...'
269+
$
270+
237271
These are optional environment variables; however, they do override the values set within a configuration file.
238272

239273
Using configuration file to store email and keys
@@ -246,12 +280,12 @@ The default profile name is ``Cloudflare`` for obvious reasons.
246280
$ cat ~/.cloudflare/cloudflare.cfg
247281
[Cloudflare]
248282
email = user@example.com # Do not set if using an API Token
249-
token = 00000000000000000000000000000000
283+
key = 00000000000000000000000000000000
250284
certtoken = v1.0-...
251285
extras =
252286
$
253287
254-
More than one profile can be stored within that file. Here’s an example for a work and home setup (in this example work has an API Token and home uses email/token).
288+
More than one profile can be stored within that file. Here’s an example for a work and home setup (in this example work has an API Token and home uses email/key).
255289

256290
.. code:: bash
257291
@@ -260,7 +294,7 @@ More than one profile can be stored within that file. Here’s an example for a
260294
token = 00000000000000000000000000000000
261295
[Home]
262296
email = home@example.com
263-
token = 00000000000000000000000000000000
297+
key = 00000000000000000000000000000000
264298
$
265299
266300
To select a profile, use the ``--profile profile-name`` option for ``cli4`` command or use ``profile="profile-name"`` in the library call.

0 commit comments

Comments
 (0)