mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 14:54:51 +02:00
Delete admin console
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=116894352
This commit is contained in:
parent
6772b2ef80
commit
f2116093b1
33 changed files with 2 additions and 2912 deletions
|
@ -6,8 +6,6 @@ java_library(
|
|||
srcs = glob(["*.java"]),
|
||||
resources = [
|
||||
"//java/com/google/domain/registry/ui:globals.txt",
|
||||
"//java/com/google/domain/registry/ui/css:admin_bin.css.js",
|
||||
"//java/com/google/domain/registry/ui/css:admin_dbg.css.js",
|
||||
"//java/com/google/domain/registry/ui/css:registrar_bin.css.js",
|
||||
"//java/com/google/domain/registry/ui/css:registrar_dbg.css.js",
|
||||
],
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
// 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.ui.server.admin;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.domain.registry.config.RegistryConfig;
|
||||
import com.google.domain.registry.config.RegistryEnvironment;
|
||||
import com.google.domain.registry.request.HttpException.NotFoundException;
|
||||
import com.google.domain.registry.security.JsonResponseHelper;
|
||||
import com.google.domain.registry.security.JsonTransportServlet;
|
||||
import com.google.domain.registry.ui.forms.FormFieldException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/** A servlet for callbacks that manipulate resources. */
|
||||
public abstract class AdminResourceServlet extends JsonTransportServlet {
|
||||
|
||||
private static final RegistryConfig CONFIG = RegistryEnvironment.get().config();
|
||||
public static final String XSRF_SCOPE = "admin";
|
||||
|
||||
public AdminResourceServlet() {
|
||||
super(XSRF_SCOPE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> doJsonPost(HttpServletRequest req, Map<String, ?> params) {
|
||||
String op = Optional.fromNullable((String) params.get("op")).or("read");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> args = (Map<String, Object>) Optional.<Object>fromNullable(params.get("args"))
|
||||
.or(ImmutableMap.of());
|
||||
try {
|
||||
switch (op) {
|
||||
case "create":
|
||||
return create(req, args);
|
||||
case "update":
|
||||
return update(req, args);
|
||||
case "delete":
|
||||
return delete(req, args);
|
||||
case "read":
|
||||
return read(req, args);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown operation: " + op);
|
||||
}
|
||||
} catch (FormFieldException e) {
|
||||
return JsonResponseHelper.createFormFieldError(e.getMessage(), e.getFieldName());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Map<String, Object> create(HttpServletRequest req, Map<String, ?> args) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Map<String, Object> read(HttpServletRequest req, Map<String, ?> args) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Map<String, Object> update(HttpServletRequest req, Map<String, ?> args) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Map<String, Object> delete(HttpServletRequest req, Map<String, ?> args) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <T> ImmutableList<T> getParamList(Map<String, ?> map, String identifier) {
|
||||
return ImmutableList.copyOf(
|
||||
Optional.fromNullable((Iterable<T>) map.get(identifier)).or(ImmutableList.<T>of()));
|
||||
}
|
||||
|
||||
/** Like checkNotNull, but throws NotFoundException if given arg is null. */
|
||||
protected static <T> T checkExists(@Nullable T obj, String msg) {
|
||||
if (obj == null) {
|
||||
throw new NotFoundException(msg);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
protected static String getValAsString(Map<String, ?> map, String identifier) {
|
||||
return (String) map.get(identifier);
|
||||
}
|
||||
|
||||
/** Returns the last path element or null if no path separator exists. */
|
||||
@VisibleForTesting
|
||||
String parsePath(HttpServletRequest req) {
|
||||
String uri = req.getRequestURI();
|
||||
String prefix = CONFIG.getAdminServletPathPrefix() + "/";
|
||||
checkArgument(
|
||||
uri.startsWith(prefix),
|
||||
"Request URI must start with: %s",
|
||||
prefix);
|
||||
return uri.substring(prefix.length());
|
||||
}
|
||||
|
||||
/** @return the last path element or null if no path separator exists. */
|
||||
@Nullable
|
||||
protected String parseId(HttpServletRequest req) {
|
||||
String[] pathParts = parsePath(req).split("/");
|
||||
return pathParts.length < 2 ? null : pathParts[pathParts.length - 1];
|
||||
}
|
||||
|
||||
/** Like parseId but path must contain at least one path separator. */
|
||||
protected String checkParseId(HttpServletRequest req) {
|
||||
return checkNotNull(parseId(req), "Path must be of the form (/<collection>)+/<id>");
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
// 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.ui.server.admin;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.domain.registry.ui.server.AbstractUiServlet;
|
||||
import com.google.domain.registry.ui.server.SoyTemplateUtils;
|
||||
import com.google.domain.registry.ui.soy.admin.ConsoleSoyInfo;
|
||||
import com.google.template.soy.shared.SoyCssRenamingMap;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
|
||||
/** UI for Registry operations. */
|
||||
public class AdminUiServlet extends AbstractUiServlet {
|
||||
|
||||
@VisibleForTesting
|
||||
static final Supplier<SoyTofu> TOFU_SUPPLIER =
|
||||
SoyTemplateUtils.createTofuSupplier(
|
||||
com.google.domain.registry.ui.soy.ConsoleSoyInfo.getInstance(),
|
||||
com.google.domain.registry.ui.soy.admin.ConsoleSoyInfo.getInstance());
|
||||
|
||||
public static final Supplier<SoyCssRenamingMap> CSS_RENAMING_MAP_SUPPLIER =
|
||||
SoyTemplateUtils.createCssRenamingMapSupplier(
|
||||
Resources.getResource("com/google/domain/registry/ui/css/admin_bin.css.js"),
|
||||
Resources.getResource("com/google/domain/registry/ui/css/admin_dbg.css.js"));
|
||||
|
||||
@Override
|
||||
protected String get() {
|
||||
return TOFU_SUPPLIER.get()
|
||||
.newRenderer(ConsoleSoyInfo.MAIN)
|
||||
.setCssRenamingMap(CSS_RENAMING_MAP_SUPPLIER.get())
|
||||
.setData(getTemplateArgs(AdminResourceServlet.XSRF_SCOPE))
|
||||
.render();
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
|
||||
|
||||
|
||||
java_library(
|
||||
name = "admin",
|
||||
srcs = glob(["*.java"]),
|
||||
resources = [
|
||||
"//java/com/google/domain/registry/ui/css:admin_bin.css.js",
|
||||
"//java/com/google/domain/registry/ui/css:admin_dbg.css.js",
|
||||
],
|
||||
deps = [
|
||||
"//java/com/google/common/annotations",
|
||||
"//java/com/google/common/base",
|
||||
"//java/com/google/common/collect",
|
||||
"//java/com/google/common/io",
|
||||
"//java/com/google/domain/registry/config",
|
||||
"//java/com/google/domain/registry/export/sheet",
|
||||
"//java/com/google/domain/registry/flows",
|
||||
"//java/com/google/domain/registry/model",
|
||||
"//java/com/google/domain/registry/request",
|
||||
"//java/com/google/domain/registry/security",
|
||||
"//java/com/google/domain/registry/security:servlets",
|
||||
"//java/com/google/domain/registry/ui/forms",
|
||||
"//java/com/google/domain/registry/ui/server",
|
||||
"//java/com/google/domain/registry/ui/server/registrar",
|
||||
"//java/com/google/domain/registry/ui/soy:soy_java_wrappers",
|
||||
"//java/com/google/domain/registry/ui/soy/admin:soy_java_wrappers",
|
||||
"//java/com/google/domain/registry/util",
|
||||
"//third_party/java/joda_time",
|
||||
"//third_party/java/jsr305_annotations",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
|
||||
"//third_party/closure/templates",
|
||||
],
|
||||
)
|
|
@ -1,165 +0,0 @@
|
|||
// 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.ui.server.admin;
|
||||
|
||||
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.export.sheet.SyncRegistrarsSheetTask;
|
||||
import com.google.domain.registry.model.registrar.Registrar;
|
||||
import com.google.domain.registry.model.registrar.RegistrarContact;
|
||||
import com.google.domain.registry.ui.forms.FormFields;
|
||||
import com.google.domain.registry.ui.server.RegistrarFormFields;
|
||||
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Admin servlet that allows creating or updating a registrar. Deletes are not allowed so as to
|
||||
* preserve history.
|
||||
*/
|
||||
public class RegistrarServlet extends AdminResourceServlet {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> create(HttpServletRequest req, final Map<String, ?> args) {
|
||||
final String clientIdentifier = FormFields.CLID.convert(parseId(req)).get();
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
Registrar registrar = new Registrar.Builder()
|
||||
.setClientIdentifier(clientIdentifier)
|
||||
.setRegistrarName(clientIdentifier)
|
||||
.setType(Registrar.Type.TEST)
|
||||
.setState(Registrar.State.ACTIVE)
|
||||
.setAllowedTlds(ImmutableSet.<String>of())
|
||||
.build();
|
||||
Registrar.Builder builder = registrar.asBuilder();
|
||||
Set<RegistrarContact> contacts = update(registrar, builder, args);
|
||||
registrar = builder.build();
|
||||
ofy().save().entity(registrar);
|
||||
if (!contacts.isEmpty()) {
|
||||
RegistrarContact.updateContacts(registrar, contacts);
|
||||
}
|
||||
}});
|
||||
return ImmutableMap.<String, Object>of("results", ImmutableList.of(clientIdentifier + ": ok"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> read(HttpServletRequest req, Map<String, ?> args) {
|
||||
String clientIdentifier = parseId(req);
|
||||
if (clientIdentifier == null) {
|
||||
List<Map<String, ?>> registrars = new ArrayList<>();
|
||||
for (Registrar registrar : Registrar.loadAll()) {
|
||||
registrars.add(registrar.toJsonMap());
|
||||
}
|
||||
return ImmutableMap.<String, Object>of("set", registrars);
|
||||
}
|
||||
Registrar registrar = Registrar.loadByClientId(clientIdentifier);
|
||||
checkExists(registrar, "No registrar exists with the given client id: " + clientIdentifier);
|
||||
return ImmutableMap.<String, Object>of("item", registrar.toJsonMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(HttpServletRequest req, final Map<String, ?> args) {
|
||||
final String clientIdentifier = checkParseId(req);
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
Registrar registrar = Registrar.loadByClientId(clientIdentifier);
|
||||
Registrar.Builder builder = checkExists(
|
||||
registrar,
|
||||
"No registrar exists with the given client id: " + clientIdentifier)
|
||||
.asBuilder();
|
||||
Set<RegistrarContact> updatedContacts = update(registrar, builder, args);
|
||||
if (!updatedContacts.isEmpty()) {
|
||||
builder.setContactsRequireSyncing(true);
|
||||
}
|
||||
Registrar updatedRegistrar = builder.build();
|
||||
ofy().save().entity(updatedRegistrar);
|
||||
if (!updatedContacts.isEmpty()) {
|
||||
RegistrarContact.updateContacts(updatedRegistrar, updatedContacts);
|
||||
}
|
||||
SyncRegistrarsSheetTask.enqueueBackendTask();
|
||||
}});
|
||||
return ImmutableMap.<String, Object>of("results", ImmutableList.of(clientIdentifier + ": ok"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin fields are updated and then a chained call is made to
|
||||
* {@link com.google.domain.registry.ui.server.registrar.RegistrarServlet#update(
|
||||
* Registrar, Registrar.Builder, Map)}
|
||||
* for the shared fields.
|
||||
*/
|
||||
private static Set<RegistrarContact> update(
|
||||
Registrar existingRegistrarObj, Registrar.Builder builder, Map<String, ?> args) {
|
||||
// Admin only settings
|
||||
for (Registrar.State state :
|
||||
RegistrarFormFields.STATE_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setState(state);
|
||||
}
|
||||
builder.setAllowedTlds(
|
||||
RegistrarFormFields.ALLOWED_TLDS_FIELD.extractUntyped(args).or(ImmutableSet.<String>of()));
|
||||
Boolean blockPremiumNames =
|
||||
RegistrarFormFields.BLOCK_PREMIUM_NAMES_FIELD.extractUntyped(args).orNull();
|
||||
builder.setBlockPremiumNames(blockPremiumNames == null ? false : blockPremiumNames);
|
||||
for (String password :
|
||||
RegistrarFormFields.PASSWORD_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setPassword(password);
|
||||
}
|
||||
for (Long billingIdentifier :
|
||||
RegistrarFormFields.BILLING_IDENTIFIER_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setBillingIdentifier(billingIdentifier);
|
||||
}
|
||||
|
||||
// Resources
|
||||
for (String driveFolderId :
|
||||
RegistrarFormFields.DRIVE_FOLDER_ID_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setDriveFolderId(driveFolderId);
|
||||
}
|
||||
|
||||
// WHOIS
|
||||
for (String registrarName :
|
||||
RegistrarFormFields.NAME_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setRegistrarName(registrarName);
|
||||
}
|
||||
for (Long ianaIdentifier :
|
||||
RegistrarFormFields.IANA_IDENTIFIER_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setIanaIdentifier(ianaIdentifier);
|
||||
}
|
||||
builder.setIcannReferralEmail(
|
||||
RegistrarFormFields.ICANN_REFERRAL_EMAIL_FIELD.extractUntyped(args).get());
|
||||
|
||||
// Security
|
||||
for (String phonePasscode :
|
||||
RegistrarFormFields.PHONE_PASSCODE_FIELD.extractUntyped(args).asSet()) {
|
||||
builder.setPhonePasscode(phonePasscode);
|
||||
}
|
||||
|
||||
// Will this ever get used?
|
||||
builder.setUrl(
|
||||
RegistrarFormFields.URL_FIELD.extractUntyped(args).orNull());
|
||||
|
||||
return com.google.domain.registry.ui.server.registrar.RegistrarServlet.update(
|
||||
existingRegistrarObj, builder, args);
|
||||
}
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
// 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.ui.server.admin;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static com.google.domain.registry.model.registry.Registries.getTlds;
|
||||
import static com.google.domain.registry.util.DomainNameUtils.canonicalizeDomainName;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.domain.registry.model.registry.Registry;
|
||||
import com.google.domain.registry.model.registry.Registry.TldState;
|
||||
import com.google.domain.registry.util.SystemClock;
|
||||
|
||||
import com.googlecode.objectify.VoidWork;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.joda.time.Seconds;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* RESTful CRUD bindings for Registry objects.
|
||||
*/
|
||||
public class RegistryServlet extends AdminResourceServlet {
|
||||
|
||||
private static final SystemClock CLOCK = new SystemClock();
|
||||
|
||||
@Override
|
||||
Map<String, Object> create(HttpServletRequest req, Map<String, ?> args) {
|
||||
final String tld = checkParseId(req);
|
||||
checkArgument(tld.equals(canonicalizeDomainName(tld)));
|
||||
try {
|
||||
ofy().transact(new VoidWork() {
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(new Registry.Builder().setTldStr(tld).build());
|
||||
}});
|
||||
return ImmutableMap.<String, Object>of("results", ImmutableList.of(tld + ": ok"));
|
||||
} catch (Exception e) {
|
||||
return ImmutableMap.<String, Object>of("results", ImmutableList.of(tld + ": " + e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Map<String, Object> read(HttpServletRequest req, Map<String, ?> args) {
|
||||
String id = parseId(req);
|
||||
if (id != null) {
|
||||
return readTld(id);
|
||||
}
|
||||
// Collection request; if no item specified, return all.
|
||||
return ImmutableMap.<String, Object>of("set", readTlds(getTlds()));
|
||||
}
|
||||
|
||||
Map<String, Object> readTld(String tld) {
|
||||
return ImmutableMap.<String, Object>of("item", toResultObject(
|
||||
checkExists(Registry.get(tld), "No registry exists for the given tld: " + tld)));
|
||||
}
|
||||
|
||||
List<Map<String, ?>> readTlds(Set<String> tlds) {
|
||||
List<Map<String, ?>> registries = new ArrayList<>();
|
||||
for (String tld : tlds) {
|
||||
registries.add(toResultObject(Registry.get(tld)));
|
||||
}
|
||||
return registries;
|
||||
}
|
||||
|
||||
Map<String, Object> toResultObject(Registry r) {
|
||||
return new ImmutableSortedMap.Builder<String, Object>(Ordering.natural())
|
||||
.put("name", r.getTld().toString())
|
||||
.put("state", r.getTldState(CLOCK.nowUtc()).toString())
|
||||
.put("tldStateTransitions", r.getTldStateTransitions().toString())
|
||||
.put("creationTime", Objects.toString(r.getCreationTime(), ""))
|
||||
.put("lastUpdateTime", Objects.toString(r.getUpdateAutoTimestamp().getTimestamp(), ""))
|
||||
.put("addGracePeriod", r.getAddGracePeriodLength().toStandardSeconds().toString())
|
||||
.put("autoRenewGracePeriod", r.getAutoRenewGracePeriodLength().toStandardSeconds().toString())
|
||||
.put("redemptionGracePeriod", r.getRedemptionGracePeriodLength().toStandardSeconds().toString())
|
||||
.put("renewGracePeriod", r.getRenewGracePeriodLength().toStandardSeconds().toString())
|
||||
.put("transferGracePeriod", r.getTransferGracePeriodLength().toStandardSeconds().toString())
|
||||
.put("automaticTransferLength", r.getAutomaticTransferLength().toStandardSeconds().toString())
|
||||
.put("pendingDeleteLength", r.getPendingDeleteLength().toStandardSeconds().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
ImmutableSortedMap<DateTime, TldState> getTldStateTransitions(Map<String, ?> args) {
|
||||
ImmutableSortedMap.Builder<DateTime, TldState> builder = ImmutableSortedMap.naturalOrder();
|
||||
for (Map<String, ?> tldStateTransition
|
||||
: AdminResourceServlet.<Map<String, ?>>getParamList(args, "tldStateTransitions")) {
|
||||
builder.put(
|
||||
DateTime.parse(getValAsString(tldStateTransition, "transitionTime")),
|
||||
TldState.valueOf(getValAsString(tldStateTransition, "tldState")));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
Duration getValAsDuration(Map<String, ?> map, String identifier) {
|
||||
return Seconds.parseSeconds(getValAsString(map, identifier)).toStandardDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
Map<String, Object> update(HttpServletRequest req, Map<String, ?> args) {
|
||||
String tld = checkParseId(req);
|
||||
|
||||
ImmutableSortedMap<DateTime, TldState> tldStateTransitions =
|
||||
getTldStateTransitions(args);
|
||||
Duration addGracePeriodLength = getValAsDuration(args, "addGracePeriod");
|
||||
Duration autoRenewGracePeriodLength = getValAsDuration(args, "autoRenewGracePeriod");
|
||||
Duration redemptionGracePeriodLength = getValAsDuration(args, "redemptionGracePeriod");
|
||||
Duration renewGracePeriodLength = getValAsDuration(args, "renewGracePeriod");
|
||||
Duration transferGracePeriodLength = getValAsDuration(args, "transferGracePeriod");
|
||||
Duration automaticTransferLength = getValAsDuration(args, "automaticTransferLength");
|
||||
Duration pendingDeleteLength = getValAsDuration(args, "pendingDeleteLength");
|
||||
|
||||
try {
|
||||
final Registry.Builder registry = Registry.get(tld).asBuilder();
|
||||
if (!tldStateTransitions.isEmpty()) {
|
||||
registry.setTldStateTransitions(tldStateTransitions);
|
||||
}
|
||||
if (!addGracePeriodLength.equals(Duration.ZERO)) {
|
||||
registry.setAddGracePeriodLength(addGracePeriodLength);
|
||||
}
|
||||
if (!autoRenewGracePeriodLength.equals(Duration.ZERO)) {
|
||||
registry.setAutoRenewGracePeriodLength(autoRenewGracePeriodLength);
|
||||
}
|
||||
if (!redemptionGracePeriodLength.equals(Duration.ZERO)) {
|
||||
registry.setRedemptionGracePeriodLength(redemptionGracePeriodLength);
|
||||
}
|
||||
if (!renewGracePeriodLength.equals(Duration.ZERO)) {
|
||||
registry.setRenewGracePeriodLength(renewGracePeriodLength);
|
||||
}
|
||||
if (!transferGracePeriodLength.equals(Duration.ZERO)) {
|
||||
registry.setTransferGracePeriodLength(transferGracePeriodLength);
|
||||
}
|
||||
if (!automaticTransferLength.equals(Duration.ZERO)) {
|
||||
registry.setAutomaticTransferLength(automaticTransferLength);
|
||||
}
|
||||
if (!pendingDeleteLength.equals(Duration.ZERO)) {
|
||||
registry.setPendingDeleteLength(pendingDeleteLength);
|
||||
}
|
||||
ofy().transact(new VoidWork(){
|
||||
@Override
|
||||
public void vrun() {
|
||||
ofy().save().entity(registry.build());
|
||||
}});
|
||||
return ImmutableMap.<String, Object>of("results", "OK");
|
||||
} catch (Exception e) {
|
||||
return ImmutableMap.<String, Object>of("results", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
// 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.
|
||||
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
package com.google.domain.registry.ui.server.admin;
|
Loading…
Add table
Add a link
Reference in a new issue