Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-505: E2E ElasticSipTrunking/AccessControlLists #121

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IpRangeRequest } from '../ip-range';

export interface CreateAccessControlListRequest {
/** Your name for the access control list entry. */
name: string;
/** Whether the access control list entry is enabled. You can use this to disable a list temporarily without deleting it. */
enabled?: boolean;
/** An array of all the IP ranges to create. */
ipRanges: IpRangeRequest[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CreateAccessControlListRequest } from './create-access-control-list-request';
1 change: 1 addition & 0 deletions packages/elastic-sip-trunking/src/models/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './access-control-list';
export * from './add-access-control-list-to-trunk';
export * from './call';
export * from './country-permission';
export * from './create-access-control-list-request';
export * from './ip-range';
export * from './list-country-permissions-response';
export * from './money';
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type { IpRange } from './ip-range';
export type { IpRange, IpRangeRequest } from './ip-range';
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export interface IpRange {
/** The ID of the access control list. */
accessControlListId?: string;
}

export type IpRangeRequest = Omit<IpRange, 'accessControlListId' | 'id' | 'createTime' | 'updateTime' | 'projectId'>;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AccessControlList } from '../../access-control-list';
import { IpRange } from '../../ip-range';
import { IpRangeRequest } from '../../ip-range';
import { UpdateAccessControlListRequest } from '../../update-access-control-list-request';
import { CreateAccessControlListRequest } from '../../create-access-control-list-request';

export interface AddIpRangeToAccessControlListRequestData {
/** The ID of the access control list entry. that you want to work with */
'accessControlListId': string;
/** */
'addIpRangeRequestBody': IpRange;
'addIpRangeRequestBody': IpRangeRequest;
}
export interface CreateAccessControlListRequestData {
/** The Access Control List details used to create an Access Control List */
'createAccessControlListBody': AccessControlList;
'createAccessControlListBody': CreateAccessControlListRequest;
}
export interface DeleteAccessControlListRequestData {
/** The ID of the access control list entry. */
Expand All @@ -22,6 +22,10 @@ export interface DeleteIpRangeFromAccessControlListRequestData {
/** The ID of the IP range that you want to update. */
'ipRangeId': string;
}
export interface GetAccessControlListRequestData {
/** The ID of the access control list entry that you want to retrieve. */
'id': string;
}
export interface ListAccessControlListRequestData {
}
export interface ListIpRangesForAccessControlListRequestData {
Expand All @@ -40,5 +44,5 @@ export interface UpdateIpRangeFromAccessControlListRequestData {
/** The ID of the IP range that you want to update. */
'ipRangeId': string;
/** The IP range details used to update the IP range property from an Access Control List */
'updateIpRangeRequestBody': IpRange;
'updateIpRangeRequestBody': IpRangeRequest;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IpRange } from '../ip-range';
import { IpRangeRequest } from '../ip-range';

export interface UpdateAccessControlListRequest {
/** Your name for the access control list entry. */
name: string;
/** Whether the access control list entry is enabled. You can use this to disable a list temporarily without deleting it. */
enabled?: boolean;
/** An array of all the IP ranges to update. */
ipRanges?: IpRange[];
ipRanges?: IpRangeRequest[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
UpdateAccessControlListRequestData,
UpdateIpRangeFromAccessControlListRequestData,
AddAccessControlListToTrunk,
GetAccessControlListRequestData,
} from '../../../models';
import { ApiListPromise } from '@sinch/sdk-client';

Expand Down Expand Up @@ -44,6 +45,11 @@ export class AccessControlListApiFixture implements Partial<Readonly<AccessContr
*/
public create: jest.Mock<
Promise<AccessControlList>, [CreateAccessControlListRequestData]> = jest.fn();
/**
* Fixture associated to function get
*/
public get: jest.Mock<
Promise<AccessControlList>, [GetAccessControlListRequestData]> = jest.fn();
/**
* Fixture associated to function delete
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ListAccessControlListsForTrunkRequestData,
AddAccessControlListToTrunk,
IpRange,
GetAccessControlListRequestData,
} from '../../../models';
import {
RequestBody,
Expand Down Expand Up @@ -183,6 +184,33 @@ export class AccessControlListApi extends ElasticSipTrunkingDomainApi {
});
}

/**
* Get Access Control List
* Search for an Access Control List by ID.
* @param { GetAccessControlListRequestData } data - The data to provide to the API call.
*/
public async get(data: GetAccessControlListRequestData): Promise<AccessControlList> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<GetAccessControlListRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};

const body: RequestBody = '';
const basePathUrl = `${this.client.apiClientOptions.hostname}/v1/projects/${this.client.apiClientOptions.projectId}/accessControlLists/${data['id']}`;

const requestOptions = await this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<AccessControlList>({
url,
requestOptions,
apiName: this.apiName,
operationId: 'GetAccessControlListById',
});
}

/**
* List ACLs
* Fetches the list of Access Control List entries.
Expand All @@ -205,7 +233,7 @@ export class AccessControlListApi extends ElasticSipTrunkingDomainApi {
const operationProperties: PaginatedApiProperties = {
pagination: PaginationEnum.PAGE2,
apiName: this.apiName,
operationId: 'GetAccessControlList',
operationId: 'GetAccessControlLists',
dataKey: 'accessControlLists',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,45 @@ describe('AccessControlListApi', () => {
});
});

describe ('getAccessControlListById', () => {
// eslint-disable-next-line max-len
it('should make a GET request to retrieve an access control list', async () => {
// Given
const requestData: ElasticSipTrunking.GetAccessControlListRequestData = {
id: '01HA9BRJW4J3QE4WBKVC337V4E',
};
const expectedResponse: ElasticSipTrunking.AccessControlList = {
name: 'My new ACL',
projectId: '3acb7ae1-cf3d-4112-ba5e-3a9d8c71cd47',
enabled: true,
id: '01HA9BRJW4J3QE4WBKVC337V4E',
createTime: new Date('2023-09-14T07:39:19Z'),
updateTime: null,
ipRanges: [
{
description: 'Location 1',
ipAddress: '15.15.15.15',
range: 20,
projectId: '3acb7ae1-cf3d-4112-ba5e-3a9d8c71cd47',
accessControlListId: '01HA9BRJW4J3QE4WBKVC337V4E',
id: '01HA9BRJYR9Q7ZBDYMXHVWT8S8',
createTime: new Date('2023-09-14T07:39:19Z'),
updateTime: null,
},
],
};

// When
fixture.get.mockResolvedValue(expectedResponse);
accessControlListApi.get = fixture.get;
const response = await accessControlListApi.get(requestData);

// Then
expect(response).toEqual(expectedResponse);
expect(fixture.get).toHaveBeenCalledWith(requestData);
});
});

describe ('deleteAccessControlList', () => {
it('should make a DELETE request to delete an access control list entry', async () => {
// Given
Expand Down Expand Up @@ -187,7 +226,7 @@ describe('AccessControlListApi', () => {
});
});

describe ('getAccessControlList', () => {
describe ('getAccessControlLists', () => {
it('should make a GET request to fetch the list of Access Control List entries', async () => {
// Given
const requestData: ElasticSipTrunking.ListAccessControlListRequestData = {};
Expand Down
Loading
Loading