From 0109c961c2737b9a0bc8ad519c72a89dfb52fc06 Mon Sep 17 00:00:00 2001 From: Nitish-Kulkarni3 Date: Thu, 23 Oct 2025 07:29:04 +0530 Subject: [PATCH] chore: support for clone smtp user credentials Signed-off-by: nitish --- .secrets.baseline | 4 +- README.md | 17 ++++ .../v1/EventNotifications.java | 3 + .../v1/model/CreateSmtpUserOptions.java | 26 ++++++ .../v1/model/SMTPUserResponse.java | 2 +- .../v1/EventNotificationsIT.java | 81 +++++++++++++------ .../v1/EventNotificationsTest.java | 6 +- .../v1/model/CreateSmtpUserOptionsTest.java | 2 + .../v1/EventNotificationsExamples.java | 29 +++++++ 9 files changed, 141 insertions(+), 29 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index d4a8d8e..48ca923 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "^.secrets.baseline$", "lines": null }, - "generated_at": "2025-09-25T01:16:58Z", + "generated_at": "2025-10-28T04:20:32Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -142,7 +142,7 @@ } ] }, - "version": "0.13.1+ibm.62.dss", + "version": "0.13.1+ibm.64.dss", "word_list": { "file": null, "hash": null diff --git a/README.md b/README.md index 4afb856..5245136 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ SDK Methods to consume - [SMTP Configurations](#SMTPConfigurations) - [Create SMTP Configuration](#create-smtp-configuration) - [Create SMTP User](#create-smtp-user) + - [Clone SMTP User](#clone-smtp-user) - [Get SMTP Configuration](#get-smtp-configuration) - [Get SMTP User](#get-smtp-user) - [Get SMTP Allowed Ips](#get-smtp-allowed-ips) @@ -1193,6 +1194,21 @@ SMTPUserResponse responseObj = response.getResult(); ``` +### Clone SMTP User + +```java + +CreateSmtpUserOptions createSmtpUserOptionsModel = new CreateSmtpUserOptions.Builder() + .instanceId() + .id() + .usernameToClone() + .build(); + +Response response = eventNotificationsService.createSmtpUser(createSmtpUserOptionsModel).execute(); +SMTPUserResponse responseObj = response.getResult(); + +``` + ### Get SMTP Configuration ```java @@ -1513,6 +1529,7 @@ Find `event_notifications.env.hide` in the repo and rename it to `event_notifica - `EVENT_NOTIFICATIONS_CODE_ENGINE_JOB_TEMPLATE_BODY` - base 64 encoded json body for Code Engine Job - `EVENT_NOTIFICATIONS_APP_CONFIG_CRN` - CRN of App Configuration instance - `EVENT_NOTIFICATIONS_APP_CONFIG_TEMPLATE_BODY` - base 64 encoded json body for App Configuration +- `EVENT_NOTIFICATIONS_SMTP_USER_TO_CLONE` - SMTP username to be cloned ## Questions diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java index ce22260..8f36d98 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java @@ -1500,6 +1500,9 @@ public ServiceCall createSmtpUser(CreateSmtpUserOptions create builder.header(header.getKey(), header.getValue()); } builder.header("Accept", "application/json"); + if (createSmtpUserOptions.usernameToClone() != null) { + builder.query("username_to_clone", String.valueOf(createSmtpUserOptions.usernameToClone())); + } final JsonObject contentJson = new JsonObject(); if (createSmtpUserOptions.description() != null) { contentJson.addProperty("description", createSmtpUserOptions.description()); diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptions.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptions.java index f9c7067..a9011ee 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptions.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptions.java @@ -22,6 +22,7 @@ public class CreateSmtpUserOptions extends GenericModel { protected String instanceId; protected String id; protected String description; + protected String usernameToClone; /** * Builder. @@ -30,6 +31,7 @@ public static class Builder { private String instanceId; private String id; private String description; + private String usernameToClone; /** * Instantiates a new Builder from an existing CreateSmtpUserOptions instance. @@ -40,6 +42,7 @@ private Builder(CreateSmtpUserOptions createSmtpUserOptions) { this.instanceId = createSmtpUserOptions.instanceId; this.id = createSmtpUserOptions.id; this.description = createSmtpUserOptions.description; + this.usernameToClone = createSmtpUserOptions.usernameToClone; } /** @@ -100,6 +103,17 @@ public Builder description(String description) { this.description = description; return this; } + + /** + * Set the usernameToClone. + * + * @param usernameToClone the usernameToClone + * @return the CreateSmtpUserOptions builder + */ + public Builder usernameToClone(String usernameToClone) { + this.usernameToClone = usernameToClone; + return this; + } } protected CreateSmtpUserOptions() { } @@ -112,6 +126,7 @@ protected CreateSmtpUserOptions(Builder builder) { instanceId = builder.instanceId; id = builder.id; description = builder.description; + usernameToClone = builder.usernameToClone; } /** @@ -155,5 +170,16 @@ public String id() { public String description() { return description; } + + /** + * Gets the usernameToClone. + * + * provide name of the user to clone. + * + * @return the usernameToClone + */ + public String usernameToClone() { + return usernameToClone; + } } diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/SMTPUserResponse.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/SMTPUserResponse.java index e1e9b53..4b106da 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/SMTPUserResponse.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/SMTPUserResponse.java @@ -92,7 +92,7 @@ public String getUsername() { /** * Gets the password. * - * password. + * Password for SMTP user; Cloned SMTP user response do not include a password. * * @return the password */ diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java index 2cd45ff..c72fae0 100644 --- a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java @@ -134,7 +134,9 @@ public class EventNotificationsIT extends SdkIntegrationTestBase { public static String cosIntegrationID = ""; public static String codeEngineProjectCRN = ""; public static String smtpConfigID = ""; + public static String smtpUserToClone = ""; public static String smtpUserID = ""; + public static String smtpUserID2 = ""; public static String notificationID = ""; public static String slackDMToken = ""; public static String slackChannelID = ""; @@ -209,6 +211,8 @@ public void constructService() { eventStreamsTopic = config.get("EVENT_STREAMS_TOPIC"); appConfigCRN = config.get("APP_CONFIG_CRN"); appConfigTemplateBody = config.get("APP_CONFIG_TEMPLATE_BODY"); + smtpUserToClone = config.get("SMTP_USER_TO_CLONE"); + service.enableRetries(4, 30); @@ -3953,8 +3957,36 @@ public void test1YCreateSMTPUser() throws Exception { e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); } } + + @Test + public void test1ZCloneSMTPUser() throws Exception { + try { + // begin-clone-smtp-user + String description = "description for SMTP user clone"; + CreateSmtpUserOptions createSmtpUserOptionsModel = new CreateSmtpUserOptions.Builder() + .instanceId(instanceId) + .id(smtpConfigID) + .usernameToClone(smtpUserToClone) + .build(); + + Response response = service.createSmtpUser(createSmtpUserOptionsModel).execute(); + assertNotNull(response); + assertEquals(response.getStatusCode(), 201); + SMTPUserResponse responseObj = response.getResult(); + assertEquals(responseObj.getDescription(), description); + assertEquals(responseObj.getSmtpConfigId(), smtpConfigID); + assertNotNull(responseObj.getId()); + smtpUserID2 = responseObj.getId(); + assertNotNull(responseObj.getUsername()); + // end-clone-smtp-user + } catch (ServiceResponseException e) { + fail(String.format("Service returned status code %s: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); + } + } + @Test - public void test1ZListSmtpConfigurations() throws Exception { + public void test2AListSmtpConfigurations() throws Exception { try { // begin-list-smtp-configurations boolean moreResults = true; @@ -3986,7 +4018,7 @@ public void test1ZListSmtpConfigurations() throws Exception { } @Test - public void test2AListSmtpUsers() throws Exception { + public void test2BListSmtpUsers() throws Exception { try { // begin-list-smtp-users boolean moreResults = true; @@ -4019,7 +4051,7 @@ public void test2AListSmtpUsers() throws Exception { } @Test - public void test2BGetSmtpConfiguration() throws Exception { + public void test2CGetSmtpConfiguration() throws Exception { try { // begin-get-smtp-configuration GetSmtpConfigurationOptions getSmtpConfigurationOptionsModel = new GetSmtpConfigurationOptions.Builder() @@ -4041,7 +4073,7 @@ public void test2BGetSmtpConfiguration() throws Exception { } } @Test - public void test2CGetSmtpAllowedIps() throws Exception { + public void test2DGetSmtpAllowedIps() throws Exception { try { // begin-get-smtp-allowed-ips GetSmtpAllowedIpsOptions getSmtpAllowedIpsOptionsModel = new GetSmtpAllowedIpsOptions.Builder() @@ -4060,7 +4092,7 @@ public void test2CGetSmtpAllowedIps() throws Exception { } } @Test - public void test2DGetSmtpUser() throws Exception { + public void test2FGetSmtpUser() throws Exception { try { // begin-get-smtp-user GetSmtpUserOptions getSmtpUserOptionsModel = new GetSmtpUserOptions.Builder() @@ -4080,7 +4112,7 @@ public void test2DGetSmtpUser() throws Exception { } } @Test - public void test2EUpdateSmtpConfiguration() throws Exception { + public void test2GUpdateSmtpConfiguration() throws Exception { try { // begin-update-smtp-configuration String name = "SMTP Configuration update"; @@ -4108,7 +4140,7 @@ public void test2EUpdateSmtpConfiguration() throws Exception { } @Test - public void test2FUpdateSmtpUser() throws Exception { + public void test2HUpdateSmtpUser() throws Exception { try { // begin-update-smtp-user String description = "description for SMTP user update"; @@ -4133,7 +4165,7 @@ public void test2FUpdateSmtpUser() throws Exception { } @Test - public void test2GSendNotifications() throws Exception { + public void test2ISendNotifications() throws Exception { try { // begin-send_notifications String notificationDevices = "{\"platforms\":[\"push_ios\",\"push_android\",\"push_chrome\",\"push_firefox\", \"push_huawei\"]}"; @@ -4193,7 +4225,7 @@ public void test2GSendNotifications() throws Exception { } } @Test - public void test2HTestDestination() { + public void test2JTestDestination() { try { List destinations = new ArrayList<>(); destinations.add(destinationId4); @@ -4221,7 +4253,7 @@ public void test2HTestDestination() { } @Test - public void test2ITestWebhookDestination() { + public void test2KTestWebhookDestination() { try { TestDestinationOptions testDestinationOptionsModel = new TestDestinationOptions.Builder() @@ -4251,7 +4283,7 @@ public void test2ITestWebhookDestination() { } @Test - public void test2JTestMetrics(){ + public void test2LTestMetrics(){ try{ Instant instant = Instant.now(); @@ -4283,7 +4315,7 @@ public void test2JTestMetrics(){ } @Test - public void test2KTestListPredefinedTemplates(){ + public void test2MTestListPredefinedTemplates(){ try{ ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() @@ -4307,7 +4339,7 @@ public void test2KTestListPredefinedTemplates(){ } @Test - public void test2LTestGetPredefinedTemplate(){ + public void test2NTestGetPredefinedTemplate(){ try{ GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() @@ -4329,7 +4361,7 @@ public void test2LTestGetPredefinedTemplate(){ } @Test - public void test2MDeleteSubscription() throws Exception { + public void test2ODeleteSubscription() throws Exception { try { List subscriptions = new ArrayList<>(); @@ -4385,7 +4417,7 @@ public void test2MDeleteSubscription() throws Exception { } @Test - public void test2NDeleteTopic() throws Exception { + public void test2PDeleteTopic() throws Exception { try { List topics = new ArrayList<>(); @@ -4424,7 +4456,7 @@ public void test2NDeleteTopic() throws Exception { } @Test - public void test2ODeleteDestination() throws Exception { + public void test2QDeleteDestination() throws Exception { try { List destinations = new ArrayList<>(); destinations.add(destinationId); @@ -4477,7 +4509,7 @@ public void test2ODeleteDestination() throws Exception { } @Test - public void test2PDeleteSource() throws Exception { + public void test2RDeleteSource() throws Exception { try { DeleteSourceOptions deleteSourceOptions = new DeleteSourceOptions.Builder() .instanceId(instanceId) @@ -4507,7 +4539,7 @@ public void test2PDeleteSource() throws Exception { } @Test - public void test2QCreateIntegration() throws Exception { + public void test2SCreateIntegration() throws Exception { try { IntegrationCreateMetadata metadata = new IntegrationCreateMetadata.Builder() .endpoint(cosEndPoint) @@ -4535,7 +4567,7 @@ public void test2QCreateIntegration() throws Exception { } @Test - public void test2RListIntegrations() throws Exception { + public void test2TListIntegrations() throws Exception { try { int limit = 1; int offset = 0; @@ -4562,7 +4594,7 @@ public void test2RListIntegrations() throws Exception { } @Test - public void test2SGetIntegration() throws Exception { + public void test2UGetIntegration() throws Exception { try { GetIntegrationOptions integrationsOptions = new GetIntegrationOptions.Builder() .instanceId(instanceId) @@ -4582,7 +4614,7 @@ public void test2SGetIntegration() throws Exception { } @Test - public void test2TUpdateIntegration() throws Exception { + public void test2VUpdateIntegration() throws Exception { try { IntegrationMetadata metadata = new IntegrationMetadata.Builder() .endpoint(cosEndPoint) @@ -4610,7 +4642,7 @@ public void test2TUpdateIntegration() throws Exception { } @Test - public void test2UDeleteTemplate() throws Exception { + public void test2WDeleteTemplate() throws Exception { try { List templates = new ArrayList<>(); templates.add(templateInvitationID); @@ -4641,10 +4673,11 @@ public void test2UDeleteTemplate() throws Exception { } } @Test - public void test2VDeleteSMTPUser() throws Exception { + public void test2XDeleteSMTPUser() throws Exception { try { List users = new ArrayList<>(); users.add(smtpUserID); + users.add(smtpUserID2); for (String user : users) { DeleteSmtpUserOptions deleteSmtpUserOptionsModel = new DeleteSmtpUserOptions.Builder() @@ -4663,7 +4696,7 @@ public void test2VDeleteSMTPUser() throws Exception { } } @Test - public void test2WDeleteSMTPConfiguration() throws Exception { + public void test2YDeleteSMTPConfiguration() throws Exception { try { List smtpConfigIDs = new ArrayList<>(); smtpConfigIDs.add(smtpConfigID); diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java index 288d94e..76f0bcb 100644 --- a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java @@ -3334,6 +3334,7 @@ public void testCreateSmtpUserWOptions() throws Throwable { .instanceId("testString") .id("testString") .description("testString") + .usernameToClone("testString") .build(); // Invoke createSmtpUser() with a valid options model and verify the result @@ -3349,9 +3350,10 @@ public void testCreateSmtpUserWOptions() throws Throwable { // Verify request path String parsedPath = TestUtilities.parseReqPath(request); assertEquals(parsedPath, createSmtpUserPath); - // Verify that there is no query string + // Verify query params Map query = TestUtilities.parseQueryString(request); - assertNull(query); + assertNotNull(query); + assertEquals(query.get("username_to_clone"), "testString"); } // Test the createSmtpUser operation with and without retries enabled diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptionsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptionsTest.java index 83abe7c..d1052d1 100644 --- a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptionsTest.java +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/CreateSmtpUserOptionsTest.java @@ -35,10 +35,12 @@ public void testCreateSmtpUserOptions() throws Throwable { .instanceId("testString") .id("testString") .description("testString") + .usernameToClone("testString") .build(); assertEquals(createSmtpUserOptionsModel.instanceId(), "testString"); assertEquals(createSmtpUserOptionsModel.id(), "testString"); assertEquals(createSmtpUserOptionsModel.description(), "testString"); + assertEquals(createSmtpUserOptionsModel.usernameToClone(), "testString"); } @Test(expectedExceptions = IllegalArgumentException.class) diff --git a/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java b/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java index 975e0d5..6d44d70 100644 --- a/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java +++ b/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java @@ -110,6 +110,8 @@ protected EventNotificationsExamples() { } public static String cosInstanceCRN = ""; public static String codeEngineProjectCRN = ""; public static String smtpConfigID = ""; + public static String smtpUserToClone = ""; + public static String smtpUserID2 = ""; public static String smtpUserID = ""; public static String notificationID = ""; public static String slackDMToken = ""; @@ -188,6 +190,7 @@ public static void main(String[] args) throws Exception { eventStreamsTopic = config.get("EVENT_STREAMS_TOPIC"); codeEngineApplicationTemplateBody = config.get("CODE_ENGINE_APP_TEMPLATE_BODY"); codeEngineJobTemplateBody = config.get("CODE_ENGINE_JOB_TEMPLATE_BODY"); + smtpUserToClone = config.get("SMTP_USER_TO_CLONE"); try { System.out.println("createSources() result:"); @@ -2621,6 +2624,23 @@ public static void main(String[] args) throws Exception { e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); } + try { + // begin-clone-smtp-user + CreateSmtpUserOptions createSmtpUserOptionsModel = new CreateSmtpUserOptions.Builder() + .instanceId(instanceId) + .id(smtpConfigID) + .usernameToClone(smtpUserToClone) + .build(); + + Response response = eventNotificationsService.createSmtpUser(createSmtpUserOptionsModel).execute(); + SMTPUserResponse responseObj = response.getResult(); + smtpUserID2 = responseObj.getId(); + // end-clone-smtp-user + } catch (ServiceResponseException e) { + logger.error(String.format("Service returned status code %s: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); + } + try { boolean moreResults = true; int limit = 1; @@ -2854,6 +2874,15 @@ public static void main(String[] args) throws Exception { Response response = eventNotificationsService.deleteSmtpUser(deleteSmtpUserOptionsModel).execute(); System.out.println(response); // end-delete_smtp_user + + DeleteSmtpUserOptions deleteSmtpUserOptionsModelClone = new DeleteSmtpUserOptions.Builder() + .instanceId(instanceId) + .id(smtpConfigID) + .userId(smtpUserID2) + .build(); + + Response responseClone = eventNotificationsService.deleteSmtpUser(deleteSmtpUserOptionsModelClone).execute(); + System.out.println(responseClone); } catch (ServiceResponseException e) { logger.error(String.format("Service returned status code %s: %s%nError details: %s", e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);