Class RemoteStorageHelper
getOptions() ()} method. Returned options have custom ServiceOptions.getRetrySettings(): RetrySettings.getMaxAttempts() is 10, RetrySettings.getMaxRetryDelay() is 30000, RetrySettings.getTotalTimeout() is
120000 and RetrySettings.getInitialRetryDelay() is 250. HttpTransportOptions.getConnectTimeout() and HttpTransportOptions.getReadTimeout() are
both set to 60000.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanBuckets(Storage storage, long olderThan, long timeoutMs) static RemoteStorageHelpercreate()Creates aRemoteStorageHelperobject using default project id and authentication credentials.static RemoteStorageHelperCreates aRemoteStorageHelperobject for the given project id and Credential.static RemoteStorageHelpercreate(String projectId, InputStream keyStream) This method is obsolete because of a potential security risk.static voidforceDelete(Storage storage, String bucket) Deletes a bucket, even if non-empty.static BooleanforceDelete(Storage storage, String bucket, long timeout, TimeUnit unit) Deletes a bucket, even if non-empty.static BooleanforceDelete(Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) Deletes a bucket, even if non-empty.static StringReturns a bucket name generated using a random UUID.Returns aStorageOptionsobject to be used for testing.
-
Method Details
-
getOptions
Returns aStorageOptionsobject to be used for testing. -
cleanBuckets
-
forceDelete
public static Boolean forceDelete(Storage storage, String bucket, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket deletion succeeds ortimeoutexpires. To allow for the timeout, this method uses a separate thread to send the delete requests. UseforceDelete(Storage storage, String bucket)if spawning an additional thread is undesirable, such as in the App Engine production runtime.- Parameters:
storage- the storage service to be used to issue requestsbucket- the bucket to be deletedtimeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- true if deletion succeeded, false if timeout expired
- Throws:
InterruptedException- if the thread deleting the bucket is interrupted while waitingExecutionException- if an exception was thrown while deleting bucket or bucket objects
-
forceDelete
public static Boolean forceDelete(Storage storage, String bucket, long timeout, TimeUnit unit, String userProject) throws InterruptedException, ExecutionException Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket deletion succeeds ortimeoutexpires. To allow for the timeout, this method uses a separate thread to send the delete requests. UseforceDelete(Storage storage, String bucket)if spawning an additional thread is undesirable, such as in the App Engine production runtime.- Parameters:
storage- the storage service to be used to issue requestsbucket- the bucket to be deletedtimeout- the maximum time to waitunit- the time unit of the timeout argumentuserProject- the project to bill for requester-pays buckets (or "")- Returns:
- true if deletion succeeded, false if timeout expired
- Throws:
InterruptedException- if the thread deleting the bucket is interrupted while waitingExecutionException- if an exception was thrown while deleting bucket or bucket objects
-
forceDelete
Deletes a bucket, even if non-empty. This method blocks until the deletion completes or fails.- Parameters:
storage- the storage service to be used to issue requestsbucket- the bucket to be deleted- Throws:
StorageException- if an exception is encountered during bucket deletion
-
generateBucketName
Returns a bucket name generated using a random UUID. -
create
@ObsoleteApi("This method is obsolete because of a potential security risk. Use the create() variant with Credential parameter instead") public static RemoteStorageHelper create(String projectId, InputStream keyStream) throws RemoteStorageHelper.StorageHelperException This method is obsolete because of a potential security risk. Use thecreate(String, GoogleCredentials)method instead.If you know that you will be loading credential configurations of a specific type, it is recommended to use a credential-type-specific `fromStream()` method. This will ensure that an unexpected credential type with potential for malicious intent is not loaded unintentionally. You might still have to do validation for certain credential types. Please follow the recommendation for that method.
If you are loading your credential configuration from an untrusted source and have not mitigated the risks (e.g. by validating the configuration yourself), make these changes as soon as possible to prevent security risks to your environment.
Regardless of the method used, it is always your responsibility to validate configurations received from external sources.
See the for more details.
Creates a
RemoteStorageHelperobject for the given project id and JSON key input stream.- Parameters:
projectId- id of the project to be used for running the testskeyStream- input stream for a JSON key- Returns:
- A
RemoteStorageHelperobject for the provided options - Throws:
RemoteStorageHelper.StorageHelperException- ifkeyStreamis not a valid JSON key stream
-
create
public static RemoteStorageHelper create(String projectId, com.google.auth.oauth2.GoogleCredentials credentials) Creates aRemoteStorageHelperobject for the given project id and Credential.- Parameters:
projectId- id of the project to be used for running the testscredentials- GoogleCredential to set to StorageOptions- Returns:
- A
RemoteStorageHelperobject for the provided options
-
create
Creates aRemoteStorageHelperobject using default project id and authentication credentials.
-