From 47beeebed8bcbe2c42fd75d6a09fae3878a0d83a Mon Sep 17 00:00:00 2001 From: Adam Bullmer Date: Sat, 4 Nov 2017 01:17:14 -0500 Subject: [PATCH] Fixed issues with it not updating the view buffer on decrypt --- MANIFEST.in | 1 - commands.py | 27 ++++++++++++++++++--------- messages.json | 3 ++- messages/1.1.0.txt | 12 ++++++++++++ requirements.txt | 0 setup.py | 34 ---------------------------------- tox.ini | 4 +--- 7 files changed, 33 insertions(+), 48 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 messages/1.1.0.txt delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index f9bd145..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include requirements.txt diff --git a/commands.py b/commands.py index 746aa1d..d0c93cf 100644 --- a/commands.py +++ b/commands.py @@ -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 @@ -80,10 +80,18 @@ 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): @@ -91,6 +99,7 @@ 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) @@ -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) diff --git a/messages.json b/messages.json index ef56f9e..ac5ac4e 100644 --- a/messages.json +++ b/messages.json @@ -1,3 +1,4 @@ { - "install": "messages/install.txt" + "install": "messages/install.txt", + "1.1.0": "messages/1.1.0.txt" } diff --git a/messages/1.1.0.txt b/messages/1.1.0.txt new file mode 100644 index 0000000..4a99eb0 --- /dev/null +++ b/messages/1.1.0.txt @@ -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. diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e69de29..0000000 diff --git a/setup.py b/setup.py deleted file mode 100644 index d0f46f4..0000000 --- a/setup.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -if __name__ == '__main__': - import logging - from pkg_resources import Requirement - from setuptools import setup, find_packages - - log = logging.getLogger(__name__) - - with open('requirements.txt') as f: - REQUIREMENTS = [] - for req in f.readlines(): - req = req.strip() - try: - Requirement.parse(req) - except: - log.warning('failed to parse `{0}` from requirements.txt, skipping\n'.format(req)) - continue - if len(req) is 0: - continue - REQUIREMENTS.append(req) - - - setup( - name='Sublime Text Ansible Vault', - version='1.0.1', - description='', - author='Adam Bullmer', - author_email='psycodrumfreak@gmail.com', - url='https://github.com/rewardStyle/sublime_ansible_vault', - packages=find_packages(), - include_package_data=True, - install_requires=REQUIREMENTS, - zip_safe=False, - ) diff --git a/tox.ini b/tox.ini index f849b1d..03f55ae 100644 --- a/tox.ini +++ b/tox.ini @@ -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