1
0
mirror of https://github.com/google/nomulus synced 2026-01-05 04:56:03 +00:00

Add a frontend endpoint for retrieving a domain in JSON form (#1916)

We might (likely will) modify some of the fiddly bits around this (maybe
the GSON serialization, where we do the actual authorization, etc) but
this should be a decent basic shell structure for endpoints that the new
registrar console can call to retrieve JSON results.
This commit is contained in:
gbrodman
2023-02-09 15:09:42 -05:00
committed by GitHub
parent 28c7bc3085
commit b1cd8c5a6f
12 changed files with 321 additions and 16 deletions

View File

@@ -0,0 +1,41 @@
// Copyright 2023 The Nomulus Authors. 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 google.registry.util;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Objects;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
/** GSON type adapter for Joda {@link DateTime} objects. */
public class DateTimeTypeAdapter extends TypeAdapter<DateTime> {
@Override
public void write(JsonWriter out, DateTime value) throws IOException {
out.value(Objects.toString(value));
}
@Override
public DateTime read(JsonReader in) throws IOException {
String stringValue = in.nextString();
if (stringValue.equals("null")) {
return null;
}
return ISODateTimeFormat.dateTime().withZoneUTC().parseDateTime(stringValue);
}
}

View File

@@ -16,6 +16,8 @@ package google.registry.util;
import com.google.appengine.api.modules.ModulesService;
import com.google.appengine.api.modules.ModulesServiceFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
@@ -25,6 +27,7 @@ import java.security.SecureRandom;
import java.util.Random;
import javax.inject.Named;
import javax.inject.Singleton;
import org.joda.time.DateTime;
/** Dagger module to provide instances of various utils classes. */
@Module
@@ -83,4 +86,13 @@ public abstract class UtilsModule {
public static StringGenerator provideDigitsOnlyStringGenerator(SecureRandom secureRandom) {
return new RandomStringGenerator(StringGenerator.Alphabets.DIGITS_ONLY, secureRandom);
}
@Singleton
@Provides
public static Gson provideGson() {
return new GsonBuilder()
.registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
.excludeFieldsWithoutExposeAnnotation()
.create();
}
}