Skip to content

Commit

Permalink
VIRA-293: allow access token auth
Browse files Browse the repository at this point in the history
@jacobstr pushed #77 allowing users to uses access
tokens over the standard `passsword`.
  • Loading branch information
n0v1c3 committed Oct 18, 2021
1 parent 5ab8afc commit be330fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
14 changes: 7 additions & 7 deletions plugin/vira.vim
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ command! -nargs=0 -bang ViraTodo call vira#_todo()
command! -nargs=0 -bang ViraTodos call vira#_todos()

" Sets
command! -nargs=0 -bang ViraSetAssignee call vira#_menu('assign_issue');
command! -nargs=0 -bang ViraSetComponent call vira#_menu('component');
command! -nargs=0 -bang ViraSetEpic call vira#_menu('epic');
command! -nargs=0 -bang ViraSetPriority call vira#_menu('priority');
command! -nargs=0 -bang ViraSetStatus call vira#_menu('set_status');
command! -nargs=0 -bang ViraSetType call vira#_menu('issuetype');
command! -nargs=0 -bang ViraSetVersion call vira#_menu('version');
command! -nargs=0 -bang ViraSetAssignee call vira#_menu('assign_issue')
command! -nargs=0 -bang ViraSetComponent call vira#_menu('component')
command! -nargs=0 -bang ViraSetEpic call vira#_menu('epic')
command! -nargs=0 -bang ViraSetPriority call vira#_menu('priority')
command! -nargs=0 -bang ViraSetStatus call vira#_menu('set_status')
command! -nargs=0 -bang ViraSetType call vira#_menu('issuetype')
command! -nargs=0 -bang ViraSetVersion call vira#_menu('version')

" Edit
command! -nargs=0 -bang ViraEditDescription call vira#_prompt_start('description')
Expand Down
23 changes: 18 additions & 5 deletions python/Vira/vira_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def connect(self, server):
self.versions = set()
self.users_type = ''

# Login arguments
auth_kwargs = {}
option_kwargs = {}

try:
# Specify whether the server's TLS certificate needs to be verified
if self.vira_servers[server].get('skip_cert_verify'):
Expand All @@ -188,12 +192,21 @@ def connect(self, server):
cert_verify = True

# Get auth for current server
username = self.vira_servers[server].get('username')
password_cmd = self.vira_servers[server].get('password_cmd')
if password_cmd:
password = run_command(password_cmd)['stdout'].strip().split('\n')[0]
if not self.vira_servers[server].get('access_token_cmd') and not self.vira_servers[server].get('access_token'):
username = self.vira_servers[server].get('username')
password_cmd = self.vira_servers[server].get('password_cmd')
if password_cmd:
password = run_command(password_cmd)['stdout'].strip().split('\n')[0]
else:
password = self.vira_servers[server]['password']
auth_kwargs['basic_auth'] = (username, password)
else:
password = self.vira_servers[server]['password']
token_cmd = self.vira_servers[server].get('access_token_cmd')
if token_cmd:
access_token = run_command(token_cmd)['stdout'].strip().split('\n')[0]
else:
access_token = self.vira_servers[server]['access_token']
option_kwargs = {"headers": {"Authorization": "Bearer %s" % access_token}}
except:
self.msg_server_fail()
raise
Expand Down

0 comments on commit be330fc

Please sign in to comment.