forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappConfigSample.ts
More file actions
54 lines (42 loc) · 1.68 KB
/
Copy pathappConfigSample.ts
File metadata and controls
54 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @summary Demonstrates the CRUD operations on the configuration settings.
*/
import {AppConfigurationClient} from '@azure/app-configuration';
export async function runAppConfigSample() {
console.log('Running helloworld sample');
// Set the following environment variable or edit the value on the following line.
const connectionString =
process.env.APPCONFIG_CONNECTION_STRING || '<connection string>';
const client = new AppConfigurationClient(connectionString);
const greetingKey = 'Samples:Greeting';
await cleanupSampleValues([greetingKey], client);
// creating a new setting
console.log(`Adding in new setting ${greetingKey}`);
await client.addConfigurationSetting({key: greetingKey, value: 'Hello!'});
const newSetting = await client.getConfigurationSetting({key: greetingKey});
console.log(`${greetingKey} has been set to ${newSetting.value}`);
// changing the value of a setting
await client.setConfigurationSetting({key: greetingKey, value: 'Goodbye!'});
const updatedSetting = await client.getConfigurationSetting({
key: greetingKey,
});
console.log(`${greetingKey} has been set to ${updatedSetting.value}`);
// removing the setting
await client.deleteConfigurationSetting({key: greetingKey});
console.log(`${greetingKey} has been deleted`);
await cleanupSampleValues([greetingKey], client);
}
async function cleanupSampleValues(
keys: string[],
client: AppConfigurationClient,
) {
const settingsIterator = client.listConfigurationSettings({
keyFilter: keys.join(','),
});
for await (const setting of settingsIterator) {
await client.deleteConfigurationSetting({
key: setting.key,
label: setting.label,
});
}
}