-
Notifications
You must be signed in to change notification settings - Fork 2
Load From Azure Front Door #123
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
Open
zhiyuanliang-ms
wants to merge
72
commits into
preview
Choose a base branch
from
zhiyuanliang/enforce-api-version-for-cdn
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
ce9f550
use pipeline policy to ensure cdn request uses correct api version
zhiyuanliang-ms 2adadc7
fix lint & add comments
zhiyuanliang-ms 30108ab
update
zhiyuanliang-ms 197db89
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms 04d8a2c
update
zhiyuanliang-ms bf99b31
fix lint
zhiyuanliang-ms 14364c5
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms 62ac2b9
add request tracing for cdn
zhiyuanliang-ms bd1c875
only send conditional request when cdn is not used
zhiyuanliang-ms 0856707
add testcase
zhiyuanliang-ms 2b78b27
fix lint
zhiyuanliang-ms fdd30e2
refresh based on page etag
zhiyuanliang-ms c886936
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms 2a7399b
merge preview
zhiyuanliang-ms b4afe7a
merge preview
zhiyuanliang-ms 50fc5b6
remove watchAll & reorganize the code
zhiyuanliang-ms 70bbdee
add testcase
zhiyuanliang-ms d8103a5
fix lint & update method name
zhiyuanliang-ms e123f0e
resolve merge conflict
zhiyuanliang-ms 6958ad5
add comment
zhiyuanliang-ms 635ca48
Merge branch 'zhiyuanliang/register-all-refresh' of https://github.co…
zhiyuanliang-ms 61e4a65
not use conditional request
zhiyuanliang-ms 4f36a1c
fix vulnerability
zhiyuanliang-ms d325127
resolve merge conflict
zhiyuanliang-ms 647c7a6
resolve conflict
zhiyuanliang-ms b74e983
update variable name
zhiyuanliang-ms eec7114
merge
zhiyuanliang-ms 01a7034
move public method
zhiyuanliang-ms 0fb81da
Merge branch 'zhiyuanliang/register-all-refresh' of https://github.co…
zhiyuanliang-ms b0ab944
append etag to url
zhiyuanliang-ms c094801
update
zhiyuanliang-ms bbf1938
update
zhiyuanliang-ms f3ac831
add more comments
zhiyuanliang-ms e6fea3c
merge preview
zhiyuanliang-ms 072bcdf
Merge branch 'zhiyuanliang/register-all-refresh' of https://github.co…
zhiyuanliang-ms 356e664
fix lint
zhiyuanliang-ms 2b95ab4
resolve merge conflict
zhiyuanliang-ms d3c2799
resolve merge conflict
zhiyuanliang-ms 290d338
merge preview
zhiyuanliang-ms ea7709e
merge
zhiyuanliang-ms 8ed48b5
merge preview
zhiyuanliang-ms 6e34f62
resolve merge conflict
zhiyuanliang-ms 14dbe96
update
zhiyuanliang-ms 8441b32
resolve copilot comment
zhiyuanliang-ms 6fe042a
fix lint
zhiyuanliang-ms 33a5964
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms f23ebe4
Merge branch 'preview' into zhiyuanliang/enforce-api-version-for-cdn
zhiyuanliang-ms e77d37d
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms 41ad554
fix lint
zhiyuanliang-ms 334a047
update testcase
zhiyuanliang-ms 9dec453
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms e457605
update
zhiyuanliang-ms 12b0216
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms c096a50
update
zhiyuanliang-ms 811b0e4
fix lint
zhiyuanliang-ms 03d956d
disable replica discovery for CDN
zhiyuanliang-ms 96df9d9
WIP
zhiyuanliang-ms ac33118
update to latest design
zhiyuanliang-ms 3528e87
update
zhiyuanliang-ms f688702
Merge branch 'preview' of https://github.com/Azure/AppConfiguration-J…
zhiyuanliang-ms 19b70c2
update
zhiyuanliang-ms a30b421
update naming
zhiyuanliang-ms 3f05285
update
zhiyuanliang-ms 4f99512
rename api to loadFromAzureFrontDoor
zhiyuanliang-ms 08f4732
update error message
zhiyuanliang-ms c0ae98a
add policy to remove authorization header
zhiyuanliang-ms c061b98
add test
zhiyuanliang-ms 9254069
Merge branch 'zhiyuanliang/enforce-api-version-for-cdn' of https://gi…
zhiyuanliang-ms 3005407
fix lint
zhiyuanliang-ms f367161
update
zhiyuanliang-ms d74fdd2
add cache break token test
zhiyuanliang-ms 333eb3b
update request tracing testcase
zhiyuanliang-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { PipelinePolicy } from "@azure/core-rest-pipeline"; | ||
import { getCryptoModule } from "../common/utils.js"; | ||
|
||
const CDN_TOKEN_QUERY_PARAMETER = "_"; | ||
const RESOURCE_DELETED_PREFIX = "ResourceDeleted"; | ||
|
||
export const CDN_TOKEN_LOOKUP_HEADER = "cdn-token-lookup"; | ||
|
||
/** | ||
* The pipeline policy that retrieves the CDN token from the request header and appends it to the request URL. After that the lookup header is removed from the request. | ||
* @remarks | ||
* The policy position should be perCall. | ||
* The App Configuration service will not recognize the CDN token query parameter in the url, but this can help to break the CDN cache as the cache entry is based on the URL. | ||
*/ | ||
export class CdnTokenPipelinePolicy implements PipelinePolicy { | ||
name: string = "AppConfigurationCdnTokenPolicy"; | ||
|
||
async sendRequest(request, next) { | ||
if (request.headers.has(CDN_TOKEN_LOOKUP_HEADER)) { | ||
const token = request.headers.get(CDN_TOKEN_LOOKUP_HEADER); | ||
request.headers.delete(CDN_TOKEN_LOOKUP_HEADER); | ||
|
||
const url = new URL(request.url); | ||
url.searchParams.append(CDN_TOKEN_QUERY_PARAMETER, token); // _ is a dummy query parameter to break the CDN cache | ||
request.url = url.toString(); | ||
} | ||
|
||
return next(request); | ||
} | ||
} | ||
|
||
/** | ||
* Calculates a cache consistency token for a deleted resource based on its previous ETag. | ||
* @param etag - The previous ETag of the deleted resource. | ||
*/ | ||
export async function calculateResourceDeletedCacheConsistencyToken(etag: string): Promise<string> { | ||
const crypto = getCryptoModule(); | ||
const rawString = `${RESOURCE_DELETED_PREFIX}\n${etag}`; | ||
const payload = new TextEncoder().encode(rawString); | ||
// In the browser or Node.js 18+, use crypto.subtle.digest | ||
if (crypto.subtle) { | ||
const hashBuffer = await crypto.subtle.digest("SHA-256", payload); | ||
const hashArray = new Uint8Array(hashBuffer); | ||
const base64String = btoa(String.fromCharCode(...hashArray)); | ||
const base64urlString = base64String.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); | ||
return base64urlString; | ||
} | ||
// Use the crypto module's hash function | ||
else { | ||
const hash = crypto.createHash("sha256").update(payload).digest(); | ||
return hash.toString("base64url"); | ||
} | ||
} | ||
|
||
/** | ||
* The pipeline policy that remove the authorization header from the request to allow anonymous access to the Azure Front Door. | ||
* @remarks | ||
* The policy position should be perRetry, since it should be executed after the "Sign" phase: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-client/src/serviceClient.ts | ||
*/ | ||
export class AnonymousRequestPipelinePolicy implements PipelinePolicy { | ||
name: string = "AppConfigurationAnonymousRequestPolicy"; | ||
|
||
async sendRequest(request, next) { | ||
if (request.headers.has("authorization")) { | ||
request.headers.delete("authorization"); | ||
} | ||
return next(request); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export { load } from "../src"; | ||
export { load, loadFromAzureFrontDoor } from "../src"; | ||
export { CDN_TOKEN_LOOKUP_HEADER } from "../src/azureFrontDoor/cdnRequestPipelinePolicy.js"; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.