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:
+27
-5
@@ -1,5 +1,7 @@
|
|||||||
# vim: set ft=python :
|
# vim: set ft=python :
|
||||||
|
|
||||||
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
def bw_unlock():
|
def bw_unlock():
|
||||||
"""Unlocks the BitWarden CLI and adds the resulting session code to the
|
"""Unlocks the BitWarden CLI and adds the resulting session code to the
|
||||||
current environment variables. Also returns the code for them."""
|
current environment variables. Also returns the code for them."""
|
||||||
@@ -15,6 +17,24 @@ def bw_unlock():
|
|||||||
$BW_SESSION = token
|
$BW_SESSION = token
|
||||||
return 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):
|
def _glrestart(args):
|
||||||
sudo nixos-container run gitlab -- systemctl restart gitlab
|
sudo nixos-container run gitlab -- systemctl restart gitlab
|
||||||
sudo nixos-container run gitlab -- systemctl restart nginx
|
sudo nixos-container run gitlab -- systemctl restart nginx
|
||||||
@@ -73,16 +93,18 @@ def _bake(args):
|
|||||||
copier copy @(str(templates / args[0])) .
|
copier copy @(str(templates / args[0])) .
|
||||||
|
|
||||||
aliases['glrestart'] = _glrestart
|
aliases['glrestart'] = _glrestart
|
||||||
aliases['cfetch'] = _cfetch
|
|
||||||
aliases['bake'] = _bake
|
aliases['bake'] = _bake
|
||||||
aliases['rebuild'] = _rebuild
|
aliases['unlock'] = _unlock
|
||||||
aliases['yaml2json'] = _yaml2json
|
aliases['cfetch'] = _cfetch
|
||||||
|
aliases['ivr'] = _ivr
|
||||||
|
aliases['newdock'] = _newdock
|
||||||
|
aliases['pip_extras'] = _pip_extras
|
||||||
aliases['py2env'] = _py2env
|
aliases['py2env'] = _py2env
|
||||||
aliases['py3env'] = _py3env
|
aliases['py3env'] = _py3env
|
||||||
|
aliases['rebuild'] = _rebuild
|
||||||
aliases['rundock'] = _rundock
|
aliases['rundock'] = _rundock
|
||||||
aliases['newdock'] = _newdock
|
|
||||||
aliases['unknown_host'] = _unknown_host
|
aliases['unknown_host'] = _unknown_host
|
||||||
aliases['pip_extras'] = _pip_extras
|
aliases['yaml2json'] = _yaml2json
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
# Other random nice-to-have things
|
# Other random nice-to-have things
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ let
|
|||||||
virtualenv
|
virtualenv
|
||||||
];
|
];
|
||||||
|
|
||||||
myPython = prev.python3.withPackages myPackages;
|
myPython = prev.python312.withPackages myPackages;
|
||||||
macOver = file: og:
|
macOver = file: og:
|
||||||
if prev.stdenv.isDarwin then
|
if prev.stdenv.isDarwin then
|
||||||
(prev.callPackage file {}) else
|
(prev.callPackage file {}) else
|
||||||
|
|||||||
Reference in New Issue
Block a user