Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package google.registry.tools;

import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;

import com.beust.jcommander.Parameter;
Expand All @@ -39,6 +40,19 @@ abstract class CreateOrUpdatePremiumListCommand extends ConfirmingCommand {
protected List<String> inputData;
protected CurrencyUnit currency;

@Parameter(
names = {"-d", "--dry_run"},
description = "Does not execute the entity mutation")
boolean dryRun;

@Parameter(
names = {"--build_environment"},
description =
"DO NOT USE THIS FLAG ON THE COMMAND LINE! This flag indicates the command is being run"
+ " by the build environment tools. This flag should never be used by a human user"
+ " from the command line.")
boolean buildEnv;

@Nullable
@Parameter(
names = {"-n", "--name"},
Expand Down Expand Up @@ -68,4 +82,17 @@ public String execute() throws Exception {
}
return message;
}

@Override
protected boolean dontRunCommand() {
return dryRun;
}

@Override
protected boolean checkExecutionState() {
checkArgument(
!RegistryToolEnvironment.get().equals(RegistryToolEnvironment.PRODUCTION) || buildEnv,
"The --build_environment flag must be used when running in production");
return super.checkExecutionState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package google.registry.tools;

import static com.google.common.base.Preconditions.checkArgument;

import com.beust.jcommander.Parameter;
import com.google.common.flogger.FluentLogger;
import google.registry.model.tld.label.ReservedList;
Expand All @@ -35,6 +37,19 @@ public abstract class CreateOrUpdateReservedListCommand extends ConfirmingComman

static final FluentLogger logger = FluentLogger.forEnclosingClass();

@Parameter(
names = {"-d", "--dry_run"},
description = "Does not execute the entity mutation")
boolean dryRun;

@Parameter(
names = {"--build_environment"},
description =
"DO NOT USE THIS FLAG ON THE COMMAND LINE! This flag indicates the command is being run"
+ " by the build environment tools. This flag should never be used by a human user"
+ " from the command line.")
boolean buildEnv;

@Nullable
@Parameter(
names = {"-n", "--name"},
Expand Down Expand Up @@ -74,4 +89,17 @@ String outputReservedListEntries(ReservedList rl) {
.collect(Collectors.joining(", "))
+ "]";
}

@Override
protected boolean dontRunCommand() {
return dryRun;
}

@Override
protected boolean checkExecutionState() {
checkArgument(
!RegistryToolEnvironment.get().equals(RegistryToolEnvironment.PRODUCTION) || buildEnv,
"The --build_environment flag must be used when running in production");
return super.checkExecutionState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static google.registry.util.ListNamingUtils.convertFilePathToName;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Strings;
import google.registry.model.tld.label.PremiumList;
Expand All @@ -30,27 +29,11 @@
@Parameters(separators = " =", commandDescription = "Update a PremiumList in Database.")
class UpdatePremiumListCommand extends CreateOrUpdatePremiumListCommand {

@Parameter(
names = {"-d", "--dry_run"},
description = "Does not execute the entity mutation")
boolean dryRun;

@Parameter(
names = {"--build_environment"},
description =
"DO NOT USE THIS FLAG ON THE COMMAND LINE! This flag indicates the command is being run"
+ " by the build environment tools. This flag should never be used by a human user"
+ " from the command line.")
boolean buildEnv;

// Indicates if there is a new change made by this command
private boolean newChange = false;

@Override
protected String prompt() throws Exception {
checkArgument(
!RegistryToolEnvironment.get().equals(RegistryToolEnvironment.PRODUCTION) || buildEnv,
"The --build_environment flag must be used when running update_premium_list in production");
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
PremiumList existingList =
PremiumListDao.getLatestRevision(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@

package google.registry.tools;

import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.util.DiffUtils.prettyPrintEntityDeepDiff;
import static google.registry.util.ListNamingUtils.convertFilePathToName;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Strings;
import google.registry.model.tld.label.ReservedList;
Expand All @@ -30,28 +28,11 @@
@Parameters(separators = " =", commandDescription = "Update a ReservedList.")
final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand {

@Parameter(
names = {"-d", "--dry_run"},
description = "Does not execute the entity mutation")
boolean dryRun;

@Parameter(
names = {"--build_environment"},
description =
"DO NOT USE THIS FLAG ON THE COMMAND LINE! This flag indicates the command is being run"
+ " by the build environment tools. This flag should never be used by a human user"
+ " from the command line.")
boolean buildEnv;

// indicates if there is a new change made by this command
private boolean newChange = true;

@Override
protected String prompt() throws Exception {
checkArgument(
!RegistryToolEnvironment.get().equals(RegistryToolEnvironment.PRODUCTION) || buildEnv,
"The --build_environment flag must be used when running update_reserved_list in"
+ " production");
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(input) : name;
ReservedList existingReservedList =
ReservedList.get(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,11 @@ void commandPrompt_failureMismatchedTldName_noOverride() {
+ "yet TLD %s does not exist",
fileName));
}

@Test
void testDryRun_doesNotCreateList() throws Exception {
runCommandForced(
"--name=" + TLD_TEST, "--input=" + premiumTermsPath, "--currency=USD", "--dry_run");
assertThat(PremiumListDao.getLatestRevision(TLD_TEST)).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,11 @@ void testStageEntityChange_succeedsWithEmptyFile() throws Exception {
command.init();
assertThat(command.prompt()).contains("reservedListMap=[]");
}

@Test
void testDryRun_doesNotCreateList() throws Exception {
runCommandForced(
"--name=xn--q9jyb4c_common-reserved", "--input=" + reservedTermsPath, "--dry_run");
assertThat(ReservedList.get("xn--q9jyb4c_common-reserved")).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ void testFailure_runCommandOnProduction_noFlag() throws Exception {
"--name=" + TLD_TEST,
"--input=" + Paths.get(tmpFile.getPath())));
assertThat(thrown.getMessage())
.isEqualTo(
"The --build_environment flag must be used when running update_premium_list in"
+ " production");
.isEqualTo("The --build_environment flag must be used when running in production");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ void testFailure_runCommandOnProduction_noFlag() throws Exception {
"--name=xn--q9jyb4c_common-reserved",
"--input=" + reservedTermsPath));
assertThat(thrown.getMessage())
.isEqualTo(
"The --build_environment flag must be used when running update_reserved_list in"
+ " production");
.isEqualTo("The --build_environment flag must be used when running in production");
}

@Test
Expand Down
Loading