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

Update PKI_VERSION in tomcat.conf #4510

Merged
merged 1 commit into from
Jul 21, 2023
Merged
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
39 changes: 29 additions & 10 deletions base/common/python/pki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,18 @@ class PropertyFile(object):
are maintained internally as a list of properties.

Properties are strings of the format <name> <delimiter> <value> where
'=' is the default delimiter.
'=' is the default delimiter. The value can optionally be quoted.
"""

def __init__(self, filename, delimiter='='):
def __init__(self, filename, delimiter='=', quote=None):
""" Constructor """

if quote and len(quote) > 1:
raise Exception('Invalid quote character: ' + quote)

self.filename = filename
self.delimiter = delimiter
self.quote = quote

self.lines = []

Expand Down Expand Up @@ -568,8 +573,6 @@ def get(self, name):
:type name: str
:return: str -- value of property
"""
result = None

for line in self.lines:

# parse <key> <delimiter> <value>
Expand All @@ -582,10 +585,16 @@ def get(self, name):
key = match.group(1)
value = match.group(2)

if key.lower() == name.lower():
return value
if key.lower() != name.lower():
continue

# remove quotes if any
if self.quote and value.startswith(self.quote) and value.endswith(self.quote):
value = value[1:-1]

return value

return result
return None

def set(self, name, value, index=None):
"""
Expand All @@ -599,6 +608,9 @@ def set(self, name, value, index=None):
:type index: int
:return: None
"""
if self.quote:
value = self.quote + value + self.quote

for i, line in enumerate(self.lines):

# parse <key> <delimiter> <value>
Expand Down Expand Up @@ -640,8 +652,15 @@ def remove(self, name):
key = match.group(1)
value = match.group(2)

if key.lower() == name.lower():
self.lines.pop(i)
return value
if key.lower() != name.lower():
continue

self.lines.pop(i)

# remove quotes if any
if self.quote and value.startswith(self.quote) and value.endswith(self.quote):
value = value[1:-1]

return value

return None
5 changes: 3 additions & 2 deletions base/common/python/pki/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class PKIUpgradeTracker(object):

def __init__(self, name, filename, delimiter='=',
version_key='PKI_VERSION',
index_key='PKI_UPGRADE_INDEX'):
index_key='PKI_UPGRADE_INDEX',
quote=None):

self.name = name
self.filename = filename
Expand All @@ -54,7 +55,7 @@ def __init__(self, name, filename, delimiter='=',
# properties must be read and written immediately to avoid
# interfering with scriptlets that update the same file

self.properties = pki.PropertyFile(filename, delimiter)
self.properties = pki.PropertyFile(filename, delimiter=delimiter, quote=quote)

# run all scriptlets for each upgrade version
self.remove_index()
Expand Down
2 changes: 1 addition & 1 deletion base/server/python/pki/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def create(self, force=False):
# copy /etc/tomcat/tomcat.conf
self.copy(Tomcat.TOMCAT_CONF, self.tomcat_conf, force=force)

tomcat_conf = pki.PropertyFile(self.tomcat_conf)
tomcat_conf = pki.PropertyFile(self.tomcat_conf, quote='"')
tomcat_conf.read()

# store JAVA_HOME from /usr/share/pki/etc/pki.conf
Expand Down
3 changes: 2 additions & 1 deletion base/server/python/pki/server/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def get_tracker(self):
'%s instance' % self.instance,
INSTANCE_TRACKER % self.instance.conf_dir,
version_key='PKI_VERSION',
index_key='PKI_UPGRADE_INDEX')
index_key='PKI_UPGRADE_INDEX',
quote='"')

return self.tracker

Expand Down
2 changes: 1 addition & 1 deletion base/server/share/conf/tomcat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TOMCAT_LOG="/var/log/pki/[pki_instance_name]/tomcat-initd.log"
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)

PKI_VERSION=[application_version]
PKI_VERSION="[application_version]"

# Debian settings
TOMCAT_USER="[pki_user]"
Expand Down
Loading