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

Change of MUSIT DB password #200

Open
MichalTorma opened this issue Feb 28, 2025 · 2 comments
Open

Change of MUSIT DB password #200

MichalTorma opened this issue Feb 28, 2025 · 2 comments

Comments

@MichalTorma
Copy link

MichalTorma commented Feb 28, 2025

I've changed passwords used for accessing MUSIT datasets on the main IPT. For posterity - here is a process:

  1. access the /srv/ipt/ on the IPT and check the encoded password string in one MUSIT dataset (for example o_vascular) in /srv/ipt/resources/o_vascular/resources.xml. It will in tag. Store this old encoded password somewhere.
  2. Change the password with IPT UI to the new one
  3. Check the resources.xml again and copy the new encoded password
  4. Create,chmod +x and run a new bash script in /srv/ipt/change_pwd.sh
#!/bin/bash

OLD_PASSWORD="old_endoded_pwd"
NEW_PASSWORD="new_endoded_pwd"

# Find all resource.xml files and process them
find resources -name "resource.xml" -type f | while read -r file; do
    if grep -q "$OLD_PASSWORD" "$file"; then
        # Create backup first
        cp "$file" "${file}.bak"
        
        # Perform the replacement and capture if any changes were made
        if sed -i "s|$OLD_PASSWORD|$NEW_PASSWORD|g" "$file"; then
            echo "Updated password in: $file"
        fi
    fi
done
@MichalTorma
Copy link
Author

MichalTorma commented Feb 28, 2025

keeping this open for a few weeks in case we find some issues in publishing pipelines

@frafra
Copy link

frafra commented Mar 5, 2025

The -i option of sed can use a suffix to automatically create a backup copy when doing an in place replacement (at least on the GNU version).

Even if using sed could be quite safe in this specific case, I would suggest not doing a global find-and-replace over the entire file, but target a specific field, using an XML parser. jq is rather popular for handling json files, but there are wrappers around to handle yaml and xml files as well, provided by yq.

#!/bin/bash

set -eu

OLD_PASSWORD="old_endoded_pwd"
NEW_PASSWORD="new_endoded_pwd"

filter='(.resource.sources | (.sqlsource, .sqlsources[])? | select(.password == $old).password) |= $new'

for file in */resource.xml; do
  xq --xml-output --arg old "$OLD_PASSWORD" --arg new "$NEW_PASSWORD" "$filter" "$file" > "${file}.tmp"
  if cmp -s <(xq --xml-output . "$file") "${file}.tmp"; then
    rm "${file}.tmp"
  else
    mv "${file}.tmp" "$file"
    echo "Updated password in: $file"
  fi
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants