com.google.api.services.storage.model.RewriteResponse Java Examples

The following examples show how to use com.google.api.services.storage.model.RewriteResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GcsUtil.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void onSuccess(RewriteResponse rewriteResponse, HttpHeaders responseHeaders)
    throws IOException {
  if (rewriteResponse.getDone()) {
    LOG.debug("Rewrite done: {} to {}", from, to);
    readyToEnqueue = false;
  } else {
    LOG.debug(
        "Rewrite progress: {} of {} bytes, {} to {}",
        rewriteResponse.getTotalBytesRewritten(),
        rewriteResponse.getObjectSize(),
        from,
        to);
    rewriteRequest.setRewriteToken(rewriteResponse.getRewriteToken());
    readyToEnqueue = true;
    if (numRewriteTokensUsed != null) {
      numRewriteTokensUsed.incrementAndGet();
    }
  }
}
 
Example #2
Source File: CustomerSuppliedEncryptionKeysSamples.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Given an existing, CSEK-protected object, changes the key used to store that object.
 *
 * @param storage A Storage object, ready for use
 * @param bucketName The name of the destination bucket
 * @param objectName The name of the destination object
 * @param originalBase64Key The AES256 key currently associated with this object, encoded as a
 *     base64 string.
 * @param originalBase64KeyHash The SHA-256 hash of the above key, also encoded as a base64
 *     string.
 * @param newBase64Key An AES256 key which will replace the existing key, encoded as a base64
 *     string.
 * @param newBase64KeyHash The SHA-256 hash of the above key, also encoded as a base64 string.
 * @throws IOException if there was some error download from GCS.
 */
public static void rotateKey(
    Storage storage,
    String bucketName,
    String objectName,
    String originalBase64Key,
    String originalBase64KeyHash,
    String newBase64Key,
    String newBase64KeyHash)
    throws Exception {

  // Set the CSEK headers
  final HttpHeaders httpHeaders = new HttpHeaders();

  // Specify the exiting object's current CSEK.
  httpHeaders.set("x-goog-copy-source-encryption-algorithm", "AES256");
  httpHeaders.set("x-goog-copy-source-encryption-key", originalBase64Key);
  httpHeaders.set("x-goog-copy-source-encryption-key-sha256", originalBase64KeyHash);

  // Specify the new CSEK that we would like to apply.
  httpHeaders.set("x-goog-encryption-algorithm", "AES256");
  httpHeaders.set("x-goog-encryption-key", newBase64Key);
  httpHeaders.set("x-goog-encryption-key-sha256", newBase64KeyHash);

  Storage.Objects.Rewrite rewriteObject =
      storage.objects().rewrite(bucketName, objectName, bucketName, objectName, null);

  rewriteObject.setRequestHeaders(httpHeaders);

  try {
    RewriteResponse rewriteResponse = rewriteObject.execute();

    // If an object is very large, you may need to continue making successive calls to
    // rewrite until the operation completes.
    while (!rewriteResponse.getDone()) {
      System.out.println("Rewrite did not complete. Resuming...");
      rewriteObject.setRewriteToken(rewriteResponse.getRewriteToken());
      rewriteResponse = rewriteObject.execute();
    }
  } catch (GoogleJsonResponseException e) {
    System.out.println("Error rotating key: " + e.getContent());
    System.exit(1);
  }
}