Skip to content

Commit

Permalink
Fixed issues with it not updating the view buffer on decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
adambullmer committed Nov 4, 2017
1 parent 4fcffbe commit 47beeeb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 48 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

27 changes: 18 additions & 9 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ def on_change(self, password):
def on_cancel(self):
pass

def ansible_vault(self, vault_file_path):
def ansible_vault(self, edit, vault_file_path):
# Use a password if one is present
password = get_setting('password')
if password != '':
self.run_vault_command(vault_file_path, password)
self.run_vault_command(edit, vault_file_path, password)
return

# Use a password file is one is present
password_file = get_setting('password_file')
if password_file != '':
self.run_vault_command(vault_file_path, password_file, password_from_file=True)
self.run_vault_command(edit, vault_file_path, password_file, password_from_file=True)
return

# No configured password, fallback to a prompt
self.prompt_vault_password(vault_file_path)

def run_vault_command(self, vault_file_path, password, password_from_file=False):
def run_vault_command(self, edit, vault_file_path, password, password_from_file=False):
vault_password_flag = '--ask-vault-pass'
password_input = password

Expand All @@ -80,17 +80,26 @@ def run_vault_command(self, vault_file_path, password, password_from_file=False)
)

output, error = proc.communicate(input=bytearray(password_input, 'utf-8'))

if error:
sublime.error_message(error.decode('utf-8'))
return

output = output.decode('utf-8')

if self.open_new_tab is True:
self.view.run_command('ansible_vault_output', {'output': output, 'title': vault_file_path})
else:
region = sublime.Region(0, self.view.size())
self.view.replace(edit, region, output)


class AnsibleVaultOutputCommand(sublime_plugin.TextCommand):
def run(self, edit, output=None, title=None):
output_view = self.view.window().new_file()
output_view.set_name(title)
output_view.insert(edit, 0, output)
output_view.set_syntax_file('Packages/YAML/YAML.sublime-syntax')
output_view.set_read_only(True)


Expand All @@ -100,20 +109,20 @@ class AnsibleVaultViewCommand(AnsibleVaultBase, sublime_plugin.TextCommand):

def run(self, edit):
vault_file = self.view.file_name()
self.ansible_vault(vault_file)
self.ansible_vault(edit, vault_file)


class AnsibleVaultDecryptCommand(AnsibleVaultBase, sublime_plugin.TextCommand):
command = 'decrypt'
command = 'decrypt --output=-'

def run(self, edit):
vault_file = self.view.file_name()
self.ansible_vault(vault_file)
self.ansible_vault(edit, vault_file)


class AnsibleVaultEncryptCommand(AnsibleVaultBase, sublime_plugin.TextCommand):
command = 'encrypt'
command = 'encrypt --output=-'

def run(self, edit):
vault_file = self.view.file_name()
self.ansible_vault(vault_file)
self.ansible_vault(edit, vault_file)
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"install": "messages/install.txt"
"install": "messages/install.txt",
"1.1.0": "messages/1.1.0.txt"
}
12 changes: 12 additions & 0 deletions messages/1.1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Ansible Vault
=============

Changelog
---------

- Fixed bug where the view would sometimes not update with the filesystem changes
- Forcing YAML syntax highlighting on `View` command new file.

Fixing the view update bug requires that this plugin takes the output of the ansible command and put it into the current view.
This makes a a dirty change on the currently open file rather than modifying the filesystem.
As a result, you will have to save the file before running the encrypt command.
Empty file removed requirements.txt
Empty file.
34 changes: 0 additions & 34 deletions setup.py

This file was deleted.

4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
[tox]
envlist = style
usedevelop = true
skipsdist = True

[testenv:style]
deps =
-r{toxinidir}/requirements.txt
flake8==2.4.0
commands =
flake8 --statistics --count {toxinidir}/commands.py

[testenv:style-ci]
deps =
-r{toxinidir}/requirements.txt
flake8==2.4.0
commands =
flake8 --statistics --count --output-file={envdir}/flake8.txt {toxinidir}/commands.py
Expand Down

0 comments on commit 47beeeb

Please sign in to comment.