Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Experimental #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/keycloak-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Python KeyCloakClient Tests

on:
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.5', '3.6', '3.7' ]
name: Python ${{ matrix.python-version }} tests
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U pipenv
pipenv install --dev
- name: Flake8
run: |
pipenv run flake8 src/keycloak tests/keycloak
- name: Test with pytest
run: |
pipenv run pytest
18 changes: 2 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ matrix:
fast_finish: true

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

before_install:
Expand All @@ -23,7 +22,7 @@ before_install:
install:
- pip install -e .

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

script:
- flake8 src/keycloak tests/keycloak $FLAKE_OPTS
Expand All @@ -32,16 +31,3 @@ script:
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
9 changes: 6 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "*"
pylint = "*"
mock = "*"
pytest = "*"
Sphinx = "*"
sphinx-autobuild = "*"

[packages]
requests = "*"
python-jose = "*"
mock = "*"


[requires]
python_version = "3.7"
python_version = "3"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,8 @@ def __init__(self, realm_name, client_id, role_name, client):
self._realm_name = realm_name
self._role_name = role_name

super(ClientRole, self).__init__(url=self.get_path("single", realm=realm_name, id=client_id, role_name=role_name),
super(ClientRole, self).__init__(url=self.get_path("single",
realm=realm_name,
id=client_id,
role_name=role_name),
client=client)
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/keycloak/admin/realm.py → keycloak/admin/realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ def users(self):
def groups(self):
from keycloak.admin.groups import Groups
return Groups(realm_name=self._name, client=self._client)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 5 additions & 21 deletions src/keycloak/client.py → keycloak/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

from keycloak.exceptions import KeycloakClientError

try:
from urllib.parse import urljoin # noqa: F401
except ImportError:
from urlparse import urljoin # noqa: F401
from urllib.parse import urljoin

import requests

Expand All @@ -17,12 +14,11 @@ class KeycloakClient(object):
_session = None
_headers = None

def __init__(self, server_url, headers=None, logger=None):
def __init__(self, server_url, session=None, logger=None):
"""
:param str server_url: The base URL where the Keycloak server can be
:param str server_url: The base URL where the Keycloak server can be
found
:param dict headers: Optional extra headers to send with requests to
the server
:param requests.Session session: Custom requests session to use
:param logging.Logger logger: Optional logger for client
"""
if logger is None:
Expand All @@ -35,7 +31,7 @@ def __init__(self, server_url, headers=None, logger=None):

self.logger = logger
self._server_url = server_url
self._headers = headers or {}
self._session = session

@property
def server_url(self):
Expand All @@ -52,7 +48,6 @@ def session(self):
"""
if self._session is None:
self._session = requests.Session()
self._session.headers.update(self._headers)
return self._session

def get_full_url(self, path, server_url=None):
Expand Down Expand Up @@ -92,14 +87,3 @@ def _handle_response(self, response):
return response.json()
except ValueError:
return response.content

def close(self):
if self._session is not None:
self._session.close()
self._session = None

def __enter__(self):
return self

def __exit__(self, *args):
self.close()
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions src/keycloak/openid_connect.py → keycloak/openid_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,23 @@ def authorization_code(self, code, redirect_uri):
:return: Access token response
"""
token = self._token_request(grant_type='authorization_code', code=code,
redirect_uri=redirect_uri)
redirect_uri=redirect_uri)
return Token(token, self)

def password_credentials(self, username, password, **kwargs):
"""
Retrieve access token by 'password credentials' grant.

https://tools.ietf.org/html/rfc6749#section-4.3

continuation
:param str username: The user name to obtain an access token for
:param str password: The user's password
:rtype: dict
:return: Access token response
"""
token = self._token_request(grant_type='password',
username=username, password=password,
**kwargs)
username=username, password=password,
**kwargs)
return Token(token, self)

def client_credentials(self, **kwargs):
Expand Down Expand Up @@ -316,4 +316,3 @@ def is_expired(self):
return False
except ExpiredSignatureError:
return True

9 changes: 4 additions & 5 deletions src/keycloak/realm.py → keycloak/realm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ class KeycloakRealm(object):
_headers = None
_client = None

def __init__(self, server_url, realm_name, headers=None):
def __init__(self, server_url, realm_name, session=None):
"""
:param str server_url: The base URL where the Keycloak server can be
found
:param str realm_name: REALM name
:param dict headers: Optional extra headers to send with requests to
the server
:param requests.Sessionpipe session: Optional requests session to use
"""
self._server_url = server_url
self._realm_name = realm_name
self._headers = headers
self._session = session

@property
def client(self):
Expand All @@ -33,7 +32,7 @@ def client(self):
"""
if self._client is None:
self._client = KeycloakClient(server_url=self._server_url,
headers=self._headers)
session=self._session)
return self._client

@property
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ values =
[aliases]
test = pytest

[flake8]
max-line-length = 119
20 changes: 3 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
import os
import sys

from setuptools import find_packages, setup

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

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', EXCLUDED_PACKAGES),
packages=find_packages(exclude=("tests", "docs")),
extras_require={
'dev': [
'bumpversion==0.5.3',
Expand All @@ -41,12 +30,9 @@
'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>=4.0,<5'
'pytest-runner>=4.0'
],
install_requires=[
'requests',
Expand Down
Empty file.
28 changes: 0 additions & 28 deletions src/keycloak/aio/__init__.py

This file was deleted.

28 changes: 0 additions & 28 deletions src/keycloak/aio/abc.py

This file was deleted.

Loading