Skip to content

Commit

Permalink
Merge pull request #7 from nkoshell/master
Browse files Browse the repository at this point in the history
Added async client based on aiohttp
  • Loading branch information
Peter Slump committed Nov 27, 2018
2 parents 09253e0 + 14e3f1b commit f76b6fe
Show file tree
Hide file tree
Showing 46 changed files with 2,150 additions and 101 deletions.
40 changes: 35 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
git:
depth: false

sudo: false

language: python

matrix:
fast_finish: true

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "nightly"

before_install:
- pip install -U pip
- pip install -U wheel setuptools flake8
- pip install codecov
- pip install -U wheel setuptools
- pip install flake8 codecov

install:
- python setup.py -q install
- pip install -e .

env: TEST_OPTS="--cov=keycloak --ignore=tests/keycloak/aio" FLAKE_OPTS="--exclude=src/keycloak/aio,tests/keycloak/aio"

script:
- flake8 ./src ./tests
- python setup.py test --addopts "--cov=keycloak"
- flake8 src/keycloak tests/keycloak $FLAKE_OPTS
- python setup.py test --addopts "$TEST_OPTS"

after_success:
- codecov

.mixins:
- &aio-mixin
env: TEST_OPTS="--cov=keycloak" FLAKE_OPTS=""
install: pip install -e .[aio]

jobs:
include:
- python: "3.5"
<<: *aio-mixin
- python: "3.6"
<<: *aio-mixin
- python: "nightly"
<<: *aio-mixin
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
install-python:
install-python[%]:
pip install --upgrade setuptools
pip install -e .
pip install "file://`pwd`#egg=python-keycloak-client[dev,doc]"
pip install "file://`pwd`#egg=python-keycloak-client[$*]"

install-python: install-python[dev,doc]

bump-patch:
bumpversion patch
Expand All @@ -14,4 +16,4 @@ deploy-pypi: clear
twine upload dist/*

clear:
rm -rf dist/*
rm -rf dist/*
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Python Keycloak Client
======================

.. image:: https://www.travis-ci.org/Peter-Slump/python-keycloak-client.svg?branch=master
:target: https://www.travis-ci.org/Peter-Slump/python-keycloak-client
.. image:: https://travis-ci.org/Peter-Slump/python-keycloak-client.svg?branch=master
:target: https://travis-ci.org/Peter-Slump/python-keycloak-client
:alt: Build Status
.. image:: https://readthedocs.org/projects/python-keycloak-client/badge/?version=latest
:target: http://python-keycloak-client.readthedocs.io/en/latest/?badge=latest
Expand Down
148 changes: 144 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. Python Keycloak Client documentation master file, created by
sphinx-quickstart on Wed Feb 21 19:29:55 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
sphinx-quickstart on Wed Feb 21 19:29:55 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

==================================================
Welcome to Python Keycloak Client's documentation!
Expand All @@ -21,6 +21,15 @@ Installation
$ pip install python-keycloak-client
-----
Async
-----

.. code-block:: bash
$ pip install python-keycloak-client[aio]
Preparation
===========

Expand All @@ -41,6 +50,32 @@ Everything starts with an instance of :class:`keycloak.realm.KeycloakRealm`
realm = KeycloakRealm(server_url='https://example.com', realm_name='my_realm')
Async
-----

.. code-block:: python3
from keycloak.aio.realm import KeycloakRealm
async def main(loop=None):
realm_params = dict(
server_url='https://example.com',
realm_name='my_realm',
loop=loop
)
async with KeycloakRealm(**realm_params) as realm:
# do something
print(realm.realm_name)
if __name__ == '__main__':
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
--------------
OpenID Connect
--------------
Expand All @@ -58,6 +93,35 @@ The OpenID Connect entry point can be retrieved from the realm object.
client_secret='very-secret-client-secret')
Async
-----

.. code-block:: python3
from keycloak.aio.realm import KeycloakRealm
async def main(loop=None):
realm_params = dict(
server_url='https://example.com',
realm_name='my_realm',
loop=loop
)
async with KeycloakRealm(**realm_params) as realm:
oidc_client = await realm.open_id_connect(
client_id='my-client',
client_secret='very-secret-client-secret'
)
# do something
if __name__ == '__main__':
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
.. automethod:: keycloak.openid_connect.KeycloakOpenidConnect.decode_token

.. automethod:: keycloak.openid_connect.KeycloakOpenidConnect.authorization_url
Expand Down Expand Up @@ -92,6 +156,31 @@ The Authz client can be retrieved from the realm object.
authz_client = realm.authz(client_id='my-client')
Async
-----

.. code-block:: python3
from keycloak.aio.realm import KeycloakRealm
async def main(loop=None):
realm_params = dict(
server_url='https://example.com',
realm_name='my_realm',
loop=loop
)
async with KeycloakRealm(**realm_params) as realm:
authz_client = await realm.authz(client_id='my-client')
# do something
if __name__ == '__main__':
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
.. automethod:: keycloak.authz.KeycloakAuthz.entitlement

---------
Expand All @@ -104,7 +193,7 @@ http://www.keycloak.org/docs-api/3.4/rest-api/index.html

The admin API client get be retrieved from the realm object.

.. code-block:: python
.. code-block:: python3
from keycloak.realm import KeycloakRealm
Expand All @@ -113,6 +202,32 @@ The admin API client get be retrieved from the realm object.
admin_client = realm.admin
Async
-----

.. code-block:: python3
from keycloak.aio.realm import KeycloakRealm
async def main(loop=None):
realm_params = dict(
server_url='https://example.com',
realm_name='my_realm',
loop=loop
)
async with KeycloakRealm(**realm_params) as realm:
admin_client = realm.admin
# do something
if __name__ == '__main__':
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
Realms
------

Expand Down Expand Up @@ -190,6 +305,31 @@ http://www.keycloak.org/docs/latest/authorization_services/index.html#_service_o
uma_client = realm.uma()
Async
-----

.. code-block:: python3
from keycloak.aio.realm import KeycloakRealm
async def main(loop=None):
realm_params = dict(
server_url='https://example.com',
realm_name='my_realm',
loop=loop
)
async with KeycloakRealm(**realm_params) as realm:
uma_client = realm.uma()
# do something
if __name__ == '__main__':
import asyncio
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
Resource Set management
-----------------------
Expand Down
32 changes: 24 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
import os
import sys

from setuptools import setup, find_packages
from setuptools import find_packages, setup

VERSION = '0.1.5-dev'
AIO_COMPATIBLE = sys.version_info >= (3, 5, 3)

with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

EXCLUDED_PACKAGES = []
TESTS_REQUIRE = [
'pytest',
'pytest-cov',
'mock>=2.0',
]

if AIO_COMPATIBLE:
TESTS_REQUIRE += [
'asynctest',
]
else:
EXCLUDED_PACKAGES.append('keycloak.aio')

setup(
name='python-keycloak-client',
version=VERSION,
long_description=README,
package_dir={'': 'src'},
packages=find_packages('src'),
packages=find_packages('src', EXCLUDED_PACKAGES),
extras_require={
'dev': [
'bumpversion==0.5.3',
],
'doc': [
'Sphinx==1.4.4',
'sphinx-autobuild==0.6.0',
],
'aio': [
'aiohttp>=3.4.4,<4; python_full_version>="3.5.3"'
]
},
setup_requires=[
'pytest-runner'
'pytest-runner>=4.0,<5'
],
install_requires=[
'requests',
'python-jose'
],
tests_require=[
'pytest-cov',
'mock>=2.0',
'python-jose',
],
tests_require=TESTS_REQUIRE,
url='https://github.com/Peter-Slump/python-keycloak-client',
license='MIT',
author='Peter Slump',
Expand Down
Empty file added src/__init__.py
Empty file.
9 changes: 7 additions & 2 deletions src/keycloak/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class KeycloakAdminBase(object):
__all__ = (
'KeycloakAdmin',
'KeycloakAdminBase',
)


class KeycloakAdminBase(object):
_client = None
_paths = None

Expand All @@ -17,7 +22,6 @@ def get_path(self, name, **kwargs):


class KeycloakAdmin(object):

_realm = None
_paths = {
'root': '/'
Expand Down Expand Up @@ -68,6 +72,7 @@ def get(self, url, headers=None, **kwargs):
return self._realm.client.get(
url=url, headers=self._add_auth_header(headers=headers)
)

#
# def delete(self, url, headers, **kwargs):
# return self.session.delete(url, headers=headers, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/keycloak/admin/clients.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from keycloak.admin import KeycloakAdminBase

__all__ = ('Client', 'Clients',)

class Clients(KeycloakAdminBase):

class Clients(KeycloakAdminBase):
_realm_name = None
_paths = {
'collection': '/auth/admin/realms/{realm}/clients'
Expand All @@ -24,7 +25,6 @@ def by_id(self, id):


class Client(KeycloakAdminBase):

_id = None
_realm_name = None

Expand Down

0 comments on commit f76b6fe

Please sign in to comment.