Skip to content

Commit

Permalink
Feat: Add get-secrets to lftools.jenkins
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
eb-oss committed Feb 3, 2022
1 parent a74bfda commit a9eec3a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lftools/cli/jenkins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredenti
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
Expand Down Expand Up @@ -179,6 +205,7 @@ def node = slave.computer
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")
Expand Down
7 changes: 7 additions & 0 deletions releasenotes/notes/add-get-secrets-402d7e2452994baa.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit a9eec3a

Please sign in to comment.