Add ttl for braintree writes to onetime donation table
This commit is contained in:
parent
372e3f83d2
commit
a37acd1f42
|
@ -104,6 +104,7 @@ dynamoDbTables:
|
|||
expiration: P30D # Duration of time until rows expire
|
||||
onetimeDonations:
|
||||
tableName: Example_OnetimeDonations
|
||||
expiration: P90D
|
||||
phoneNumberIdentifiers:
|
||||
tableName: Example_PhoneNumberIdentifiers
|
||||
profiles:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.storage;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -21,6 +22,7 @@ public class OnetimeDonationsManagerTest {
|
|||
void beforeEach() {
|
||||
oneTimeDonationsManager = new OneTimeDonationsManager(
|
||||
DynamoDbExtensionSchema.Tables.ONETIME_DONATIONS.tableName(),
|
||||
Duration.ofDays(90),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbAsyncClient());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue