mirror of
https://github.com/wakatime/sublime-wakatime.git
synced 2023-08-10 21:13:02 +03:00
read api key vault cmd from sublime settings and wakatime config file
This commit is contained in:
parent
a387c08b44
commit
5077c5e290
36
WakaTime.py
36
WakaTime.py
@ -186,6 +186,7 @@ class ApiKey(object):
|
|||||||
self._key = key
|
self._key = key
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
|
configs = None
|
||||||
try:
|
try:
|
||||||
configs = parseConfigFile(CONFIG_FILE)
|
configs = parseConfigFile(CONFIG_FILE)
|
||||||
if configs:
|
if configs:
|
||||||
@ -194,27 +195,36 @@ class ApiKey(object):
|
|||||||
if key:
|
if key:
|
||||||
self._key = key
|
self._key = key
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
apiKeyFromVault = self.__readFromVaultCmd()
|
|
||||||
if apiKeyFromVault:
|
|
||||||
self._key = apiKeyFromVault
|
|
||||||
return self._key
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
key = self.api_key_from_vault_cmd(configs)
|
||||||
|
if key:
|
||||||
|
self._key = key
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
def __readFromVaultCmd(self):
|
return self._key
|
||||||
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
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
p = Popen(apiKeyCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
process = Popen(vault_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = process.communicate()
|
||||||
if p.returncode == 0:
|
retcode = process.poll()
|
||||||
return stdout.strip()
|
if retcode:
|
||||||
log(WARNING, u(stderr))
|
log(ERROR, 'Vault command error ({retcode}): {stderr}'.format(retcode=retcode, stderr=u(stderr)))
|
||||||
|
return None
|
||||||
|
return stdout.strip() or None
|
||||||
except:
|
except:
|
||||||
log(ERROR, traceback.format_exc())
|
log(ERROR, traceback.format_exc())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user