github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/hack/jwt_generator.sh (about) 1 #!/usr/bin/env bash 2 3 function get_internal_tenant(){ 4 local INTERNAL_TENANT_ID=$(docker exec -i ${POSTGRES_CONTAINER} psql -qtAX -U "${DB_USER}" -h "${DB_HOST}" -p "${DB_PORT}" -d "${DB_NAME}" -c "SELECT id FROM business_tenant_mappings WHERE external_tenant = '3e64ebae-38b5-46a0-b1ed-9ccee153a0ae'") 5 echo "$INTERNAL_TENANT_ID" 6 } 7 8 function get_token(){ 9 local INTERNAL_TENANT_ID 10 read -r INTERNAL_TENANT_ID <<< $(get_internal_tenant) 11 12 local HEADER=$(echo "{ \"alg\": \"none\", \"typ\": \"JWT\" }" | base64 | tr '/+' '_-' | tr -d '=') 13 local PAYLOAD=$(echo "{ \"scopes\": \"webhook:write formation_template.webhooks:read runtime.webhooks:read application.local_tenant_id:write tenant_subscription:write tenant:write fetch-request.auth:read webhooks.auth:read application.auths:read application.webhooks:read application.application_template:read application_template:write application_template:read application_template.webhooks:read document.fetch_request:read event_spec.fetch_request:read api_spec.fetch_request:read runtime.auths:read integration_system.auths:read bundle.instance_auths:read bundle.instance_auths:read application:read automatic_scenario_assignment:read health_checks:read application:write runtime:write label_definition:write label_definition:read runtime:read tenant:read formation:read formation:write internal_visibility:read formation_template:read formation_template:write formation_constraint:read formation_constraint:write certificate_subject_mapping:read certificate_subject_mapping:write formation.state:write tenant_access:write bundle_instance_auth:write\", \"tenant\":\"{\\\"consumerTenant\\\":\\\"$INTERNAL_TENANT_ID\\\",\\\"externalTenant\\\":\\\"3e64ebae-38b5-46a0-b1ed-9ccee153a0ae\\\"}\" }" | base64 | tr '/+' '_-' | tr -d '=') 14 echo "$HEADER.$PAYLOAD." 15 } 16 17 POSTGRES_CONTAINER="${POSTGRES_CONTAINER:-"test-postgres"}" 18 POSTGRES_VERSION="${POSTGRES_VERSION:-"11"}" 19 DB_USER="${DB_USER:-"postgres"}" 20 DB_PWD="${DB_PWD:-"pgsql@12345"}" 21 DB_NAME="${DB_NAME:-"compass"}" 22 DB_PORT="${DB_PORT:-"5432"}" 23 DB_HOST="${DB_HOST:-"127.0.0.1"}" 24 25 read -r INTERNAL_TENANT_ID <<< "$(get_internal_tenant)" 26 echo "Internal Tenant ID for default tenant from dump:" 27 echo -E "${INTERNAL_TENANT_ID}" 28 29 read -r JWT_TOKEN <<< "$(get_token)" 30 echo "Use the following JWT token when requesting Director as default tenant:" 31 echo -E "${JWT_TOKEN}"