Created
May 5, 2017 14:47
-
-
Save wadewegner/452c646b95bc7d87a3f7234b72c465f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# JWT login | |
sfdx force:auth:jwt:grant --clientid ${CLIENT_ID} \ | |
--jwtkeyfile ${JWT_KEY_FILE} --username ${HUB_USERNAME} \ | |
--setdefaultdevhubusername > /dev/null | |
# Create an org | |
created="$(sfdx force:org:create -s -j '{ | |
"Company": "StreamSets", | |
"Country": "US", | |
"LastName": "Tester", | |
"Email": "[email protected]", | |
"Edition": "Enterprise", | |
"OrgPreferences" : { | |
"S1DesktopEnabled" : true | |
} | |
}' --json)" | |
orgId="$(echo ${created} | jq -r .orgId)" | |
username="$(echo ${created} | jq -r .username)" | |
# Emit username | |
echo -n ${username} | |
# Generate user password | |
password="$(sfdx force:user:password:generate -u ${username} --json | jq -r .password)" | |
# Get accessToken, instanceUrl etc | |
org="$(sfdx force:org:describe -u ${username} --json)" | |
accessToken="$(echo ${org} | jq -r .accessToken)" | |
instanceUrl="$(echo ${org} | jq -r .instanceUrl)" | |
# Get my IP address | |
myip="$(curl -s http://ipinfo.io/ip)" | |
# Wait until new instance resolves | |
until host ${instanceUrl} > /dev/null | |
do | |
sleep 10 | |
done | |
# Set IP range | |
opened="$(curl -s ${instanceUrl}/services/Soap/m/39.0/${orgId} \ | |
-H "Content-Type: text/xml; charset=UTF-8" \ | |
-H "SOAPAction: updateMetadata" \ | |
-d '<?xml version="1.0" encoding="UTF-8"?> | |
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<env:Header> | |
<SessionHeader xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<sessionId>'${accessToken}'</sessionId> | |
</SessionHeader> | |
</env:Header> | |
<env:Body> | |
<m:updateMetadata xmlns:m="http://soap.sforce.com/2006/04/metadata" xmlns:sobj="null"> | |
<m:metadata xsi:type="m:SecuritySettings"> | |
<m:networkAccess> | |
<m:ipRanges> | |
<m:start>'${myip}'</m:start> | |
<m:end>'${myip}'</m:end> | |
</m:ipRanges> | |
</m:networkAccess> | |
</m:metadata> | |
</m:updateMetadata> | |
</env:Body> | |
</env:Envelope>')" | |
# Test login with username and password | |
login="$(curl -s https://test.salesforce.com/services/Soap/u/39.0 \ | |
-H "Content-Type: text/xml; charset=UTF-8" \ | |
-H "SOAPAction: login" \ | |
-d '<?xml version="1.0" encoding="utf-8" ?> | |
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> | |
<env:Body> | |
<n1:login xmlns:n1="urn:partner.soap.sforce.com"> | |
<n1:username>'${username}'</n1:username> | |
<n1:password>'${password}'</n1:password> | |
</n1:login> | |
</env:Body> | |
</env:Envelope>')" | |
if [[ $(echo ${login} | xpath '/soapenv:Envelope/soapenv:Body/loginResponse') ]]; then | |
# No loginResponse! | |
exit 1 | |
fi | |
# All is good | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment