( iamPolicy: IamPolicy, targetRole?: string, getGroupByIdentifier?: (identifier: string) => Group | undefined )
| 146 | // memberMapToRolesInProjectIAM return the Map<users/{email}, Set<roles/{role}>> |
| 147 | // the user could includes users/ALL_USERS_USER_EMAIL |
| 148 | export const memberMapToRolesInProjectIAM = ( |
| 149 | iamPolicy: IamPolicy, |
| 150 | targetRole?: string, |
| 151 | getGroupByIdentifier?: (identifier: string) => Group | undefined |
| 152 | ): Map<string, Set<string>> => { |
| 153 | // Map<userfullname, Set<roles/{role}>> |
| 154 | const rolesMapByName = new Map<string, Set<string>>(); |
| 155 | |
| 156 | // Handle project level roles. |
| 157 | for (const binding of iamPolicy.bindings) { |
| 158 | if (targetRole && binding.role !== targetRole) { |
| 159 | continue; |
| 160 | } |
| 161 | if (isBindingPolicyExpired(binding)) { |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | const fullnames = getUserListInBinding({ |
| 166 | binding, |
| 167 | ignoreGroup: false, |
| 168 | getGroupByIdentifier, |
| 169 | }); |
| 170 | for (const fullname of fullnames) { |
| 171 | if (!rolesMapByName.has(fullname)) { |
| 172 | rolesMapByName.set(fullname, new Set()); |
| 173 | } |
| 174 | rolesMapByName.get(fullname)?.add(binding.role); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // Handle workspace level project roles. |
| 179 | const roleMapToUsers = |
| 180 | appStoreUtilBridge()?.workspaceRoleMapToUsers() ?? |
| 181 | new Map<string, Set<string>>(); |
| 182 | for (const [role, userSet] of roleMapToUsers.entries()) { |
| 183 | if (targetRole && role !== targetRole) { |
| 184 | continue; |
| 185 | } |
| 186 | for (const user of userSet.values()) { |
| 187 | if (!rolesMapByName.has(user)) { |
| 188 | rolesMapByName.set(user, new Set()); |
| 189 | } |
| 190 | rolesMapByName.get(user)?.add(role); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return rolesMapByName; |
| 195 | }; |
| 196 | |
| 197 | export const filterBindingsByUserName = ({ |
| 198 | policy, |
no test coverage detected