Skip to content

Commit

Permalink
[template] Replace existing template package with tutorial client (#1…
Browse files Browse the repository at this point in the history
…3467)

* [template] Replaced template with tutorial appconfig SDK

* Retained old changelog and version information.

* Lint

* Fixed recordings to use stable values

* Remove unnecessary getEnv function

* Addressed some feedback items

* Added some docs

* Renamed an env var, added some docs to sample README

* Added live testing configuration for template

* Fixed some sample links

* Improved samples

* Fixed missing docs command, renamed smokeTestConfiguration

* Added missing typedoc dependency

* Final feedback items

* Regenerate API.md

* Use createSpanFunction instead of defining the span function manually.

* Removed extra deps

* Fixed readme issues, use App Config README for example instead of TA.

* Karma single run
  • Loading branch information
witemple-msft authored Feb 4, 2021
1 parent 9c6bbc0 commit dfb933d
Show file tree
Hide file tree
Showing 44 changed files with 4,972 additions and 782 deletions.
222 changes: 121 additions & 101 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion sdk/template/template/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
# Release History

## 1.0.11-beta.1 (Unreleased)

- Restructured the template package to use the Client SDK developer training materials.

## 1.0.10-beta.1 (2020-11-16)

- Test Release Pipeline

## 1.0.9-beta.13 (2020-10-13)

- Test Release Pipeline

## 1.0.9-beta.3 (2020-09-05)

- Test Release Pipeline

## 1.0.9-beta.2 (2020-09-04)

- Testing release tag replacement

## 1.0.9-beta.1 (2020-08-27)

- Testing prerelease versioning changes

## 1.0.8 (Unreleased)

## 1.0.7 (2020-04-01)

## 1.0.6 (2020-03-26)

- Test Release Pipeline

## 1.0.5 (2020-03-25)

- Test Release Pipeline

## 1.0.4 (2020-03-245

- Test Release Pipeline

## 1.0.3 (2020-03-24)

- Test Release Pipeline

## 1.0.2 (2020-03-24)
- Test Release Pipeline

- Test Release Pipeline

## 1.0.1 (2020-03-24)

- Test Release Pipeline
188 changes: 188 additions & 0 deletions sdk/template/template/README-EXAMPLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# App Configuration client library for JavaScript

<!-- NOTE: This is an example README copied from the real Azure App Configuration SDK. The real SDK has much more functionality than is exposed in the template/tutorial project, but this README can serve as an example to help you write a high-quality README for your own package. -->

[Azure App Configuration](https://docs.microsoft.com/azure/azure-app-configuration/overview) is a managed service that helps developers centralize their application and feature settings simply and securely.

Use the client library for App Configuration to:

- Create flexible key representations and mappings
- Tag keys with labels
- Replay settings from any point in time

[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/appconfiguration/app-configuration/) |
[Package (NPM)](https://www.npmjs.com/package/@azure/app-configuration) |
[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/app-configuration) |
[Product documentation](https://docs.microsoft.com/azure/azure-app-configuration/) |
[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples)

## Getting started

### Install the package

```bash
npm install @azure/app-configuration
```

### Prerequisites

- You must have an [Azure Subscription](https://azure.microsoft.com) and an [App Configuration](https://docs.microsoft.com/azure/azure-app-configuration/) resource to use this package.
- Node.js version 8.x.x or higher

### Create an App Configuration resource

You can use the [Azure Portal](https://portal.azure.com) or the [Azure CLI](https://docs.microsoft.com/cli/azure) to create an Azure App Configuration resource.

Example (Azure CLI):

```
az appconfig create --name <app-configuration-resource-name> --resource-group <resource-group-name> --location eastus
```

### Authenticate the client

AppConfigurationClient can authenticate using a [service principal](#authenticating-with-a-service-principal) or using a [connection string](#authenticating-with-a-connection-string).

#### Authenticating with a service principal

Authentication via service principal is done by:

- Creating a credential using the `@azure/identity` package.
- Setting appropriate RBAC rules on your AppConfiguration resource.
More information on App Configuration roles can be found [here](https://docs.microsoft.com/azure/azure-app-configuration/concept-enable-rbac#azure-built-in-roles-for-azure-app-configuration).

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

```javascript
const azureIdentity = require("@azure/identity");
const appConfig = require("@azure/app-configuration");

const credential = new azureIdentity.DefaultAzureCredential();
const client = new appConfig.AppConfigurationClient(
endpoint, // ex: <https://<your appconfig resource>.azconfig.io>
credential
);
```

More information about `@azure/identity` can be found [here](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md)

#### Authenticating with a connection string

To get the Primary **connection string** for an App Configuration resource you can use this Azure CLI command:

```
az appconfig credential list -g <resource-group-name> -n <app-configuration-resource-name> --query "([?name=='Primary'].connectionString)[0]"
```

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

```typescript
const client = new AppConfigurationClient("<connection string>");
```

## Key concepts

The [`AppConfigurationClient`](https://docs.microsoft.com/javascript/api/@azure/app-configuration/appconfigurationclient) has some terminology changes from App Configuration in the portal.

- Key/Value pairs are represented as [`ConfigurationSetting`](https://docs.microsoft.com/javascript/api/@azure/app-configuration/configurationsetting) objects
- Locking and unlocking a setting is represented in the `isReadOnly` field, which you can toggle using `setReadOnly`.

The client follows a simple design methodology - [`ConfigurationSetting`](https://docs.microsoft.com/javascript/api/@azure/app-configuration/configurationsetting) can be passed into any method that takes a [`ConfigurationSettingParam`](https://docs.microsoft.com/javascript/api/@azure/app-configuration/configurationsettingparam) or [`ConfigurationSettingId`](https://docs.microsoft.com/javascript/api/@azure/app-configuration/configurationsettingid).

This means this pattern works:

```typescript
const setting = await client.getConfigurationSetting({
key: "hello"
});

setting.value = "new value!";
await client.setConfigurationSetting(setting);

// fields unrelated to just identifying the setting are simply
// ignored (for instance, the `value` field)
await client.setReadOnly(setting, true);

// delete just needs to identify the setting so other fields are
// just ignored
await client.deleteConfigurationSetting(setting);
```

or, for example, re-getting a setting:

```typescript
let setting = await client.getConfigurationSetting({
key: "hello"
});

// re-get the setting
setting = await.getConfigurationSetting(setting);
```

## Examples

#### Create and get a setting

```javascript
const appConfig = require("@azure/app-configuration");

const client = new appConfig.AppConfigurationClient(
"<App Configuration connection string goes here>"
);

async function run() {
const newSetting = await client.setConfigurationSetting({
key: "testkey",
value: "testvalue",
// Labels allow you to create variants of a key tailored
// for specific use-cases like supporting multiple environments.
// https://docs.microsoft.com/azure/azure-app-configuration/concept-key-value#label-keys
label: "optional-label"
});

let retrievedSetting = await client.getConfigurationSetting({
key: "testkey",
label: "optional-label"
});

console.log("Retrieved value:", retrievedSetting.value);
}

run().catch((err) => console.log("ERROR:", err));
```

## Next steps

The following samples show you the various ways you can interact with App Configuration:

- [`helloworld.ts`](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples/typescript/src/helloworld.ts) - Get, set, and delete configuration values.
- [`helloworldWithLabels.ts`](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples/typescript/src/helloworldWithLabels.ts) - Use labels to add additional dimensions to your settings for scenarios like beta vs production.
- [`optimisticConcurrencyViaEtag.ts`](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples/typescript/src/optimisticConcurrencyViaEtag.ts) - Set values using etags to prevent accidental overwrites.
- [`setReadOnlySample.ts`](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples/typescript/src/setReadOnlySample.ts) - Marking settings as read-only to prevent modification.
- [`getSettingOnlyIfChanged.ts`](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples/typescript/src/getSettingOnlyIfChanged.ts) - Get a setting only if it changed from the last time you got it.
- [`listRevisions.ts`](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples/typescript/src/listRevisions.ts) - List the revisions of a key, allowing you to see previous values and when they were set.

More in-depth examples can be found in the [samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration/samples) folder on GitHub.

## Contributing

If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.

This module's tests are a mixture of live and unit tests, which require you to have an Azure App Configuration instance. To execute the tests you'll need to run:

1. `rush update`
2. `rush build -t @azure/app-configuration`
3. Create a .env file with these contents in the `sdk\appconfiguration\app-configuration` folder:
`APPCONFIG_CONNECTION_STRING=connection string for your App Configuration instance`
4. `cd sdk\appconfiguration\app-configuration`
5. `npm run test`.

View our [tests](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/appconfiguration/app-configuration/test)
folder for more details.

## Related projects

- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)
- [Azure App Configuration](https://docs.microsoft.com/azure/azure-app-configuration/overview)

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fappconfiguration%2Fapp-configuration%2FREADME.png)
Loading

0 comments on commit dfb933d

Please sign in to comment.