Skip to content

Commit

Permalink
Migration to Azure core 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AriZavala2 committed Apr 5, 2022
1 parent 9a046e7 commit 9ae85a3
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/communication-common": "^1.1.0",
"@azure/communication-common": "^2.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-http": "^2.0.0",
"@azure/core-client": "^1.3.0",
"@azure/core-rest-pipeline": "^1.3.0",
"@azure/core-tracing": "1.0.0-preview.13",
"@azure/logger": "^1.0.0",
"events": "^3.0.0",
Expand All @@ -86,7 +87,8 @@
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^2.0.1",
"@azure/test-utils": "^1.0.0",
"@azure-tools/test-recorder": "^1.0.0",
"@azure-tools/test-recorder": "^2.0.0",
"@azure-tools/test-credential": "^1.0.0",
"@microsoft/api-extractor": "^7.18.11",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
// Licensed under the MIT license.

import {
createCommunicationAuthPolicy,
isKeyCredential,
createCommunicationAuthPolicy,
parseClientArguments,
} from "@azure/communication-common";
import { isTokenCredential, KeyCredential, TokenCredential } from "@azure/core-auth";
import {
createPipelineFromOptions,
InternalPipelineOptions,
operationOptionsToRequestOptionsBase,
} from "@azure/core-http";

import { SpanStatusCode } from "@azure/core-tracing";
import {
CommunicationNetworkTraversal,
NetworkRelayRestClient,
} from "./generated/src/networkRelayRestClient";

import { SDK_VERSION } from "./constants";
import { InternalClientPipelineOptions } from "@azure/core-client";
import { logger } from "./common/logger";
import { createSpan } from "./common/tracing";
import { CommunicationRelayClientOptions, GetRelayConfigurationOptions } from "./models";
Expand All @@ -39,7 +33,7 @@ export class CommunicationRelayClient {
/**
* A reference to the auto-generated UserToken HTTP client.
*/
private readonly client: CommunicationNetworkTraversal;
private readonly client: NetworkRelayRestClient;

/**
* Initializes a new instance of the CommunicationRelayClient class.
Expand Down Expand Up @@ -90,19 +84,8 @@ export class CommunicationRelayClient {
const options = isCommunicationRelayClientOptions(credentialOrOptions)
? credentialOrOptions
: maybeOptions;
const libInfo = `azsdk-js-communication-network-traversal/${SDK_VERSION}`;

if (!options.userAgentOptions) {
options.userAgentOptions = {};
}

if (options.userAgentOptions.userAgentPrefix) {
options.userAgentOptions.userAgentPrefix = `${options.userAgentOptions.userAgentPrefix} ${libInfo}`;
} else {
options.userAgentOptions.userAgentPrefix = libInfo;
}

const internalPipelineOptions: InternalPipelineOptions = {
const internalPipelineOptions: InternalClientPipelineOptions = {
...options,
...{
loggingOptions: {
Expand All @@ -112,8 +95,11 @@ export class CommunicationRelayClient {
};

const authPolicy = createCommunicationAuthPolicy(credential);
const pipeline = createPipelineFromOptions(internalPipelineOptions, authPolicy);
this.client = new NetworkRelayRestClient(url, pipeline).communicationNetworkTraversal;
this.client = new NetworkRelayRestClient(url, {
endpoint: url,
...internalPipelineOptions
});
this.client.pipeline.addPolicy(authPolicy);
}

/**
Expand All @@ -140,7 +126,9 @@ export class CommunicationRelayClient {
options;

if (options !== "undefined") {
requestOptions.body = { id: options.id, routeType: options.routeType, ttl: options.ttl };
requestOptions.id = options.id;
requestOptions.routeType = options.routeType;
requestOptions.ttl = options.ttl;
}

const { span, updatedOptions } = createSpan(
Expand All @@ -149,8 +137,8 @@ export class CommunicationRelayClient {
);

try {
const { ...result } = await this.client.issueRelayConfiguration(
operationOptionsToRequestOptionsBase(updatedOptions)
const { ...result } = await this.client.communicationNetworkTraversal.issueRelayConfiguration(
updatedOptions
);
return result;
} catch (e) {
Expand Down

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.

Loading

0 comments on commit 9ae85a3

Please sign in to comment.