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 2 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?: OperationOptions): 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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 +19,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 @@ -79,17 +79,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 @@ -35,6 +35,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 +51,12 @@ import {
InternalPipelineOptions,
createPipelineFromOptions,
operationOptionsToRequestOptionsBase,
RestResponse
RestResponse,
OperationArguments,
OperationOptions,
OperationSpec,
Serializer,
URLBuilder
} from "@azure/core-http";
import { SpanStatusCode } from "@azure/core-tracing";
import { CallingServerApiClient } from "./generated/src/callingServerApiClient";
Expand Down Expand Up @@ -85,7 +91,7 @@ export class CallingServerClient {
private readonly callingServerServiceClient: CallingServerApiClient;
private readonly callConnectionRestClient: CallConnections;
private readonly serverCallRestClient: ServerCalls;
private readonly downloadCallingServerApiClient: CallingServerApiClientContext;
private readonly deleteAndDownloadCallingServerApiClient: CallingServerApiClientContext;

/**
* Initializes a new instance of the CallingServerClient class.
Expand Down Expand Up @@ -138,7 +144,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.deleteAndDownloadCallingServerApiClient = new CallingServerApiClientContext(url, pipeline);
melneubert marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

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

/**
* Deletes the content pointed to the uri passed as a parameter.
*
* * In Node.js, data returns ?
melneubert marked this conversation as resolved.
Show resolved Hide resolved
* * In browsers, data returns ?
*
* @param deleteUri - Endpoint where the content exists.
*
* Example usage (Node.js):
melneubert marked this conversation as resolved.
Show resolved Hide resolved
*
* ```js
* // Delete and convert a blob to a string
melneubert marked this conversation as resolved.
Show resolved Hide resolved
* const deleteUri = "https://deleteUri.com";
* const deleteResponse = await callingServerClient.delete(deleteUri);
*
* ```
*/
public async delete(
deleteUri: string,
options: OperationOptions = {}
melneubert marked this conversation as resolved.
Show resolved Hide resolved
): Promise<RestResponse>
{
const { span, updatedOptions } = createSpan("ServerCallRestClient-delete", options);

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

try
{
const q = URLBuilder.parse(deleteUri);
const formattedUrl = q.getPath()!.startsWith("/") ? q.getPath()!.substr(1) : q.getPath()!;
const stringToSign = this.deleteAndDownloadCallingServerApiClient.endpoint + formattedUrl;
melneubert marked this conversation as resolved.
Show resolved Hide resolved

return this.deleteAndDownloadCallingServerApiClient.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;
}
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"
}
}
}
}
}
Loading