2017-08-28 11:51:35 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Open the secrets.yml and replace all passwords.
|
|
|
|
Original is backed up.
|
|
|
|
"""
|
|
|
|
|
2017-08-31 15:02:47 +02:00
|
|
|
from os import path
|
2017-08-28 11:51:35 +02:00
|
|
|
import random
|
|
|
|
import string
|
|
|
|
from subprocess import call
|
|
|
|
from yaml import load, dump
|
|
|
|
|
|
|
|
try:
|
|
|
|
from yaml import CLoader as Loader, CDumper as Dumper
|
|
|
|
except ImportError:
|
|
|
|
from yaml import Loader, Dumper
|
|
|
|
|
|
|
|
# length of generated passwords.
|
|
|
|
pass_length = 20
|
|
|
|
|
2017-08-29 09:29:53 +02:00
|
|
|
with open('secrets.yml.topol', 'r') as f:
|
2017-08-28 11:51:35 +02:00
|
|
|
data = load(f, Loader=Loader)
|
|
|
|
|
|
|
|
for key, value in data.iteritems():
|
|
|
|
data[key] = ''.join(
|
|
|
|
random.choice(string.ascii_letters + string.digits)
|
|
|
|
for _ in range(pass_length))
|
|
|
|
|
|
|
|
# Make numbered backups of the secrets file.
|
2017-08-31 15:02:47 +02:00
|
|
|
if path.isfile('secrets.yml'):
|
|
|
|
call(['cp', '--backup=numbered', 'secrets.yml', 'secrets.yml.bak'])
|
2017-08-28 11:51:35 +02:00
|
|
|
|
|
|
|
with open('secrets.yml', 'w') as f:
|
|
|
|
dump(data, f, Dumper=Dumper, default_flow_style=False)
|