Skip to content

Commit

Permalink
Add Fusillade API client (#417)
Browse files Browse the repository at this point in the history
* Adding auth to the CLI
* Adding auth to the documentation
* '.' are removed from path
* add defaults for missing swagger fields.
* description and summary required
* fixing tests
  • Loading branch information
Bento007 committed Oct 23, 2019
1 parent b7707c3 commit 22886df
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ API documentation

.. automodule:: hca.query
:members:

.. automodule:: hca.auth
:members:
:inherited-members:
2 changes: 1 addition & 1 deletion hca/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .config import HCAConfig, get_config, logger
from . import dss, upload, query
from . import dss, upload, auth, query


def clear_hca_cache(args):
Expand Down
14 changes: 14 additions & 0 deletions hca/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Authorization and Authentication system
***************************************
"""

from __future__ import absolute_import, division, print_function, unicode_literals

from ..util import SwaggerClient


class AuthClient(SwaggerClient):
"""
Client for Authentication and Authorization System.
"""
18 changes: 18 additions & 0 deletions hca/auth/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import sys

from . import AuthClient


def add_commands(subparsers, help_menu=False):
auth_parser = subparsers.add_parser('auth', help="Interact with the HCA authorization and authentication system.")

def help(args):
auth_parser.print_help()

if sys.version_info >= (2, 7, 9): # See https://bugs.python.org/issue9351
auth_parser.set_defaults(entry_point=help)
auth_subparsers = auth_parser.add_subparsers()
auth_cli_client = AuthClient()
auth_cli_client.build_argparse_subparsers(auth_subparsers, help_menu=help_menu)
2 changes: 2 additions & 0 deletions hca/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .dss import cli as dss_cli
from .upload import cli as upload_cli
from .query import cli as query_cli
from .auth import cli as auth_cli
from . import logger, get_config, clear_hca_cache


Expand Down Expand Up @@ -96,6 +97,7 @@ def help(args):
upload_cli.add_commands(parser._subparsers)
dss_cli.add_commands(parser._subparsers, help_menu=help_menu)
query_cli.add_commands(parser._subparsers, help_menu=help_menu)
auth_cli.add_commands(parser._subparsers, help_menu=help_menu)

argcomplete.autocomplete(parser)
return parser
Expand Down
3 changes: 3 additions & 0 deletions hca/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
},
"DCPQueryClient": {
"swagger_url": "https://query.data.humancellatlas.org/v1/openapi.json"
},
"AuthClient": {
"swagger_url": "https://auth.data.humancellatlas.org/swagger.json"
}
}
7 changes: 4 additions & 3 deletions hca/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ def _get_jwt_from_service_account_credentials(self):
'exp': exp,
'email': service_credentials["client_email"],
'scope': ['email', 'openid', 'offline_access'],
'https://auth.data.humancellatlas.org/group': 'hca'
'https://auth.data.humancellatlas.org/group': 'hca',
'https://auth.data.humancellatlas.org/email': service_credentials["client_email"]
}
additional_headers = {'kid': service_credentials["private_key_id"]}
signed_jwt = jwt.encode(payload, service_credentials["private_key"], headers=additional_headers,
Expand Down Expand Up @@ -529,7 +530,7 @@ def _build_client_method(self, http_method, http_path, method_data):
Parameter("client", Parameter.POSITIONAL_OR_KEYWORD)]
params += [v["param"] for k, v in method_args.items() if not k.startswith("_")]
client_method.__signature__ = signature(client_method).replace(parameters=params)
docstring = method_data["summary"] + "\n\n"
docstring = method_data.get("summary", '') + "\n\n"

if method_supports_pagination:
docstring += _pagination_docstring.format(client_name=self.__class__.__name__, method_name=method_name)
Expand All @@ -542,7 +543,7 @@ def _build_client_method(self, http_method, http_path, method_data):
param_doc = _md2rst(method_args[param]["doc"] or "")
docstring += ":param {}: {}\n".format(param, param_doc.replace("\n", " "))
docstring += ":type {}: {}\n".format(param, method_args[param]["param"].annotation)
docstring += "\n\n" + _md2rst(method_data["description"])
docstring += "\n\n" + _md2rst(method_data.get("description", ''))
client_method.__doc__ = docstring

setattr(self.__class__, method_name, types.MethodType(client_method, SwaggerClient))
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions test/integration/auth/test_auth_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# coding: utf-8
import os
import sys
import tempfile

pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')) # noqa
sys.path.insert(0, pkg_root) # noqa

import hca.auth
import unittest

TemporaryDirectory = tempfile.TemporaryDirectory


class TestDssApi(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.client = hca.auth.AuthClient(swagger_url="https://auth.dev.data.humancellatlas.org/swagger.json")

def test_smoke(self):
self.client.get_well_known_openid_configuration(host="auth.dev.data.humancellatlas.org")


if __name__ == "__main__":
unittest.main()

0 comments on commit 22886df

Please sign in to comment.