Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sdk/appconfiguration/app-configuration/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
106 changes: 106 additions & 0 deletions sdk/appconfiguration/app-configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
## Azure ConfigurationClient SDK for JavaScript

This package contains an isomorphic SDK for ConfigurationClient.

### Currently supported environments

- Node.js version 6.x.x or higher
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the README configurable at all through autorest? I think we're now saying we only support version 8.x.x or higher, and should be using @azure/identity over @azure/ms-rest-nodeauth if possible.

Since this package also includes the convenience layer we should probably make these changes (though they can probably be done in a separate PR to get this base out), but will it get replaced if we need to regenerate from the models again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When generating code, there is an option to skip the readme

- Browser JavaScript

### How to Install

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

### How to use

#### nodejs - Authentication, client creation and listConfigurationSettings as an example written in TypeScript.

##### Install @azure/ms-rest-nodeauth

```bash
npm install @azure/ms-rest-nodeauth
```

##### Sample code

```typescript
import * as coreHttp from "@azure/core-http";
import * as coreArm from "@azure/core-arm";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import { ConfigurationClient, ConfigurationModels, ConfigurationMappers } from "@azure/app-config";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];

msRestNodeAuth.interactiveLogin().then((creds) => {
const client = new ConfigurationClient(creds, subscriptionId);
const label = ["testlabel"];
const key = ["testkey"];
const acceptDateTime = new Date().toISOString();
const fields = ["etag"];
client.listConfigurationSettings(label, key, acceptDateTime, fields).then((result) => {
console.log("The result is:");
console.log(result);
});
}).catch((err) => {
console.error(err);
});
```

#### browser - Authentication, client creation and listConfigurationSettings as an example written in JavaScript.

##### Install @azure/ms-rest-browserauth

```bash
npm install @azure/ms-rest-browserauth
```

##### Sample code

See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.

- index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/app-configuration sample</title>
<script src="node_modules/@azure/core-http/dist/coreHttp.browser.js"></script>
<script src="node_modules/@azure/core-arm/dist/coreArm.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/app-config/dist/app-config.js"></script>
<script type="text/javascript">
const subscriptionId = "<Subscription_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.AppConfig.ConfigurationClient(res.creds, subscriptionId);
const label = ["testlabel"];
const key = ["testkey"];
const acceptDateTime = new Date().toISOString();
const fields = ["etag"];
client.listConfigurationSettings(label, key, acceptDateTime, fields).then((result) => {
console.log("The result is:");
console.log(result);
}).catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
<body></body>
</html>
```

## Related projects

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/appconfiguration/app-config/README.png)
59 changes: 59 additions & 0 deletions sdk/appconfiguration/app-configuration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@azure/app-configuration",
"author": "Microsoft Corporation",
"description": "An isomorphic client library for the Azure App Configuration service.",
"version": "1.0.0-preview.1",
"dependencies": {
"@azure/core-arm": "1.0.0-preview.1",
"@azure/core-http": "1.0.0-preview.1",
"tslib": "^1.9.3"
},
"keywords": [
"node",
"azure",
"typescript",
"browser",
"isomorphic"
],
"license": "MIT",
"main": "./dist/app-configuration.js",
"module": "./esm/index.js",
"types": "./esm/index.d.ts",
"devDependencies": {
"rollup": "^0.66.2",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"ts-node": "^8.3.0",
"typescript": "^3.1.1",
"uglify-js": "^3.4.9"
},
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/appconfiguration/app-configuration",
"repository": {
"type": "git",
"url": "https://github.com/Azure/azure-sdk-for-js.git"
},
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"files": [
"dist/**/*.js",
"dist/**/*.js.map",
"dist/**/*.d.ts",
"dist/**/*.d.ts.map",
"esm/**/*.js",
"esm/**/*.js.map",
"esm/**/*.d.ts",
"esm/**/*.d.ts.map",
"src/**/*.ts",
"README.md",
"rollup.config.js",
"tsconfig.json"
],
"scripts": {
"build": "tsc && rollup -c rollup.config.js && npm run minify",
"minify": "uglifyjs -c -m --comments --source-map \"content='./dist/app-configuration.js.map'\" -o ./dist/app-configuration.min.js ./dist/app-configuration.js",
"prepack": "npm install && npm run build"
},
"sideEffects": false,
"autoPublish": false
}
30 changes: 30 additions & 0 deletions sdk/appconfiguration/app-configuration/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import rollup from "rollup";
import nodeResolve from "rollup-plugin-node-resolve";
import sourcemaps from "rollup-plugin-sourcemaps";

/**
* @type {rollup.RollupFileOptions}
*/
const config = {
input: "./esm/index.js",
external: [
"@azure/core-http",
"@azure/core-arm"
],
output: {
file: "./dist/app-configuration.js",
format: "umd",
name: "Azure.AppConfig",
sourcemap: true,
globals: {
"@azure/core-http": "coreHttp",
"@azure/core-arm": "coreArm"
}
},
plugins: [
nodeResolve({ module: true }),
sourcemaps()
]
};

export default config;
41 changes: 41 additions & 0 deletions sdk/appconfiguration/app-configuration/src/appConfigCredential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as crypto from "crypto";
import { ServiceClientCredentials, WebResource, URLBuilder } from "@azure/core-http";

export class AppConfigCredential implements ServiceClientCredentials {
private credential: string;
private secret: string;

constructor(credential: string, secret: string) {
this.credential = credential;
this.secret = secret;
}

signRequest(webResource: WebResource): Promise<WebResource> {
const verb = webResource.method.toUpperCase()
const utcNow = new Date().toUTCString();
const contentHash =
crypto.createHash("sha256")
.update(webResource.body || "")
.digest("base64");

const signedHeaders = "x-ms-date;host;x-ms-content-sha256";

const url = URLBuilder.parse(webResource.url);
const query = url.getQuery();
const urlPathAndQuery = `${url.getPath()}${ query ? "?" + query : "" }`

const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${url.getHost()};${contentHash}`;

const decodedSecret = Buffer.from(this.secret, "base64");
var signature =
crypto.createHmac("sha256", decodedSecret)
.update(stringToSign)
.digest("base64");

webResource.headers.set("x-ms-date", utcNow);
webResource.headers.set("x-ms-content-sha256", contentHash);
webResource.headers.set("Authorization", `HMAC-SHA256 Credential=${this.credential}, SignedHeaders=${signedHeaders}, Signature=${signature}`);

return Promise.resolve(webResource);
}
}
Loading