Skip to content

Commit

Permalink
Add exist_ok param for PKIServer.copyfile()
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Apr 22, 2024
1 parent ef5c1ed commit 218f7d2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
6 changes: 5 additions & 1 deletion base/server/python/pki/server/__init__.py
Expand Up @@ -695,7 +695,11 @@ def copydirs(self, source, dest, force=False):
mode=DEFAULT_DIR_MODE,
force=force)

def copyfile(self, source, dest, params=None, force=False):
def copyfile(self, source, dest, params=None, exist_ok=False, force=False):

if os.path.exists(dest) and exist_ok:
logger.info('Reusing %s', dest)
return

logger.info('Creating %s', dest)

Expand Down
6 changes: 5 additions & 1 deletion base/server/python/pki/server/deployment/__init__.py
Expand Up @@ -765,7 +765,10 @@ def install_cert_chain(self):
# validation there. This is only usually necessary when
# installing a non-CA subsystem on a fresh system.

self.instance.copyfile(cert_chain_path, destination)
self.instance.copyfile(
cert_chain_path,
destination,
exist_ok=True)

def import_ds_ca_cert(self):

Expand Down Expand Up @@ -831,6 +834,7 @@ def create_cs_cfg(self, subsystem):
source_cs_cfg,
tmp_cs_cfg,
params=self.mdict,
exist_ok=True,
force=True)

# Merge temporary CS.cfg into /var/lib/pki/<instance>/conf/<subsystem>/CS.cfg
Expand Down
Expand Up @@ -287,7 +287,8 @@ def spawn(self, deployer):
instance.copyfile(
pki_source_proxy_conf,
pki_target_proxy_conf,
params=deployer.mdict)
params=deployer.mdict,
exist_ok=True)

elif deployer.subsystem_type == "TPS":

Expand All @@ -301,7 +302,8 @@ def spawn(self, deployer):
instance.copyfile(
deployer.mdict['pki_source_phone_home_xml'],
pki_target_phone_home_xml,
params=deployer.mdict)
params=deployer.mdict,
exist_ok=True)

instance.load()

Expand Down
3 changes: 2 additions & 1 deletion base/server/python/pki/server/instance.py
Expand Up @@ -362,7 +362,8 @@ def create_registry(self):
'pki_group': self.group,
'pki_instance_name': self.name,
'pki_instance_path': self.base_dir
})
},
exist_ok=True)

def load(self):

Expand Down
6 changes: 5 additions & 1 deletion base/server/python/pki/server/upgrade.py
Expand Up @@ -88,7 +88,11 @@ def copydirs(self, source, dest, force=False):
self.instance.copydirs(source, dest, force=force)

def copyfile(self, source, dest, force=False):
self.instance.copyfile(source, dest, force=force)
self.instance.copyfile(
source,
dest,
exist_ok=True,
force=force)

def init_scriptlet(self, scriptlet):
scriptlet.instance = self.instance
Expand Down
11 changes: 6 additions & 5 deletions base/server/upgrade/10.10.2/01-AddProfileCaAuditSigningCert.py
Expand Up @@ -41,13 +41,14 @@ def upgrade_subsystem(self, instance, subsystem):

pki.util.store_properties(opath, oconfig)

# now handle new profile
logger.info('Creating caAuditSigningCert.cfg')
path = os.path.join(subsystem.base_dir, 'profiles', 'ca', 'caAuditSigningCert.cfg')
self.backup(path)

if not os.path.exists(path):
logger.info('Creating caAuditSigningCert.cfg')
self.backup(path)
instance.copyfile('/usr/share/pki/ca/profiles/ca/caAuditSigningCert.cfg', path)
instance.copyfile(
'/usr/share/pki/ca/profiles/ca/caAuditSigningCert.cfg',
path,
exist_ok=True)

logger.info('Adding caAuditSigningCert into profile.list')
profile_list = subsystem.config.get('profile.list').split(',')
Expand Down
10 changes: 6 additions & 4 deletions base/server/upgrade/10.9.0/02-AddACMEServerCertProfile.py
Expand Up @@ -25,12 +25,14 @@ def upgrade_subsystem(self, instance, subsystem):
if subsystem.name != 'ca':
return

logger.info('Creating acmeServerCert.cfg')
path = os.path.join(subsystem.base_dir, 'profiles', 'ca', 'acmeServerCert.cfg')
self.backup(path)

if not os.path.exists(path):
logger.info('Creating acmeServerCert.cfg')
self.backup(path)
instance.copyfile('/usr/share/pki/ca/profiles/ca/acmeServerCert.cfg', path)
instance.copyfile(
'/usr/share/pki/ca/profiles/ca/acmeServerCert.cfg',
path,
exist_ok=True)

logger.info('Adding acmeServerCert into profile.list')
profile_list = subsystem.config.get('profile.list').split(',')
Expand Down
11 changes: 6 additions & 5 deletions base/server/upgrade/10.9.0/04-AddMissingCertProfiles.py
Expand Up @@ -55,13 +55,14 @@ def upgrade_subsystem(self, instance, subsystem):
# Create the right file name
file_name = '{}.cfg'.format(profile)

logger.info('Creating %s', file_name)
path = os.path.join(subsystem.base_dir, 'profiles', 'ca', file_name)
self.backup(path)

if not os.path.exists(path):
logger.info('Creating %s', file_name)
self.backup(path)
# copy file from rpm installed to installed instance
instance.copyfile('/usr/share/pki/ca/profiles/ca/{}'.format(file_name), path)
instance.copyfile(
'/usr/share/pki/ca/profiles/ca/{}'.format(file_name),
path,
exist_ok=True)

logger.info('Adding %s into profile.list', file_name)
if profile not in profile_list:
Expand Down

0 comments on commit 218f7d2

Please sign in to comment.