forked from cloudflare/python-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for profiles - see README
- Loading branch information
Showing
5 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,9 @@ import CloudFlare | |
|
||
# An authenticated call using an API Key and CA-Origin info | ||
cf = CloudFlare.CloudFlare(email='[email protected]', token='00000000000000000000000000000000', certtoken='v1.0-...') | ||
|
||
# An authenticated call using using a stored profile (see below) | ||
cf = CloudFlare.CloudFlare(profile="CompanyX")) | ||
``` | ||
|
||
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. | ||
|
@@ -203,6 +206,7 @@ If you're using an API Token, any `cloudflare.cfg` file must either not contain | |
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. | ||
|
||
### Using shell environment variables | ||
|
||
```bash | ||
$ export CF_API_EMAIL='[email protected]' # Do not set if using an API Token | ||
$ export CF_API_KEY='00000000000000000000000000000000' | ||
|
@@ -224,6 +228,45 @@ extras = | |
$ | ||
``` | ||
|
||
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). | ||
|
||
```bash | ||
$ cat ~/.cloudflare/cloudflare.cfg | ||
[Work] | ||
token = 00000000000000000000000000000000 | ||
[Home] | ||
email = [email protected] | ||
token = 00000000000000000000000000000000 | ||
$ | ||
``` | ||
|
||
To select a profile, use the `--profile profile-name` option for `cli4` command or use `profile="profile-name"` in the library call. | ||
|
||
```bash | ||
$ cli4 --profile Work /zones | jq '.[]|.name' | wc -l | ||
13 | ||
$ | ||
|
||
$ cli4 --profile Home /zones | jq '.[]|.name' | wc -l | ||
1 | ||
$ | ||
``` | ||
|
||
Here is the same in code. | ||
|
||
```python | ||
#!/usr/bin/env python | ||
|
||
import CloudFlare | ||
|
||
def main(): | ||
cf = CloudFlare.CloudFlare(profile="Work") | ||
... | ||
``` | ||
|
||
### About /certificates and certtoken | ||
|
||
The *CF_API_CERTKEY* or *certtoken* values are used for the Origin-CA */certificates* API calls. | ||
You can leave *certtoken* in the configuration with a blank value (or omit the option variable fully). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,9 @@ parameters. | |
# An authenticated call using an API Key and CA-Origin info | ||
cf = CloudFlare.CloudFlare(email='[email protected]', token='00000000000000000000000000000000', certtoken='v1.0-...') | ||
# An authenticated call using using a stored profile (see below) | ||
cf = CloudFlare.CloudFlare(profile="CompanyX")) | ||
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 | ||
|
@@ -261,6 +264,48 @@ Using configuration file to store email and keys | |
extras = | ||
$ | ||
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). | ||
|
||
.. code:: bash | ||
$ cat ~/.cloudflare/cloudflare.cfg | ||
[Work] | ||
token = 00000000000000000000000000000000 | ||
[Home] | ||
email = [email protected] | ||
token = 00000000000000000000000000000000 | ||
$ | ||
To select a profile, use the ``--profile profile-name`` option for | ||
``cli4`` command or use ``profile="profile-name"`` in the library call. | ||
|
||
.. code:: bash | ||
$ cli4 --profile Work /zones | jq '.[]|.name' | wc -l | ||
13 | ||
$ | ||
$ cli4 --profile Home /zones | jq '.[]|.name' | wc -l | ||
1 | ||
$ | ||
Here is the same in code. | ||
|
||
.. code:: python | ||
#!/usr/bin/env python | ||
import CloudFlare | ||
def main(): | ||
cf = CloudFlare.CloudFlare(profile="Work") | ||
... | ||
About /certificates and certtoken | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The *CF\_API\_CERTKEY* or *certtoken* values are used for the Origin-CA | ||
*/certificates* API calls. You can leave *certtoken* in the | ||
configuration with a blank value (or omit the option variable fully). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters