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

Recording delete APIs in CallingServerClient #18493

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class CallingServerClient {
cancelMediaOperation(callLocator: CallLocator, mediaOperationId: string, options?: CancelMediaOperationOptions): Promise<void>;
cancelParticipantMediaOperation(callLocator: CallLocator, participant: CommunicationIdentifier, mediaOperationId: string, options?: CancelMediaOperationOptions): Promise<void>;
createCallConnection(source: CommunicationIdentifier, targets: CommunicationIdentifier[], options: CreateCallConnectionOptions): Promise<CallConnection>;
delete(deleteUri: string, options?: DeleteOptions): Promise<RestResponse>;
download(uri: string, offset?: number, options?: DownloadOptions): Promise<ContentDownloadResponse>;
getCallConnection(callConnectionId: string): CallConnection;
// Warning: (ae-forgotten-export) The symbol "CallRecordingProperties" needs to be exported by the entry point index.d.ts
Expand All @@ -102,7 +103,7 @@ export class CallingServerClient {
// Warning: (ae-forgotten-export) The symbol "StartCallRecordingResult" needs to be exported by the entry point index.d.ts
startRecording(callLocator: CallLocator, recordingStateCallbackUri: string, options?: StartRecordingOptions): Promise<StartCallRecordingResult>;
stopRecording(recordingId: string, options?: StopRecordingOptions): Promise<RestResponse>;
}
}

// @public
export interface CallingServerClientOptions extends PipelineOptions {
Expand Down Expand Up @@ -164,6 +165,9 @@ export interface CreateCallConnectionOptions extends OperationOptions {
subject?: string;
}

// @public
export type DeleteOptions = OperationOptions;

// @public (undocumented)
export interface DownloadContentOptions extends DownloadOptions {
range?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as Parameters from "./parameters";
import * as Mappers from "./generated/src/models/mappers";
import * as ExtraMappers from "./mappers";
import { CallingServerApiClientContext } from "./generated/src/callingServerApiClientContext";
import { URLBuilder } from "@azure/core-http";
import { OperationQueryParameter } from "@azure/core-http";
import { createSpan } from "./tracing";
import { SpanStatusCode } from "@azure/core-tracing";

Expand All @@ -20,6 +18,7 @@ import {
OperationSpec
} from "@azure/core-http";
import { ContentDownloadResponse } from ".";
import { CallingServerUtils } from "./utils/utils";

export class ContentDownloader {
private readonly client: CallingServerApiClientContext;
Expand Down Expand Up @@ -64,10 +63,7 @@ export class ContentDownloader {
const operationArguments: OperationArguments = {
options: operationOptionsToRequestOptionsBase(options || {})
};

const q = URLBuilder.parse(contentUri);
const formattedUrl = q.getPath()!.startsWith("/") ? q.getPath()!.substr(1) : q.getPath()!;
const stringToSign = this.client.endpoint + formattedUrl;
const stringToSign = CallingServerUtils.getStringToSign(this.client.endpoint, contentUri);
return this.client.sendOperationRequest(
operationArguments,
getDownloadContentOperationSpec(contentUri, stringToSign)
Expand All @@ -79,17 +75,7 @@ export class ContentDownloader {
const serializer = new Serializer(Mappers, /* isXml */ false);

function getDownloadContentOperationSpec(url: string, stringToSign: string): OperationSpec {
const stringToSignHeader: OperationQueryParameter = {
parameterPath: "UriToSignWith",
mapper: {
defaultValue: stringToSign,
isConstant: true,
serializedName: "UriToSignWith",
type: {
name: "String"
}
}
};
const stringToSignHeader = CallingServerUtils.getStringToSignHeader(stringToSign);

const downloadContentOperationSpec: OperationSpec = {
path: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
PauseRecordingOptions,
ResumeRecordingOptions,
StopRecordingOptions,
GetRecordingPropertiesOptions
GetRecordingPropertiesOptions,
DeleteOptions
} from "./models";
import { CallConnections, ServerCalls } from "./generated/src/operations";
import {
Expand All @@ -35,6 +36,7 @@ import {
StartCallRecordingWithCallLocatorRequest,
CallRecordingProperties
} from "./generated/src/models";
import * as Mappers from "./generated/src/models/mappers";
import { TokenCredential } from "@azure/core-auth";

import {
Expand All @@ -50,7 +52,10 @@ import {
InternalPipelineOptions,
createPipelineFromOptions,
operationOptionsToRequestOptionsBase,
RestResponse
RestResponse,
OperationArguments,
OperationSpec,
Serializer
} from "@azure/core-http";
import { SpanStatusCode } from "@azure/core-tracing";
import { CallingServerApiClient } from "./generated/src/callingServerApiClient";
Expand Down Expand Up @@ -85,7 +90,7 @@ export class CallingServerClient {
private readonly callingServerServiceClient: CallingServerApiClient;
private readonly callConnectionRestClient: CallConnections;
private readonly serverCallRestClient: ServerCalls;
private readonly downloadCallingServerApiClient: CallingServerApiClientContext;
private readonly storageApiClient: CallingServerApiClientContext;

/**
* Initializes a new instance of the CallingServerClient class.
Expand Down Expand Up @@ -138,7 +143,7 @@ export class CallingServerClient {
this.callingServerServiceClient = new CallingServerApiClient(url, pipeline);
this.callConnectionRestClient = this.callingServerServiceClient.callConnections;
this.serverCallRestClient = this.callingServerServiceClient.serverCalls;
this.downloadCallingServerApiClient = new CallingServerApiClientContext(url, pipeline);
this.storageApiClient = new CallingServerApiClientContext(url, pipeline);
}

/**
Expand All @@ -150,7 +155,7 @@ export class CallingServerClient {
}

public initializeContentDownloader(): ContentDownloader {
return new ContentDownloader(this.downloadCallingServerApiClient);
return new ContentDownloader(this.storageApiClient);
}

/**
Expand Down Expand Up @@ -824,4 +829,73 @@ export class CallingServerClient {
span.end();
}
}

/**
* Deletes the content pointed to the uri passed as a parameter.
*
* * Returns a RestResponse indicating the result of the delete operation.
*
* @param deleteUri - Endpoint where the content exists.
*
* Example usage:
*
* ```js
* // Delete content
* const deleteUri = "https://deleteUri.com";
* const deleteResponse = await callingServerClient.delete(deleteUri);
*
* ```
*/
public async delete(deleteUri: string, options: DeleteOptions = {}): Promise<RestResponse> {
const { span, updatedOptions } = createSpan("ServerCallRestClient-delete", options);

const operationArguments: OperationArguments = {
options: operationOptionsToRequestOptionsBase(updatedOptions)
};

try {
const stringToSign = CallingServerUtils.getStringToSign(
this.storageApiClient.endpoint,
deleteUri
);
return this.storageApiClient.sendOperationRequest(
operationArguments,
getDeleteOperationSpec(deleteUri, stringToSign)
) as Promise<RestResponse>;
} catch (e) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: e.message
});
throw e;
} finally {
span.end();
}
}
}

function getDeleteOperationSpec(url: string, stringToSign: string): OperationSpec {
// Operation Specifications
const serializer = new Serializer(Mappers, /* isXml */ false);
const stringToSignHeader = CallingServerUtils.getStringToSignHeader(stringToSign);
const hostHeader = CallingServerUtils.getMsHostHeaders(stringToSign);

const deleteOperationSpec: OperationSpec = {
path: "",
baseUrl: url,
httpMethod: "DELETE",
responses: {
200: {},
default: {
bodyMapper: Mappers.CommunicationErrorResponse
}
},
requestBody: undefined,
queryParameters: [],
urlParameters: [],
headerParameters: [stringToSignHeader, hostHeader],
serializer
};

return deleteOperationSpec;
}
4 changes: 4 additions & 0 deletions sdk/communication/communication-callingserver/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export type StopRecordingOptions = OperationOptions;
* Options to get recording properties.
*/
export type GetRecordingPropertiesOptions = OperationOptions;
/**
* Options to delete recording.
*/
export type DeleteOptions = OperationOptions;

/**
* Call Locator.
Expand Down
37 changes: 37 additions & 0 deletions sdk/communication/communication-callingserver/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { OperationQueryParameter } from "@azure/core-http";
import { URLBuilder } from "@azure/core-http";

export class CallingServerUtils {
Expand All @@ -13,4 +14,40 @@ export class CallingServerUtils {
}
return url.getScheme() === "http" || url.getScheme() === "https";
}

public static getStringToSignHeader(stringToSign: string): OperationQueryParameter {
return {
parameterPath: "UriToSignWith",
mapper: {
defaultValue: stringToSign,
isConstant: true,
serializedName: "UriToSignWith",
type: {
name: "String"
}
}
};
}

public static getMsHostHeaders(hostName: string): OperationQueryParameter {
const q = URLBuilder.parse(hostName!);
const hostAndPort = q.getHost()! + (q.getPort() !== undefined ? q.getPort() : "");
return {
parameterPath: "x-ms-host",
mapper: {
defaultValue: hostAndPort,
isConstant: true,
serializedName: "x-ms-host",
type: {
name: "String"
}
}
};
}

public static getStringToSign(resourceEndpoint: string, requestUri: string): string {
const q = URLBuilder.parse(requestUri);
const formattedUrl = q.getPath()!.startsWith("/") ? q.getPath()!.substr(1) : q.getPath()!;
return resourceEndpoint + formattedUrl;
}
}
Loading