mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Allow setting DS records in create_domain and update_domain
The DS records consist of 4 values: - keyTag: unsigned short (2 bytes) - alg: unsigned byte - digestType: unsigned byte - digest: binary hex NOTE: the current CL doesn't support keyData, neither as the optional field in dsData nor as a replacement for dsData The command tool accepts DS records as a string, where the 4 values are given as one string separated by white-spaces as follows: <keyTag> <alg> <digestType> <digest> e.g. something like: 60485 5 2 D4B7D520E7BB5F0F67674A0CCEB1E3E0614B93C4F9E99B8383F6A1E4469DA50A which is how it's written in Zone files, allowing easy copy-paste from existing values. ommas is confusing when using spaces. The various "numbers" (keyTag, alg, digestType) are only checked that they are positive integers - the rest is left for the server. digest it checked to be an even-lengthed hex string. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=184583068
This commit is contained in:
parent
e5b000638b
commit
2e62ad2658
17 changed files with 565 additions and 5 deletions
|
@ -15,11 +15,20 @@
|
|||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static google.registry.util.CollectionUtils.findDuplicates;
|
||||
|
||||
import com.beust.jcommander.IStringConverter;
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.template.soy.data.SoyListData;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -67,8 +76,78 @@ abstract class CreateOrUpdateDomainCommand extends MutatingEppToolCommand {
|
|||
)
|
||||
String password;
|
||||
|
||||
@Parameter(
|
||||
names = "--ds_records",
|
||||
description =
|
||||
"Comma-separated list of DS records. Each DS record is given as "
|
||||
+ "<keyTag> <alg> <digestType> <digest>, in order, as it appears in the Zonefile.",
|
||||
converter = DsRecordConverter.class
|
||||
)
|
||||
List<DsRecord> dsRecords = new ArrayList<>();
|
||||
|
||||
Set<String> domains;
|
||||
|
||||
@AutoValue
|
||||
abstract static class DsRecord {
|
||||
private static final Splitter SPLITTER =
|
||||
Splitter.on(CharMatcher.whitespace()).omitEmptyStrings();
|
||||
|
||||
public abstract int keyTag();
|
||||
public abstract int alg();
|
||||
public abstract int digestType();
|
||||
public abstract String digest();
|
||||
|
||||
private static DsRecord create(int keyTag, int alg, int digestType, String digest) {
|
||||
digest = Ascii.toUpperCase(digest);
|
||||
checkArgument(
|
||||
BaseEncoding.base16().canDecode(digest),
|
||||
"digest should be even-lengthed hex, but is %s (length %s)",
|
||||
digest,
|
||||
digest.length());
|
||||
return new AutoValue_CreateOrUpdateDomainCommand_DsRecord(keyTag, alg, digestType, digest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string representation of the DS record.
|
||||
*
|
||||
* <p>The string format accepted is "[keyTag] [alg] [digestType] [digest]" (i.e., the 4
|
||||
* arguments separated by any number of spaces, as it appears in the Zone file)
|
||||
*/
|
||||
public static DsRecord parse(String dsRecord) {
|
||||
List<String> elements = SPLITTER.splitToList(dsRecord);
|
||||
checkArgument(
|
||||
elements.size() == 4,
|
||||
"dsRecord %s should have 4 parts, but has %s",
|
||||
dsRecord,
|
||||
elements.size());
|
||||
return DsRecord.create(
|
||||
Integer.parseUnsignedInt(elements.get(0)),
|
||||
Integer.parseUnsignedInt(elements.get(1)),
|
||||
Integer.parseUnsignedInt(elements.get(2)),
|
||||
elements.get(3));
|
||||
}
|
||||
|
||||
public SoyMapData toSoyData() {
|
||||
return new SoyMapData(
|
||||
"keyTag", keyTag(),
|
||||
"alg", alg(),
|
||||
"digestType", digestType(),
|
||||
"digest", digest());
|
||||
}
|
||||
|
||||
public static SoyListData convertToSoy(List<DsRecord> dsRecords) {
|
||||
return new SoyListData(
|
||||
dsRecords.stream().map(DsRecord::toSoyData).collect(toImmutableList()));
|
||||
}
|
||||
}
|
||||
|
||||
public static class DsRecordConverter implements IStringConverter<DsRecord> {
|
||||
@Override
|
||||
public DsRecord convert(String dsRecord) {
|
||||
return DsRecord.parse(dsRecord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initEppToolCommand() throws Exception {
|
||||
checkArgument(nameservers.size() <= 13, "There can be at most 13 nameservers.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue