Skip to content

Commit

Permalink
updating lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
v-vdharmaraj committed Nov 2, 2024
1 parent c6b280d commit 4eff580
Show file tree
Hide file tree
Showing 11 changed files with 4,912 additions and 4,912 deletions.
1,044 changes: 522 additions & 522 deletions sdk/communication/communication-call-automation/src/callMedia.ts

Large diffs are not rendered by default.

226 changes: 113 additions & 113 deletions sdk/communication/communication-call-automation/src/contentDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,130 +3,130 @@

import { CallAutomationApiClient } from "./generated/src/callAutomationApiClient";
import {
AddPipelineOptions,
createHttpHeaders,
createPipelineRequest,
PipelineRequest,
PipelineRequestOptions,
PipelineResponse,
SendRequest,
AddPipelineOptions,
createHttpHeaders,
createPipelineRequest,
PipelineRequest,
PipelineRequestOptions,
PipelineResponse,
SendRequest,
} from "@azure/core-rest-pipeline";
import { DeleteRecordingOptions, DownloadRecordingOptions } from "./models/options";

/** Class containing ContentDownloading operations. */
export class ContentDownloaderImpl {
private readonly client: CallAutomationApiClient;

/**
* Initialize a new instance of the class ContentDownloader class.
* @param client - Reference to the service client
*/
constructor(client: CallAutomationApiClient) {
this.client = client;
this.addCustomSignUrlPolicy();
}

private addCustomSignUrlPolicy(): void {
const signUrlPolicy = {
name: "CustomSignUrlPolicy",
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {
if (request.headers.has("OriginalUrl")) {
request.url = `${request.headers.get("OriginalUrl")}`;
const originalRequest = new URL(request.url);
request.headers.set("Host", originalRequest.host);
}
return next(request);
},
};

const pipelineOptions: AddPipelineOptions = {};
pipelineOptions.afterPhase = "Sign";
this.client.pipeline.addPolicy(signUrlPolicy, pipelineOptions);
}

/**
* Deletes a recording.
* @param deleteLocationUrl - The recording location url. Required.
*/
async deleteRecording(deleteLocationUrl: string, options: DeleteRecordingOptions): Promise<void> {
const fileLocation = new URL(deleteLocationUrl);
const endpoint = new URL(this.client.endpoint);
const modifiedUrlForSigning = endpoint.origin + fileLocation.pathname;

const opt: PipelineRequestOptions = {
url: modifiedUrlForSigning,
method: "DELETE",
headers: createHttpHeaders(),
body: "",
abortSignal: options?.abortSignal,
tracingOptions: options?.tracingOptions,
};

opt.headers?.set("OriginalUrl", deleteLocationUrl);
opt.headers?.set("x-ms-host", endpoint.host);
opt.headers?.set("accept", "application/json");

const req = createPipelineRequest(opt);

const results = await this.client.sendRequest(req);

if (results.status !== 200) {
if (results.bodyAsText) {
const jsonBody = JSON.parse(results.bodyAsText);
throw { status: jsonBody.status, message: jsonBody.message };
}
throw { status: results.status };
private readonly client: CallAutomationApiClient;

/**
* Initialize a new instance of the class ContentDownloader class.
* @param client - Reference to the service client
*/
constructor(client: CallAutomationApiClient) {
this.client = client;
this.addCustomSignUrlPolicy();
}

private addCustomSignUrlPolicy(): void {
const signUrlPolicy = {
name: "CustomSignUrlPolicy",
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {
if (request.headers.has("OriginalUrl")) {
request.url = `${request.headers.get("OriginalUrl")}`;
const originalRequest = new URL(request.url);
request.headers.set("Host", originalRequest.host);
}
return next(request);
},
};

const pipelineOptions: AddPipelineOptions = {};
pipelineOptions.afterPhase = "Sign";
this.client.pipeline.addPolicy(signUrlPolicy, pipelineOptions);
}

/**
* Deletes a recording.
* @param deleteLocationUrl - The recording location url. Required.
*/
async deleteRecording(deleteLocationUrl: string, options: DeleteRecordingOptions): Promise<void> {
const fileLocation = new URL(deleteLocationUrl);
const endpoint = new URL(this.client.endpoint);
const modifiedUrlForSigning = endpoint.origin + fileLocation.pathname;

const opt: PipelineRequestOptions = {
url: modifiedUrlForSigning,
method: "DELETE",
headers: createHttpHeaders(),
body: "",
abortSignal: options?.abortSignal,
tracingOptions: options?.tracingOptions,
};

opt.headers?.set("OriginalUrl", deleteLocationUrl);
opt.headers?.set("x-ms-host", endpoint.host);
opt.headers?.set("accept", "application/json");

const req = createPipelineRequest(opt);

const results = await this.client.sendRequest(req);

if (results.status !== 200) {
if (results.bodyAsText) {
const jsonBody = JSON.parse(results.bodyAsText);
throw { status: jsonBody.status, message: jsonBody.message };
}
throw { status: results.status };
}
}

/**
* Returns a stream with a call recording.
* @param sourceLocationUrl - The source location url. Required.
* @param options - Additional request options contains downloadRecording options.
*/
async download(
sourceLocationUrl: string,
options: DownloadRecordingOptions,
): Promise<PipelineResponse> {
const fileLocation = new URL(sourceLocationUrl);
const endpoint = new URL(this.client.endpoint);
const modifiedUrlForSigning = endpoint.origin + fileLocation.pathname;

const opt: PipelineRequestOptions = {
url: modifiedUrlForSigning,
method: "GET",
headers: createHttpHeaders(),
body: "",
streamResponseStatusCodes: new Set([200, 206]),
abortSignal: options.abortSignal,
tracingOptions: options?.tracingOptions,
};

if (options.length && !options.offset) {
throw Error("Download offset value must not be empty if length is set.");
} else if (options.length && options.offset) {
options.length = options.offset + options.length - 1;
}

/**
* Returns a stream with a call recording.
* @param sourceLocationUrl - The source location url. Required.
* @param options - Additional request options contains downloadRecording options.
*/
async download(
sourceLocationUrl: string,
options: DownloadRecordingOptions,
): Promise<PipelineResponse> {
const fileLocation = new URL(sourceLocationUrl);
const endpoint = new URL(this.client.endpoint);
const modifiedUrlForSigning = endpoint.origin + fileLocation.pathname;

const opt: PipelineRequestOptions = {
url: modifiedUrlForSigning,
method: "GET",
headers: createHttpHeaders(),
body: "",
streamResponseStatusCodes: new Set([200, 206]),
abortSignal: options.abortSignal,
tracingOptions: options?.tracingOptions,
};

if (options.length && !options.offset) {
throw Error("Download offset value must not be empty if length is set.");
} else if (options.length && options.offset) {
options.length = options.offset + options.length - 1;
}

let rangeHeader = "bytes=" + options.offset;
if (options.length) rangeHeader += "-" + options.length;
let rangeHeader = "bytes=" + options.offset;
if (options.length) rangeHeader += "-" + options.length;

opt.headers?.set("OriginalUrl", sourceLocationUrl);
opt.headers?.set("x-ms-host", endpoint.host);
opt.headers?.set("accept", "application/json");
opt.headers?.set("Range", rangeHeader);
opt.headers?.set("OriginalUrl", sourceLocationUrl);
opt.headers?.set("x-ms-host", endpoint.host);
opt.headers?.set("accept", "application/json");
opt.headers?.set("Range", rangeHeader);

const req = createPipelineRequest(opt);
const req = createPipelineRequest(opt);

const results = await this.client.sendRequest(req);
const results = await this.client.sendRequest(req);

if (results.status !== 200 && results.status !== 206) {
if (results.bodyAsText) {
const jsonBody = JSON.parse(results.bodyAsText);
throw { status: jsonBody.status, message: jsonBody.message };
}
throw { status: results.status };
}
return results;
if (results.status !== 200 && results.status !== 206) {
if (results.bodyAsText) {
const jsonBody = JSON.parse(results.bodyAsText);
throw { status: jsonBody.status, message: jsonBody.message };
}
throw { status: results.status };
}
return results;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT License.

import {
BearerTokenAuthenticationPolicyOptions,
PipelinePolicy,
bearerTokenAuthenticationPolicy,
BearerTokenAuthenticationPolicyOptions,
PipelinePolicy,
bearerTokenAuthenticationPolicy,
} from "@azure/core-rest-pipeline";
import { KeyCredential, TokenCredential, isTokenCredential } from "@azure/core-auth";
import { createCallAutomationAccessKeyCredentialPolicy } from "./callAutomationAccessKeyCredentialPolicy";
Expand All @@ -18,18 +18,18 @@ import { createCommunicationAuthPolicy } from "@azure/communication-common";
* @param credential - The KeyCredential or TokenCredential.
*/
export function createCallAutomationAuthPolicy(
credential: KeyCredential | TokenCredential,
acsUrl: string,
credential: KeyCredential | TokenCredential,
acsUrl: string,
): PipelinePolicy {
if (isTokenCredential(credential)) {
const policyOptions: BearerTokenAuthenticationPolicyOptions = {
credential: credential,
scopes: ["https://communication.azure.com//.default"],
};
return bearerTokenAuthenticationPolicy(policyOptions);
} else {
return createCallAutomationAccessKeyCredentialPolicy(credential, acsUrl);
}
if (isTokenCredential(credential)) {
const policyOptions: BearerTokenAuthenticationPolicyOptions = {
credential: credential,
scopes: ["https://communication.azure.com//.default"],
};
return bearerTokenAuthenticationPolicy(policyOptions);
} else {
return createCallAutomationAccessKeyCredentialPolicy(credential, acsUrl);
}
}

/**
Expand All @@ -41,24 +41,24 @@ export function createCallAutomationAuthPolicy(
* @param url - ACS url.
*/
export function createCustomCallAutomationApiClient(
credential: KeyCredential | TokenCredential,
internalPipelineOptions: CallAutomationApiClientOptionalParams | undefined,
url: string,
credential: KeyCredential | TokenCredential,
internalPipelineOptions: CallAutomationApiClientOptionalParams | undefined,
url: string,
): CallAutomationApiClient {
// read environment variable for callAutomation auth
const customEnabled = process.env.COMMUNICATION_CUSTOM_ENDPOINT_ENABLED;
const customUrl = process.env.COMMUNICATION_CUSTOM_URL;
let callAutomationApiClient: CallAutomationApiClient;
// read environment variable for callAutomation auth
const customEnabled = process.env.COMMUNICATION_CUSTOM_ENDPOINT_ENABLED;
const customUrl = process.env.COMMUNICATION_CUSTOM_URL;
let callAutomationApiClient: CallAutomationApiClient;

if (customEnabled?.toLowerCase() === "true" && customUrl) {
// add custom header for Call Automation auth when flag is true
callAutomationApiClient = new CallAutomationApiClient(customUrl, internalPipelineOptions);
const callAutomationAuthPolicy = createCallAutomationAuthPolicy(credential, url);
callAutomationApiClient.pipeline.addPolicy(callAutomationAuthPolicy);
} else {
callAutomationApiClient = new CallAutomationApiClient(url, internalPipelineOptions);
const authPolicy = createCommunicationAuthPolicy(credential);
callAutomationApiClient.pipeline.addPolicy(authPolicy);
}
return callAutomationApiClient;
if (customEnabled?.toLowerCase() === "true" && customUrl) {
// add custom header for Call Automation auth when flag is true
callAutomationApiClient = new CallAutomationApiClient(customUrl, internalPipelineOptions);
const callAutomationAuthPolicy = createCallAutomationAuthPolicy(credential, url);
callAutomationApiClient.pipeline.addPolicy(callAutomationAuthPolicy);
} else {
callAutomationApiClient = new CallAutomationApiClient(url, internalPipelineOptions);
const authPolicy = createCommunicationAuthPolicy(credential);
callAutomationApiClient.pipeline.addPolicy(authPolicy);
}
return callAutomationApiClient;
}
Loading

0 comments on commit 4eff580

Please sign in to comment.