From d6808bba718de652f6dedde7205218e08c255c6c Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Wed, 4 Aug 2021 14:01:04 -0400 Subject: [PATCH] Fix GCS bucket/subdir handling in IcannReportingStager (#1265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the migration to the new GCS API it becomes apparent that the BlobId.of() method needs to take the bucket name (without any trailing directories) as the first argument. I did a search on all occurrences of "BlobId.of" in the code base and verified that it is only in the ICANN reporting job that the API was misused. This change is [Reviewable](https://reviewable.io/reviews/google/nomulus/1265) --- .../registry/reporting/icann/IcannReportingStager.java | 8 ++++---- .../reporting/icann/IcannReportingUploadAction.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingStager.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingStager.java index 557d9b616..887687a93 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingStager.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingStager.java @@ -259,8 +259,8 @@ public class IcannReportingStager { tld, Ascii.toLowerCase(reportType.toString()), DateTimeFormat.forPattern("yyyyMM").print(yearMonth)); - String reportBucketname = String.format("%s/%s", reportingBucket, subdir); - final BlobId gcsFilename = BlobId.of(reportBucketname, reportFilename); + final BlobId gcsFilename = + BlobId.of(reportingBucket, String.format("%s/%s", subdir, reportFilename)); gcsUtils.createFromBytes(gcsFilename, reportBytes); logger.atInfo().log("Wrote %d bytes to file location %s", reportBytes.length, gcsFilename); return reportFilename; @@ -268,8 +268,8 @@ public class IcannReportingStager { /** Creates and stores a manifest file on GCS, indicating which reports were generated. */ void createAndUploadManifest(String subdir, ImmutableList filenames) throws IOException { - String reportBucketname = String.format("%s/%s", reportingBucket, subdir); - final BlobId gcsFilename = BlobId.of(reportBucketname, MANIFEST_FILE_NAME); + final BlobId gcsFilename = + BlobId.of(reportingBucket, String.format("%s/%s", subdir, MANIFEST_FILE_NAME)); StringBuilder manifestString = new StringBuilder(); filenames.forEach((filename) -> manifestString.append(filename).append("\n")); gcsUtils.createFromBytes(gcsFilename, manifestString.toString().getBytes(UTF_8)); diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java index a6b1c2dc7..353c0e368 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java @@ -145,10 +145,10 @@ public final class IcannReportingUploadAction implements Runnable { String.format( "icann/monthly/%d-%02d", cursorTimeMinusMonth.getYear(), cursorTimeMinusMonth.getMonthOfYear()); - String reportBucketname = String.format("%s/%s", reportingBucket, reportSubdir); String filename = getFileName(cursorType, cursorTime, tldStr); - final BlobId gcsFilename = BlobId.of(reportBucketname, filename); - logger.atInfo().log("Reading ICANN report %s from bucket %s", filename, reportBucketname); + final BlobId gcsFilename = + BlobId.of(reportingBucket, String.format("%s/%s", reportSubdir, filename)); + logger.atInfo().log("Reading ICANN report %s from bucket %s", filename, reportingBucket); // Check that the report exists try { verifyFileExists(gcsFilename);