Skip to content

Commit 2a07ed3

Browse files
[App Config] Migrate to core-v2 (Azure#20766)
* app-config changes - checkpoint- only 3 test failures * core-rest-pipeline changes * test changes * credential fix * skip { timeout: 1 } tests in playback for now * lint:fix * expand throttlingRetryStrategy with "retry-after-ms", "x-ms-retry-after-ms" headers * Expand test suite with "retry-after-ms" and "x-ms-retry-after-ms" * changelog * lock file * rely on core's throttling policy * changelog * "version": "1.3.2" -> "version": "1.4.0", * Update sdk/core/core-rest-pipeline/src/retryStrategies/throttlingRetryStrategy.ts * no new variable * no internal tag * refactor * new lines for readability * more refactor * Update sdk/core/core-rest-pipeline/src/retryStrategies/throttlingRetryStrategy.ts * part of the feedback * lint * Update sdk/core/core-rest-pipeline/src/retryStrategies/throttlingRetryStrategy.ts Co-authored-by: Jeff Fisher <[email protected]> * format and lock file * lock file * lock file * sarangan feedback * @azure/core-http-compat * remove comments * default * do not let status code to be 0 * api report * lock file * lock file * lock file and formatting * _response is back * CHANGELOG * 1.4.0-beta.1 * revert * lock file * fixes * add options * version automate updater * regenrate after deleting to remove appConfigContext file * simplify HttpResponseField instances * helper updates * assertResponse as suggested by Jeff * fix tests * fix tests * changes in core-compat * status code is never undefined * export utils * api report * api report * format * lock filke * changelog * TransferProgressEvent * 1.3.0 * feedback address * Update sdk/appconfiguration/app-configuration/src/internal/helpers.ts Co-authored-by: Jeff Fisher <[email protected]> * Update sdk/appconfiguration/app-configuration/src/internal/synctokenpolicy.ts Co-authored-by: Jeff Fisher <[email protected]> * unneeded excess code * don't throw * remove toUpperCase Co-authored-by: Jeff Fisher <[email protected]>
1 parent 8f0a73b commit 2a07ed3

35 files changed

+2623
-3144
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 1897 additions & 1768 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/appconfiguration/app-configuration/CHANGELOG.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Release History
22

3-
## 1.3.2 (Unreleased)
3+
## 1.4.0-beta.1 (Unreleased)
44

55
### Features Added
66

7+
- Migrated from using `@azure/core-http` to depend on newer version of Core libraries `@azure/core-client` and `@azure/core-rest-pipeline` which bring better maintainability and performance. [#20766](https://github.com/Azure/azure-sdk-for-js/pull/20766). See [Azure Core v1 vs v2](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-rest-pipeline/documentation/core2.md) for more on the difference and benefits of the move.
8+
- As part of the migration to `@azure/core-client` and `@azure/core-rest-pipeline`,
9+
through the operation options, the methods such as `AppConfgurationClient#addConfigurationSetting` can take a callback (`onResponse`) to access the HTTP response. See [Change to the \_response property](https://github.com/Azure/autorest.typescript/wiki/%60core-http%60-dependency-migration-to-%60core-client%60-%60core-rest-pipeline%60#change-to-the-_response-property).
10+
711
### Breaking Changes
812

913
### Bugs Fixed
@@ -101,8 +105,8 @@ This release marks the general availability of the `@azure/app-configuration` pa
101105
```typescript
102106
new AppConfigurationClient(connectionString, {
103107
userAgentOptions: {
104-
userAgentPrefix: "MyUserAgent"
105-
}
108+
userAgentPrefix: "MyUserAgent",
109+
},
106110
});
107111
```
108112

@@ -158,11 +162,11 @@ In previous previews:
158162
await client.getConfigurationSetting("MyKey", { label: "MyLabel" });
159163
await client.addConfigurationSetting("MyKey", {
160164
label: "MyLabel",
161-
value: "MyValue"
165+
value: "MyValue",
162166
});
163167
await client.setConfigurationSetting("MyKey", {
164168
label: "MyLabel",
165-
value: "MyValue"
169+
value: "MyValue",
166170
});
167171
await client.deleteConfigurationSetting("MyKey", { label: "MyLabel" });
168172
```
@@ -175,12 +179,12 @@ await client.getConfigurationSetting({ key: "MyKey", label: "MyLabel" });
175179
await client.addConfigurationSetting({
176180
key: "MyKey",
177181
label: "MyLabel",
178-
value: "MyValue"
182+
value: "MyValue",
179183
});
180184
await client.setConfigurationSetting({
181185
key: "MyKey",
182186
label: "MyLabel",
183-
value: "MyValue"
187+
value: "MyValue",
184188
});
185189
await client.deleteConfigurationSetting({ key: "MyKey", label: "MyLabel" });
186190
```

sdk/appconfiguration/app-configuration/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@azure/app-configuration",
33
"author": "Microsoft Corporation",
44
"description": "An isomorphic client library for the Azure App Configuration service.",
5-
"version": "1.3.2",
5+
"version": "1.4.0-beta.1",
66
"sdk-type": "client",
77
"keywords": [
88
"node",
@@ -81,14 +81,20 @@
8181
{
8282
"path": "src/generated/src/appConfigurationContext.ts",
8383
"prefix": "packageVersion"
84+
},
85+
{
86+
"path": "swagger/swagger.md",
87+
"prefix": "package-version"
8488
}
8589
]
8690
},
8791
"dependencies": {
8892
"@azure/abort-controller": "^1.0.0",
8993
"@azure/core-asynciterator-polyfill": "^1.0.0",
90-
"@azure/core-http": "^2.0.0",
94+
"@azure/core-client": "^1.5.0",
95+
"@azure/core-http-compat": "^1.2.0",
9196
"@azure/core-paging": "^1.1.1",
97+
"@azure/core-rest-pipeline": "^1.6.0",
9298
"@azure/core-tracing": "1.0.0-preview.13",
9399
"@azure/core-auth": "^1.3.0",
94100
"tslib": "^2.2.0"
@@ -110,6 +116,7 @@
110116
"@types/mocha": "^7.0.2",
111117
"@types/node": "^12.0.0",
112118
"@types/sinon": "^9.0.4",
119+
"@types/uuid": "^8.3.4",
113120
"chai": "^4.2.0",
114121
"dotenv": "^8.2.0",
115122
"eslint": "^7.15.0",
@@ -139,6 +146,7 @@
139146
"ts-node": "^10.0.0",
140147
"typescript": "~4.2.0",
141148
"uglify-js": "^3.4.9",
149+
"uuid": "^8.3.0",
142150
"cross-env": "^7.0.2"
143151
},
144152
"//sampleConfiguration": {

sdk/appconfiguration/app-configuration/review/app-configuration.api.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
/// <reference lib="esnext.asynciterable" />
88

9-
import { HttpResponse } from '@azure/core-http';
10-
import { OperationOptions } from '@azure/core-http';
9+
import { CommonClientOptions } from '@azure/core-client';
10+
import { CompatResponse } from '@azure/core-http-compat';
11+
import { OperationOptions } from '@azure/core-client';
1112
import { PagedAsyncIterableIterator } from '@azure/core-paging';
1213
import { TokenCredential } from '@azure/core-auth';
13-
import { UserAgentOptions } from '@azure/core-http';
1414

1515
// @public
1616
export interface AddConfigurationSettingOptions extends OperationOptions {
@@ -38,9 +38,7 @@ export class AppConfigurationClient {
3838
}
3939

4040
// @public
41-
export interface AppConfigurationClientOptions {
42-
retryOptions?: RetryOptions;
43-
userAgentOptions?: UserAgentOptions;
41+
export interface AppConfigurationClientOptions extends CommonClientOptions {
4442
}
4543

4644
// @public
@@ -124,7 +122,7 @@ export interface HttpOnlyIfUnchangedField {
124122

125123
// @public
126124
export interface HttpResponseField<HeadersT> {
127-
_response: HttpResponse & {
125+
_response: CompatResponse & {
128126
parsedHeaders: HeadersT;
129127
bodyAsText: string;
130128
};

sdk/appconfiguration/app-configuration/src/appConfigCredential.ts

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,41 @@
22
// Licensed under the MIT license.
33

44
import {
5-
ServiceClientCredentials,
6-
WebResource,
7-
URLBuilder,
8-
WebResourceLike,
9-
} from "@azure/core-http";
5+
PipelinePolicy,
6+
PipelineRequest,
7+
PipelineResponse,
8+
SendRequest,
9+
} from "@azure/core-rest-pipeline";
1010
import { sha256Digest, sha256Hmac } from "./internal/cryptoHelpers";
1111

1212
/**
13-
* @internal
13+
* Create an HTTP pipeline policy to authenticate a request
14+
* using an `AzureKeyCredential` for AppConfig.
1415
*/
15-
export class AppConfigCredential implements ServiceClientCredentials {
16-
private credential: string;
17-
private secret: string;
18-
19-
constructor(credential: string, secret: string) {
20-
this.credential = credential;
21-
this.secret = secret;
22-
}
23-
24-
/**
25-
* Signs a request with the values provided in the credential and secret parameter.
26-
*
27-
* @param webResource - The WebResource to be signed.
28-
* @returns The signed request object.
29-
*/
30-
async signRequest(webResource: WebResourceLike): Promise<WebResource> {
31-
const verb = webResource.method.toUpperCase();
32-
const utcNow = new Date().toUTCString();
33-
34-
const contentHash = await sha256Digest(webResource.body || "");
35-
36-
const signedHeaders = "x-ms-date;host;x-ms-content-sha256";
37-
38-
const url = URLBuilder.parse(webResource.url);
39-
const query = url.getQuery();
40-
const urlPathAndQuery = `${url.getPath()}${query ? "?" + query : ""}`;
41-
42-
const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${url.getHost()};${contentHash}`;
43-
44-
const signature = await sha256Hmac(this.secret, stringToSign);
45-
46-
webResource.headers.set("x-ms-date", utcNow);
47-
webResource.headers.set("x-ms-content-sha256", contentHash);
48-
// Syntax for Authorization header
49-
// Reference - https://docs.microsoft.com/en-us/azure/azure-app-configuration/rest-api-authentication-hmac#syntax
50-
webResource.headers.set(
51-
"Authorization",
52-
`HMAC-SHA256 Credential=${this.credential}&SignedHeaders=${signedHeaders}&Signature=${signature}`
53-
);
54-
return webResource;
55-
}
16+
export function appConfigKeyCredentialPolicy(credential: string, secret: string): PipelinePolicy {
17+
return {
18+
name: "AppConfigKeyCredentialPolicy",
19+
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {
20+
const verb = request.method;
21+
const utcNow = new Date().toUTCString();
22+
const contentHash = await sha256Digest(request.body?.toString() || "");
23+
const signedHeaders = "x-ms-date;host;x-ms-content-sha256";
24+
const url = new URL(request.url);
25+
const query = url.search;
26+
const urlPathAndQuery = query ? `${url.pathname}${query}` : url.pathname;
27+
const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${url.host};${contentHash}`;
28+
const signature = await sha256Hmac(secret, stringToSign);
29+
30+
request.headers.set("x-ms-date", utcNow);
31+
request.headers.set("x-ms-content-sha256", contentHash);
32+
// Syntax for Authorization header
33+
// Reference - https://docs.microsoft.com/en-us/azure/azure-app-configuration/rest-api-authentication-hmac#syntax
34+
request.headers.set(
35+
"Authorization",
36+
`HMAC-SHA256 Credential=${credential}&SignedHeaders=${signedHeaders}&Signature=${signature}`
37+
);
38+
39+
return next(request);
40+
},
41+
};
5642
}

0 commit comments

Comments
 (0)