Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows compatibility #16

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ in
}
```

### Windows

Install with pip/pipx and be sure that you have `sudo` and `openconnect` executables
in your PATH.

## Configuration

If you want to save credentials and get them automatically
Expand Down
22 changes: 11 additions & 11 deletions openconnect_sso/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import getpass
import json
import logging
import os
import shlex
import signal
from pathlib import Path
Expand All @@ -25,6 +26,8 @@ def run(args):
configure_logger(logging.getLogger(), args.log_level)

try:
if os.name == 'nt':
asyncio.set_event_loop(asyncio.ProactorEventLoop())
return asyncio.get_event_loop().run_until_complete(_run(args))
except KeyboardInterrupt:
logger.warn("CTRL-C pressed, exiting")
Expand Down Expand Up @@ -125,7 +128,10 @@ async def select_profile(profile_list):
),
values=[(p, p.name) for i, p in enumerate(profile_list)],
).run_async()
asyncio.get_event_loop().remove_signal_handler(signal.SIGWINCH)
# Somehow prompt_toolkit sets up a bogus signal handler upon exit
# TODO: Report this issue upstream
if hasattr(signal, "SIGWINCH"):
asyncio.get_event_loop().remove_signal_handler(signal.SIGWINCH)
if not selection:
return selection
logger.info("Selected profile", profile=selection.name)
Expand All @@ -141,20 +147,14 @@ async def run_openconnect(auth_info, host, args):
command_line = [
"sudo",
"openconnect",
"--cookie-on-stdin",
"--cookie",
auth_info.session_token,
"--servercert",
auth_info.server_cert_hash,
*args,
host.vpn_url,
]

logger.debug("Starting OpenConnect", command_line=command_line)
proc = await asyncio.create_subprocess_exec(
*command_line,
host.vpn_url,
stdin=asyncio.subprocess.PIPE,
stdout=None,
stderr=None,
)
proc.stdin.write(f"{auth_info.session_token}\n".encode())
await proc.stdin.drain()
proc = await asyncio.create_subprocess_exec(*command_line)
await proc.wait()