message: Move drushCron keycloak integration into a separate function to support upgrade paths
diff: @@ -827,18 +827,6 @@ EOF
  "scopes": ["drushCacheClear:production","drushCacheClear:development"],
  "policies": ["User has access to project","Users role for project is Guest"]
  }
  -EOF
  -
  - /opt/jboss/keycloak/bin/kcadm.sh create clients/$CLIENT_ID/authz/resource-server/permission/scope --config $CONFIG_PATH -r lagoon -f - <<EOF
  -{
  - "name": "Run Drush cron",
  - "type": "scope",
  - "logic": "POSITIVE",
  - "decisionStrategy": "UNANIMOUS",
  - "resources": ["task"],
  - "scopes": ["drushCron:production","drushCron:development"],
  - "policies": ["User has access to project","Users role for project is Guest"]
  -}
  EOF
  /opt/jboss/keycloak/bin/kcadm.sh create clients/$CLIENT_ID/authz/resource-server/permission/scope --config $CONFIG_PATH -r lagoon -f - <<EOF
  @@ -1305,6 +1293,31 @@ function add_group_viewall {
  EOF
  }
  +function configure_task_cron {
  +
  + CLIENT_ID=$(/opt/jboss/keycloak/bin/kcadm.sh get -r lagoon clients?clientId=api --config $CONFIG_PATH | python -c 'import sys, json; print json.load(sys.stdin)[0]["id"]')
  + cron_task_groups=$(/opt/jboss/keycloak/bin/kcadm.sh get -r lagoon clients/$CLIENT_ID/authz/resource-server/permission?name=Run+Drush+cron --config $CONFIG_PATH)
  +
  + if [ "$cron_task_groups" != "[ ]" ]; then
  + echo "group:drushCron already configured"
  + return 0
  + fi
  +
  + echo Configuring group:drushCron
  +
  + /opt/jboss/keycloak/bin/kcadm.sh create clients/$CLIENT_ID/authz/resource-server/permission/scope --config $CONFIG_PATH -r lagoon -f - <<EOF
  +{
  + "name": "Run Drush cron",
  + "type": "scope",
  + "logic": "POSITIVE",
  + "decisionStrategy": "UNANIMOUS",
  + "resources": ["task"],
  + "scopes": ["drushCron:production","drushCron:development"],
  + "policies": ["User has access to project","Users role for project is Guest"]
  +}
  +EOF
  +}
  +
  function configure_keycloak {
  until is_keycloak_running; do
  echo Keycloak still not running, waiting 5 seconds
  @@ -1322,6 +1335,7 @@ function configure_keycloak {
  configure_opendistro_security_client
  configure_api_client
  add_group_viewall
  + configure_task_cron
  echo "Config of Keycloak done. Log in via admin user '$KEYCLOAK_ADMIN_USER' and password '$KEYCLOAK_ADMIN_PASSWORD'"
  }
  