-
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 6 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
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,17 @@ | ||
| # You can defined environment variables in .env file and load them with 'dotenv' package. | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # This is a template of related environment variables in examples. | ||
| # Please rename this file to .env to make it working | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| APPCONFIG_CONNECTION_STRING=<app-configuration-connection-string> | ||
|
|
||
| # Used to specify endpoint when you are using role-based authentication instead of connection string. | ||
| # Should be https://<resource-name>.azconfig.io | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| APPCONFIG_ENDPOINT=<app-configuration-endpoint> | ||
|
|
||
| # Used to authenticate using Microsoft Entra ID (Azure AD) as a service principal for role-based authentication. | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # | ||
| # See the documentation for `EnvironmentCredential` at the following link: | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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,40 @@ | ||
| # 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][freesub] and the following Azure resources to run these sample programs: | ||
|
|
||
| - [Azure App Configuration account][createinstance_azureappconfigurationaccount] | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Samples retrieve credentials to access the service endpoint 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. | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Setup | ||
|
|
||
| To run the samples using the published version of the package: | ||
|
|
||
| 1. Install the dependencies using `npm`: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| 2. Edit the file `.env.template`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `.env.template` to just `.env`. The sample programs will read this file automatically. | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 3. Run whichever samples you like (note that some samples may require additional setup, see the table above): | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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 | ||
| ``` | ||
|
|
||
| [freesub]: https://azure.microsoft.com/free/ | ||
| [createinstance_azureappconfigurationaccount]: https://docs.microsoft.com/azure/azure-app-configuration/quickstart-aspnet-core-app?tabs=core5x#create-an-app-configuration-store | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,25 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example retrives all settings starting with "app.settings.". | ||
| * 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,30 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import * as dotenv from "dotenv"; | ||
| dotenv.config() | ||
|
|
||
| /** | ||
| * This example retrives all settings starting with "app.settings.". | ||
| * 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() | ||
|
|
||
| /** | ||
| * This example retrives all settings and resolve secret value from keyvault. | ||
| * Before you run it, please add a sample keyvault secret reference "app.secret". | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Value of secret "app.secret" will be printed. | ||
| * | ||
| * Below environment variables are required for this example: | ||
| * - APPCONFIG_CONNECTION_STRING | ||
Eskibear marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * - APPCONFIG_ENDPOINT | ||
| * - AZURE_TENANT_ID | ||
| * - AZURE_CLIENT_ID | ||
| * - AZURE_CLIENT_SECRET | ||
| */ | ||
|
|
||
| import { load } from "@azure/app-configuration-provider"; | ||
| import { getDefaultAzureCredential } from "@azure/identity"; | ||
| const connectionString = process.env.APPCONFIG_CONNECTION_STRING; | ||
| const settings = await load(connectionString, { | ||
| keyVaultOptions: { | ||
| credential: getDefaultAzureCredential() | ||
| } | ||
| }); | ||
| 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.