Skip to content

Commit

Permalink
[app-configuration] Remove manual instrumentation of each method for …
Browse files Browse the repository at this point in the history
…syncToken and just use the policy correctly (it can handle requests _and_ responses) (#6466)
  • Loading branch information
richardpark-msft committed Dec 9, 2019
1 parent ad0bf9a commit f1552d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
Expand Up @@ -51,7 +51,7 @@ import {
import { tracingPolicy } from "@azure/core-http";
import { Spanner } from "./internal/tracingHelpers";
import { GetKeyValuesResponse, AppConfigurationOptions } from "./generated/src/models";
import { syncTokenPolicy, SyncTokens, SyncTokenHeaderName } from './internal/synctokenpolicy';
import { syncTokenPolicy, SyncTokens } from './internal/synctokenpolicy';

const apiVersion = "1.0";
const ConnectionStringRegex = /Endpoint=(.*);Id=(.*);Secret=(.*)/;
Expand Down Expand Up @@ -90,7 +90,6 @@ export interface InternalAppConfigurationClientOptions extends AppConfigurationC
export class AppConfigurationClient {
private client: AppConfiguration;
private spanner: Spanner<AppConfigurationClient>;
private _syncTokens: SyncTokens;

/**
* Initializes a new instance of the AppConfigurationClient class.
Expand All @@ -112,17 +111,17 @@ export class AppConfigurationClient {
options?:AppConfigurationClientOptions
) {
if (isTokenCredential(tokenCredentialOrOptions)) {
this._syncTokens =
const syncTokens =
(options && (options as InternalAppConfigurationClientOptions).syncTokens) ||
new SyncTokens();

this.client = new AppConfiguration(
tokenCredentialOrOptions,
apiVersion,
getAppConfigurationOptions(connectionStringOrEndpoint, this._syncTokens)
getAppConfigurationOptions(connectionStringOrEndpoint, syncTokens)
);
} else {
this._syncTokens =
const syncTokens =
(tokenCredentialOrOptions &&
(tokenCredentialOrOptions as InternalAppConfigurationClientOptions).syncTokens) ||
new SyncTokens();
Expand All @@ -134,7 +133,7 @@ export class AppConfigurationClient {
this.client = new AppConfiguration(
appConfigCredential,
apiVersion,
getAppConfigurationOptions(regexMatch[1], this._syncTokens)
getAppConfigurationOptions(regexMatch[1], syncTokens)
);
} else {
throw new Error(
Expand Down Expand Up @@ -170,8 +169,6 @@ export class AppConfigurationClient {
...newOptions
});

this._syncTokens.addSyncTokenFromHeaderValue(originalResponse._response.headers.get(SyncTokenHeaderName));

return transformKeyValueResponse(originalResponse);
});
}
Expand All @@ -198,8 +195,6 @@ export class AppConfigurationClient {
...checkAndFormatIfAndIfNoneMatch(id, options)
});

this._syncTokens.addSyncTokenFromHeaderValue(originalResponse._response.headers.get(SyncTokenHeaderName));

return transformKeyValueResponseWithStatusCode(originalResponse);
});
}
Expand Down Expand Up @@ -228,8 +223,6 @@ export class AppConfigurationClient {
...checkAndFormatIfAndIfNoneMatch(id, options)
});

this._syncTokens.addSyncTokenFromHeaderValue(originalResponse._response.headers.get(SyncTokenHeaderName));

const response: GetConfigurationSettingResponse = transformKeyValueResponseWithStatusCode(
originalResponse
);
Expand Down Expand Up @@ -303,8 +296,6 @@ export class AppConfigurationClient {
...formatWildcards(newOptions)
});

this._syncTokens.addSyncTokenFromHeaderValue(response._response.headers.get(SyncTokenHeaderName));

return response;
}
);
Expand All @@ -323,8 +314,6 @@ export class AppConfigurationClient {
after: extractAfterTokenFromNextLink(currentResponse.nextLink!)
});

this._syncTokens.addSyncTokenFromHeaderValue(response._response.headers.get(SyncTokenHeaderName));

return response;
}
);
Expand Down Expand Up @@ -395,8 +384,6 @@ export class AppConfigurationClient {
...formatWildcards(newOptions)
});

this._syncTokens.addSyncTokenFromHeaderValue(response._response.headers.get(SyncTokenHeaderName));

return response;
});

Expand Down Expand Up @@ -451,8 +438,6 @@ export class AppConfigurationClient {
...checkAndFormatIfAndIfNoneMatch(configurationSetting, options)
});

this._syncTokens.addSyncTokenFromHeaderValue(response._response.headers.get(SyncTokenHeaderName));

return transformKeyValueResponse(response);
});
}
Expand All @@ -476,8 +461,6 @@ export class AppConfigurationClient {
...checkAndFormatIfAndIfNoneMatch(id, options)
});

this._syncTokens.addSyncTokenFromHeaderValue(response._response.headers.get(SyncTokenHeaderName));

return transformKeyValueResponse(response);
} else {
const response = await this.client.deleteLock(id.key, {
Expand All @@ -486,8 +469,6 @@ export class AppConfigurationClient {
...checkAndFormatIfAndIfNoneMatch(id, options)
});

this._syncTokens.addSyncTokenFromHeaderValue(response._response.headers.get(SyncTokenHeaderName));

return transformKeyValueResponse(response);
}
});
Expand Down
Expand Up @@ -39,7 +39,9 @@ class SyncTokenPolicy extends BaseRequestPolicy {
webResource.headers.set(SyncTokenHeaderName, syncTokenHeaderValue);
}

return this._nextPolicy.sendRequest(webResource);
const response = await this._nextPolicy.sendRequest(webResource);
this._syncTokens.addSyncTokenFromHeaderValue(response.headers.get(SyncTokenHeaderName));
return response;
}
}

Expand Down

0 comments on commit f1552d7

Please sign in to comment.