From a9eec3ace38c11b01e43d6c2ce0bc45b166edc2d Mon Sep 17 00:00:00 2001 From: Eric Ball Date: Wed, 2 Feb 2022 16:13:31 -0800 Subject: [PATCH] Feat: Add get-secrets to lftools.jenkins Get-credentials only produces username/password credentials, which does not include "secret text" stores. This feature will add the command "get-secrets" in order to print these as well. Change-Id: Iac1911b486be1dc125a42b23595431c7065adfce Signed-off-by: Eric Ball --- lftools/cli/jenkins/__init__.py | 27 ++++++++++++++++++++++ .../notes/add-get-secrets-402d7e2452994baa.yaml | 7 ++++++ 2 files changed, 34 insertions(+) create mode 100644 releasenotes/notes/add-get-secrets-402d7e2452994baa.yaml diff --git a/lftools/cli/jenkins/__init__.py b/lftools/cli/jenkins/__init__.py index 9e67d7d6..7b0ce340 100644 --- a/lftools/cli/jenkins/__init__.py +++ b/lftools/cli/jenkins/__init__.py @@ -73,6 +73,32 @@ for (c in creds) { log.info(result) +@click.command() +@click.pass_context +def get_secrets(ctx): + """Print all available secrets.""" + jenkins = ctx.obj["jenkins"] + groovy_script = """ +import com.cloudbees.plugins.credentials.* + +println "Printing all secrets..." +def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( + com.cloudbees.plugins.credentials.common.StandardCredentials.class, + Jenkins.instance, + null, + null +); + +for (c in creds) { + try { + println(c.id + " : " + c.secret ) + } catch (MissingPropertyException) {} +} +""" + result = jenkins.server.run_script(groovy_script) + log.info(result) + + @click.command() @click.argument("groovy_file") @click.pass_context @@ -179,6 +205,7 @@ jenkins_cli.add_command(plugins_init, name="plugins") jenkins_cli.add_command(nodes) jenkins_cli.add_command(builds) jenkins_cli.add_command(get_credentials, name="get-credentials") +jenkins_cli.add_command(get_secrets, name="get-secrets") jenkins_cli.add_command(groovy) jenkins_cli.add_command(jobs) jenkins_cli.add_command(quiet_down, name="quiet-down") diff --git a/releasenotes/notes/add-get-secrets-402d7e2452994baa.yaml b/releasenotes/notes/add-get-secrets-402d7e2452994baa.yaml new file mode 100644 index 00000000..2f1afec2 --- /dev/null +++ b/releasenotes/notes/add-get-secrets-402d7e2452994baa.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Add ``get-secrets`` to lftools.jenkins. ``get-credentials`` only produces + username/password credentials, which does not include "secret text" stores. + This feature will add the command ``get-secrets`` in order to print these as + well. -- 2.16.6