Make sure the keystore directory exists when moving default keys

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
This commit is contained in:
Vladimir Diaz 2018-03-22 14:07:44 -04:00
parent 274aa35efa
commit dfd88860c6
No known key found for this signature in database
GPG key ID: 5DEE9B97B0E2289A

View file

@ -296,10 +296,16 @@ def gen_key(parsed_arguments):
# working directory. By default, the filenames are written to <KEYID>.pub
# and <KEYID> (private key). Move them from the CWD to the repo's keystore.
if not parsed_arguments.filename:
shutil.move(keypath, os.path.join(parsed_arguments.path,
KEYSTORE_DIR, os.path.basename(keypath)))
shutil.move(keypath + '.pub', os.path.join(parsed_arguments.path,
KEYSTORE_DIR, os.path.basename(keypath + '.pub')))
privkey_repo_path = os.path.join(parsed_arguments.path,
KEYSTORE_DIR, os.path.basename(keypath))
pubkey_repo_path = os.path.join(parsed_arguments.path,
KEYSTORE_DIR, os.path.basename(keypath + '.pub'))
securesystemslib.util.ensure_parent_dir(privkey_repo_path)
securesystemslib.util.ensure_parent_dir(pubkey_repo_path)
shutil.move(keypath, privkey_repo_path)
shutil.move(keypath + '.pub', pubkey_repo_path)