Mohammed Naser | f3f59a7 | 2023-01-15 21:02:04 -0500 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | #!/bin/bash |
| 14 | |
| 15 | set -ex |
| 16 | |
| 17 | # Get IDs for filtering |
| 18 | OS_PROJECT_ID=$(openstack project show -f value -c id ${OS_PROJECT_NAME}) |
| 19 | OS_USER_ID=$(openstack user show -f value -c id ${OS_USERNAME}) |
| 20 | SERVICE_OS_TRUSTEE_ID=$(openstack user show -f value -c id --domain ${SERVICE_OS_TRUSTEE_DOMAIN} ${SERVICE_OS_TRUSTEE}) |
| 21 | |
| 22 | # Check if trust doesn't already exist |
| 23 | openstack trust list -f value -c "Project ID" \ |
| 24 | -c "Trustee User ID" -c "Trustor User ID" | \ |
| 25 | grep "^${OS_PROJECT_ID} ${SERVICE_OS_TRUSTEE_ID} ${OS_USER_ID}$" && \ |
| 26 | exit 0 |
| 27 | |
| 28 | # If there are no roles specified... |
| 29 | if [ -z "${SERVICE_OS_ROLES}" ]; then |
| 30 | # ...Heat will try to delegate all of the roles that user has in the |
| 31 | # project. Let's fetch them all and use that. |
| 32 | readarray -t roles < <(openstack role assignment list -f value \ |
| 33 | -c "Role" --user="${OS_USERNAME}" --project="${OS_PROJECT_ID}") |
| 34 | else |
| 35 | # Split roles into an array |
| 36 | IFS=',' read -r -a roles <<< "${SERVICE_OS_ROLES}" |
| 37 | fi |
| 38 | |
| 39 | # Create trust between trustor and trustee |
| 40 | SERVICE_OS_TRUST_ID=$(openstack trust create -f value -c id \ |
| 41 | --project="${OS_PROJECT_NAME}" \ |
| 42 | ${roles[@]/#/--role=} \ |
| 43 | --trustee-domain="${SERVICE_OS_TRUSTEE_DOMAIN}" \ |
| 44 | "${OS_USERNAME}" \ |
| 45 | "${SERVICE_OS_TRUSTEE}") |
| 46 | |
| 47 | # Display trust |
| 48 | openstack trust show "${SERVICE_OS_TRUST_ID}" |