Skip to content

Commit

Permalink
Accommodate "enhanced" Requester Pays error messages [CROM-6820] (#6556)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcovarr authored Nov 4, 2021
1 parent b360c11 commit c93519c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Cromwell Change Log

## 71 Release Notes

### Bug Fixes

* Fixed an issue handling data in Google Cloud Storage buckets with requester pays enabled that could sometimes cause I/O to fail.

## 70 Release Notes

### CWL security fix [#6510](https://github.com/broadinstitute/cromwell/pull/6510)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cromwell.filesystems.gcs

import java.io.FileNotFoundException

import akka.http.scaladsl.model.StatusCodes
import cats.effect.IO
import com.google.api.client.googleapis.json.GoogleJsonResponseException
import com.google.cloud.storage.StorageException
import cromwell.filesystems.gcs.RequesterPaysErrors.isProjectNotProvidedError

import java.io.FileNotFoundException

object GcsEnhancedRequest {

// If the request fails because no project was passed, recover the request, this time setting the project
Expand All @@ -19,11 +19,11 @@ object GcsEnhancedRequest {
// Use NoSuchFileException for better error reporting
case e: StorageException if e.getCode == StatusCodes.NotFound.intValue =>
IO.raiseError(new FileNotFoundException(s"File not found: ${path.pathAsString}"))
case e: GoogleJsonResponseException if isProjectNotProvidedError(e) =>
case e: GoogleJsonResponseException if isProjectNotProvidedError(e) =>
IO(f(true))
case e: GoogleJsonResponseException if e.getStatusCode == StatusCodes.NotFound.intValue =>
IO.raiseError(new FileNotFoundException(s"File not found: ${path.pathAsString}"))
case e =>
case e =>
IO.raiseError(e)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ package cromwell.filesystems.gcs

import com.google.api.client.googleapis.json.{GoogleJsonError, GoogleJsonResponseException}
import com.google.cloud.storage.StorageException
import org.apache.commons.lang3.StringUtils

object RequesterPaysErrors {
val BucketIsRequesterPaysErrorCode = 400
val BucketIsRequesterPaysErrorMessage = "Bucket is requester pays bucket but no user project provided."
val DoesNotHaveServiceUsePermissionErrorCode = 403
val DoesNotHaveServiceUsePermissionErrorMessage = "does not have serviceusage.services.use"

def isProjectNotProvidedError(storageException: StorageException) =
def isProjectNotProvidedError(storageException: StorageException) =
storageException.getCode == BucketIsRequesterPaysErrorCode &&
storageException.getMessage == BucketIsRequesterPaysErrorMessage
StringUtils.contains(storageException.getMessage, BucketIsRequesterPaysErrorMessage)

def isProjectNotProvidedError(googleJsonError: GoogleJsonError) =
googleJsonError.getCode == BucketIsRequesterPaysErrorCode &&
googleJsonError.getMessage == BucketIsRequesterPaysErrorMessage
StringUtils.contains(googleJsonError.getMessage, BucketIsRequesterPaysErrorMessage)

def isProjectNotProvidedError(googleJsonError: GoogleJsonResponseException) =
googleJsonError.getStatusCode == BucketIsRequesterPaysErrorCode &&
googleJsonError.getContent == BucketIsRequesterPaysErrorMessage
StringUtils.contains(googleJsonError.getContent, BucketIsRequesterPaysErrorMessage)
}

0 comments on commit c93519c

Please sign in to comment.