beta.blog

Archive for November, 2016

hybris: run a platform update via curl

by on Nov.20, 2016, under Programming

You might have been wondering if it’s possible to trigger a hybris commerce suite platform update via curl. It’s actually quite easy to do so by enabling the ws410 extension as described in the hybris wiki.

Alternatively, you could also just use the build callback ant updatesystem in the platform folder in order to trigger an update. This approach is recommended and you may find further instructions on how to do it here (requires hybris 5.5 or higher): hybris: run a platform update via command line

If you’re unable to use the ws410 extension for whatever reason and if the buildcallback isn’t an option for you neither, you may still trigger an update through the hybris administration console (hac) but it’s slightly more complicated to do so due to the CSRF (Cross-Site-Request-Forgery) token being used for security purposes.

Please keep in mind that I do not recommend using this method in productive systems at all for the following reason: the update calls the following page /hac/platform/init/execute. It is the same controller used for initializing the system (!). That means if you send a wrong payload, an initialization will be started rather than a platform update, potentially resulting in a complete loss of data. Thus you have to be very careful when using this approach.

Anyways, here’s the script. Tested on macOS with tools that came with the default installation. Needless to say, it will work on any *nix system:

#!/bin/bash

# ----------------------------------------
USERNAME="admin"
PASSWORD=""
BASEURL="http://localhost:9001/hac"
# ----------------------------------------

echo "Accessing login page..."
csrf=$(curl -s -c cookies.txt -b cookies.txt -L "$BASEURL/login.jsp" | egrep -o -m1 "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}")

jsessionid=$(cat cookies.txt | egrep -o -m1 "[A-F0-9]{32}")

echo "Logging in..."
curl -s -c cookies.txt -b cookies.txt -L "$BASEURL/j_spring_security_check" -H 'Cookie: JSESSIONID=$jsessionid' -d "j_username=$USERNAME" -d "j_password=$PASSWORD" -d "_csrf=$csrf" > /dev/null

echo "Going to update page..."
csrf=$(curl -s -c cookies.txt -b cookies.txt -L "$BASEURL/platform/update" -H 'Cookie: JSESSIONID=$jsessionid' | egrep -o -m1 "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}")

echo "Executing platform update..."
echo $(curl -s -c cookies.txt -b cookies.txt -L -H 'Cookie: JSESSIONID=$jsessionid' -H "X-CSRF-Token: $csrf" -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" -H "Content-Type: application/json; charset=UTF-8" -X POST "$BASEURL/platform/init/execute" --data-binary '{

"dropTables": false,

"clearHMC": true,
"createEssentialData": true,
"localizeTypes": true,
"allParameters":{},
"initMethod": "UPDATE"

}' | egrep -o -m1 '"success":[a-z]{4}')
Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!