[~] Refactor
This commit is contained in:
parent
0f1f526078
commit
88e0c6f5ee
@ -565,6 +565,12 @@ def http_server(argv):
|
||||
def pass_ssh_osx(argv):
|
||||
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option(
|
||||
'--list',
|
||||
dest='list',
|
||||
default=False,
|
||||
action='store_true',
|
||||
)
|
||||
parser.add_option(
|
||||
'--pass_option',
|
||||
dest='pass_option',
|
||||
@ -591,6 +597,13 @@ def pass_ssh_osx(argv):
|
||||
t1 = options.pass_option
|
||||
assert len(t1) > 0
|
||||
|
||||
|
||||
reset_gpg_agent = r'''
|
||||
gpgconf --kill gpg-agent && \
|
||||
gpgconf --reload gpg-agent
|
||||
'''
|
||||
|
||||
if not options.list:
|
||||
print(
|
||||
'select on of pass names\n%s' % '\n'.join([
|
||||
'%d: %s' % (k, v)
|
||||
@ -607,10 +620,22 @@ def pass_ssh_osx(argv):
|
||||
except:
|
||||
continue
|
||||
|
||||
reset_gpg_agent = r'''
|
||||
gpgconf --kill gpg-agent;
|
||||
gpgconf --reload gpg-agent;
|
||||
'''
|
||||
command = r'''
|
||||
%s
|
||||
gpg \
|
||||
--pinentry-mode=ask \
|
||||
-q -u $(cat ~/.password-store/.gpg-id) \
|
||||
--decrypt \
|
||||
~/.password-store/%s.gpg && \
|
||||
echo -n '['$?']' && \
|
||||
%s
|
||||
''' % (
|
||||
reset_gpg_agent,
|
||||
t1[t3],
|
||||
reset_gpg_agent,
|
||||
)
|
||||
else:
|
||||
command = 'pass list | less -R'
|
||||
|
||||
ssh_command = [
|
||||
'ssh', '-C',
|
||||
@ -618,20 +643,7 @@ def pass_ssh_osx(argv):
|
||||
'-o', 'ServerAliveInterval 1',
|
||||
*args,
|
||||
'-t',
|
||||
r'''
|
||||
%s
|
||||
gpg \
|
||||
--pinentry-mode=ask \
|
||||
-q -u $(cat ~/.password-store/.gpg-id) \
|
||||
--decrypt \
|
||||
~/.password-store/%s.gpg;
|
||||
echo -n '['$?']';
|
||||
%s
|
||||
''' % (
|
||||
reset_gpg_agent,
|
||||
t1[t3],
|
||||
reset_gpg_agent,
|
||||
),
|
||||
command,
|
||||
]
|
||||
|
||||
if options.debug:
|
||||
@ -641,6 +653,19 @@ def pass_ssh_osx(argv):
|
||||
)
|
||||
)
|
||||
|
||||
if options.list:
|
||||
subprocess.check_call(ssh_command)
|
||||
else:
|
||||
def cliboard_set(text):
|
||||
with subprocess.Popen([
|
||||
'pbcopy',
|
||||
], stdin=subprocess.PIPE) as p:
|
||||
p.stdin.write(text.encode('utf-8'))
|
||||
p.stdin.flush()
|
||||
p.stdin.close()
|
||||
p.wait(1)
|
||||
assert p.poll() == 0
|
||||
|
||||
with subprocess.Popen(
|
||||
ssh_command,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -687,6 +712,7 @@ def pass_ssh_osx(argv):
|
||||
|
||||
assert not last_chunk is None
|
||||
assert last_chunk['returncode'] == 0
|
||||
|
||||
if options.debug:
|
||||
pprint.pprint(last_chunk['data'])
|
||||
|
||||
@ -706,20 +732,13 @@ def pass_ssh_osx(argv):
|
||||
if pos2 == -1:
|
||||
last_line2 = last_line
|
||||
else:
|
||||
last_line2 = last_line[pos2 + 1:]
|
||||
last_line2 = last_line[
|
||||
pos2 + len(pinentry_delimeter):
|
||||
]
|
||||
|
||||
password = last_line2.decode('utf-8').rstrip('\r\n')
|
||||
assert not password is None
|
||||
|
||||
def cliboard_set(text):
|
||||
with subprocess.Popen([
|
||||
'pbcopy',
|
||||
], stdin=subprocess.PIPE) as p:
|
||||
p.stdin.write(text.encode('utf-8'))
|
||||
p.stdin.flush()
|
||||
p.stdin.close()
|
||||
p.wait(1)
|
||||
assert p.poll() == 0
|
||||
|
||||
cliboard_set(password)
|
||||
|
||||
get_time = lambda : datetime.datetime.now().timestamp()
|
||||
|
Loading…
Reference in New Issue
Block a user