Add console-api/settings/security endpoint (#2057)

This commit is contained in:
Pavlo Tkach 2023-07-12 16:19:20 -04:00 committed by GitHub
parent 3ea31d024e
commit 304e7c9726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 396 additions and 3 deletions

View file

@ -19,6 +19,10 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.AbstractSequentialIterator;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.InetAddresses;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
@ -476,4 +480,20 @@ public class CidrAddressBlock implements Iterable<InetAddress>, Serializable {
public String toString() {
return getCidrString(ip, netmask);
}
public static class CidrAddressBlockAdapter extends TypeAdapter<CidrAddressBlock> {
@Override
public CidrAddressBlock read(JsonReader reader) throws IOException {
String stringValue = reader.nextString();
if (stringValue.equals("null")) {
return null;
}
return new CidrAddressBlock(stringValue);
}
@Override
public void write(JsonWriter writer, CidrAddressBlock cidrAddressBlock) throws IOException {
writer.value(cidrAddressBlock.toString());
}
}
}

View file

@ -19,6 +19,7 @@ import com.google.gson.GsonBuilder;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import google.registry.util.CidrAddressBlock.CidrAddressBlockAdapter;
import java.security.NoSuchAlgorithmException;
import java.security.ProviderException;
import java.security.SecureRandom;
@ -79,6 +80,7 @@ public abstract class UtilsModule {
public static Gson provideGson() {
return new GsonBuilder()
.registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
.registerTypeAdapter(CidrAddressBlock.class, new CidrAddressBlockAdapter())
.excludeFieldsWithoutExposeAnnotation()
.create();
}