Search in sources :

Example 1 with EnablePermissionsFailedException

use of bio.terra.service.resourcemanagement.exception.EnablePermissionsFailedException in project jade-data-repo by DataBiosphere.

the class GoogleResourceService method enableIamPermissions.

public void enableIamPermissions(Map<String, List<String>> userPermissions, String projectId) throws InterruptedException {
    GetIamPolicyRequest getIamPolicyRequest = new GetIamPolicyRequest();
    Exception lastException = null;
    int retryWait = INITIAL_WAIT_SECONDS;
    for (int i = 0; i < RETRIES; i++) {
        try {
            CloudResourceManager resourceManager = cloudResourceManager();
            Policy policy = resourceManager.projects().getIamPolicy(projectId, getIamPolicyRequest).execute();
            List<Binding> bindingsList = policy.getBindings();
            for (Map.Entry<String, List<String>> entry : userPermissions.entrySet()) {
                Binding binding = new Binding().setRole(entry.getKey()).setMembers(entry.getValue());
                bindingsList.add(binding);
            }
            policy.setBindings(bindingsList);
            SetIamPolicyRequest setIamPolicyRequest = new SetIamPolicyRequest().setPolicy(policy);
            resourceManager.projects().setIamPolicy(projectId, setIamPolicyRequest).execute();
            return;
        } catch (IOException | GeneralSecurityException ex) {
            logger.info("Failed to enable iam permissions. Retry " + i + " of " + RETRIES, ex);
            lastException = ex;
        }
        TimeUnit.SECONDS.sleep(retryWait);
        retryWait = retryWait + retryWait;
        if (retryWait > MAX_WAIT_SECONDS) {
            retryWait = MAX_WAIT_SECONDS;
        }
    }
    throw new EnablePermissionsFailedException("Cannot enable iam permissions", lastException);
}
Also used : Policy(com.google.api.services.cloudresourcemanager.model.Policy) Binding(com.google.api.services.cloudresourcemanager.model.Binding) CloudResourceManager(com.google.api.services.cloudresourcemanager.CloudResourceManager) SetIamPolicyRequest(com.google.api.services.cloudresourcemanager.model.SetIamPolicyRequest) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) GetIamPolicyRequest(com.google.api.services.cloudresourcemanager.model.GetIamPolicyRequest) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GeneralSecurityException(java.security.GeneralSecurityException) InaccessibleBillingAccountException(bio.terra.service.resourcemanagement.exception.InaccessibleBillingAccountException) GoogleResourceException(bio.terra.service.resourcemanagement.exception.GoogleResourceException) CorruptMetadataException(bio.terra.service.snapshot.exception.CorruptMetadataException) EnablePermissionsFailedException(bio.terra.service.resourcemanagement.exception.EnablePermissionsFailedException) BucketLockException(bio.terra.service.resourcemanagement.exception.BucketLockException) IOException(java.io.IOException) StorageException(com.google.cloud.storage.StorageException) GoogleResourceNotFoundException(bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException) List(java.util.List) EnablePermissionsFailedException(bio.terra.service.resourcemanagement.exception.EnablePermissionsFailedException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

BucketLockException (bio.terra.service.resourcemanagement.exception.BucketLockException)1 EnablePermissionsFailedException (bio.terra.service.resourcemanagement.exception.EnablePermissionsFailedException)1 GoogleResourceException (bio.terra.service.resourcemanagement.exception.GoogleResourceException)1 GoogleResourceNotFoundException (bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException)1 InaccessibleBillingAccountException (bio.terra.service.resourcemanagement.exception.InaccessibleBillingAccountException)1 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)1 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 CloudResourceManager (com.google.api.services.cloudresourcemanager.CloudResourceManager)1 Binding (com.google.api.services.cloudresourcemanager.model.Binding)1 GetIamPolicyRequest (com.google.api.services.cloudresourcemanager.model.GetIamPolicyRequest)1 Policy (com.google.api.services.cloudresourcemanager.model.Policy)1 SetIamPolicyRequest (com.google.api.services.cloudresourcemanager.model.SetIamPolicyRequest)1 StorageException (com.google.cloud.storage.StorageException)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1