From 3c2947cf79c92f3914df8ffa8feae7ab21f7f1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= Date: Fri, 11 Nov 2022 21:55:29 -0300 Subject: [PATCH 1/3] Support for api key vault cmd config --- WakaTime.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/WakaTime.py b/WakaTime.py index ab48538..364a84b 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -194,11 +194,32 @@ class ApiKey(object): if key: self._key = key return self._key + + apiKeyFromVault = self.__readFromVaultCmd() + if apiKeyFromVault: + self._key = apiKeyFromVault + return self._key except: pass return self._key + def __readFromVaultCmd(self): + apiKeyCmd = SETTINGS.get('api_key_vault_cmd') + if not apiKeyCmd: + return None + + try: + p = Popen(apiKeyCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = p.communicate() + if p.returncode == 0: + return stdout.strip() + log(WARNING, u(stderr)) + except: + log(ERROR, traceback.format_exc()) + + return None + def write(self, key): global SETTINGS self._key = key From a387c08b44c6b0223898a3c6ec0b9386b6a71c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= Date: Fri, 11 Nov 2022 21:57:09 -0300 Subject: [PATCH 2/3] changes for v11.1.0 --- HISTORY.rst | 6 ++++++ README.md | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c90c5ba..dbb5011 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ------- +11.1.0 (2022-11-11) +++++++++++++++++++ + +- Support for api key vault cmd config + + 11.0.8 (2022-08-23) ++++++++++++++++++ diff --git a/README.md b/README.md index c420287..e4e17ff 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [WakaTime][wakatime] is an open source Sublime Text plugin for metrics, insights, and time tracking automatically generated from your programming activity. - ## Installation 1. Install [Package Control](https://packagecontrol.io/installation). @@ -19,12 +18,10 @@ 6. Use Sublime and your coding activity will be displayed on your [WakaTime dashboard](https://wakatime.com). - ## Screen Shots ![Project Overview](https://wakatime.com/static/img/ScreenShots/Screen-Shot-2016-03-21.png) - ## Unresponsive Plugin Warning In Sublime Text 2, if you get a warning message: @@ -35,7 +32,6 @@ To fix this, go to `Preferences → Settings - User` then add the following sett `"detect_slow_plugins": false` - ## Troubleshooting First, turn on debug mode in your `WakaTime.sublime-settings` file. From 5077c5e2902a3aec77a117c25ee37bf2d9e87da0 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sat, 12 Nov 2022 12:32:43 -0600 Subject: [PATCH 3/3] read api key vault cmd from sublime settings and wakatime config file --- WakaTime.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/WakaTime.py b/WakaTime.py index 364a84b..1440d06 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -186,6 +186,7 @@ class ApiKey(object): self._key = key return self._key + configs = None try: configs = parseConfigFile(CONFIG_FILE) if configs: @@ -194,27 +195,36 @@ class ApiKey(object): if key: self._key = key return self._key - - apiKeyFromVault = self.__readFromVaultCmd() - if apiKeyFromVault: - self._key = apiKeyFromVault - return self._key except: pass + key = self.api_key_from_vault_cmd(configs) + if key: + self._key = key + return self._key + return self._key - def __readFromVaultCmd(self): - apiKeyCmd = SETTINGS.get('api_key_vault_cmd') - if not apiKeyCmd: + def api_key_from_vault_cmd(self, configs): + vault_cmd = SETTINGS.get('api_key_vault_cmd') + if not vault_cmd and configs: + try: + if configs.has_option('settings', 'api_key_vault_cmd'): + vault_cmd = configs.get('settings', 'api_key_vault_cmd') + except: + pass + + if not vault_cmd or not vault_cmd.strip(): return None try: - p = Popen(apiKeyCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - stdout, stderr = p.communicate() - if p.returncode == 0: - return stdout.strip() - log(WARNING, u(stderr)) + process = Popen(vault_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + stdout, stderr = process.communicate() + retcode = process.poll() + if retcode: + log(ERROR, 'Vault command error ({retcode}): {stderr}'.format(retcode=retcode, stderr=u(stderr))) + return None + return stdout.strip() or None except: log(ERROR, traceback.format_exc())