mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Make BillingModule.OVERALL_INVOICE_PREFIX configurable
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=221700223
This commit is contained in:
parent
45f63cbecf
commit
36c6265980
8 changed files with 31 additions and 11 deletions
|
@ -75,6 +75,10 @@ public class InvoicingPipeline implements Serializable {
|
|||
@Config("billingBucketUrl")
|
||||
String billingBucketUrl;
|
||||
|
||||
@Inject
|
||||
@Config("invoiceFilePrefix")
|
||||
String invoiceFilePrefix;
|
||||
|
||||
@Inject
|
||||
InvoicingPipeline() {}
|
||||
|
||||
|
@ -164,7 +168,7 @@ public class InvoicingPipeline implements Serializable {
|
|||
billingBucketUrl,
|
||||
BillingModule.INVOICES_DIRECTORY,
|
||||
yearMonth,
|
||||
BillingModule.OVERALL_INVOICE_PREFIX,
|
||||
invoiceFilePrefix,
|
||||
yearMonth)))
|
||||
.withHeader(InvoiceGroupingKey.invoiceHeader())
|
||||
.withoutSharding()
|
||||
|
|
|
@ -692,6 +692,18 @@ public final class RegistryConfig {
|
|||
return ImmutableList.copyOf(config.billing.invoiceEmailRecipients);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file prefix for the invoice CSV file.
|
||||
*
|
||||
* @see google.registry.beam.invoicing.InvoicingPipeline
|
||||
* @see google.registry.reporting.billing.BillingEmailUtils
|
||||
*/
|
||||
@Provides
|
||||
@Config("invoiceFilePrefix")
|
||||
public static String provideInvoiceFilePrefix(RegistryConfigSettings config) {
|
||||
return config.billing.invoiceFilePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Google Cloud Storage bucket for staging escrow deposits pending upload.
|
||||
*
|
||||
|
|
|
@ -131,6 +131,7 @@ public class RegistryConfigSettings {
|
|||
/** Configuration for monthly invoices. */
|
||||
public static class Billing {
|
||||
public List<String> invoiceEmailRecipients;
|
||||
public String invoiceFilePrefix;
|
||||
}
|
||||
|
||||
/** Configuration for Registry Data Escrow (RDE). */
|
||||
|
|
|
@ -293,6 +293,7 @@ icannReporting:
|
|||
|
||||
billing:
|
||||
invoiceEmailRecipients: []
|
||||
invoiceFilePrefix: REG-INV
|
||||
|
||||
rde:
|
||||
# URL prefix of ICANN's server to upload RDE reports to. Nomulus adds /TLD/ID
|
||||
|
|
|
@ -48,6 +48,7 @@ class BillingEmailUtils {
|
|||
private final String alertRecipientAddress;
|
||||
private final ImmutableList<String> invoiceEmailRecipients;
|
||||
private final String billingBucket;
|
||||
private final String invoiceFilePrefix;
|
||||
private final String invoiceDirectoryPrefix;
|
||||
private final GcsUtils gcsUtils;
|
||||
private final Retrier retrier;
|
||||
|
@ -60,6 +61,7 @@ class BillingEmailUtils {
|
|||
@Config("alertRecipientEmailAddress") String alertRecipientAddress,
|
||||
@Config("invoiceEmailRecipients") ImmutableList<String> invoiceEmailRecipients,
|
||||
@Config("billingBucket") String billingBucket,
|
||||
@Config("invoiceFilePrefix") String invoiceFilePrefix,
|
||||
@InvoiceDirectoryPrefix String invoiceDirectoryPrefix,
|
||||
GcsUtils gcsUtils,
|
||||
Retrier retrier) {
|
||||
|
@ -69,6 +71,7 @@ class BillingEmailUtils {
|
|||
this.alertRecipientAddress = alertRecipientAddress;
|
||||
this.invoiceEmailRecipients = invoiceEmailRecipients;
|
||||
this.billingBucket = billingBucket;
|
||||
this.invoiceFilePrefix = invoiceFilePrefix;
|
||||
this.invoiceDirectoryPrefix = invoiceDirectoryPrefix;
|
||||
this.gcsUtils = gcsUtils;
|
||||
this.retrier = retrier;
|
||||
|
@ -80,8 +83,7 @@ class BillingEmailUtils {
|
|||
retrier.callWithRetry(
|
||||
() -> {
|
||||
String invoiceFile =
|
||||
String.format(
|
||||
"%s-%s.csv", BillingModule.OVERALL_INVOICE_PREFIX, yearMonth.toString());
|
||||
String.format("%s-%s.csv", invoiceFilePrefix, yearMonth);
|
||||
GcsFilename invoiceFilename =
|
||||
new GcsFilename(billingBucket, invoiceDirectoryPrefix + invoiceFile);
|
||||
try (InputStream in = gcsUtils.openInputStream(invoiceFilename)) {
|
||||
|
@ -91,12 +93,12 @@ class BillingEmailUtils {
|
|||
msg.addRecipient(RecipientType.TO, new InternetAddress(recipient));
|
||||
}
|
||||
msg.setSubject(
|
||||
String.format("Domain Registry invoice data %s", yearMonth.toString()));
|
||||
String.format("Domain Registry invoice data %s", yearMonth));
|
||||
Multipart multipart = new MimeMultipart();
|
||||
BodyPart textPart = new MimeBodyPart();
|
||||
textPart.setText(
|
||||
String.format(
|
||||
"Attached is the %s invoice for the domain registry.", yearMonth.toString()));
|
||||
"Attached is the %s invoice for the domain registry.", yearMonth));
|
||||
multipart.addBodyPart(textPart);
|
||||
BodyPart invoicePart = new MimeBodyPart();
|
||||
String invoiceData = CharStreams.toString(new InputStreamReader(in, UTF_8));
|
||||
|
@ -128,7 +130,7 @@ class BillingEmailUtils {
|
|||
Message msg = emailService.createMessage();
|
||||
msg.setFrom(new InternetAddress(outgoingEmailAddress));
|
||||
msg.addRecipient(RecipientType.TO, new InternetAddress(alertRecipientAddress));
|
||||
msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth.toString()));
|
||||
msg.setSubject(String.format("Billing Pipeline Alert: %s", yearMonth));
|
||||
msg.setText(body);
|
||||
emailService.sendMessage(msg);
|
||||
return null;
|
||||
|
|
|
@ -32,8 +32,6 @@ import org.joda.time.YearMonth;
|
|||
public final class BillingModule {
|
||||
|
||||
public static final String DETAIL_REPORT_PREFIX = "invoice_details";
|
||||
// TODO(b/119551360): This should be configurable, not hard-coded to Charleston Road Registry.
|
||||
public static final String OVERALL_INVOICE_PREFIX = "CRR-INV";
|
||||
public static final String INVOICES_DIRECTORY = "invoices";
|
||||
|
||||
static final String PARAM_SHOULD_PUBLISH = "shouldPublish";
|
||||
|
|
|
@ -62,6 +62,7 @@ public class InvoicingPipelineTest {
|
|||
invoicingPipeline.projectId = "test-project";
|
||||
File beamTempFolder = tempFolder.newFolder();
|
||||
invoicingPipeline.beamBucketUrl = beamTempFolder.getAbsolutePath();
|
||||
invoicingPipeline.invoiceFilePrefix = "REG-INV";
|
||||
invoicingPipeline.beamStagingUrl = beamTempFolder.getAbsolutePath() + "/staging";
|
||||
invoicingPipeline.invoiceTemplateUrl =
|
||||
beamTempFolder.getAbsolutePath() + "/templates/invoicing";
|
||||
|
@ -196,7 +197,7 @@ public class InvoicingPipelineTest {
|
|||
.containsExactlyElementsIn(entry.getValue());
|
||||
}
|
||||
|
||||
ImmutableList<String> overallInvoice = resultFileContents("CRR-INV-2017-10.csv");
|
||||
ImmutableList<String> overallInvoice = resultFileContents("REG-INV-2017-10.csv");
|
||||
assertThat(overallInvoice.get(0))
|
||||
.isEqualTo(
|
||||
"StartDate,EndDate,ProductAccountKey,Amount,AmountCurrency,BillingProductCode,"
|
||||
|
|
|
@ -67,7 +67,7 @@ public class BillingEmailUtilsTest {
|
|||
when(emailService.createMessage())
|
||||
.thenReturn(new MimeMessage(Session.getDefaultInstance(new Properties(), null)));
|
||||
gcsUtils = mock(GcsUtils.class);
|
||||
when(gcsUtils.openInputStream(new GcsFilename("test-bucket", "results/CRR-INV-2017-10.csv")))
|
||||
when(gcsUtils.openInputStream(new GcsFilename("test-bucket", "results/REG-INV-2017-10.csv")))
|
||||
.thenReturn(
|
||||
new ByteArrayInputStream("test,data\nhello,world".getBytes(StandardCharsets.UTF_8)));
|
||||
msgCaptor = ArgumentCaptor.forClass(Message.class);
|
||||
|
@ -80,6 +80,7 @@ public class BillingEmailUtilsTest {
|
|||
"my-receiver@test.com",
|
||||
ImmutableList.of("hello@world.com", "hola@mundo.com"),
|
||||
"test-bucket",
|
||||
"REG-INV",
|
||||
"results/",
|
||||
gcsUtils,
|
||||
new Retrier(new FakeSleeper(new FakeClock()), RETRY_COUNT));
|
||||
|
@ -109,7 +110,7 @@ public class BillingEmailUtilsTest {
|
|||
.isEqualTo("Attached is the 2017-10 invoice for the domain registry.");
|
||||
assertThat(contents.getBodyPart(1)).isInstanceOf(BodyPart.class);
|
||||
BodyPart attachmentPart = contents.getBodyPart(1);
|
||||
assertThat(attachmentPart.getContentType()).endsWith("name=CRR-INV-2017-10.csv");
|
||||
assertThat(attachmentPart.getContentType()).endsWith("name=REG-INV-2017-10.csv");
|
||||
assertThat(attachmentPart.getContent().toString()).isEqualTo("test,data\nhello,world");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue