WHEW. GPG decryption now works correctly.
This commit is contained in:
parent
2545138ae1
commit
2b9b78d3f9
@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import vaultpass
|
|
||||||
|
|
||||||
cfg = vaultpass.config.LocalFile('/tmp/vaultpass.xml')
|
|
||||||
cfg.main()
|
|
||||||
|
|
@ -46,8 +46,10 @@ class Config(object):
|
|||||||
def decryptGpg(self, gpg_xml):
|
def decryptGpg(self, gpg_xml):
|
||||||
home = gpg_xml.attrib.get('gpgHome')
|
home = gpg_xml.attrib.get('gpgHome')
|
||||||
tag = gpg_xml.tag
|
tag = gpg_xml.tag
|
||||||
ns_xml = self.xml.find(tag)
|
ns_search = './/{0}'.format(tag)
|
||||||
xml = self.stripNS(obj = ns_xml).tag
|
ns_xml = self.namespaced_xml.find(ns_search)
|
||||||
|
search = './/{0}'.format(self.stripNS(obj = ns_xml).tag)
|
||||||
|
xml = self.xml.find(search)
|
||||||
fpath = gpg_xml.text
|
fpath = gpg_xml.text
|
||||||
if not self.gpg:
|
if not self.gpg:
|
||||||
self.gpg = gpg_handler.GPG(home = home)
|
self.gpg = gpg_handler.GPG(home = home)
|
||||||
@ -129,15 +131,14 @@ class Config(object):
|
|||||||
return(None)
|
return(None)
|
||||||
|
|
||||||
def parseGpg(self):
|
def parseGpg(self):
|
||||||
gpg_elem_found = False # Change to True if we find any GPG-encrypted elems
|
gpg_elem_found = False
|
||||||
search = []
|
search = []
|
||||||
for x in self.gpg_elems:
|
for x in self.gpg_elems:
|
||||||
search.append("local-name()='{0}'".format(x))
|
search.append("local-name()='{0}'".format(x))
|
||||||
search = '[{0}]'.format(' or '.join(search))
|
search = '//*[{0}]'.format(' or '.join(search))
|
||||||
print(search)
|
gpg_elems = self.namespaced_xml.xpath(search)
|
||||||
gpg_elems = self.namespaced_xml.findall('|'.join(search))
|
|
||||||
for e in gpg_elems:
|
for e in gpg_elems:
|
||||||
print(e)
|
self.decryptGpg(e)
|
||||||
return(gpg_elem_found)
|
return(gpg_elem_found)
|
||||||
|
|
||||||
def parseRaw(self, parser = None):
|
def parseRaw(self, parser = None):
|
||||||
@ -166,7 +167,7 @@ class Config(object):
|
|||||||
_logger.debug('Stripping namespace.')
|
_logger.debug('Stripping namespace.')
|
||||||
# https://stackoverflow.com/questions/30232031/how-can-i-strip-namespaces-out-of-an-lxml-tree/30233635#30233635
|
# https://stackoverflow.com/questions/30232031/how-can-i-strip-namespaces-out-of-an-lxml-tree/30233635#30233635
|
||||||
xpathq = "descendant-or-self::*[namespace-uri()!='']"
|
xpathq = "descendant-or-self::*[namespace-uri()!='']"
|
||||||
if not obj:
|
if obj is None:
|
||||||
_logger.debug('No XML object selected; using instance\'s xml and tree.')
|
_logger.debug('No XML object selected; using instance\'s xml and tree.')
|
||||||
for x in (self.tree, self.xml):
|
for x in (self.tree, self.xml):
|
||||||
for e in x.xpath(xpathq):
|
for e in x.xpath(xpathq):
|
||||||
|
@ -13,8 +13,7 @@ class GPG(object):
|
|||||||
gpg = None
|
gpg = None
|
||||||
|
|
||||||
def __init__(self, home = None):
|
def __init__(self, home = None):
|
||||||
if home:
|
self.home = home
|
||||||
self.home = home
|
|
||||||
self.initHome()
|
self.initHome()
|
||||||
|
|
||||||
def decrypt(self, fpath):
|
def decrypt(self, fpath):
|
||||||
@ -36,4 +35,5 @@ class GPG(object):
|
|||||||
if not os.path.isdir(self.home):
|
if not os.path.isdir(self.home):
|
||||||
raise ValueError('GPG home does not exist')
|
raise ValueError('GPG home does not exist')
|
||||||
_logger.debug('Set GPG home to explicitly specified value {0}'.format(self.home))
|
_logger.debug('Set GPG home to explicitly specified value {0}'.format(self.home))
|
||||||
|
self.gpg = gpg.Context(home_dir = self.home)
|
||||||
return(None)
|
return(None)
|
||||||
|
Reference in New Issue
Block a user