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

Migrations: Update notebook to omit Mongo credentials from commands when authentication disabled #672

Closed
eecavanna opened this issue Sep 11, 2024 · 2 comments · Fixed by #745
Assignees
Labels
enhancement New feature or request

Comments

@eecavanna
Copy link
Collaborator

eecavanna commented Sep 11, 2024

In migrate_10_8_0_to_11_0_0.ipynb, there is a cell that contains the following:

# Dump all collections from the "origin" database.
shell_command = f"""
  {mongodump} \
      --host='{cfg.origin_mongo_host}' \
      --port='{cfg.origin_mongo_port}' \
      --username='{cfg.origin_mongo_username}' \
      --password='{cfg.origin_mongo_password}' \
      --authenticationDatabase='admin' \
      --db='nmdc' \
      --gzip \
      --out='{cfg.origin_dump_folder_path}'
"""
completed_process = subprocess.run(shell_command, shell=True)
print(f"\nReturn code: {completed_process.returncode}")

Task

When the Mongo server does not have authentication enabled, omit the --username, --password, and --authenticationDatabase options from the command.

Do the same for similar cells.

@eecavanna
Copy link
Collaborator Author

I'm going to defer this until after the Berkeley schema roll out.

@eecavanna
Copy link
Collaborator Author

Here's a snippet that has the effect I want, although it infers the authentication enabled-ness from the value of the username configuration parameter (as opposed to getting an explicit indicator of authentication enabled-ness, assuming such a thing exists):

cli_options_for_authentication = f"""
      --username='{cfg.origin_mongo_username}' \
      --password='{cfg.origin_mongo_password}' \
      --authenticationDatabase='admin'
""" if cfg.origin_mongo_username not in ["", None] else ""

# Load the transformed collections into the origin server, replacing any same-named ones that are there.
shell_command = f"""
  {mongorestore} \
      --host='{cfg.origin_mongo_host}' \
      --port='{cfg.origin_mongo_port}' \
      {cli_options_for_authentication} \
      --gzip \
      --verbose \
      --dir='{cfg.transformer_dump_folder_path}' \
      --drop \
      --preserveUUID \
      --stopOnError
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
1 participant