Add ttl for braintree writes to onetime donation table

This commit is contained in:
Katherine
2023-12-15 13:37:35 -05:00
committed by GitHub
parent 372e3f83d2
commit a37acd1f42
5 changed files with 15 additions and 5 deletions

View File

@@ -549,7 +549,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
dynamoDbAsyncClient,
config.getDynamoDbTables().getIssuedReceipts().getGenerator());
OneTimeDonationsManager oneTimeDonationsManager = new OneTimeDonationsManager(
config.getDynamoDbTables().getOnetimeDonations().getTableName(), dynamoDbAsyncClient);
config.getDynamoDbTables().getOnetimeDonations().getTableName(), config.getDynamoDbTables().getOnetimeDonations().getExpiration(), dynamoDbAsyncClient);
RedeemedReceiptsManager redeemedReceiptsManager = new RedeemedReceiptsManager(clock,
config.getDynamoDbTables().getRedeemedReceipts().getTableName(),
dynamoDbAsyncClient,

View File

@@ -59,7 +59,7 @@ public class DynamoDbTables {
private final Table kemKeys;
private final Table kemLastResortKeys;
private final TableWithExpiration messages;
private final Table onetimeDonations;
private final TableWithExpiration onetimeDonations;
private final Table phoneNumberIdentifiers;
private final Table profiles;
private final Table pushChallenge;
@@ -83,7 +83,7 @@ public class DynamoDbTables {
@JsonProperty("pqKeys") final Table kemKeys,
@JsonProperty("pqLastResortKeys") final Table kemLastResortKeys,
@JsonProperty("messages") final TableWithExpiration messages,
@JsonProperty("onetimeDonations") final Table onetimeDonations,
@JsonProperty("onetimeDonations") final TableWithExpiration onetimeDonations,
@JsonProperty("phoneNumberIdentifiers") final Table phoneNumberIdentifiers,
@JsonProperty("profiles") final Table profiles,
@JsonProperty("pushChallenge") final Table pushChallenge,
@@ -192,7 +192,7 @@ public class DynamoDbTables {
@NotNull
@Valid
public Table getOnetimeDonations() {
public TableWithExpiration getOnetimeDonations() {
return onetimeDonations;
}

View File

@@ -8,6 +8,7 @@ package org.whispersystems.textsecuregcm.storage;
import static com.codahale.metrics.MetricRegistry.name;
import io.micrometer.core.instrument.Metrics;
import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
@@ -21,14 +22,19 @@ import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
public class OneTimeDonationsManager {
public static final String KEY_PAYMENT_ID = "P"; // S
public static final String ATTR_PAID_AT = "A"; // N
public static final String ATTR_TTL = "E"; // N
private static final String ONETIME_DONATION_NOT_FOUND_COUNTER_NAME = name(OneTimeDonationsManager.class, "onetimeDonationNotFound");
private final String table;
private final Duration ttl;
private final DynamoDbAsyncClient dynamoDbAsyncClient;
public OneTimeDonationsManager(
@Nonnull String table,
@Nonnull Duration ttl,
@Nonnull DynamoDbAsyncClient dynamoDbAsyncClient) {
this.table = Objects.requireNonNull(table);
this.ttl = Objects.requireNonNull(ttl);
this.dynamoDbAsyncClient = Objects.requireNonNull(dynamoDbAsyncClient);
}
@@ -55,7 +61,8 @@ public class OneTimeDonationsManager {
.tableName(table)
.item(Map.of(
KEY_PAYMENT_ID, AttributeValues.fromString(paymentId),
ATTR_PAID_AT, AttributeValues.fromLong(paidAt.getEpochSecond())))
ATTR_PAID_AT, AttributeValues.fromLong(paidAt.getEpochSecond()),
ATTR_TTL, AttributeValues.fromLong(paidAt.plus(ttl).getEpochSecond())))
.build())
.thenApply(unused -> paymentId);
}