Fix parsing of smartcardoptions config
With the previous code, a trailing newline would result in an empty space being part of the list. When this is passed to keytool, it fails with "Illegal option: ".
Instead of doing overly complicated regex based string substitution
followed by parametrized splitting, we can simply use .split()
without
any parameters, and Python will automatically strip any whitespace.
Example:
>>> import yaml, re
>>> parsed = yaml.safe_load('''
... smartcardoptions: |
... -storetype PKCS11
... -providerClass sun.security.pkcs11.SunPKCS11
... -providerArg /etc/pkcs11_java.cfg
...
... ''')
>>> parsed['smartcardoptions']
'-storetype PKCS11\n-providerClass sun.security.pkcs11.SunPKCS11\n-providerArg /etc/pkcs11_java.cfg\n'
With the old approach (note the empty string at the end):
>>> re.sub(r'\s+', r' ', parsed['smartcardoptions']).split(' ')
['-storetype', 'PKCS11', '-providerClass', 'sun.security.pkcs11.SunPKCS11', '-providerArg', '/etc/pkcs11_java.cfg', '']
With the fix:
>>> parsed['smartcardoptions'].split()
['-storetype', 'PKCS11', '-providerClass', 'sun.security.pkcs11.SunPKCS11', '-providerArg', '/etc/pkcs11_java.cfg']
Edited by Hans-Christoph Steiner