Skip to content

Commit

Permalink
Merge pull request Normation#90 from jooooooon/bug_3785/migrate_old_a…
Browse files Browse the repository at this point in the history
…pi_accounts_to_have_an_id

Bug 3785/migrate old api accounts to have an
  • Loading branch information
jooooooon committed Jul 25, 2013
2 parents 9c37467 + 9ce2bc6 commit 7748905
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions rudder-webapp/SOURCES/rudder-upgrade
Expand Up @@ -51,6 +51,7 @@ set -e
# - 2.7.0 : Add FileFormat 3 to 4 migration script
# - 2.7.0 : Migration LDAP to add the global parameter OU
# - 2.7.0 : Migration LDAP to add the defaut parameter for file edition
# - 2.7.0~rc1 : LDAP migration to add a UUID to REST API accounts
#####################################################################################

# Some variables
Expand Down Expand Up @@ -390,6 +391,20 @@ if [ ${LDAP_EXISTS} -ne 0 ]; then
/opt/rudder/bin/ldapadd -x -D "${LDAP_USER}" -w "${LDAP_PASSWORD}" -H ldap://localhost -f ${RUDDER_UPGRADE_TOOLS}/rudder-upgrade-LDAP-schema-2.6-2.7-add-default-global-parameter.ldif >/dev/null 2>&1
echo " Done."
fi

# - 2.7.0~rc1 : LDAP migration to add a UUID to REST API accounts
LDAP_TEST_OLD_API_ACCOUNTS=$(/opt/rudder/bin/ldapsearch -H ldap://localhost -x -w "${LDAP_PASSWORD}" -D "${LDAP_USER}" -b "ou=API Accounts,ou=Rudder,cn=rudder-configuration" -LLL dn 2>/dev/null | grep "^dn: cn=" | wc -l)
if [ ${LDAP_TEST_OLD_API_ACCOUNTS} -ne 0 ]; then
echo -n "INFO: Renaming API accounts to have a unique ID..."
/opt/rudder/bin/ldapsearch -H ldap://localhost -x -w "${LDAP_PASSWORD}" -D "${LDAP_USER}" -b "ou=API Accounts,ou=Rudder,cn=rudder-configuration" -LLL dn 2>/dev/null |\
grep "^dn: cn=" |\
while read line; do
NEW_UUID=$(uuidgen)
DN=$(echo ${line} | sed 's/^dn: \(.*\)$/\1/')
echo -e "${DN}\napiAccountId=${NEW_UUID}" | /opt/rudder/bin/ldapmodrdn -H ldap://localhost -x -w "${LDAP_PASSWORD}" -D "${LDAP_USER}" > /dev/null 2>&1
done
echo " Done."
fi
fi

# For every upgrade, we force the root server to run a new inventory on the next CFEngine run
Expand Down

0 comments on commit 7748905

Please sign in to comment.