From 7358ca660e28e98d23a00a2d1cbf039202d2422d Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Mon, 19 Aug 2024 09:37:28 -0400 Subject: [PATCH] Connect to the correct endpoints based on runtime --- .../registry/batch/AsyncTaskEnqueuer.java | 6 +- .../batch/CannedScriptExecutionAction.java | 3 +- .../batch/CheckBulkComplianceAction.java | 4 +- .../registry/batch/CloudTasksUtils.java | 182 +++++++++----- .../batch/DeleteExpiredDomainsAction.java | 3 +- .../batch/DeleteLoadTestDataAction.java | 3 +- .../batch/DeleteProberDataAction.java | 3 +- .../batch/ExpandBillingRecurrencesAction.java | 3 +- .../registry/batch/RelockDomainAction.java | 3 +- .../ResaveAllEppResourcesPipelineAction.java | 3 +- .../registry/batch/ResaveEntityAction.java | 3 +- ...ingCertificateNotificationEmailAction.java | 3 +- .../batch/WipeOutContactHistoryPiiAction.java | 4 +- .../java/google/registry/beam/rde/RdeIO.java | 14 +- .../registry/bsa/BsaDownloadAction.java | 3 +- .../google/registry/bsa/BsaRefreshAction.java | 3 +- .../registry/bsa/BsaValidateAction.java | 3 +- .../UploadBsaUnavailableDomainsAction.java | 4 +- .../google/registry/config/ConfigUtils.java | 8 +- .../registry/config/RegistryConfig.java | 9 + .../google/registry/cron/TldFanoutAction.java | 14 +- .../registry/dns/PublishDnsUpdatesAction.java | 10 +- .../dns/ReadDnsRefreshRequestsAction.java | 10 +- .../google/registry/dns/RefreshDnsAction.java | 3 +- .../dns/RefreshDnsOnHostRenameAction.java | 8 +- .../export/ExportDomainListsAction.java | 3 +- .../export/ExportPremiumTermsAction.java | 3 +- .../export/ExportReservedTermsAction.java | 3 +- .../export/SyncGroupMembersAction.java | 3 +- .../sheet/SyncRegistrarsSheetAction.java | 3 +- .../google/registry/flows/CheckApiAction.java | 3 +- .../google/registry/flows/EppTlsAction.java | 3 +- .../google/registry/flows/EppToolAction.java | 3 +- .../registry/flows/ExtensionManager.java | 6 +- .../registry/flows/host/HostUpdateFlow.java | 8 +- .../registry/loadtest/LoadTestAction.java | 11 +- .../google/registry/model/console/User.java | 8 +- .../registry/module/RegistryComponent.java | 4 +- .../registry/rdap/RdapAutnumAction.java | 3 +- .../registry/rdap/RdapDomainAction.java | 3 +- .../registry/rdap/RdapDomainSearchAction.java | 3 +- .../registry/rdap/RdapEntityAction.java | 3 +- .../registry/rdap/RdapEntitySearchAction.java | 3 +- .../google/registry/rdap/RdapHelpAction.java | 3 +- .../google/registry/rdap/RdapIpAction.java | 3 +- .../registry/rdap/RdapNameserverAction.java | 3 +- .../rdap/RdapNameserverSearchAction.java | 3 +- .../UpdateRegistrarRdapBaseUrlsAction.java | 3 +- .../google/registry/rde/BrdaCopyAction.java | 3 +- .../google/registry/rde/RdeReportAction.java | 3 +- .../google/registry/rde/RdeStagingAction.java | 3 +- .../google/registry/rde/RdeUploadAction.java | 7 +- .../billing/CopyDetailReportsAction.java | 3 +- .../billing/GenerateInvoicesAction.java | 10 +- .../billing/PublishInvoicesAction.java | 10 +- .../icann/IcannReportingStagingAction.java | 11 +- .../icann/IcannReportingUploadAction.java | 3 +- .../spec11/GenerateSpec11ReportAction.java | 10 +- .../spec11/PublishSpec11ReportAction.java | 3 +- .../java/google/registry/request/Action.java | 44 +++- .../registry/request/RequestHandler.java | 11 +- .../registry/tmch/NordnUploadAction.java | 10 +- .../registry/tmch/NordnVerifyAction.java | 3 +- .../google/registry/tmch/TmchCrlAction.java | 3 +- .../google/registry/tmch/TmchDnlAction.java | 3 +- .../google/registry/tmch/TmchSmdrlAction.java | 3 +- .../google/registry/tools/CurlCommand.java | 12 +- .../registry/tools/DomainLockUtils.java | 8 +- .../tools/GenerateEscrowDepositCommand.java | 5 +- .../google/registry/tools/RegistryCli.java | 16 +- .../registry/tools/RegistryToolComponent.java | 5 + .../registry/tools/ServiceConnection.java | 54 ++--- .../tools/server/CreateGroupsAction.java | 3 +- .../tools/server/GenerateZoneFilesAction.java | 3 +- .../tools/server/ListDomainsAction.java | 3 +- .../tools/server/ListHostsAction.java | 3 +- .../tools/server/ListPremiumListsAction.java | 3 +- .../tools/server/ListRegistrarsAction.java | 3 +- .../tools/server/ListReservedListsAction.java | 3 +- .../registry/tools/server/ListTldsAction.java | 3 +- .../server/RefreshDnsForAllDomainsAction.java | 3 +- .../tools/server/UpdateUserGroupAction.java | 3 +- .../tools/server/VerifyOteAction.java | 3 +- .../ui/server/console/ConsoleApiAction.java | 4 +- .../console/ConsoleDomainGetAction.java | 3 +- .../console/ConsoleDomainListAction.java | 3 +- .../console/ConsoleDumDownloadAction.java | 3 +- .../console/ConsoleEppPasswordAction.java | 3 +- .../ui/server/console/ConsoleOteAction.java | 2 +- .../console/ConsoleRegistryLockAction.java | 3 +- .../ConsoleRegistryLockVerifyAction.java | 3 +- .../console/ConsoleUpdateRegistrarAction.java | 3 +- .../server/console/ConsoleUserDataAction.java | 3 +- .../ui/server/console/RegistrarsAction.java | 3 +- .../console/settings/ContactAction.java | 3 +- .../console/settings/SecurityAction.java | 3 +- .../settings/WhoisRegistrarFieldsAction.java | 3 +- .../registrar/ConsoleOteSetupAction.java | 3 +- .../ConsoleRegistrarCreatorAction.java | 4 +- .../ui/server/registrar/ConsoleUiAction.java | 3 +- .../ui/server/registrar/OteStatusAction.java | 3 +- .../registrar/RegistrarSettingsAction.java | 8 +- .../registrar/RegistryLockGetAction.java | 3 +- .../registrar/RegistryLockPostAction.java | 3 +- .../registrar/RegistryLockVerifyAction.java | 3 +- .../google/registry/whois/WhoisAction.java | 3 +- .../registry/whois/WhoisHttpAction.java | 3 +- .../registry/batch/CloudTasksUtilsTest.java | 223 ++++++++---------- .../backend/BackendRequestComponentTest.java | 4 +- .../module/bsa/BsaRequestComponentTest.java | 4 +- .../FrontendRequestComponentTest.java | 4 +- .../pubapi/PubApiRequestComponentTest.java | 4 +- .../tools/ToolsRequestComponentTest.java | 4 +- .../registry/rdap/RdapActionBaseTest.java | 3 +- .../google/registry/rdap/RdapTestHelper.java | 71 +++--- .../registry/request/RequestHandlerTest.java | 20 +- .../google/registry/request/RouterTest.java | 15 +- .../registry/tools/CurlCommandTest.java | 8 +- .../tools/GcpProjectConnectionTest.java | 3 +- .../registry/tools/ServiceConnectionTest.java | 6 +- 120 files changed, 635 insertions(+), 491 deletions(-) diff --git a/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java b/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java index 555fdb8ff9..aa4366d53b 100644 --- a/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java +++ b/core/src/main/java/google/registry/batch/AsyncTaskEnqueuer.java @@ -24,7 +24,7 @@ import com.google.common.flogger.FluentLogger; import google.registry.model.EppResource; import google.registry.persistence.VKey; -import google.registry.request.Action.Service; +import google.registry.request.Action; import javax.inject.Inject; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -78,7 +78,7 @@ public void enqueueAsyncResave( logger.atInfo().log("Enqueuing async re-save of %s to run at %s.", entityKey, whenToResave); cloudTasksUtils.enqueue( QUEUE_ASYNC_ACTIONS, - cloudTasksUtils.createPostTaskWithDelay( - ResaveEntityAction.PATH, Service.BACKEND, params, etaDuration)); + cloudTasksUtils.createTaskWithDelay( + ResaveEntityAction.class, Action.Method.POST, params, etaDuration)); } } diff --git a/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java b/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java index 44e2bdf906..da874f0b83 100644 --- a/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java +++ b/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java @@ -20,6 +20,7 @@ import com.google.common.flogger.FluentLogger; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.UrlConnectionService; @@ -42,7 +43,7 @@ * --service BACKEND -X POST -u '/_dr/task/executeCannedScript}'} */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/executeCannedScript", method = {POST, GET}, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/batch/CheckBulkComplianceAction.java b/core/src/main/java/google/registry/batch/CheckBulkComplianceAction.java index 7b95a6c9af..67faa10bdd 100644 --- a/core/src/main/java/google/registry/batch/CheckBulkComplianceAction.java +++ b/core/src/main/java/google/registry/batch/CheckBulkComplianceAction.java @@ -27,7 +27,7 @@ import google.registry.model.domain.token.BulkPricingPackage; import google.registry.model.registrar.Registrar; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import google.registry.ui.server.SendEmailUtils; import google.registry.util.Clock; @@ -39,7 +39,7 @@ * An action that checks all {@link BulkPricingPackage} objects for compliance with their max create * limit. */ -@Action(service = Service.BACKEND, path = CheckBulkComplianceAction.PATH, auth = Auth.AUTH_ADMIN) +@Action(service = GaeService.BACKEND, path = CheckBulkComplianceAction.PATH, auth = Auth.AUTH_ADMIN) public class CheckBulkComplianceAction implements Runnable { public static final String PATH = "/_dr/task/checkBulkCompliance"; diff --git a/core/src/main/java/google/registry/batch/CloudTasksUtils.java b/core/src/main/java/google/registry/batch/CloudTasksUtils.java index 3ecc662f10..65379a7381 100644 --- a/core/src/main/java/google/registry/batch/CloudTasksUtils.java +++ b/core/src/main/java/google/registry/batch/CloudTasksUtils.java @@ -15,8 +15,8 @@ package google.registry.batch; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.ImmutableList.toImmutableList; -import static google.registry.tools.ServiceConnection.getServer; import static java.util.concurrent.TimeUnit.SECONDS; import com.google.api.gax.rpc.ApiException; @@ -39,11 +39,15 @@ import com.google.protobuf.util.Timestamps; import google.registry.config.CredentialModule.ApplicationDefaultCredential; import google.registry.config.RegistryConfig.Config; +import google.registry.request.Action; +import google.registry.request.Action.Method; import google.registry.request.Action.Service; import google.registry.util.Clock; import google.registry.util.CollectionUtils; import google.registry.util.GoogleCredentialsBundle; +import google.registry.util.RegistryEnvironment; import google.registry.util.Retrier; +import java.io.Serial; import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -58,7 +62,7 @@ /** Utilities for dealing with Cloud Tasks. */ public class CloudTasksUtils implements Serializable { - private static final long serialVersionUID = -7605156291755534069L; + @Serial private static final long serialVersionUID = -7605156291755534069L; private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final Random random = new Random(); @@ -122,7 +126,7 @@ public ImmutableList enqueue(String queue, Task... tasks) { */ private static String processRequestParameters( String path, - HttpMethod method, + Method method, Multimap params, BiConsumer putHeadersFunction, Consumer setBodyFunction) { @@ -140,7 +144,7 @@ private static String processRequestParameters( "%s=%s", escaper.escape(entry.getKey()), escaper.escape(entry.getValue()))) .collect(toImmutableList())); - if (method.equals(HttpMethod.GET)) { + if (method.equals(Method.GET)) { return String.format("%s?%s", path, encodedParams); } putHeadersFunction.accept(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString()); @@ -155,9 +159,12 @@ private static String processRequestParameters( * default service account as the principal. That account must have permission to submit tasks to * Cloud Tasks. * + *

The caller of this method is responsible for passing in the appropriate service based on the + * runtime (GAE/GKE). Use the overload that takes an action class if possible. + * * @param path the relative URI (staring with a slash and ending without one). - * @param method the HTTP method to be used for the request, only GET and POST are supported. - * @param service the App Engine service to route the request to. + * @param method the HTTP method to be used for the request. + * @param service the GAE/GKE service to route the request to. * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up * to the server to process the duplicate keys. * @return the enqueued task. @@ -165,16 +172,13 @@ private static String processRequestParameters( * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig * the worker service */ - private Task createTask( - String path, HttpMethod method, Service service, Multimap params) { + protected Task createTask( + String path, Method method, Service service, Multimap params) { checkArgument( path != null && !path.isEmpty() && path.charAt(0) == '/', "The path must start with a '/'."); - checkArgument( - method.equals(HttpMethod.GET) || method.equals(HttpMethod.POST), - "HTTP method %s is used. Only GET and POST are allowed.", - method); - HttpRequest.Builder requestBuilder = HttpRequest.newBuilder().setHttpMethod(method); + HttpRequest.Builder requestBuilder = + HttpRequest.newBuilder().setHttpMethod(HttpMethod.valueOf(method.name())); path = processRequestParameters( path, method, params, requestBuilder::putHeaders, requestBuilder::setBody); @@ -183,17 +187,52 @@ private Task createTask( .setServiceAccountEmail(credential.serviceAccount()) .setAudience(oauthClientId); requestBuilder.setOidcToken(oidcTokenBuilder.build()); - String totalPath = String.format("%s%s", getServer(service), path); + String totalPath = String.format("%s%s", service.getServiceUrl(), path); requestBuilder.setUrl(totalPath); return Task.newBuilder().setHttpRequest(requestBuilder.build()).build(); } + /** + * Create a {@link Task} to be enqueued. + * + *

This uses the standard Cloud Tasks auth format to create and send an OIDC ID token with the + * default service account as the principal. That account must have permission to submit tasks to + * Cloud Tasks. + * + *

Prefer this overload over the one where the path and service are explicit defined, as this + * class will automatically determine the service to use based on the action and the runtime. + * + * @param actionClazz the action class to run, must be annotated with {@link Action}. + * @param method the HTTP method to be used for the request. + * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up + * to the server to process the duplicate keys. + * @return the enqueued task. + * @see Specifyinig + * the worker service + */ + public Task createTask( + Class actionClazz, Method method, Multimap params) { + Action action = actionClazz.getAnnotation(Action.class); + checkArgument( + action != null, + "Action class %s is not annotated with @Action", + actionClazz.getSimpleName()); + String path = action.path(); + Service service = + RegistryEnvironment.isOnJetty() ? Action.ServiceGetter.get(action) : action.service(); + return createTask(path, method, service, params); + } + /** * Create a {@link Task} to be enqueued with a random delay up to {@code jitterSeconds}. * + *

The caller of this method is responsible for passing in the appropriate service based on the + * runtime (GAE/GKE). Use the overload that takes an action class if possible. + * * @param path the relative URI (staring with a slash and ending without one). - * @param method the HTTP method to be used for the request, only GET and POST are supported. - * @param service the App Engine service to route the request to. + * @param method the HTTP method to be used for the request. + * @param service the GAE/GKE service to route the request to. * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up * to the server to process the duplicate keys. * @param jitterSeconds the number of seconds that a task is randomly delayed up to. @@ -202,9 +241,9 @@ private Task createTask( * href=ttps://cloud.google.com/appengine/docs/standard/java/taskqueue/push/creating-tasks#target>Specifyinig * the worker service */ - private Task createTaskWithJitter( + public Task createTaskWithJitter( String path, - HttpMethod method, + Method method, Service service, Multimap params, Optional jitterSeconds) { @@ -219,12 +258,44 @@ private Task createTaskWithJitter( Duration.millis(random.nextInt((int) SECONDS.toMillis(jitterSeconds.get())))); } + /** + * Create a {@link Task} to be enqueued with a random delay up to {@code jitterSeconds}. + * + *

Prefer this overload over the one where the path and service are explicit defined, as this + * class will automatically determine the service to use based on the action and the runtime. + * + * @param actionClazz the action class to run, must be annotated with {@link Action}. + * @param method the HTTP method to be used for the request. + * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up + * to the server to process the duplicate keys. + * @param jitterSeconds the number of seconds that a task is randomly delayed up to. + * @return the enqueued task. + * @see Specifyinig + * the worker service + */ + public Task createTaskWithJitter( + Class actionClazz, + Method method, + Multimap params, + Optional jitterSeconds) { + Action action = getAction(actionClazz); + checkState( + action != null, + "Action class %s is not annotated with @Action", + actionClazz.getSimpleName()); + String path = action.path(); + Service service = + RegistryEnvironment.isOnJetty() ? Action.ServiceGetter.get(action) : action.service(); + return createTaskWithJitter(path, method, service, params, jitterSeconds); + } + /** * Create a {@link Task} to be enqueued with delay of {@code duration}. * * @param path the relative URI (staring with a slash and ending without one). - * @param method the HTTP method to be used for the request, only GET and POST are supported. - * @param service the App Engine service to route the request to. + * @param method the HTTP method to be used for the request. + * @param service the GAE/GKE service to route the request to. * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up * to the server to process the duplicate keys. * @param delay the amount of time that a task needs to delayed for. @@ -235,7 +306,7 @@ private Task createTaskWithJitter( */ private Task createTaskWithDelay( String path, - HttpMethod method, + Method method, Service service, Multimap params, Duration delay) { @@ -248,58 +319,53 @@ private Task createTaskWithDelay( .build(); } - public Task createPostTask(String path, Service service, Multimap params) { - return createTask(path, HttpMethod.POST, service, params); - } - - public Task createGetTask(String path, Service service, Multimap params) { - return createTask(path, HttpMethod.GET, service, params); - } - - /** - * Create a {@link Task} via HTTP.POST that will be randomly delayed up to {@code jitterSeconds}. - */ - public Task createPostTaskWithJitter( - String path, - Service service, - Multimap params, - Optional jitterSeconds) { - return createTaskWithJitter(path, HttpMethod.POST, service, params, jitterSeconds); - } - /** - * Create a {@link Task} via HTTP.GET that will be randomly delayed up to {@code jitterSeconds}. + * Create a {@link Task} to be enqueued with delay of {@code duration}. + * + *

Prefer this overload over the one where the path and service are explicit defined, as this + * class will automatically determine the service to use based on the action and the runtime. + * + * @param actionClazz the action class to run, must be annotated with {@link Action}. + * @param method the HTTP method to be used for the request. + * @param params a multimap of URL query parameters. Duplicate keys are saved as is, and it is up + * to the server to process the duplicate keys. + * @param delay the amount of time that a task needs to delayed for. + * @return the enqueued task. + * @see Specifyinig + * the worker service */ - public Task createGetTaskWithJitter( - String path, - Service service, + public Task createTaskWithDelay( + Class actionClazz, + Method method, Multimap params, - Optional jitterSeconds) { - return createTaskWithJitter(path, HttpMethod.GET, service, params, jitterSeconds); - } - - /** Create a {@link Task} via HTTP.POST that will be delayed for {@code delay}. */ - public Task createPostTaskWithDelay( - String path, Service service, Multimap params, Duration delay) { - return createTaskWithDelay(path, HttpMethod.POST, service, params, delay); + Duration delay) { + Action action = getAction(actionClazz); + String path = action.path(); + Service service = + RegistryEnvironment.isOnJetty() ? Action.ServiceGetter.get(action) : action.service(); + return createTaskWithDelay(path, method, service, params, delay); } - /** Create a {@link Task} via HTTP.GET that will be delayed for {@code delay}. */ - public Task createGetTaskWithDelay( - String path, Service service, Multimap params, Duration delay) { - return createTaskWithDelay(path, HttpMethod.GET, service, params, delay); + private static Action getAction(Class actionClazz) { + Action action = actionClazz.getAnnotation(Action.class); + checkState( + action != null, + "Action class %s is not annotated with @Action", + actionClazz.getSimpleName()); + return action; } public abstract static class SerializableCloudTasksClient implements Serializable { - private static final long serialVersionUID = 7872861868968535498L; + @Serial private static final long serialVersionUID = 7872861868968535498L; public abstract Task enqueue(String projectId, String locationId, String queueName, Task task); } public static class GcpCloudTasksClient extends SerializableCloudTasksClient { - private static final long serialVersionUID = -5959253033129154037L; + @Serial private static final long serialVersionUID = -5959253033129154037L; // Use a supplier so that we can use try-with-resources with the client, which implements // Autocloseable. diff --git a/core/src/main/java/google/registry/batch/DeleteExpiredDomainsAction.java b/core/src/main/java/google/registry/batch/DeleteExpiredDomainsAction.java index 8bb14055a2..28185be9ef 100644 --- a/core/src/main/java/google/registry/batch/DeleteExpiredDomainsAction.java +++ b/core/src/main/java/google/registry/batch/DeleteExpiredDomainsAction.java @@ -37,6 +37,7 @@ import google.registry.model.eppoutput.EppOutput; import google.registry.persistence.transaction.QueryComposer.Comparator; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.request.lock.LockHandler; @@ -67,7 +68,7 @@ * this action runs, thus alerting us that human action is needed to correctly process the delete. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = DeleteExpiredDomainsAction.PATH, auth = Auth.AUTH_ADMIN) public class DeleteExpiredDomainsAction implements Runnable { diff --git a/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java b/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java index 2de32b9458..da2debe013 100644 --- a/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java +++ b/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java @@ -37,6 +37,7 @@ import google.registry.model.reporting.HistoryEntryDao; import google.registry.persistence.VKey; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.util.Clock; @@ -54,7 +55,7 @@ * production. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/deleteLoadTestData", method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/batch/DeleteProberDataAction.java b/core/src/main/java/google/registry/batch/DeleteProberDataAction.java index 4dd9cd2ee4..4e0bdacb85 100644 --- a/core/src/main/java/google/registry/batch/DeleteProberDataAction.java +++ b/core/src/main/java/google/registry/batch/DeleteProberDataAction.java @@ -42,6 +42,7 @@ import google.registry.model.domain.DomainHistory; import google.registry.model.tld.Tld.TldType; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.util.RegistryEnvironment; @@ -58,7 +59,7 @@ * billing events, along with their ForeignKeyDomainIndex entities. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/deleteProberData", method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/batch/ExpandBillingRecurrencesAction.java b/core/src/main/java/google/registry/batch/ExpandBillingRecurrencesAction.java index ce4ff474d0..204608824e 100644 --- a/core/src/main/java/google/registry/batch/ExpandBillingRecurrencesAction.java +++ b/core/src/main/java/google/registry/batch/ExpandBillingRecurrencesAction.java @@ -35,6 +35,7 @@ import google.registry.model.billing.BillingRecurrence; import google.registry.model.common.Cursor; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -50,7 +51,7 @@ * BillingRecurrence} billing events into synthetic {@link BillingEvent} events. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/expandBillingRecurrences", auth = Auth.AUTH_ADMIN) public class ExpandBillingRecurrencesAction implements Runnable { diff --git a/core/src/main/java/google/registry/batch/RelockDomainAction.java b/core/src/main/java/google/registry/batch/RelockDomainAction.java index c0b38ddf5e..c8c2cb197d 100644 --- a/core/src/main/java/google/registry/batch/RelockDomainAction.java +++ b/core/src/main/java/google/registry/batch/RelockDomainAction.java @@ -35,6 +35,7 @@ import google.registry.model.tld.RegistryLockDao; import google.registry.persistence.VKey; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -49,7 +50,7 @@ /** Task that re-locks a previously-Registry-Locked domain after a predetermined period of time. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = RelockDomainAction.PATH, method = POST, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/batch/ResaveAllEppResourcesPipelineAction.java b/core/src/main/java/google/registry/batch/ResaveAllEppResourcesPipelineAction.java index 76e94fd7ab..17c10e9d2c 100644 --- a/core/src/main/java/google/registry/batch/ResaveAllEppResourcesPipelineAction.java +++ b/core/src/main/java/google/registry/batch/ResaveAllEppResourcesPipelineAction.java @@ -28,6 +28,7 @@ import com.google.common.net.MediaType; import google.registry.config.RegistryConfig.Config; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -53,7 +54,7 @@ *

This runs the {@link google.registry.beam.resave.ResaveAllEppResourcesPipeline}. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = ResaveAllEppResourcesPipelineAction.PATH, auth = Auth.AUTH_ADMIN) public class ResaveAllEppResourcesPipelineAction implements Runnable { diff --git a/core/src/main/java/google/registry/batch/ResaveEntityAction.java b/core/src/main/java/google/registry/batch/ResaveEntityAction.java index 507004e992..f5b98d3c11 100644 --- a/core/src/main/java/google/registry/batch/ResaveEntityAction.java +++ b/core/src/main/java/google/registry/batch/ResaveEntityAction.java @@ -25,6 +25,7 @@ import google.registry.model.EppResource; import google.registry.persistence.VKey; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; import google.registry.request.Parameter; import google.registry.request.Response; @@ -39,7 +40,7 @@ *

{@link EppResource}s will be projected forward to the current time. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = ResaveEntityAction.PATH, auth = Auth.AUTH_ADMIN, method = Method.POST) diff --git a/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java b/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java index afb840b530..e0277c178a 100644 --- a/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java +++ b/core/src/main/java/google/registry/batch/SendExpiringCertificateNotificationEmailAction.java @@ -35,6 +35,7 @@ import google.registry.model.registrar.RegistrarPoc; import google.registry.model.registrar.RegistrarPocBase.Type; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.EmailMessage; @@ -49,7 +50,7 @@ /** An action that sends notification emails to registrars whose certificates are expiring soon. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = SendExpiringCertificateNotificationEmailAction.PATH, auth = Auth.AUTH_ADMIN) public class SendExpiringCertificateNotificationEmailAction implements Runnable { diff --git a/core/src/main/java/google/registry/batch/WipeOutContactHistoryPiiAction.java b/core/src/main/java/google/registry/batch/WipeOutContactHistoryPiiAction.java index 564e8f914c..dd6d630298 100644 --- a/core/src/main/java/google/registry/batch/WipeOutContactHistoryPiiAction.java +++ b/core/src/main/java/google/registry/batch/WipeOutContactHistoryPiiAction.java @@ -30,7 +30,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.model.contact.ContactHistory; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -49,7 +49,7 @@ * time. */ @Action( - service = Service.BACKEND, + service = GaeService.BACKEND, path = WipeOutContactHistoryPiiAction.PATH, auth = Auth.AUTH_ADMIN) public class WipeOutContactHistoryPiiAction implements Runnable { diff --git a/core/src/main/java/google/registry/beam/rde/RdeIO.java b/core/src/main/java/google/registry/beam/rde/RdeIO.java index d97340d267..1263d0b4ae 100644 --- a/core/src/main/java/google/registry/beam/rde/RdeIO.java +++ b/core/src/main/java/google/registry/beam/rde/RdeIO.java @@ -44,7 +44,7 @@ import google.registry.rde.RdeResourceType; import google.registry.rde.RdeUploadAction; import google.registry.rde.RdeUtils; -import google.registry.request.Action.Service; +import google.registry.request.Action; import google.registry.request.RequestParameters; import google.registry.tldconfig.idn.IdnTableEnum; import google.registry.xjc.rdeheader.XjcRdeHeader; @@ -302,9 +302,9 @@ public void processElement( if (key.mode() == RdeMode.FULL) { cloudTasksUtils.enqueue( RDE_UPLOAD_QUEUE, - cloudTasksUtils.createPostTaskWithDelay( - RdeUploadAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTaskWithDelay( + RdeUploadAction.class, + Action.Method.POST, ImmutableMultimap.of( RequestParameters.PARAM_TLD, key.tld(), @@ -314,9 +314,9 @@ public void processElement( } else { cloudTasksUtils.enqueue( BRDA_QUEUE, - cloudTasksUtils.createPostTaskWithDelay( - BrdaCopyAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTaskWithDelay( + BrdaCopyAction.class, + Action.Method.POST, ImmutableMultimap.of( RequestParameters.PARAM_TLD, key.tld(), diff --git a/core/src/main/java/google/registry/bsa/BsaDownloadAction.java b/core/src/main/java/google/registry/bsa/BsaDownloadAction.java index f2dba14581..9090a93b60 100644 --- a/core/src/main/java/google/registry/bsa/BsaDownloadAction.java +++ b/core/src/main/java/google/registry/bsa/BsaDownloadAction.java @@ -41,6 +41,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.model.tld.Tlds; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.Clock; @@ -50,7 +51,7 @@ import javax.inject.Inject; @Action( - service = Action.Service.BSA, + service = GaeService.BSA, path = BsaDownloadAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/bsa/BsaRefreshAction.java b/core/src/main/java/google/registry/bsa/BsaRefreshAction.java index 6bc20e519f..de23e0a296 100644 --- a/core/src/main/java/google/registry/bsa/BsaRefreshAction.java +++ b/core/src/main/java/google/registry/bsa/BsaRefreshAction.java @@ -31,6 +31,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.model.tld.Tlds; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.BatchedStreams; @@ -41,7 +42,7 @@ import org.joda.time.Duration; @Action( - service = Action.Service.BSA, + service = GaeService.BSA, path = BsaRefreshAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/bsa/BsaValidateAction.java b/core/src/main/java/google/registry/bsa/BsaValidateAction.java index bb0685d627..beb7d60745 100644 --- a/core/src/main/java/google/registry/bsa/BsaValidateAction.java +++ b/core/src/main/java/google/registry/bsa/BsaValidateAction.java @@ -55,6 +55,7 @@ import google.registry.model.tld.Tld.TldType; import google.registry.persistence.VKey; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.Clock; @@ -67,7 +68,7 @@ /** Validates the BSA data in the database against the most recent block lists. */ @Action( - service = Action.Service.BSA, + service = GaeService.BSA, path = BsaValidateAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/bsa/UploadBsaUnavailableDomainsAction.java b/core/src/main/java/google/registry/bsa/UploadBsaUnavailableDomainsAction.java index 2fedf03770..71d7248268 100644 --- a/core/src/main/java/google/registry/bsa/UploadBsaUnavailableDomainsAction.java +++ b/core/src/main/java/google/registry/bsa/UploadBsaUnavailableDomainsAction.java @@ -42,7 +42,7 @@ import google.registry.model.tld.Tld.TldType; import google.registry.model.tld.label.ReservedList; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import google.registry.util.Clock; import jakarta.persistence.TypedQuery; @@ -72,7 +72,7 @@ *

The file is also uploaded to GCS to preserve it as a record for ourselves. */ @Action( - service = Service.BSA, + service = GaeService.BSA, path = "/_dr/task/uploadBsaUnavailableNames", method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/config/ConfigUtils.java b/core/src/main/java/google/registry/config/ConfigUtils.java index 1e4cb5252b..9e30851106 100644 --- a/core/src/main/java/google/registry/config/ConfigUtils.java +++ b/core/src/main/java/google/registry/config/ConfigUtils.java @@ -15,6 +15,8 @@ package google.registry.config; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; /** Helper methods for configuration classes. */ @@ -23,12 +25,12 @@ public final class ConfigUtils { /** * Creates a URL instance. * - * @throws RuntimeException to rethrow {@link MalformedURLException} + * @throws RuntimeException to rethrow {@link URISyntaxException} or {@link MalformedURLException} */ public static URL makeUrl(String url) { try { - return new URL(url); - } catch (MalformedURLException e) { + return new URI(url).toURL(); + } catch (URISyntaxException | MalformedURLException e) { throw new RuntimeException(e); } } diff --git a/core/src/main/java/google/registry/config/RegistryConfig.java b/core/src/main/java/google/registry/config/RegistryConfig.java index d26d6f32d2..6b12f80e44 100644 --- a/core/src/main/java/google/registry/config/RegistryConfig.java +++ b/core/src/main/java/google/registry/config/RegistryConfig.java @@ -37,6 +37,7 @@ import google.registry.dns.ReadDnsRefreshRequestsAction; import google.registry.model.common.DnsRefreshRequest; import google.registry.persistence.transaction.JpaTransactionManager; +import google.registry.request.Action.GkeService; import google.registry.util.RegistryEnvironment; import google.registry.util.YamlUtils; import jakarta.mail.internet.AddressException; @@ -1593,6 +1594,14 @@ public static boolean areServersLocal() { return CONFIG_SETTINGS.get().gcpProject.isLocal; } + public static String getBaseDomain() { + return CONFIG_SETTINGS.get().gcpProject.baseDomain; + } + + public static URL getServiceUrl(GkeService service) { + return makeUrl(String.format("https://%s.%s", service.getServiceId(), getBaseDomain())); + } + /** * Returns the address of the Nomulus app default HTTP server. * diff --git a/core/src/main/java/google/registry/cron/TldFanoutAction.java b/core/src/main/java/google/registry/cron/TldFanoutAction.java index 3c82f3b560..6e77fab9c7 100644 --- a/core/src/main/java/google/registry/cron/TldFanoutAction.java +++ b/core/src/main/java/google/registry/cron/TldFanoutAction.java @@ -40,12 +40,14 @@ import com.google.common.flogger.FluentLogger; import google.registry.batch.CloudTasksUtils; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; +import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.ParameterMap; import google.registry.request.RequestParameters; import google.registry.request.Response; import google.registry.request.auth.Auth; +import google.registry.util.RegistryEnvironment; import java.util.Optional; import java.util.stream.Stream; import javax.inject.Inject; @@ -78,7 +80,7 @@ * */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/cron/fanout", automaticallyPrintOk = true, auth = Auth.AUTH_ADMIN) @@ -157,7 +159,11 @@ private Task createTask(String tld, Multimap params) { params = ArrayListMultimap.create(params); params.put(RequestParameters.PARAM_TLD, tld); } - return cloudTasksUtils.createPostTaskWithJitter( - endpoint, Service.BACKEND, params, jitterSeconds); + return cloudTasksUtils.createTaskWithJitter( + endpoint, + Action.Method.POST, + RegistryEnvironment.isOnJetty() ? GkeService.BACKEND : GaeService.BACKEND, + params, + jitterSeconds); } } diff --git a/core/src/main/java/google/registry/dns/PublishDnsUpdatesAction.java b/core/src/main/java/google/registry/dns/PublishDnsUpdatesAction.java index 9f0ff8185d..ea626028cd 100644 --- a/core/src/main/java/google/registry/dns/PublishDnsUpdatesAction.java +++ b/core/src/main/java/google/registry/dns/PublishDnsUpdatesAction.java @@ -53,7 +53,7 @@ import google.registry.model.registrar.RegistrarPocBase; import google.registry.model.tld.Tld; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Header; import google.registry.request.HttpException.ServiceUnavailableException; import google.registry.request.Parameter; @@ -73,7 +73,7 @@ /** Task that sends domain and host updates to the DNS server. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = PublishDnsUpdatesAction.PATH, method = POST, automaticallyPrintOk = true, @@ -328,9 +328,9 @@ private void splitBatch() { private void enqueue(ImmutableList domains, ImmutableList hosts) { cloudTasksUtils.enqueue( DNS_PUBLISH_PUSH_QUEUE_NAME, - cloudTasksUtils.createPostTask( - PATH, - Service.BACKEND, + cloudTasksUtils.createTask( + this.getClass(), + POST, ImmutableMultimap.builder() .put(PARAM_TLD, tld) .put(PARAM_DNS_WRITER, dnsWriter) diff --git a/core/src/main/java/google/registry/dns/ReadDnsRefreshRequestsAction.java b/core/src/main/java/google/registry/dns/ReadDnsRefreshRequestsAction.java index cdaa8a0aa8..c78a20ef6a 100644 --- a/core/src/main/java/google/registry/dns/ReadDnsRefreshRequestsAction.java +++ b/core/src/main/java/google/registry/dns/ReadDnsRefreshRequestsAction.java @@ -45,7 +45,7 @@ import google.registry.model.common.DnsRefreshRequest; import google.registry.model.tld.Tld; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.util.Clock; @@ -60,7 +60,7 @@ * table. */ @Action( - service = Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/readDnsRefreshRequests", automaticallyPrintOk = true, method = POST, @@ -182,9 +182,9 @@ void enqueueUpdates(int lockIndex, int numPublishLocks, Collection hosts = hostsBuilder.build(); for (String dnsWriter : Tld.get(tld).getDnsWriters()) { Task task = - cloudTasksUtils.createPostTaskWithJitter( - PublishDnsUpdatesAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTaskWithJitter( + PublishDnsUpdatesAction.class, + POST, ImmutableMultimap.builder() .put(PARAM_TLD, tld) .put(PARAM_DNS_WRITER, dnsWriter) diff --git a/core/src/main/java/google/registry/dns/RefreshDnsAction.java b/core/src/main/java/google/registry/dns/RefreshDnsAction.java index 3f55ba0f1f..0a92a277ca 100644 --- a/core/src/main/java/google/registry/dns/RefreshDnsAction.java +++ b/core/src/main/java/google/registry/dns/RefreshDnsAction.java @@ -26,6 +26,7 @@ import google.registry.model.domain.Domain; import google.registry.model.host.Host; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotFoundException; import google.registry.request.Parameter; @@ -35,7 +36,7 @@ /** Action that manually triggers refresh of DNS information. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/dnsRefresh", automaticallyPrintOk = true, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/dns/RefreshDnsOnHostRenameAction.java b/core/src/main/java/google/registry/dns/RefreshDnsOnHostRenameAction.java index 72c020fc11..2384f3dce1 100644 --- a/core/src/main/java/google/registry/dns/RefreshDnsOnHostRenameAction.java +++ b/core/src/main/java/google/registry/dns/RefreshDnsOnHostRenameAction.java @@ -26,14 +26,18 @@ import google.registry.model.host.Host; import google.registry.persistence.VKey; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; import javax.inject.Inject; import org.joda.time.DateTime; -@Action(service = Service.BACKEND, path = PATH, method = Action.Method.POST, auth = Auth.AUTH_ADMIN) +@Action( + service = GaeService.BACKEND, + path = PATH, + method = Action.Method.POST, + auth = Auth.AUTH_ADMIN) public class RefreshDnsOnHostRenameAction implements Runnable { public static final String QUEUE_HOST_RENAME = "async-host-rename"; diff --git a/core/src/main/java/google/registry/export/ExportDomainListsAction.java b/core/src/main/java/google/registry/export/ExportDomainListsAction.java index f5a4ec956b..2911f14823 100644 --- a/core/src/main/java/google/registry/export/ExportDomainListsAction.java +++ b/core/src/main/java/google/registry/export/ExportDomainListsAction.java @@ -31,6 +31,7 @@ import google.registry.model.tld.Tld; import google.registry.model.tld.Tld.TldType; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import google.registry.storage.drive.DriveConnection; import google.registry.util.Clock; @@ -47,7 +48,7 @@ * name TLD.txt into the domain-lists bucket. Note that this overwrites the files in place. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/exportDomainLists", method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java b/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java index a3f61b5d2f..8c8af6eb9a 100644 --- a/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java +++ b/core/src/main/java/google/registry/export/ExportPremiumTermsAction.java @@ -33,6 +33,7 @@ import google.registry.model.tld.label.PremiumList.PremiumEntry; import google.registry.model.tld.label.PremiumListDao; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.RequestParameters; import google.registry.request.Response; @@ -45,7 +46,7 @@ /** Action that exports the premium terms list for a TLD to Google Drive. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/exportPremiumTerms", method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/export/ExportReservedTermsAction.java b/core/src/main/java/google/registry/export/ExportReservedTermsAction.java index 2ac192c546..8046f280ad 100644 --- a/core/src/main/java/google/registry/export/ExportReservedTermsAction.java +++ b/core/src/main/java/google/registry/export/ExportReservedTermsAction.java @@ -25,6 +25,7 @@ import com.google.common.net.MediaType; import google.registry.model.tld.Tld; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.RequestParameters; import google.registry.request.Response; @@ -34,7 +35,7 @@ /** Action that exports the publicly viewable reserved terms list for a TLD to Google Drive. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/exportReservedTerms", method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/export/SyncGroupMembersAction.java b/core/src/main/java/google/registry/export/SyncGroupMembersAction.java index 8f1cebf722..296a4391fd 100644 --- a/core/src/main/java/google/registry/export/SyncGroupMembersAction.java +++ b/core/src/main/java/google/registry/export/SyncGroupMembersAction.java @@ -35,6 +35,7 @@ import google.registry.model.registrar.RegistrarPoc; import google.registry.model.registrar.RegistrarPocBase; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.Retrier; @@ -53,7 +54,7 @@ *

This uses the Directory API. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/syncGroupMembers", method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java b/core/src/main/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java index d19d434812..b2f476ed2e 100644 --- a/core/src/main/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java +++ b/core/src/main/java/google/registry/export/sheet/SyncRegistrarsSheetAction.java @@ -24,6 +24,7 @@ import com.google.common.flogger.FluentLogger; import google.registry.config.RegistryConfig.Config; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -54,7 +55,7 @@ * @see SyncRegistrarsSheet */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = SyncRegistrarsSheetAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/flows/CheckApiAction.java b/core/src/main/java/google/registry/flows/CheckApiAction.java index 55e4ae21dc..f5d3f13c73 100644 --- a/core/src/main/java/google/registry/flows/CheckApiAction.java +++ b/core/src/main/java/google/registry/flows/CheckApiAction.java @@ -55,6 +55,7 @@ import google.registry.monitoring.whitebox.CheckApiMetric; import google.registry.monitoring.whitebox.CheckApiMetric.Availability; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.RequestParameters; import google.registry.request.Response; @@ -72,7 +73,7 @@ * user controlled, lest it open an XSS vector. Do not modify this to return the domain name in the * response. */ -@Action(service = Action.Service.PUBAPI, path = "/check", auth = Auth.AUTH_PUBLIC) +@Action(service = GaeService.PUBAPI, path = "/check", auth = Auth.AUTH_PUBLIC) public class CheckApiAction implements Runnable { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); diff --git a/core/src/main/java/google/registry/flows/EppTlsAction.java b/core/src/main/java/google/registry/flows/EppTlsAction.java index 908bbd1a8b..4ef0590ba2 100644 --- a/core/src/main/java/google/registry/flows/EppTlsAction.java +++ b/core/src/main/java/google/registry/flows/EppTlsAction.java @@ -15,6 +15,7 @@ package google.registry.flows; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; import google.registry.request.Payload; import google.registry.request.auth.Auth; @@ -26,7 +27,7 @@ * to RFC 5730. Commands must be requested via POST. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = "/_dr/epp", method = Method.POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/flows/EppToolAction.java b/core/src/main/java/google/registry/flows/EppToolAction.java index 0e1312cef6..047d3ca6a9 100644 --- a/core/src/main/java/google/registry/flows/EppToolAction.java +++ b/core/src/main/java/google/registry/flows/EppToolAction.java @@ -22,6 +22,7 @@ import dagger.Provides; import google.registry.model.eppcommon.ProtocolDefinition; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -30,7 +31,7 @@ /** Runs EPP commands directly without logging in, verifying an XSRF token from the tool. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = EppToolAction.PATH, method = Method.POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/flows/ExtensionManager.java b/core/src/main/java/google/registry/flows/ExtensionManager.java index 255da4483a..fc18dad444 100644 --- a/core/src/main/java/google/registry/flows/ExtensionManager.java +++ b/core/src/main/java/google/registry/flows/ExtensionManager.java @@ -164,8 +164,10 @@ private static void checkForUnimplementedExtensions( /** Service extension(s) must be declared at login. */ public static class UndeclaredServiceExtensionException extends CommandUseErrorException { public UndeclaredServiceExtensionException(Set undeclaredUris) { - super(String.format("Service extension(s) must be declared at login: %s", - Joiner.on(", ").join(undeclaredUris))); + super( + String.format( + "Service extension(s) must be declared at login: %s", + Joiner.on(", ").join(undeclaredUris))); } } diff --git a/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java b/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java index 647f44d356..df5205d0b2 100644 --- a/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostUpdateFlow.java @@ -65,7 +65,7 @@ import google.registry.model.host.HostHistory; import google.registry.model.reporting.IcannReportingTypes.ActivityReportField; import google.registry.persistence.VKey; -import google.registry.request.Action.Service; +import google.registry.request.Action; import java.util.Objects; import java.util.Optional; import javax.inject.Inject; @@ -277,9 +277,9 @@ private void enqueueTasks(Host existingHost, Host newHost) { // We must also enqueue updates for all domains that use this host as their nameserver so // that their NS records can be updated to point at the new name. Task task = - cloudTasksUtils.createPostTask( - RefreshDnsOnHostRenameAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTask( + RefreshDnsOnHostRenameAction.class, + Action.Method.POST, ImmutableMultimap.of(PARAM_HOST_KEY, existingHost.createVKey().stringify())); cloudTasksUtils.enqueue(QUEUE_HOST_RENAME, task); } diff --git a/core/src/main/java/google/registry/loadtest/LoadTestAction.java b/core/src/main/java/google/registry/loadtest/LoadTestAction.java index d37830bc10..4076c0b12c 100644 --- a/core/src/main/java/google/registry/loadtest/LoadTestAction.java +++ b/core/src/main/java/google/registry/loadtest/LoadTestAction.java @@ -29,8 +29,9 @@ import com.google.common.flogger.FluentLogger; import com.google.protobuf.Timestamp; import google.registry.batch.CloudTasksUtils; +import google.registry.flows.EppToolAction; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.security.XsrfTokenManager; @@ -54,7 +55,7 @@ * least one must be specified in order for load testing to do anything. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = LoadTestAction.PATH, method = Action.Method.POST, automaticallyPrintOk = true, @@ -335,9 +336,9 @@ private List createTasks(List xmls, DateTime start) { Task.newBuilder() .setAppEngineHttpRequest( cloudTasksUtils - .createPostTask( - "/_dr/epptool", - Service.TOOLS, + .createTask( + EppToolAction.class, + Action.Method.POST, ImmutableMultimap.of( "clientId", registrarId, diff --git a/core/src/main/java/google/registry/model/console/User.java b/core/src/main/java/google/registry/model/console/User.java index c1c0fb4d48..cd7390a6a5 100644 --- a/core/src/main/java/google/registry/model/console/User.java +++ b/core/src/main/java/google/registry/model/console/User.java @@ -24,7 +24,7 @@ import com.google.common.net.MediaType; import google.registry.batch.CloudTasksUtils; import google.registry.persistence.VKey; -import google.registry.request.Action.Service; +import google.registry.request.Action; import google.registry.tools.IamClient; import google.registry.tools.ServiceConnection; import google.registry.tools.server.UpdateUserGroupAction; @@ -126,9 +126,9 @@ private static void modifyGroupMembershipAsync( CloudTasksUtils cloudTasksUtils, Mode mode) { Task task = - cloudTasksUtils.createPostTask( - UpdateUserGroupAction.PATH, - Service.TOOLS, + cloudTasksUtils.createTask( + UpdateUserGroupAction.class, + Action.Method.POST, ImmutableMultimap.of( "userEmailAddress", userEmailAddress, diff --git a/core/src/main/java/google/registry/module/RegistryComponent.java b/core/src/main/java/google/registry/module/RegistryComponent.java index ff515b89f1..f131ba8786 100644 --- a/core/src/main/java/google/registry/module/RegistryComponent.java +++ b/core/src/main/java/google/registry/module/RegistryComponent.java @@ -102,11 +102,9 @@ interface RegistryComponent { class RegistryModule { @Provides static RequestHandler provideRequestHandler( - @Config("baseDomain") String baseDomain, Provider componentProvider, RequestAuthenticator requestAuthenticator) { - return RequestHandler.create( - RequestComponent.class, baseDomain, componentProvider, requestAuthenticator); + return RequestHandler.create(RequestComponent.class, componentProvider, requestAuthenticator); } } } diff --git a/core/src/main/java/google/registry/rdap/RdapAutnumAction.java b/core/src/main/java/google/registry/rdap/RdapAutnumAction.java index 2293811a82..d32e0cb20f 100644 --- a/core/src/main/java/google/registry/rdap/RdapAutnumAction.java +++ b/core/src/main/java/google/registry/rdap/RdapAutnumAction.java @@ -20,6 +20,7 @@ import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapObjectClasses.ReplyPayloadBase; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NotImplementedException; import google.registry.request.auth.Auth; import javax.inject.Inject; @@ -31,7 +32,7 @@ * ARIN, not domain registries. */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/autnum/", method = {GET, HEAD}, isPrefix = true, diff --git a/core/src/main/java/google/registry/rdap/RdapDomainAction.java b/core/src/main/java/google/registry/rdap/RdapDomainAction.java index 0e01bbd424..5f8a9524a3 100644 --- a/core/src/main/java/google/registry/rdap/RdapDomainAction.java +++ b/core/src/main/java/google/registry/rdap/RdapDomainAction.java @@ -26,6 +26,7 @@ import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapObjectClasses.RdapDomain; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotFoundException; import google.registry.request.auth.Auth; @@ -34,7 +35,7 @@ /** RDAP (new WHOIS) action for domain requests. */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/domain/", method = {GET, HEAD}, isPrefix = true, diff --git a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java index 861609c766..e21fc7d4e8 100644 --- a/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapDomainSearchAction.java @@ -43,6 +43,7 @@ import google.registry.rdap.RdapSearchResults.DomainSearchResponse; import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotFoundException; import google.registry.request.HttpException.UnprocessableEntityException; @@ -71,7 +72,7 @@ // TODO: This isn't required by the RDAP Technical Implementation Guide, and hence should be // deleted, at least until it's actually required. @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/domains", method = {GET, HEAD}, auth = Auth.AUTH_PUBLIC) diff --git a/core/src/main/java/google/registry/rdap/RdapEntityAction.java b/core/src/main/java/google/registry/rdap/RdapEntityAction.java index f4c24adb66..7510a66645 100644 --- a/core/src/main/java/google/registry/rdap/RdapEntityAction.java +++ b/core/src/main/java/google/registry/rdap/RdapEntityAction.java @@ -30,6 +30,7 @@ import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapObjectClasses.RdapEntity; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NotFoundException; import google.registry.request.auth.Auth; import java.util.Optional; @@ -46,7 +47,7 @@ * Registrar ID registry. The type value of the publicID object MUST be equal to IANA Registrar ID. */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/entity/", method = {GET, HEAD}, isPrefix = true, diff --git a/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java b/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java index 7314a37d12..282cd4bdc4 100644 --- a/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapEntitySearchAction.java @@ -37,6 +37,7 @@ import google.registry.rdap.RdapSearchResults.EntitySearchResponse; import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotFoundException; import google.registry.request.HttpException.UnprocessableEntityException; @@ -78,7 +79,7 @@ // TODO: This isn't required by the RDAP Technical Implementation Guide, and hence should be // deleted, at least until it's actually required. @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/entities", method = {GET, HEAD}, auth = Auth.AUTH_PUBLIC) diff --git a/core/src/main/java/google/registry/rdap/RdapHelpAction.java b/core/src/main/java/google/registry/rdap/RdapHelpAction.java index bf71636992..fe1403f2e6 100644 --- a/core/src/main/java/google/registry/rdap/RdapHelpAction.java +++ b/core/src/main/java/google/registry/rdap/RdapHelpAction.java @@ -22,6 +22,7 @@ import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapObjectClasses.HelpResponse; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NotFoundException; import google.registry.request.auth.Auth; import java.util.Optional; @@ -29,7 +30,7 @@ /** RDAP (new WHOIS) action for help requests. */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/help", method = {GET, HEAD}, isPrefix = true, diff --git a/core/src/main/java/google/registry/rdap/RdapIpAction.java b/core/src/main/java/google/registry/rdap/RdapIpAction.java index 2209184093..4121e08925 100644 --- a/core/src/main/java/google/registry/rdap/RdapIpAction.java +++ b/core/src/main/java/google/registry/rdap/RdapIpAction.java @@ -20,6 +20,7 @@ import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapObjectClasses.ReplyPayloadBase; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NotImplementedException; import google.registry.request.auth.Auth; import javax.inject.Inject; @@ -31,7 +32,7 @@ * ARIN, not domain registries. */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/ip/", method = {GET, HEAD}, isPrefix = true, diff --git a/core/src/main/java/google/registry/rdap/RdapNameserverAction.java b/core/src/main/java/google/registry/rdap/RdapNameserverAction.java index 25ecce7801..9f6dc2ef56 100644 --- a/core/src/main/java/google/registry/rdap/RdapNameserverAction.java +++ b/core/src/main/java/google/registry/rdap/RdapNameserverAction.java @@ -26,6 +26,7 @@ import google.registry.rdap.RdapMetrics.EndpointType; import google.registry.rdap.RdapObjectClasses.RdapNameserver; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotFoundException; import google.registry.request.auth.Auth; @@ -34,7 +35,7 @@ /** RDAP (new WHOIS) action for nameserver requests. */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/nameserver/", method = {GET, HEAD}, isPrefix = true, diff --git a/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java b/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java index 2a5977cc6e..d3d507e428 100644 --- a/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java +++ b/core/src/main/java/google/registry/rdap/RdapNameserverSearchAction.java @@ -34,6 +34,7 @@ import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.rdap.RdapSearchResults.NameserverSearchResponse; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotFoundException; import google.registry.request.HttpException.UnprocessableEntityException; @@ -56,7 +57,7 @@ * Data Access Protocol (RDAP) */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = "/rdap/nameservers", method = {GET, HEAD}, auth = Auth.AUTH_PUBLIC) diff --git a/core/src/main/java/google/registry/rdap/UpdateRegistrarRdapBaseUrlsAction.java b/core/src/main/java/google/registry/rdap/UpdateRegistrarRdapBaseUrlsAction.java index 583115d3b3..b3960bae03 100644 --- a/core/src/main/java/google/registry/rdap/UpdateRegistrarRdapBaseUrlsAction.java +++ b/core/src/main/java/google/registry/rdap/UpdateRegistrarRdapBaseUrlsAction.java @@ -26,6 +26,7 @@ import com.google.common.flogger.FluentLogger; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.InternalServerErrorException; import google.registry.request.UrlConnectionService; import google.registry.request.UrlConnectionUtils; @@ -52,7 +53,7 @@ * CSV endpoint requires no authentication. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/updateRegistrarRdapBaseUrls", automaticallyPrintOk = true, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/rde/BrdaCopyAction.java b/core/src/main/java/google/registry/rde/BrdaCopyAction.java index f59546bfea..2590a6ee10 100644 --- a/core/src/main/java/google/registry/rde/BrdaCopyAction.java +++ b/core/src/main/java/google/registry/rde/BrdaCopyAction.java @@ -32,6 +32,7 @@ import google.registry.model.rde.RdeRevision; import google.registry.model.tld.Tld; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NoContentException; import google.registry.request.Parameter; import google.registry.request.RequestParameters; @@ -62,7 +63,7 @@ * Agreement */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = BrdaCopyAction.PATH, method = POST, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/rde/RdeReportAction.java b/core/src/main/java/google/registry/rde/RdeReportAction.java index 9717bfa1fa..11707c8441 100644 --- a/core/src/main/java/google/registry/rde/RdeReportAction.java +++ b/core/src/main/java/google/registry/rde/RdeReportAction.java @@ -36,6 +36,7 @@ import google.registry.model.tld.Tld; import google.registry.rde.EscrowTaskRunner.EscrowTask; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NoContentException; import google.registry.request.Parameter; import google.registry.request.RequestParameters; @@ -53,7 +54,7 @@ * Action that uploads a small XML RDE report to ICANN after {@link RdeUploadAction} has finished. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = RdeReportAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/rde/RdeStagingAction.java b/core/src/main/java/google/registry/rde/RdeStagingAction.java index 2cd97a5602..f446b6565c 100644 --- a/core/src/main/java/google/registry/rde/RdeStagingAction.java +++ b/core/src/main/java/google/registry/rde/RdeStagingAction.java @@ -50,6 +50,7 @@ import google.registry.model.rde.RdeMode; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.Parameter; import google.registry.request.RequestParameters; @@ -204,7 +205,7 @@ * Name Registration Data Objects Mapping */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = RdeStagingAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/rde/RdeUploadAction.java b/core/src/main/java/google/registry/rde/RdeUploadAction.java index a3f80eb1ea..3b175edf43 100644 --- a/core/src/main/java/google/registry/rde/RdeUploadAction.java +++ b/core/src/main/java/google/registry/rde/RdeUploadAction.java @@ -50,7 +50,7 @@ import google.registry.rde.EscrowTaskRunner.EscrowTask; import google.registry.rde.JSchSshSession.JSchSshSessionFactory; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.NoContentException; import google.registry.request.Parameter; import google.registry.request.RequestParameters; @@ -84,7 +84,7 @@ * RdeReportAction}. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = RdeUploadAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) @@ -130,8 +130,7 @@ public void run() { params.put(RequestParameters.PARAM_TLD, tld); prefix.ifPresent(s -> params.put(RdeModule.PARAM_PREFIX, s)); cloudTasksUtils.enqueue( - RDE_REPORT_QUEUE, - cloudTasksUtils.createPostTask(RdeReportAction.PATH, Service.BACKEND, params)); + RDE_REPORT_QUEUE, cloudTasksUtils.createTask(RdeReportAction.class, POST, params)); } @Override diff --git a/core/src/main/java/google/registry/reporting/billing/CopyDetailReportsAction.java b/core/src/main/java/google/registry/reporting/billing/CopyDetailReportsAction.java index 12856410e2..7af9befd96 100644 --- a/core/src/main/java/google/registry/reporting/billing/CopyDetailReportsAction.java +++ b/core/src/main/java/google/registry/reporting/billing/CopyDetailReportsAction.java @@ -32,6 +32,7 @@ import google.registry.model.registrar.Registrar; import google.registry.reporting.billing.BillingModule.InvoiceDirectoryPrefix; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.storage.drive.DriveConnection; @@ -44,7 +45,7 @@ /** Copy all registrar detail reports in a given bucket's subdirectory from GCS to Drive. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = CopyDetailReportsAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java b/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java index bc81da2b5a..bb379a432c 100644 --- a/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java +++ b/core/src/main/java/google/registry/reporting/billing/GenerateInvoicesAction.java @@ -32,7 +32,7 @@ import google.registry.persistence.PersistenceModule; import google.registry.reporting.ReportingModule; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -51,7 +51,7 @@ * template. The pipeline then generates invoices for the month and stores them on GCS. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = GenerateInvoicesAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) @@ -138,9 +138,9 @@ public void run() { if (shouldPublish) { cloudTasksUtils.enqueue( ReportingModule.BEAM_QUEUE, - cloudTasksUtils.createPostTaskWithDelay( - PublishInvoicesAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTaskWithDelay( + PublishInvoicesAction.class, + POST, ImmutableMultimap.of( ReportingModule.PARAM_JOB_ID, jobId, diff --git a/core/src/main/java/google/registry/reporting/billing/PublishInvoicesAction.java b/core/src/main/java/google/registry/reporting/billing/PublishInvoicesAction.java index 8ac43e2ade..b473117fec 100644 --- a/core/src/main/java/google/registry/reporting/billing/PublishInvoicesAction.java +++ b/core/src/main/java/google/registry/reporting/billing/PublishInvoicesAction.java @@ -30,7 +30,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.reporting.ReportingModule; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -49,7 +49,7 @@ * Job States */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = PublishInvoicesAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) @@ -125,9 +125,9 @@ public void run() { private void enqueueCopyDetailReportsTask() { cloudTasksUtils.enqueue( BillingModule.CRON_QUEUE, - cloudTasksUtils.createPostTask( - CopyDetailReportsAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTask( + CopyDetailReportsAction.class, + POST, ImmutableMultimap.of(PARAM_YEAR_MONTH, yearMonth.toString()))); } } diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java index b091de4691..08617556e6 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingStagingAction.java @@ -34,7 +34,7 @@ import google.registry.reporting.ReportingModule; import google.registry.reporting.icann.IcannReportingModule.ReportType; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -66,7 +66,7 @@ * 'transactions'. If none specified - defaults to generating both. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = IcannReportingStagingAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) @@ -138,11 +138,8 @@ public void run() { logger.atInfo().log("Enqueueing report upload."); cloudTasksUtils.enqueue( CRON_QUEUE, - cloudTasksUtils.createPostTaskWithDelay( - IcannReportingUploadAction.PATH, - Service.BACKEND, - null, - Duration.standardMinutes(2))); + cloudTasksUtils.createTaskWithDelay( + IcannReportingUploadAction.class, POST, null, Duration.standardMinutes(2))); } else { logger.atInfo().log("Would have enqueued report upload"); } diff --git a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java index 1970d1045d..885680311e 100644 --- a/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java +++ b/core/src/main/java/google/registry/reporting/icann/IcannReportingUploadAction.java @@ -35,6 +35,7 @@ import google.registry.model.tld.Tlds; import google.registry.persistence.VKey; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.ServiceUnavailableException; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -67,7 +68,7 @@ * Defaults to "icann/monthly/[last month in yyyy-MM format]". */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = IcannReportingUploadAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java b/core/src/main/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java index b95d8f347b..ece7ea2b80 100644 --- a/core/src/main/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java +++ b/core/src/main/java/google/registry/reporting/spec11/GenerateSpec11ReportAction.java @@ -32,7 +32,7 @@ import google.registry.keyring.api.KeyModule.Key; import google.registry.reporting.ReportingModule; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -50,7 +50,7 @@ * generates the specified month's Spec11 report and stores it on GCS. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = GenerateSpec11ReportAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) @@ -133,9 +133,9 @@ public void run() { if (sendEmail) { cloudTasksUtils.enqueue( ReportingModule.BEAM_QUEUE, - cloudTasksUtils.createPostTaskWithDelay( - PublishSpec11ReportAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTaskWithDelay( + PublishSpec11ReportAction.class, + POST, ImmutableMultimap.of( ReportingModule.PARAM_JOB_ID, jobId, diff --git a/core/src/main/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java b/core/src/main/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java index 43c16db57a..e3205edb82 100644 --- a/core/src/main/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java +++ b/core/src/main/java/google/registry/reporting/spec11/PublishSpec11ReportAction.java @@ -38,6 +38,7 @@ import google.registry.reporting.ReportingModule; import google.registry.reporting.spec11.soy.Spec11EmailSoyInfo; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -56,7 +57,7 @@ * ImmutableSet)} on success or {@link Spec11EmailUtils#sendAlertEmail(String, String)} on failure. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = PublishSpec11ReportAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/request/Action.java b/core/src/main/java/google/registry/request/Action.java index b213895c9f..2445006e1a 100644 --- a/core/src/main/java/google/registry/request/Action.java +++ b/core/src/main/java/google/registry/request/Action.java @@ -16,11 +16,13 @@ import static com.google.common.base.Preconditions.checkState; +import google.registry.config.RegistryConfig; import google.registry.request.auth.Auth; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.net.URL; /** Annotation for {@link Runnable} actions accepting HTTP requests from {@link RequestHandler}. */ @Retention(RetentionPolicy.RUNTIME) @@ -28,10 +30,19 @@ public @interface Action { /** HTTP methods recognized by the request processor. */ - enum Method { GET, HEAD, POST } + enum Method { + GET, + HEAD, + POST + } + + interface Service { + String getServiceId(); - /** App Engine services supported by the request processor. */ - enum Service { + URL getServiceUrl(); + } + + enum GaeService implements Service { BSA("bsa"), DEFAULT("default"), TOOLS("tools"), @@ -40,17 +51,28 @@ enum Service { private final String serviceId; - Service(String serviceId) { + GaeService(String serviceId) { this.serviceId = serviceId; } - /** Returns the actual service id in App Engine. */ + @Override public String getServiceId() { return serviceId; } + + @Override + public URL getServiceUrl() { + return switch (this) { + case DEFAULT -> RegistryConfig.getDefaultServer(); + case TOOLS -> RegistryConfig.getToolsServer(); + case BACKEND -> RegistryConfig.getBackendServer(); + case BSA -> RegistryConfig.getBsaServer(); + case PUBAPI -> RegistryConfig.getPubapiServer(); + }; + } } - enum GkeService { + enum GkeService implements Service { // This designation means that it defers to the GAE service, so we don't have to annotate EVERY // action during the GKE migration. SAME_AS_GAE("same_as_gae"), @@ -65,14 +87,20 @@ enum GkeService { this.serviceId = serviceId; } + @Override public String getServiceId() { checkState(this != SAME_AS_GAE, "Cannot get service Id for SAME_AS_GAE"); return serviceId; } + + @Override + public URL getServiceUrl() { + return RegistryConfig.getServiceUrl(this); + } } /** Which App Engine service this action lives on. */ - Service service(); + GaeService service(); /** Which GKE service this action lives on. */ GkeService gkeService() default GkeService.SAME_AS_GAE; @@ -105,7 +133,7 @@ public static GkeService get(Action action) { if (service != GkeService.SAME_AS_GAE) { return service; } - Service gaeService = action.service(); + GaeService gaeService = action.service(); return switch (gaeService) { case DEFAULT -> GkeService.FRONTEND; case BACKEND -> GkeService.BACKEND; diff --git a/core/src/main/java/google/registry/request/RequestHandler.java b/core/src/main/java/google/registry/request/RequestHandler.java index e81efe95e7..79662ea3ae 100644 --- a/core/src/main/java/google/registry/request/RequestHandler.java +++ b/core/src/main/java/google/registry/request/RequestHandler.java @@ -22,6 +22,7 @@ import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; import com.google.common.flogger.FluentLogger; +import google.registry.config.RegistryConfig; import google.registry.request.Action.GkeService; import google.registry.request.auth.AuthResult; import google.registry.request.auth.RequestAuthenticator; @@ -72,7 +73,6 @@ public class RequestHandler { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private final Router router; - @Nullable private final String baseDomain; private final Provider> requestComponentBuilderProvider; private final RequestAuthenticator requestAuthenticator; private final SystemClock clock = new SystemClock(); @@ -95,22 +95,20 @@ public class RequestHandler { protected RequestHandler( Provider> requestComponentBuilderProvider, RequestAuthenticator requestAuthenticator) { - this(null, null, requestComponentBuilderProvider, requestAuthenticator); + this(null, requestComponentBuilderProvider, requestAuthenticator); } /** Creates a new RequestHandler with an explicit component class for test purposes. */ public static RequestHandler create( Class component, - @Nullable String baseDomain, Provider> requestComponentBuilderProvider, RequestAuthenticator requestAuthenticator) { return new RequestHandler<>( - checkNotNull(component), baseDomain, requestComponentBuilderProvider, requestAuthenticator); + checkNotNull(component), requestComponentBuilderProvider, requestAuthenticator); } private RequestHandler( @Nullable Class component, - @Nullable String baseDomain, Provider> requestComponentBuilderProvider, RequestAuthenticator requestAuthenticator) { // If the component class isn't explicitly provided, infer it from the class's own typing. @@ -118,7 +116,6 @@ private RequestHandler( // preserved at runtime, so only expose that option via the protected constructor. this.router = Router.create( component != null ? component : new TypeInstantiator(getClass()){}.getExactType()); - this.baseDomain = baseDomain; this.requestComponentBuilderProvider = checkNotNull(requestComponentBuilderProvider); this.requestAuthenticator = checkNotNull(requestAuthenticator); } @@ -144,7 +141,7 @@ public void handleRequest(HttpServletRequest req, HttpServletResponse rsp) throw } if (RegistryEnvironment.isOnJetty()) { GkeService service = Action.ServiceGetter.get(route.get().action()); - String expectedDomain = String.format("%s.%s", service.getServiceId(), baseDomain); + String expectedDomain = RegistryConfig.getServiceUrl(service).getHost(); String actualDomain = req.getServerName(); if (!Objects.equals(actualDomain, expectedDomain)) { logger.atWarning().log( diff --git a/core/src/main/java/google/registry/tmch/NordnUploadAction.java b/core/src/main/java/google/registry/tmch/NordnUploadAction.java index 371b98ef2b..20eeaaf8d9 100644 --- a/core/src/main/java/google/registry/tmch/NordnUploadAction.java +++ b/core/src/main/java/google/registry/tmch/NordnUploadAction.java @@ -37,7 +37,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.model.domain.Domain; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.RequestParameters; import google.registry.request.UrlConnectionService; @@ -66,7 +66,7 @@ * @see NordnVerifyAction */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = NordnUploadAction.PATH, method = Action.Method.POST, automaticallyPrintOk = true, @@ -240,9 +240,9 @@ private URL uploadCsvToLordn(String urlPath, String csvData) private Task makeVerifyTask(URL url) { // The actionLogId is used to uniquely associate the verify task back to the upload task. - return cloudTasksUtils.createPostTaskWithDelay( - NordnVerifyAction.PATH, - Service.BACKEND, + return cloudTasksUtils.createTaskWithDelay( + NordnVerifyAction.class, + Action.Method.POST, ImmutableMultimap.builder() .put(NordnVerifyAction.NORDN_URL_PARAM, url.toString()) .put(NordnVerifyAction.NORDN_LOG_ID_PARAM, actionLogId) diff --git a/core/src/main/java/google/registry/tmch/NordnVerifyAction.java b/core/src/main/java/google/registry/tmch/NordnVerifyAction.java index 6233fb0cbb..e2265e0a47 100644 --- a/core/src/main/java/google/registry/tmch/NordnVerifyAction.java +++ b/core/src/main/java/google/registry/tmch/NordnVerifyAction.java @@ -23,6 +23,7 @@ import com.google.common.flogger.FluentLogger; import com.google.common.io.ByteSource; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.ConflictException; import google.registry.request.Parameter; import google.registry.request.RequestParameters; @@ -50,7 +51,7 @@ * http://tools.ietf.org/html/draft-lozano-tmch-func-spec-08#section-5.2.3.3 */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = NordnVerifyAction.PATH, method = Action.Method.POST, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/tmch/TmchCrlAction.java b/core/src/main/java/google/registry/tmch/TmchCrlAction.java index 13b1b00ae2..af2cd5b18a 100644 --- a/core/src/main/java/google/registry/tmch/TmchCrlAction.java +++ b/core/src/main/java/google/registry/tmch/TmchCrlAction.java @@ -19,6 +19,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import java.io.IOException; import java.net.URL; @@ -28,7 +29,7 @@ /** Action to download the latest ICANN TMCH CRL from MarksDB. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/tmchCrl", method = POST, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/tmch/TmchDnlAction.java b/core/src/main/java/google/registry/tmch/TmchDnlAction.java index 03e77acaea..1a8e0e0384 100644 --- a/core/src/main/java/google/registry/tmch/TmchDnlAction.java +++ b/core/src/main/java/google/registry/tmch/TmchDnlAction.java @@ -22,6 +22,7 @@ import google.registry.model.tmch.ClaimsList; import google.registry.model.tmch.ClaimsListDao; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import java.io.IOException; import java.security.GeneralSecurityException; @@ -31,7 +32,7 @@ /** Action to download the latest domain name list (aka claims list) from MarksDB. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/tmchDnl", method = POST, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/tmch/TmchSmdrlAction.java b/core/src/main/java/google/registry/tmch/TmchSmdrlAction.java index a478832d9d..4ecdd2ce39 100644 --- a/core/src/main/java/google/registry/tmch/TmchSmdrlAction.java +++ b/core/src/main/java/google/registry/tmch/TmchSmdrlAction.java @@ -21,6 +21,7 @@ import google.registry.keyring.api.KeyModule.Key; import google.registry.model.smd.SignedMarkRevocationList; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import java.io.IOException; import java.security.GeneralSecurityException; @@ -30,7 +31,7 @@ /** Action to download the latest signed mark revocation list from MarksDB. */ @Action( - service = Action.Service.BACKEND, + service = GaeService.BACKEND, path = "/_dr/task/tmchSmdrl", method = POST, automaticallyPrintOk = true, diff --git a/core/src/main/java/google/registry/tools/CurlCommand.java b/core/src/main/java/google/registry/tools/CurlCommand.java index 7a66ccb193..1b3c234fa4 100644 --- a/core/src/main/java/google/registry/tools/CurlCommand.java +++ b/core/src/main/java/google/registry/tools/CurlCommand.java @@ -26,8 +26,12 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; +import google.registry.config.RegistryConfig.Config; +import google.registry.request.Action.GaeService; +import google.registry.request.Action.GkeService; import google.registry.request.Action.Service; import java.util.List; +import javax.inject.Inject; @Parameters(separators = " =", commandDescription = "Send an HTTP command to the nomulus server.") class CurlCommand implements CommandWithConnection { @@ -73,13 +77,17 @@ public enum Method { names = {"--service"}, description = "Which service to connect to", required = true) - private Service service; + private String serviceName; @Parameter( names = {"--canary"}, description = "If set, use the canary end-point; otherwise use the regular end-point.") private Boolean canary = Boolean.FALSE; + @Inject + @Config("useGke") + boolean useGke; + @Override public void setConnection(ServiceConnection connection) { this.connection = connection; @@ -95,6 +103,8 @@ public void run() throws Exception { throw new IllegalArgumentException("You may not specify a body for a get method."); } + Service service = useGke ? GkeService.valueOf(serviceName) : GaeService.valueOf(serviceName); + ServiceConnection connectionToService = connection.withService(service, canary); String response = (method == Method.GET) diff --git a/core/src/main/java/google/registry/tools/DomainLockUtils.java b/core/src/main/java/google/registry/tools/DomainLockUtils.java index 76ddff8db7..7b0af21ea6 100644 --- a/core/src/main/java/google/registry/tools/DomainLockUtils.java +++ b/core/src/main/java/google/registry/tools/DomainLockUtils.java @@ -34,7 +34,7 @@ import google.registry.model.reporting.HistoryEntry; import google.registry.model.tld.RegistryLockDao; import google.registry.model.tld.Tld; -import google.registry.request.Action.Service; +import google.registry.request.Action; import google.registry.util.StringGenerator; import java.util.Optional; import javax.annotation.Nullable; @@ -191,9 +191,9 @@ public void enqueueDomainRelock(RegistryLock lock) { public void enqueueDomainRelock(Duration countdown, long lockRevisionId, int previousAttempts) { cloudTasksUtils.enqueue( QUEUE_ASYNC_ACTIONS, - cloudTasksUtils.createPostTaskWithDelay( - RelockDomainAction.PATH, - Service.BACKEND, + cloudTasksUtils.createTaskWithDelay( + RelockDomainAction.class, + Action.Method.POST, ImmutableMultimap.of( RelockDomainAction.OLD_UNLOCK_REVISION_ID_PARAM, String.valueOf(lockRevisionId), diff --git a/core/src/main/java/google/registry/tools/GenerateEscrowDepositCommand.java b/core/src/main/java/google/registry/tools/GenerateEscrowDepositCommand.java index 3b8ceeb40c..60013764c2 100644 --- a/core/src/main/java/google/registry/tools/GenerateEscrowDepositCommand.java +++ b/core/src/main/java/google/registry/tools/GenerateEscrowDepositCommand.java @@ -22,6 +22,7 @@ import static google.registry.rde.RdeModule.PARAM_REVISION; import static google.registry.rde.RdeModule.PARAM_WATERMARKS; import static google.registry.rde.RdeModule.RDE_REPORT_QUEUE; +import static google.registry.request.Action.Method.POST; import static google.registry.request.RequestParameters.PARAM_TLDS; import com.beust.jcommander.Parameter; @@ -31,7 +32,6 @@ import google.registry.batch.CloudTasksUtils; import google.registry.model.rde.RdeMode; import google.registry.rde.RdeStagingAction; -import google.registry.request.Action.Service; import java.util.List; import java.util.stream.Collectors; import javax.inject.Inject; @@ -124,8 +124,7 @@ public void run() { } cloudTasksUtils.enqueue( RDE_REPORT_QUEUE, - cloudTasksUtils.createPostTask( - RdeStagingAction.PATH, Service.BACKEND, paramsBuilder.build())); + cloudTasksUtils.createTask(RdeStagingAction.class, POST, paramsBuilder.build())); } } diff --git a/core/src/main/java/google/registry/tools/RegistryCli.java b/core/src/main/java/google/registry/tools/RegistryCli.java index 0b3400ec6e..3ce447dea1 100644 --- a/core/src/main/java/google/registry/tools/RegistryCli.java +++ b/core/src/main/java/google/registry/tools/RegistryCli.java @@ -70,6 +70,9 @@ final class RegistryCli implements CommandRunner { + "Beam pipelines") private String sqlAccessInfoFile = null; + @Parameter(names = "--gke", description = "Whether to use GKE runtime, instead of GAE") + private boolean useGke = false; + // Do not make this final - compile-time constant inlining may interfere with JCommander. @ParametersDelegate private LoggingParameters loggingParams = new LoggingParameters(); @@ -93,10 +96,10 @@ final class RegistryCli implements CommandRunner { Security.addProvider(new BouncyCastleProvider()); } - // The > wildcard looks a little funny, but is needed so that - // we can accept maps with value types that are subtypes of Class rather than - // literally that type. For more explanation, see: - // http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeArguments.html#FAQ104 + // The > wildcard looks a little funny, but is necessary so + // that we can accept maps with value types that are subtypes of Class rather + // than literally that type. For more explanation, see: + // http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeArguments.html#FAQ104 @Override public void run(String[] args) throws Exception { @@ -105,7 +108,7 @@ public void run(String[] args) throws Exception { jcommander.addConverterFactory(new ParameterFactory()); jcommander.setProgramName(programName); - // Create all command instances. It would be preferrable to do this in the constructor, but + // Create all command instances. It would be preferable to do this in the constructor, but // JCommander mutates the command instances and doesn't reset them, so we have to do it for // every run. try { @@ -162,6 +165,7 @@ public void run(String[] args) throws Exception { DaggerRegistryToolComponent.builder() .credentialFilePath(credentialJson) .sqlAccessInfoFile(sqlAccessInfoFile) + .useGke(useGke) .build(); // JCommander stores sub-commands as nested JCommander objects containing a list of user objects @@ -204,7 +208,7 @@ public void run(String[] args) throws Exception { } private ServiceConnection getConnection() { - // Get the App Engine connection, advise the user if they are not currently logged in.. + // Get the App Engine connection, advise the user if they are not currently logged in. if (connection == null) { connection = component.serviceConnection(); } diff --git a/core/src/main/java/google/registry/tools/RegistryToolComponent.java b/core/src/main/java/google/registry/tools/RegistryToolComponent.java index d5ffd0f830..40b093c18d 100644 --- a/core/src/main/java/google/registry/tools/RegistryToolComponent.java +++ b/core/src/main/java/google/registry/tools/RegistryToolComponent.java @@ -101,6 +101,8 @@ interface RegistryToolComponent { void inject(CreateUserCommand command); + void inject(CurlCommand command); + void inject(DeleteUserCommand command); void inject(EncryptEscrowDepositCommand command); @@ -190,6 +192,9 @@ interface Builder { @BindsInstance Builder sqlAccessInfoFile(@Nullable @Config("sqlAccessInfoFile") String sqlAccessInfoFile); + @BindsInstance + Builder useGke(@Config("useGke") boolean useGke); + RegistryToolComponent build(); } } diff --git a/core/src/main/java/google/registry/tools/ServiceConnection.java b/core/src/main/java/google/registry/tools/ServiceConnection.java index 3eaa2898ba..5d7fdb382a 100644 --- a/core/src/main/java/google/registry/tools/ServiceConnection.java +++ b/core/src/main/java/google/registry/tools/ServiceConnection.java @@ -19,6 +19,7 @@ import static com.google.common.base.Verify.verify; import static com.google.common.net.HttpHeaders.X_REQUESTED_WITH; import static com.google.common.net.MediaType.JSON_UTF_8; +import static google.registry.config.ConfigUtils.makeUrl; import static google.registry.security.JsonHttp.JSON_SAFETY_PREFIX; import static java.nio.charset.StandardCharsets.UTF_8; @@ -35,11 +36,12 @@ import com.google.common.net.MediaType; import com.google.re2j.Matcher; import com.google.re2j.Pattern; -import google.registry.config.RegistryConfig; +import google.registry.config.RegistryConfig.Config; +import google.registry.request.Action.GaeService; +import google.registry.request.Action.GkeService; import google.registry.request.Action.Service; import java.io.IOException; import java.io.InputStreamReader; -import java.net.MalformedURLException; import java.net.URL; import java.util.Map; import javax.annotation.Nullable; @@ -49,33 +51,33 @@ /** * An HTTP connection to a service. * - *

By default - connects to the TOOLS service. To create a Connection to another service, call - * the {@link #withService} function. + *

By default - connects to the TOOLS service in GAE and the BACKEND service in GKE. To create a + * Connection to another service, call the {@link #withService} function. */ public class ServiceConnection { /** Pattern to heuristically extract title tag contents in HTML responses. */ - private static final Pattern HTML_TITLE_TAG_PATTERN = Pattern.compile("(.*?)"); + protected static final Pattern HTML_TITLE_TAG_PATTERN = Pattern.compile("(.*?)"); - @Inject HttpRequestFactory requestFactory; - private final Service service; - private final boolean useCanary; + protected final Service service; + protected final boolean useCanary; + protected final HttpRequestFactory requestFactory; @Inject - ServiceConnection() { - service = Service.TOOLS; - useCanary = false; + ServiceConnection(@Config("useGke") boolean useGke, HttpRequestFactory requestFactory) { + this(useGke ? GkeService.BACKEND : GaeService.TOOLS, requestFactory, false); } - private ServiceConnection(Service service, HttpRequestFactory requestFactory, boolean useCanary) { + protected ServiceConnection( + Service service, HttpRequestFactory requestFactory, boolean useCanary) { this.service = service; this.requestFactory = requestFactory; this.useCanary = useCanary; } /** Returns a copy of this connection that talks to a different service endpoint. */ - public ServiceConnection withService(Service service, boolean isCanary) { - return new ServiceConnection(service, requestFactory, isCanary); + public ServiceConnection withService(Service service, boolean useCanary) { + return new ServiceConnection(service, requestFactory, useCanary); } /** Returns the contents of the title tag in the given HTML, or null if not found. */ @@ -129,14 +131,14 @@ url, new ByteArrayContent(contentType.toString(), payload)) @VisibleForTesting URL getServer() { - URL url = getServer(service); - if (useCanary) { + URL url = service.getServiceUrl(); + // Currently only GAE supports connecting to canary. + if (service instanceof GaeService && useCanary) { verify(!isNullOrEmpty(url.getHost()), "Null host in url"); - try { - return new URL(url.getProtocol(), "nomulus-dot-" + url.getHost(), url.getFile()); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } + url = + makeUrl( + String.format( + "%s://nomulus-dot-%s%s", url.getProtocol(), url.getHost(), url.getFile())); } return url; } @@ -161,14 +163,4 @@ public Map sendJson(String endpoint, Map object) thro JSONValue.toJSONString(object).getBytes(UTF_8)); return (Map) JSONValue.parse(response.substring(JSON_SAFETY_PREFIX.length())); } - - public static URL getServer(Service service) { - return switch (service) { - case DEFAULT -> RegistryConfig.getDefaultServer(); - case TOOLS -> RegistryConfig.getToolsServer(); - case BACKEND -> RegistryConfig.getBackendServer(); - case BSA -> RegistryConfig.getBsaServer(); - case PUBAPI -> RegistryConfig.getPubapiServer(); - }; - } } diff --git a/core/src/main/java/google/registry/tools/server/CreateGroupsAction.java b/core/src/main/java/google/registry/tools/server/CreateGroupsAction.java index 2f1d6ca54c..ac2485290f 100644 --- a/core/src/main/java/google/registry/tools/server/CreateGroupsAction.java +++ b/core/src/main/java/google/registry/tools/server/CreateGroupsAction.java @@ -26,6 +26,7 @@ import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarPocBase; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.InternalServerErrorException; import google.registry.request.Parameter; @@ -40,7 +41,7 @@ /** Action that creates Google Groups for a registrar's mailing lists. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = CreateGroupsAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/GenerateZoneFilesAction.java b/core/src/main/java/google/registry/tools/server/GenerateZoneFilesAction.java index 12f5c311fc..28c96f9b9a 100644 --- a/core/src/main/java/google/registry/tools/server/GenerateZoneFilesAction.java +++ b/core/src/main/java/google/registry/tools/server/GenerateZoneFilesAction.java @@ -33,6 +33,7 @@ import google.registry.model.host.Host; import google.registry.model.tld.Tld; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.JsonActionRunner; import google.registry.request.auth.Auth; @@ -62,7 +63,7 @@ * days in the past, and must be at midnight UTC. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = GenerateZoneFilesAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/ListDomainsAction.java b/core/src/main/java/google/registry/tools/server/ListDomainsAction.java index dc1e742c36..bed2e3a6de 100644 --- a/core/src/main/java/google/registry/tools/server/ListDomainsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListDomainsAction.java @@ -28,6 +28,7 @@ import google.registry.model.EppResourceUtils; import google.registry.model.domain.Domain; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.util.Clock; @@ -36,7 +37,7 @@ /** An action that lists domains, for use by the {@code nomulus list_domains} command. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = ListDomainsAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/ListHostsAction.java b/core/src/main/java/google/registry/tools/server/ListHostsAction.java index 0ae68c8a2b..461ceed38f 100644 --- a/core/src/main/java/google/registry/tools/server/ListHostsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListHostsAction.java @@ -24,6 +24,7 @@ import google.registry.model.EppResourceUtils; import google.registry.model.host.Host; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import google.registry.util.Clock; import javax.inject.Inject; @@ -31,7 +32,7 @@ /** An action that lists hosts, for use by the {@code nomulus list_hosts} command. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = ListHostsAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/ListPremiumListsAction.java b/core/src/main/java/google/registry/tools/server/ListPremiumListsAction.java index e8e16ad8e3..e981c715ec 100644 --- a/core/src/main/java/google/registry/tools/server/ListPremiumListsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListPremiumListsAction.java @@ -23,6 +23,7 @@ import google.registry.model.tld.label.PremiumList; import google.registry.model.tld.label.PremiumListDao; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import java.util.Comparator; import java.util.Optional; @@ -32,7 +33,7 @@ * An action that lists premium lists, for use by the {@code nomulus list_premium_lists} command. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = ListPremiumListsAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/ListRegistrarsAction.java b/core/src/main/java/google/registry/tools/server/ListRegistrarsAction.java index 1fc2d40469..4dbc1744ce 100644 --- a/core/src/main/java/google/registry/tools/server/ListRegistrarsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListRegistrarsAction.java @@ -22,12 +22,13 @@ import com.google.common.collect.ImmutableSet; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import javax.inject.Inject; /** An action that lists registrars, for use by the {@code nomulus list_registrars} command. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = ListRegistrarsAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/ListReservedListsAction.java b/core/src/main/java/google/registry/tools/server/ListReservedListsAction.java index 7fd2d239da..630610256e 100644 --- a/core/src/main/java/google/registry/tools/server/ListReservedListsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListReservedListsAction.java @@ -23,6 +23,7 @@ import google.registry.model.tld.label.ReservedList; import google.registry.model.tld.label.ReservedListDao; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import java.util.Comparator; import java.util.Optional; @@ -30,7 +31,7 @@ /** A that lists reserved lists, for use by the {@code nomulus list_reserved_lists} command. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = ListReservedListsAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/ListTldsAction.java b/core/src/main/java/google/registry/tools/server/ListTldsAction.java index 351a206596..078945c728 100644 --- a/core/src/main/java/google/registry/tools/server/ListTldsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListTldsAction.java @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableSet; import google.registry.model.tld.Tld; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import google.registry.util.Clock; import javax.inject.Inject; @@ -31,7 +32,7 @@ /** An action that lists top-level domains, for use by the {@code nomulus list_tlds} command. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = ListTldsAction.PATH, method = {GET, POST}, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/RefreshDnsForAllDomainsAction.java b/core/src/main/java/google/registry/tools/server/RefreshDnsForAllDomainsAction.java index a4f876e39f..43b46138a1 100644 --- a/core/src/main/java/google/registry/tools/server/RefreshDnsForAllDomainsAction.java +++ b/core/src/main/java/google/registry/tools/server/RefreshDnsForAllDomainsAction.java @@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.flogger.FluentLogger; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -57,7 +58,7 @@ * domains that have since been deleted. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = "/_dr/task/refreshDnsForAllDomains", auth = Auth.AUTH_ADMIN) public class RefreshDnsForAllDomainsAction implements Runnable { diff --git a/core/src/main/java/google/registry/tools/server/UpdateUserGroupAction.java b/core/src/main/java/google/registry/tools/server/UpdateUserGroupAction.java index 7f0b1aa701..181ba71a50 100644 --- a/core/src/main/java/google/registry/tools/server/UpdateUserGroupAction.java +++ b/core/src/main/java/google/registry/tools/server/UpdateUserGroupAction.java @@ -20,6 +20,7 @@ import google.registry.groups.GroupsConnection; import google.registry.groups.GroupsConnection.Role; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -27,7 +28,7 @@ /** Action that adds or deletes a console user to/from the group that has IAP permissions. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = UpdateUserGroupAction.PATH, method = POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/tools/server/VerifyOteAction.java b/core/src/main/java/google/registry/tools/server/VerifyOteAction.java index 61cbac4ce1..3827ac255f 100644 --- a/core/src/main/java/google/registry/tools/server/VerifyOteAction.java +++ b/core/src/main/java/google/registry/tools/server/VerifyOteAction.java @@ -21,6 +21,7 @@ import google.registry.model.OteStats; import google.registry.model.OteStats.StatType; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.JsonActionRunner; import google.registry.request.JsonActionRunner.JsonAction; import google.registry.request.auth.Auth; @@ -34,7 +35,7 @@ * OT&E commands that have been run just previously to verification may not be picked up yet. */ @Action( - service = Action.Service.TOOLS, + service = GaeService.TOOLS, path = VerifyOteAction.PATH, method = Action.Method.POST, auth = Auth.AUTH_ADMIN) diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleApiAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleApiAction.java index 7660349f80..f230229d8e 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleApiAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleApiAction.java @@ -41,7 +41,6 @@ import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarPoc; import google.registry.model.registrar.RegistrarPocBase; -import google.registry.request.Action.Service; import google.registry.request.HttpException; import google.registry.security.XsrfTokenManager; import google.registry.ui.server.registrar.ConsoleUiAction; @@ -197,8 +196,7 @@ protected void sendExternalUpdates( // there's an update besides the lastUpdateTime cloudTasksUtils.enqueue( SyncRegistrarsSheetAction.QUEUE, - cloudTasksUtils.createGetTask( - SyncRegistrarsSheetAction.PATH, Service.BACKEND, ImmutableMultimap.of())); + cloudTasksUtils.createTask(SyncRegistrarsSheetAction.class, GET, ImmutableMultimap.of())); } String environment = Ascii.toLowerCase(String.valueOf(RegistryEnvironment.get())); diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleDomainGetAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleDomainGetAction.java index e9d2b08cbf..0ce8c80754 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleDomainGetAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleDomainGetAction.java @@ -24,6 +24,7 @@ import google.registry.model.console.User; import google.registry.model.domain.Domain; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -32,7 +33,7 @@ /** Returns a JSON representation of a domain to the registrar console. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleDomainGetAction.PATH, auth = Auth.AUTH_PUBLIC_LOGGED_IN) diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleDomainListAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleDomainListAction.java index 9717663c45..1d852e4b0e 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleDomainListAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleDomainListAction.java @@ -27,6 +27,7 @@ import google.registry.model.console.User; import google.registry.model.domain.Domain; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -38,7 +39,7 @@ /** Returns a (paginated) list of domains for a particular registrar. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleDomainListAction.PATH, method = Action.Method.GET, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java index 020d3a80ea..45eaaa81b8 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleDumDownloadAction.java @@ -26,6 +26,7 @@ import google.registry.model.console.ConsolePermission; import google.registry.model.console.User; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -39,7 +40,7 @@ import org.joda.time.DateTime; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleDumDownloadAction.PATH, method = {GET}, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleEppPasswordAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleEppPasswordAction.java index 577e7a4e46..a801d186e2 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleEppPasswordAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleEppPasswordAction.java @@ -30,6 +30,7 @@ import google.registry.model.console.User; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -40,7 +41,7 @@ import javax.inject.Inject; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleEppPasswordAction.PATH, method = {POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleOteAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleOteAction.java index b98a4a27df..799fa7c664 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleOteAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleOteAction.java @@ -50,7 +50,7 @@ import javax.inject.Named; @Action( - service = Action.Service.DEFAULT, + service = Action.GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleOteAction.PATH, method = {GET, POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockAction.java index d3c5d6a846..760deab205 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockAction.java @@ -35,6 +35,7 @@ import google.registry.model.registrar.Registrar; import google.registry.model.tld.RegistryLockDao; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.Response; @@ -55,7 +56,7 @@ * action). */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleRegistryLockAction.PATH, method = {GET, POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockVerifyAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockVerifyAction.java index e062b210b5..c71d6b81e1 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockVerifyAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleRegistryLockVerifyAction.java @@ -22,6 +22,7 @@ import google.registry.model.console.User; import google.registry.model.domain.RegistryLock; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -31,7 +32,7 @@ /** Handler for verifying registry lock requests, a form of 2FA. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleRegistryLockVerifyAction.PATH, method = {GET}, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleUpdateRegistrarAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleUpdateRegistrarAction.java index 58ac3d5880..1d25ef6870 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleUpdateRegistrarAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleUpdateRegistrarAction.java @@ -26,6 +26,7 @@ import google.registry.model.console.User; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.Parameter; @@ -37,7 +38,7 @@ import javax.inject.Inject; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleUpdateRegistrarAction.PATH, method = {POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleUserDataAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleUserDataAction.java index 21798f0d55..cb211e00cd 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleUserDataAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleUserDataAction.java @@ -21,6 +21,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.model.console.User; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.auth.Auth; import google.registry.security.XsrfTokenManager; @@ -29,7 +30,7 @@ import org.json.JSONObject; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ConsoleUserDataAction.PATH, method = {GET}, diff --git a/core/src/main/java/google/registry/ui/server/console/RegistrarsAction.java b/core/src/main/java/google/registry/ui/server/console/RegistrarsAction.java index 83aea60643..8541564950 100644 --- a/core/src/main/java/google/registry/ui/server/console/RegistrarsAction.java +++ b/core/src/main/java/google/registry/ui/server/console/RegistrarsAction.java @@ -34,6 +34,7 @@ import google.registry.model.registrar.RegistrarBase.State; import google.registry.model.registrar.RegistrarPoc; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -45,7 +46,7 @@ import javax.inject.Named; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = RegistrarsAction.PATH, method = {GET, POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/settings/ContactAction.java b/core/src/main/java/google/registry/ui/server/console/settings/ContactAction.java index d2603b9496..cf2e9e96b2 100644 --- a/core/src/main/java/google/registry/ui/server/console/settings/ContactAction.java +++ b/core/src/main/java/google/registry/ui/server/console/settings/ContactAction.java @@ -31,6 +31,7 @@ import google.registry.model.registrar.RegistrarPoc; import google.registry.persistence.transaction.QueryComposer.Comparator; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -43,7 +44,7 @@ import javax.inject.Inject; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = ContactAction.PATH, method = {GET, POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/settings/SecurityAction.java b/core/src/main/java/google/registry/ui/server/console/settings/SecurityAction.java index cb53035f97..0f4c9ba481 100644 --- a/core/src/main/java/google/registry/ui/server/console/settings/SecurityAction.java +++ b/core/src/main/java/google/registry/ui/server/console/settings/SecurityAction.java @@ -28,6 +28,7 @@ import google.registry.model.console.User; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -39,7 +40,7 @@ import javax.inject.Inject; @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = SecurityAction.PATH, method = {POST}, diff --git a/core/src/main/java/google/registry/ui/server/console/settings/WhoisRegistrarFieldsAction.java b/core/src/main/java/google/registry/ui/server/console/settings/WhoisRegistrarFieldsAction.java index 64e7742453..a96620268d 100644 --- a/core/src/main/java/google/registry/ui/server/console/settings/WhoisRegistrarFieldsAction.java +++ b/core/src/main/java/google/registry/ui/server/console/settings/WhoisRegistrarFieldsAction.java @@ -25,6 +25,7 @@ import google.registry.model.console.User; import google.registry.model.registrar.Registrar; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.GkeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -43,7 +44,7 @@ * WHOIS/RDAP and don't have any other obvious means of edit. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, gkeService = GkeService.CONSOLE, path = WhoisRegistrarFieldsAction.PATH, method = {POST}, diff --git a/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java b/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java index 4a57bf85c6..69c3f20753 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java @@ -28,6 +28,7 @@ import google.registry.config.RegistryConfig.Config; import google.registry.model.OteAccountBuilder; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; import google.registry.request.HttpException.BadRequestException; import google.registry.request.Parameter; @@ -54,7 +55,7 @@ * Methods), separate this class to 2 Actions. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = ConsoleOteSetupAction.PATH, method = {Method.POST, Method.GET}, auth = Auth.AUTH_PUBLIC_LOGGED_IN) diff --git a/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java b/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java index ff04b995eb..f75cb68027 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java @@ -35,8 +35,8 @@ import google.registry.model.registrar.RegistrarAddress; import google.registry.model.registrar.RegistrarBase.State; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; -import google.registry.request.Action.Service; import google.registry.request.HttpException.BadRequestException; import google.registry.request.Parameter; import google.registry.request.auth.Auth; @@ -66,7 +66,7 @@ * information. - for POST, receives the information and creates the Registrar. */ @Action( - service = Service.DEFAULT, + service = GaeService.DEFAULT, path = ConsoleRegistrarCreatorAction.PATH, method = {Method.POST, Method.GET}, auth = Auth.AUTH_PUBLIC_LOGGED_IN) diff --git a/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java b/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java index 6cda96d2b4..1efcf2a928 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java @@ -32,6 +32,7 @@ import google.registry.model.common.FeatureFlag; import google.registry.model.console.GlobalRole; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.request.auth.AuthenticatedRegistrarAccessor; @@ -48,7 +49,7 @@ /** Action that serves Registrar Console single HTML page (SPA). */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = ConsoleUiAction.PATH, auth = Auth.AUTH_PUBLIC_LOGGED_IN) public final class ConsoleUiAction extends HtmlAction { diff --git a/core/src/main/java/google/registry/ui/server/registrar/OteStatusAction.java b/core/src/main/java/google/registry/ui/server/registrar/OteStatusAction.java index 190c1c06a6..8eaec51b6c 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/OteStatusAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/OteStatusAction.java @@ -28,6 +28,7 @@ import google.registry.model.registrar.Registrar; import google.registry.model.registrar.RegistrarBase.Type; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.JsonActionRunner; import google.registry.request.auth.Auth; import google.registry.request.auth.AuthenticatedRegistrarAccessor; @@ -42,7 +43,7 @@ * preserve history. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = OteStatusAction.PATH, method = Action.Method.POST, auth = Auth.AUTH_PUBLIC_LOGGED_IN) diff --git a/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java b/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java index 48c4efc805..ba5169972f 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java @@ -43,7 +43,7 @@ import google.registry.model.registrar.RegistrarPoc; import google.registry.model.registrar.RegistrarPocBase.Type; import google.registry.request.Action; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.ForbiddenException; import google.registry.request.JsonActionRunner; @@ -74,7 +74,7 @@ * preserve history. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = RegistrarSettingsAction.PATH, method = Action.Method.POST, auth = Auth.AUTH_PUBLIC_LOGGED_IN) @@ -604,8 +604,8 @@ private void sendExternalUpdatesIfNecessary(EmailInfo emailInfo) { // there's an update besides the lastUpdateTime cloudTasksUtils.enqueue( SyncRegistrarsSheetAction.QUEUE, - cloudTasksUtils.createGetTask( - SyncRegistrarsSheetAction.PATH, Service.BACKEND, ImmutableMultimap.of())); + cloudTasksUtils.createTask( + SyncRegistrarsSheetAction.class, Action.Method.GET, ImmutableMultimap.of())); } String environment = Ascii.toLowerCase(String.valueOf(RegistryEnvironment.get())); sendEmailUtils.sendEmail( diff --git a/core/src/main/java/google/registry/ui/server/registrar/RegistryLockGetAction.java b/core/src/main/java/google/registry/ui/server/registrar/RegistryLockGetAction.java index 2c62a2d6f4..90d760d9d4 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/RegistryLockGetAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/RegistryLockGetAction.java @@ -34,6 +34,7 @@ import google.registry.model.registrar.Registrar; import google.registry.model.tld.RegistryLockDao; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; import google.registry.request.Parameter; import google.registry.request.RequestMethod; @@ -54,7 +55,7 @@ * URL, which is why this is distinct from the {@link RegistryLockPostAction}. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = RegistryLockGetAction.PATH, auth = Auth.AUTH_PUBLIC_LOGGED_IN) public final class RegistryLockGetAction implements JsonGetAction { diff --git a/core/src/main/java/google/registry/ui/server/registrar/RegistryLockPostAction.java b/core/src/main/java/google/registry/ui/server/registrar/RegistryLockPostAction.java index 8f34ee8273..8dd6d448b4 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/RegistryLockPostAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/RegistryLockPostAction.java @@ -32,6 +32,7 @@ import google.registry.model.console.User; import google.registry.model.domain.RegistryLock; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Action.Method; import google.registry.request.HttpException.ForbiddenException; import google.registry.request.JsonActionRunner; @@ -60,7 +61,7 @@ * URL, which is why this is distinct from the {@link RegistryLockGetAction}. */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = RegistryLockPostAction.PATH, method = Method.POST, auth = Auth.AUTH_PUBLIC_LOGGED_IN) diff --git a/core/src/main/java/google/registry/ui/server/registrar/RegistryLockVerifyAction.java b/core/src/main/java/google/registry/ui/server/registrar/RegistryLockVerifyAction.java index 866cc8cfb5..d8751442c1 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/RegistryLockVerifyAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/RegistryLockVerifyAction.java @@ -22,6 +22,7 @@ import com.google.template.soy.tofu.SoyTofu; import google.registry.model.domain.RegistryLock; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Parameter; import google.registry.request.auth.Auth; import google.registry.tools.DomainLockUtils; @@ -32,7 +33,7 @@ /** Action that allows for verification of registry lock / unlock requests */ @Action( - service = Action.Service.DEFAULT, + service = GaeService.DEFAULT, path = RegistryLockVerifyAction.PATH, auth = Auth.AUTH_PUBLIC_LOGGED_IN) public final class RegistryLockVerifyAction extends HtmlAction { diff --git a/core/src/main/java/google/registry/whois/WhoisAction.java b/core/src/main/java/google/registry/whois/WhoisAction.java index b5ba2b3ef3..0128cdb073 100644 --- a/core/src/main/java/google/registry/whois/WhoisAction.java +++ b/core/src/main/java/google/registry/whois/WhoisAction.java @@ -22,6 +22,7 @@ import com.google.common.net.MediaType; import google.registry.config.RegistryConfig.Config; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.Response; import google.registry.request.auth.Auth; import google.registry.util.Clock; @@ -47,7 +48,7 @@ * @see WhoisHttpAction * @see RFC 3912: WHOIS Protocol Specification */ -@Action(service = Action.Service.PUBAPI, path = "/_dr/whois", method = POST, auth = Auth.AUTH_ADMIN) +@Action(service = GaeService.PUBAPI, path = "/_dr/whois", method = POST, auth = Auth.AUTH_ADMIN) public class WhoisAction implements Runnable { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); diff --git a/core/src/main/java/google/registry/whois/WhoisHttpAction.java b/core/src/main/java/google/registry/whois/WhoisHttpAction.java index ad20aa1946..8d25366090 100644 --- a/core/src/main/java/google/registry/whois/WhoisHttpAction.java +++ b/core/src/main/java/google/registry/whois/WhoisHttpAction.java @@ -32,6 +32,7 @@ import com.google.common.flogger.FluentLogger; import google.registry.config.RegistryConfig.Config; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.RequestPath; import google.registry.request.Response; import google.registry.request.auth.Auth; @@ -94,7 +95,7 @@ * @see WhoisAction */ @Action( - service = Action.Service.PUBAPI, + service = GaeService.PUBAPI, path = WhoisHttpAction.PATH, isPrefix = true, auth = Auth.AUTH_PUBLIC) diff --git a/core/src/test/java/google/registry/batch/CloudTasksUtilsTest.java b/core/src/test/java/google/registry/batch/CloudTasksUtilsTest.java index f99fcbe271..6980b4a33e 100644 --- a/core/src/test/java/google/registry/batch/CloudTasksUtilsTest.java +++ b/core/src/test/java/google/registry/batch/CloudTasksUtilsTest.java @@ -15,6 +15,8 @@ package google.registry.batch; import static com.google.common.truth.Truth.assertThat; +import static google.registry.request.Action.Method.GET; +import static google.registry.request.Action.Method.POST; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -29,7 +31,10 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.LinkedListMultimap; import google.registry.batch.CloudTasksUtils.SerializableCloudTasksClient; -import google.registry.request.Action.Service; +import google.registry.request.Action; +import google.registry.request.Action.GaeService; +import google.registry.request.Action.GkeService; +import google.registry.request.auth.Auth; import google.registry.testing.CloudTasksHelper.FakeGoogleCredentialsBundle; import google.registry.testing.FakeClock; import google.registry.testing.FakeSleeper; @@ -68,24 +73,13 @@ void beforeEach() { } @Test - void testFailure_createGetTasks_withNegativeDelay() { + void testFailure_createTasks_withNegativeDelay() { IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> - cloudTasksUtils.createGetTaskWithDelay( - "/the/path", Service.BACKEND, params, Duration.standardMinutes(-10))); - assertThat(thrown).hasMessageThat().isEqualTo("Negative duration is not supported."); - } - - @Test - void testFailure_createPostTasks_withNegativeDelay() { - IllegalArgumentException thrown = - assertThrows( - IllegalArgumentException.class, - () -> - cloudTasksUtils.createGetTaskWithDelay( - "/the/path", Service.BACKEND, params, Duration.standardMinutes(-10))); + cloudTasksUtils.createTaskWithDelay( + TheAction.class, GET, params, Duration.standardMinutes(-10))); assertThat(thrown).hasMessageThat().isEqualTo("Negative duration is not supported."); } @@ -93,26 +87,26 @@ void testFailure_createPostTasks_withNegativeDelay() { void testFailure_illegalPath() { assertThrows( IllegalArgumentException.class, - () -> cloudTasksUtils.createPostTask("the/path", Service.BACKEND, params)); + () -> cloudTasksUtils.createTask("the/path", GET, GkeService.BACKEND, params)); assertThrows( IllegalArgumentException.class, - () -> cloudTasksUtils.createPostTask(null, Service.BACKEND, params)); + () -> cloudTasksUtils.createTask(null, GET, GkeService.BACKEND, params)); assertThrows( IllegalArgumentException.class, - () -> cloudTasksUtils.createPostTask("", Service.BACKEND, params)); + () -> cloudTasksUtils.createTask("", GET, GkeService.BACKEND, params)); } @Test void testSuccess_enqueueTask() { - Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params); + Task task = cloudTasksUtils.createTask(TheAction.class, GET, params); cloudTasksUtils.enqueue("test-queue", task); verify(mockClient).enqueue("project", "location", "test-queue", task); } @Test void testSuccess_enqueueTasks_varargs() { - Task task1 = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params); - Task task2 = cloudTasksUtils.createGetTask("/other/path", Service.TOOLS, params); + Task task1 = cloudTasksUtils.createTask(TheAction.class, GET, params); + Task task2 = cloudTasksUtils.createTask(OtherAction.class, GET, params); cloudTasksUtils.enqueue("test-queue", task1, task2); verify(mockClient).enqueue("project", "location", "test-queue", task1); verify(mockClient).enqueue("project", "location", "test-queue", task2); @@ -120,8 +114,8 @@ void testSuccess_enqueueTasks_varargs() { @Test void testSuccess_enqueueTasks_iterable() { - Task task1 = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params); - Task task2 = cloudTasksUtils.createGetTask("/other/path", Service.TOOLS, params); + Task task1 = cloudTasksUtils.createTask(TheAction.class, GET, params); + Task task2 = cloudTasksUtils.createTask(OtherAction.class, GET, params); cloudTasksUtils.enqueue("test-queue", ImmutableList.of(task1, task2)); verify(mockClient).enqueue("project", "location", "test-queue", task1); verify(mockClient).enqueue("project", "location", "test-queue", task2); @@ -129,7 +123,17 @@ void testSuccess_enqueueTasks_iterable() { @Test void testSuccess_createGetTasks() { - Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params); + Task task = cloudTasksUtils.createTask(TheAction.class, GET, params); + assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); + assertThat(task.getHttpRequest().getUrl()) + .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); + verifyOidcToken(task); + assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); + } + + @Test + void testSuccess_createTasks_WithPathAndService_GAE() { + Task task = cloudTasksUtils.createTask("/the/path", GET, GaeService.BACKEND, params); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()) .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); @@ -137,9 +141,26 @@ void testSuccess_createGetTasks() { assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); } + @Test + void testSuccess_createTasks_WithPathAndService_GKE() { + Task task = cloudTasksUtils.createTask("/the/path", GET, GkeService.BACKEND, params); + assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); + assertThat(task.getHttpRequest().getUrl()) + .isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3"); + verifyOidcToken(task); + assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); + } + + @Test + void testFailure_createTasks_notAnAction() { + assertThrows( + IllegalArgumentException.class, + () -> cloudTasksUtils.createTask(NotAnAction.class, GET, params)); + } + @Test void testSuccess_createPostTasks() { - Task task = cloudTasksUtils.createPostTask("/the/path", Service.BACKEND, params); + Task task = cloudTasksUtils.createTask(TheAction.class, POST, params); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type")) @@ -152,7 +173,7 @@ void testSuccess_createPostTasks() { @Test void testSuccess_createGetTasks_withNullParams() { - Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, null); + Task task = cloudTasksUtils.createTask(TheAction.class, GET, null); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); verifyOidcToken(task); @@ -161,7 +182,7 @@ void testSuccess_createGetTasks_withNullParams() { @Test void testSuccess_createPostTasks_withNullParams() { - Task task = cloudTasksUtils.createPostTask("/the/path", Service.BACKEND, null); + Task task = cloudTasksUtils.createTask(TheAction.class, POST, null); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEmpty(); @@ -171,7 +192,7 @@ void testSuccess_createPostTasks_withNullParams() { @Test void testSuccess_createGetTasks_withEmptyParams() { - Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, ImmutableMultimap.of()); + Task task = cloudTasksUtils.createTask(TheAction.class, GET, ImmutableMultimap.of()); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); verifyOidcToken(task); @@ -180,8 +201,7 @@ void testSuccess_createGetTasks_withEmptyParams() { @Test void testSuccess_createPostTasks_withEmptyParams() { - Task task = - cloudTasksUtils.createPostTask("/the/path", Service.BACKEND, ImmutableMultimap.of()); + Task task = cloudTasksUtils.createTask(TheAction.class, POST, ImmutableMultimap.of()); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEmpty(); @@ -191,66 +211,27 @@ void testSuccess_createPostTasks_withEmptyParams() { @SuppressWarnings("ProtoTimestampGetSecondsGetNano") @Test - void testSuccess_createGetTasks_withJitterSeconds() { + void testSuccess_createTasks_withJitterSeconds() { Task task = - cloudTasksUtils.createGetTaskWithJitter( - "/the/path", Service.BACKEND, params, Optional.of(100)); + cloudTasksUtils.createTaskWithJitter(TheAction.class, GET, params, Optional.of(100)); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()) .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); verifyOidcToken(task); - Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds()); - Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis()); - Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(100).getMillis()); - - assertThat(scheduleTime.isBefore(lowerBoundTime)).isFalse(); - assertThat(upperBound.isBefore(scheduleTime)).isFalse(); - } - - @SuppressWarnings("ProtoTimestampGetSecondsGetNano") - @Test - void testSuccess_createPostTasks_withJitterSeconds() { - Task task = - cloudTasksUtils.createPostTaskWithJitter( - "/the/path", Service.BACKEND, params, Optional.of(1)); - assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); - assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); - assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type")) - .isEqualTo("application/x-www-form-urlencoded"); - assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)) - .isEqualTo("key1=val1&key2=val2&key1=val3"); - verifyOidcToken(task); assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0); - Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds()); Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis()); - Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(1).getMillis()); + Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(100).getMillis()); assertThat(scheduleTime.isBefore(lowerBoundTime)).isFalse(); assertThat(upperBound.isBefore(scheduleTime)).isFalse(); } @Test - void testSuccess_createPostTasks_withEmptyJitterSeconds() { - Task task = - cloudTasksUtils.createPostTaskWithJitter( - "/the/path", Service.BACKEND, params, Optional.empty()); - assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); - assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); - assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type")) - .isEqualTo("application/x-www-form-urlencoded"); - assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)) - .isEqualTo("key1=val1&key2=val2&key1=val3"); - verifyOidcToken(task); - assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); - } - - @Test - void testSuccess_createGetTasks_withEmptyJitterSeconds() { + void testSuccess_createTasks_withEmptyJitterSeconds() { Task task = - cloudTasksUtils.createGetTaskWithJitter( - "/the/path", Service.BACKEND, params, Optional.empty()); + cloudTasksUtils.createTaskWithJitter(TheAction.class, GET, params, Optional.empty()); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()) .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); @@ -259,25 +240,8 @@ void testSuccess_createGetTasks_withEmptyJitterSeconds() { } @Test - void testSuccess_createPostTasks_withZeroJitterSeconds() { - Task task = - cloudTasksUtils.createPostTaskWithJitter( - "/the/path", Service.BACKEND, params, Optional.of(0)); - assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); - assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); - assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type")) - .isEqualTo("application/x-www-form-urlencoded"); - assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)) - .isEqualTo("key1=val1&key2=val2&key1=val3"); - verifyOidcToken(task); - assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); - } - - @Test - void testSuccess_createGetTasks_withZeroJitterSeconds() { - Task task = - cloudTasksUtils.createGetTaskWithJitter( - "/the/path", Service.BACKEND, params, Optional.of(0)); + void testSuccess_createTasks_withZeroJitterSeconds() { + Task task = cloudTasksUtils.createTaskWithJitter(TheAction.class, GET, params, Optional.of(0)); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()) .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); @@ -286,10 +250,10 @@ void testSuccess_createGetTasks_withZeroJitterSeconds() { } @Test - void testSuccess_createGetTasks_withDelay() { + void testSuccess_createTasks_withDelay() { Task task = - cloudTasksUtils.createGetTaskWithDelay( - "/the/path", Service.BACKEND, params, Duration.standardMinutes(10)); + cloudTasksUtils.createTaskWithDelay( + TheAction.class, GET, params, Duration.standardMinutes(10)); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()) .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); @@ -299,41 +263,8 @@ void testSuccess_createGetTasks_withDelay() { } @Test - void testSuccess_createPostTasks_withDelay() { - Task task = - cloudTasksUtils.createPostTaskWithDelay( - "/the/path", Service.BACKEND, params, Duration.standardMinutes(10)); - assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); - assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); - assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type")) - .isEqualTo("application/x-www-form-urlencoded"); - assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)) - .isEqualTo("key1=val1&key2=val2&key1=val3"); - verifyOidcToken(task); - assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0); - assertThat(Instant.ofEpochSecond(task.getScheduleTime().getSeconds())) - .isEqualTo(Instant.ofEpochMilli(clock.nowUtc().plusMinutes(10).getMillis())); - } - - @Test - void testSuccess_createPostTasks_withZeroDelay() { - Task task = - cloudTasksUtils.createPostTaskWithDelay( - "/the/path", Service.BACKEND, params, Duration.ZERO); - assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST); - assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path"); - assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type")) - .isEqualTo("application/x-www-form-urlencoded"); - assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)) - .isEqualTo("key1=val1&key2=val2&key1=val3"); - verifyOidcToken(task); - assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); - } - - @Test - void testSuccess_createGetTasks_withZeroDelay() { - Task task = - cloudTasksUtils.createGetTaskWithDelay("/the/path", Service.BACKEND, params, Duration.ZERO); + void testSuccess_createTasks_withZeroDelay() { + Task task = cloudTasksUtils.createTaskWithDelay(TheAction.class, GET, params, Duration.ZERO); assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET); assertThat(task.getHttpRequest().getUrl()) .isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3"); @@ -341,6 +272,36 @@ void testSuccess_createGetTasks_withZeroDelay() { assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0); } + @Action( + service = GaeService.BACKEND, + gkeService = GkeService.BACKEND, + path = "/the/path", + method = {GET}, + auth = Auth.AUTH_ADMIN) + private static class TheAction implements Runnable { + + @Override + public void run() {} + } + + @Action( + service = GaeService.TOOLS, + gkeService = GkeService.BACKEND, + path = "/other/path", + method = {GET}, + auth = Auth.AUTH_ADMIN) + private static class OtherAction implements Runnable { + + @Override + public void run() {} + } + + private static class NotAnAction implements Runnable { + + @Override + public void run() {} + } + private static void verifyOidcToken(Task task) { assertThat(task.getHttpRequest().getOidcToken()) .isEqualTo( diff --git a/core/src/test/java/google/registry/module/backend/BackendRequestComponentTest.java b/core/src/test/java/google/registry/module/backend/BackendRequestComponentTest.java index d33aa1994d..b82ddfe0d9 100644 --- a/core/src/test/java/google/registry/module/backend/BackendRequestComponentTest.java +++ b/core/src/test/java/google/registry/module/backend/BackendRequestComponentTest.java @@ -16,7 +16,7 @@ import static com.google.common.truth.Truth.assertThat; -import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.RouterDisplayHelper; import google.registry.testing.GoldenFileTestHelper; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ void testRoutingMap() { void testRoutingService() { assertThat( RouterDisplayHelper.extractHumanReadableRoutesWithWrongService( - BackendRequestComponent.class, Action.Service.BACKEND)) + BackendRequestComponent.class, GaeService.BACKEND)) .isEmpty(); } } diff --git a/core/src/test/java/google/registry/module/bsa/BsaRequestComponentTest.java b/core/src/test/java/google/registry/module/bsa/BsaRequestComponentTest.java index 849252c57b..996f9e9ef4 100644 --- a/core/src/test/java/google/registry/module/bsa/BsaRequestComponentTest.java +++ b/core/src/test/java/google/registry/module/bsa/BsaRequestComponentTest.java @@ -16,7 +16,7 @@ import static com.google.common.truth.Truth.assertThat; -import google.registry.request.Action.Service; +import google.registry.request.Action.GaeService; import google.registry.request.RouterDisplayHelper; import google.registry.testing.GoldenFileTestHelper; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ void testRoutingMap() { void testRoutingService() { assertThat( RouterDisplayHelper.extractHumanReadableRoutesWithWrongService( - BsaRequestComponent.class, Service.BSA)) + BsaRequestComponent.class, GaeService.BSA)) .isEmpty(); } } diff --git a/core/src/test/java/google/registry/module/frontend/FrontendRequestComponentTest.java b/core/src/test/java/google/registry/module/frontend/FrontendRequestComponentTest.java index c94a77cf60..2d53d7edbf 100644 --- a/core/src/test/java/google/registry/module/frontend/FrontendRequestComponentTest.java +++ b/core/src/test/java/google/registry/module/frontend/FrontendRequestComponentTest.java @@ -16,7 +16,7 @@ import static com.google.common.truth.Truth.assertThat; -import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.RouterDisplayHelper; import google.registry.testing.GoldenFileTestHelper; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ void testRoutingMap() { void testRoutingService() { assertThat( RouterDisplayHelper.extractHumanReadableRoutesWithWrongService( - FrontendRequestComponent.class, Action.Service.DEFAULT)) + FrontendRequestComponent.class, GaeService.DEFAULT)) .isEmpty(); } } diff --git a/core/src/test/java/google/registry/module/pubapi/PubApiRequestComponentTest.java b/core/src/test/java/google/registry/module/pubapi/PubApiRequestComponentTest.java index 9e5b6ef86e..6d4e320291 100644 --- a/core/src/test/java/google/registry/module/pubapi/PubApiRequestComponentTest.java +++ b/core/src/test/java/google/registry/module/pubapi/PubApiRequestComponentTest.java @@ -16,7 +16,7 @@ import static com.google.common.truth.Truth.assertThat; -import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.RouterDisplayHelper; import google.registry.testing.GoldenFileTestHelper; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ void testRoutingMap() { void testRoutingService() { assertThat( RouterDisplayHelper.extractHumanReadableRoutesWithWrongService( - PubApiRequestComponent.class, Action.Service.PUBAPI)) + PubApiRequestComponent.class, GaeService.PUBAPI)) .isEmpty(); } } diff --git a/core/src/test/java/google/registry/module/tools/ToolsRequestComponentTest.java b/core/src/test/java/google/registry/module/tools/ToolsRequestComponentTest.java index 554bf4373e..8c6055c6e5 100644 --- a/core/src/test/java/google/registry/module/tools/ToolsRequestComponentTest.java +++ b/core/src/test/java/google/registry/module/tools/ToolsRequestComponentTest.java @@ -16,7 +16,7 @@ import static com.google.common.truth.Truth.assertThat; -import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.RouterDisplayHelper; import google.registry.testing.GoldenFileTestHelper; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ void testRoutingMap() { void testRoutingService() { assertThat( RouterDisplayHelper.extractHumanReadableRoutesWithWrongService( - ToolsRequestComponent.class, Action.Service.TOOLS)) + ToolsRequestComponent.class, GaeService.TOOLS)) .isEmpty(); } } diff --git a/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java b/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java index 47c2dcb208..588dafdd68 100644 --- a/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java +++ b/core/src/test/java/google/registry/rdap/RdapActionBaseTest.java @@ -30,6 +30,7 @@ import google.registry.rdap.RdapObjectClasses.ReplyPayloadBase; import google.registry.rdap.RdapSearchResults.IncompletenessWarningType; import google.registry.request.Action; +import google.registry.request.Action.GaeService; import google.registry.request.auth.Auth; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; @@ -44,7 +45,7 @@ class RdapActionBaseTest extends RdapActionBaseTestCase new Builder() { @Override diff --git a/core/src/test/java/google/registry/request/RouterTest.java b/core/src/test/java/google/registry/request/RouterTest.java index 6aa1ea2055..57f4b1d40d 100644 --- a/core/src/test/java/google/registry/request/RouterTest.java +++ b/core/src/test/java/google/registry/request/RouterTest.java @@ -18,6 +18,7 @@ import static google.registry.request.auth.Auth.AUTH_ADMIN; import static org.junit.jupiter.api.Assertions.assertThrows; +import google.registry.request.Action.GaeService; import java.util.Optional; import java.util.concurrent.Callable; import java.util.function.Function; @@ -41,7 +42,7 @@ void testRoute_noRoutes_throws() { //////////////////////////////////////////////////////////////////////////////////////////////// - @Action(service = Action.Service.DEFAULT, path = "/sloth", auth = AUTH_ADMIN) + @Action(service = GaeService.DEFAULT, path = "/sloth", auth = AUTH_ADMIN) public static final class SlothTask implements Runnable { @Override public void run() {} @@ -71,7 +72,7 @@ void testRoute_pathIsAPrefix_notAllowedByDefault() { //////////////////////////////////////////////////////////////////////////////////////////////// - @Action(service = Action.Service.DEFAULT, path = "/prefix", isPrefix = true, auth = AUTH_ADMIN) + @Action(service = GaeService.DEFAULT, path = "/prefix", isPrefix = true, auth = AUTH_ADMIN) public static final class PrefixTask implements Runnable { @Override public void run() {} @@ -97,11 +98,7 @@ void testRoute_prefixDoesNotMatch_returnsEmpty() { //////////////////////////////////////////////////////////////////////////////////////////////// - @Action( - service = Action.Service.DEFAULT, - path = "/prefix/long", - isPrefix = true, - auth = AUTH_ADMIN) + @Action(service = GaeService.DEFAULT, path = "/prefix/long", isPrefix = true, auth = AUTH_ADMIN) public static final class LongTask implements Runnable { @Override public void run() {} @@ -153,13 +150,13 @@ void testRoute_methodsInComponentAreIgnored_throws() { //////////////////////////////////////////////////////////////////////////////////////////////// - @Action(service = Action.Service.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN) + @Action(service = GaeService.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN) public static final class DuplicateTask1 implements Runnable { @Override public void run() {} } - @Action(service = Action.Service.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN) + @Action(service = GaeService.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN) public static final class DuplicateTask2 implements Runnable { @Override public void run() {} diff --git a/core/src/test/java/google/registry/tools/CurlCommandTest.java b/core/src/test/java/google/registry/tools/CurlCommandTest.java index d32e34665f..d1593c0f48 100644 --- a/core/src/test/java/google/registry/tools/CurlCommandTest.java +++ b/core/src/test/java/google/registry/tools/CurlCommandTest.java @@ -15,10 +15,10 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; -import static google.registry.request.Action.Service.BACKEND; -import static google.registry.request.Action.Service.DEFAULT; -import static google.registry.request.Action.Service.PUBAPI; -import static google.registry.request.Action.Service.TOOLS; +import static google.registry.request.Action.GaeService.BACKEND; +import static google.registry.request.Action.GaeService.DEFAULT; +import static google.registry.request.Action.GaeService.PUBAPI; +import static google.registry.request.Action.GaeService.TOOLS; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; diff --git a/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java b/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java index d73130b0ef..2e655ea682 100644 --- a/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java +++ b/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java @@ -84,9 +84,8 @@ void beforeEach() throws Exception { .thenReturn(new ByteArrayInputStream("MyContent".getBytes(UTF_8))); when(lowLevelHttpResponse.getStatusCode()).thenReturn(200); - connection = new ServiceConnection(); httpTransport = new TestHttpTransport(); - connection.requestFactory = httpTransport.createRequestFactory(); + connection = new ServiceConnection(false, httpTransport.createRequestFactory()); } @Test diff --git a/core/src/test/java/google/registry/tools/ServiceConnectionTest.java b/core/src/test/java/google/registry/tools/ServiceConnectionTest.java index c33cd40f63..d04f2a7c04 100644 --- a/core/src/test/java/google/registry/tools/ServiceConnectionTest.java +++ b/core/src/test/java/google/registry/tools/ServiceConnectionTest.java @@ -15,7 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; -import static google.registry.request.Action.Service.DEFAULT; +import static google.registry.request.Action.GaeService.DEFAULT; import org.junit.jupiter.api.Test; @@ -24,14 +24,14 @@ public class ServiceConnectionTest { @Test void testServerUrl_notCanary() { - ServiceConnection connection = new ServiceConnection().withService(DEFAULT, false); + ServiceConnection connection = new ServiceConnection(false, null).withService(DEFAULT, false); String serverUrl = connection.getServer().toString(); assertThat(serverUrl).isEqualTo("https://default.example.com"); // See default-config.yaml } @Test void testServerUrl_canary() { - ServiceConnection connection = new ServiceConnection().withService(DEFAULT, true); + ServiceConnection connection = new ServiceConnection(false, null).withService(DEFAULT, true); String serverUrl = connection.getServer().toString(); assertThat(serverUrl).isEqualTo("https://nomulus-dot-default.example.com"); }