Skip to content

Commit

Permalink
Merge pull request #15224 from cloudsufi/cConf-log-fixup
Browse files Browse the repository at this point in the history
Remove the LDAP username from the logs files generated and shipped fo…
  • Loading branch information
rmstar authored Jul 12, 2023
2 parents 86fe213 + d7ea11a commit 02d3ff0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cdap-support-bundle/bin/collect_support_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import subprocess
import sys
from datetime import datetime
import re

parser = argparse.ArgumentParser(description='Log collector program for CDAP.')
parser.add_argument(
Expand Down Expand Up @@ -627,6 +628,17 @@ def main(kube_namespace, username, password, cdap_ns, pipeline_name, run_id, run
print(f'Logs collection completed. Please find {directoryName}.tar.gz in current directory')
exit()

def remove_security_authorization_from_cconf_log(cconf_file_output):
flag = True
while flag:
start = cconf_file_output.find("""<property>
<name>security.authorization.extension.config.""")
if start != -1:
end = cconf_file_output.find("""</property>""", start)
cconf_file_output = cconf_file_output[0:start] + cconf_file_output[end + 11:].strip()
else:
flag = False
return cconf_file_output

def log_file_write(pathName, filename, fileWriteMode, contentToWrite, fileExt="log"):
with open(f"{pathName}/{filename}.{fileExt}", fileWriteMode) as f:
Expand Down Expand Up @@ -673,6 +685,8 @@ def log_commands_processor(commandLists, directoryName, cdap_ns, pipeline_name,
placeholderCommand = x["forEachCommand"]
command = placeholderCommand.replace(x["placeholderString"], a)
for_command_output = subprocess.getoutput(command)
if x["parentFolder"] == "config_map_info" and re.search("-cconf$", a):
for_command_output = remove_security_authorization_from_cconf_log(for_command_output)
directory_name = os.path.join(directoryName , x["parentFolder"])
log_file_write(directory_name , f'{x["childFileName"]}-{a}', "a", for_command_output, x["fileExt"])

Expand All @@ -682,4 +696,4 @@ def log_commands_processor(commandLists, directoryName, cdap_ns, pipeline_name,

if __name__ == "__main__":
args = parser.parse_args()
main(args.kube_namespace, args.username, args.password, args.cdap_ns, args.pipeline_name, args.run_id, args.runtime_namespace)
main(args.kube_namespace, args.username, args.password, args.cdap_ns, args.pipeline_name, args.run_id, args.runtime_namespace)

0 comments on commit 02d3ff0

Please sign in to comment.