Last active
October 4, 2018 14:41
-
-
Save rosskarchner/3fa93cfeb63d7d6eb2a3a9e00110d420 to your computer and use it in GitHub Desktop.
export a simple report of Jenkins credential usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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