diff --git a/core/src/main/java/google/registry/batch/BatchModule.java b/core/src/main/java/google/registry/batch/BatchModule.java index 07f77bb7158..8eb99b00c0f 100644 --- a/core/src/main/java/google/registry/batch/BatchModule.java +++ b/core/src/main/java/google/registry/batch/BatchModule.java @@ -53,18 +53,6 @@ public class BatchModule { static final int DEFAULT_MAX_QPS = 10; - @Provides - @Parameter("replyTo") - static String provideReplyTo(HttpServletRequest req) { - return extractRequiredParameter(req, "replyTo"); - } - - @Provides - @Parameter("receiver") - static String provideReceiver(HttpServletRequest req) { - return extractRequiredParameter(req, "receiver"); - } - @Provides @Parameter("jobName") static Optional provideJobName(HttpServletRequest req) { diff --git a/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java b/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java deleted file mode 100644 index 7ea73872328..00000000000 --- a/core/src/main/java/google/registry/batch/CannedScriptExecutionAction.java +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2022 The Nomulus Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package google.registry.batch; - -import static google.registry.request.Action.Method.GET; -import static google.registry.request.Action.Method.POST; - -import com.google.api.services.gmail.Gmail; -import com.google.common.collect.ImmutableList; -import com.google.common.flogger.FluentLogger; -import com.google.common.net.MediaType; -import dagger.Lazy; -import google.registry.config.RegistryConfig.Config; -import google.registry.groups.GmailClient; -import google.registry.request.Action; -import google.registry.request.Parameter; -import google.registry.request.Response; -import google.registry.request.auth.Auth; -import google.registry.util.EmailMessage; -import google.registry.util.Retrier; -import jakarta.inject.Inject; -import jakarta.mail.internet.AddressException; -import jakarta.mail.internet.InternetAddress; -import java.util.Optional; - -/** - * Action that executes a canned script specified by the caller. - * - *

This class provides a hook for invoking hard-coded methods. The main use case is to verify in - * Sandbox and Production environments new features that depend on environment-specific - * configurations. - * - *

This action can be invoked using the Nomulus CLI command: {@code nomulus -e ${env} curl - * --service BACKEND -X POST -d 'sender=sender@example.com' -d 'receiver=receiver@example.com' -u - * '/_dr/task/executeCannedScript'} - */ -@Action( - service = Action.Service.BACKEND, - path = "/_dr/task/executeCannedScript", - method = {POST, GET}, - automaticallyPrintOk = true, - auth = Auth.AUTH_ADMIN) -public class CannedScriptExecutionAction implements Runnable { - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - - @Inject Lazy gmail; - @Inject Retrier retrier; - - @Inject - @Config("isEmailSendingEnabled") - boolean isEmailSendingEnabled; - - @Inject Response response; - - @Inject - @Parameter("replyTo") - String replyTo; - - @Inject - @Parameter("receiver") - String receiver; - - @Config("invoiceReplyToEmailAddress") - Optional replyToEmailAddressFromConfig; - - @Inject - CannedScriptExecutionAction() {} - - @Override - public void run() { - // For b/510340944, validating a new G Workspace user can send email. Code below can be - // removed or changed afterward. - try { - logger.atInfo().log("Sending email to %s with replyTo %s", receiver, replyTo); - GmailClient gmailClient = - new GmailClient(gmail, retrier, isEmailSendingEnabled, new InternetAddress(replyTo)); - gmailClient.sendEmail( - EmailMessage.newBuilder() - .addRecipient(new InternetAddress(receiver)) - .setSubject(String.format("Email with manually set replyTo header %s", replyTo)) - .setBody("See subject") - .build()); - - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - - gmailClient.sendEmail( - EmailMessage.newBuilder() - .setSubject( - String.format( - "Email with injected replyTo header %s", replyToEmailAddressFromConfig)) - .setBody("See header") - .setRecipients(ImmutableList.of(new InternetAddress(receiver))) - .setReplyToEmailAddress(replyToEmailAddressFromConfig) - .setContentType(MediaType.HTML_UTF_8) - .build()); - response.setPayload("Emails sent successfully."); - } catch (AddressException e) { - logger.atWarning().withCause(e).log( - "Invalid email address: sender=%s, receiver=%s", replyTo, receiver); - response.setStatus(400); - response.setPayload("Invalid email address provided."); - } catch (Exception e) { - logger.atSevere().withCause(e).log("Failed to send email"); - throw new RuntimeException(e); - } - } -} diff --git a/core/src/main/java/google/registry/groups/GmailClient.java b/core/src/main/java/google/registry/groups/GmailClient.java index d66ec18c7e1..08895030798 100644 --- a/core/src/main/java/google/registry/groups/GmailClient.java +++ b/core/src/main/java/google/registry/groups/GmailClient.java @@ -78,20 +78,6 @@ public final class GmailClient { } } - // TODO(b/510340944): Remove this experiment method - public GmailClient( - Lazy gmail, - Retrier retrier, - @Config("isEmailSendingEnabled") boolean isEmailSendingEnabled, - @Config("replyToEmailAddress") InternetAddress replyToEmailAddress) { - - this.gmail = gmail; - this.retrier = retrier; - this.isEmailSendingEnabled = isEmailSendingEnabled; - this.replyToEmailAddress = replyToEmailAddress; - this.outgoingEmailAddressWithUsername = null; - } - /** * Sends {@code emailMessage} using {@link Gmail}. */ @@ -131,9 +117,7 @@ MimeMessage toMimeMessage(EmailMessage emailMessage) { try { MimeMessage msg = new MimeMessage(Session.getDefaultInstance(new Properties(), /* authenticator= */ null)); - if (this.outgoingEmailAddressWithUsername != null) { - msg.setFrom(this.outgoingEmailAddressWithUsername); - } + msg.setFrom(this.outgoingEmailAddressWithUsername); msg.setReplyTo( new InternetAddress[] {emailMessage.replyToEmailAddress().orElse(replyToEmailAddress)}); msg.addRecipients( diff --git a/core/src/main/java/google/registry/module/RequestComponent.java b/core/src/main/java/google/registry/module/RequestComponent.java index 7aabe46919b..bf63ea0169e 100644 --- a/core/src/main/java/google/registry/module/RequestComponent.java +++ b/core/src/main/java/google/registry/module/RequestComponent.java @@ -18,7 +18,6 @@ import dagger.Subcomponent; import google.registry.batch.BatchModule; import google.registry.batch.BulkDomainTransferAction; -import google.registry.batch.CannedScriptExecutionAction; import google.registry.batch.DeleteExpiredDomainsAction; import google.registry.batch.DeleteLoadTestDataAction; import google.registry.batch.DeleteProberDataAction; @@ -179,8 +178,6 @@ public interface RequestComponent { BulkDomainTransferAction bulkDomainTransferAction(); - CannedScriptExecutionAction cannedScriptExecutionAction(); - CheckApiAction checkApiAction(); ConsoleBulkDomainAction consoleBulkDomainAction(); diff --git a/core/src/test/resources/google/registry/module/routing.txt b/core/src/test/resources/google/registry/module/routing.txt index 59d674bae93..2980f9766a5 100644 --- a/core/src/test/resources/google/registry/module/routing.txt +++ b/core/src/test/resources/google/registry/module/routing.txt @@ -25,7 +25,6 @@ BACKEND /_dr/task/deleteLoadTestData DeleteLoadTestDataAc BACKEND /_dr/task/deleteProberData DeleteProberDataAction POST n APP ADMIN BACKEND /_dr/task/dnsRefresh RefreshDnsAction GET y APP ADMIN BACKEND /_dr/task/domainWatcher DomainWatcherAction POST n APP ADMIN -BACKEND /_dr/task/executeCannedScript CannedScriptExecutionAction POST,GET y APP ADMIN BACKEND /_dr/task/expandBillingRecurrences ExpandBillingRecurrencesAction GET n APP ADMIN BACKEND /_dr/task/exportDomainLists ExportDomainListsAction POST n APP ADMIN BACKEND /_dr/task/exportDropList ExportDropListAction POST n APP ADMIN