Skip to content

Instantly share code, notes, and snippets.

@fdlk
Last active November 5, 2019 20:55
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 fdlk/893216c47bc3c119b0961844855f633e to your computer and use it in GitHub Desktop.
Save fdlk/893216c47bc3c119b0961844855f633e to your computer and use it in GitHub Desktop.
scrape hashicorp kv store contents
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)
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