-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVEXP-411: Add suport for Access Control List
- Loading branch information
1 parent
ec111e8
commit 1f85c89
Showing
29 changed files
with
1,420 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
examples/simple-examples/src/elastic-sip-trunking/access-control-list/addIpRange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { | ||
getAccessControlListIdFromConfig, | ||
getPrintFormat, | ||
initElasticSipTrunkingService, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*******************************'); | ||
console.log('* addAccessControlListToTrunk *'); | ||
console.log('*******************************'); | ||
|
||
const aclId = getAccessControlListIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.AddIpRangeToAccessControlListRequestData = { | ||
accessControlListId: aclId, | ||
addIpRangeRequestBody: { | ||
description: 'IP range to add with the Node.js SDK', | ||
ipAddress: '11.12.13.14', | ||
range: 27, | ||
}, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
const response = await elasticSipTrunkingService.accessControlList.addIpRange(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The IP range with the ID ${response.id} associated to the ACL '${response.accessControlListId}' has been created at ${response.createTime?.toISOString()}`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
38 changes: 38 additions & 0 deletions
38
examples/simple-examples/src/elastic-sip-trunking/access-control-list/addToTrunk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { | ||
getAccessControlListIdFromConfig, | ||
getPrintFormat, | ||
getSipTrunkIdFromConfig, | ||
initElasticSipTrunkingService, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*******************************'); | ||
console.log('* addAccessControlListToTrunk *'); | ||
console.log('*******************************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
const aclId = getAccessControlListIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.AddAccessControlListToTrunkRequestData = { | ||
trunkId: sipTrunkId, | ||
addAccessControlListToTrunkRequestBody: { | ||
accessControlListIds: [ | ||
aclId, | ||
], | ||
}, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
const response = await elasticSipTrunkingService.accessControlList.addToTrunk(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The SIP trunk with the id '${requestData.trunkId}' contains the following ACL IDs:\n - ${response.accessControlListIds?.join('\n - ')}`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
34 changes: 34 additions & 0 deletions
34
examples/simple-examples/src/elastic-sip-trunking/access-control-list/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('***************************'); | ||
console.log('* createAccessControlList *'); | ||
console.log('***************************'); | ||
|
||
const requestData: ElasticSipTrunking.CreateAccessControlListRequestData = { | ||
createAccessControlListBody: { | ||
name: 'New ACL created with the Node.js SDK', | ||
enabled: true, | ||
ipRanges: [ | ||
{ | ||
description: 'Location 1', | ||
ipAddress: '15.15.15.15', | ||
range: 20, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
const response = await elasticSipTrunkingService.accessControlList.create(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`New access control list created with the id '${response.id}' at '${response.createTime?.toISOString()}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
20 changes: 20 additions & 0 deletions
20
examples/simple-examples/src/elastic-sip-trunking/access-control-list/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { getAccessControlListIdFromConfig, initElasticSipTrunkingService } from '../../config'; | ||
|
||
(async () => { | ||
console.log('***************************'); | ||
console.log('* deleteAccessControlList *'); | ||
console.log('***************************'); | ||
|
||
const aclId = getAccessControlListIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.DeleteAccessControlListRequestData = { | ||
id: aclId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
await elasticSipTrunkingService.accessControlList.delete(requestData); | ||
|
||
console.log(`The SIP trunk with the id '${requestData.id}' has been deleted.`); | ||
|
||
})(); |
26 changes: 26 additions & 0 deletions
26
examples/simple-examples/src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { | ||
getAccessControlListIdFromConfig, | ||
getSipTrunkIdFromConfig, | ||
initElasticSipTrunkingService, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('************************************'); | ||
console.log('* deleteAccessControlListFromTrunk *'); | ||
console.log('************************************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
const aclId = getAccessControlListIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.DeleteAccessControlListFromTrunkRequestData = { | ||
trunkId: sipTrunkId, | ||
accessControlListId: aclId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
await elasticSipTrunkingService.accessControlList.deleteFromTrunk(requestData); | ||
|
||
console.log(`The ACL '${requestData.accessControlListId}' has been removed fromm the SIP trunk '${requestData.trunkId}'`); | ||
|
||
})(); |
26 changes: 26 additions & 0 deletions
26
examples/simple-examples/src/elastic-sip-trunking/access-control-list/deleteIpRange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { | ||
getAccessControlListIdFromConfig, | ||
getIpRangeIdFromConfig, | ||
initElasticSipTrunkingService, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('**************************************'); | ||
console.log('* deleteIpRangeFromAccessControlList *'); | ||
console.log('**************************************'); | ||
|
||
const aclId = getAccessControlListIdFromConfig(); | ||
const ipRangeId = getIpRangeIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.DeleteIpRangeFromAccessControlListRequestData = { | ||
accessControlListId: aclId, | ||
ipRangeId: ipRangeId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
await elasticSipTrunkingService.accessControlList.deleteIpRange(requestData); | ||
|
||
console.log(`The IP range '${requestData.ipRangeId}' has been removed fromm the ACL '${requestData.accessControlListId}'`); | ||
|
||
})(); |
63 changes: 63 additions & 0 deletions
63
examples/simple-examples/src/elastic-sip-trunking/access-control-list/list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ElasticSipTrunking, PageResult } from '@sinch/sdk-core'; | ||
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config'; | ||
|
||
const populateACLsList = ( | ||
aclPage: PageResult<ElasticSipTrunking.AccessControlList>, | ||
aclsList: ElasticSipTrunking.AccessControlList[], | ||
aclsDetailsList: string[], | ||
) => { | ||
aclPage.data.map((acl: ElasticSipTrunking.AccessControlList) => { | ||
aclsList.push(acl); | ||
aclsDetailsList.push(`${acl.id} - ${acl.name}`); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
console.log('************************'); | ||
console.log('* getAccessControlList *'); | ||
console.log('************************'); | ||
|
||
const requestData: ElasticSipTrunking.ListAccessControlListRequestData = {}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await elasticSipTrunkingService.accessControlList.list(requestData); | ||
const aclsList: ElasticSipTrunking.AccessControlList[] = []; | ||
const aclsDetailsList: string[] = []; | ||
|
||
// Loop on all the pages to get all the active numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
populateACLsList(response, aclsList, aclsDetailsList); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(aclsDetailsList.length > 0 | ||
? 'List of ACLs:\n' + aclsDetailsList.join('\n') | ||
: 'Sorry, no ACLs were found.'); | ||
} else { | ||
printFullResponse(aclsList); | ||
} | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const acl of elasticSipTrunkingService.accessControlList.list(requestData)) { | ||
if (printFormat === 'pretty') { | ||
console.log(`${acl.id} - ${acl.name}`); | ||
} else { | ||
console.log(acl); | ||
} | ||
} | ||
|
||
})(); |
44 changes: 44 additions & 0 deletions
44
examples/simple-examples/src/elastic-sip-trunking/access-control-list/listForTrunk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { getSipTrunkIdFromConfig, initElasticSipTrunkingService, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('*********************************'); | ||
console.log('* getAccessControlListsForTrunk *'); | ||
console.log('*********************************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.ListAccessControlListsForTrunkRequestData = { | ||
trunkId: sipTrunkId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await elasticSipTrunkingService.accessControlList.listForTrunk(requestData); | ||
|
||
const aclList: string[] = []; | ||
|
||
// Loop on all the pages to get all the active numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
aclList.push(...response.data); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
printFullResponse(aclList); | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const acl of elasticSipTrunkingService.accessControlList.listForTrunk(requestData)) { | ||
console.log(acl); | ||
} | ||
|
||
})(); |
Oops, something went wrong.