2024-03-02 00:34:29 -05:00
#!/usr/bin/env python3
from typing import Optional
import re
import configparser
import autoproc
import XWBSSOi
async def task_smartcard ( proc , config : Optional [ configparser . ConfigParser ] = None ) :
""" Smartcard authentication """
async with proc . sendline , autoproc . expect_async ( proc ) as expect :
if await expect . endswith ( ' \r \n ACCESS CODE: ' , timeout_settle = 60 ) :
try :
certificate = config [ ' auth ' ] [ ' certificate ' ]
except ( TypeError , KeyError ) :
choice = XWBSSOi . get_vista_certificate ( )
certificate = XWBSSOi . get_certificate_thumbprint ( choice ) . hex ( ) if choice else None
doc = await XWBSSOi . get_sso_token_async ( certificate = certificate )
if doc :
proc . sendline ( re . sub ( r ' [ \ r \ n] ' , ' ' , doc ) )
if await expect . earliest ( re . compile ( r ' ^ \ s+You last signed on \ s+ ' , flags = re . MULTILINE ) , timeout_settle = 5 ) :
if certificate :
config . set ( ' auth ' , ' certificate ' , certificate )
proc . create_task ( task_keepalive ( proc , True ) , name = ' @task:keepalive ' )
2025-01-14 21:56:51 -05:00
async for prompt , response in expect . promptmatches ( (
( re . compile ( r ' Press \' RETURN \' to continue, \' \ ^ \' to stop: $ ' ) , None ) ,
( ' Select Patient Information and OE/RR Option: ' , None , True ) ,
( ' Select Patient Information and OE/RR <TEST ACCOUNT> Option: ' , None , True ) ,
) , throw = True ) :
if prompt . index == 0 :
proc . sendline ( response )
2024-03-02 00:34:29 -05:00
return True
async def task_keepalive ( proc , suppress = False ) :
""" Keepalive """
with autoproc . expect ( proc ) as expect :
if suppress :
while True :
if m := await expect . endswith ( ' \r \n Do you want to halt and continue with this option later? YES// ' , ' \r \n Do you really want to halt? YES// ' , timeout_settle = 60 ) :
await proc . sendline . withlock ( ' NO ' )
if m . index == 1 :
print ( ' Suppressed; type \' ^ \' or \' ^Halt \' to actually halt. ' )
else :
while True :
if await expect . endswith ( ' \r \n Do you want to halt and continue with this option later? YES// ' , timeout_settle = 60 ) :
await proc . sendline . withlock ( ' NO ' )