-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[monitor-query] Allowing for passing a custom endpoint and custom aut…
…horization scopes. (#15705) This PR makes it so you can pass in a custom endpoint and custom scopes for authentication. Without these you can't properly connect to government-based clouds. Example usage: ```typescript const dac = new DefaultAzureCredential({ authorityHost: AzureAuthorityHosts.AzureGovernment }); const client = new LogsQueryClient(dac, { endpoint: "https://api.loganalytics.us/v1", scopes: "https://api.loganalytics.us/.default" }); ``` Fixes #15663
- Loading branch information
1 parent
c4f51be
commit 9167bc3
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
sdk/monitor/monitor-query/test/internal/unit/logsQueryClient.unittest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { Durations, LogsQueryClient } from "../../../src"; | ||
import { AccessToken, GetTokenOptions, TokenCredential } from "@azure/core-auth"; | ||
import { assert } from "chai"; | ||
|
||
describe("LogsQueryClient unit tests", () => { | ||
/** | ||
* Custom scopes and endpoints are needed if you're connecting to | ||
* a government cloud, for instance. | ||
*/ | ||
it("using custom scopes and endpoints", async () => { | ||
const scopesPassed: string[] = []; | ||
|
||
const tokenCredential: TokenCredential = { | ||
async getToken( | ||
scopes: string | string[], | ||
_options?: GetTokenOptions | ||
): Promise<AccessToken | null> { | ||
if (Array.isArray(scopes)) { | ||
scopesPassed.push(...scopes); | ||
} else { | ||
scopesPassed.push(scopes); | ||
} | ||
|
||
throw new Error("Shortcircuit auth exception"); | ||
} | ||
}; | ||
|
||
const client = new LogsQueryClient(tokenCredential, { | ||
endpoint: "customEndpoint1", | ||
scopes: "customScopes1" | ||
}); | ||
|
||
assert.equal(client["_logAnalytics"].$host, "customEndpoint1"); | ||
assert.equal(client["_logAnalytics"]["baseUri"], "customEndpoint1"); | ||
|
||
try { | ||
await client.queryLogs("workspaceId", "query", Durations.last5Minutes); | ||
assert.fail("Should have thrown"); | ||
} catch (err) { | ||
assert.deepNestedInclude(err, { | ||
message: "Shortcircuit auth exception" | ||
}); | ||
} | ||
|
||
assert.deepEqual(scopesPassed, ["customScopes1"]); | ||
}); | ||
}); |