mirror of
https://github.com/google/nomulus.git
synced 2025-05-21 19:59:34 +02:00
Import code from internal repository to git
This commit is contained in:
commit
0ef0c933d2
2490 changed files with 281594 additions and 0 deletions
119
java/com/google/domain/registry/tools/VerifyOteCommand.java
Normal file
119
java/com/google/domain/registry/tools/VerifyOteCommand.java
Normal file
|
@ -0,0 +1,119 @@
|
|||
// Copyright 2016 Google Inc. 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 com.google.domain.registry.tools;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Predicates.notNull;
|
||||
import static com.google.common.base.Verify.verifyNotNull;
|
||||
import static com.google.domain.registry.model.registrar.Registrar.loadByClientId;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.config.RegistryEnvironment;
|
||||
import com.google.domain.registry.model.registrar.Registrar;
|
||||
import com.google.domain.registry.tools.Command.GtechCommand;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.Parameters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/** Command to verify that a registrar has passed OT&E. */
|
||||
@Parameters(
|
||||
separators = " =",
|
||||
commandDescription = "Verify passage of OT&E for specified (or all) registrars")
|
||||
final class VerifyOteCommand implements ServerSideCommand, GtechCommand {
|
||||
|
||||
@Parameter(
|
||||
description = "List of registrar names to check; must be the same names as the ones used "
|
||||
+ "when creating the OT&E accounts")
|
||||
private List<String> mainParameters = new ArrayList<>();
|
||||
|
||||
@Parameter(
|
||||
names = "--check-all",
|
||||
description = "Check the OT&E pass status of all active registrars")
|
||||
private boolean checkAll;
|
||||
|
||||
@Parameter(
|
||||
names = "--summarize",
|
||||
description = "Only show a summary of information")
|
||||
private boolean summarize;
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@Override
|
||||
public void setConnection(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
if (RegistryEnvironment.get() != RegistryEnvironment.SANDBOX) {
|
||||
System.err.printf(
|
||||
"WARNING: Running against %s environment. Are "
|
||||
+ "you sure you didn\'t mean to run this against sandbox (e.g. \"-e SANDBOX\")?%n",
|
||||
RegistryEnvironment.get());
|
||||
}
|
||||
checkArgument(
|
||||
mainParameters.isEmpty() == checkAll,
|
||||
"Must provide at least one registrar name, or supply --check-all with no names.");
|
||||
for (String clientId : mainParameters) {
|
||||
// OT&E registrars are created with clientIDs of registrarName-[1-4], but this command is
|
||||
// passed registrarName. So check the existence of the first persisted registrar to see if
|
||||
// the input is valid.
|
||||
verifyNotNull(loadByClientId(clientId + "-1"), "Registrar %s does not exist.", clientId);
|
||||
}
|
||||
Iterable<String> registrars =
|
||||
mainParameters.isEmpty() ? getAllRegistrarNames() : mainParameters;
|
||||
Map<String, Object> response = connection.sendJson(
|
||||
"/_dr/admin/verifyOte",
|
||||
ImmutableMap.of("summarize", Boolean.toString(summarize), "registrars", registrars));
|
||||
System.out.println(Strings.repeat("-", 80));
|
||||
for (Entry<String, Object> registrar : response.entrySet()) {
|
||||
System.out.printf(
|
||||
summarize ? "%-20s - %s\n" : "\n=========== %s OT&E status ============\n%s\n",
|
||||
registrar.getKey(),
|
||||
registrar.getValue());
|
||||
}
|
||||
System.out.println(Strings.repeat("-", 80));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of all active registrars. Finds registrar accounts with clientIds matching
|
||||
* the format used for OT&E accounts (regname-1, regname-2, etc.) and returns just the common
|
||||
* prefixes of those accounts (in this case, regname).
|
||||
*/
|
||||
private ImmutableSet<String> getAllRegistrarNames() {
|
||||
return Registrar.loadAllActive()
|
||||
.transform(new Function<Registrar, String>() {
|
||||
@Override
|
||||
public String apply(Registrar registrar) {
|
||||
String name = registrar.getClientIdentifier();
|
||||
// Look for names of the form "regname-1", "regname-2", etc. and strip the -# suffix.
|
||||
String replacedName = name.replaceFirst("^(.*)-[1234]$", "$1");
|
||||
// Check if any replacement happened, and thus whether the name matches the format.
|
||||
// If it matches, provide the shortened name, and otherwise return null.
|
||||
return name.equals(replacedName) ? null : replacedName;
|
||||
}})
|
||||
.filter(notNull())
|
||||
.toSet();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue