Skip to content

Commit

Permalink
Move authdb methods into PKIDeployer
Browse files Browse the repository at this point in the history
  • Loading branch information
edewata committed Jun 19, 2024
1 parent b27cf23 commit 28595ab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
29 changes: 29 additions & 0 deletions base/server/python/pki/server/deployment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def __init__(self):
self.startup_timeout = None
self.request_timeout = None

self.authdb_url = None

self.force = False
self.remove_conf = False
self.remove_logs = False
Expand Down Expand Up @@ -223,6 +225,33 @@ def ds_init(self):
self.mdict['pki_ds_secure_connection_ca_pem_file'])
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_DEMAND)

def authdb_init(self):

hostname = self.mdict['pki_authdb_hostname']
port = self.mdict['pki_authdb_port']

if config.str2bool(self.mdict['pki_authdb_secure_conn']):
scheme = 'ldaps'
else:
scheme = 'ldap'

self.authdb_url = scheme + '://' + hostname + ':' + port

def authdb_base_dn_exists(self):
try:
connection = ldap.initialize(self.authdb_url)
results = connection.search_s(
self.mdict['pki_authdb_basedn'],
ldap.SCOPE_BASE)

if results is None or len(results) == 0:
return False

return True

except ldap.NO_SUCH_OBJECT:
return False

def init_logger(self, filename):

pki_logger = logging.getLogger('pki')
Expand Down
30 changes: 0 additions & 30 deletions base/server/python/pki/server/deployment/pkiparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import argparse
import getpass
import json
import ldap
import logging
import os
import string
Expand Down Expand Up @@ -304,7 +303,6 @@ def __init__(self, description, epilog, deployer=None):
help='Run in debug mode')

self.indent = 0
self.authdb_connection = None

self.mdict = deployer.mdict

Expand Down Expand Up @@ -619,34 +617,6 @@ def validate_user_config(self, filename):

logger.warning(message)

def authdb_connect(self):

hostname = self.mdict['pki_authdb_hostname']
port = self.mdict['pki_authdb_port']

if config.str2bool(self.mdict['pki_authdb_secure_conn']):
protocol = 'ldaps'
else:
protocol = 'ldap'

self.authdb_connection = ldap.initialize(
protocol + '://' + hostname + ':' + port)
self.authdb_connection.search_s('', ldap.SCOPE_BASE)

def authdb_base_dn_exists(self):
try:
results = self.authdb_connection.search_s(
self.mdict['pki_authdb_basedn'],
ldap.SCOPE_BASE)

if results is None or len(results) == 0:
return False

return True

except ldap.NO_SUCH_OBJECT:
return False

def get_server_status(self, system_type, system_uri):
parse = urlparse(self.mdict[system_uri])
# Because this is utilized exclusively during pkispawn, we can safely
Expand Down
4 changes: 2 additions & 2 deletions base/server/python/pki/server/pkispawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ def main(argv):
deployer.set_property('pki_authdb_basedn', basedn)

try:
parser.authdb_connect()
if parser.authdb_base_dn_exists():
deployer.authdb_init()
if deployer.authdb_base_dn_exists():
break
else:
parser.print_text('ERROR: base DN does not exist')
Expand Down

0 comments on commit 28595ab

Please sign in to comment.