diff --git a/CHANGELOG.md b/CHANGELOG.md index aef2c475..45394651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [0.0.2] - 2019-05-17 + +### Changed +- Package prefix changed from `conjur_api_python3` to `conjur` +- Bundle name changed from `conjur-api-python` to `conjur-api` +- CLI renamed from `conjur-py3-cli` to `conjur-cli` + ### Added - Support for returning output from policy changes invocations +- Fatal exception is raised when this module is run on Python2 ## [0.0.1] - 2019-05-01 The first tagged version. -[Unreleased]: https://github.com/conjurinc/conjur-api-python3/compare/v0.0.1...HEAD +[Unreleased]: https://github.com/conjurinc/conjur-api-python3/compare/v0.0.2...HEAD +[0.0.2]: https://github.com/conjurinc/conjur-api-python3/compare/v0.0.1...0.0.2 diff --git a/Dockerfile.test b/Dockerfile.test index d9f086fd..2aeba3e2 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -5,6 +5,7 @@ ENV INSTALL_DIR=/opt/conjur-api-python3 RUN apk add --no-cache bash \ binutils \ build-base \ + git \ python3 \ python3-dev diff --git a/Jenkinsfile b/Jenkinsfile index 06272d06..da72a9f6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -39,6 +39,18 @@ pipeline { } } } + + // Only publish to PyPI if the HEAD is + // tagged with the same version as in __version__.py + stage('Publish to PyPI') { + steps { + sh 'summon -e production ./bin/publish' + } + + when { + branch "master" + } + } } post { diff --git a/README.md b/README.md index 32bc2acc..fa87424c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # conjur-api-python3 Python3-based API SDK for [Conjur OSS](https://www.conjur.org/). The repo -also includes a self-contained CLI tool that wraps the API in a simple executable -script/binary. +also includes a self-contained CLI tool (`conjur-cli`) that wraps the API +in a simple executable script/binary. --- @@ -30,6 +30,23 @@ you will want to use `pip3` if it's available for your platform. ## Usage +### CLI + +CLI can either be used with the included executable script: + +```shell +conjur-cli --insecure -l https://myserver -a orgname -u admin -p secret \ + variable get foo/bar +``` + +Or through the installed module: + +```shell +python -m conjur --insecure -l https://myserver -a orgname -u admin -p secret list +``` + +### API + Most usage is done by creating a Client instance and then invoking the API on it: #### With login ID and password @@ -37,7 +54,7 @@ Most usage is done by creating a Client instance and then invoking the API on it ```python3 #!/usr/bin/env python3 -from conjur_api_python3 import Client +from conjur import Client client = Client(url='https://conjur.myorg.com', account='default', diff --git a/bin/build_binary b/bin/build_binary index aeef0203..8b28a83a 100755 --- a/bin/build_binary +++ b/bin/build_binary @@ -1,6 +1,6 @@ #!/bin/bash -e -BIN_BUILD_CMD="pyinstaller --onefile pkg_bin/conjur-py3-cli" +BIN_BUILD_CMD="pyinstaller --onefile pkg_bin/conjur-cli" rm -rf dist/ diff --git a/bin/needs_publishing b/bin/needs_publishing new file mode 100755 index 00000000..73809305 --- /dev/null +++ b/bin/needs_publishing @@ -0,0 +1,47 @@ +#!/bin/bash -e + +PYPI_URL="${1-https://pypi.org}" +echo "Using $PYPI_URL as the publish endpoint" + +package_name=$(python3 ./setup.py --name) +package_name=Conjur + +echo "Determining if publishing is needed for package '$package_name'..." + +local_version=$(python3 ./setup.py --version) +echo "Local version: $local_version" + +published_version=$(curl -Ls $PYPI_URL/pypi/$package_name/json | jq -r '.info.version' || echo "") +echo "Published version on $PYPI_URL: $published_version" +if [[ "$local_version" == "$current_published_version" ]]; then + echo "WARN: Local version of $package_name ($local_version) is the same as published version ($published_version)!" + echo "WARN: Skipping publishing!" + exit 1 +fi + +echo "Published version ($published_version) does not match local version ($local_version)!" +echo "Checking current git tag to see if it matches this commit..." + +# Jenkins git plugin is broken and always fetches with `--no-tags` +# (or `--tags`, neither of which is what you want), so tags end up +# not being fetched. Try to fix that. +# (Unfortunately this fetches all remote heads, so we may have to find +# another solution for bigger repos.) +git fetch -q + +tag_commit=$(git rev-list -n 1 "v$local_version" 2>/dev/null || true) +echo "Tag v$local_version commit: '$tag_commit'" + +head_commit=$(git rev-parse HEAD) +echo "Head commit: '$head_commit'" + +if [[ "$head_commit" != "$tag_commit" ]]; then + echo "WARN: HEAD commit '$head_commit' does not match version commit '$tag_commit'!" + echo "WARN: Skipping publishing!" + exit 1 +fi + +echo "We are on a tagged commit that matches our declared version!" +echo "*** Publishing is needed! ***" + +exit 0 diff --git a/bin/publish b/bin/publish new file mode 100755 index 00000000..4fe86012 --- /dev/null +++ b/bin/publish @@ -0,0 +1,43 @@ +#!/bin/bash -e + +CURRENT_DIR=$(pwd) + +$CURRENT_DIR/bin/build_container + +REQUIRED_VARS=( "TWINE_REPOSITORY_URL" + "TWINE_USERNAME" + "TWINE_PASSWORD" ) + +# Sanity check +for required_var in "${REQUIRED_VARS[@]}"; do + if [[ "${!required_var}" == "" ]]; then + echo "ERROR: '$required_var' not set!" + exit 1 + fi +done + +rm -rf $CURRENT_DIR/dist/ +docker run --rm \ + -t \ + -e TWINE_REPOSITORY_URL \ + -e TWINE_USERNAME \ + -e TWINE_PASSWORD \ + -v "$(pwd):/opt/conjur-api-python3" \ + conjur-api-python3-test bash -exc " + echo 'Installing new versions of pip and wheel...' + /usr/bin/env pip3 install --progress-bar off --upgrade pip wheel + + if ! ./bin/needs_publishing \$TWINE_REPOSITORY_URL; then + echo 'WARN: Publishing skipped!' + exit 0 + fi + + echo 'Building distributable package...' + /usr/bin/env python3 setup.py sdist bdist_wheel + + echo 'Testing artifacts in dist/*' + /usr/bin/env twine check dist/* + + echo 'Publishing package to \$TWINE_REPOSITORY_URL using account '\$TWINE_USERNAME'...' + /usr/bin/env twine upload dist/* + " diff --git a/bin/test_linting b/bin/test_linting index 35f155ce..16f0be10 100755 --- a/bin/test_linting +++ b/bin/test_linting @@ -1,6 +1,6 @@ #!/bin/bash -e -SRC_DIRS=( "./conjur_api_python3" +SRC_DIRS=( "./conjur" "./pkg_bin" ) DISABLED_ERRORS="fixme" diff --git a/conjur/__init__.py b/conjur/__init__.py new file mode 100644 index 00000000..e14dc568 --- /dev/null +++ b/conjur/__init__.py @@ -0,0 +1,31 @@ +""" +Main module + +This metafile includes all the functionality that will be exposed +when you install this module +""" + +import sys + +if sys.version_info < (3,): + raise ImportError("""You are running Conjur Python3 APIs on Python 2 + +This package is not compatible with Python 2, and you still ended up +with this version installed which should not have happened. Make sure you +have pip >= 9.0 to avoid this kind of issue, as well as setuptools >= 24.2: + + $ pip install pip setuptools --upgrade + +Your choices: + +- Upgrade to Python 3. + +- Install an older version of Conjur APIs: + + $ pip install Conjur +""") + +#pylint: disable=wrong-import-position +from .client import Client +#pylint: disable=wrong-import-position +from .cli import Cli diff --git a/conjur_api_python3/__main__.py b/conjur/__main__.py similarity index 100% rename from conjur_api_python3/__main__.py rename to conjur/__main__.py diff --git a/conjur_api_python3/api.py b/conjur/api.py similarity index 100% rename from conjur_api_python3/api.py rename to conjur/api.py diff --git a/conjur_api_python3/cli.py b/conjur/cli.py similarity index 100% rename from conjur_api_python3/cli.py rename to conjur/cli.py diff --git a/conjur_api_python3/client.py b/conjur/client.py similarity index 100% rename from conjur_api_python3/client.py rename to conjur/client.py diff --git a/conjur_api_python3/config.py b/conjur/config.py similarity index 100% rename from conjur_api_python3/config.py rename to conjur/config.py diff --git a/conjur_api_python3/endpoints.py b/conjur/endpoints.py similarity index 100% rename from conjur_api_python3/endpoints.py rename to conjur/endpoints.py diff --git a/conjur_api_python3/http.py b/conjur/http.py similarity index 100% rename from conjur_api_python3/http.py rename to conjur/http.py diff --git a/conjur_api_python3/version.py b/conjur/version.py similarity index 100% rename from conjur_api_python3/version.py rename to conjur/version.py diff --git a/conjur_api_python3/__init__.py b/conjur_api_python3/__init__.py deleted file mode 100644 index 6829934c..00000000 --- a/conjur_api_python3/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -Main module - -This metafile includes all the functionality that will be exposed -when you install this module -""" - -from .client import Client -from .cli import Cli diff --git a/e2e/test_full_flow.py b/e2e/test_full_flow.py index f1e682f3..e214a83a 100755 --- a/e2e/test_full_flow.py +++ b/e2e/test_full_flow.py @@ -9,7 +9,7 @@ import os import time -import conjur_api_python3 as conjur +import conjur VARIABLE_PATH = 'a/ b/c' USE_CONJURRC = True diff --git a/pkg_bin/conjur-py3-cli b/pkg_bin/conjur-cli similarity index 89% rename from pkg_bin/conjur-py3-cli rename to pkg_bin/conjur-cli index 8be0b9f8..3800da6b 100755 --- a/pkg_bin/conjur-py3-cli +++ b/pkg_bin/conjur-cli @@ -13,7 +13,7 @@ sys.path.append(".") sys.path.append("..") #pylint: disable=wrong-import-position -from conjur_api_python3.cli import Cli +from conjur.cli import Cli if __name__ == '__main__': Cli.launch() diff --git a/requirements.txt b/requirements.txt index 0b692678..e6cb809a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ pylint>=2.3.1 PyInstaller>=3.4 PyYAML>=3.13 requests>=2.21.0 +twine>=1.13.0 # https://github.com/kennethreitz/requests/issues/5065 urllib3>=1.24.2,<1.25 diff --git a/secrets.yml b/secrets.yml new file mode 100644 index 00000000..a71d07e9 --- /dev/null +++ b/secrets.yml @@ -0,0 +1,11 @@ +production: + TWINE_REPOSITORY_URL: !var ecosystems/pypi/users/endpoint + TWINE_USERNAME: !var ecosystems/pypi/users/conjur/username + TWINE_PASSWORD: !var ecosystems/pypi/users/conjur/password + +# https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives +# NOTE: Sometimes, test PyPI wipes their DB so re-registration will be needed +testing: + TWINE_REPOSITORY_URL: !var ecosystems/pypi/test-users/endpoint + TWINE_USERNAME: !var ecosystems/pypi/test-users/conjur/username + TWINE_PASSWORD: !var ecosystems/pypi/test-users/conjur/password diff --git a/setup.py b/setup.py index 82adad51..6b89ecdb 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages -PACKAGE_NAME = "conjur_api_python3" +PACKAGE_NAME = "conjur" CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) VERSION_FILE = os.path.join(CURRENT_DIR, PACKAGE_NAME, "version.py") @@ -18,19 +18,24 @@ with open(VERSION_FILE, 'r') as version_fp: exec(version_fp.read(), VERSION_DATA) +long_description="" +with open('README.md', 'r') as readme_file: + long_description = readme_file.read() + setup( - name="conjur-api-python", + name="conjur-client", version=VERSION_DATA['__version__'], - packages=find_packages(), + python_requires='>=3.5', + packages=find_packages(exclude=("test")), zip_safe=True, - scripts=['pkg_bin/conjur-py3-cli'], + scripts=['pkg_bin/conjur-cli'], - entry_points = { - 'console_scripts': ['conjur-py3-cli=conjur_api_python3:Cli.launch'], + entry_points={ + 'console_scripts': ['conjur-cli=conjur:Cli.launch'], 'setuptools.installation': [ - 'eggsecutable = conjur_api_python3:Cli.launch', + 'eggsecutable = conjur:Cli.launch', ] }, @@ -48,21 +53,23 @@ author="CyberArk Software, Inc", author_email="CyberArk Maintainers ", description="APIs for interacting with the Conjur v5 appliance", + long_description=long_description, + long_description_content_type='text/markdown', license="MIT", url="https://github.com/conjurinc/conjur-api-python3", keywords=[ "conjur", "cyberark", + "microservices" + "privileged access", "security", "vault", - "privileged access", - "microservices" - ], + ], classifiers=[ "Programming Language :: Python :: 3 :: Only", - "Development Status :: 2 - Pre-Alpha", + "Development Status :: 3 - Alpha", "Intended Audience :: Developers", - "License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)", + "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Natural Language :: English", "Topic :: Office/Business", @@ -74,5 +81,5 @@ "Topic :: System :: Systems Administration", "Topic :: System :: Systems Administration :: Authentication/Directory", "Topic :: Utilities", - ], + ], ) diff --git a/test/test_api.py b/test/test_api.py index 5132959f..5f92e446 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -3,10 +3,10 @@ from datetime import datetime from unittest.mock import call, patch, MagicMock -from conjur_api_python3.http import HttpVerb -from conjur_api_python3.endpoints import ConjurEndpoint +from conjur.http import HttpVerb +from conjur.endpoints import ConjurEndpoint -from conjur_api_python3.api import Api +from conjur.api import Api MOCK_RESOURCE_LIST = [ @@ -69,7 +69,7 @@ def verify_http_call(self, http_client, method, endpoint, *args, ssl_verify=ssl_verify) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_login_invokes_http_client_correctly(self, mock_http_client): Api(url='http://localhost').login('myuser', 'mypass') self.verify_http_call(mock_http_client, HttpVerb.GET, ConjurEndpoint.LOGIN, @@ -77,7 +77,7 @@ def test_login_invokes_http_client_correctly(self, mock_http_client): api_token=False, ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_login_saves_login_id(self, _): api = Api(url='http://localhost') @@ -85,7 +85,7 @@ def test_login_saves_login_id(self, _): self.assertEquals(api.login_id, 'myuser') - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_if_api_token_is_missing_fetch_a_new_one(self, mock_http_client): api = Api(url='http://localhost') api.authenticate = MagicMock(return_value='mytoken') @@ -93,7 +93,7 @@ def test_if_api_token_is_missing_fetch_a_new_one(self, mock_http_client): self.assertEquals(api.api_token, 'mytoken') api.authenticate.assert_called_once_with() - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_if_account_is_empty_throw_an_error(self, mock_http_client): empty_values = [ None, "" ] for empty_value in empty_values: @@ -101,7 +101,7 @@ def test_if_account_is_empty_throw_an_error(self, mock_http_client): with self.assertRaises(RuntimeError): api = Api(url='http://localhost', account=empty_value) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_if_api_token_is_not_expired_dont_fetch_new_one(self, mock_http_client): api = Api(url='http://localhost') api.authenticate = MagicMock(return_value='mytoken') @@ -111,7 +111,7 @@ def test_if_api_token_is_not_expired_dont_fetch_new_one(self, mock_http_client): self.assertEquals(api.api_token, 'mytoken') - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_if_api_token_is_expired_fetch_new_one(self, mock_http_client): api = Api(url='http://localhost') api.authenticate = MagicMock(return_value='mytoken') @@ -123,7 +123,7 @@ def test_if_api_token_is_expired_fetch_new_one(self, mock_http_client): self.assertEquals(api.api_token, 'newtoken') - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_authenticate_invokes_http_client_correctly(self, mock_http_client): Api(url='http://localhost', login_id='mylogin', api_key='apikey').authenticate() @@ -133,7 +133,7 @@ def test_authenticate_invokes_http_client_correctly(self, mock_http_client): api_token=False, ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_account_info_is_passed_down_to_http_call(self, mock_http_client): Api(url='http://localhost', account='myacct', @@ -147,7 +147,7 @@ def test_account_info_is_passed_down_to_http_call(self, mock_http_client): api_token=False, ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_authenticate_passes_down_ssl_verify_param(self, mock_http_client): Api(url='http://localhost', login_id='mylogin', api_key='apikey', ssl_verify='verify').authenticate() @@ -160,7 +160,7 @@ def test_authenticate_passes_down_ssl_verify_param(self, mock_http_client): # Get variable - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_get_variable_invokes_http_client_correctly(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -174,7 +174,7 @@ def mock_auth(): identifier='myvar', ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_get_variable_passes_down_ssl_verify_param(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey', ssl_verify='verify') @@ -191,7 +191,7 @@ def mock_auth(): # Set variable - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_set_variable_invokes_http_client_correctly(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -206,7 +206,7 @@ def mock_auth(): identifier='myvar', ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse()) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse()) def test_set_variable_passes_down_ssl_verify_param(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey', ssl_verify='verify') @@ -224,7 +224,7 @@ def mock_auth(): # Policy apply - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) def test_apply_policy_invokes_http_client_correctly(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -242,7 +242,7 @@ def mock_auth(): identifier='mypolicyname', ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(text=json.dumps(MOCK_POLICY_CHANGE_OBJECT))) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(text=json.dumps(MOCK_POLICY_CHANGE_OBJECT))) def test_apply_policy_converts_returned_data_to_expected_objects(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -252,7 +252,7 @@ def mock_auth(): output = api.apply_policy_file('mypolicyname', self.POLICY_FILE) self.assertEqual(output, MOCK_POLICY_CHANGE_OBJECT) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) def test_apply_policy_passes_down_ssl_verify_parameter(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey', ssl_verify='ssl_verify') def mock_auth(): @@ -272,7 +272,7 @@ def mock_auth(): # Policy replace - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) def test_replace_policy_invokes_http_client_correctly(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -290,7 +290,7 @@ def mock_auth(): identifier='mypolicyname', ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(text=json.dumps(MOCK_POLICY_CHANGE_OBJECT))) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(text=json.dumps(MOCK_POLICY_CHANGE_OBJECT))) def test_replace_policy_converts_returned_data_to_expected_objects(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -300,7 +300,7 @@ def mock_auth(): output = api.replace_policy_file('mypolicyname', self.POLICY_FILE) self.assertEqual(output, MOCK_POLICY_CHANGE_OBJECT) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(text='{}')) def test_replace_policy_passes_down_ssl_verify_parameter(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey', ssl_verify='ssl_verify') def mock_auth(): @@ -320,7 +320,7 @@ def mock_auth(): # Get variables - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(content='{"foo": "a", "bar": "b"}')) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(content='{"foo": "a", "bar": "b"}')) def test_get_variables_invokes_http_client_correctly(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') def mock_auth(): @@ -335,7 +335,7 @@ def mock_auth(): }, ssl_verify=True) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(content=MOCK_BATCH_GET_RESPONSE)) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(content=MOCK_BATCH_GET_RESPONSE)) def test_get_variables_converts_returned_data_to_expected_objects(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey', account='myaccount') def mock_auth(): @@ -349,7 +349,7 @@ def mock_auth(): 'bar': 'b', }) - @patch('conjur_api_python3.api.invoke_endpoint', return_value=MockClientResponse(content='{"foo": "a", "bar": "b"}')) + @patch('conjur.api.invoke_endpoint', return_value=MockClientResponse(content='{"foo": "a", "bar": "b"}')) def test_get_variables_passes_down_ssl_verify_parameter(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey', ssl_verify='sslverify') def mock_auth(): @@ -366,7 +366,7 @@ def mock_auth(): # List resources - @patch('conjur_api_python3.api.invoke_endpoint', \ + @patch('conjur.api.invoke_endpoint', \ return_value=MockClientResponse(content=json.dumps(MOCK_RESOURCE_LIST))) def test_get_resources_invokes_http_client_correctly(self, mock_http_client): api = Api(url='http://localhost', login_id='mylogin', api_key='apikey') diff --git a/test/test_cli.py b/test/test_cli.py index 90a4f875..28a7b91e 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -2,7 +2,7 @@ from .util.cli_helpers import cli_arg_test, cli_test -from conjur_api_python3.version import __version__ +from conjur.version import __version__ RESOURCE_LIST = [ diff --git a/test/test_cli_integration.py b/test/test_cli_integration.py index c19a2d36..060b7a84 100644 --- a/test/test_cli_integration.py +++ b/test/test_cli_integration.py @@ -8,7 +8,7 @@ from .util.cli_helpers import integration_test, invoke_cli -from conjur_api_python3.version import __version__ +from conjur.version import __version__ # Not coverage tested since integration tests doesn't run in diff --git a/test/test_client.py b/test/test_client.py index 8712eda1..e727dbd0 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -4,8 +4,8 @@ from unittest.mock import MagicMock, Mock, patch -from conjur_api_python3.client import ConfigException, Client -from conjur_api_python3 import api +from conjur.client import ConfigException, Client +from conjur import api # ApiConfig mocking class diff --git a/test/test_config.py b/test/test_config.py index 110295e7..bed350ed 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -1,7 +1,7 @@ import os import unittest -from conjur_api_python3.config import Config +from conjur.config import Config class ConfigTest(unittest.TestCase): CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/test/test_endpoints.py b/test/test_endpoints.py index 6e0d3b22..2540cd41 100644 --- a/test/test_endpoints.py +++ b/test/test_endpoints.py @@ -1,6 +1,6 @@ import unittest -from conjur_api_python3.endpoints import ConjurEndpoint +from conjur.endpoints import ConjurEndpoint class EndpointsTest(unittest.TestCase): diff --git a/test/test_http.py b/test/test_http.py index bd0ec967..c99a0a72 100644 --- a/test/test_http.py +++ b/test/test_http.py @@ -5,8 +5,8 @@ import requests -from conjur_api_python3.endpoints import ConjurEndpoint -from conjur_api_python3.http import HttpVerb, invoke_endpoint +from conjur.endpoints import ConjurEndpoint +from conjur.http import HttpVerb, invoke_endpoint class HttpVerbTest(unittest.TestCase): diff --git a/test/test_version.py b/test/test_version.py index 92fdd2b0..0d7da50a 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -1,6 +1,6 @@ import unittest -from conjur_api_python3.version import __version__ +from conjur.version import __version__ class VersionTest(unittest.TestCase): def test_version_is_set(self): diff --git a/test/util/cli_helpers.py b/test/util/cli_helpers.py index 0bbe2ba2..a156db17 100644 --- a/test/util/cli_helpers.py +++ b/test/util/cli_helpers.py @@ -6,7 +6,7 @@ from unittest.mock import patch, MagicMock -from conjur_api_python3.cli import Cli +from conjur.cli import Cli def invoke_cli(test_runner, *args): capture_stream = io.StringIO() @@ -47,7 +47,7 @@ def test_wrapper_func(self, *inner_args, **inner_kwargs): with self.assertRaises(SystemExit) as sys_exit: with redirect_stdout(capture_stream): with patch.object(sys, 'argv', ["cli"] + cli_args), \ - patch('conjur_api_python3.cli.Client') as mock_client: + patch('conjur.cli.Client') as mock_client: mock_client.return_value = client_instance_mock Cli().run() @@ -87,7 +87,7 @@ def test_wrapper_func(self, *inner_args, **inner_kwargs): with self.assertRaises(SystemExit) as sys_exit: with redirect_stdout(capture_stream): with patch.object(sys, 'argv', ["cli"] + cli_args), \ - patch('conjur_api_python3.cli.Client') as mock_client: + patch('conjur.cli.Client') as mock_client: mock_client.return_value = MagicMock() client = mock_client