Skip to content

Instantly share code, notes, and snippets.

@rosskarchner
Last active October 4, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosskarchner/3fa93cfeb63d7d6eb2a3a9e00110d420 to your computer and use it in GitHub Desktop.
Save rosskarchner/3fa93cfeb63d7d6eb2a3a9e00110d420 to your computer and use it in GitHub Desktop.
export a simple report of Jenkins credential usage
import csv
import requests
auth = ('username', 'password')
API_URL = 'http://jenkins.host/credentials/store/system/api/json?depth=3&pretty=1'
response = requests.get(API_URL, auth=auth)
data = response.json()
with open('filename.csv', 'w') as csvfile:
writer = csv.DictWriter(
csvfile, fieldnames=['displayName', 'description', 'usage'],
extrasaction='ignore')
writer.writeheader()
for domain, domain_data in data['domains'].items():
for cred_data in domain_data['credentials']:
usage = 0
if cred_data['fingerprint']:
usage = len(cred_data['fingerprint'].get('usage'))
cred_data['usage'] = usage
writer.writerow(cred_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment