Skip to content

Commit ae7ecc2

Browse files
authored
Merge pull request #6871 from arrabito/fixgetESparams02
[8.0] fix (Configuration): fix ES access using certificates
2 parents a055642 + be56d25 commit ae7ecc2

File tree

1 file changed

+74
-71
lines changed

1 file changed

+74
-71
lines changed

src/DIRAC/ConfigurationSystem/Client/Utilities.py

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -450,26 +450,85 @@ def getElasticDBParameters(fullname):
450450
cs_path = getDatabaseSection(fullname)
451451
parameters = {}
452452

453-
# Check mandatory parameters first: Password, User
454-
result = gConfig.getOption(cs_path + "/Password")
453+
# Check if connection is through certificates and get certificate parameters
454+
# Elasticsearch use certs
455+
result = gConfig.getOption(cs_path + "/CRT")
455456
if not result["OK"]:
456-
# No individual password found, try at the common place
457-
result = gConfig.getOption("/Systems/NoSQLDatabases/Password")
457+
# No CRT option found, try at the common place
458+
result = gConfig.getOption("/Systems/NoSQLDatabases/CRT")
458459
if not result["OK"]:
459-
return S_ERROR("Failed to get the configuration parameter: Password.")
460-
dbPass = result["Value"]
461-
parameters["Password"] = dbPass
460+
gLogger.debug("Failed to get the configuration parameter: CRT. Using False")
461+
certs = False
462+
else:
463+
certs = result["Value"]
464+
else:
465+
certs = result["Value"]
466+
parameters["CRT"] = certs
462467

463-
result = gConfig.getOption(cs_path + "/User")
464-
if not result["OK"]:
465-
# No individual user name found, try at the common place
466-
result = gConfig.getOption("/Systems/NoSQLDatabases/User")
468+
# If connection is through certificates get the mandatory parameters: ca_certs, client_key, client_cert
469+
if parameters["CRT"]:
470+
parameters["Password"] = None
471+
parameters["User"] = None
472+
473+
# Elasticsearch ca_certs
474+
result = gConfig.getOption(cs_path + "/ca_certs")
467475
if not result["OK"]:
468-
return S_ERROR("Failed to get the configuration parameter: User.")
469-
dbUser = result["Value"]
470-
parameters["User"] = dbUser
476+
# No CA certificate found, try at the common place
477+
result = gConfig.getOption("/Systems/NoSQLDatabases/ca_certs")
478+
if not result["OK"]:
479+
return S_ERROR("Failed to get the configuration parameter: ca_certs.")
480+
else:
481+
ca_certs = result["Value"]
482+
else:
483+
ca_certs = result["Value"]
484+
parameters["ca_certs"] = ca_certs
485+
486+
# Elasticsearch client_key
487+
result = gConfig.getOption(cs_path + "/client_key")
488+
if not result["OK"]:
489+
# No client private key found, try at the common place
490+
result = gConfig.getOption("/Systems/NoSQLDatabases/client_key")
491+
if not result["OK"]:
492+
return S_ERROR("Failed to get the configuration parameter: client_key.")
493+
else:
494+
client_key = result["Value"]
495+
else:
496+
client_key = result["Value"]
497+
parameters["client_key"] = client_key
498+
499+
# Elasticsearch client_cert
500+
result = gConfig.getOption(cs_path + "/client_cert")
501+
if not result["OK"]:
502+
# No cient certificate found, try at the common place
503+
result = gConfig.getOption("/Systems/NoSQLDatabases/client_cert")
504+
if not result["OK"]:
505+
return S_ERROR("Failed to get the configuration parameter: client_cert.")
506+
else:
507+
client_cert = result["Value"]
508+
else:
509+
client_cert = result["Value"]
510+
parameters["client_cert"] = client_cert
511+
# If connection is not through certificates get the mandatory parameters: Password, User
512+
else:
513+
result = gConfig.getOption(cs_path + "/Password")
514+
if not result["OK"]:
515+
# No individual password found, try at the common place
516+
result = gConfig.getOption("/Systems/NoSQLDatabases/Password")
517+
if not result["OK"]:
518+
return S_ERROR("Failed to get the configuration parameter: Password.")
519+
dbPass = result["Value"]
520+
parameters["Password"] = dbPass
471521

472-
# Check optional parameters: Host, Port, SSL, CRT, ca_certs, client_key, client_cert
522+
result = gConfig.getOption(cs_path + "/User")
523+
if not result["OK"]:
524+
# No individual user name found, try at the common place
525+
result = gConfig.getOption("/Systems/NoSQLDatabases/User")
526+
if not result["OK"]:
527+
return S_ERROR("Failed to get the configuration parameter: User.")
528+
dbUser = result["Value"]
529+
parameters["User"] = dbUser
530+
531+
# Check optional parameters: Host, Port, SSL
473532
result = gConfig.getOption(cs_path + "/Host")
474533
if not result["OK"]:
475534
# No host name found, try at the common place
@@ -516,62 +575,6 @@ def getElasticDBParameters(fullname):
516575
ssl = False if result["Value"].lower() in ("false", "no", "n") else True
517576
parameters["SSL"] = ssl
518577

519-
# Elasticsearch use certs
520-
result = gConfig.getOption(cs_path + "/CRT")
521-
if not result["OK"]:
522-
# No CRT option found, try at the common place
523-
result = gConfig.getOption("/Systems/NoSQLDatabases/CRT")
524-
if not result["OK"]:
525-
gLogger.debug("Failed to get the configuration parameter: CRT. Using False")
526-
certs = False
527-
else:
528-
certs = result["Value"]
529-
else:
530-
certs = result["Value"]
531-
parameters["CRT"] = certs
532-
533-
# Elasticsearch ca_certs
534-
result = gConfig.getOption(cs_path + "/ca_certs")
535-
if not result["OK"]:
536-
# No CA certificate found, try at the common place
537-
result = gConfig.getOption("/Systems/NoSQLDatabases/ca_certs")
538-
if not result["OK"]:
539-
gLogger.debug("Failed to get the configuration parameter: ca_certs. Using None")
540-
ca_certs = None
541-
else:
542-
ca_certs = result["Value"]
543-
else:
544-
ca_certs = result["Value"]
545-
parameters["ca_certs"] = ca_certs
546-
547-
# Elasticsearch client_key
548-
result = gConfig.getOption(cs_path + "/client_key")
549-
if not result["OK"]:
550-
# No client private key found, try at the common place
551-
result = gConfig.getOption("/Systems/NoSQLDatabases/client_key")
552-
if not result["OK"]:
553-
gLogger.debug("Failed to get the configuration parameter: client_key. Using None")
554-
client_key = None
555-
else:
556-
client_key = result["Value"]
557-
else:
558-
client_key = result["Value"]
559-
parameters["client_key"] = client_key
560-
561-
# Elasticsearch client_cert
562-
result = gConfig.getOption(cs_path + "/client_cert")
563-
if not result["OK"]:
564-
# No cient certificate found, try at the common place
565-
result = gConfig.getOption("/Systems/NoSQLDatabases/client_cert")
566-
if not result["OK"]:
567-
gLogger.debug("Failed to get the configuration parameter: client_cert. Using None")
568-
client_cert = None
569-
else:
570-
client_cert = result["Value"]
571-
else:
572-
client_cert = result["Value"]
573-
parameters["client_cert"] = client_cert
574-
575578
return S_OK(parameters)
576579

577580

0 commit comments

Comments
 (0)