Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Created July 27, 2017 16:38
Show Gist options
  • Save wadewegner/ef77520073dd60dbb63e295ef941c5f9 to your computer and use it in GitHub Desktop.
Save wadewegner/ef77520073dd60dbb63e295ef941c5f9 to your computer and use it in GitHub Desktop.
A bash script that uses the Salesforce CLI to determine if the org has the dev hub enabled
# specify your username or alias
usernameOrAlias="my@org.com"
# return a json result of
org="$(sfdx force:org:display -u ${usernameOrAlias} --json)"
# parse response
result="$(echo ${org} | jq -r .result)"
accessToken="$(echo ${result} | jq -r .accessToken)"
instanceUrl="$(echo ${result} | jq -r .instanceUrl)"
id="$(echo ${result} | jq -r .id)"
# use curl to call the Tooling API and run a query
query="SELECT+DurableId,+SettingValue+FROM+OrganizationSettingsDetail+WHERE+SettingName+\=+\'ScratchOrgManagementPref\'"
http="${instanceUrl}/services/data/v40.0/tooling/query/\?q\=${query}"
flags="-H 'Authorization: Bearer ${accessToken}'"
hub=$(eval curl $http $flags --silent)
# parse response
size="$(echo ${hub} | jq -r .size)"
if [[ $size -eq 0 ]];
then
echo "${id} is not a dev hub"
exit 0
fi
records="$(echo ${hub} | jq -r .records)"
value="$(echo ${records} | jq -r .[].SettingValue)"
# evaluate the setting value
if $value === 'true'
then
echo "${id} is a dev hub"
else
echo "${id} is not a dev hub"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment