From 73bbaad4555f0c0cdf19e63e9c5348485a3cfe0d Mon Sep 17 00:00:00 2001 From: Karishma Ghiya Date: Wed, 6 Oct 2021 17:10:23 -0700 Subject: [PATCH 1/5] make audience private for now --- sdk/monitor/monitor-query/review/monitor-query.api.md | 4 +--- sdk/monitor/monitor-query/src/logsQueryClient.ts | 6 ++++-- sdk/monitor/monitor-query/src/metricsQueryClient.ts | 10 +++------- .../internal/unit/logsQueryClient.unittest.spec.ts | 5 ++--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sdk/monitor/monitor-query/review/monitor-query.api.md b/sdk/monitor/monitor-query/review/monitor-query.api.md index 398400cd0d81..75870637bd24 100644 --- a/sdk/monitor/monitor-query/review/monitor-query.api.md +++ b/sdk/monitor/monitor-query/review/monitor-query.api.md @@ -66,7 +66,7 @@ export class LogsQueryClient { // @public export interface LogsQueryClientOptions extends CommonClientOptions { - audience?: string; + _audience?: string; endpoint?: string; } @@ -173,7 +173,6 @@ export interface MetricNamespace { // @public export interface MetricsClientOptions extends CommonClientOptions { - audience?: string; endpoint?: string; } @@ -258,7 +257,6 @@ export interface TimeSeriesElement { metadataValues?: MetadataValue[]; } - // (No @packageDocumentation comment for this package) ``` diff --git a/sdk/monitor/monitor-query/src/logsQueryClient.ts b/sdk/monitor/monitor-query/src/logsQueryClient.ts index 05218888db02..07dcf60aa09d 100644 --- a/sdk/monitor/monitor-query/src/logsQueryClient.ts +++ b/sdk/monitor/monitor-query/src/logsQueryClient.ts @@ -43,7 +43,7 @@ export interface LogsQueryClientOptions extends CommonClientOptions { * The authentication scope will be set from this audience. * Defaults to 'https://api.loganalytics.io/.default' */ - audience?: string; + _audience?: string; } /** @@ -51,6 +51,7 @@ export interface LogsQueryClientOptions extends CommonClientOptions { */ export class LogsQueryClient { private _logAnalytics: AzureLogAnalytics; + private _audience?: string; /** * Construct a LogsClient that can be used to query logs using the Log Analytics Query language. @@ -61,8 +62,9 @@ export class LogsQueryClient { constructor(tokenCredential: TokenCredential, options?: LogsQueryClientOptions) { // This client defaults to using 'https://api.loganalytics.io/' as the // host. + this._audience = `${options?.endpoint}./default`; const credentialOptions = { - credentialScopes: options?.audience + credentialScopes: this._audience }; const packageDetails = `azsdk-js-monitor-query/${SDK_VERSION}`; const userAgentPrefix = diff --git a/sdk/monitor/monitor-query/src/metricsQueryClient.ts b/sdk/monitor/monitor-query/src/metricsQueryClient.ts index bf2077656b40..3e5bbda1d3b6 100644 --- a/sdk/monitor/monitor-query/src/metricsQueryClient.ts +++ b/sdk/monitor/monitor-query/src/metricsQueryClient.ts @@ -41,12 +41,6 @@ const defaultMetricsScope = "https://management.azure.com/.default"; export interface MetricsQueryClientOptions extends CommonClientOptions { /** Overrides client endpoint. */ endpoint?: string; - /** - * Gets or sets the audience to use for authentication with Azure Active Directory. - * The authentication scope will be set from this audience. - * Defaults to "https://management.azure.com/.default" - */ - audience?: string; } /** @@ -56,6 +50,7 @@ export class MetricsQueryClient { private _metricsClient: GeneratedMetricsClient; private _definitionsClient: GeneratedMetricsDefinitionsClient; private _namespacesClient: GeneratedMetricsNamespacesClient; + private _audience?: string; /** * Creates a MetricsQueryClient. @@ -63,8 +58,9 @@ export class MetricsQueryClient { * @param options - Options for the client like controlling request retries. */ constructor(tokenCredential: TokenCredential, options?: MetricsQueryClientOptions) { + this._audience = `${options?.endpoint}/.default`; const credentialOptions = { - credentialScopes: options?.audience + credentialScopes: this._audience }; const packageDetails = `azsdk-js-monitor-query/${SDK_VERSION}`; const userAgentPrefix = diff --git a/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts b/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts index dc3aa15db757..3c81a14619b2 100644 --- a/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts +++ b/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts @@ -29,8 +29,7 @@ describe("LogsQueryClient unit tests", () => { }; const client = new LogsQueryClient(tokenCredential, { - endpoint: "https://customEndpoint1", - audience: "https://customscopes1/" + endpoint: "https://customEndpoint1" }); assert.equal(client["_logAnalytics"].$host, "https://customEndpoint1"); @@ -45,6 +44,6 @@ describe("LogsQueryClient unit tests", () => { }); } - assert.deepEqual(scopesPassed, ["https://customscopes1/"]); + // assert.deepEqual(scopesPassed, ["https://customscopes1/"]); }); }); From fe3c38589c5a8c4d046a5b1701b1d543453a56ca Mon Sep 17 00:00:00 2001 From: Karishma Ghiya Date: Wed, 6 Oct 2021 18:03:40 -0700 Subject: [PATCH 2/5] update api --- sdk/monitor/monitor-query/CHANGELOG.md | 3 +-- sdk/monitor/monitor-query/review/monitor-query.api.md | 1 - sdk/monitor/monitor-query/src/logsQueryClient.ts | 11 +---------- sdk/monitor/monitor-query/src/metricsQueryClient.ts | 4 +--- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/sdk/monitor/monitor-query/CHANGELOG.md b/sdk/monitor/monitor-query/CHANGELOG.md index 15337620adfa..d88280d0973f 100644 --- a/sdk/monitor/monitor-query/CHANGELOG.md +++ b/sdk/monitor/monitor-query/CHANGELOG.md @@ -4,7 +4,6 @@ ### Features Added -- Added `audience` property in `MetricsClientOptions` - Enabled browser support - Added different result objects `LogsQueryPartialResult`, `LogsQuerySuccessfulResult` or `LogsQueryError` based on the success scenarios for log queries. @@ -13,11 +12,11 @@ - Renamed `ErrorInfo` to `LogsErrorInfo`, which now extends the `Error` class and `code` as an additional property. Removed all the other properties. - `query` method in `LogsQueryClient` renamed to `queryWorkspace` - `query` method in `MetricsQueryClient` renamed to `queryResource` -- Renamed `credentialOptions.credentialScopes` property in `LogsQueryClientOptions` to `audience` - Renamed the status types in `LogsQueryResultStatus`. `Partial` to `PartialFailure` and `Failed` to `Failure`. - Renamed `timeGrain` in `MetricAvailability` to `granularity` - Renamed `TimeInterval` to `QueryTimeInterval` - Updated constants in `Durations` to camel-case. +- Removed `credentialOptions.credentialScopes` property in `LogsQueryClientOptions` since scopes other than default are not supported yet. - Removed `throwOnAnyError` flag from `LogsQueryOptions` and `LogsQueryBatchOptions` - Removed the error classes `BatchError` and `AggregateBatchError` - Updated `LogsQueryBatchResult` object to be a list of objects with the following possible types: diff --git a/sdk/monitor/monitor-query/review/monitor-query.api.md b/sdk/monitor/monitor-query/review/monitor-query.api.md index 75870637bd24..9327d5c3556a 100644 --- a/sdk/monitor/monitor-query/review/monitor-query.api.md +++ b/sdk/monitor/monitor-query/review/monitor-query.api.md @@ -66,7 +66,6 @@ export class LogsQueryClient { // @public export interface LogsQueryClientOptions extends CommonClientOptions { - _audience?: string; endpoint?: string; } diff --git a/sdk/monitor/monitor-query/src/logsQueryClient.ts b/sdk/monitor/monitor-query/src/logsQueryClient.ts index 07dcf60aa09d..6004c39d323f 100644 --- a/sdk/monitor/monitor-query/src/logsQueryClient.ts +++ b/sdk/monitor/monitor-query/src/logsQueryClient.ts @@ -37,13 +37,6 @@ export interface LogsQueryClientOptions extends CommonClientOptions { * The host to connect to. */ endpoint?: string; - - /** - * Gets or sets the audience to use for authentication with Azure Active Directory. - * The authentication scope will be set from this audience. - * Defaults to 'https://api.loganalytics.io/.default' - */ - _audience?: string; } /** @@ -51,7 +44,6 @@ export interface LogsQueryClientOptions extends CommonClientOptions { */ export class LogsQueryClient { private _logAnalytics: AzureLogAnalytics; - private _audience?: string; /** * Construct a LogsClient that can be used to query logs using the Log Analytics Query language. @@ -62,9 +54,8 @@ export class LogsQueryClient { constructor(tokenCredential: TokenCredential, options?: LogsQueryClientOptions) { // This client defaults to using 'https://api.loganalytics.io/' as the // host. - this._audience = `${options?.endpoint}./default`; const credentialOptions = { - credentialScopes: this._audience + credentialScopes: `${options?.endpoint}./default` }; const packageDetails = `azsdk-js-monitor-query/${SDK_VERSION}`; const userAgentPrefix = diff --git a/sdk/monitor/monitor-query/src/metricsQueryClient.ts b/sdk/monitor/monitor-query/src/metricsQueryClient.ts index 3e5bbda1d3b6..aba45f2451ba 100644 --- a/sdk/monitor/monitor-query/src/metricsQueryClient.ts +++ b/sdk/monitor/monitor-query/src/metricsQueryClient.ts @@ -50,7 +50,6 @@ export class MetricsQueryClient { private _metricsClient: GeneratedMetricsClient; private _definitionsClient: GeneratedMetricsDefinitionsClient; private _namespacesClient: GeneratedMetricsNamespacesClient; - private _audience?: string; /** * Creates a MetricsQueryClient. @@ -58,9 +57,8 @@ export class MetricsQueryClient { * @param options - Options for the client like controlling request retries. */ constructor(tokenCredential: TokenCredential, options?: MetricsQueryClientOptions) { - this._audience = `${options?.endpoint}/.default`; const credentialOptions = { - credentialScopes: this._audience + credentialScopes: `${options?.endpoint}/.default` }; const packageDetails = `azsdk-js-monitor-query/${SDK_VERSION}`; const userAgentPrefix = From 4d78c4d3803200a4bdd7920746237dda319f313f Mon Sep 17 00:00:00 2001 From: Karishma Ghiya Date: Wed, 6 Oct 2021 23:00:16 -0700 Subject: [PATCH 3/5] fix scope --- sdk/monitor/monitor-query/src/logsQueryClient.ts | 6 +++++- sdk/monitor/monitor-query/src/metricsQueryClient.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sdk/monitor/monitor-query/src/logsQueryClient.ts b/sdk/monitor/monitor-query/src/logsQueryClient.ts index 6004c39d323f..d969d032cecd 100644 --- a/sdk/monitor/monitor-query/src/logsQueryClient.ts +++ b/sdk/monitor/monitor-query/src/logsQueryClient.ts @@ -54,8 +54,12 @@ export class LogsQueryClient { constructor(tokenCredential: TokenCredential, options?: LogsQueryClientOptions) { // This client defaults to using 'https://api.loganalytics.io/' as the // host. + let scope; + if (options?.endpoint) { + scope = `${options?.endpoint}./default`; + } const credentialOptions = { - credentialScopes: `${options?.endpoint}./default` + credentialScopes: scope }; const packageDetails = `azsdk-js-monitor-query/${SDK_VERSION}`; const userAgentPrefix = diff --git a/sdk/monitor/monitor-query/src/metricsQueryClient.ts b/sdk/monitor/monitor-query/src/metricsQueryClient.ts index aba45f2451ba..5df900735f4c 100644 --- a/sdk/monitor/monitor-query/src/metricsQueryClient.ts +++ b/sdk/monitor/monitor-query/src/metricsQueryClient.ts @@ -57,8 +57,12 @@ export class MetricsQueryClient { * @param options - Options for the client like controlling request retries. */ constructor(tokenCredential: TokenCredential, options?: MetricsQueryClientOptions) { + let scope; + if (options?.endpoint) { + scope = `${options?.endpoint}./default`; + } const credentialOptions = { - credentialScopes: `${options?.endpoint}/.default` + credentialScopes: scope }; const packageDetails = `azsdk-js-monitor-query/${SDK_VERSION}`; const userAgentPrefix = From 2b44ddf572d7f3b718ab3267609b9932768e7f9c Mon Sep 17 00:00:00 2001 From: KarishmaGhiya Date: Wed, 6 Oct 2021 23:02:28 -0700 Subject: [PATCH 4/5] Update sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts Co-authored-by: Jeremy Meng --- .../test/internal/unit/logsQueryClient.unittest.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts b/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts index 3c81a14619b2..28acf19b98cc 100644 --- a/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts +++ b/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts @@ -44,6 +44,5 @@ describe("LogsQueryClient unit tests", () => { }); } - // assert.deepEqual(scopesPassed, ["https://customscopes1/"]); }); }); From 4e01108995260d0a247efe1ba531140fe3edac4d Mon Sep 17 00:00:00 2001 From: Karishma Ghiya Date: Wed, 6 Oct 2021 23:15:50 -0700 Subject: [PATCH 5/5] fix format --- .../test/internal/unit/logsQueryClient.unittest.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts b/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts index 28acf19b98cc..a275d71f2965 100644 --- a/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts +++ b/sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts @@ -43,6 +43,5 @@ describe("LogsQueryClient unit tests", () => { message: "Shortcircuit auth exception" }); } - }); });