Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 4a898ca

Browse files
committed
merge from main
2 parents b1f23e6 + 5c19744 commit 4a898ca

File tree

72 files changed

+4000
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4000
-379
lines changed

.github/workflows/constraints.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pip==21.2.4
2-
nox==2021.6.12
1+
pip==21.3.1
2+
nox==2021.10.1
33
nox-poetry==0.8.6
4-
poetry==1.1.8
5-
virtualenv==20.7.2
4+
virtualenv==20.9.0
5+
poetry==1.1.11

.github/workflows/test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,53 @@ jobs:
7373
- name: Run Nox
7474
run: |
7575
nox --force-color --python=${{ matrix.python-version }}
76+
77+
- name: Upload coverage data
78+
if: always() && matrix.session == 'tests'
79+
uses: "actions/[email protected]"
80+
with:
81+
name: coverage-data
82+
path: ".coverage.*"
83+
84+
coverage:
85+
runs-on: ubuntu-latest
86+
needs: tests
87+
steps:
88+
- name: Check out the repository
89+
uses: actions/[email protected]
90+
91+
- name: Set up Python 3.9
92+
uses: actions/[email protected]
93+
with:
94+
python-version: 3.9
95+
96+
- name: Upgrade pip
97+
run: |
98+
pip install --constraint=.github/workflows/constraints.txt pip
99+
pip --version
100+
101+
- name: Install Poetry
102+
run: |
103+
pip install --constraint=.github/workflows/constraints.txt poetry
104+
poetry --version
105+
106+
- name: Install Nox
107+
run: |
108+
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
109+
nox --version
110+
111+
- name: Download coverage data
112+
uses: actions/[email protected]
113+
with:
114+
name: coverage-data
115+
116+
- name: Combine coverage data and display human readable report
117+
run: |
118+
nox --force-color --session=coverage
119+
120+
- name: Create coverage report
121+
run: |
122+
nox --force-color --session=coverage -- xml
123+
124+
- name: Upload coverage report
125+
uses: codecov/[email protected]

.gitignore

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ cover/
5353
*.mo
5454
*.pot
5555

56-
# pipenv
57-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
58-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
59-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
60-
# install all needed dependencies.
61-
#Pipfile.lock
62-
6356
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
6457
__pypackages__/
6558

@@ -75,7 +68,7 @@ __pypackages__/
7568
dmypy.json
7669

7770
# vscode
78-
vscode/
71+
.vscode/
7972
.vscode/settings.json
8073
.vscode/launch.json
8174

CONTRIBUTING.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ welcomes contributions in the form of bug reports, feature requests, and pull re
88
Here is a list of important resources for contributors:
99

1010
- `Source Code`_
11-
- `Documentation`_
1211
- `Issue Tracker`_
1312
- `Code of Conduct`_
1413

@@ -57,11 +56,6 @@ Install the package with development requirements:
5756
You can now run an interactive Python session,
5857
or the command-line interface:
5958

60-
.. code:: console
61-
62-
$ poetry run python
63-
$ poetry run aiocloudflare
64-
6559
.. _Poetry: https://python-poetry.org/
6660
.. _Nox: https://nox.thea.codes/
6761
.. _nox-poetry: https://nox-poetry.readthedocs.io/

README.rst

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ aioCloudflare
77

88
|pre-commit| |Black|
99

10+
|Downloads|
11+
1012
.. |PyPI| image:: https://img.shields.io/pypi/v/aiocloudflare.svg
1113
:target: https://pypi.org/project/aiocloudflare/
1214
:alt: PyPI
@@ -31,12 +33,15 @@ aioCloudflare
3133
.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
3234
:target: https://github.com/psf/black
3335
:alt: Black
36+
.. |Downloads| image:: https://static.pepy.tech/badge/aiocloudflare
37+
:target: https://pepy.tech/project/aiocloudflare
38+
:alt: Downloads
3439

35-
Inspired by the offical `python-cloudflare` library developed by `Cloudflare`_. This project is created to be competible to use with `asyncio` for non-blocking IO.
40+
Inspired by the offical ``python-cloudflare`` library developed by `Cloudflare`_. This project is created to be compatible with ``asyncio`` for non-blocking IO.
3641

37-
For sync code, it is recommanded to use `python-cloudflare` via `pip install python-cloudflare` as it is used by hundreds and offically maintained by cloudflare. This ensure that APIs are always updated according to Cloudflare API release.
42+
For sync code, it is recommanded to use ``python-cloudflare`` via ``pip install python-cloudflare`` as it is used by hundreds and offically maintained by Cloudflare. This ensure that APIs are always updated according to Cloudflare API release.
3843

39-
*NOTE:* This library is in Pre-Alpha, this means things might break. Do not use it in Production unless you have tested on the API route specific to your use case and that would be at your own risk.
44+
*NOTE:* This library is in Beta, this means fixes and updates are still going on every second. Do not use it in Production unless you have tested on the API route specific to your use case and that would be at your own risk.
4045

4146
Having said that, do submit an issue if you encounter any bug so we can move away from the Alpha stage sooner.
4247

@@ -47,6 +52,15 @@ Features
4752
* Autocompletion on IDE.
4853
* Fully type hinted.
4954

55+
Feature Roadmap
56+
---------------
57+
58+
* to support cert token
59+
* to support sync API client
60+
61+
These are some alternative use cases that are not in the top of my priority now as I have not received
62+
any request for. If you are interested, you may want to submit a pull request to contribute some of these features.
63+
5064

5165
Requirements
5266
------------
@@ -73,19 +87,82 @@ Usage
7387
7488
async def get_zone():
7589
async with Cloudflare() as cf:
76-
result = await cf.zones.get()
90+
response = await cf.zones.get()
91+
92+
Unlike the offical ``python-cloudflare`` library, ``aiocloudflare`` does not parse and handle http responses.
93+
94+
So the awaited response object will have to be handled just as any http request, response pattern. the ``Response`` object is the same as ``httpx``'s ``Response``.
95+
96+
.. code:: Python
97+
98+
from aiocloudflare import Cloudflare
99+
100+
async def get_zone():
101+
async with Cloudflare() as cf:
102+
response = await cf.zones.get()
103+
104+
# check status code
105+
if response.status_code == 200:
106+
107+
# get json data
108+
resp_json = response.json()
109+
110+
# Cloudflare API typically store results in a ``result`` key.
111+
return resp_json["result"]
77112
78-
Full configuration can be done using `Config()` class.
113+
else:
114+
# to get texture data from response
115+
print(response.text)
116+
117+
118+
Full configuration can be done using ``Config()`` class.
79119

80120
.. code:: Python
81121
82122
from aioCloudflare import Cloudflare, Config
83123
84-
config = Config(email="[email protected]", token="<secret>")
124+
config = Config(email="[email protected]", token="<secret>") # for demo only, do not hardcode secrets
85125
async def get_zone():
86126
async with Cloudflare(config=config) as cf:
87127
result = await cf.zones.get()
88128
129+
Configuration can also be stored in a ``.env`` file for a "global" configuration without needing to create a ``Config()`` class. Keys available are:
130+
131+
.. code:: console
132+
133+
CF_API_EMAIL=""
134+
CF_API_KEY=""
135+
CF_API_CERTKEY=""
136+
CF_API_URL=""
137+
DEBUG=false
138+
CF_PROFILE=""
139+
USER_AGENT=""
140+
141+
Advance Usage
142+
_____________
143+
144+
You may wish to wrap ``Cloudflare()`` into you own class for customised settings or requirements. To do that, just provide a ``__aenter__()`` and ``__aexit__()`` method to your class like so.
145+
146+
.. code:: Python
147+
148+
class MyCfClient:
149+
def __init__(self):
150+
self._config = Config(email="[email protected]", token="<secret>") # for demo only, do not hardcode secrets
151+
152+
async def __aenter__(self):
153+
self._client = Cloudflare(config=self._config)
154+
return self
155+
156+
async def __aexit__(self, exc_type, exc_value, traceback):
157+
await self._client.aclose()
158+
159+
Then you can call your own class with async context manager.
160+
161+
.. code:: Python
162+
163+
async with MyCfClient() as own_class:
164+
await own_class.zones.get()
165+
89166
90167
Contributing
91168
------------
@@ -98,7 +175,7 @@ License
98175
-------
99176

100177
Distributed under the terms of the `MIT license`_,
101-
*Hello World* is free and open source software.
178+
*aioCloudflare* is free and open source software.
102179

103180

104181
Issues
@@ -112,6 +189,6 @@ please `file an issue`_ along with a detailed description.
112189
.. _PyPI: https://pypi.org/
113190
.. _file an issue: https://github.com/stewart86/aiocloudflare/issues
114191
.. _pip: https://pip.pypa.io/
192+
.. _Cloudflare: https://github.com/cloudflare/python-cloudflare
115193
.. github-only
116194
.. _Contributor Guide: CONTRIBUTING.rst
117-
.. _Cloudflare: https://cloudflare.com
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
from aiocloudflare.commons.unused import Unused
22

3+
from .apps.apps import Apps
4+
from .certificates.certificates import Certificates
5+
from .groups.groups import Groups
6+
from .identity_providers.identity_providers import IdentityProviders
7+
from .logs.logs import Logs
8+
from .organizations.organizations import Organizations
9+
from .service_tokens.service_tokens import ServiceTokens
10+
311

412
class Access(Unused):
513
_endpoint1 = "accounts"
614
_endpoint2 = "access"
715
_endpoint3 = None
16+
17+
@property
18+
def logs(self) -> Logs:
19+
return Logs(self._config, self._session)
20+
21+
@property
22+
def identity_providers(self) -> IdentityProviders:
23+
return IdentityProviders(self._config, self._session)
24+
25+
@property
26+
def organizations(self) -> Organizations:
27+
return Organizations(self._config, self._session)
28+
29+
@property
30+
def groups(self) -> Groups:
31+
return Groups(self._config, self._session)
32+
33+
@property
34+
def service_tokens(self) -> ServiceTokens:
35+
return ServiceTokens(self._config, self._session)
36+
37+
@property
38+
def certificates(self) -> Certificates:
39+
return Certificates(self._config, self._session)
40+
41+
@property
42+
def apps(self) -> Apps:
43+
return Apps(self._config, self._session)

aiocloudflare/api/accounts/access/apps/apps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class Apps(Auth):
1010
_endpoint2 = "access/apps"
1111
_endpoint3 = None
1212

13-
@property
14-
def ca(self) -> Ca:
15-
return Ca(self._config, self._session)
16-
1713
@property
1814
def policies(self) -> Policies:
1915
return Policies(self._config, self._session)
2016

2117
@property
2218
def revoke_tokens(self) -> RevokeTokens:
2319
return RevokeTokens(self._config, self._session)
20+
21+
@property
22+
def ca(self) -> Ca:
23+
return Ca(self._config, self._session)

0 commit comments

Comments
 (0)