Skip to content

Commit

Permalink
Merge pull request #27 from caskdata/feature/easier_install
Browse files Browse the repository at this point in the history
fix tests + easier install
  • Loading branch information
anwar6953 committed Sep 26, 2014
2 parents d9fe897 + 5288f10 commit 276e595
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.jar
*.war
*.ear
*.pyc

# Intellij Files & Dir #
*.iml
Expand All @@ -25,4 +26,5 @@ target/
logs/

# Examples Stuff
dependency-reduced-pom.xml
dependency-reduced-pom.xml

10 changes: 8 additions & 2 deletions cdap-authentication-clients/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ external Python applications.
- LDAP
- JAASPI

## Installation
To install CDAP Authentication Client, run:
```
$ python setup.py install
```

## Usage

To use the Authentication Client Python API, include these imports in your Python script:

```
from Config import Config
from BasicAuthenticationClient import BasicAuthenticationClient
from cdap_auth_client import Config
from cdap_auth_client import BasicAuthenticationClient
```

## Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AbstractAuthenticationClient(AuthenticationClient):
ACCESS_TOKEN_KEY = u"access_token"
AUTH_URI_KEY = u"auth_uri"
AUTHENTICATION_HEADER_PREFIX_BASIC = u"Basic "
GATEWAY_VERSION = u'/v2'
HTTP_PROTOCOL = u"http"
HTTPS_PROTOCOL = u"https"
EXPIRES_IN_KEY = u"expires_in"
Expand Down Expand Up @@ -81,9 +82,9 @@ def fetch_auth_url(self):
raise ValueError(u"Base authentication"
u" client is not configured!")
LOG.debug(u"Try to get the authentication URI from "
u"the gateway server: {}.", self.__base_url)
u"the gateway server: {}.", self.__base_url + GATEWAY_VERSION + '/ping')

response = requests.get(self.__base_url,
response = requests.get(self.__base_url + GATEWAY_VERSION + '/ping',
verify=self.ssl_verification_status())
result = None
if response.status_code == hl.UNAUTHORIZED:
Expand Down
4 changes: 3 additions & 1 deletion cdap-authentication-clients/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
description='Authentication client for Cask Data Application Platform',
author='Cask Data',
author_email='cask-dev@googlegroups.com',
install_requires=["six"],
packages=find_packages(),
)
)

Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import sys
import inspect

currentdir = os.path.dirname(
current_dir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)
parent_dir = os.path.dirname(current_dir)
src_dir = parent_dir + '/cdap_auth_client'
sys.path.insert(0, src_dir)

from AuthDisabledHandler import AuthDisabledHandler
from EmptyUrlListHandler import EmptyUrlListHandler
Expand All @@ -46,11 +47,9 @@
class BasicAuthenticationClientTest(unittest.TestCase):

def setUp(self):

self.__authentication_client = BasicAuthenticationClient()
self.__local_test_server = SimpleTCPServer(
(u"localhost", TestConstants.SERVER_PORT), AuthenticationHandler)
self.__local_test_server.allow_reuse_address = True
self.__server_thread = threading.\
Thread(target=self.__local_test_server.serve_forever)
self.__server_thread.start()
Expand All @@ -71,12 +70,12 @@ def setUp(self):
.start()

def tearDown(self):
self.__local_test_server.server_close()
self.__local_test_server.shutdown()
self.empty_response_server.server_close()
self.__local_test_server.server_close()
self.empty_response_server.shutdown()
self.auth_disabled_server.server_close()
self.empty_response_server.server_close()
self.auth_disabled_server.shutdown()
self.auth_disabled_server.server_close()

def test_auth_is_auth_enabled(self):
config = Config().read_from_file(u"auth_config.json")
Expand All @@ -92,7 +91,6 @@ def test_success_get_access_token(self):
self.assertEqual(TestConstants.TOKEN_TYPE, access_token.token_type)
self.assertEqual(TestConstants.TOKEN_LIFE_TIME,
access_token.expires_in)
self.__local_test_server.server_close()

def test_not_authorization_get_access_token(self):
self.__authentication_client.username = u"fail"
Expand Down

0 comments on commit 276e595

Please sign in to comment.