Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow an optional argument for a specific vault file #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ansible_toolkit/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ def backup(path, password_file=None):
f.write(decrypted_data)


def backup_all(password_file=None):
for file_ in get_files('.'):
backup(file_, password_file)
def backup_all(password_file=None, vault_file=None):

if vault_file:
if not os.path.isfile(vault_file):
raise RuntimeError("Unable to locate vault file")
backup(vault_file, password_file)
else:
for file_ in get_files('.'):
backup(file_, password_file)


def restore(path, password_file=None):
Expand Down
4 changes: 3 additions & 1 deletion bin/atk-vault
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ if __name__ == '__main__':
parser.add_argument('action', help="open, close")
parser.add_argument('-p', '--vault-password-file', type=str,
help="Path to vault password file")
parser.add_argument('-f', '--vault-file', type=str,
help="Path to vault file")
args = parser.parse_args()
if args.action not in ['open', 'close']:
raise RuntimeError(
"atk-vault command must be either 'open' or 'close'")

# Open / Close Vault
if args.action == 'open':
vault.backup_all(args.vault_password_file)
vault.backup_all(args.vault_password_file, args.vault_file)
elif args.action == 'close':
vault.restore_all(args.vault_password_file)