Skip to content

Commit 612f79e

Browse files
authored
feat: support for clone smtp user credentials (#83)
Signed-off-by: nitish <[email protected]>
1 parent 87a82f4 commit 612f79e

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed

.secrets.baseline

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "package-lock.json|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-09-25T01:54:39Z",
6+
"generated_at": "2025-10-28T09:15:04Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -126,15 +126,15 @@
126126
"hashed_secret": "d4c3d66fd0c38547a3c7a4c6bdc29c36911bc030",
127127
"is_secret": false,
128128
"is_verified": false,
129-
"line_number": 1658,
129+
"line_number": 1661,
130130
"type": "Secret Keyword",
131131
"verified_result": null
132132
},
133133
{
134134
"hashed_secret": "3235b7f8d626cde63611d2e9ec43473f4e844c67",
135135
"is_secret": false,
136136
"is_verified": false,
137-
"line_number": 2967,
137+
"line_number": 2970,
138138
"type": "Base64 High Entropy String",
139139
"verified_result": null
140140
}
@@ -144,21 +144,21 @@
144144
"hashed_secret": "0cc20f91828bed53ddb6294968b7f9abd631a3ba",
145145
"is_secret": false,
146146
"is_verified": false,
147-
"line_number": 1598,
147+
"line_number": 1601,
148148
"type": "Secret Keyword",
149149
"verified_result": null
150150
},
151151
{
152152
"hashed_secret": "3235b7f8d626cde63611d2e9ec43473f4e844c67",
153153
"is_secret": false,
154154
"is_verified": false,
155-
"line_number": 3332,
155+
"line_number": 3335,
156156
"type": "Base64 High Entropy String",
157157
"verified_result": null
158158
}
159159
]
160160
},
161-
"version": "0.13.1+ibm.62.dss",
161+
"version": "0.13.1+ibm.64.dss",
162162
"word_list": {
163163
"file": null,
164164
"hash": null

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,19 @@ const res = await eventNotificationsService.createSmtpUser(createSmtpUserParams)
13141314

13151315
```
13161316
1317+
### Clone SMTP User
1318+
1319+
```js
1320+
const cloneSmtpUserParams = {
1321+
instanceId : <instance-id>,
1322+
id: <smtp-Config-id>,
1323+
usernameToClone: <smtp-user-to-clone>,
1324+
};
1325+
1326+
const res = await eventNotificationsService.createSmtpUser(cloneSmtpUserParams);
1327+
1328+
```
1329+
13171330
### Get SMTP Configuration
13181331
13191332
```js
@@ -1675,6 +1688,7 @@ Find [event_notifications_v1.env.hide](https://github.com/IBM/event-notification
16751688
- `EVENT_NOTIFICATIONS_CODE_ENGINE_JOB_TEMPLATE_BODY` - base 64 encoded json body for Code Engine Job
16761689
- `EVENT_NOTIFICATIONS_APP_CONFIG_CRN` - CRN of App Configuration instance
16771690
- `EVENT_NOTIFICATIONS_APP_CONFIG_TEMPLATE_BODY` - base 64 encoded json body for App Configuration
1691+
- `EVENT_NOTIFICATIONS_SMTP_USER_TO_CLONE` - SMTP username to be cloned
16781692
16791693
## Questions
16801694

event-notifications/v1.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,6 +2725,7 @@ class EventNotificationsV1 extends BaseService {
27252725
* @param {string} params.instanceId - Unique identifier for IBM Cloud Event Notifications instance.
27262726
* @param {string} params.id - Unique identifier for SMTP.
27272727
* @param {string} [params.description] - The description of SMTP configuration.
2728+
* @param {string} [params.usernameToClone] - provide name of the user to clone.
27282729
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
27292730
* @returns {Promise<EventNotificationsV1.Response<EventNotificationsV1.SMTPUserResponse>>}
27302731
*/
@@ -2733,7 +2734,7 @@ class EventNotificationsV1 extends BaseService {
27332734
): Promise<EventNotificationsV1.Response<EventNotificationsV1.SMTPUserResponse>> {
27342735
const _params = { ...params };
27352736
const _requiredParams = ['instanceId', 'id'];
2736-
const _validParams = ['instanceId', 'id', 'description', 'headers'];
2737+
const _validParams = ['instanceId', 'id', 'description', 'usernameToClone', 'headers'];
27372738
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
27382739
if (_validationErrors) {
27392740
return Promise.reject(_validationErrors);
@@ -2743,6 +2744,10 @@ class EventNotificationsV1 extends BaseService {
27432744
'description': _params.description,
27442745
};
27452746

2747+
const query = {
2748+
'username_to_clone': _params.usernameToClone,
2749+
};
2750+
27462751
const path = {
27472752
'instance_id': _params.instanceId,
27482753
'id': _params.id,
@@ -2759,6 +2764,7 @@ class EventNotificationsV1 extends BaseService {
27592764
url: '/v1/instances/{instance_id}/smtp/config/{id}/users',
27602765
method: 'POST',
27612766
body,
2767+
qs: query,
27622768
path,
27632769
},
27642770
defaultOptions: extend(true, {}, this.baseOptions, {
@@ -3989,6 +3995,8 @@ namespace EventNotificationsV1 {
39893995
id: string;
39903996
/** The description of SMTP configuration. */
39913997
description?: string;
3998+
/** provide name of the user to clone. */
3999+
usernameToClone?: string;
39924000
headers?: OutgoingHttpHeaders;
39934001
}
39944002

@@ -4702,8 +4710,8 @@ namespace EventNotificationsV1 {
47024710
smtp_config_id: string;
47034711
/** SMTP user name. */
47044712
username: string;
4705-
/** password. */
4706-
password: string;
4713+
/** Password for SMTP user; Cloned SMTP user response do not include a password. */
4714+
password?: string;
47074715
/** Created time. */
47084716
created_at: string;
47094717
}

examples/event-notifications.v1.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ let eventStreamsEndPoint = '';
124124
let appConfigTemplateBody = '';
125125
let appConfigCRN = '';
126126
let appConfigTemplateID = '';
127+
let smtpUserToClone = '';
128+
let smtpUserID2 = '';
127129

128130
// Save original console.log
129131
const originalLog = console.log;
@@ -170,6 +172,7 @@ describe('EventNotificationsV1', () => {
170172
eventStreamsEndPoint = config.eventStreamsEndpoint;
171173
appConfigTemplateBody = config.appConfigTemplateBody;
172174
appConfigCRN = config.appConfigCrn;
175+
smtpUserToClone = config.smtpUserToClone;
173176

174177
let eventNotificationsService = EventNotificationsV1.newInstance({});
175178

@@ -3186,6 +3189,34 @@ describe('EventNotificationsV1', () => {
31863189
// end-create_smtp_user
31873190
});
31883191

3192+
test('cloneSMTPUser request example', async () => {
3193+
consoleLogMock.mockImplementation((output) => {
3194+
originalLog(output);
3195+
});
3196+
consoleWarnMock.mockImplementation((output) => {
3197+
// if an error occurs, display the message and then fail the test
3198+
originalWarn(output);
3199+
expect(true).toBeFalsy();
3200+
});
3201+
3202+
originalLog('cloneSMTPUser() result:');
3203+
// begin-clone_smtp_user
3204+
const cloneSMTPUserParams = {
3205+
instanceId,
3206+
id: smtpConfigID,
3207+
usernameToClone: smtpUserToClone,
3208+
};
3209+
3210+
try {
3211+
const res = await eventNotificationsService.createSmtpUser(cloneSMTPUserParams);
3212+
smtpUserID2 = res.result.id;
3213+
console.log(JSON.stringify(res.result, null, 2));
3214+
} catch (err) {
3215+
console.warn(err);
3216+
}
3217+
// end-clone_smtp_user
3218+
});
3219+
31893220
test('listSMTPConfigurations request example', async () => {
31903221
consoleLogMock.mockImplementation((output) => {
31913222
originalLog(output);
@@ -3472,6 +3503,19 @@ describe('EventNotificationsV1', () => {
34723503
console.warn(err);
34733504
}
34743505
// end-delete_smtp_user
3506+
3507+
const deleteSmtpClonedUserParams = {
3508+
instanceId,
3509+
id: smtpConfigID,
3510+
userId: smtpUserID2,
3511+
};
3512+
3513+
try {
3514+
const res = await eventNotificationsService.deleteSmtpUser(deleteSmtpClonedUserParams);
3515+
console.log(JSON.stringify(res.result, null, 2));
3516+
} catch (err) {
3517+
console.warn(err);
3518+
}
34753519
});
34763520

34773521
test('deleteSMTPConfiguration request example', async () => {

test/integration/event-notifications.v1.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ let slackTemplateBody = '';
107107
let cosInstanceCRN = '';
108108
let cosIntegrationId = '';
109109
let smtpConfigID = '';
110+
let smtpUserToClone = '';
110111
let smtpUserID = '';
112+
let smtpUserID2 = '';
111113
let notificationID = '';
112114
let slackDmToken = '';
113115
let slackChannelID = '';
@@ -178,6 +180,7 @@ describe('EventNotificationsV1_integration', () => {
178180
codeEngineJobTemplateBody = config.codeEngineJobTemplateBody;
179181
appConfigTemplateBody = config.appConfigTemplateBody;
180182
appConfigCRN = config.appConfigCrn;
183+
smtpUserToClone = config.smtpUserToClone;
181184
eventNotificationsService.enableRetries();
182185
});
183186

@@ -3509,6 +3512,24 @@ describe('EventNotificationsV1_integration', () => {
35093512
smtpUserID = res.result.id;
35103513
});
35113514

3515+
test('cloneSMTPUser()', async () => {
3516+
const description = 'SMTP user description clone';
3517+
const createSmtpUserParams = {
3518+
instanceId,
3519+
id: smtpConfigID,
3520+
usernameToClone: smtpUserToClone,
3521+
description,
3522+
};
3523+
3524+
const res = await eventNotificationsService.createSmtpUser(createSmtpUserParams);
3525+
expect(res).toBeDefined();
3526+
expect(res.status).toBe(201);
3527+
expect(res.result).toBeDefined();
3528+
expect(res.result.username).toBeDefined();
3529+
expect(res.result.domain).toBeDefined();
3530+
smtpUserID2 = res.result.id;
3531+
});
3532+
35123533
test('listSMTPConfigurations()', async () => {
35133534
const limit = 1;
35143535
const offset = 0;
@@ -3656,7 +3677,7 @@ describe('EventNotificationsV1_integration', () => {
36563677
});
36573678

36583679
test('deleteSMTPUser()', async () => {
3659-
const userIDs = [smtpUserID];
3680+
const userIDs = [smtpUserID, smtpUserID2];
36603681

36613682
for (let i = 0; i < userIDs.length; i += 1) {
36623683
const deleteSmtpUserParams = {

test/unit/event-notifications.v1.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,10 +4920,12 @@ describe('EventNotificationsV1', () => {
49204920
const instanceId = 'testString';
49214921
const id = 'testString';
49224922
const description = 'testString';
4923+
const usernameToClone = 'testString';
49234924
const createSmtpUserParams = {
49244925
instanceId,
49254926
id,
49264927
description,
4928+
usernameToClone,
49274929
};
49284930

49294931
const createSmtpUserResult = eventNotificationsService.createSmtpUser(createSmtpUserParams);
@@ -4945,6 +4947,7 @@ describe('EventNotificationsV1', () => {
49454947
const expectedContentType = 'application/json';
49464948
checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType);
49474949
expect(mockRequestOptions.body.description).toEqual(description);
4950+
expect(mockRequestOptions.qs.username_to_clone).toEqual(usernameToClone);
49484951
expect(mockRequestOptions.path.instance_id).toEqual(instanceId);
49494952
expect(mockRequestOptions.path.id).toEqual(id);
49504953
}

0 commit comments

Comments
 (0)