mirror of
https://github.com/google/nomulus.git
synced 2025-05-19 18:59:35 +02:00
Refactor StringGenerator bindings
Make every dependency request explicit on what encoding is used. Also get rid of InjectRule in XjcToDomainResourceConverterTest. Random number generator providers are separated to secure and insecure ones. The insecure ones must be explicitly requested (usually for use cases where security is not of concern, for better speed). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217921422
This commit is contained in:
parent
1a4aae8f7d
commit
2020dcb50f
15 changed files with 84 additions and 116 deletions
|
@ -54,6 +54,7 @@ import google.registry.request.Action;
|
|||
import google.registry.request.Parameter;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.util.StringGenerator;
|
||||
import google.registry.util.SystemClock;
|
||||
import google.registry.xjc.JaxbFragment;
|
||||
import google.registry.xjc.rdedomain.XjcRdeDomain;
|
||||
|
@ -83,6 +84,7 @@ public class RdeDomainImportAction implements Runnable {
|
|||
protected final String importBucketName;
|
||||
protected final String importFileName;
|
||||
protected final Optional<Integer> mapShards;
|
||||
protected final StringGenerator stringGenerator;
|
||||
|
||||
@Inject
|
||||
public RdeDomainImportAction(
|
||||
|
@ -90,12 +92,14 @@ public class RdeDomainImportAction implements Runnable {
|
|||
Response response,
|
||||
@Config("rdeImportBucket") String importBucketName,
|
||||
@Parameter(PATH) String importFileName,
|
||||
@Parameter(PARAM_MAP_SHARDS) Optional<Integer> mapShards) {
|
||||
@Parameter(PARAM_MAP_SHARDS) Optional<Integer> mapShards,
|
||||
@Config("base64StringGenerator") StringGenerator stringGenerator) {
|
||||
this.mrRunner = mrRunner;
|
||||
this.response = response;
|
||||
this.importBucketName = importBucketName;
|
||||
this.importFileName = importFileName;
|
||||
this.mapShards = mapShards;
|
||||
this.stringGenerator = stringGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,7 +126,7 @@ public class RdeDomainImportAction implements Runnable {
|
|||
* Creates a new {@link RdeDomainImportMapper}
|
||||
*/
|
||||
private RdeDomainImportMapper createMapper() {
|
||||
return new RdeDomainImportMapper(importBucketName);
|
||||
return new RdeDomainImportMapper(importBucketName, stringGenerator);
|
||||
}
|
||||
|
||||
/** Mapper to import domains from an escrow file. */
|
||||
|
@ -132,11 +136,13 @@ public class RdeDomainImportAction implements Runnable {
|
|||
private static final long serialVersionUID = -7645091075256589374L;
|
||||
|
||||
private final String importBucketName;
|
||||
private final StringGenerator stringGenerator;
|
||||
private transient RdeImportUtils importUtils;
|
||||
private transient DnsQueue dnsQueue;
|
||||
|
||||
public RdeDomainImportMapper(String importBucketName) {
|
||||
public RdeDomainImportMapper(String importBucketName, StringGenerator stringGenerator) {
|
||||
this.importBucketName = importBucketName;
|
||||
this.stringGenerator = stringGenerator;
|
||||
}
|
||||
|
||||
private RdeImportUtils getImportUtils() {
|
||||
|
@ -196,7 +202,7 @@ public class RdeDomainImportAction implements Runnable {
|
|||
createAutoRenewPollMessageForDomainImport(xjcDomain, historyEntry);
|
||||
DomainResource domain =
|
||||
XjcToDomainResourceConverter.convertDomain(
|
||||
xjcDomain, autorenewBillingEvent, autorenewPollMessage);
|
||||
xjcDomain, autorenewBillingEvent, autorenewPollMessage, stringGenerator);
|
||||
getDnsQueue().addDomainRefreshTask(domain.getFullyQualifiedDomainName());
|
||||
// Keep a list of "extra objects" that need to be saved along with the domain
|
||||
// and add to it if necessary.
|
||||
|
|
|
@ -42,8 +42,6 @@ import google.registry.model.registry.Registries;
|
|||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import google.registry.util.RandomStringGenerator;
|
||||
import google.registry.util.StringGenerator;
|
||||
import google.registry.util.XmlToEnumMapper;
|
||||
import google.registry.xjc.domain.XjcDomainContactType;
|
||||
|
@ -54,27 +52,12 @@ import google.registry.xjc.rdedomain.XjcRdeDomainElement;
|
|||
import google.registry.xjc.rdedomain.XjcRdeDomainTransferDataType;
|
||||
import google.registry.xjc.rgp.XjcRgpStatusType;
|
||||
import google.registry.xjc.secdns.XjcSecdnsDsDataType;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.ProviderException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.function.Function;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/** Utility class that converts an {@link XjcRdeDomainElement} into a {@link DomainResource}. */
|
||||
final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
|
||||
|
||||
@NonFinalForTesting
|
||||
static StringGenerator stringGenerator =
|
||||
new RandomStringGenerator(StringGenerator.Alphabets.BASE_64, getRandom());
|
||||
|
||||
static SecureRandom getRandom() {
|
||||
try {
|
||||
return SecureRandom.getInstance("NativePRNG");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new ProviderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final XmlToEnumMapper<TransferStatus> TRANSFER_STATUS_MAPPER =
|
||||
XmlToEnumMapper.create(TransferStatus.values());
|
||||
|
||||
|
@ -152,7 +135,8 @@ final class XjcToDomainResourceConverter extends XjcToEppResourceConverter {
|
|||
static DomainResource convertDomain(
|
||||
XjcRdeDomain domain,
|
||||
BillingEvent.Recurring autoRenewBillingEvent,
|
||||
PollMessage.Autorenew autoRenewPollMessage) {
|
||||
PollMessage.Autorenew autoRenewPollMessage,
|
||||
StringGenerator stringGenerator) {
|
||||
GracePeriodConverter gracePeriodConverter =
|
||||
new GracePeriodConverter(domain, Key.create(autoRenewBillingEvent));
|
||||
DomainResource.Builder builder =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue