Add vpn alias for Xonsh

Adding a set of aliases to my Xonsh work to start up a VPN that uses
BitWarden for OTP storage
Changed my Linux to specifically use Python 3.12 because the flag for
NamedTemporaryFile is introduced in 3.12
This commit is contained in:
Greg Hellings
2024-07-17 12:05:21 -05:00
parent 7d882d161e
commit 09d8400312
2 changed files with 28 additions and 6 deletions
+27 -5
View File
@@ -1,5 +1,7 @@
# vim: set ft=python :
from tempfile import NamedTemporaryFile
def bw_unlock():
"""Unlocks the BitWarden CLI and adds the resulting session code to the
current environment variables. Also returns the code for them."""
@@ -15,6 +17,24 @@ def bw_unlock():
$BW_SESSION = token
return token
def vpn(con, bwname):
bw_unlock()
base=$(bw get password @(bwname))
secret=$(bw get totp @(bwname))
#echo vpn.secrets.password:${base}$(oathtool -b -d "${digits}" -s "${period}" --totp "${secret}") > "${f}"
with NamedTemporaryFile(delete_on_close=False) as fp:
secret = f"vpn.secrets.password:{base}{secret}"
fp.write(secret.encode("utf-8"))
fp.close()
nmcli c up @(con) passwd-file @(fp.name)
def _unlock(args):
bw_unlock()
def _ivr(args):
vpn("350Main", "IVR Technology")
def _glrestart(args):
sudo nixos-container run gitlab -- systemctl restart gitlab
sudo nixos-container run gitlab -- systemctl restart nginx
@@ -73,16 +93,18 @@ def _bake(args):
copier copy @(str(templates / args[0])) .
aliases['glrestart'] = _glrestart
aliases['cfetch'] = _cfetch
aliases['bake'] = _bake
aliases['rebuild'] = _rebuild
aliases['yaml2json'] = _yaml2json
aliases['unlock'] = _unlock
aliases['cfetch'] = _cfetch
aliases['ivr'] = _ivr
aliases['newdock'] = _newdock
aliases['pip_extras'] = _pip_extras
aliases['py2env'] = _py2env
aliases['py3env'] = _py3env
aliases['rebuild'] = _rebuild
aliases['rundock'] = _rundock
aliases['newdock'] = _newdock
aliases['unknown_host'] = _unknown_host
aliases['pip_extras'] = _pip_extras
aliases['yaml2json'] = _yaml2json
###
#
# Other random nice-to-have things
+1 -1
View File
@@ -18,7 +18,7 @@ let
virtualenv
];
myPython = prev.python3.withPackages myPackages;
myPython = prev.python312.withPackages myPackages;
macOver = file: og:
if prev.stdenv.isDarwin then
(prev.callPackage file {}) else