-
Notifications
You must be signed in to change notification settings - Fork 4
Add examples and getting started instructions #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2cd3208
Add examples and getting started instructions
Eskibear 774ddb2
Merge remote-tracking branch 'origin/main' into yanzh/example
Eskibear 0556d39
fix typo
Eskibear 6822346
Merge branch 'main' into yanzh/example
Eskibear 45495dd
add stack overflow guide in support.md
Eskibear 55984bc
add example for secret reference
Eskibear d0dff70
Merge remote-tracking branch 'origin/main' into yanzh/example
Eskibear bb3c3ce
update .env.template
Eskibear 531f007
update READEME.md
Eskibear 00f8e6b
update examples/README.md
Eskibear 0dee869
update secretReference.mjs to reuse same credential
Eskibear cc75d3b
describe trimKeyPrefixes in helloworld.mjs
Eskibear 9a2bc53
update wording in examples/README.md
Eskibear 14ece55
describe trimKeyPrefixes in helloworld_aad.mjs
Eskibear 49cff58
address comments: reorganize examples/README.md
Eskibear 2ba9d78
address comments: the Azure service -> your Azure App Configuration s…
Eskibear fb9ee7e
Merge branch 'main' into yanzh/example
Eskibear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,4 +406,7 @@ types/ | |
| .env | ||
|
|
||
| # npm pack | ||
| *.tgz | ||
| *.tgz | ||
|
|
||
| # examples | ||
| examples/package-lock.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # You can define environment variables in .env file and load them with 'dotenv' package. | ||
| # This is a template of related environment variables in examples. | ||
| # To use this file directly, please rename it to .env | ||
| APPCONFIG_CONNECTION_STRING=<app-configuration-connection-string> | ||
|
|
||
| APPCONFIG_ENDPOINT=<app-configuration-endpoint> | ||
|
|
||
| # Credential used to authenticate using Microsoft Entra ID (Azure AD) role-based authentication. | ||
| # https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential | ||
| AZURE_TENANT_ID=<AD tenant id or name> | ||
| AZURE_CLIENT_ID=<ID of the user/service principal to authenticate as> | ||
| AZURE_CLIENT_SECRET=<client secret used to authenticate to Azure AD> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Examples for Azure App Configuration JavaScript Provider | ||
|
|
||
| These examples show how to use the JavaScript Provider for Azure App Configuration in some common scenarios. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). | ||
|
|
||
| You need [an Azure subscription](https://azure.microsoft.com/free/) and the following Azure resources to run these sample programs: | ||
|
|
||
| - [Azure App Configuration store](https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-azure-app-configuration-create?tabs=azure-portal) | ||
|
|
||
| Samples retrieve credentials to access your App Configuration store from environment variables. | ||
| Alternatively, edit the source code to include the appropriate credentials. | ||
| See each individual sample for details on which environment variables/credentials it requires to function. | ||
|
|
||
| ## Setup | ||
|
|
||
| To run the samples using the published version of the package: | ||
|
|
||
| 1. Install the dependencies using `npm`: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| 2. There are two ways to run the samples using correct credentials: | ||
|
|
||
| - Edit the file `.env.template`, adding the correct credentials to access your Azure App Configuration store and rename the file from `.env.template` to just `.env`. | ||
| Then run the samples, it will read this file automatically. | ||
| ```bash | ||
| node helloworld.mjs | ||
| ``` | ||
|
|
||
| - Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): | ||
| ```bash | ||
| npx cross-env APPCONFIG_CONNECTION_STRING="<appconfig connection string>" node helloworld.mjs | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
| * With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
| * Value of config "app.settings.message" will be printed. | ||
Eskibear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_CONNECTION_STRING | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
| const settings = await load(connectionString, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }], | ||
| trimKeyPrefixes: ["app.settings."] | ||
| }); | ||
| const message = settings.get("message"); | ||
|
|
||
| console.log(`Message from Azure App Configuration: ${message}`); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example retrives all settings with key following pattern "app.settings.*", i.e. starting with "app.settings.". | ||
| * With the option `trimKeyPrefixes`, it trims the prefix "app.settings." from keys for simplicity. | ||
| * Value of config "app.settings.message" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_ENDPOINT | ||
| * - AZURE_TENANT_ID | ||
| * - AZURE_CLIENT_ID | ||
| * - AZURE_CLIENT_SECRET | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { getDefaultAzureCredential } from "@azure/identity"; | ||
| const endpoint = process.env.APPCONFIG_ENDPOINT; | ||
| const credential = getDefaultAzureCredential(); | ||
| const settings = await load(endpoint, credential, { | ||
| selectors: [{ | ||
| keyFilter: "app.settings.*" | ||
| }], | ||
| trimKeyPrefixes: ["app.settings."] | ||
| }); | ||
| const message = settings.get("message"); | ||
|
|
||
| console.log(`Message from Azure App Configuration: ${message}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "dependencies": { | ||
| "@azure/app-configuration-provider": "latest", | ||
| "@azure/identity": "^3.3.0", | ||
| "dotenv": "^16.3.1" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * Before you run it, please add a Key Vault reference with key "app.secret" in your App Configuration store. | ||
| * This example uses the same identity to authenticate with both App Configuration and Key Vault. Make sure that this identity has access to read secrets from Key Vault. | ||
| * Value of secret "app.secret" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_ENDPOINT | ||
| * - AZURE_TENANT_ID | ||
| * - AZURE_CLIENT_ID | ||
| * - AZURE_CLIENT_SECRET | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { getDefaultAzureCredential } from "@azure/identity"; | ||
| const endpoint = process.env.APPCONFIG_ENDPOINT; | ||
| const credential = getDefaultAzureCredential(); | ||
| const settings = await load(endpoint, credential, { | ||
| keyVaultOptions: { | ||
| credential: credential | ||
| } | ||
| }); | ||
| const secretKey = "app.secret"; | ||
| const value = settings.get(secretKey); | ||
|
|
||
| console.log(`Get the secret from keyvault key: ${secretKey}, value: ${value}`); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.