Skip to content

Commit 4c331c4

Browse files
update
1 parent 5ede801 commit 4c331c4

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

rollup.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default [
77
external: [
88
"@azure/app-configuration",
99
"@azure/keyvault-secrets",
10+
"@azure/core-client",
1011
"@azure/core-rest-pipeline",
1112
"@azure/identity",
1213
"crypto",

src/AzureAppConfigurationImpl.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4+
import { OperationOptions } from "@azure/core-client";
45
import {
56
AppConfigurationClient,
67
ConfigurationSetting,
@@ -516,19 +517,17 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
516517
);
517518
for (const selector of selectorsToUpdate) {
518519
if (selector.snapshotName === undefined) {
519-
let listOptions: ListConfigurationSettingsOptions = {
520+
const listOptions: ListConfigurationSettingsOptions = {
520521
keyFilter: selector.keyFilter,
521522
labelFilter: selector.labelFilter,
522523
tagsFilter: selector.tagFilters
523524
};
524525

525526
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
526527
if (this.#isCdnUsed && selectorCollection.cdnToken) {
527-
listOptions = {
528-
...listOptions,
529-
requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken }}
530-
};
528+
this.#addCdnTokenLookupHeader(listOptions, selectorCollection.cdnToken);
531529
}
530+
532531
const pageEtags: string[] = [];
533532
const pageIterator = listConfigurationSettingsWithTrace(
534533
this.#requestTraceOptions,
@@ -631,10 +630,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
631630
sentinel.etag = loaded.etag;
632631
} else {
633632
// Send a request to retrieve watched key-value since it may be either not loaded or loaded with a different selector
634-
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
635-
let getOptions: GetConfigurationSettingOptions = {};
633+
const getOptions: GetConfigurationSettingOptions = {};
636634
if (this.#isCdnUsed && this.#kvSelectorCollection.cdnToken) {
637-
getOptions = { requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: this.#kvSelectorCollection.cdnToken } } };
635+
this.#addCdnTokenLookupHeader(getOptions, this.#kvSelectorCollection.cdnToken);
638636
}
639637
const response = await this.#getConfigurationSetting(sentinel, getOptions);
640638
sentinel.etag = response?.etag;
@@ -691,16 +689,14 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
691689
}
692690
// if watchAll is true, there should be no sentinels
693691
for (const sentinel of this.#sentinels.values()) {
694-
// if CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
695-
let getOptions: GetConfigurationSettingOptions = {};
692+
const getOptions: GetConfigurationSettingOptions = {
693+
// send conditional request only when CDN is not used
694+
onlyIfChanged: !this.#isCdnUsed
695+
};
696696
if (this.#isCdnUsed && this.#kvSelectorCollection.cdnToken) {
697-
// if CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
698-
getOptions = {
699-
requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: this.#kvSelectorCollection.cdnToken ?? "" } },
700-
};
697+
this.#addCdnTokenLookupHeader(getOptions, this.#kvSelectorCollection.cdnToken);
701698
}
702-
// send conditional request only when CDN is not used
703-
const response = await this.#getConfigurationSetting(sentinel, { ...getOptions, onlyIfChanged: !this.#isCdnUsed });
699+
const response = await this.#getConfigurationSetting(sentinel, getOptions);
704700

705701
if ((response?.statusCode === 200 && sentinel.etag !== response?.etag) ||
706702
(response === undefined && sentinel.etag !== undefined) // deleted
@@ -777,24 +773,17 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
777773
if (selector.snapshotName) { // skip snapshot selector
778774
continue;
779775
}
780-
let listOptions: ListConfigurationSettingsOptions = {
776+
const listOptions: ListConfigurationSettingsOptions = {
781777
keyFilter: selector.keyFilter,
782778
labelFilter: selector.labelFilter,
783779
tagsFilter: selector.tagFilters
784780
};
785781

786782
if (!this.#isCdnUsed) {
787783
// if CDN is not used, add page etags to the listOptions to send conditional request
788-
listOptions = {
789-
...listOptions,
790-
pageEtags: selector.pageEtags
791-
};
784+
listOptions.pageEtags = selector.pageEtags;
792785
} else if (selectorCollection.cdnToken) {
793-
// If CDN is used, add etag to request header so that the pipeline policy can retrieve and append it to the request URL
794-
listOptions = {
795-
...listOptions,
796-
requestOptions: { customHeaders: { [CDN_TOKEN_LOOKUP_HEADER]: selectorCollection.cdnToken } }
797-
};
786+
this.#addCdnTokenLookupHeader(listOptions, selectorCollection.cdnToken);
798787
}
799788

800789
const pageIterator = listConfigurationSettingsWithTrace(
@@ -1132,6 +1121,16 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
11321121
return first15Bytes.toString("base64url");
11331122
}
11341123
}
1124+
1125+
#addCdnTokenLookupHeader(operationOptions: OperationOptions, cdnToken: string): void {
1126+
if (!operationOptions.requestOptions) {
1127+
operationOptions.requestOptions = {};
1128+
}
1129+
if (!operationOptions.requestOptions.customHeaders) {
1130+
operationOptions.requestOptions.customHeaders = {};
1131+
}
1132+
operationOptions.requestOptions.customHeaders[CDN_TOKEN_LOOKUP_HEADER] = cdnToken;
1133+
}
11351134
}
11361135

11371136
function getValidSettingSelectors(selectors: SettingSelector[]): SettingSelector[] {

0 commit comments

Comments
 (0)