mirror of
https://github.com/google/nomulus.git
synced 2025-08-15 05:54:06 +02:00
parent
0c6f399533
commit
2495167215
5 changed files with 18 additions and 77 deletions
|
@ -194,18 +194,6 @@ public class GracePeriod extends GracePeriodBase implements DatastoreAndSqlEntit
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a clone of this {@link GracePeriod} with {@link #billingEventRecurring} set to the
|
|
||||||
* given value.
|
|
||||||
*
|
|
||||||
* <p>TODO(b/162231099): Remove this function after duplicate id issue is solved.
|
|
||||||
*/
|
|
||||||
public GracePeriod cloneWithRecurringBillingEvent(VKey<BillingEvent.Recurring> recurring) {
|
|
||||||
GracePeriod clone = clone(this);
|
|
||||||
clone.billingEventRecurring = BillingRecurrenceVKey.create(recurring);
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Entity class to represent a historic {@link GracePeriod}. */
|
/** Entity class to represent a historic {@link GracePeriod}. */
|
||||||
@Entity(name = "GracePeriodHistory")
|
@Entity(name = "GracePeriodHistory")
|
||||||
@Table(indexes = @Index(columnList = "domainRepoId"))
|
@Table(indexes = @Index(columnList = "domainRepoId"))
|
||||||
|
|
|
@ -15,18 +15,14 @@
|
||||||
package google.registry.tools;
|
package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
|
||||||
import static com.google.common.collect.ImmutableSetMultimap.flatteningToImmutableSetMultimap;
|
import static com.google.common.collect.ImmutableSetMultimap.flatteningToImmutableSetMultimap;
|
||||||
import static google.registry.util.CollectionUtils.nullToEmpty;
|
import static google.registry.util.CollectionUtils.nullToEmpty;
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
|
|
||||||
|
|
||||||
import com.beust.jcommander.Parameter;
|
import com.beust.jcommander.Parameter;
|
||||||
import com.beust.jcommander.Parameters;
|
import com.beust.jcommander.Parameters;
|
||||||
import com.google.api.services.appengine.v1.Appengine;
|
import com.google.api.services.appengine.v1.Appengine;
|
||||||
import com.google.common.base.Enums;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.ImmutableSetMultimap;
|
import com.google.common.collect.ImmutableSetMultimap;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
|
@ -35,8 +31,6 @@ import google.registry.request.Action.Service;
|
||||||
import google.registry.util.AppEngineServiceUtils;
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Set;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/** A command to set the number of instances for an App Engine service. */
|
/** A command to set the number of instances for an App Engine service. */
|
||||||
|
@ -49,19 +43,18 @@ final class SetNumInstancesCommand implements CommandWithRemoteApi {
|
||||||
|
|
||||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||||
|
|
||||||
private static final ImmutableSet<Service> ALL_DEPLOYED_SERVICES =
|
private static final ImmutableList<Service> ALL_DEPLOYED_SERVICES =
|
||||||
ImmutableSet.copyOf(Service.values());
|
ImmutableList.copyOf(Service.values());
|
||||||
|
|
||||||
private static final ImmutableMap<String, Service> SERVICE_ID_TO_SERVICE =
|
private static final ImmutableMap<String, Service> SERVICE_ID_TO_SERVICE =
|
||||||
Maps.uniqueIndex(ALL_DEPLOYED_SERVICES, Service::getServiceId);
|
Maps.uniqueIndex(ALL_DEPLOYED_SERVICES, Service::getServiceId);
|
||||||
|
|
||||||
// TODO(b/119629679): Use List<Service> after upgrading jcommander to latest version.
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"-s", "--services"},
|
names = {"-s", "--services"},
|
||||||
description =
|
description =
|
||||||
"Comma-delimited list of App Engine services to set. "
|
"Comma-delimited list of App Engine services to set. "
|
||||||
+ "Allowed values: [DEFAULT, TOOLS, BACKEND, PUBAPI]")
|
+ "Allowed values: [DEFAULT, TOOLS, BACKEND, PUBAPI]")
|
||||||
private List<String> serviceNames = ImmutableList.of();
|
private List<Service> services = ImmutableList.of();
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"-v", "--versions"},
|
names = {"-v", "--versions"},
|
||||||
|
@ -93,19 +86,6 @@ final class SetNumInstancesCommand implements CommandWithRemoteApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
ImmutableSet<Service> services =
|
|
||||||
serviceNames.stream()
|
|
||||||
.map(s -> s.toUpperCase(Locale.US))
|
|
||||||
.map(
|
|
||||||
name ->
|
|
||||||
checkArgumentPresent(
|
|
||||||
Enums.getIfPresent(Service.class, name).toJavaUtil(),
|
|
||||||
"Invalid service '%s'. Allowed values are %s",
|
|
||||||
name,
|
|
||||||
ALL_DEPLOYED_SERVICES))
|
|
||||||
.collect(toImmutableSet());
|
|
||||||
|
|
||||||
if (nonLiveVersions) {
|
if (nonLiveVersions) {
|
||||||
checkArgument(versions.isEmpty(), "--versions cannot be set if --non_live_versions is set");
|
checkArgument(versions.isEmpty(), "--versions cannot be set if --non_live_versions is set");
|
||||||
|
|
||||||
|
@ -149,7 +129,7 @@ final class SetNumInstancesCommand implements CommandWithRemoteApi {
|
||||||
version, service, numInstances);
|
version, service, numInstances);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableSetMultimap<Service, String> getAllLiveVersionsMap(Set<Service> services) {
|
private ImmutableSetMultimap<Service, String> getAllLiveVersionsMap(List<Service> services) {
|
||||||
try {
|
try {
|
||||||
return nullToEmpty(appengine.apps().services().list(projectId).execute().getServices())
|
return nullToEmpty(appengine.apps().services().list(projectId).execute().getServices())
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -165,7 +145,8 @@ final class SetNumInstancesCommand implements CommandWithRemoteApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableSetMultimap<Service, String> getManualScalingVersionsMap(Set<Service> services) {
|
private ImmutableSetMultimap<Service, String> getManualScalingVersionsMap(
|
||||||
|
List<Service> services) {
|
||||||
return services.stream()
|
return services.stream()
|
||||||
.collect(
|
.collect(
|
||||||
flatteningToImmutableSetMultimap(
|
flatteningToImmutableSetMultimap(
|
||||||
|
|
|
@ -56,7 +56,6 @@ final class ValidateLoginCredentialsCommand implements CommandWithRemoteApi {
|
||||||
validateWith = PathParameter.InputFile.class)
|
validateWith = PathParameter.InputFile.class)
|
||||||
private Path clientCertificatePath;
|
private Path clientCertificatePath;
|
||||||
|
|
||||||
// TODO(sarahbot@): Remove this after hash fallback is removed
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"-h", "--cert_hash"},
|
names = {"-h", "--cert_hash"},
|
||||||
|
|
|
@ -58,22 +58,28 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_emptyService_throwsException() {
|
void test_emptyService_throwsException() {
|
||||||
IllegalArgumentException thrown =
|
ParameterException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
ParameterException.class,
|
||||||
() -> runCommand("--services=", "--versions=version", "--num_instances=5"));
|
() -> runCommand("--services=", "--versions=version", "--num_instances=5"));
|
||||||
assertThat(thrown).hasMessageThat().contains("Invalid service ''");
|
assertThat(thrown)
|
||||||
|
.hasMessageThat()
|
||||||
|
.contains(
|
||||||
|
"Invalid value for -s parameter. Allowed values:[DEFAULT, TOOLS, BACKEND, PUBAPI]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test_invalidService_throwsException() {
|
void test_invalidService_throwsException() {
|
||||||
IllegalArgumentException thrown =
|
ParameterException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
ParameterException.class,
|
||||||
() ->
|
() ->
|
||||||
runCommand(
|
runCommand(
|
||||||
"--services=INVALID,DEFAULT", "--versions=version", "--num_instances=5"));
|
"--services=INVALID,DEFAULT", "--versions=version", "--num_instances=5"));
|
||||||
assertThat(thrown).hasMessageThat().contains("Invalid service 'INVALID'");
|
assertThat(thrown)
|
||||||
|
.hasMessageThat()
|
||||||
|
.contains(
|
||||||
|
"Invalid value for -s parameter. Allowed values:[DEFAULT, TOOLS, BACKEND, PUBAPI]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -456,39 +456,6 @@ class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase {
|
||||||
(builder, s) -> builder.setFailoverClientCertificate(s, clock.nowUtc()));
|
(builder, s) -> builder.setFailoverClientCertificate(s, clock.nowUtc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOfyAndSql
|
|
||||||
void testUpdate_failoverClientCertificateWithViolationsAlreadyExistedSucceeds() {
|
|
||||||
// TODO(sarahbot): remove this test after November 1, 2020.
|
|
||||||
|
|
||||||
// The frontend will always send the entire registrar entity back for an update, so the checks
|
|
||||||
// on the certificate should only run if it is a new certificate
|
|
||||||
|
|
||||||
// Set a bad certificate before checks on uploads are enforced
|
|
||||||
clock.setTo(DateTime.parse("2018-07-02T00:00:00Z"));
|
|
||||||
Registrar existingRegistrar = loadRegistrar(CLIENT_ID);
|
|
||||||
existingRegistrar =
|
|
||||||
existingRegistrar
|
|
||||||
.asBuilder()
|
|
||||||
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT, clock.nowUtc())
|
|
||||||
.build();
|
|
||||||
persistResource(existingRegistrar);
|
|
||||||
|
|
||||||
// Update with the same certificate after enforcement starts
|
|
||||||
clock.setTo(DateTime.parse("2020-11-02T00:00:00Z"));
|
|
||||||
Map<String, Object> args = Maps.newHashMap(loadRegistrar(CLIENT_ID).toJsonMap());
|
|
||||||
args.put("failoverClientCertificate", CertificateSamples.SAMPLE_CERT);
|
|
||||||
Map<String, Object> response =
|
|
||||||
action.handleJsonRequest(
|
|
||||||
ImmutableMap.of(
|
|
||||||
"op", "update",
|
|
||||||
"id", CLIENT_ID,
|
|
||||||
"args", args));
|
|
||||||
|
|
||||||
assertThat(response).containsEntry("status", "SUCCESS");
|
|
||||||
assertMetric(CLIENT_ID, "update", "[OWNER]", "SUCCESS");
|
|
||||||
cloudTasksHelper.assertNoTasksEnqueued("sheet");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestOfyAndSql
|
@TestOfyAndSql
|
||||||
void testUpdate_failoverClientCertificateWithViolationsFails() {
|
void testUpdate_failoverClientCertificateWithViolationsFails() {
|
||||||
clock.setTo(DateTime.parse("2020-11-02T00:00:00Z"));
|
clock.setTo(DateTime.parse("2020-11-02T00:00:00Z"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue