From 6d156100d0381f5da7b14d22f63615fcdccb8a04 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Wed, 6 Mar 2019 11:56:13 -0500 Subject: [PATCH] Expose Python commands to shell signer mode param Change-Id: I3202f9b30d24ace82d583cf6b92c12fef0c3c85c Signed-off-by: Thanh Ha --- lftools/cli/sign.py | 28 ++++++++++++++++++++-------- shell/sign | 12 +++++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/lftools/cli/sign.py b/lftools/cli/sign.py index 256d13ce..c3997502 100644 --- a/lftools/cli/sign.py +++ b/lftools/cli/sign.py @@ -28,10 +28,13 @@ def sign(ctx): @click.command(name='dir') @click.argument('directory') +@click.option( + '-m', '--mode', type=str, default='parallel', + help='Signing mode serial|parallel') @click.pass_context -def directory(ctx, directory): +def directory(ctx, directory, mode): """GPG signs all of the files in a directory.""" - status = subprocess.call(['sign', 'dir', directory]) + status = subprocess.call(['sign', 'dir', directory, mode]) sys.exit(status) @@ -41,24 +44,30 @@ def directory(ctx, directory): '-d', '--sign-dir', type=str, default=None, help='Local directory to clone repository. (default /tmp/gpg-signatures.*)') +@click.option( + '-m', '--mode', type=str, default='parallel', + help='Signing mode serial|parallel') @click.option( '-w', '--sign-with', type=str, default='gpg', help='Sign artifacts with GPG or Sigul. (default gpg)') @click.pass_context -def nexus(ctx, sign_dir, sign_with, nexus_repo_url): +def nexus(ctx, sign_dir, sign_with, nexus_repo_url, mode): """Fetch and GPG or Sigul sign a Nexus repo.""" if not sign_dir: sign_dir = tempfile.mkdtemp(prefix='gpg-signatures.') - status = subprocess.call(['sign', 'nexus', '-d', sign_dir, '-w', sign_with, nexus_repo_url]) + status = subprocess.call(['sign', 'nexus', '-d', sign_dir, '-m', mode, '-w', sign_with, nexus_repo_url]) sys.exit(status) @click.command(name='sigul') @click.argument('directory') +@click.option( + '-m', '--mode', type=str, default='parallel', + help='Signing mode serial|parallel') @click.pass_context -def sigul(ctx, directory): +def sigul(ctx, directory, mode): """Sigul signs all of the files in a directory.""" - status = subprocess.call(['sign', 'sigul', directory]) + status = subprocess.call(['sign', 'sigul', directory, mode]) sys.exit(status) @@ -70,6 +79,9 @@ def sigul(ctx, directory): '-d', '--sign-dir', type=str, default=None, help='Local directory to clone repository. (default /tmp/gpg-signatures.*)') +@click.option( + '-m', '--mode', type=str, default='parallel', + help='Signing mode serial|parallel') @click.option( '-r', '--root-domain', type=str, default='org', help='Root download path of staging repo. (default org)') @@ -77,7 +89,7 @@ def sigul(ctx, directory): '-w', '--sign-with', type=str, default='gpg', help='Sign artifacts with GPG or Sigul. (default gpg)') @click.pass_context -def deploy_nexus(ctx, nexus_url, nexus_repo, staging_profile_id, sign_dir, sign_with, root_domain): +def deploy_nexus(ctx, nexus_url, nexus_repo, staging_profile_id, sign_dir, sign_with, root_domain, mode): """Sign artifacts from a Nexus repo then upload to a staging repo. This is a porcelain command that ties the lftools sign and deploy tools @@ -96,7 +108,7 @@ def deploy_nexus(ctx, nexus_url, nexus_repo, staging_profile_id, sign_dir, sign_ if not sign_dir: sign_dir = tempfile.mkdtemp(prefix='gpg-signatures.') - status = subprocess.call(['sign', 'nexus', '-d', sign_dir, '-w', sign_with, nexus_repo_url]) + status = subprocess.call(['sign', 'nexus', '-d', sign_dir, '-m', mode, '-w', sign_with, nexus_repo_url]) if status: sys.exit(status) diff --git a/shell/sign b/shell/sign index 4ef50a03..23e22ecd 100755 --- a/shell/sign +++ b/shell/sign @@ -62,7 +62,9 @@ sign_dir() { # # Parameters: # + # : gpg|sigul # : The directory to find and sign artifacts. + # : serial|parallel local signer="$1" local dir="$2" @@ -168,7 +170,7 @@ sign_nexus() { # /tmp/gpg-signatures.XXXXXXXXXX unless the -d parameter is passed to # override. local signer='gpg' - while getopts d:w:h o; do + while getopts d:m:w:h o; do case "$o" in h) sign_nexus_usage @@ -180,6 +182,10 @@ sign_nexus() { mkdir -p "$sign_dir" ;; + m) + local sign_mode="$OPTARG" + ;; + w) if [[ "$OPTARG" =~ ^(gpg|sigul)$ ]] then @@ -244,9 +250,9 @@ sign_nexus() { echo "Signing artifacts..." if [ "$signer" == "gpg" ] then - sign_dir 'gpg' "$sign_dir" + sign_dir 'gpg' "$sign_dir" "$sign_mode" else - sign_dir 'sigul' "$sign_dir" + sign_dir 'sigul' "$sign_dir" "$sign_mode" fi echo "Removing non-signature files..." -- 2.16.6