mirror of
https://github.com/google/nomulus
synced 2026-09-19 22:44:26 +00:00
Remove files that are not longer used for create/update premium list (#1288)
* Remove files that are not longer used for create/update premium list * Remove comments/notes related to create/update premium list action files
This commit is contained in:
@@ -30,7 +30,6 @@ import google.registry.request.RequestComponentBuilder;
|
||||
import google.registry.request.RequestModule;
|
||||
import google.registry.request.RequestScope;
|
||||
import google.registry.tools.server.CreateGroupsAction;
|
||||
import google.registry.tools.server.CreatePremiumListAction;
|
||||
import google.registry.tools.server.GenerateZoneFilesAction;
|
||||
import google.registry.tools.server.KillAllCommitLogsAction;
|
||||
import google.registry.tools.server.KillAllEppResourcesAction;
|
||||
@@ -43,7 +42,6 @@ import google.registry.tools.server.ListTldsAction;
|
||||
import google.registry.tools.server.RefreshDnsForAllDomainsAction;
|
||||
import google.registry.tools.server.ResaveAllHistoryEntriesAction;
|
||||
import google.registry.tools.server.ToolsServerModule;
|
||||
import google.registry.tools.server.UpdatePremiumListAction;
|
||||
import google.registry.tools.server.VerifyOteAction;
|
||||
|
||||
/** Dagger component with per-request lifetime for "tools" App Engine module. */
|
||||
@@ -61,7 +59,6 @@ import google.registry.tools.server.VerifyOteAction;
|
||||
})
|
||||
interface ToolsRequestComponent {
|
||||
CreateGroupsAction createGroupsAction();
|
||||
CreatePremiumListAction createPremiumListAction();
|
||||
EppToolAction eppToolAction();
|
||||
FlowComponent.Builder flowComponentBuilder();
|
||||
GenerateZoneFilesAction generateZoneFilesAction();
|
||||
@@ -77,7 +74,6 @@ interface ToolsRequestComponent {
|
||||
RefreshDnsForAllDomainsAction refreshDnsForAllDomainsAction();
|
||||
ResaveAllHistoryEntriesAction resaveAllHistoryEntriesAction();
|
||||
RestoreCommitLogsAction restoreCommitLogsAction();
|
||||
UpdatePremiumListAction updatePremiumListAction();
|
||||
VerifyOteAction verifyOteAction();
|
||||
|
||||
@Subcomponent.Builder
|
||||
|
||||
@@ -43,7 +43,6 @@ public class CreatePremiumListCommand extends CreateOrUpdatePremiumListCommand {
|
||||
String currencyUnit;
|
||||
|
||||
@Override
|
||||
// Using CreatePremiumListAction.java as reference;
|
||||
protected String prompt() throws Exception {
|
||||
currency = CurrencyUnit.of(currencyUnit);
|
||||
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
|
||||
@@ -51,7 +50,6 @@ public class CreatePremiumListCommand extends CreateOrUpdatePremiumListCommand {
|
||||
!PremiumListDao.getLatestRevision(name).isPresent(),
|
||||
"A premium list already exists by this name");
|
||||
if (!override) {
|
||||
// refer to CreatePremiumListAction.java
|
||||
assertTldExists(
|
||||
name,
|
||||
"Premium names must match the name of the TLD they are intended to be used on"
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.util.Optional;
|
||||
class UpdatePremiumListCommand extends CreateOrUpdatePremiumListCommand {
|
||||
|
||||
@Override
|
||||
// Using UpdatePremiumListAction.java as reference;
|
||||
protected String prompt() throws Exception {
|
||||
name = Strings.isNullOrEmpty(name) ? convertFilePathToName(inputFile) : name;
|
||||
Optional<PremiumList> list = PremiumListDao.getLatestRevision(name);
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
// Copyright 2017 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.tools.server;
|
||||
|
||||
import static com.google.common.flogger.LazyArgs.lazy;
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.request.JsonResponse;
|
||||
import google.registry.request.Parameter;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** Abstract base class for actions that update premium lists. */
|
||||
public abstract class CreateOrUpdatePremiumListAction implements Runnable {
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final int MAX_LOGGING_PREMIUM_LIST_LENGTH = 1000;
|
||||
|
||||
public static final String NAME_PARAM = "name";
|
||||
public static final String INPUT_PARAM = "inputData";
|
||||
|
||||
@Inject JsonResponse response;
|
||||
|
||||
@Inject
|
||||
@Parameter("premiumListName")
|
||||
String name;
|
||||
|
||||
@Inject
|
||||
@Parameter(INPUT_PARAM)
|
||||
String inputData;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
checkArgumentNotNull(inputData, "Input data must not be null");
|
||||
save();
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.atInfo().withCause(e).log(
|
||||
"Usage error in attempting to save premium list from nomulus tool command");
|
||||
response.setPayload(ImmutableMap.of("error", e.getMessage(), "status", "error"));
|
||||
} catch (Exception e) {
|
||||
logger.atSevere().withCause(e).log(
|
||||
"Unexpected error saving premium list to Datastore from nomulus tool command");
|
||||
response.setPayload(ImmutableMap.of("error", e.getMessage(), "status", "error"));
|
||||
}
|
||||
}
|
||||
|
||||
/** Logs the premium list data at INFO, truncated if too long. */
|
||||
void logInputData() {
|
||||
String logData = (inputData == null) ? "(null)" : inputData;
|
||||
logger.atInfo().log(
|
||||
"Received the following input data: %s",
|
||||
lazy(
|
||||
() ->
|
||||
(logData.length() < MAX_LOGGING_PREMIUM_LIST_LENGTH)
|
||||
? logData
|
||||
: (logData.substring(0, MAX_LOGGING_PREMIUM_LIST_LENGTH) + "<truncated>")));
|
||||
}
|
||||
|
||||
/** Saves the premium list to both Datastore and Cloud SQL. */
|
||||
protected abstract void save();
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
// Copyright 2017 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.tools.server;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.model.tld.Registries.assertTldExists;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.model.tld.label.PremiumListDao;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Parameter;
|
||||
import google.registry.request.auth.Auth;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
|
||||
/**
|
||||
* An action that creates a premium list, for use by the {@code nomulus create_premium_list}
|
||||
* command.
|
||||
*/
|
||||
@Action(
|
||||
service = Action.Service.TOOLS,
|
||||
path = CreatePremiumListAction.PATH,
|
||||
method = POST,
|
||||
auth = Auth.AUTH_INTERNAL_OR_ADMIN)
|
||||
public class CreatePremiumListAction extends CreateOrUpdatePremiumListAction {
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
public static final String OVERRIDE_PARAM = "override";
|
||||
public static final String PATH = "/_dr/admin/createPremiumList";
|
||||
public static final String CURRENCY = "currency";
|
||||
|
||||
@Inject @Parameter(OVERRIDE_PARAM) boolean override;
|
||||
|
||||
@Inject
|
||||
@Parameter("currency")
|
||||
CurrencyUnit currency;
|
||||
|
||||
@Inject CreatePremiumListAction() {}
|
||||
|
||||
@Override
|
||||
protected void save() {
|
||||
checkArgument(
|
||||
!PremiumListDao.getLatestRevision(name).isPresent(),
|
||||
"A premium list of this name already exists: %s",
|
||||
name);
|
||||
if (!override) {
|
||||
assertTldExists(
|
||||
name,
|
||||
"Premium names must match the name of the TLD they are intended to be used on"
|
||||
+ " (unless --override is specified), yet TLD %s does not exist");
|
||||
}
|
||||
logger.atInfo().log("Saving premium list for TLD %s", name);
|
||||
logInputData();
|
||||
List<String> inputDataPreProcessed =
|
||||
Splitter.on('\n').omitEmptyStrings().splitToList(inputData);
|
||||
PremiumListDao.save(name, currency, inputDataPreProcessed);
|
||||
String message =
|
||||
String.format("Saved premium list %s with %d entries", name, inputDataPreProcessed.size());
|
||||
logger.atInfo().log(message);
|
||||
response.setPayload(ImmutableMap.of("status", "success", "message", message));
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@
|
||||
package google.registry.tools.server;
|
||||
|
||||
import static com.google.common.base.Strings.emptyToNull;
|
||||
import static google.registry.request.RequestParameters.extractBooleanParameter;
|
||||
import static google.registry.request.RequestParameters.extractIntParameter;
|
||||
import static google.registry.request.RequestParameters.extractOptionalParameter;
|
||||
import static google.registry.request.RequestParameters.extractRequiredParameter;
|
||||
@@ -28,7 +27,6 @@ import google.registry.request.Parameter;
|
||||
import google.registry.request.RequestParameters;
|
||||
import java.util.Optional;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.joda.money.CurrencyUnit;
|
||||
|
||||
/**
|
||||
* Dagger module for the tools package.
|
||||
@@ -55,30 +53,6 @@ public class ToolsServerModule {
|
||||
return (s == null) ? Optional.empty() : Optional.of(Boolean.parseBoolean(s));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("inputData")
|
||||
static String provideInput(HttpServletRequest req) {
|
||||
return extractRequiredParameter(req, CreatePremiumListAction.INPUT_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("premiumListName")
|
||||
static String provideName(HttpServletRequest req) {
|
||||
return extractRequiredParameter(req, CreatePremiumListAction.NAME_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("currency")
|
||||
static CurrencyUnit provideCurrency(HttpServletRequest req) {
|
||||
return CurrencyUnit.of(extractRequiredParameter(req, CreatePremiumListAction.CURRENCY));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("override")
|
||||
static boolean provideOverride(HttpServletRequest req) {
|
||||
return extractBooleanParameter(req, CreatePremiumListAction.OVERRIDE_PARAM);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Parameter("printHeaderRow")
|
||||
static Optional<Boolean> providePrintHeaderRow(HttpServletRequest req) {
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright 2017 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.tools.server;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static google.registry.request.Action.Method.POST;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.model.tld.label.PremiumList;
|
||||
import google.registry.model.tld.label.PremiumListDao;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.auth.Auth;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* An action that creates a premium list, for use by the {@code nomulus create_premium_list}
|
||||
* command.
|
||||
*/
|
||||
@Action(
|
||||
service = Action.Service.TOOLS,
|
||||
path = UpdatePremiumListAction.PATH,
|
||||
method = POST,
|
||||
auth = Auth.AUTH_INTERNAL_OR_ADMIN)
|
||||
public class UpdatePremiumListAction extends CreateOrUpdatePremiumListAction {
|
||||
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
public static final String PATH = "/_dr/admin/updatePremiumList";
|
||||
|
||||
@Inject UpdatePremiumListAction() {}
|
||||
|
||||
@Override
|
||||
protected void save() {
|
||||
Optional<PremiumList> existingList = PremiumListDao.getLatestRevision(name);
|
||||
checkArgument(
|
||||
existingList.isPresent(),
|
||||
"Could not update premium list %s because it doesn't exist.",
|
||||
name);
|
||||
|
||||
logger.atInfo().log("Updating premium list for TLD %s", name);
|
||||
logInputData();
|
||||
List<String> inputDataPreProcessed =
|
||||
Splitter.on('\n').omitEmptyStrings().splitToList(inputData);
|
||||
PremiumList newPremiumList =
|
||||
PremiumListDao.save(name, existingList.get().getCurrency(), inputDataPreProcessed);
|
||||
|
||||
String message =
|
||||
String.format(
|
||||
"Updated premium list %s with %d entries.",
|
||||
newPremiumList.getName(), inputDataPreProcessed.size());
|
||||
logger.atInfo().log(message);
|
||||
response.setPayload(ImmutableMap.of("status", "success", "message", message));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user