Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from cyberark/enable-pypi-uploads
Browse files Browse the repository at this point in the history
Enable pypi uploads
  • Loading branch information
garymoon authored May 30, 2019
2 parents 03545df + ffba84d commit 5199f46
Show file tree
Hide file tree
Showing 32 changed files with 238 additions and 68 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENV INSTALL_DIR=/opt/conjur-api-python3
RUN apk add --no-cache bash \
binutils \
build-base \
git \
python3 \
python3-dev

Expand Down
12 changes: 12 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

---

Expand Down Expand Up @@ -30,14 +30,31 @@ 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

```python3
#!/usr/bin/env python3

from conjur_api_python3 import Client
from conjur import Client

client = Client(url='https://conjur.myorg.com',
account='default',
Expand Down
2 changes: 1 addition & 1 deletion bin/build_binary
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
47 changes: 47 additions & 0 deletions bin/needs_publishing
Original file line number Diff line number Diff line change
@@ -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 "<not published>")
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
43 changes: 43 additions & 0 deletions bin/publish
Original file line number Diff line number Diff line change
@@ -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/*
"
2 changes: 1 addition & 1 deletion bin/test_linting
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

SRC_DIRS=( "./conjur_api_python3"
SRC_DIRS=( "./conjur"
"./pkg_bin" )

DISABLED_ERRORS="fixme"
Expand Down
31 changes: 31 additions & 0 deletions conjur/__init__.py
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions conjur_api_python3/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/test_full_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import time

import conjur_api_python3 as conjur
import conjur

VARIABLE_PATH = 'a/ b/c'
USE_CONJURRC = True
Expand Down
2 changes: 1 addition & 1 deletion pkg_bin/conjur-py3-cli → pkg_bin/conjur-cli
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions secrets.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 20 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,32 @@

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")

VERSION_DATA = {}
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',
]
},

Expand All @@ -48,21 +53,23 @@
author="CyberArk Software, Inc",
author_email="CyberArk Maintainers <conj_maintainers@cyberark.com>",
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",
Expand All @@ -74,5 +81,5 @@
"Topic :: System :: Systems Administration",
"Topic :: System :: Systems Administration :: Authentication/Directory",
"Topic :: Utilities",
],
],
)
Loading

0 comments on commit 5199f46

Please sign in to comment.