diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..3632bd0445fdfe5eae96e148e62d99e9f65e84ab --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +packages/** filter=lfs diff=lfs merge=lfs -text diff --git a/Description.txt b/Description.txt deleted file mode 100644 index 555c396514df97c4372a580cc3e678129b674555..0000000000000000000000000000000000000000 --- a/Description.txt +++ /dev/null @@ -1,3 +0,0 @@ -== A tool to manage certificate lifecycle on Vault, Redis, Consul - -this tool is used in conjunction with certbot to upload certificates to the key stores diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000000000000000000000000000000000..52f8dfab85d252b5d14fe61ac08a08fdb6f04e78 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include requirements.txt +include README.rst +include LICENSE.md diff --git a/README.md b/README.md index 74db8ad2257e88fc375fa3b37efa1396b71745f3..27c1a8a33a837527f5e62155907e3aedfdaf8d24 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,34 @@ -# A tool to manage certificate lifecycle on Vault, Redis, Consul +# A tool to manage certificates lifecycle on Vault, Redis, Consul  -## Build & Install the package +## Install the package -The version number is defined in `./version/__init__.py`\ -In this README we assume that we are using version `0.5.0` +### dependencies -### Build pip +`py-consul` is a fork of `python-consul` and is only available as PIP package. -```sh -python3 setup.py bdist_wheel -pip install dist wile_coyote-0.5.0-py3-none-any.whl -``` +DEB users need to install `packages/deb/python3-py-consul_1.2.4-1_all.deb` +RPM users need to install `packages/rpm/py-consul-1.2.4-1.noarch.rpm`, as well as pip versions of `docopt` and `hvac` on CentOS 7. _[ **untested** ]_ -### UBuildse RPM +### packages -```sh -python3 setup.py bdist_rpm -sudo rpm -Uvh dist/wile_coyote-0.5.0-1.noarch.rpm +You can install one of the packages stored under the following directories: + +```txt +packages/ +├── deb +├── rpm +└── whl ``` -### Build DEB +## developer's notes -`DEB_BUILD_OPTIONS=nocheck` is required because `dh_auto_test` resets `$HOME` variable and the unit test fails because it won't find `acme.ini` +### version number -```sh -sudo apt install python3-stdeb fakeroot python-all dh-python -DEB_BUILD_OPTIONS=nocheck python3 setup.py --command-packages=stdeb.command bdist_deb -sudo dpkg -i deb_dist/python3-wile-coyote_0.5.0-1_all.deb -``` +the version number is stored inside `./version/__init__.py` -## create README.rst +### create README.rst ```sh pandoc README.md --from markdown --to rst -s -o README.rst diff --git a/README.rst b/README.rst index 62937cbb4c0be0c4e9e7fb3cc5a7a3d9d0fc5152..d2ab797c8bc25fe3851407b7e0e80285c1733250 100644 --- a/README.rst +++ b/README.rst @@ -1,45 +1,48 @@ -A tool to manage certificate lifecycle on Vault, Redis, Consul -============================================================== +A tool to manage certificates lifecycle on Vault, Redis, Consul +=============================================================== .. figure:: https://filesender.geant.org/images/wile_coyote.jpg :alt: Wile coyote Wile Coyote -Build & Install the package ---------------------------- +Install the package +------------------- -Let’s assume we have version ``0.5.0`` +dependencies +~~~~~~~~~~~~ -Use pip -~~~~~~~ +``py-consul`` is a fork of ``python-consul`` and is only available as +PIP package. -.. code:: sh - - python3 setup.py bdist_wheel - pip install dist wile_coyote-0.5.0-py3-none-any.whl +DEB users need to install +``packages/deb/python3-py-consul_1.2.4-1_all.deb`` RPM users need to +install ``packages/rpm/py-consul-1.2.4-1.noarch.rpm``, as well as pip +versions of ``docopt`` and ``hvac`` on CentOS 7. *[*\ **untested**\ *]* -Use RPM -~~~~~~~ +packages +~~~~~~~~ -.. code:: sh +You can install one of the packages stored under the following +directories: - python3 setup.py bdist_rpm - rpm -Uvh dist/wile_coyote-0.5.0-1.noarch.rpm +.. code:: txt -Use DEB -~~~~~~~ + packages/ + ├── deb + ├── rpm + └── whl -sudo is required to install the packages and to create the debian -package +developer’s notes +----------------- -.. code:: sh +version number +~~~~~~~~~~~~~~ - sudo apt install python3-stdeb fakeroot python-all dh-python - DEB_BUILD_OPTIONS=nocheck python3 setup.py --command-packages=stdeb.command bdist_deb +the version number is stored inside ``./version/__init__.py`` create README.rst ------------------ +~~~~~~~~~~~~~~~~~ .. code:: sh diff --git a/bin/anvil.py b/bin/anvil.py index e394e9931fadfcd29ce34f5d2350175281b9ba60..0294cc36fe7aed673ff6578066d5a83e8ad280b8 100755 --- a/bin/anvil.py +++ b/bin/anvil.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 -"""Anvil - wile_coyote test tool, erases, uploads and check certificates - validity onto test instances of Vault, Redis and Consul +"""Anvil, + wile_coyote test tool, erases, uploads and checks certificates + validity onto test instances of Vault, Redis and Consul. + In order to use Anvil you need to define a list of certificates + that you always expect to find in Vault, Redis and Consul. Usage: anvil.py [--prune] @@ -9,7 +11,7 @@ Usage: Options: -h --help Show this screen. - -p --prune Client + -p --prune Delete local certificates and fetch them again """ import os import re diff --git a/create-packages.sh b/create-packages.sh new file mode 100755 index 0000000000000000000000000000000000000000..9aaa17630a21aa54cf183e154dd6ed6e7e9c255b --- /dev/null +++ b/create-packages.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" + +usage() { + echo "" + echo "Create Wile_Coyote DEB, RPM, PIP package" + echo "-----------------------------------------" + echo "" + echo "example: $(basename $0) --deb --pip" + echo "" + echo "Usage: $(basename $0)" + echo " -h | --help Print this help and exit" + echo " -d | --deb Create DEB package" + echo " -r | --rpm Create RPM package" + echo " -p | --pip Create PIP package" + echo "" + exit 3 +} + +parameters=0 +OPTS=$(getopt -o "h,d,r,p" --longoptions "help,deb,rpm,pip" -- "$@") +if [ $? != 0 ]; then + usage +fi +eval set -- "$OPTS" + +while true; do + case $1 in + -h | --help) + usage + ;; + -d | --deb) + DEB='yes' + ((parameters++)) + ;; + -r | --rpm) + RPM='yes' + ((parameters++)) + ;; + -p | --pip) + PIP='yes' + ((parameters++)) + ;; + --) + shift + break + ;; + *) + break + ;; + esac + shift +done + +if [[ $parameters -eq 0 ]]; then + printf "\nYou need to use at least one option\n" >&2 + usage +fi + +VERSION=$(awk -F\' '/__version__/{print $2}' version/__init__.py) + +# == Create RPM +# +if [[ -n $RPM ]]; then + RPM_NAME="wile_coyote-${VERSION}-1.noarch.rpm" + python3 setup.py bdist_rpm --packager="Massimiliano Adamo <massimiliano.adamo@geant.org" \ + --requires="python3-redis, python36-requests, python36-pyOpenSSL" + if [[ $? -eq 0 ]]; then + mv dist/$RPM_NAME packages/rpm/ + echo -e "\nthe package was created and stored as ./packages/rpm/${RPM_NAME}" + else + echo -e "\nthere was an error creating the package" + fi +fi + +# == Create DEB +# +# reminder: +# `DEB_BUILD_OPTIONS=nocheck` is needed because `dh_auto_test` resets `$HOME` +# variable and the unit test fails because it won't find `acme.ini` +# +if [[ -n $DEB ]]; then + for pkg in python3-stdeb fakeroot python-all dh-python; do + if ! dpkg -l | grep -wq $pkg; then + echo "please use apt to install ${pkg}" + exit + fi + done + DEB_NAME="python3-wile-coyote_${VERSION}-1_all.deb" + DEB_BUILD_OPTIONS=nocheck python3 setup.py --command-packages=stdeb.command bdist_deb + if [[ $? -eq 0 ]]; then + mv deb_dist/$DEB_NAME packages/deb/ + echo -e "\nthe package was created and stored as ./packages/deb/${DEB_NAME}" + else + echo -e "\nthere was an error creating the package" + fi +fi + +# == Create PIP +# +if [[ -n $PIP ]]; then + PIP_NAME="wile_coyote-${VERSION}-py3-none-any.whl" + python3 setup.py bdist_wheel + if [[ $? -eq 0 ]]; then + mv dist/$PIP_NAME packages/pip/ + echo -e "\nthe package was created and stored as ./packages/pip/${PIP_NAME}" + else + echo -e "\nthere was an error creating the package" + fi +fi diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..4bb8457d5dd1b5ca032e8aec92c0bccae914d48f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +docopt==0.6.2 +hvac==0.11.2 +pyopenssl==22.0.0 +py-consul==1.2.4 +redis==3.5.3 +requests==2.28.1 diff --git a/setup.py b/setup.py index 7f047464026561ef868d035adf04089a5af58d23..bccd014367fa0b00fb7e878e614d69e69d58660a 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,18 @@ """ wile_coyote """ +from ensurepip import version import os from glob import glob from shutil import rmtree from setuptools import setup, find_packages -VERSION = __import__("version").__version__ +version = __import__("version").__version__ +description = """ this tool is used in conjunction with certbot to leverage + the lifecycle of the certificates on the key store""" +requirements = [ + x.strip() for x in + open('requirements.txt').readlines() if not x.startswith('#') and x != '\n'] rmtree('dist', ignore_errors=True) rmtree('deb_dist', ignore_errors=True) @@ -19,19 +25,11 @@ def read(fname): setup( name="wile_coyote", - version=VERSION, + version=version, description="A tool to manage certificates on Vault, Redis, Consul", - long_description=read('Description.txt'), - url="https://gitlab.geant.net/devops/wile_coyote", - install_requires=[ - 'configparser==5.0.2', - 'docopt==0.6.2', - 'hvac==0.11.2', - 'pyopenssl==22.0.0', - 'python-consul2==0.1.5', - 'redis==3.5.3', - 'requests==2.28.1', - ], + long_description=description, + url="https://gitlab.geant.org/devops/wile_coyote", + install_requires=requirements, author="Massimiliano Adamo", author_email="massimiliano.adamo@geant.org", license='GPLv3',