mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Convert CreateCdnsTld into a ConfirmingCommand
This will result is a prompt like Creating TLD with: projectId= domain-registry-alpha description= some description dnsName= mytld. name= mytld. nameServerSet= cloud-dns-registry-test Perform this command? (y/N): before actually performing the command, and adds a --force flag to bypass the prompt. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=172369944
This commit is contained in:
parent
03087ddc85
commit
af99f64b88
2 changed files with 26 additions and 8 deletions
|
@ -28,11 +28,12 @@ import google.registry.config.RegistryConfig.Config;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@Parameters(separators = " =", commandDescription = "Create a Managed Zone for a TLD in Cloud DNS.")
|
@Parameters(separators = " =", commandDescription = "Create a Managed Zone for a TLD in Cloud DNS.")
|
||||||
class CreateCdnsTld implements Command {
|
class CreateCdnsTld extends ConfirmingCommand {
|
||||||
|
|
||||||
@Parameter(names = "--description", description = "Description of the new TLD.")
|
@Parameter(names = "--description", description = "Description of the new TLD.")
|
||||||
String description;
|
String description;
|
||||||
|
@ -55,21 +56,38 @@ class CreateCdnsTld implements Command {
|
||||||
@Config("projectId")
|
@Config("projectId")
|
||||||
String projectId;
|
String projectId;
|
||||||
|
|
||||||
|
private static final String KEY_VALUE_FORMAT = " %s = %s";
|
||||||
|
|
||||||
|
private ManagedZone requestBody;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() throws IOException, GeneralSecurityException {
|
protected void init() throws IOException, GeneralSecurityException {
|
||||||
ManagedZone requestBody = new ManagedZone();
|
requestBody = new ManagedZone();
|
||||||
requestBody.setDescription(description);
|
requestBody.setDescription(description);
|
||||||
// TODO(b/67413698): allow parameterizing the nameserver set once it's safe to do so.
|
// TODO(b/67413698): allow parameterizing the nameserver set once it's safe to do so.
|
||||||
requestBody.setNameServerSet("cloud-dns-registry-test");
|
requestBody.setNameServerSet("cloud-dns-registry-test");
|
||||||
requestBody.setDnsName(dnsName);
|
requestBody.setDnsName(dnsName);
|
||||||
requestBody.setName((name != null) ? name : dnsName);
|
requestBody.setName((name != null) ? name : dnsName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String prompt() {
|
||||||
|
return String.format(
|
||||||
|
"Creating TLD with:\n%s\n%s",
|
||||||
|
String.format(KEY_VALUE_FORMAT, "projectId", projectId),
|
||||||
|
requestBody
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(entry -> String.format(KEY_VALUE_FORMAT, entry.getKey(), entry.getValue()))
|
||||||
|
.collect(Collectors.joining("\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute() throws IOException, GeneralSecurityException {
|
||||||
Dns dnsService = createDnsService();
|
Dns dnsService = createDnsService();
|
||||||
Dns.ManagedZones.Create request = dnsService.managedZones().create(projectId, requestBody);
|
Dns.ManagedZones.Create request = dnsService.managedZones().create(projectId, requestBody);
|
||||||
|
|
||||||
ManagedZone response = request.execute();
|
ManagedZone response = request.execute();
|
||||||
|
return String.format("Created managed zone: %s", response);
|
||||||
System.err.println("Created managed zone: " + response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicFunctionality() throws Exception {
|
public void testBasicFunctionality() throws Exception {
|
||||||
runCommand("--dns_name=tld.", "--name=tld", "--description=test run");
|
runCommand("--dns_name=tld.", "--name=tld", "--description=test run", "--force");
|
||||||
verify(request).execute();
|
verify(request).execute();
|
||||||
assertThat(projectId.getValue()).isEqualTo("test-project");
|
assertThat(projectId.getValue()).isEqualTo("test-project");
|
||||||
ManagedZone zone = requestBody.getValue();
|
ManagedZone zone = requestBody.getValue();
|
||||||
|
@ -69,7 +69,7 @@ public class CreateCdnsTldTest extends CommandTestCase<CreateCdnsTld> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameDefault() throws Exception {
|
public void testNameDefault() throws Exception {
|
||||||
runCommand("--dns_name=tld.", "--description=test run");
|
runCommand("--dns_name=tld.", "--description=test run", "--force");
|
||||||
ManagedZone zone = requestBody.getValue();
|
ManagedZone zone = requestBody.getValue();
|
||||||
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
|
assertThat(zone.getNameServerSet()).isEqualTo("cloud-dns-registry-test");
|
||||||
assertThat(zone.getDnsName()).isEqualTo("tld.");
|
assertThat(zone.getDnsName()).isEqualTo("tld.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue