[core-arm] delete it! (#12682)
* delete core-arm * remove core-arm from a bunch of places * rush update
This commit is contained in:
Родитель
a928820bea
Коммит
c88d1faf32
|
@ -10,7 +10,6 @@ dependencies:
|
|||
'@rush-temp/communication-common': 'file:projects/communication-common.tgz'
|
||||
'@rush-temp/communication-sms': 'file:projects/communication-sms.tgz'
|
||||
'@rush-temp/core-amqp': 'file:projects/core-amqp.tgz'
|
||||
'@rush-temp/core-arm': 'file:projects/core-arm.tgz'
|
||||
'@rush-temp/core-asynciterator-polyfill': 'file:projects/core-asynciterator-polyfill.tgz'
|
||||
'@rush-temp/core-auth': 'file:projects/core-auth.tgz'
|
||||
'@rush-temp/core-client': 'file:projects/core-client.tgz'
|
||||
|
@ -9100,7 +9099,7 @@ packages:
|
|||
dev: false
|
||||
name: '@rush-temp/ai-text-analytics'
|
||||
resolution:
|
||||
integrity: sha512-ynAlVrS3nk6apbPNyP3i/xi5+IOi3yfae4LNT6gqoxQ4vxRpQEF79d6qi3ujYZf9UzwLn3Vksdr0WQM26LYVBQ==
|
||||
integrity: sha512-VLKH85eh2Gp7BAGZFRL5CbF8Q5uHXP/hJwkDUGU34MwAi157MMnb9o0+zrpMKUdyYyQ+XhkVpluCbR75GxMGag==
|
||||
tarball: 'file:projects/ai-text-analytics.tgz'
|
||||
version: 0.0.0
|
||||
'file:projects/app-configuration.tgz':
|
||||
|
@ -9469,39 +9468,6 @@ packages:
|
|||
integrity: sha512-x6mKN9gSowCFmjRbwapUXG+7Q8SXgIj04M9Uxzz2em44VtCvLxDt1xQEoVM735J1ggwtEKJeNU3NwGO125NfEA==
|
||||
tarball: 'file:projects/core-amqp.tgz'
|
||||
version: 0.0.0
|
||||
'file:projects/core-arm.tgz':
|
||||
dependencies:
|
||||
'@rollup/plugin-node-resolve': 8.4.0_rollup@1.32.1
|
||||
'@types/chai': 4.2.12
|
||||
'@types/mocha': 7.0.2
|
||||
'@types/node': 8.10.62
|
||||
'@typescript-eslint/eslint-plugin': 2.34.0_5004700905763c91177aaa7d1d0d56ac
|
||||
'@typescript-eslint/parser': 2.34.0_eslint@6.8.0+typescript@3.9.7
|
||||
chai: 4.2.0
|
||||
eslint: 6.8.0
|
||||
eslint-config-prettier: 6.11.0_eslint@6.8.0
|
||||
eslint-plugin-no-null: 1.0.2_eslint@6.8.0
|
||||
eslint-plugin-no-only-tests: 2.4.0
|
||||
eslint-plugin-promise: 4.2.1
|
||||
mocha: 7.2.0
|
||||
mocha-junit-reporter: 1.23.3_mocha@7.2.0
|
||||
npm-run-all: 4.1.5
|
||||
nyc: 14.1.1
|
||||
rimraf: 3.0.2
|
||||
rollup: 1.32.1
|
||||
rollup-plugin-sourcemaps: 0.4.2_rollup@1.32.1
|
||||
rollup-plugin-visualizer: 4.1.1_rollup@1.32.1
|
||||
shx: 0.3.2
|
||||
ts-node: 8.10.2_typescript@3.9.7
|
||||
tslib: 2.0.1
|
||||
typescript: 3.9.7
|
||||
uglify-js: 3.10.2
|
||||
dev: false
|
||||
name: '@rush-temp/core-arm'
|
||||
resolution:
|
||||
integrity: sha512-Zb61MgOHT1RDAjJuzgtNeCzngU6qWSHyTPraBYk+GoTMSBs/SYUiXp0hMxIriJj8dQIai5BvVDswIVXFSWddUg==
|
||||
tarball: 'file:projects/core-arm.tgz'
|
||||
version: 0.0.0
|
||||
'file:projects/core-asynciterator-polyfill.tgz':
|
||||
dependencies:
|
||||
'@types/node': 8.10.62
|
||||
|
@ -10816,6 +10782,7 @@ packages:
|
|||
version: 0.0.0
|
||||
'file:projects/opentelemetry-exporter-azure-monitor.tgz':
|
||||
dependencies:
|
||||
'@microsoft/api-extractor': 7.7.11
|
||||
'@opentelemetry/api': 0.10.2
|
||||
'@opentelemetry/core': 0.10.2
|
||||
'@opentelemetry/semantic-conventions': 0.10.2
|
||||
|
@ -10838,7 +10805,7 @@ packages:
|
|||
dev: false
|
||||
name: '@rush-temp/opentelemetry-exporter-azure-monitor'
|
||||
resolution:
|
||||
integrity: sha512-xphjre86JoSr3r7lb9hM9tpds8mkwmPeBkH7cqnc8QWqB38q9PLa+UA5NCjzkQvj39cmTIqYr46NsudBRl3RJA==
|
||||
integrity: sha512-xYPlB3UO4LSslU7rnHjR7pwLkPPOmQEGzqtG+gI0/imVB2H0JcGeFQuX1w83J2LzhUp8UNZxVbSGUdPL6BNcFw==
|
||||
tarball: 'file:projects/opentelemetry-exporter-azure-monitor.tgz'
|
||||
version: 0.0.0
|
||||
'file:projects/schema-registry-avro.tgz':
|
||||
|
@ -11656,7 +11623,6 @@ specifiers:
|
|||
'@rush-temp/communication-common': 'file:./projects/communication-common.tgz'
|
||||
'@rush-temp/communication-sms': 'file:./projects/communication-sms.tgz'
|
||||
'@rush-temp/core-amqp': 'file:./projects/core-amqp.tgz'
|
||||
'@rush-temp/core-arm': 'file:./projects/core-arm.tgz'
|
||||
'@rush-temp/core-asynciterator-polyfill': 'file:./projects/core-asynciterator-polyfill.tgz'
|
||||
'@rush-temp/core-auth': 'file:./projects/core-auth.tgz'
|
||||
'@rush-temp/core-client': 'file:./projects/core-client.tgz'
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
"name": "core-amqp",
|
||||
"path": "sdk/core/core-amqp"
|
||||
},
|
||||
{
|
||||
"name": "core-arm",
|
||||
"path": "sdk/core/core-arm"
|
||||
},
|
||||
{
|
||||
"name": "core-asynciterator-polyfill",
|
||||
"path": "sdk/core/core-asynciterator-polyfill"
|
||||
|
|
|
@ -13,7 +13,6 @@ trigger:
|
|||
- sdk/communication/communication-sms/
|
||||
- sdk/core/abort-controller/
|
||||
- sdk/core/core-amqp/
|
||||
- sdk/core/core-arm/
|
||||
- sdk/core/core-asynciterator-polyfill/
|
||||
- sdk/core/core-auth/
|
||||
- sdk/core/core-client/
|
||||
|
|
|
@ -13,7 +13,6 @@ pr:
|
|||
- sdk/communication/communication-sms/
|
||||
- sdk/core/abort-controller/
|
||||
- sdk/core/core-amqp/
|
||||
- sdk/core/core-arm/
|
||||
- sdk/core/core-asynciterator-polyfill/
|
||||
- sdk/core/core-auth/
|
||||
- sdk/core/core-client/
|
||||
|
|
|
@ -382,11 +382,6 @@
|
|||
"projectFolder": "sdk/core/core-amqp",
|
||||
"versionPolicyName": "core"
|
||||
},
|
||||
{
|
||||
"packageName": "@azure/core-arm",
|
||||
"projectFolder": "sdk/core/core-arm",
|
||||
"versionPolicyName": "core"
|
||||
},
|
||||
{
|
||||
"packageName": "@azure/core-asynciterator-polyfill",
|
||||
"projectFolder": "sdk/core/core-asynciterator-polyfill",
|
||||
|
|
|
@ -38,8 +38,6 @@ extends:
|
|||
safeName: azureabortcontroller
|
||||
- name: azure-core-amqp
|
||||
safeName: azurecoreamqp
|
||||
- name: azure-core-arm
|
||||
safeName: azurecorearm
|
||||
- name: azure-core-asynciterator-polyfill
|
||||
safeName: azurecoreasynciteratorpolyfill
|
||||
- name: azure-core-auth
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
/node_modules
|
||||
|
||||
output/*
|
||||
package-lock.json
|
||||
|
||||
# Typescript output
|
||||
.nyc_output/
|
||||
coverage/
|
||||
dist/
|
||||
*.d.ts.map
|
||||
*.js
|
||||
*.js.map
|
||||
test-results.xml
|
||||
|
||||
# Rollup
|
||||
!rollup.config.js
|
||||
*-stats.html
|
|
@ -1,28 +0,0 @@
|
|||
# Release History
|
||||
|
||||
## 1.0.0-preview.8 (Unreleased)
|
||||
|
||||
## 1.0.0-preview.7 (2019-10-29)
|
||||
|
||||
- Updated to use the latest version of `@azure/core-http` package.
|
||||
|
||||
## 1.0.0-preview.6 (2019-10-22)
|
||||
|
||||
- Updated to use the latest version of `@azure/core-http` package
|
||||
|
||||
## 1.0.0-preview.4 (2019-10-07)
|
||||
|
||||
- Updated to use the latest version of the `@azure/core-http` library.
|
||||
|
||||
## 1.0.0-preview.3 (2019-09-09)
|
||||
|
||||
- Reintroduces `ServiceClientCredentials` type to `credentials` parameter of
|
||||
`AzureServiceClient` ([PR #4773](https://github.com/Azure/azure-sdk-for-js/pull/4773)).
|
||||
|
||||
## 1.0.0-preview.2 (2019-08-05)
|
||||
|
||||
- Removed `ServiceClientCredentials` type from `credentials` parameter of `AzureServiceClient` ([PR #4367](https://github.com/Azure/azure-sdk-for-js/pull/4367)). Credential implementations are now standardized on `@azure/core-auth`'s `TokenCredential` interface and provided by `@azure/identity`.
|
||||
|
||||
## 1.0.0-preview.1 (2019-07-10)
|
||||
|
||||
- Forked `@azure/ms-rest-azure-js` to `@azure/core-arm` to add the Azure HTTP pipeline layer for Azure SDK TypeScript/JavaScript libraries.
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 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.
|
|
@ -1,57 +0,0 @@
|
|||
# Azure Core ARM client library for JavaScript
|
||||
|
||||
This is an Azure-specific layer for the core HTTP pipeline of Azure SDK JavaScript libraries which work in the browser and Node.js. This library is primarily intended to be used in code generated by [AutoRest](https://github.com/Azure/Autorest) and [`autorest.typescript`](https://github.com/Azure/autorest.typescript).
|
||||
|
||||
## Getting started
|
||||
|
||||
### Requirements
|
||||
|
||||
- Node.js version > 6.x
|
||||
- npm install -g typescript
|
||||
|
||||
### Installation
|
||||
|
||||
- After cloning the repo, execute `npm install`
|
||||
|
||||
## Key concepts
|
||||
|
||||
This library provides a `ServiceClient` subclass called `AzureServiceClient` which adds some Azure-specific behavior such as the management of long-running operations. For more information on the design of the underlying library `@azure/core-http`, consult the [architecture overview](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-http/docs/architectureOverview.md).
|
||||
|
||||
## Examples
|
||||
|
||||
Examples can be found in the `samples` folder.
|
||||
|
||||
## Next steps
|
||||
|
||||
### Node.js
|
||||
|
||||
- Set the subscriptionId and token
|
||||
- Run `node samples/node-sample.js`
|
||||
|
||||
### In the browser
|
||||
|
||||
- Set the subscriptionId and token and then run
|
||||
- Open index.html file in the browser. It should show the response from GET request on the storage account. From Chrome type Ctrl + Shift + I and you can see the logs in console.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you run into issues while using this library, please feel free to [file an issue](https://github.com/Azure/azure-sdk-for-js/issues/new).
|
||||
|
||||
# Contributing
|
||||
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
||||
|
||||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
||||
|
||||
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 project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
|
||||
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-arm%2FREADME.png)
|
|
@ -1,127 +0,0 @@
|
|||
{
|
||||
"name": "@azure/core-arm",
|
||||
"author": {
|
||||
"name": "Microsoft Corporation",
|
||||
"email": "azsdkteam@microsoft.com",
|
||||
"url": "https://github.com/Azure/azure-sdk-for-js"
|
||||
},
|
||||
"sdk-type": "client",
|
||||
"version": "1.0.0-preview.8",
|
||||
"description": "Isomorphic Azure client runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
|
||||
"tags": [
|
||||
"isomorphic",
|
||||
"browser",
|
||||
"javascript",
|
||||
"node",
|
||||
"microsoft",
|
||||
"autorest",
|
||||
"clientruntime"
|
||||
],
|
||||
"keywords": [
|
||||
"isomorphic",
|
||||
"browser",
|
||||
"javascript",
|
||||
"node",
|
||||
"microsoft",
|
||||
"autorest",
|
||||
"clientruntime"
|
||||
],
|
||||
"main": "./dist/coreArm.js",
|
||||
"module": "./es/src/coreArm.js",
|
||||
"types": "./es/src/coreArm.d.ts",
|
||||
"files": [
|
||||
"dist/**/*.js",
|
||||
"dist/**/*.js.map",
|
||||
"es/src/**/*.js",
|
||||
"es/src/**/*.js.map",
|
||||
"es/src/**/*.d.ts",
|
||||
"es/src/**/*.d.ts.map",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-arm",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:Azure/azure-sdk-for-js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/Azure/azure-sdk-for-js/issues"
|
||||
},
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts"
|
||||
],
|
||||
"exclude": [
|
||||
"coverage/**/*",
|
||||
"**/*.d.ts",
|
||||
"**/*.js"
|
||||
],
|
||||
"reporter": [
|
||||
"text",
|
||||
"html",
|
||||
"cobertura"
|
||||
],
|
||||
"all": true
|
||||
},
|
||||
"scripts": {
|
||||
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
|
||||
"build": "run-p build:src",
|
||||
"build:src": "run-s build:tsc build:rollup build:minify",
|
||||
"build:tsc": "tsc -p tsconfig.es.json",
|
||||
"build:rollup": "rollup -c rollup.config.js 2>&1",
|
||||
"build:minify": "uglifyjs -c -m --comments --source-map \"content='./dist/coreArm.js.map'\" -o ./dist/coreArm.min.js ./dist/coreArm.js",
|
||||
"build:test": "npm run build",
|
||||
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
||||
"clean": "rimraf ./es ./dist",
|
||||
"execute:samples": "echo skipped",
|
||||
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
|
||||
"integration-test:browser": "echo skipped",
|
||||
"integration-test:node": "echo skipped",
|
||||
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
||||
"lint:fix": "echo skipped",
|
||||
"lint": "echo skipped",
|
||||
"test:browser": "npm run build && npm run unit-test:browser && npm run integration-test:browser",
|
||||
"test:node": "npm run build && npm run unit-test:node && npm run integration-test:node",
|
||||
"test": "npm run build && npm run unit-test && npm run integration-test",
|
||||
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
||||
"unit-test:browser": "echo skipped",
|
||||
"unit-test:node": "mocha --require ts-node/register --timeout 50000 --reporter ../../../common/tools/mocha-multi-reporter.js --colors \"test/**/*.ts\"",
|
||||
"cover:unit:node": "nyc npm run unit-test:node",
|
||||
"pack": "npm pack 2>&1",
|
||||
"prebuild": "npm run clean"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"//metadata": {
|
||||
"constantPaths": [
|
||||
{
|
||||
"path": "src/util/constants.ts",
|
||||
"prefix": "coreArmVersion"
|
||||
}
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@azure/core-http": "^1.2.0",
|
||||
"tslib": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-node-resolve": "^8.0.0",
|
||||
"@types/chai": "^4.1.6",
|
||||
"@types/mocha": "^7.0.2",
|
||||
"@types/node": "^8.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^6.1.0",
|
||||
"mocha": "^7.1.1",
|
||||
"mocha-junit-reporter": "^1.18.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^14.0.0",
|
||||
"rimraf": "^3.0.0",
|
||||
"rollup": "^1.16.3",
|
||||
"rollup-plugin-sourcemaps": "^0.4.2",
|
||||
"rollup-plugin-visualizer": "^4.0.4",
|
||||
"shx": "^0.3.2",
|
||||
"ts-node": "^8.3.0",
|
||||
"typescript": "~3.9.3",
|
||||
"uglify-js": "^3.4.9"
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
import nodeResolve from "@rollup/plugin-node-resolve";
|
||||
import visualizer from "rollup-plugin-visualizer";
|
||||
import sourcemaps from "rollup-plugin-sourcemaps";
|
||||
|
||||
const banner = `/** @license @azure/core-arm
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*/`;
|
||||
|
||||
/**
|
||||
* @type {import('rollup').RollupFileOptions}
|
||||
*/
|
||||
const config = {
|
||||
input: './es/src/coreArm.js',
|
||||
external: ["@azure/core-http"],
|
||||
output: {
|
||||
file: "./dist/coreArm.js",
|
||||
format: "umd",
|
||||
name: "Azure.Core.ARM",
|
||||
sourcemap: true,
|
||||
globals: {
|
||||
"@azure/core-http": "Azure.Core.HTTP"
|
||||
},
|
||||
banner
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({ mainFields: ['module'] }),
|
||||
sourcemaps(),
|
||||
visualizer({ filename: "dist/node-stats.html", sourcemap: true })
|
||||
]
|
||||
}
|
||||
|
||||
export default config;
|
|
@ -1,26 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>My Todos</title>
|
||||
<script type="text/javascript" src="../node_modules/@azure/core-http/dist/coreHttp.browser.js"></script>
|
||||
<script type="text/javascript" src="../dist/coreArm.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
document.write("hello world");
|
||||
const subscriptionId = "subscriptionId";
|
||||
const token = "token";
|
||||
const creds = new Azure.Core.HTTP.RawTokenCredential(token);
|
||||
const client = new Azure.Core.ARM.AzureServiceClient(creds);
|
||||
const req = {
|
||||
url: `https://management.azure.com/subscriptions/${subscriptionId}/providers/Microsoft.Storage/storageAccounts?api-version=2015-06-15`,
|
||||
method: "GET"
|
||||
};
|
||||
client.sendRequest(req).then((res) => { document.write(res.bodyAsText); }).catch((err) => { console.log(err); });
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,73 +0,0 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const msRest = require("core-http");
|
||||
const msRestAzure = require("../dist/lib/msRestAzure");
|
||||
const clientOptions = {
|
||||
filters: [new msRest.LogFilter()]
|
||||
};
|
||||
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"] || "00977cdb-163f-435f-9c32-39ec8ae61f4d";
|
||||
const resourceGroupName = "foozap002";
|
||||
const accountName = "foozy894";
|
||||
const location = "westus";
|
||||
const apiVersion = "2017-06-01";
|
||||
// An easy way to get the token
|
||||
// 1. Go to this test drive link https://azure.github.io/projects/apis and authenticate by clicking on Authorize. Check the user impersoantion checkbox in the popup.
|
||||
// 1.1 select a subscription of your choice
|
||||
// 1.2 select the storage-2015-06-15 option from the first drop down list
|
||||
// 1.3 expand the url to list storage accounts in a subscription
|
||||
// 1.4 click on try it out button.
|
||||
// 1.5 in the curl tab you will see the actual curl request that has the bearer token in it
|
||||
// 1.6 copy paste that token here. That token is valid for 1 hour
|
||||
const token = "token";
|
||||
const creds = new msRest.TokenCredentials(token);
|
||||
const client = new msRestAzure.AzureServiceClient(creds, clientOptions);
|
||||
const req = {
|
||||
url: `https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Storage/storageAccounts/${accountName}?api-version=${apiVersion}`,
|
||||
method: "PUT",
|
||||
body: {
|
||||
location: location,
|
||||
sku: {
|
||||
name: "Standard_GRS"
|
||||
},
|
||||
kind: "Storage",
|
||||
tags: {
|
||||
key1: "value1",
|
||||
key2: "value2"
|
||||
}
|
||||
}
|
||||
};
|
||||
function execute(req) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let res;
|
||||
try {
|
||||
res = yield client.sendLongRunningRequest(req);
|
||||
console.dir(res);
|
||||
document.write(JSON.stringify(res));
|
||||
return Promise.resolve(res);
|
||||
}
|
||||
catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log("Hi There!!");
|
||||
// client.sendLongRunningRequest(req).then((res: msRest.HttpOperationResponse) => {
|
||||
// console.log(res.body as string);
|
||||
// }).catch((err) => {
|
||||
// console.dir(err);
|
||||
// });
|
||||
execute(req).catch((err) => { console.dir(err); });
|
||||
for (var i = 1; i <= 20; i++) {
|
||||
console.log("Hello World " + i);
|
||||
setTimeout(function (x) { return function () { console.log(x); }; }(i), 1000 * i);
|
||||
// 1 2 3 4 5
|
||||
}
|
||||
//# sourceMappingURL=sample.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"sample.js","sourceRoot":"","sources":["../../samples/sample.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AAEb,qCAAqC;AACrC,kDAAkD;AAClD,MAAM,aAAa,GAA0C;IAC3D,OAAO,EAAE,CAAC,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,sCAAsC,CAAC;AACtG,MAAM,iBAAiB,GAAG,WAAW,CAAC;AACtC,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAC1B,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,+BAA+B;AAC/B,qKAAqK;AACrK,2CAA2C;AAC3C,yEAAyE;AACzE,gEAAgE;AAChE,kCAAkC;AAClC,2FAA2F;AAC3F,iEAAiE;AACjE,MAAM,KAAK,GAAG,OAAO,CAAC;AACtB,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACjD,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;AACxE,MAAM,GAAG,GAAiC;IACxC,GAAG,EAAE,8CAA8C,cAAc,mBAAmB,iBAAiB,gDAAgD,WAAW,gBAAgB,UAAU,EAAE;IAC5L,MAAM,EAAE,KAAK;IACb,IAAI,EAAE;QACJ,QAAQ,EAAE,QAAQ;QAClB,GAAG,EAAE;YACH,IAAI,EAAE,cAAc;SACrB;QACD,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;SACf;KACF;CACF,CAAC;AAEF,iBAAuB,GAAiC;;QACtD,IAAI,GAAiC,CAAC;QACtC,IAAI,CAAC;YACH,GAAG,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACpC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACb,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CAAA;AACD,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC1B,mFAAmF;AACnF,qCAAqC;AACrC,sBAAsB;AACtB,sBAAsB;AACtB,MAAM;AACN,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnD,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IAChC,UAAU,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,cAAc,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC;IAClF,YAAY;AACd,CAAC"}
|
|
@ -1,64 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
import * as coreHttp from "@azure/core-http";
|
||||
import * as coreArm from "../lib/coreArm";
|
||||
const clientOptions: coreArm.AzureServiceClientOptions = {
|
||||
filters: [new coreHttp.LogFilter()]
|
||||
};
|
||||
|
||||
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"] || "00977cdb-163f-435f-9c32-39ec8ae61f4d";
|
||||
const resourceGroupName = "foozap002";
|
||||
const accountName = "foozy894";
|
||||
const location = "westus";
|
||||
const apiVersion = "2017-06-01";
|
||||
// An easy way to get the token
|
||||
// 1. Go to this test drive link https://azure.github.io/projects/apis and authenticate by clicking on Authorize. Check the user impersoantion checkbox in the popup.
|
||||
// 1.1 select a subscription of your choice
|
||||
// 1.2 select the storage-2015-06-15 option from the first drop down list
|
||||
// 1.3 expand the url to list storage accounts in a subscription
|
||||
// 1.4 click on try it out button.
|
||||
// 1.5 in the curl tab you will see the actual curl request that has the bearer token in it
|
||||
// 1.6 copy paste that token here. That token is valid for 1 hour
|
||||
const token = "token";
|
||||
const creds = new coreHttp.RawTokenCredential(token);
|
||||
const client = new coreArm.AzureServiceClient(creds, clientOptions);
|
||||
const req: coreHttp.RequestPrepareOptions = {
|
||||
url: `https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Storage/storageAccounts/${accountName}?api-version=${apiVersion}`,
|
||||
method: "PUT",
|
||||
body: {
|
||||
location: location,
|
||||
sku: {
|
||||
name: "Standard_GRS"
|
||||
},
|
||||
kind: "Storage",
|
||||
tags: {
|
||||
key1: "value1",
|
||||
key2: "value2"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async function execute(req: coreHttp.RequestPrepareOptions): Promise<msRest.HttpOperationResponse> {
|
||||
let res: coreHttp.HttpOperationResponse;
|
||||
try {
|
||||
res = await client.sendLongRunningRequest(req);
|
||||
console.dir(res);
|
||||
document.write(JSON.stringify(res));
|
||||
return Promise.resolve(res);
|
||||
} catch (err) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
console.log("Hi There!!");
|
||||
// client.sendLongRunningRequest(req).then((res: coreHttp.HttpOperationResponse) => {
|
||||
// console.log(res.body as string);
|
||||
// }).catch((err) => {
|
||||
// console.dir(err);
|
||||
// });
|
||||
execute(req).catch((err) => { console.dir(err); });
|
||||
|
||||
for (var i = 1; i <= 20; i++) {
|
||||
console.log("Hello World " + i);
|
||||
setTimeout(function (x) { return function () { console.log(x); }; }(i), 1000 * i);
|
||||
// 1 2 3 4 5
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { HttpOperationResponse, OperationArguments, OperationSpec, RequestOptionsBase, RequestPrepareOptions, ServiceClient, ServiceClientCredentials, ServiceClientOptions, TokenCredential, WebResource, getDefaultUserAgentValue as getDefaultUserAgentValueFromMsRest } from "@azure/core-http";
|
||||
import { createLROPollerFromInitialResponse, createLROPollerFromPollState, LROPoller } from "./lroPoller";
|
||||
import { LROPollState } from "./lroPollStrategy";
|
||||
import * as Constants from "./util/constants";
|
||||
|
||||
/**
|
||||
* Options to be provided while creating the client.
|
||||
*/
|
||||
export interface AzureServiceClientOptions extends ServiceClientOptions {
|
||||
/**
|
||||
* @property {string} [options.acceptLanguage] - Gets or sets the preferred language for the response. Default value is: "en-US".
|
||||
*/
|
||||
acceptLanguage?: string;
|
||||
|
||||
/**
|
||||
* @property {number} [options.longRunningOperationRetryTimeout] - Gets or sets the retry timeout in seconds for
|
||||
* Long Running Operations. Default value is 30.
|
||||
*/
|
||||
longRunningOperationRetryTimeout?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @class
|
||||
* Initializes a new instance of the AzureServiceClient class.
|
||||
* @constructor
|
||||
*
|
||||
* @param credentials The credentials used for authentication with the service.
|
||||
* @param options The parameter options used by AzureServiceClient.
|
||||
*/
|
||||
export class AzureServiceClient extends ServiceClient {
|
||||
public acceptLanguage: string = Constants.DEFAULT_LANGUAGE;
|
||||
/**
|
||||
* The retry timeout in seconds for Long Running Operations. Default value is 30.
|
||||
*/
|
||||
public longRunningOperationRetryTimeout?: number;
|
||||
|
||||
constructor(credentials: TokenCredential | ServiceClientCredentials, options?: AzureServiceClientOptions) {
|
||||
super(credentials, options = updateOptionsWithDefaultValues(options));
|
||||
|
||||
// For convenience, if the credentials have an associated AzureEnvironment,
|
||||
// automatically use the baseUri from that environment.
|
||||
const env = (credentials as any).environment;
|
||||
if (env && !this.baseUri) {
|
||||
this.baseUri = env.resourceManagerEndpointUrl;
|
||||
}
|
||||
|
||||
if (options.acceptLanguage != undefined) {
|
||||
this.acceptLanguage = options.acceptLanguage;
|
||||
}
|
||||
|
||||
if (options.longRunningOperationRetryTimeout != undefined) {
|
||||
this.longRunningOperationRetryTimeout = options.longRunningOperationRetryTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the initial request of a LRO (long running operation) and get back an
|
||||
* LROPoller that provides methods for polling the LRO and checking if the LRO is finished.
|
||||
* @param operationArguments The arguments to the operation.
|
||||
* @param operationSpec The specification for the operation.
|
||||
* @param options Additional options to be sent while making the request.
|
||||
* @returns The LROPoller object that provides methods for interacting with the LRO.
|
||||
*/
|
||||
sendLRORequest(operationArguments: OperationArguments, operationSpec: OperationSpec, options?: RequestOptionsBase): Promise<LROPoller> {
|
||||
return this.sendOperationRequest(operationArguments, operationSpec)
|
||||
.then(initialResponse => createLROPollerFromInitialResponse(this, initialResponse._response, options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a mechanism to make a request that will poll and provide the final result.
|
||||
* @param {RequestPrepareOptions | WebResource} request - The request object
|
||||
* @param {AzureRequestOptionsBase} [options] Additional options to be sent while making the request
|
||||
* @returns {Promise<HttpOperationResponse>} The HttpOperationResponse containing the final polling request, response and the responseBody.
|
||||
*/
|
||||
sendLongRunningRequest(request: RequestPrepareOptions | WebResource, options?: RequestOptionsBase): Promise<HttpOperationResponse> {
|
||||
return this.beginLongRunningRequest(request, options)
|
||||
.then((lroResponse: LROPoller) => lroResponse.pollUntilFinished())
|
||||
.then(res => res._response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the initial request of a LRO (long running operation) and get back an
|
||||
* HttpLongRunningOperationResponse that provides methods for polling the LRO and checking if the
|
||||
* LRO is finished.
|
||||
* @param {RequestPrepareOptions | WebResource} request - The request object
|
||||
* @param {AzureRequestOptionsBase} [options] Additional options to be sent while making the request
|
||||
* @returns {Promise<LROPoller>} The HttpLongRunningOperationResponse
|
||||
* that provides methods for interacting with the LRO.
|
||||
*/
|
||||
beginLongRunningRequest(request: RequestPrepareOptions | WebResource, options?: RequestOptionsBase): Promise<LROPoller> {
|
||||
return this.sendRequest(request)
|
||||
.then((initialResponse: HttpOperationResponse) => createLROPollerFromInitialResponse(this, initialResponse, options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore an LROPoller from the provided LROPollState. This method can be used to recreate an
|
||||
* LROPoller on a different process or machine.
|
||||
*/
|
||||
restoreLROPoller(lroPollState: LROPollState): LROPoller {
|
||||
return createLROPollerFromPollState(this, lroPollState);
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultUserAgentValue(): string {
|
||||
const defaultUserAgent = getDefaultUserAgentValueFromMsRest();
|
||||
return `core-arm/${Constants.coreArmVersion} ${defaultUserAgent}`;
|
||||
}
|
||||
|
||||
export function updateOptionsWithDefaultValues(options?: AzureServiceClientOptions): AzureServiceClientOptions {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (options.generateClientRequestIdHeader == undefined) {
|
||||
options.generateClientRequestIdHeader = true;
|
||||
}
|
||||
|
||||
if (!options.userAgent) {
|
||||
options.userAgent = getDefaultUserAgentValue();
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { CompositeMapper } from "@azure/core-http";
|
||||
|
||||
/**
|
||||
* @class
|
||||
* An empty interface.
|
||||
*/
|
||||
export interface BaseResource { }
|
||||
|
||||
export const BaseResourceMapper: CompositeMapper = {
|
||||
serializedName: "BaseResource",
|
||||
type: {
|
||||
name: "Composite",
|
||||
className: "BaseResource",
|
||||
modelProperties: {
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,125 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { CompositeMapper } from "@azure/core-http";
|
||||
|
||||
/**
|
||||
* @class
|
||||
* Provides additional information about an http error response returned from a Microsoft Azure service.
|
||||
*/
|
||||
export interface CloudError extends Error {
|
||||
/**
|
||||
* @property {string} code The error code parsed from the body of the http error response.
|
||||
*/
|
||||
code: string;
|
||||
/**
|
||||
* @property {string} message The error message parsed from the body of the http error response.
|
||||
*/
|
||||
message: string;
|
||||
/**
|
||||
* @property {string} [target] The target of the error.
|
||||
*/
|
||||
target?: string;
|
||||
/**
|
||||
* @property {Array<CloudError>} [details] An array of CloudError objects specifying the details.
|
||||
*/
|
||||
details?: Array<CloudError>;
|
||||
/**
|
||||
* @property {any} [innerError] The inner error parsed from the body of the http error response
|
||||
*/
|
||||
innerError?: any;
|
||||
/**
|
||||
* @property {AdditionalInfoElement} [innerError] The additional error information
|
||||
*/
|
||||
additionalInfo?: AdditionalInfoElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* Additional data for an instance of CloudError.
|
||||
*/
|
||||
export interface AdditionalInfoElement {
|
||||
/**
|
||||
* @property {string} [type] Type of the data.
|
||||
*/
|
||||
type?: string;
|
||||
|
||||
/**
|
||||
* @property {string} [info] Additional info.
|
||||
*/
|
||||
info?: string;
|
||||
}
|
||||
|
||||
export const CloudErrorMapper: CompositeMapper = {
|
||||
serializedName: "CloudError",
|
||||
type: {
|
||||
name: "Composite",
|
||||
className: "CloudError",
|
||||
modelProperties: {
|
||||
code: {
|
||||
required: true,
|
||||
serializedName: "code",
|
||||
type: {
|
||||
name: "String"
|
||||
}
|
||||
},
|
||||
message: {
|
||||
required: true,
|
||||
serializedName: "message",
|
||||
type: {
|
||||
name: "String"
|
||||
}
|
||||
},
|
||||
target: {
|
||||
serializedName: "target",
|
||||
type: {
|
||||
name: "String"
|
||||
}
|
||||
},
|
||||
details: {
|
||||
serializedName: "details",
|
||||
type: {
|
||||
name: "Sequence",
|
||||
element: {
|
||||
serializedName: "CloudErrorElementType",
|
||||
type: {
|
||||
name: "Composite",
|
||||
className: "CloudError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
innerError: {
|
||||
required: false,
|
||||
serializedName: "innererror",
|
||||
type: {
|
||||
name: "Object"
|
||||
}
|
||||
},
|
||||
additionalInfo: {
|
||||
required: false,
|
||||
serializedName: "additionalInfo",
|
||||
type: {
|
||||
name: "Composite",
|
||||
className: "AdditionalInfoElement",
|
||||
modelProperties: {
|
||||
type: {
|
||||
required: true,
|
||||
serializedName: "type",
|
||||
type: {
|
||||
name: "String"
|
||||
}
|
||||
},
|
||||
info: {
|
||||
required: false,
|
||||
serializedName: "info",
|
||||
type: {
|
||||
name: "Object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
export { AzureServiceClient, AzureServiceClientOptions, getDefaultUserAgentValue } from "./azureServiceClient";
|
||||
export { BaseResource, BaseResourceMapper } from "./baseResource";
|
||||
export { CloudError, CloudErrorMapper } from "./cloudError";
|
||||
export { CognitiveServicesCredentials } from "./credentials/cognitiveServicesCredentials";
|
||||
export { createLROPollerFromInitialResponse, createLROPollerFromPollState, LROPoller } from "./lroPoller";
|
||||
export { DEFAULT_LANGUAGE, LongRunningOperationStates, coreArmVersion } from "./util/constants";
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { ApiKeyCredentials } from "@azure/core-http";
|
||||
|
||||
/**
|
||||
* Creates a new CognitiveServicesCredentials object.
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} subscriptionKey The CognitiveServices subscription key
|
||||
*/
|
||||
export class CognitiveServicesCredentials extends ApiKeyCredentials {
|
||||
constructor(subscriptionKey: string) {
|
||||
if (!subscriptionKey || (subscriptionKey && typeof subscriptionKey.valueOf() !== "string")) {
|
||||
throw new Error("subscriptionKey cannot be null or undefined and must be of type string.");
|
||||
}
|
||||
|
||||
const options = {
|
||||
inHeader: {
|
||||
"Ocp-Apim-Subscription-Key": subscriptionKey,
|
||||
"X-BingApis-SDK-Client": "node-SDK"
|
||||
}
|
||||
};
|
||||
super(options);
|
||||
}
|
||||
}
|
|
@ -1,592 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { delay, HttpMethods, HttpOperationResponse, RequestOptionsBase, RestError, stripRequest, WebResource, OperationResponse, OperationSpec } from "@azure/core-http";
|
||||
import { AzureServiceClient } from "./azureServiceClient";
|
||||
import { LongRunningOperationStates } from "./util/constants";
|
||||
|
||||
export type LROPollStrategyType = "AzureAsyncOperation" | "Location" | "GetResource";
|
||||
|
||||
export interface LROPollState {
|
||||
pollStrategyType: LROPollStrategyType;
|
||||
initialResponse: HttpOperationResponse;
|
||||
state: LongRunningOperationStates;
|
||||
mostRecentRequest: WebResource;
|
||||
mostRecentResponse: HttpOperationResponse;
|
||||
resource: any;
|
||||
azureAsyncOperationHeaderValue?: string;
|
||||
locationHeaderValue?: string;
|
||||
options?: RequestOptionsBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* A long-running operation polling strategy base class that other polling strategies should extend.
|
||||
*/
|
||||
export abstract class LROPollStrategy {
|
||||
constructor(private readonly _azureServiceClient: AzureServiceClient, protected readonly _pollState: LROPollState) {
|
||||
}
|
||||
|
||||
public getOperationStatus(): LongRunningOperationStates {
|
||||
return this._pollState.state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not this poll strategy's LRO is finished.
|
||||
* @returns Whether or not this poll strategy's LRO is finished.
|
||||
*/
|
||||
public isFinished(): boolean {
|
||||
return isFinished(this._pollState.state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send poll requests that check the LRO's status until it is determined that the LRO is finished.
|
||||
* @returns Whether or not the LRO succeeded.
|
||||
*/
|
||||
public async pollUntilFinished(): Promise<boolean> {
|
||||
while (!this.isFinished()) {
|
||||
const delayInSeconds: number = getDelayInSeconds(this._azureServiceClient, this._pollState.mostRecentResponse);
|
||||
await delay(delayInSeconds * 1000);
|
||||
|
||||
await this.sendPollRequest();
|
||||
}
|
||||
return this.isFinalStatusAcceptable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a single poll request that checks the LRO's status and return the response. If the LRO is
|
||||
* finished, then no request will be sent and the last response received will be returned.
|
||||
*/
|
||||
public abstract sendPollRequest(): Promise<void>;
|
||||
|
||||
public abstract isFinalStatusAcceptable(): boolean;
|
||||
|
||||
protected shouldDoFinalGetResourceRequest(): boolean {
|
||||
const initialRequestMethod: HttpMethods = this._pollState.initialResponse.request.method;
|
||||
return !this._pollState.resource && (initialRequestMethod === "PUT" || initialRequestMethod === "PATCH" || initialRequestMethod === "POST");
|
||||
}
|
||||
|
||||
protected abstract doFinalGetResourceRequest(): Promise<void>;
|
||||
|
||||
public getMostRecentResponse(): HttpOperationResponse {
|
||||
return this._pollState.mostRecentResponse;
|
||||
}
|
||||
|
||||
public async getOperationResponse(): Promise<HttpOperationResponse> {
|
||||
if (this.shouldDoFinalGetResourceRequest()) {
|
||||
await this.doFinalGetResourceRequest();
|
||||
}
|
||||
const response: HttpOperationResponse = this._pollState.mostRecentResponse;
|
||||
const result: HttpOperationResponse = {
|
||||
...response,
|
||||
headers: response.headers.clone()
|
||||
};
|
||||
const resource: any = this._pollState.resource;
|
||||
if (!resource) {
|
||||
result.bodyAsText = response.bodyAsText;
|
||||
result.parsedBody = response.parsedBody;
|
||||
} else if (typeof resource.valueOf() === "string") {
|
||||
result.bodyAsText = resource;
|
||||
result.parsedBody = JSON.parse(resource);
|
||||
} else {
|
||||
result.bodyAsText = JSON.stringify(resource);
|
||||
result.parsedBody = resource;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public getRestError(): RestError {
|
||||
const error = new RestError("");
|
||||
error.request = stripRequest(this._pollState.mostRecentRequest);
|
||||
error.response = this._pollState.mostRecentResponse;
|
||||
error.message = `Long running operation failed with status: "${this._pollState.state}".`;
|
||||
error.response.parsedBody = this._pollState.resource;
|
||||
if (error.response.parsedBody) {
|
||||
const innerError: any = error.response.parsedBody.error;
|
||||
if (innerError) {
|
||||
if (innerError.message) {
|
||||
error.message = `Long running operation failed with error: "${innerError.message}".`;
|
||||
}
|
||||
if (innerError.code) {
|
||||
error.code = innerError.code;
|
||||
}
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
protected updateState(url: string, shouldDeserialize: boolean | ((response: HttpOperationResponse) => boolean)): Promise<void> {
|
||||
return this.updateOperationStatus(url, shouldDeserialize).then(result => {
|
||||
this._pollState.state = getProvisioningState(result.parsedBody) || "Succeeded";
|
||||
this._pollState.mostRecentResponse = result;
|
||||
this._pollState.mostRecentRequest = result.request;
|
||||
this._pollState.resource = getResponseBody(result);
|
||||
}).catch((error) => {
|
||||
let resultStatus: number | undefined;
|
||||
if (error.response && error.response.status) {
|
||||
resultStatus = error.response.status;
|
||||
if (this._pollState.initialResponse.request.method !== "DELETE" || resultStatus! < 400 || 499 < resultStatus!) {
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves operation status by querying the operation URL.
|
||||
* @param {string} statusUrl URL used to poll operation result.
|
||||
*/
|
||||
protected updateOperationStatus(statusUrl: string, shouldDeserialize: boolean | ((response: HttpOperationResponse) => boolean)): Promise<HttpOperationResponse> {
|
||||
const requestUrl: string = statusUrl.replace(" ", "%20");
|
||||
const httpRequest = new WebResource(requestUrl, "GET");
|
||||
const pollState: LROPollState = this._pollState;
|
||||
httpRequest.operationSpec = pollState.mostRecentRequest.operationSpec;
|
||||
httpRequest.shouldDeserialize = shouldDeserialize;
|
||||
httpRequest.operationResponseGetter = getOperationResponse;
|
||||
const options: RequestOptionsBase | undefined = pollState.options;
|
||||
if (options && options.customHeaders) {
|
||||
const customHeaders = options.customHeaders;
|
||||
for (const headerName of Object.keys(customHeaders)) {
|
||||
httpRequest.headers.set(headerName, customHeaders[headerName]);
|
||||
}
|
||||
}
|
||||
return this._azureServiceClient.sendRequest(httpRequest);
|
||||
}
|
||||
|
||||
public getPollState(): LROPollState {
|
||||
return this._pollState;
|
||||
}
|
||||
}
|
||||
|
||||
function getOperationResponse(operationSpec: OperationSpec, response: HttpOperationResponse): OperationResponse | undefined {
|
||||
const statusCode: number = response.status;
|
||||
const operationResponses: { [statusCode: string]: OperationResponse } = operationSpec.responses;
|
||||
let result: OperationResponse | undefined = operationResponses[statusCode];
|
||||
if (!result) {
|
||||
if (statusCode === 200) {
|
||||
result = operationResponses[201] || operationResponses[202];
|
||||
} else if (201 <= statusCode && statusCode <= 299) {
|
||||
result = {};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function getDelayInSeconds(azureServiceClient: AzureServiceClient, previousResponse: HttpOperationResponse): number {
|
||||
let delayInSeconds = 30;
|
||||
if (azureServiceClient.longRunningOperationRetryTimeout != undefined) {
|
||||
delayInSeconds = azureServiceClient.longRunningOperationRetryTimeout;
|
||||
} else {
|
||||
const retryAfterHeaderValue: string | undefined = previousResponse.headers.get("retry-after");
|
||||
if (retryAfterHeaderValue) {
|
||||
const retryAfterDelayInSeconds: number = parseInt(retryAfterHeaderValue);
|
||||
if (!Number.isNaN(retryAfterDelayInSeconds)) {
|
||||
delayInSeconds = retryAfterDelayInSeconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
return delayInSeconds;
|
||||
}
|
||||
|
||||
function getProvisioningState(responseBody: any): LongRunningOperationStates | undefined {
|
||||
let result: LongRunningOperationStates | undefined;
|
||||
if (responseBody) {
|
||||
if (responseBody.provisioningState) {
|
||||
result = responseBody.provisioningState;
|
||||
} else if (responseBody.properties) {
|
||||
result = responseBody.properties.provisioningState;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getResponseBody(response: HttpOperationResponse): any {
|
||||
let result: any;
|
||||
try {
|
||||
if (response.parsedBody) {
|
||||
result = response.parsedBody;
|
||||
} else if (response.bodyAsText && response.bodyAsText.length > 0) {
|
||||
result = JSON.parse(response.bodyAsText);
|
||||
}
|
||||
} catch (error) {
|
||||
const deserializationError = new RestError(`Error "${error}" occurred in parsing the responseBody " +
|
||||
"while creating the PollingState for Long Running Operation- "${response.bodyAsText}"`);
|
||||
deserializationError.request = response.request;
|
||||
deserializationError.response = response;
|
||||
throw deserializationError;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getStatusFromResponse(response: HttpOperationResponse, responseBody?: any): LongRunningOperationStates {
|
||||
if (responseBody == undefined) {
|
||||
responseBody = getResponseBody(response);
|
||||
}
|
||||
|
||||
let result: LongRunningOperationStates;
|
||||
switch (response.status) {
|
||||
case 202:
|
||||
result = "InProgress";
|
||||
break;
|
||||
|
||||
case 204:
|
||||
result = "Succeeded";
|
||||
break;
|
||||
|
||||
case 201:
|
||||
result = getProvisioningState(responseBody) || "InProgress";
|
||||
break;
|
||||
|
||||
case 200:
|
||||
const provisioningState: LongRunningOperationStates | undefined = getProvisioningState(responseBody);
|
||||
if (provisioningState) {
|
||||
result = provisioningState;
|
||||
} else if (getAzureAsyncOperationHeaderValue(response) || getLocationHeaderValue(response)) {
|
||||
result = "InProgress";
|
||||
} else {
|
||||
result = "Succeeded";
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
result = "Failed";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const terminalStates: LongRunningOperationStates[] = ["Succeeded", "Failed", "Canceled", "Cancelled"];
|
||||
|
||||
/**
|
||||
* Get whether or not a long-running operation with the provided status is finished.
|
||||
* @param status The current status of a long-running operation.
|
||||
* @returns Whether or not a long-running operation with the provided status is finished.
|
||||
*/
|
||||
export function isFinished(status: LongRunningOperationStates): boolean {
|
||||
let result = false;
|
||||
for (const terminalState of terminalStates) {
|
||||
if (longRunningOperationStatesEqual(status, terminalState)) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function longRunningOperationStatesEqual(lhs: LongRunningOperationStates, rhs: LongRunningOperationStates): boolean {
|
||||
const lhsLowerCased: string = lhs && lhs.toLowerCase();
|
||||
const rhsLowerCased: string = rhs && rhs.toLowerCase();
|
||||
return lhsLowerCased === rhsLowerCased;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new long-running operation polling strategy based on the provided initial response.
|
||||
* @param initialResponse The initial response to the long-running operation's initial request.
|
||||
* @param azureServiceClient The AzureServiceClient that was used to send the initial request.
|
||||
* @param options Any options that were provided to the initial request.
|
||||
*/
|
||||
export function createLROPollStrategyFromInitialResponse(initialResponse: HttpOperationResponse, azureServiceClient: AzureServiceClient, options?: RequestOptionsBase): LROPollStrategy | undefined {
|
||||
const initialRequestMethod: HttpMethods = initialResponse.request.method;
|
||||
const initialResponseStatus: number = initialResponse.status;
|
||||
|
||||
let lroPollStrategyType: LROPollStrategyType | undefined;
|
||||
if (getAzureAsyncOperationHeaderValue(initialResponse)) {
|
||||
lroPollStrategyType = "AzureAsyncOperation";
|
||||
} else if (getLocationHeaderValue(initialResponse)) {
|
||||
lroPollStrategyType = "Location";
|
||||
} else if (initialRequestMethod === "PUT" || initialRequestMethod === "PATCH") {
|
||||
lroPollStrategyType = "GetResource";
|
||||
} else if (initialResponseStatus !== 201 && initialResponseStatus !== 202 && !isFinished(getStatusFromResponse(initialResponse))) {
|
||||
throw new Error("Can't determine long running operation polling strategy.");
|
||||
}
|
||||
|
||||
let result: LROPollStrategy | undefined;
|
||||
if (lroPollStrategyType) {
|
||||
const resource: any = getResponseBody(initialResponse);
|
||||
const lroPollState: LROPollState = {
|
||||
pollStrategyType: lroPollStrategyType,
|
||||
options: options,
|
||||
initialResponse: initialResponse,
|
||||
mostRecentResponse: initialResponse,
|
||||
mostRecentRequest: initialResponse.request,
|
||||
azureAsyncOperationHeaderValue: getAzureAsyncOperationHeaderValue(initialResponse),
|
||||
locationHeaderValue: getLocationHeaderValue(initialResponse),
|
||||
resource: resource,
|
||||
state: getStatusFromResponse(initialResponse, resource)
|
||||
};
|
||||
result = createLROPollStrategyFromPollState(azureServiceClient, lroPollState);
|
||||
} else {
|
||||
result = undefined;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function createLROPollStrategyFromPollState(azureServiceClient: AzureServiceClient, lroPollState: LROPollState): LROPollStrategy | undefined {
|
||||
let result: LROPollStrategy;
|
||||
switch (lroPollState.pollStrategyType) {
|
||||
case "AzureAsyncOperation":
|
||||
result = new AzureAsyncOperationLROPollStrategy(azureServiceClient, lroPollState);
|
||||
break;
|
||||
|
||||
case "Location":
|
||||
result = new LocationLROPollStrategy(azureServiceClient, lroPollState);
|
||||
break;
|
||||
|
||||
case "GetResource":
|
||||
result = new GetResourceLROPollStrategy(azureServiceClient, lroPollState);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error(`Unrecognized LRO poll strategy type: "${lroPollState.pollStrategyType}"`);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getLocationHeaderValue(response: HttpOperationResponse): string | undefined {
|
||||
return response.headers.get("location");
|
||||
}
|
||||
|
||||
/**
|
||||
* A long-running operation polling strategy that is based on the location header.
|
||||
*/
|
||||
class LocationLROPollStrategy extends LROPollStrategy {
|
||||
private locationStrategyShouldDeserialize(parsedResponse: HttpOperationResponse): boolean {
|
||||
let shouldDeserialize = false;
|
||||
|
||||
const initialResponse: HttpOperationResponse = this._pollState.initialResponse;
|
||||
const initialRequestMethod: HttpMethods = initialResponse.request.method;
|
||||
const statusCode: number = parsedResponse.status;
|
||||
if (statusCode === 200 ||
|
||||
(statusCode === 201 && (initialRequestMethod === "PUT" || initialRequestMethod === "PATCH")) ||
|
||||
(statusCode === 204 && (initialRequestMethod === "DELETE" || initialRequestMethod === "POST"))) {
|
||||
shouldDeserialize = true;
|
||||
}
|
||||
|
||||
return shouldDeserialize;
|
||||
}
|
||||
/**
|
||||
* Retrieve PUT operation status by polling from "location" header.
|
||||
* @param {string} method - The HTTP method.
|
||||
* @param {PollingState} pollingState - The object to persist current operation state.
|
||||
*/
|
||||
public sendPollRequest(): Promise<void> {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
return this.updateOperationStatus(lroPollState.locationHeaderValue!, this.locationStrategyShouldDeserialize.bind(this)).then((result: HttpOperationResponse) => {
|
||||
const locationHeaderValue: string | undefined = getLocationHeaderValue(result);
|
||||
if (locationHeaderValue) {
|
||||
lroPollState.locationHeaderValue = locationHeaderValue;
|
||||
}
|
||||
|
||||
lroPollState.mostRecentResponse = result;
|
||||
lroPollState.mostRecentRequest = result.request;
|
||||
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
const initialRequestMethod: HttpMethods = initialResponse.request.method;
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
const statusCode: number = result.status;
|
||||
if (statusCode === 202) {
|
||||
lroPollState.state = "InProgress";
|
||||
} else if (statusCode === 200 ||
|
||||
(statusCode === 201 && (initialRequestMethod === "PUT" || initialRequestMethod === "PATCH")) ||
|
||||
(statusCode === 204 && (initialRequestMethod === "DELETE" || initialRequestMethod === "POST"))) {
|
||||
lroPollState.state = "Succeeded";
|
||||
lroPollState.resource = getResponseBody(result);
|
||||
} else if (statusCode === 404 && initialRequestMethod === "POST" &&
|
||||
(initialResponseStatusCode === 200 || initialResponseStatusCode === 201 || initialResponseStatusCode === 202)) {
|
||||
lroPollState.state = "Failed";
|
||||
lroPollState.resource = getResponseBody(result);
|
||||
} else if (400 <= statusCode && statusCode <= 499) {
|
||||
const resultBody: string = result.bodyAsText!;
|
||||
let errorMessage: string = resultBody;
|
||||
try {
|
||||
const resultObject = JSON.parse(resultBody);
|
||||
errorMessage = resultObject.message;
|
||||
} catch (parseError) {
|
||||
// Ignore the exception, use resultBody as the error message
|
||||
}
|
||||
|
||||
throw new RestError(errorMessage, undefined, statusCode, stripRequest(result.request), result);
|
||||
} else {
|
||||
throw new Error(`The response with status code ${statusCode} from polling for long running operation url "${lroPollState.locationHeaderValue}" is not valid.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public isFinalStatusAcceptable(): boolean {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
return longRunningOperationStatesEqual(lroPollState.state, "Succeeded") ||
|
||||
(initialResponse.request.method === "POST" && lroPollState.mostRecentResponse.status === 404 &&
|
||||
(initialResponseStatusCode === 200 ||
|
||||
initialResponseStatusCode === 201 ||
|
||||
initialResponseStatusCode === 202));
|
||||
}
|
||||
|
||||
protected shouldDoFinalGetResourceRequest(): boolean {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
let result: boolean;
|
||||
const initialRequestMethod: HttpMethods = initialResponse.request.method;
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
if (initialRequestMethod === "POST" && lroPollState.mostRecentResponse.status === 404 &&
|
||||
(initialResponseStatusCode === 200 ||
|
||||
initialResponseStatusCode === 201 ||
|
||||
initialResponseStatusCode === 202)) {
|
||||
result = false;
|
||||
} else {
|
||||
result = super.shouldDoFinalGetResourceRequest() ||
|
||||
(initialRequestMethod === "POST" && initialResponseStatusCode === 201);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected doFinalGetResourceRequest(): Promise<void> {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
let getResourceRequestUrl: string;
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
const initialRequest: WebResource = initialResponse.request;
|
||||
if (initialRequest.method === "POST" &&
|
||||
(initialResponseStatusCode === 200 ||
|
||||
initialResponseStatusCode === 201 ||
|
||||
initialResponseStatusCode === 202)) {
|
||||
getResourceRequestUrl = lroPollState.locationHeaderValue!;
|
||||
} else {
|
||||
getResourceRequestUrl = initialRequest.url;
|
||||
}
|
||||
return this.updateState(getResourceRequestUrl, true);
|
||||
}
|
||||
}
|
||||
|
||||
function getAzureAsyncOperationHeaderValue(response: HttpOperationResponse): string | undefined {
|
||||
return response.headers.get("azure-asyncoperation");
|
||||
}
|
||||
|
||||
/**
|
||||
* A long-running operation polling strategy that is based on the azure-asyncoperation header.
|
||||
*/
|
||||
class AzureAsyncOperationLROPollStrategy extends LROPollStrategy {
|
||||
/**
|
||||
* Retrieve operation status by polling from "azure-asyncoperation" header.
|
||||
* @param {PollingState} pollingState - The object to persist current operation state.
|
||||
* @param {boolean} inPostOrDelete - Invoked by Post Or Delete operation.
|
||||
*/
|
||||
public sendPollRequest(): Promise<void> {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
return this.updateOperationStatus(lroPollState.azureAsyncOperationHeaderValue!, false).then((response: HttpOperationResponse) => {
|
||||
const statusCode: number = response.status;
|
||||
const parsedResponse: any = response.parsedBody;
|
||||
if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202 && statusCode !== 204) {
|
||||
const error = new RestError(`Invalid status code (${statusCode}) with response body "${response.bodyAsText}" occurred when polling for operation status.`);
|
||||
error.statusCode = statusCode;
|
||||
error.request = stripRequest(response.request);
|
||||
error.response = response;
|
||||
error.response.parsedBody = parsedResponse;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!parsedResponse) {
|
||||
throw new Error("The response from long running operation does not contain a body.");
|
||||
} else if (!parsedResponse.status) {
|
||||
throw new Error(`The response "${response.bodyAsText}" from long running operation does not contain the status property.`);
|
||||
}
|
||||
|
||||
const azureAsyncOperationHeaderValue: string | undefined = getAzureAsyncOperationHeaderValue(response);
|
||||
if (azureAsyncOperationHeaderValue) {
|
||||
lroPollState.azureAsyncOperationHeaderValue = azureAsyncOperationHeaderValue;
|
||||
}
|
||||
|
||||
lroPollState.state = parsedResponse.status;
|
||||
lroPollState.mostRecentResponse = response;
|
||||
lroPollState.mostRecentRequest = response.request;
|
||||
lroPollState.resource = getResponseBody(response);
|
||||
});
|
||||
}
|
||||
|
||||
protected shouldDoFinalGetResourceRequest(): boolean {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
const initialRequestMethod: HttpMethods = initialResponse.request.method;
|
||||
let result = false;
|
||||
if (initialRequestMethod === "PUT" || initialRequestMethod === "PATCH") {
|
||||
result = true;
|
||||
} else {
|
||||
if (lroPollState.locationHeaderValue) {
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
if (initialRequestMethod === "POST") {
|
||||
result = initialResponseStatusCode === 200 || initialResponseStatusCode === 201;
|
||||
} else if (initialRequestMethod === "DELETE") {
|
||||
result = initialResponseStatusCode === 200 || initialResponseStatusCode === 202;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected doFinalGetResourceRequest(): Promise<void> {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
const locationHeaderValue: string | undefined = lroPollState.locationHeaderValue;
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
const initialRequest: WebResource = initialResponse.request;
|
||||
let getResourceRequestUrl: string = initialRequest.url;
|
||||
if (locationHeaderValue) {
|
||||
const initialRequestMethod: HttpMethods = initialRequest.method;
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
if (initialRequestMethod === "POST" && (initialResponseStatusCode === 200 || initialResponseStatusCode === 201 || initialResponseStatusCode === 202)) {
|
||||
getResourceRequestUrl = locationHeaderValue;
|
||||
} else if (initialRequestMethod === "DELETE" && (initialResponseStatusCode === 200 || initialResponseStatusCode === 202)) {
|
||||
getResourceRequestUrl = locationHeaderValue;
|
||||
}
|
||||
}
|
||||
return this.updateState(getResourceRequestUrl, true);
|
||||
}
|
||||
|
||||
public isFinalStatusAcceptable(): boolean {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
const initialResponse: HttpOperationResponse = lroPollState.initialResponse;
|
||||
const initialResponseStatusCode: number = initialResponse.status;
|
||||
return longRunningOperationStatesEqual(lroPollState.state, "Succeeded") ||
|
||||
(initialResponse.request.method === "POST" && (initialResponseStatusCode === 200 || initialResponseStatusCode === 201));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A long-running operation polling strategy that is based on the resource's provisioning state.
|
||||
*/
|
||||
class GetResourceLROPollStrategy extends LROPollStrategy {
|
||||
public sendPollRequest(): Promise<void> {
|
||||
const lroPollState: LROPollState = this._pollState;
|
||||
return this.updateOperationStatus(lroPollState.initialResponse.request.url, false).then(result => {
|
||||
const statusCode: number = result.status;
|
||||
const responseBody: any = result.parsedBody;
|
||||
if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202 && statusCode !== 204) {
|
||||
const error = new RestError(`Invalid status code with response body "${result.bodyAsText}" occurred when polling for operation status.`);
|
||||
error.statusCode = statusCode;
|
||||
error.request = stripRequest(result.request);
|
||||
error.response = result;
|
||||
error.response.parsedBody = responseBody;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!result.parsedBody) {
|
||||
throw new Error("The response from long running operation does not contain a body.");
|
||||
}
|
||||
|
||||
lroPollState.state = getProvisioningState(result.parsedBody) || "Succeeded";
|
||||
lroPollState.mostRecentResponse = result;
|
||||
lroPollState.mostRecentRequest = result.request;
|
||||
lroPollState.resource = getResponseBody(result);
|
||||
});
|
||||
}
|
||||
|
||||
public isFinalStatusAcceptable(): boolean {
|
||||
return longRunningOperationStatesEqual(this._pollState.state, "Succeeded");
|
||||
}
|
||||
|
||||
protected doFinalGetResourceRequest(): Promise<void> {
|
||||
return this.sendPollRequest();
|
||||
}
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { HttpOperationResponse, RequestOptionsBase, RestResponse, flattenResponse } from "@azure/core-http";
|
||||
import { AzureServiceClient } from "./azureServiceClient";
|
||||
import { createLROPollStrategyFromInitialResponse, createLROPollStrategyFromPollState, LROPollState, LROPollStrategy } from "./lroPollStrategy";
|
||||
import { LongRunningOperationStates } from "./util/constants";
|
||||
|
||||
/**
|
||||
* An HTTP operation response that provides special methods for interacting with LROs (long running
|
||||
* operations).
|
||||
*/
|
||||
export class LROPoller {
|
||||
/**
|
||||
* Create a new HttpLongRunningOperationResponse.
|
||||
* @param _lroPollStrategy The LROPollStrategy that this HttpLongRunningOperationResponse will
|
||||
* use to interact with the LRO.
|
||||
*/
|
||||
constructor(private readonly _lroPollStrategy: LROPollStrategy | undefined, private readonly _initialResponse: HttpOperationResponse) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first response that the service sent back when the LRO was initiated.
|
||||
*/
|
||||
public getInitialResponse(): HttpOperationResponse {
|
||||
return this._initialResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the most recent response that the service sent back during this LRO.
|
||||
*/
|
||||
public getMostRecentResponse(): HttpOperationResponse {
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
return !lroPollStrategy ? this._initialResponse : lroPollStrategy.getMostRecentResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not the LRO is finished.
|
||||
*/
|
||||
public isFinished(): boolean {
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
return !lroPollStrategy ? true : lroPollStrategy.isFinished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether or not the LRO is finished and its final state is acceptable. If the LRO has not
|
||||
* finished yet, then undefined will be returned. An "acceptable" final state is determined by the
|
||||
* LRO strategy that the Azure service uses to perform long running operations.
|
||||
*/
|
||||
public isFinalStatusAcceptable(): boolean | undefined {
|
||||
let result: boolean | undefined;
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
if (!lroPollStrategy) {
|
||||
result = true;
|
||||
} else if (lroPollStrategy.isFinished()) {
|
||||
result = lroPollStrategy.isFinalStatusAcceptable();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current status of the LRO.
|
||||
*/
|
||||
public getOperationStatus(): LongRunningOperationStates {
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
return !lroPollStrategy ? "Succeeded" : lroPollStrategy.getOperationStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the LRO is finished and in an acceptable state, then return the HttpOperationResponse. If
|
||||
* the LRO is finished and not in an acceptable state, then throw the error that the LRO produced.
|
||||
* If the LRO is not finished, then return undefined.
|
||||
*/
|
||||
public getOperationResponse(): Promise<HttpOperationResponse | undefined> {
|
||||
let result: Promise<HttpOperationResponse | undefined>;
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
if (!lroPollStrategy) {
|
||||
result = Promise.resolve(this._initialResponse);
|
||||
} else if (!lroPollStrategy.isFinished()) {
|
||||
result = Promise.resolve(undefined);
|
||||
} else if (lroPollStrategy.isFinalStatusAcceptable()) {
|
||||
result = lroPollStrategy.getOperationResponse();
|
||||
} else {
|
||||
throw lroPollStrategy.getRestError();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a single poll request and return the LRO's state.
|
||||
*/
|
||||
public poll(): Promise<LongRunningOperationStates> {
|
||||
let result: Promise<LongRunningOperationStates>;
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
if (!lroPollStrategy) {
|
||||
result = Promise.resolve<LongRunningOperationStates>("Succeeded");
|
||||
} else {
|
||||
result = lroPollStrategy.sendPollRequest().then(() => {
|
||||
return lroPollStrategy.getOperationStatus();
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send poll requests that check the LRO's status until it is determined that the LRO is finished.
|
||||
*/
|
||||
public async pollUntilFinished(): Promise<RestResponse> {
|
||||
let result: Promise<RestResponse>;
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
|
||||
if (!lroPollStrategy) {
|
||||
result = Promise.resolve(flattenAzureResponse(this._initialResponse));
|
||||
} else {
|
||||
result = lroPollStrategy.pollUntilFinished().then((succeeded: boolean) => {
|
||||
if (succeeded) {
|
||||
return lroPollStrategy.getOperationResponse().then(flattenAzureResponse);
|
||||
} else {
|
||||
throw lroPollStrategy.getRestError();
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an LROPollState object that can be used to poll this LRO in a different context (such as on
|
||||
* a different process or a different machine). If the LRO couldn't produce an LRO polling
|
||||
* strategy, then this will return undefined.
|
||||
*/
|
||||
public getPollState(): LROPollState | undefined {
|
||||
const lroPollStrategy: LROPollStrategy | undefined = this._lroPollStrategy;
|
||||
return !lroPollStrategy ? undefined : lroPollStrategy.getPollState();
|
||||
}
|
||||
}
|
||||
|
||||
export function createLROPollerFromInitialResponse(azureServiceClient: AzureServiceClient, initialResponse: HttpOperationResponse, options?: RequestOptionsBase): LROPoller {
|
||||
const lroPollStrategy: LROPollStrategy | undefined = createLROPollStrategyFromInitialResponse(initialResponse, azureServiceClient, options);
|
||||
return new LROPoller(lroPollStrategy, initialResponse);
|
||||
}
|
||||
|
||||
export function createLROPollerFromPollState(azureServiceClient: AzureServiceClient, lroMemento: LROPollState): LROPoller {
|
||||
const lroPollStrategy: LROPollStrategy | undefined = createLROPollStrategyFromPollState(azureServiceClient, lroMemento);
|
||||
return new LROPoller(lroPollStrategy, lroMemento.initialResponse);
|
||||
}
|
||||
|
||||
function flattenAzureResponse(response: HttpOperationResponse): RestResponse {
|
||||
const { operationResponseGetter, operationSpec } = response.request;
|
||||
return flattenResponse(response, operationResponseGetter && operationSpec && operationResponseGetter(operationSpec, response));
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// d.ts shims provide types for things we use internally but are not part
|
||||
// of this package's surface area.
|
||||
|
||||
interface RequestInit {}
|
||||
|
||||
interface RequestInfo {}
|
||||
|
||||
interface Response {}
|
||||
|
||||
interface Headers {}
|
|
@ -1,30 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
/**
|
||||
* Defines constants for long running operation states.
|
||||
*
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
export type LongRunningOperationStates =
|
||||
| "InProgress"
|
||||
| "Succeeded"
|
||||
| "Failed"
|
||||
| "Canceled"
|
||||
| "Cancelled";
|
||||
|
||||
/**
|
||||
* The default language in the request header.
|
||||
*
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
export const DEFAULT_LANGUAGE = "en-us";
|
||||
|
||||
/**
|
||||
* The core-arm version.
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
export const coreArmVersion = "1.0.0-preview.8";
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,119 +0,0 @@
|
|||
import { Serializer } from "@azure/core-http";
|
||||
import { CloudErrorMapper, CloudError } from "../src/cloudError";
|
||||
import { expect } from "chai";
|
||||
|
||||
|
||||
describe("CloudError", () => {
|
||||
const serializer = new Serializer({ "CloudError": CloudErrorMapper });
|
||||
|
||||
describe("serialization", () => {
|
||||
it("serializes properly required properties", () => {
|
||||
const cloudError: CloudError = {
|
||||
name: "my error",
|
||||
code: "401",
|
||||
message: "test message"
|
||||
};
|
||||
|
||||
const serializedCloudError = serializer.serialize(CloudErrorMapper, cloudError);
|
||||
|
||||
expect(serializedCloudError.name).to.not.exist;
|
||||
expect(serializedCloudError.code).to.be.equal(cloudError.code);
|
||||
expect(serializedCloudError.message).to.be.equal(cloudError.message);
|
||||
expect(serializedCloudError.target).to.not.exist;
|
||||
expect(serializedCloudError.details).to.not.exist;
|
||||
expect(serializedCloudError.innerError).to.not.exist;
|
||||
});
|
||||
|
||||
it("serializes properly optional properties", () => {
|
||||
const cloudError: CloudError = {
|
||||
name: "my error",
|
||||
code: "200",
|
||||
message: "test message",
|
||||
target: "my target",
|
||||
details: [{ name: "error", code: "404", message: "not found" }, { name: "error", code: "500", message: "Internal error" }],
|
||||
innerError: new Error("Resource not found"),
|
||||
stack: "call stack"
|
||||
};
|
||||
|
||||
const serializedCloudError = serializer.serialize(CloudErrorMapper, cloudError);
|
||||
|
||||
expect(serializedCloudError.target).to.be.equal(cloudError.target);
|
||||
expect(serializedCloudError.details[0].code).to.be.equal(cloudError.details![0].code);
|
||||
expect(serializedCloudError.details[0].message).to.be.equal(cloudError.details![0].message);
|
||||
expect(serializedCloudError.details[0].name).to.not.exist;
|
||||
expect(serializedCloudError.details[1].code).to.be.equal(cloudError.details![1].code);
|
||||
expect(serializedCloudError.details[1].message).to.be.equal(cloudError.details![1].message);
|
||||
expect(serializedCloudError.details[1].name).to.not.exist;
|
||||
expect(serializedCloudError.innererror).to.be.equal(cloudError.innerError);
|
||||
expect(serializedCloudError.stack).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe("deserialization", () => {
|
||||
it("serializes properly required properties", () => {
|
||||
const cloudError = {
|
||||
name: "my error",
|
||||
code: "401",
|
||||
message: "test message"
|
||||
};
|
||||
|
||||
const deserializedCloudError: CloudError = serializer.deserialize(CloudErrorMapper, cloudError, "deserializedCloudError");
|
||||
|
||||
expect(deserializedCloudError.name).to.equal(cloudError.name);
|
||||
expect(deserializedCloudError.code).to.be.equal(cloudError.code);
|
||||
expect(deserializedCloudError.message).to.be.equal(cloudError.message);
|
||||
expect(deserializedCloudError.target).to.not.exist;
|
||||
expect(deserializedCloudError.details).to.not.exist;
|
||||
expect(deserializedCloudError.innerError).to.not.exist;
|
||||
});
|
||||
|
||||
it("serializes properly optional properties", () => {
|
||||
const cloudError = {
|
||||
name: "my error",
|
||||
code: "200",
|
||||
message: "test message",
|
||||
target: "my target",
|
||||
details: [{ code: "404", message: "not found" }, { code: "500", message: "Internal error" }],
|
||||
innererror: new Error("Resource not found"),
|
||||
stack: "call stack"
|
||||
};
|
||||
|
||||
const deserializedCloudError: CloudError = serializer.deserialize(CloudErrorMapper, cloudError, "deserializedCloudError");
|
||||
|
||||
expect(deserializedCloudError.target).to.equal(cloudError.target);
|
||||
expect(deserializedCloudError.details).to.deep.equal(cloudError.details);
|
||||
expect(deserializedCloudError.innerError).to.equal(cloudError.innererror);
|
||||
expect(deserializedCloudError.stack).to.equal(cloudError.stack);
|
||||
});
|
||||
|
||||
it("should correctly deserialize additionalInfo", function (done) {
|
||||
const errorBody = {
|
||||
"code": "BadArgument",
|
||||
"message": "The provided database ‘foo’ has an invalid username.",
|
||||
"target": "query",
|
||||
"details": [{
|
||||
"code": "301",
|
||||
"target": "$search",
|
||||
"message": "$search query option not supported",
|
||||
"additionalInfo": {
|
||||
"type": "SomeErrorType",
|
||||
"info": {
|
||||
"someProperty": "SomeValue"
|
||||
}
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
const deserializedError = serializer.deserialize(CloudErrorMapper, errorBody, "deserializedCloudError");
|
||||
|
||||
expect(deserializedError.code).to.equal("BadArgument");
|
||||
expect(deserializedError.message).to.equal("The provided database ‘foo’ has an invalid username.");
|
||||
expect(deserializedError.target).to.equal("query");
|
||||
expect(deserializedError.details.length).to.equal(1);
|
||||
expect(deserializedError.details![0].code).to.equal("301");
|
||||
expect(deserializedError.details![0].additionalInfo.type).to.equal("SomeErrorType");
|
||||
expect(deserializedError.details![0].additionalInfo.info.someProperty).to.equal("SomeValue");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { WebResource } from "@azure/core-http";
|
||||
import { CognitiveServicesCredentials } from "../../src/credentials/cognitiveServicesCredentials";
|
||||
import * as msAssert from "../msAssert";
|
||||
|
||||
describe("CognitiveServicesCredentials", () => {
|
||||
describe("constructor()", () => {
|
||||
it("with undefined subscription key", () => {
|
||||
msAssert.throws(() => new CognitiveServicesCredentials(undefined as any),
|
||||
new Error("subscriptionKey cannot be null or undefined and must be of type string."));
|
||||
});
|
||||
|
||||
it("with null subscription key", () => {
|
||||
// tslint:disable-next-line:no-null-keyword
|
||||
msAssert.throws(() => new CognitiveServicesCredentials(null as any),
|
||||
new Error("subscriptionKey cannot be null or undefined and must be of type string."));
|
||||
});
|
||||
|
||||
it("with number subscription key", () => {
|
||||
msAssert.throws(() => new CognitiveServicesCredentials(50 as any),
|
||||
new Error("subscriptionKey cannot be null or undefined and must be of type string."));
|
||||
});
|
||||
|
||||
it("with empty subscription key", () => {
|
||||
msAssert.throws(() => new CognitiveServicesCredentials(""),
|
||||
new Error("subscriptionKey cannot be null or undefined and must be of type string."));
|
||||
});
|
||||
|
||||
it("with non-empty subscription key", async () => {
|
||||
const credentials = new CognitiveServicesCredentials("fake-subscription-key");
|
||||
const httpRequest = new WebResource();
|
||||
const signedHttpRequest: WebResource = await credentials.signRequest(httpRequest);
|
||||
assert.strictEqual(signedHttpRequest, httpRequest);
|
||||
assert.deepEqual(signedHttpRequest.headers.rawHeaders(), {
|
||||
"ocp-apim-subscription-key": "fake-subscription-key",
|
||||
"x-bingapis-sdk-client": "node-SDK"
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,117 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
import { HttpHeaders, HttpOperationResponse, WebResource } from "@azure/core-http";
|
||||
import { AzureServiceClient } from "../src/azureServiceClient";
|
||||
import { getDelayInSeconds, isFinished } from "../src/lroPollStrategy";
|
||||
import { TestTokenCredential } from "./testTokenCredential";
|
||||
|
||||
describe("LROPollStrategy", function () {
|
||||
describe("getDelayInMilliseconds()", function () {
|
||||
it("with no AzureServiceClient.longRunningOperationRetryTimeout value and no retry-after header", function () {
|
||||
const azureServiceClient = new AzureServiceClient(new TestTokenCredential("my-fake-token"));
|
||||
const previousResponse: HttpOperationResponse = {
|
||||
request: new WebResource(),
|
||||
status: 200,
|
||||
headers: new HttpHeaders()
|
||||
};
|
||||
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 30);
|
||||
});
|
||||
|
||||
it("with 11 AzureServiceClient.longRunningOperationRetryTimeout and no retry-after header", function () {
|
||||
const azureServiceClient = new AzureServiceClient(new TestTokenCredential("my-fake-token"), { longRunningOperationRetryTimeout: 11 });
|
||||
const previousResponse: HttpOperationResponse = {
|
||||
request: new WebResource(),
|
||||
status: 200,
|
||||
headers: new HttpHeaders()
|
||||
};
|
||||
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 11);
|
||||
});
|
||||
|
||||
it("with no AzureServiceClient.longRunningOperationRetryTimeout value and 12 retry-after header", function () {
|
||||
const azureServiceClient = new AzureServiceClient(new TestTokenCredential("my-fake-token"));
|
||||
const previousResponse: HttpOperationResponse = {
|
||||
request: new WebResource(),
|
||||
status: 200,
|
||||
headers: new HttpHeaders({ "retry-after": "12" })
|
||||
};
|
||||
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 12);
|
||||
});
|
||||
|
||||
it("with no AzureServiceClient.longRunningOperationRetryTimeout value and spam retry-after header", function () {
|
||||
const azureServiceClient = new AzureServiceClient(new TestTokenCredential("my-fake-token"));
|
||||
const previousResponse: HttpOperationResponse = {
|
||||
request: new WebResource(),
|
||||
status: 200,
|
||||
headers: new HttpHeaders({ "retry-after": "spam" })
|
||||
};
|
||||
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 30);
|
||||
});
|
||||
|
||||
it("with 11 AzureServiceClient.longRunningOperationRetryTimeout and 12 retry-after header", function () {
|
||||
const azureServiceClient = new AzureServiceClient(new TestTokenCredential("my-fake-token"), { longRunningOperationRetryTimeout: 11 });
|
||||
const previousResponse: HttpOperationResponse = {
|
||||
request: new WebResource(),
|
||||
status: 200,
|
||||
headers: new HttpHeaders({ "retry-after": "12" })
|
||||
};
|
||||
assert.strictEqual(getDelayInSeconds(azureServiceClient, previousResponse), 11);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isFinished(LongRunningOperationStates)", function () {
|
||||
it(`with undefined`, function () {
|
||||
assert(!isFinished(undefined as any));
|
||||
});
|
||||
|
||||
it(`with null`, function () {
|
||||
// tslint:disable-next-line:no-null-keyword
|
||||
assert(!isFinished(null as any));
|
||||
});
|
||||
|
||||
it(`with ""`, function () {
|
||||
assert(!isFinished("" as any));
|
||||
});
|
||||
|
||||
it(`with "spam"`, function () {
|
||||
assert(!isFinished("spam" as any));
|
||||
});
|
||||
|
||||
it(`with "InProgress"`, function () {
|
||||
assert(!isFinished("InProgress"));
|
||||
});
|
||||
|
||||
it(`with "succeeded"`, function () {
|
||||
assert(isFinished("succeeded" as any));
|
||||
});
|
||||
|
||||
it(`with "Succeeded"`, function () {
|
||||
assert(isFinished("Succeeded"));
|
||||
});
|
||||
|
||||
it(`with "failed"`, function () {
|
||||
assert(isFinished("failed" as any));
|
||||
});
|
||||
|
||||
it(`with "Failed"`, function () {
|
||||
assert(isFinished("Failed"));
|
||||
});
|
||||
|
||||
it(`with "cancelled"`, function () {
|
||||
assert(isFinished("cancelled" as any));
|
||||
});
|
||||
|
||||
it(`with "Cancelled"`, function () {
|
||||
assert(isFinished("Cancelled"));
|
||||
});
|
||||
|
||||
it(`with "canceled"`, function () {
|
||||
assert(isFinished("canceled" as any));
|
||||
});
|
||||
|
||||
it(`with "Canceled"`, function () {
|
||||
assert(isFinished("Canceled"));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,58 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import assert from "assert";
|
||||
|
||||
/**
|
||||
* Assert that the provided syncFunction throws an Error. If the expectedError is undefined, then
|
||||
* this function will just assert that an Error was thrown. If the expectedError is defined, then
|
||||
* this function will assert that the Error that was thrown is equal to the provided expectedError.
|
||||
* @param syncFunction The synchronous function that is expected to thrown an Error.
|
||||
* @param expectedError The Error that is expected to be thrown.
|
||||
*/
|
||||
export function throws(syncFunction: () => void, expectedError?: ((error: Error) => void) | Error): Error {
|
||||
let thrownError: Error | undefined;
|
||||
|
||||
try {
|
||||
syncFunction();
|
||||
} catch (error) {
|
||||
thrownError = error;
|
||||
}
|
||||
|
||||
if (!thrownError) {
|
||||
assert.throws(() => { });
|
||||
} else if (expectedError instanceof Error) {
|
||||
assert.deepStrictEqual(thrownError, expectedError);
|
||||
} else if (expectedError) {
|
||||
expectedError(thrownError);
|
||||
}
|
||||
|
||||
return thrownError!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the provided asyncFunction throws an Error. If the expectedError is undefined, then
|
||||
* this function will just assert that an Error was thrown. If the expectedError is defined, then
|
||||
* this function will assert that the Error that was thrown is equal to the provided expectedError.
|
||||
* @param asyncFunction The asynchronous function that is expected to thrown an Error.
|
||||
* @param expectedError The Error that is expected to be thrown.
|
||||
*/
|
||||
export async function throwsAsync<T>(asyncFunction: (() => Promise<T>) | Promise<T>, expectedError?: ((error: Error) => void) | Error): Promise<Error> {
|
||||
let thrownError: Error | undefined;
|
||||
|
||||
try {
|
||||
await (typeof asyncFunction === "function" ? asyncFunction() : asyncFunction);
|
||||
} catch (error) {
|
||||
thrownError = error;
|
||||
}
|
||||
|
||||
if (!thrownError) {
|
||||
assert.throws(() => { });
|
||||
} else if (expectedError instanceof Error) {
|
||||
assert.deepStrictEqual(thrownError, expectedError);
|
||||
} else if (expectedError) {
|
||||
expectedError(thrownError);
|
||||
}
|
||||
|
||||
return thrownError!;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
|
||||
|
||||
export class TestTokenCredential implements TokenCredential {
|
||||
public token: string;
|
||||
public expiresOn: number;
|
||||
|
||||
constructor(token: string, expiresOn?: Date) {
|
||||
this.token = token;
|
||||
this.expiresOn = expiresOn ? expiresOn.getTime() : Date.now() + 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
async getToken(
|
||||
_scopes: string | string[],
|
||||
_options?: GetTokenOptions
|
||||
): Promise<AccessToken | null> {
|
||||
return {
|
||||
token: this.token,
|
||||
expiresOnTimestamp: this.expiresOn
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "es6",
|
||||
"outDir": "es"
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"extends": "../../../tsconfig.package",
|
||||
"compilerOptions": {
|
||||
"preserveConstEnums": true,
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"outDir": "es"
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"include": ["./src/**/*.ts", "./test/**/*.ts"]
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
{
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"comment-format": [true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [true,
|
||||
"spaces"
|
||||
],
|
||||
"linebreak-style": [true, "LF"],
|
||||
"one-line": [true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"no-var-keyword": true,
|
||||
"quotemark": [true,
|
||||
"double",
|
||||
"avoid-escape"
|
||||
],
|
||||
"semicolon": [true, "always", "ignore-bound-class-methods"],
|
||||
"whitespace": [true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-module",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
},
|
||||
{
|
||||
"call-signature": "onespace",
|
||||
"index-signature": "onespace",
|
||||
"parameter": "onespace",
|
||||
"property-declaration": "onespace",
|
||||
"variable-declaration": "onespace"
|
||||
}
|
||||
],
|
||||
"no-internal-module": true,
|
||||
"jsdoc-format": true,
|
||||
"no-inferrable-types": [true],
|
||||
"no-null-keyword": true,
|
||||
"no-return-await": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"prefer-const": true,
|
||||
"triple-equals": [true, "allow-undefined-check"]
|
||||
}
|
||||
}
|
|
@ -85,8 +85,7 @@ export function browserConfig(test = false) {
|
|||
format: "umd",
|
||||
name: "azurecorelro",
|
||||
globals: {
|
||||
"@azure/core-http": "Azure.Core.HTTP",
|
||||
"@azure/core-arm": "Azure.Core.ARM"
|
||||
"@azure/core-http": "Azure.Core.HTTP"
|
||||
},
|
||||
sourcemap: true
|
||||
},
|
||||
|
|
|
@ -90,8 +90,7 @@ export function browserConfig(test = false) {
|
|||
format: "umd",
|
||||
name: "azurekeyvaultadmin",
|
||||
globals: {
|
||||
"@azure/core-http": "Azure.Core.HTTP",
|
||||
"@azure/core-arm": "Azure.Core.ARM"
|
||||
"@azure/core-http": "Azure.Core.HTTP"
|
||||
},
|
||||
sourcemap: true
|
||||
},
|
||||
|
|
|
@ -89,7 +89,6 @@ export function browserConfig(test = false) {
|
|||
name: "azurekeyvaultcertificates",
|
||||
globals: {
|
||||
"@azure/core-http": "Azure.Core.HTTP",
|
||||
"@azure/core-arm": "Azure.Core.ARM",
|
||||
"@azure/keyvault-keys": "Azure.KeyVault.Keys",
|
||||
"@azure/keyvault-secrets": "Azure.KeyVault.Secrets"
|
||||
},
|
||||
|
|
|
@ -88,8 +88,7 @@ export function browserConfig(test = false) {
|
|||
format: "umd",
|
||||
name: "azurekeyvaultkeys",
|
||||
globals: {
|
||||
"@azure/core-http": "Azure.Core.HTTP",
|
||||
"@azure/core-arm": "Azure.Core.ARM"
|
||||
"@azure/core-http": "Azure.Core.HTTP"
|
||||
},
|
||||
sourcemap: true
|
||||
},
|
||||
|
|
|
@ -88,8 +88,7 @@ export function browserConfig(test = false) {
|
|||
format: "umd",
|
||||
name: "azurekeyvaultsecrets",
|
||||
globals: {
|
||||
"@azure/core-http": "Azure.Core.HTTP",
|
||||
"@azure/core-arm": "Azure.Core.ARM"
|
||||
"@azure/core-http": "Azure.Core.HTTP"
|
||||
},
|
||||
sourcemap: true
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче