mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +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
|
@ -25,6 +25,7 @@ import com.beust.jcommander.Parameter;
|
|||
import com.beust.jcommander.Parameters;
|
||||
import com.google.common.net.InternetDomainName;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.tools.soy.CreateAnchorTenantSoyInfo;
|
||||
import google.registry.util.StringGenerator;
|
||||
import javax.inject.Inject;
|
||||
|
@ -72,6 +73,7 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand {
|
|||
private boolean fee;
|
||||
|
||||
@Inject
|
||||
@Config("base64StringGenerator")
|
||||
StringGenerator passwordGenerator;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.tools.params.PhoneNumberParameter;
|
||||
import google.registry.tools.soy.ContactCreateSoyInfo;
|
||||
import google.registry.util.StringGenerator;
|
||||
|
@ -103,6 +104,7 @@ final class CreateContactCommand extends MutatingEppToolCommand {
|
|||
private String password;
|
||||
|
||||
@Inject
|
||||
@Config("base64StringGenerator")
|
||||
StringGenerator passwordGenerator;
|
||||
|
||||
private static final int PASSWORD_LENGTH = 16;
|
||||
|
|
|
@ -23,6 +23,7 @@ import static org.joda.time.DateTimeZone.UTC;
|
|||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
|
||||
import google.registry.tools.soy.DomainCreateSoyInfo;
|
||||
import google.registry.util.StringGenerator;
|
||||
|
@ -46,6 +47,7 @@ final class CreateDomainCommand extends CreateOrUpdateDomainCommand
|
|||
private boolean forcePremiums;
|
||||
|
||||
@Inject
|
||||
@Config("base64StringGenerator")
|
||||
StringGenerator passwordGenerator;
|
||||
|
||||
private static final int PASSWORD_LENGTH = 16;
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.google.common.base.Splitter;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.Files;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.util.NonFinalForTesting;
|
||||
import google.registry.util.Retrier;
|
||||
|
@ -40,7 +41,6 @@ import java.io.IOException;
|
|||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/** Command to generate and persist {@link AllocationToken}s. */
|
||||
@Parameters(
|
||||
|
@ -80,7 +80,10 @@ class GenerateAllocationTokensCommand implements CommandWithRemoteApi {
|
|||
description = "Do not actually persist the tokens; defaults to false")
|
||||
boolean dryRun;
|
||||
|
||||
@Inject @Named("base58StringGenerator") StringGenerator stringGenerator;
|
||||
@Inject
|
||||
@Config("base58StringGenerator")
|
||||
StringGenerator stringGenerator;
|
||||
|
||||
@Inject Retrier retrier;
|
||||
|
||||
private static final int BATCH_SIZE = 20;
|
||||
|
|
|
@ -64,7 +64,6 @@ import javax.inject.Singleton;
|
|||
KeyringModule.class,
|
||||
KmsModule.class,
|
||||
RdeModule.class,
|
||||
RegistryToolModule.class,
|
||||
SystemClockModule.class,
|
||||
SystemSleeperModule.class,
|
||||
URLFetchServiceModule.class,
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import google.registry.util.RandomStringGenerator;
|
||||
import google.registry.util.StringGenerator;
|
||||
import google.registry.util.StringGenerator.Alphabets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.ProviderException;
|
||||
import java.security.SecureRandom;
|
||||
import javax.inject.Named;
|
||||
|
||||
/** Dagger module for Registry Tool. */
|
||||
@Module
|
||||
abstract class RegistryToolModule {
|
||||
|
||||
@Provides
|
||||
static RegistryToolEnvironment provideRegistryToolEnvironment() {
|
||||
return RegistryToolEnvironment.get();
|
||||
}
|
||||
|
||||
@Binds
|
||||
abstract StringGenerator provideStringGenerator(RandomStringGenerator stringGenerator);
|
||||
|
||||
@Provides
|
||||
static SecureRandom provideSecureRandom() {
|
||||
try {
|
||||
return SecureRandom.getInstance("NativePRNG");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new ProviderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("alphabetBase64")
|
||||
static String provideAlphabetBase64() {
|
||||
return Alphabets.BASE_64;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("alphabetBase58")
|
||||
static String provideAlphabetBase58() {
|
||||
return Alphabets.BASE_58;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("base58StringGenerator")
|
||||
static StringGenerator provideBase58StringGenerator(
|
||||
@Named("alphabetBase58") String alphabet, SecureRandom random) {
|
||||
return new RandomStringGenerator(alphabet, random);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import com.google.common.base.Throwables;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.re2j.Pattern;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.model.common.GaeUserIdConverter;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
|
@ -139,7 +140,9 @@ final class SetupOteCommand extends ConfirmingCommand implements CommandWithRemo
|
|||
)
|
||||
private boolean eapOnly = false;
|
||||
|
||||
@Inject StringGenerator passwordGenerator;
|
||||
@Inject
|
||||
@Config("base64StringGenerator")
|
||||
StringGenerator passwordGenerator;
|
||||
|
||||
/**
|
||||
* Long registrar names are truncated and then have an incrementing digit appended at the end so
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue