Last active
November 5, 2019 20:55
-
-
Save fdlk/893216c47bc3c119b0961844855f633e to your computer and use it in GitHub Desktop.
scrape hashicorp kv store contents
This file contains 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 json | |
import subprocess | |
# read file | |
with open('scraped.json', 'r') as scraped: | |
data=scraped.read() | |
# parse file | |
obj = json.loads(data) | |
for (path, value) in obj.items(): | |
with open('data.json', 'w') as outfile: | |
outfile.write(value) | |
subprocess.check_output(['vault', 'kv', 'put', path, '@data.json']) | |
print(path) |
This file contains 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 subprocess | |
import json | |
scraped = dict() | |
def scrape(path): | |
try: | |
content = json.loads(subprocess.check_output(['vault', 'kv', 'list', '-format=json', path])) | |
for item in content: | |
scrape(path+item) | |
except subprocess.CalledProcessError as ex: | |
entry = json.loads(subprocess.check_output(['vault', 'read', path, '-format=json'])) | |
data = json.dumps(entry['data']) | |
print(path, data) | |
scraped[path] = data | |
scrape('/secret/') | |
print(json.dumps(scraped)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment