174
174
config['ssh_public_key'] = f.read().rstrip()
175
175
config['ssh_public_key_file'] = os.path.join(config['var_dir'], 'ssh_key.pub')
176
176
config['ssh_private_key_file'] = os.path.join(config['var_dir'], 'ssh_key')
177
elif os.path.isfile(os.path.join(config['config_dir'], 'id_rsa.pub')):
179
with open(os.path.join(config['config_dir'], 'id_rsa.pub')) as f:
180
config['ssh_public_key'] = f.read().rstrip()
181
config['ssh_public_key_file'] = os.path.join(config['config_dir'], 'id_rsa.pub')
182
config['ssh_private_key_file'] = os.path.join(config['config_dir'], 'id_rsa')
184
178
sources_config = {}
185
179
# Merge in sources.d/*.json to the sources dict
293
287
# Check for missing usernames/passwords
294
288
if not ('username' in config['sources'][s] or 'password' in config['sources'][s]):
295
289
sources_secrets_d = os.path.join(config['config_dir'], 'sources_secrets.d')
296
if os.path.isfile(os.path.join(sources_secrets_d, s + '.json')):
298
j = json_load_file(os.path.join(sources_secrets_d, s + '.json'))
299
config['sources'][s]['username'] = j['username']
300
config['sources'][s]['password'] = j['password']
302
if 'username' not in config['sources'][s]:
303
config['sources'][s]['username'] = str(uuid.uuid4())
304
if 'password' not in config['sources'][s]:
305
config['sources'][s]['password'] = ''.join(
306
random.choice(string.ascii_letters + string.digits)
290
if 'username' not in config['sources'][s]:
291
config['sources'][s]['username'] = str(uuid.uuid4())
292
if 'password' not in config['sources'][s]:
293
config['sources'][s]['password'] = ''.join(
294
random.choice(string.ascii_letters + string.digits)
309
297
with open(os.path.join(var_sources_d, '10-' + s + '.json'), 'w') as f:
310
298
os.fchmod(f.fileno(), 0o600)
319
def migrate_configs(config):
322
config_d = os.path.join(config['config_dir'], 'config.d')
323
sources_secrets_d = os.path.join(config['config_dir'], 'sources_secrets.d')
324
var_config_d = os.path.join(config['var_dir'], 'config.d')
326
# Avoid ETCBZR in the deployed Puppet environment
327
cleanup_migration = True
328
if 'cleanup_migration' in config:
329
cleanup_migration = config['cleanup_migration']
332
(os.path.join(config['config_dir'], 'id_rsa'), os.path.join(config['var_dir'], 'ssh_key')),
333
(os.path.join(config['config_dir'], 'id_rsa.pub'), os.path.join(config['var_dir'], 'ssh_key.pub')),
334
(os.path.join(config_d, '10-machine_uuid.json'), os.path.join(var_config_d, '10-machine_uuid.json')),
335
(os.path.join(config_d, '10-restore.json'), os.path.join(var_config_d, '10-restore.json')),
339
os.path.join(config['config_dir'], 'rsyncd.conf'),
340
os.path.join(config['config_dir'], 'rsyncd.secrets'),
341
os.path.join(config['var_dir'], 'server_config.json'),
344
for src, dst in file_migrations:
345
if os.path.isfile(src) and (not os.path.isfile(dst)):
346
if cleanup_migration:
347
shutil.move(src, dst)
349
shutil.copy2(src, dst)
351
if cleanup_migration:
352
for file in file_deletions:
353
if os.path.isfile(file):
356
# Generated secrets have already been replicated in var_sources_d
357
if os.path.isdir(sources_secrets_d):
358
shutil.rmtree(sources_secrets_d)
361
307
def api_call(api_url, cmd, post_data, timeout=5):
362
308
url = urllib.parse.urlparse(api_url)
363
309
if url.scheme == 'https':