in sources/src/main/java/com/google/solutions/jitaccess/apis/clients/AssetInventoryClient.java [63:103]
public List<PolicyInfo> getEffectiveIamPolicies(
@NotNull String scope,
@NotNull String resourceId
) throws AccessException, IOException {
Preconditions.checkNotNull(scope, "scope");
Preconditions.checkNotNull(resourceId, "resourceId");
Preconditions.checkNotNull(resourceId.contains("/"), "resourceId");
try
{
var results = createClient()
.effectiveIamPolicies()
.batchGet(scope)
.setNames(List.of(ABSOLUTE_PREFIX + resourceId))
.execute()
.getPolicyResults();
return results.isEmpty()
? List.of()
: results.get(0).getPolicies();
}
catch (GoogleJsonResponseException e) {
switch (e.getStatusCode()) {
case 401:
throw new NotAuthenticatedException("Not authenticated", e);
case 403:
throw new AccessDeniedException(
String.format("Access to scope '%s' is denied", scope), e);
case 404:
throw new ResourceNotFoundException(
String.format("The resource '%s' does not exist", resourceId), e);
case 429:
throw new QuotaExceededException(
"Exceeded quota for BatchGetEffectiveIamPolicies API requests. Consider increasing the request " +
"quota in the application project.",
e);
default:
throw (GoogleJsonResponseException) e.fillInStackTrace();
}
}
}