Skip to content

Commit 71a971e

Browse files
authored
[appconfiguration] Update snippets (#32487)
### Packages impacted by this PR - @azure/app-configuration - @azure/arm-appconfiguration ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `appconfiguration` to use snippets extraction. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent f93ec86 commit 71a971e

File tree

10 files changed

+642
-170
lines changed

10 files changed

+642
-170
lines changed

sdk/appconfiguration/app-configuration/CHANGELOG.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- dev-tool snippets ignore -->
2+
13
# Release History
24

35
## 1.8.1 (Unreleased)
@@ -20,7 +22,7 @@
2022

2123
### Features Added
2224

23-
- Support `listLabels` method to list all the labels in the configuration setting store.
25+
- Support `listLabels` method to list all the labels in the configuration setting store.
2426

2527
Example:
2628

@@ -39,9 +41,10 @@ const allProdTags = client.listConfigurationSettings({
3941
tagsFilter: ["production=prod*"],
4042
});
4143
```
44+
4245
See [`listConfigurationSettings.ts`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appconfiguration/app-configuration/samples/v1/typescript/src/listConfigurationSettings.ts) for more information now how to use this feature.
43-
- Add `tagsFilter` in `ConfigurationSettingsFilter` so that you can create snapshot by filtering configuration settings tags.
4446

47+
- Add `tagsFilter` in `ConfigurationSettingsFilter` so that you can create snapshot by filtering configuration settings tags.
4548

4649
## 1.6.1 (2024-07-11)
4750

@@ -65,13 +68,10 @@ See [`listConfigurationSettings.ts`](https://github.com/Azure/azure-sdk-for-js/t
6568

6669
### Features Added
6770

68-
- With the new API version `2023-10-01`, the configuration snapshot feature is generally available.
69-
70-
This feature allows you to create snapshots by specifying key and label filters. These filters help capture the necessary configuration settings from your App Configuration instance, creating an immutable, composed view of the configuration store.
71-
71+
- With the new API version `2023-10-01`, the configuration snapshot feature is generally available.
72+
This feature allows you to create snapshots by specifying key and label filters. These filters help capture the necessary configuration settings from your App Configuration instance, creating an immutable, composed view of the configuration store.
7273
The filtered configuration settings are stored as a snapshot with the name provided during its creation.
73-
`AppConfigurationClient` is enhanced to support new operations such as create, list archive, and recover operations with snapshots.
74-
74+
`AppConfigurationClient` is enhanced to support new operations such as create, list archive, and recover operations with snapshots.
7575
See [`snapshot.ts`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appconfiguration/app-configuration/samples/v1/typescript/src/snapshot.ts) for more information now how to use snapshots.
7676

7777
### Bugs Fixed
@@ -101,6 +101,7 @@ See [`listConfigurationSettings.ts`](https://github.com/Azure/azure-sdk-for-js/t
101101
## 1.4.1 (2023-04-24)
102102

103103
### Features Added
104+
104105
- Added dependency on `@azure/logger` to help with debugging. [#23860](https://github.com/Azure/azure-sdk-for-js/pull/23860)
105106

106107
### Bugs Fixed

sdk/appconfiguration/app-configuration/README.md

+144-81
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ Authentication via service principal is done by:
6161

6262
Using [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md#defaultazurecredential)
6363

64-
```javascript
65-
const azureIdentity = require("@azure/identity");
66-
const appConfig = require("@azure/app-configuration");
67-
68-
const credential = new azureIdentity.DefaultAzureCredential();
69-
const client = new appConfig.AppConfigurationClient(
70-
endpoint, // ex: <https://<your appconfig resource>.azconfig.io>
71-
credential
72-
);
64+
```ts snippet:ReadmeSampleCreateClient_Node
65+
import { DefaultAzureCredential } from "@azure/identity";
66+
import { AppConfigurationClient } from "@azure/app-configuration";
67+
68+
// The endpoint for your App Configuration resource
69+
const endpoint = "https://example.azconfig.io";
70+
const credential = new DefaultAzureCredential();
71+
const client = new AppConfigurationClient(endpoint, credential);
7372
```
7473

7574
More information about `@azure/identity` can be found [here](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md)
@@ -78,14 +77,16 @@ More information about `@azure/identity` can be found [here](https://github.com/
7877

7978
To authenticate with a resource in a [Sovereign Cloud](https://docs.microsoft.com/azure/active-directory/develop/authentication-national-cloud), you will need to set the `authorityHost` in the credential options or via the `AZURE_AUTHORITY_HOST` environment variable.
8079

81-
```javascript
82-
const { AppConfigurationClient } = require("@azure/app-configuration");
83-
const { DefaultAzureCredential, AzureAuthorityHosts } = require("@azure/identity");
80+
```ts snippet:AuthenticatingWithAzureSovereignCloud
81+
import { AppConfigurationClient } from "@azure/app-configuration";
82+
import { DefaultAzureCredential, AzureAuthorityHosts } from "@azure/identity";
8483

84+
// The endpoint for your App Configuration resource
85+
const endpoint = "https://example.azconfig.azure.cn";
8586
// Create an AppConfigurationClient that will authenticate through AAD in the China cloud
8687
const client = new AppConfigurationClient(
87-
endpoint, // ex: <https://<your appconfig resource>.azconfig.azure.cn>
88-
new DefaultAzureCredential({ authorityHost: AzureAuthorityHosts.AzureChina })
88+
endpoint,
89+
new DefaultAzureCredential({ authorityHost: AzureAuthorityHosts.AzureChina }),
8990
);
9091
```
9192

@@ -101,8 +102,11 @@ az appconfig credential list -g <resource-group-name> -n <app-configuration-reso
101102

102103
And in code you can now create your App Configuration client with the **connection string** you got from the Azure CLI:
103104

104-
```typescript
105-
const client = new AppConfigurationClient("<connection string>");
105+
```ts snippet:ReadmeSampleCreateClientWithConnectionString
106+
import { AppConfigurationClient } from "@azure/app-configuration";
107+
108+
const connectionString = "Endpoint=https://example.azconfig.io;XXX=YYYY;YYY=ZZZZ";
109+
const client = new AppConfigurationClient(connectionString);
106110
```
107111

108112
## Key concepts
@@ -117,9 +121,17 @@ The client follows a simple design methodology - [`ConfigurationSetting`](https:
117121

118122
This means this pattern works:
119123

120-
```typescript
124+
```ts snippet:ConfigurationSettingPattern
125+
import { DefaultAzureCredential } from "@azure/identity";
126+
import { AppConfigurationClient } from "@azure/app-configuration";
127+
128+
// The endpoint for your App Configuration resource
129+
const endpoint = "https://example.azconfig.io";
130+
const credential = new DefaultAzureCredential();
131+
const client = new AppConfigurationClient(endpoint, credential);
132+
121133
const setting = await client.getConfigurationSetting({
122-
key: "hello"
134+
key: "hello",
123135
});
124136

125137
setting.value = "new value!";
@@ -136,101 +148,134 @@ await client.deleteConfigurationSetting(setting);
136148

137149
or, for example, re-getting a setting:
138150

139-
```typescript
151+
```ts snippet:ReGetSetting
152+
import { DefaultAzureCredential } from "@azure/identity";
153+
import { AppConfigurationClient } from "@azure/app-configuration";
154+
155+
// The endpoint for your App Configuration resource
156+
const endpoint = "https://example.azconfig.io";
157+
const credential = new DefaultAzureCredential();
158+
const client = new AppConfigurationClient(endpoint, credential);
159+
140160
let setting = await client.getConfigurationSetting({
141-
key: "hello"
161+
key: "hello",
142162
});
143163

144164
// re-get the setting
145165
setting = await client.getConfigurationSetting(setting);
146166
```
147167

148-
The `2022-11-01-preview` API version supports configuration snapshots: immutable, point-in-time copies of a configuration store. Snapshots can be created with filters that determine which key-value pairs are contained within the snapshot, creating an immutable, composed view of the configuration store. This feature enables applications to hold a consistent view of configuration, ensuring that there are no version mismatches to individual settings due to reading as updates were made. For example, this feature can be used to create "release configuration snapshots" within an App Configuration. See [the _create and get a snapshot_ section](#create-and-get-a-setting) in the example below.
168+
The `2022-11-01-preview` API version supports configuration snapshots: immutable, point-in-time copies of a configuration store. Snapshots can be created with filters that determine which key-value pairs are contained within the snapshot, creating an immutable, composed view of the configuration store. This feature enables applications to hold a consistent view of configuration, ensuring that there are no version mismatches to individual settings due to reading as updates were made. For example, this feature can be used to create "release configuration snapshots" within an App Configuration. See [the _create and get a snapshot_ section](#create-and-get-a-setting) in the example below.
149169

150170
## Examples
151171

152172
### Create and get a setting
153173

154-
```javascript
155-
const appConfig = require("@azure/app-configuration");
156-
157-
const client = new appConfig.AppConfigurationClient(
158-
"<App Configuration connection string goes here>"
159-
);
174+
```ts snippet:CreateSetting
175+
import { DefaultAzureCredential } from "@azure/identity";
176+
import { AppConfigurationClient } from "@azure/app-configuration";
177+
178+
// The endpoint for your App Configuration resource
179+
const endpoint = "https://example.azconfig.io";
180+
const credential = new DefaultAzureCredential();
181+
const client = new AppConfigurationClient(endpoint, credential);
182+
183+
await client.setConfigurationSetting({
184+
key: "testkey",
185+
value: "testvalue",
186+
// Labels allow you to create variants of a key tailored
187+
// for specific use-cases like supporting multiple environments.
188+
// https://docs.microsoft.com/azure/azure-app-configuration/concept-key-value#label-keys
189+
label: "optional-label",
190+
});
160191

161-
async function run() {
162-
const newSetting = await client.setConfigurationSetting({
163-
key: "testkey",
164-
value: "testvalue",
165-
// Labels allow you to create variants of a key tailored
166-
// for specific use-cases like supporting multiple environments.
167-
// https://docs.microsoft.com/azure/azure-app-configuration/concept-key-value#label-keys
168-
label: "optional-label"
169-
});
170-
171-
const retrievedSetting = await client.getConfigurationSetting({
172-
key: "testkey",
173-
label: "optional-label"
174-
});
175-
176-
console.log("Retrieved value:", retrievedSetting.value);
177-
}
192+
const retrievedSetting = await client.getConfigurationSetting({
193+
key: "testkey",
194+
label: "optional-label",
195+
});
178196

179-
run().catch((err) => console.log("ERROR:", err));
197+
console.log("Retrieved value:", retrievedSetting.value);
180198
```
181199

182200
### Create a snapshot
183201

184-
`beginCreateSnapshot` gives you the poller to poll for the snapshot creation.
185-
186-
```javascript
187-
const { AppConfigurationClient } = require("@azure/app-configuration");
188-
189-
const client = new AppConfigurationClient(
190-
"<App Configuration connection string goes here>"
191-
);
202+
`beginCreateSnapshot` gives you the poller to poll for the snapshot creation.
192203

204+
```ts snippet:CreateSnapshot
205+
import { DefaultAzureCredential } from "@azure/identity";
206+
import { AppConfigurationClient } from "@azure/app-configuration";
193207

194-
async function run() {
195-
const key = "testkey";
196-
const value = "testvalue";
197-
const label = "optional-label";
208+
// The endpoint for your App Configuration resource
209+
const endpoint = "https://example.azconfig.io";
210+
const credential = new DefaultAzureCredential();
211+
const client = new AppConfigurationClient(endpoint, credential);
198212

199-
await client.addConfigurationSetting({
200-
key,
201-
value,
202-
label
203-
});
213+
const key = "testkey";
214+
const value = "testvalue";
215+
const label = "optional-label";
204216

205-
const poller = await client.beginCreateSnapshot({
206-
name:"testsnapshot",
207-
retentionPeriod: 2592000,
208-
filters: [{keyFilter: key, labelFilter: label}],
209-
});
210-
const snapshot = await poller.pollUntilDone();
211-
}
217+
await client.addConfigurationSetting({
218+
key,
219+
value,
220+
label,
221+
});
212222

213-
run().catch((err) => console.log("ERROR:", err));
223+
const poller = await client.beginCreateSnapshot({
224+
name: "testsnapshot",
225+
retentionPeriod: 2592000,
226+
filters: [{ keyFilter: key, labelFilter: label }],
227+
});
228+
const snapshot = await poller.pollUntilDone();
214229
```
215230

216231
You can also use `beginCreateSnapshotAndWait` to have the result of the creation directly after the polling is done.
217-
```js
218-
const snapshot = await client.beginCreateSnapshotAndWait({
219-
name:"testsnapshot",
232+
233+
```ts snippet:CreateSnapshotAndWait
234+
import { DefaultAzureCredential } from "@azure/identity";
235+
import { AppConfigurationClient } from "@azure/app-configuration";
236+
237+
// The endpoint for your App Configuration resource
238+
const endpoint = "https://example.azconfig.io";
239+
const credential = new DefaultAzureCredential();
240+
const client = new AppConfigurationClient(endpoint, credential);
241+
242+
const key = "testkey";
243+
const value = "testvalue";
244+
const label = "optional-label";
245+
246+
const snapshot = await client.beginCreateSnapshotAndWait({
247+
name: "testsnapshot",
220248
retentionPeriod: 2592000,
221-
filters: [{keyFilter: key, labelFilter: label}],
249+
filters: [{ keyFilter: key, labelFilter: label }],
222250
});
223251
```
224252

225253
### Get a snapshot
226254

227-
```js
255+
```ts snippet:GetSnapshot
256+
import { DefaultAzureCredential } from "@azure/identity";
257+
import { AppConfigurationClient } from "@azure/app-configuration";
258+
259+
// The endpoint for your App Configuration resource
260+
const endpoint = "https://example.azconfig.io";
261+
const credential = new DefaultAzureCredential();
262+
const client = new AppConfigurationClient(endpoint, credential);
263+
228264
const retrievedSnapshot = await client.getSnapshot("testsnapshot");
229265
console.log("Retrieved snapshot:", retrievedSnapshot);
230266
```
231267

232268
### List the `ConfigurationSetting` in the snapshot
233-
```javascript
269+
270+
```ts snippet:ListSnapshotSettings
271+
import { DefaultAzureCredential } from "@azure/identity";
272+
import { AppConfigurationClient } from "@azure/app-configuration";
273+
274+
// The endpoint for your App Configuration resource
275+
const endpoint = "https://example.azconfig.io";
276+
const credential = new DefaultAzureCredential();
277+
const client = new AppConfigurationClient(endpoint, credential);
278+
234279
const retrievedSnapshotSettings = await client.listConfigurationSettingsForSnapshot("testsnapshot");
235280

236281
for await (const setting of retrievedSnapshotSettings) {
@@ -239,7 +284,16 @@ for await (const setting of retrievedSnapshotSettings) {
239284
```
240285

241286
### List all snapshots from the service
242-
```javascript
287+
288+
```ts snippet:ListSnapshots
289+
import { DefaultAzureCredential } from "@azure/identity";
290+
import { AppConfigurationClient } from "@azure/app-configuration";
291+
292+
// The endpoint for your App Configuration resource
293+
const endpoint = "https://example.azconfig.io";
294+
const credential = new DefaultAzureCredential();
295+
const client = new AppConfigurationClient(endpoint, credential);
296+
243297
const snapshots = await client.listSnapshots();
244298

245299
for await (const snapshot of snapshots) {
@@ -248,7 +302,16 @@ for await (const snapshot of snapshots) {
248302
```
249303

250304
### Recover and archive the snapshot
251-
```javascript
305+
306+
```ts snippet:RecoverAndArchiveSnapshot
307+
import { DefaultAzureCredential } from "@azure/identity";
308+
import { AppConfigurationClient } from "@azure/app-configuration";
309+
310+
// The endpoint for your App Configuration resource
311+
const endpoint = "https://example.azconfig.io";
312+
const credential = new DefaultAzureCredential();
313+
const client = new AppConfigurationClient(endpoint, credential);
314+
252315
// Snapshot is in ready status
253316
const archivedSnapshot = await client.archiveSnapshot("testsnapshot");
254317
console.log("Snapshot updated status is:", archivedSnapshot.status);
@@ -264,8 +327,8 @@ console.log("Snapshot updated status is:", recoverSnapshot.status);
264327

265328
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
266329

267-
```javascript
268-
const { setLogLevel } = require("@azure/logger");
330+
```ts snippet:SetLogLevel
331+
import { setLogLevel } from "@azure/logger";
269332

270333
setLogLevel("info");
271334
```
@@ -274,7 +337,7 @@ For more detailed instructions on how to enable logs, you can look at the [@azur
274337

275338
### React Native support
276339

277-
React Native does not support some JavaScript API used by this SDK library so you need to provide polyfills for them. Please see our [React Native sample with Expo](https://github.com/Azure/azure-sdk-for-js/blob/main/samples/frameworks/react-native/appconfigBasic/README.md#add-polyfills) for more details.
340+
React Native does not support some JavaScript API used by this SDK library so you need to provide polyfills for them. Please see our [React Native sample with Expo](https://github.com/Azure/azure-sdk-for-js/blob/main/samples/frameworks/react-native/appconfigBasic/README.md#add-polyfills) for more details.
278341

279342
## Next steps
280343

0 commit comments

Comments
 (0)