Initial commit for copying files from azure-sdk-for-node
This commit is contained in:
Родитель
891f6f6161
Коммит
f30dc3098e
|
@ -1,59 +1,57 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
projects/*
|
||||
targets/*
|
||||
packages/*
|
||||
test/data/test_package.zip
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
# Visual Studio #
|
||||
*.suo
|
||||
*.user
|
||||
.ntvs_analysis.dat
|
||||
obj/*
|
||||
examples/obj
|
||||
examples/.ntvs_analysis.dat
|
||||
examples/.vs
|
||||
examples/bin
|
||||
.vs
|
||||
TestResults/*
|
||||
.vscode/*
|
||||
./**/.vscode/*
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
# Node #
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
npm-debug.log.*
|
||||
azure_error
|
||||
checkstyle-result.xml
|
||||
test-result.xml
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
# Mac OS #
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
# Windows #
|
||||
Thumbs.db
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
# Credentials #
|
||||
*.cer
|
||||
*.pfx
|
||||
*.pem
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
# WebStorm #
|
||||
.idea/
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
# docs #
|
||||
docs/
|
||||
main.conf.json
|
||||
child.conf.json
|
||||
.grunt/
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
# temporary test artifacts
|
||||
test/tmp/*
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
# Nuget packages and corresponding codegen sources
|
||||
.nuget
|
||||
packages
|
||||
|
||||
# Coverage report
|
||||
coverage
|
||||
.nyc_output
|
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "8"
|
||||
- "6"
|
||||
|
||||
before_script:
|
||||
- npm i -g typescript
|
||||
- tsc
|
|
@ -0,0 +1,5 @@
|
|||
# Contribute Code or Provide Feedback
|
||||
|
||||
If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines/).
|
||||
|
||||
If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-node/issues) section of the project.
|
34
LICENSE
34
LICENSE
|
@ -1,21 +1,21 @@
|
|||
MIT License
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Copyright (c) 2018 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:
|
||||
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 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
|
||||
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.
|
153
README.md
153
README.md
|
@ -1,14 +1,147 @@
|
|||
# Azure SDK for Javascript
|
||||
|
||||
# Contributing
|
||||
[![Build Status](https://travis-ci.org/Azure/azure-sdk-for-js.png?branch=master)](https://travis-ci.org/Azure/azure-sdk-for-js)
|
||||
|
||||
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.
|
||||
This project provides a Javascript package that makes it easy to consume and manage
|
||||
Microsoft Azure Services.
|
||||
It supports SDKs for:
|
||||
- ARM services (packages with the naming convention of `azure-arm-<servicename>`)
|
||||
- data plane of some Azure services (packages with the naming convention of `azure-<servicename>`).
|
||||
|
||||
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.
|
||||
## Documentation
|
||||
|
||||
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.
|
||||
Documentation of the supported SDKs can be found here:
|
||||
- https://docs.microsoft.com/en-us/javascript/azure - This website primarily provides SDK documentation for
|
||||
- ARM based services (`azure-arm-<serviceName>`)
|
||||
- data plane SDKs like `azure-batch`, `azure-graph`, etc.
|
||||
|
||||
## Authenticating
|
||||
|
||||
There are three ways to authenticate against Azure while using the management plane (`azure-arm-<serviceName>`) SDKs and the `azure-graph` SDK, use
|
||||
[this guide](./documentation/Authentication.md) to determine which method to use.
|
||||
|
||||
## Install individual modules
|
||||
|
||||
| **Azure Service (Data plane)** | **Install Command** |
|
||||
| --- | --- |
|
||||
| [Gallery](http://azure.microsoft.com/en-us/marketplace/) | `npm install azure-gallery` |
|
||||
| [Graph](https://azure.microsoft.com/en-us/services/active-directory/) | `npm install azure-graph` |
|
||||
| [Key Vault](http://azure.microsoft.com/en-us/services/key-vault/) | `npm install azure-keyvault` |
|
||||
| [Monitoring](https://msdn.microsoft.com/library/azure/dn306639.aspx) | `npm install azure-monitoring` |
|
||||
| [Scheduler](http://azure.microsoft.com/en-us/services/scheduler/) | `npm install azure-scheduler` |
|
||||
| [Service Fabric](https://azure.microsoft.com/en-us/services/service-fabric/) | `npm install azure-servicefabric` |
|
||||
| [Service Bus](http://azure.microsoft.com/en-us/services/service-bus/) | `npm install azure-sb` |
|
||||
| [Storage](http://azure.microsoft.com/en-us/services/storage/) | `npm install azure-storage` |
|
||||
| [Batch](https://azure.microsoft.com/en-us/services/batch/) | `npm install azure-batch` |
|
||||
| **Azure Resource Management (ARM) (Control plane)** |
|
||||
| [Advisor](https://docs.microsoft.com/en-us/rest/api/advisor/) | `npm install azure-arm-advisor` |
|
||||
| [Api Management](https://docs.microsoft.com/en-us/rest/api/apimanagement/) | `npm install azure-arm-apimanagement` |
|
||||
| [App Insights](https://docs.microsoft.com/en-us/rest/api/application-insights/) | `npm install azure-arm-appinsights` |
|
||||
| [Automation](https://docs.microsoft.com/en-us/azure/automation/) | `npm install azure-arm-automation` |
|
||||
| [Authorization](https://azure.microsoft.com/en-us/documentation/articles/role-based-access-control-configure/) | `npm install azure-arm-authorization` |
|
||||
| [Batch](https://azure.microsoft.com/en-us/services/batch/) | `npm install azure-arm-batch` |
|
||||
| [BatchAI](https://docs.microsoft.com/en-us/azure/batch-ai/) | `npm install azure-arm-batchai` |
|
||||
| [Billing](https://docs.microsoft.com/en-us/azure/billing/billing-usage-rate-card-overview) | `npm install azure-arm-billing` |
|
||||
| [CDN](https://azure.microsoft.com/en-us/services/cdn/) | `npm install azure-arm-cdn` |
|
||||
| [CognitiveServices](https://azure.microsoft.com/en-us/services/cognitive-services/) | `npm install azure-arm-cognitiveservices` |
|
||||
| [ContainerInstance](https://docs.microsoft.com/en-us/rest/api/container-instances/) | `npm install azure-arm-containerinstance` |
|
||||
| [CosmosDB](https://docs.microsoft.com/en-us/rest/api/documentdbresourceprovider/) | `npm install azure-arm-cosmosdb` |
|
||||
| [Commerce/Usage](https://azure.microsoft.com/en-us/documentation/articles/billing-usage-rate-card-overview/) | `npm install azure-arm-commerce` |
|
||||
| [Container Registry](https://azure.microsoft.com/en-us/services/container-registry/) | `npm install azure-arm-containerregistry` |
|
||||
| [CustomerInsights](https://docs.microsoft.com/en-us/dynamics365/customer-insights/ref/progref) | `npm install azure-arm-customerinsights` |
|
||||
| [Compute](http://azure.microsoft.com/en-us/services/virtual-machines/) | `npm install azure-arm-compute`|
|
||||
| [Datafactory](https://azure.microsoft.com/en-us/services/datafactory/) | `npm install azure-arm-datafactory` |
|
||||
| [Datalake Analytics](https://azure.microsoft.com/en-us/services/data-lake-analytics/) | `npm install azure-arm-datalake-analytics` |
|
||||
| [Datalake Store](https://azure.microsoft.com/en-us/services/data-lake-store/) | `npm install azure-arm-datalake-store` |
|
||||
| [DevTest Labs](https://azure.microsoft.com/en-us/services/devtest-lab/) | `npm install azure-arm-devtestlabs` |
|
||||
| [DNS](http://azure.microsoft.com/en-us/services/dns/) | `npm install azure-arm-dns` |
|
||||
| [DomainServices](https://docs.microsoft.com/en-us/azure/active-directory-domain-services/) | `npm install azure-arm-domainservices` |
|
||||
| [EventGrid](https://azure.microsoft.com/en-us/services/eventgrid/) | `npm install azure-arm-eventgrid` |
|
||||
| [EventHubs](https://azure.microsoft.com/en-us/services/event-hubs/) | `npm install azure-arm-eventhub` |
|
||||
| [HDInsight](http://azure.microsoft.com/en-us/services/hdinsight/) | `npm install azure-arm-hdinsight` |
|
||||
| [HDInsightJobs](https://msdn.microsoft.com/en-us/library/azure/mt613023.aspx) | `npm install azure-arm-hdinsight-jobs` |
|
||||
| [Insights](https://msdn.microsoft.com/en-us/library/azure/dn931943.aspx) | `npm install azure-arm-insights` |
|
||||
| [IotHub](https://azure.microsoft.com/en-us/documentation/services/iot-hub/) | `npm install azure-arm-iothub` |
|
||||
| [Key Vault](http://azure.microsoft.com/en-us/services/key-vault/) | `npm install azure-arm-keyvault` |
|
||||
| [Logic Apps](https://azure.microsoft.com/en-us/services/logic-apps/) | `npm install azure-arm-logic` |
|
||||
| [Machine Learning](https://azure.microsoft.com/en-us/services/machine-learning/) | `npm install azure-arm-machinelearning` |
|
||||
| [Machine Learning Compute](https://azure.microsoft.com/en-us/services/machine-learning/) | `npm install azure-arm-machinelearningcompute` |
|
||||
| [Media Services](https://azure.microsoft.com/en-us/services/media-services/) | `npm install azure-arm-mediaservices` |
|
||||
| [Mobile Engagement](https://docs.microsoft.com/en-us/azure/mobile-engagement/) | `npm install azure-arm-mobileengagement` |
|
||||
| [Monitor Management](https://docs.microsoft.com/en-us/rest/api/monitor/) | `npm install azure-arm-monitor` |
|
||||
| [Notification Hubs](https://azure.microsoft.com/en-us/documentation/services/notification-hubs/) | `npm install azure-arm-notificationhubs` |
|
||||
| [Operations Management](https://docs.microsoft.com/en-us/azure/operations-management-suite/) | `npm install azure-arm-operations` |
|
||||
| [Operational Insights](https://azure.microsoft.com/en-us/resources/videos/azure-operational-insights-overview/) | `npm install azure-arm-operationalinsights` |
|
||||
| [PowerBi Embedded](https://azure.microsoft.com/en-us/services/power-bi-embedded/) | `npm install azure-arm-powerbiembedded` |
|
||||
| [RecoveryServices](https://azure.microsoft.com/en-us/services/site-recovery/) | `npm install azure-arm-recoveryservices` |
|
||||
| [RecoveryServices Backup](https://azure.microsoft.com/en-us/services/site-recovery/) | `npm install azure-arm-recoveryservicesbackup` |
|
||||
| [RecoveryServices SiteRecovery](https://docs.microsoft.com/en-us/rest/api/site-recovery/) | `npm install azure-arm-recoveryservices-siterecovery` |
|
||||
| [Redis Cache](https://azure.microsoft.com/en-us/services/cache/) | `npm install azure-arm-rediscache` |
|
||||
| [Relay](https://docs.microsoft.com/en-us/azure/service-bus-relay/relay-what-is-it) | `npm install azure-arm-relay` |
|
||||
| [Resource Health](https://docs.microsoft.com/en-us/rest/api/resourcehealth/) | `npm install azure-arm-resourcehealth ` |
|
||||
| [Resource Manager](https://azure.microsoft.com/en-us/documentation/articles/resource-group-overview/) | `npm install azure-arm-resource` |
|
||||
| [Scheduler](https://azure.microsoft.com/en-us/documentation/articles/resource-group-overview/) | `npm install azure-arm-scheduler` |
|
||||
| [Search](https://azure.microsoft.com/en-us/services/search/) | `npm install azure-arm-search` |
|
||||
| [ServerManagement](https://azure.microsoft.com/en-us/documentation/articles/resource-group-overview/) | `npm install azure-arm-servermanagement` |
|
||||
| [Servicebus](https://msdn.microsoft.com/en-us/library/mt639375.aspx) | `npm install azure-arm-sb` |
|
||||
| [Service Fabric](https://azure.microsoft.com/en-us/services/service-fabric/) | `npm install azure-arm-servicefabric` |
|
||||
| [Storage](http://azure.microsoft.com/en-us/services/storage/) | `npm install azure-arm-storage` |
|
||||
| [Storage Import-Export](https://docs.microsoft.com/en-us/azure/storage/storage-import-export-service) | `npm install azure-arm-storageimportexport` |
|
||||
| [Storsimple8000series](https://docs.microsoft.com/en-us/azure/storsimple/storsimple-overview) | `npm install azure-arm-storsimple8000series` |
|
||||
| [Stream Analytics](https://docs.microsoft.com/en-us/rest/api/streamanalytics/) | `npm install azure-arm-streamanalytics` |
|
||||
| [Sql](https://azure.microsoft.com/en-us/services/sql-database/) | `npm install azure-arm-sql` |
|
||||
| [Traffic Manager](http://azure.microsoft.com/en-us/services/traffic-manager/) | `npm install azure-arm-trafficmanager` |
|
||||
| [Virtual Networks](http://azure.microsoft.com/en-us/services/virtual-network/) | `npm install azure-arm-network` |
|
||||
| [VisualStudio](https://docs.microsoft.com/en-us/rest/api/) | `npm install azure-arm-visualstudio` |
|
||||
| [WebApps (WebSites)](http://azure.microsoft.com/en-us/services/app-service/web/) | `npm install azure-arm-website` |
|
||||
| **Base Libraries** |
|
||||
| Common Functionality for ARM clients generated from Autorest (Generic) | `npm install ms-rest-js` |
|
||||
| Common Functionality for ARM clients generated from Autorest (Azure) | `npm install ms-rest-azure-js` |
|
||||
|
||||
## Need Help?
|
||||
|
||||
* [Read the docs](https://docs.microsoft.com/en-us/javascript/azure/?view=azure-node-latest)
|
||||
* [Open an issue in GitHub](http://github.com/azure/azure-sdk-for-node)
|
||||
* [Microsoft Azure Forums on MSDN and Stack Overflow](http://go.microsoft.com/fwlink/?LinkId=234489)
|
||||
|
||||
## AzureNodeEssentials VSCode extension
|
||||
|
||||
The [AzureNodeEssentials](https://marketplace.visualstudio.com/items?itemName=azuresdkteam.azurenodeessentials) extension helps you easily interact with Azure.
|
||||
It helps you:
|
||||
- create a project scaffolding
|
||||
- install correct dependencies
|
||||
- ready to use snippets for authentication and deploying templates to azure
|
||||
|
||||
Please feel free to provide feedback for the extension by opening github issues over [here](https://github.com/Azure/azure-node-essentials).
|
||||
|
||||
## Related Projects
|
||||
|
||||
* [Azure CLI](http://github.com/azure/azure-xplat-cli)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under MIT and Apache-2.0.
|
||||
- "MIT" license is usually used for the client libraries generated using [Autorest](https://github.com/Azure/Autorest) that are targeting ARM (V2 version of Azure REST API). The license can be found in "LICENSE.MIT.txt" file in this repository.
|
||||
- "Apache-2.0" license is usually used for the client libraries generated using an internal code generator that are targeting ASM (V1 version of Azure REST API). The license can be found in "LICENSE.Apache.txt" file in this repository.
|
||||
|
||||
## Contribute
|
||||
|
||||
* If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines/).
|
||||
|
||||
### Getting Started Developing
|
||||
Want to get started hacking on the code, super! Follow the following instructions to get up and running. These
|
||||
instructions expect you have Git and a supported version of Node installed.
|
||||
|
||||
1. Fork it
|
||||
2. Git Clone your fork (`git clone {your repo} --recursive`)
|
||||
3. Move into SDK directory (`cd azure-sdk-for-js`)
|
||||
4. Install all dependencies (`npm install`)
|
||||
5. Run the tests (`npm test`). You should see all tests passing.
|
||||
|
||||
### Contributing Code to the Project
|
||||
You found something you'd like to change, great! Please submit a pull request and we'll do our best to work with you to
|
||||
get your code included into the project.
|
||||
|
||||
1. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
2. Push to the branch (`git push origin my-new-feature`)
|
||||
3. Create new Pull Request
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
# Authentication
|
||||
|
||||
All service APIs require authentication via a `credentials` object when being
|
||||
instantiated. There are three ways of authenticating and creating the required
|
||||
`credentials` via the SDK: basic authentication, interactive login, and service
|
||||
principal authentication.
|
||||
|
||||
## Basic Authentication
|
||||
|
||||
Simply provide your username and password to authenticate with the API using your
|
||||
Azure account. It is encouraged that your username and password be stored in
|
||||
environment variables rather than in the source code for your project.
|
||||
|
||||
```js
|
||||
const Azure = require('azure');
|
||||
const MsRest = require('ms-rest-azure');
|
||||
|
||||
MsRest.loginWithUsernamePassword(process.env.AZURE_USER, process.env.AZURE_PASS, (err, credentials) => {
|
||||
if (err) throw err;
|
||||
|
||||
let storageClient = Azure.createStorageManagementClient(credentials, 'subscription-id');
|
||||
|
||||
// ..use the client instance to manage service resources.
|
||||
});
|
||||
```
|
||||
|
||||
## Interactive login
|
||||
|
||||
Interactive login will provide a link and a code that will allow the user to
|
||||
authenticate from a browser. Use this method when multiple accounts are used by
|
||||
the same script or when user intervention is preferred.
|
||||
|
||||
```js
|
||||
const Azure = require('azure');
|
||||
const MsRest = require('ms-rest-azure');
|
||||
|
||||
MsRest.interactiveLogin((err, credentials) => {
|
||||
if (err) throw err;
|
||||
|
||||
let storageClient = Azure.createStorageManagementClient(credentials, 'subscription-id');
|
||||
|
||||
// ..use the client instance to manage service resources.
|
||||
});
|
||||
```
|
||||
|
||||
### For azure-graph sdk
|
||||
|
||||
One needs to set the tokenAudience to 'graph' and provide the tenantId in the options object.
|
||||
```javascript
|
||||
const AzureGraphClient = require('azure-graph');
|
||||
const MsRestAzure = require('ms-rest-azure');
|
||||
|
||||
const options = {
|
||||
tokenAudience: 'graph',
|
||||
domain: '<tenantId>'
|
||||
};
|
||||
|
||||
MsRestAzure.interactiveLogin(options, (err, credentials) => {
|
||||
if (err) throw err;
|
||||
|
||||
let graphClient = AzureGraphClient(credentials, '<tenantId>');
|
||||
|
||||
// ..use the client instance to manage service resources.
|
||||
});
|
||||
```
|
||||
|
||||
## Service Principal Authentication
|
||||
|
||||
Interactive login, similar to how the CLI authenticates, is the easiest way to
|
||||
authenticate; however, when using the Node.js SDK programmatically, you may want
|
||||
to use service principal authentication rather than providing your account
|
||||
credentials. This essentially creates keys for your Azure Active Directory
|
||||
account that you can provide to the SDK to authenticate rather than requiring
|
||||
user intervention or username/password.
|
||||
|
||||
### Creating a Service Principal
|
||||
|
||||
There are three ways to create a Service Principal, the next sections will walk
|
||||
you through each method.
|
||||
|
||||
#### 1. Azure Portal
|
||||
|
||||
Follow the steps outlined in the
|
||||
[Azure Portal documentation](https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/)
|
||||
to generate the necessary keys.
|
||||
|
||||
#### 2. Azure CLI
|
||||
|
||||
This method can be used with either the
|
||||
[Azure CLI v2.0 (Python)](https://github.com/Azure/azure-cli) or the
|
||||
[Azure Cross-Platform CLI (npm module)](https://github.com/Azure/azure-xplat-cli).
|
||||
|
||||
_using the Python Azure CLI v2.0 requires just one step_
|
||||
```shell
|
||||
$ az ad sp create-for-rbac
|
||||
```
|
||||
|
||||
_Using the Node.js cross-platform CLI requires additional steps for setting up
|
||||
roles_
|
||||
```shell
|
||||
$ azure login # or $ azure login -u user@domain.tld
|
||||
$ azure ad sp create -n sp-name -p sp-password
|
||||
```
|
||||
|
||||
This will create a new Service Principal and output the keys, copy the output for
|
||||
use in your script. Note: you can retrieve the keys later by running
|
||||
`$ azure ad sp list` in your terminal.
|
||||
|
||||
The important fields are marked below (the other required field is the password
|
||||
that was provided when creating the service principal)
|
||||
|
||||
```shell
|
||||
+ Creating application sp-name
|
||||
+ Creating service principal for application **56894bd4-0fde-41d8-a0d7-5bsslccety2**
|
||||
data: Object Id: weewrerer-e329-4e9b-98c6-7878787
|
||||
data: Display Name: sp-name
|
||||
data: Service Principal Names:
|
||||
data: **56894bd4-0fde-41d8-a0d7-5bsslccety2**
|
||||
data: https://sp-name
|
||||
info: ad sp create command OK
|
||||
```
|
||||
|
||||
Next, you'll need to assign a role to the service principal that was just
|
||||
created. You can get a list of available roles by running `$ azure role list`
|
||||
|
||||
_In this example we are creating the service principal as a Contributor at the
|
||||
subscription level. A contributor role looks like this in the list_
|
||||
```
|
||||
data: Name : Contributor
|
||||
data: Actions : 0=*
|
||||
data: NotActions : 0=Microsoft.Authorization/*/Delete, 1=Microsoft.Authorization/*/Write
|
||||
data: IsCustom : false
|
||||
```
|
||||
|
||||
This will associate the service principal to your current subscription. Use the
|
||||
service principal that was returned in the `create` step for the `--spn` option.
|
||||
|
||||
```shell
|
||||
$ azure role assignment create --spn 56894bd4-0fde-41d8-a0d7-5bsslccety2 -o Contributor
|
||||
info: Executing command role assignment create
|
||||
+ Finding role with specified name
|
||||
data: RoleAssignmentId : /subscriptions/abcdefgh-1234-4cc9-89b5-12345678/providers/Microsoft.Authorization/roleAssignments/987654-ea85-40a5-80c2-abcdferghtt
|
||||
data: RoleDefinitionName : Contributor
|
||||
data: RoleDefinitionId : jhfskjf-6180-42a0-ab88-5656eiu677e23e
|
||||
data: Scope : /subscriptions/abcdefgh-1234-4cc9-89b5-12345678
|
||||
data: Display Name : sp-name
|
||||
data: SignInName :
|
||||
data: ObjectId : weewrerer-e329-4e9b-98c6-7878787
|
||||
data: ObjectType : ServicePrincipal
|
||||
data:
|
||||
+
|
||||
info: role assignment create command OK
|
||||
```
|
||||
|
||||
The service principal can now be used to log in.
|
||||
```shell
|
||||
$ azure login -u 56894bd4-0fde-41d8-a0d7-5bsslccety2 -p P@ssw0rd --tenant <a guid OR your domain(contosocorp.com)> --service-principal
|
||||
info: Executing command login
|
||||
info: Added subscription TestSubscription
|
||||
+
|
||||
info: login command OK
|
||||
```
|
||||
|
||||
#### 3. SDK
|
||||
|
||||
Run the [Service Principal creation script](./ServicePrincipal) to
|
||||
programmatically create a service principal.
|
||||
|
||||
|
||||
### Using the Service Principal
|
||||
|
||||
Now you can use the Service Principal keys to authenticate in the SDK.
|
||||
|
||||
```js
|
||||
const Azure = require('azure');
|
||||
const MsRest = require('ms-rest-azure');
|
||||
|
||||
MsRest.loginWithServicePrincipalSecret(
|
||||
'clientId or appId',
|
||||
'secret or password',
|
||||
'domain or tenantId',
|
||||
(err, credentials) => {
|
||||
if (err) throw err
|
||||
|
||||
let storageClient = Azure.createStorageManagementClient(credentials, 'subscription-id');
|
||||
|
||||
// ..use the client instance to manage service resources.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
### For azure-graph sdk
|
||||
|
||||
One needs to set the tokenAudience to 'graph' and provide the tenantId in the options object.
|
||||
```javascript
|
||||
const AzureGraphClient = require('azure-graph');
|
||||
const MsRestAzure = require('ms-rest-azure');
|
||||
|
||||
const options = {
|
||||
tokenAudience: 'graph',
|
||||
domain: '<tenantId>'
|
||||
};
|
||||
|
||||
MsRestAzure.loginWithServicePrincipalSecret(
|
||||
'clientId or appId',
|
||||
'secret or password',
|
||||
'domain or tenantId',
|
||||
options,
|
||||
(err, credentials) => {
|
||||
if (err) throw err;
|
||||
|
||||
let graphClient = AzureGraphClient(credentials, '<tenantId>');
|
||||
|
||||
// ..use the client instance to manage service resources.
|
||||
});
|
||||
```
|
|
@ -0,0 +1,74 @@
|
|||
Different ways to debug azure-sdk-for-js
|
||||
|
||||
## Using console.log()
|
||||
This is always handy and is guaranteed to work.
|
||||
It is a good practice to use util.inspect() to dump well formatted objects.
|
||||
In your script:
|
||||
```
|
||||
var util = require('util');
|
||||
. . .
|
||||
console.log(">>>>>>>>>>>>>> Some Identifier " + util.inspect(some_object, {depth: null}));
|
||||
. . .
|
||||
```
|
||||
Providing **{depth: null}** is optional. By default, it will dump object upto 3 levels deep. Setting depth to null will dump the complete object.
|
||||
|
||||
## Using Visual Studio
|
||||
The Visual Studio plugin for node.js can be downloaded from [here](https://github.com/Microsoft/nodejstools/releases).
|
||||
|
||||
### Setting up the project
|
||||
* Open the **nodeSDK.sln** file present at the root of the cloned repo.
|
||||
* Set the Tab size and Indentation to 2 spaces by going to
|
||||
* Tools --> Options --> TextEditor --> Node.js --> Tabs --> [Tab size: 2, Indent size: 2]
|
||||
* Tools --> Options --> TextEditor --> Javascript --> Tabs --> [Tab size: 2, Indent size: 2]
|
||||
|
||||
### For debugging the tests:
|
||||
* From the menu bar go to Project --> Properties and set the environment variables required for running tests.
|
||||
* The list of environment variables can be found over [here](./EnvironmentVariables.md)
|
||||
* If the need arises to add a new environment variable for tests please update the [Documentation](EnvironmentVariables.md) to keep the list current
|
||||
* Visual Studio can also be opened from **"Visual Studio Debugger Cmd Prompt"** usually located at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\Developer Command Prompt for VS2013.lnk" to set the environment variables. Then open the .sln file from the prompt.
|
||||
* In the Solution Explorer, click on a test that needs to be debugged. For example: "azure-sdk-for-node\test\services\storageManagement\storageManagementClient-tests.js"
|
||||
* In the **Properties** pane select **"Mocha"** as the Test Framework. Save All the changes.
|
||||
* The tests shall be seen in the "Test Explorer". Right Click on any Test and Select "Debug Selected Test".
|
||||
* **Note:** If the test file has any errors then you might not see the tests in the TestExplorer. In the Properties pane select **ExportRunner** as the test framework and save the solution. You will see the error in the output pane. Once the errors are resolved change the test framework back to **Mocha** in the Properties pane for that test file. When you save the solution, you should see your tests in the test explorer.
|
||||
* You can also run ```npm -s run-script jshint``` in the cmd prompt from the root of the repo to find errors if any.
|
||||
|
||||
## Using node inspector
|
||||
This will open a debugging session in a browser (chrome or opera). It is super easy to use.
|
||||
Steps to get it working:
|
||||
|
||||
* ```npm install -g node-inspector```
|
||||
* Assuming this is being executing in the cmd prompt from the root directory of the cloned repo "azure-sdk-for-node/"
|
||||
* ```node-debug some-test-script-that-calls-your-service.js```
|
||||
* A browser (Chrome/Opera) should pop up, or it can be manually browsed at this url - http://127.0.0.1:8080/debug?port=5858
|
||||
* Now breakpoints can be set at desired location.
|
||||
* It may happen that files with extension "._js" are not seen initially in the left pane. Please set a break point anywhere in lib\azure.js and keep on pressing "F10". After some time, files with extension "_.js" can be seen. Breakpoints can now be set at desired line in "*._js" file.
|
||||
|
||||
### For debugging tests:
|
||||
Please follow the below mentioned steps for the debugger to accept breakpoints set in your test file:
|
||||
* In the file azure-sdk-for-node/scripts/unit.js
|
||||
```
|
||||
modify the last line
|
||||
from - require('../node_modules/mocha/bin/mocha');
|
||||
to - require('../node_modules/mocha/bin/_mocha');
|
||||
```
|
||||
* set a breakpoint at runTest() method of mocha's runner.
|
||||
In the file "azure-sdk-for-node\node_modules\mocha\lib\runner.js" in the "runTest()" method around Line 378.
|
||||
* **Note**: "node_modules" directory is not a part of "azure-sdk-for-node" repository. If the **"node_modules"** directory or the **"mocha"** directory inside **"node_modules"** directory is not present, then ```npm install``` needs to be executed from the root directory of the cloned "azure-sdk-for-node" repo.
|
||||
```
|
||||
Runner.prototype.runTest = function(fn){
|
||||
var test = this.test
|
||||
, self = this;
|
||||
|
||||
if (this.asyncOnly) test.asyncOnly = true;
|
||||
|
||||
try {
|
||||
test.on('error', function(err){
|
||||
self.fail(test, err);
|
||||
});
|
||||
test.run(fn); <<<<<<<<<<<<<<<<<<<<<<<-------- set a breakpoint here
|
||||
} catch (err) {
|
||||
fn(err);
|
||||
}
|
||||
};
|
||||
```
|
||||
* Set a breakpoint in your test which should be located under "azure-sdk-for-node/test/commands" directory
|
|
@ -0,0 +1,131 @@
|
|||
## Environment Variables Setup
|
||||
|
||||
|
||||
### For clients targeting the ARM (V2) Azure API that are generated using [AutoRest](https://github.com/Azure/autorest) should setup following environment variables:
|
||||
|
||||
#### For data plane sdks
|
||||
If your service is not following the standanrd Azure AD authentication then please feel free to skip the authentication check by setting the following environment variable:
|
||||
|
||||
```
|
||||
set SKIP_CREDENTIAL_CHECK=true
|
||||
```
|
||||
|
||||
In your test file, you can have
|
||||
|
||||
```javascript
|
||||
var requiredEnvironment = [
|
||||
{ name: 'AZURE_YOUR_SERVICE_KEY', secure: true }
|
||||
];
|
||||
|
||||
// later when instantiating the test suite pass the requiredEnvironment
|
||||
suite = new SuiteBase(this, testPrefix, requiredEnvironment);
|
||||
```
|
||||
|
||||
#### For management plane sdks make sure to set up the following environment variables
|
||||
From an admin cmd console/terminal, at the root directory of your cloned repo, run the following for environment setup:
|
||||
* **Windows**
|
||||
```
|
||||
set AZURE_SUBSCRIPTION_ID=<A Guid>
|
||||
set CLIENT_ID=<A Guid> # Application Id provided by Azure Active Directory (SPN for service principal auth)
|
||||
set DOMAIN=<A Guid or the domain name of your org> contosoCorp.com
|
||||
set AZURE_USERNAME=<Your org-id user name> user@contosoCorp.com # Only set this if you are using user authentication
|
||||
set AZURE_PASSWORD=<Your Password> # Only set this if you are using user authentication
|
||||
set APPLICATION_SECRET=<Your service principal password or secret> # Only set this if you are using service principal auth
|
||||
set NOCK_OFF=true
|
||||
set AZURE_NOCK_RECORD=
|
||||
```
|
||||
|
||||
* **OS X**, **Linux**
|
||||
```
|
||||
export AZURE_SUBSCRIPTION_ID=<A Guid>
|
||||
export CLIENT_ID=<A Guid> # Application Id provided by Azure Active Directory (SPN for service principal auth)
|
||||
export DOMAIN=<A Guid or the domain name of your org> contosoCorp.com
|
||||
export AZURE_USERNAME=<Your org-id user name> user@contosoCorp.com # Only set this if you are using user authentication
|
||||
export AZURE_PASSWORD=<Your Password> # Only set this if you are using user authentication
|
||||
export APPLICATION_SECRET=<Your service principal password or secret> # Only set this if you are using service principal auth
|
||||
export NOCK_OFF=true
|
||||
export AZURE_NOCK_RECORD=
|
||||
```
|
||||
|
||||
### For clients targeting the ASM (V1) Azure API following environment variables need to be setup
|
||||
|
||||
From an admin cmd console/terminal, at the root directory of your cloned repo, run the following for environment setup:
|
||||
* **Windows**
|
||||
```
|
||||
set AZURE_APNS_CERTIFICATE_FILE=[path-to-your-certificatefile.pfx]
|
||||
set AZURE_APNS_CERTIFICATE_KEY=[your-certificate-key]
|
||||
set AZURE_CERTIFICATE_FILE=[path-to-your-certificatefile.cer]
|
||||
set AZURE_CERTIFICATE_KEY_FILE=[path-to-your-certificatefile.pfx]
|
||||
set AZURE_MPNS_CERTIFICATE_FILE=[path-to-the.pfx]
|
||||
set AZURE_MPNS_CERTIFICATE_KEY=[certificate-key]
|
||||
set AZURE_SERVICEBUS_ACCESS_KEY=[your-access-key]
|
||||
set AZURE_SERVICEBUS_ISSUER=owner
|
||||
set AZURE_SERVICEBUS_NAMESPACE=[your-servicebus-namespace]
|
||||
set AZURE_STORAGE_ACCESS_KEY=[your-storage-account-access-key]
|
||||
set AZURE_STORAGE_ACCOUNT=[your-storage-account-name]
|
||||
set AZURE_SUBSCRIPTION_ID=[your-subscripotion-id {a guid}]
|
||||
set AZURE_MANAGEMENT_HOST=management.core.windows.net
|
||||
set AZURE_SQL_TEST_LOCATION=West US
|
||||
set AZURE_STORAGE_DNS_SUFFIX=core.windows.net
|
||||
set AZURE_SQL_DNS_SUFFIX=core.windows.net
|
||||
set AZURE_WNS_PACKAGE_SID=package
|
||||
set AZURE_WNS_SECRET_KEY=key
|
||||
set AZURE_GCM_KEY=[your-GCMKey]
|
||||
set NOCK_OFF=true
|
||||
```
|
||||
|
||||
* **OS X**, **Linux**
|
||||
```
|
||||
export AZURE_APNS_CERTIFICATE_FILE=[path-to-your-certificatefile.pfx]
|
||||
export AZURE_APNS_CERTIFICATE_KEY=[your-certificate-key]
|
||||
export AZURE_CERTIFICATE_FILE=[path-to-your-certificatefile.cer]
|
||||
export AZURE_CERTIFICATE_KEY_FILE=[path-to-your-certificatefile.pfx]
|
||||
export AZURE_MPNS_CERTIFICATE_FILE=[path-to-the.pfx]
|
||||
export AZURE_MPNS_CERTIFICATE_KEY=[certificate-key]
|
||||
export AZURE_SERVICEBUS_ACCESS_KEY=[your-access-key]
|
||||
export AZURE_SERVICEBUS_ISSUER=owner
|
||||
export AZURE_SERVICEBUS_NAMESPACE=[your-servicebus-namespace]
|
||||
export AZURE_STORAGE_ACCESS_KEY=[your-storage-account-access-key]
|
||||
export AZURE_STORAGE_ACCOUNT=[your-storage-account-name]
|
||||
export AZURE_SUBSCRIPTION_ID=[your-subscripotion-id {a guid}]
|
||||
export AZURE_MANAGEMENT_HOST=management.core.windows.net
|
||||
export AZURE_SQL_TEST_LOCATION="West US"
|
||||
export AZURE_STORAGE_DNS_SUFFIX=core.windows.net
|
||||
export AZURE_SQL_DNS_SUFFIX=core.windows.net
|
||||
export AZURE_WNS_PACKAGE_SID=package
|
||||
export AZURE_WNS_SECRET_KEY=key
|
||||
export AZURE_GCM_KEY=[your-GCMKey]
|
||||
export NOCK_OFF=true
|
||||
```
|
||||
|
||||
### For clients targeting any of the Cognitive Services sdks, please make sure to set the corresponding environment variables. Each key is associated with the service that the account was created for.
|
||||
From an admin cmd console/terminal, at the root directory of your cloned repo, run the following for environment setup:
|
||||
* **Windows**
|
||||
```
|
||||
set AZURE_TEXT_ANALYTICS_KEY=<service-key>
|
||||
set AZURE_COMPUTER_VISION_KEY=<service-key>
|
||||
set AZURE_FACE_KEY=<service-key>
|
||||
set AZURE_ENTITY_SEARCH_KEY=<service-key>
|
||||
set AZURE_WEB_SEARCH_KEY=<service-key>
|
||||
set AZURE_VIDEO_SEARCH_KEY=<service-key>
|
||||
set AZURE_NEWS_SEARCH_KEY=<service-key>
|
||||
set AZURE_IMAGE_SEARCH_KEY=<service-key>
|
||||
set AZURE_CUSTOM_SEARCH_KEY=<service-key>
|
||||
set AZURE_CONTENT_MODERATOR_KEY=<service-key>
|
||||
```
|
||||
|
||||
* **OS X**, **Linux**
|
||||
```
|
||||
export AZURE_TEXT_ANALYTICS_KEY=<service-key>
|
||||
export AZURE_COMPUTER_VISION_KEY=<service-key>
|
||||
export AZURE_FACE_KEY=<service-key>
|
||||
export AZURE_ENTITY_SEARCH_KEY=<service-key>
|
||||
export AZURE_WEB_SEARCH_KEY=<service-key>
|
||||
export AZURE_VIDEO_SEARCH_KEY=<service-key>
|
||||
export AZURE_NEWS_SEARCH_KEY=<service-key>
|
||||
export AZURE_IMAGE_SEARCH_KEY=<service-key>
|
||||
export AZURE_CUSTOM_SEARCH_KEY=<service-key>
|
||||
export AZURE_CONTENT_MODERATOR_KEY=<service-key>
|
||||
```
|
||||
|
||||
#### Note: Not all tests require all these environment variables, and if a required one is not set the test will fail and tell you which ones need to be set.
|
|
@ -0,0 +1,12 @@
|
|||
# Azure-SDK-For-Node Documentation
|
||||
|
||||
1. [Setting up the repo](./SetupRepo.md)
|
||||
2. [Login using ServicePrincipal](./Authentication.md)
|
||||
3. [Regenerating code for your service](./RegeneratingCode.md)
|
||||
4. Testing the SDK
|
||||
- [Setting up the Environment Variables](./EnvironmentVariables.md)
|
||||
- [Test Modes & Recording Infrastructure](./TestModes.md)
|
||||
- [Running Tests](./RunTests.md)
|
||||
5. [Release Process](./ReleaseProcess.md)
|
||||
6. [Debugging the SDK](./Debugging.md)
|
||||
7. [Generating Self Signed Certificates for Testing Purpose](./DummyCerts.md)
|
|
@ -0,0 +1,19 @@
|
|||
# Regenerating Code
|
||||
|
||||
- Please execute `npm install` locally from the root of the cloned repo (This will install gulp locally for the repo).
|
||||
- Please install gulp globally `npm install gulp -g`
|
||||
- Please install autorest `npm install -g autorest`
|
||||
- Check the help `autorest --help`
|
||||
- Make sure you have updated the [mappings object](https://github.com/Azure/azure-sdk-for-node/blob/master/codegen_mappings.json) correctly for generating the source code for your service
|
||||
- To list all the tasks execute `gulp -T` from the root of the repo
|
||||
- Regenertion command options
|
||||
- If you want to regenerate all the services then execute `gulp codegen`
|
||||
- If you want to generate for your project then execute `gulp codegen --project <your project name a.k.a the key of the mappings object in codegen_mappings.json>`
|
||||
- If you want to use a local file then save the file locally say "D:\sdk" and make sure to have the same path as defined in the source of your project in the mappings object. Execute `gulp codegen --spec-root "D:\sdk" --project <your-project-name>`.
|
||||
- If generation is successful then you will see the generated code in the lib folder under `lib/services/<YourServiceName>`
|
||||
- Make sure you have License.txt (MIT), README.md and package.json file. Take a look at [StorageManagement2](https://github.com/Azure/azure-sdk-for-node/tree/master/lib/services/storageManagement2) as an example.
|
||||
- **Please make sure to have accurate examples in README.md as that is what customers will see when they search for your client libraries on [npm](https://npmjs.com).**
|
||||
- If you are adding a brand new client library or adding a new client to your library then please make sure that a function to create a client for your service is exported in the rollup azure file (azure-sdk-for-node/lib/azure.js). You can take a look at an exported function as an example over [here](https://github.com/Azure/azure-sdk-for-node/blob/master/lib/azure.js#L1640).
|
||||
|
||||
## Publishing to npm
|
||||
- Once your PR is merged into the master branch, you can publish your package to npm by following the instructions in "step 6" over [here](https://github.com/Azure/adx-documentation-pr/blob/master/clis/azure-cli/guide.md#swagger-specs---using-autorest----node-sdk--------azure-cli)
|
|
@ -0,0 +1,37 @@
|
|||
## What We're Doing
|
||||
Node SDK contains the autogenerated code for different services. In order to make sure that partners can easily keep their copies of Node SDK in sync, we need to finagle things a little as we get ready for release.
|
||||
|
||||
## At Code Complete
|
||||
|
||||
At code complete, we do the following:
|
||||
|
||||
### Node SDK repository
|
||||
1. Create a new branch off the dev branch named `release-<version>`, where version is the release number for the new release. So as we work towards releasing version 0.6.10, the branch will be "release-0.6.10". All work as part of this release process will be done on this new branch.
|
||||
|
||||
2. Update the package.json file with the upcoming version number.
|
||||
|
||||
3. Update the change log.
|
||||
|
||||
|
||||
## Stabilization
|
||||
|
||||
This is the phase after code complete where everyone's banging on the bits, looking for (and probably finding) bugs.
|
||||
|
||||
All issues will be fixed in the release branch of the appropriate repositories. We will decide if we need to rebuild packages and restart test passes on a case-by-case basis.
|
||||
|
||||
## Release
|
||||
|
||||
After we've completed stabilization, we will do the following steps to do the release.
|
||||
|
||||
1. Publish azure SDK from the release branch to npm
|
||||
|
||||
## Post Release
|
||||
|
||||
After the release is done, we need to:
|
||||
|
||||
1. Add a git tag for the release commits in the repo.
|
||||
2. Merge release branch into master
|
||||
3. Merge master to dev
|
||||
4. Delete release branch (we have the tag if we need to go back)
|
||||
|
||||
And we're ready for the next go round.
|
|
@ -0,0 +1,13 @@
|
|||
## Running Node SDK Tests
|
||||
|
||||
#### Pre-requisite
|
||||
|
||||
* [Setup Environment Variables](./EnvironmentVariables.md)
|
||||
|
||||
#### Run Tests
|
||||
* This will execute all the tests mentioned in azure-sdk-for-node/test/testlistarm.txt ```npm test```
|
||||
|
||||
* Running selective tests:
|
||||
Comment out the unrequired tests in azure-sdk-for-node/test/testlistarm.txt file by putting "# " at the beginning of line and run the tests by executing: ```npm test```
|
||||
|
||||
* For running arm tests, execute `npm run unit-arm`
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"name": "azure-sp",
|
||||
"author": "Microsoft Corporation",
|
||||
"contributors": [
|
||||
"Zavery, Amar <amzavery@microsoft.com>"
|
||||
],
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"description": "Sample script for creating a service principal in Azure.",
|
||||
"tags": [
|
||||
"azure",
|
||||
"sdk"
|
||||
],
|
||||
"keywords": [
|
||||
"node",
|
||||
"azure"
|
||||
],
|
||||
"main": "./spCreate.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms-rest": "^1.15.0",
|
||||
"ms-rest-azure": "^1.15.0",
|
||||
"azure-graph": "1.1.1",
|
||||
"azure-arm-authorization": "3.1.1"
|
||||
},
|
||||
"homepage": "http://github.com/Azure/azure-sdk-for-node",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:Azure/azure-sdk-for-node.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/Azure/azure-sdk-for-node/issues"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for
|
||||
* license information.
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Different basic role types that can be assigned to a ServicePrincipal.
|
||||
|
||||
///////////////
|
||||
//Contributor//
|
||||
///////////////
|
||||
// Name : Contributor
|
||||
// Id : b24988ac-6180-42a0-ab88-20f7382dd24c <<<<<<
|
||||
// Description : Lets you manage everything except access to resources.
|
||||
// AssignableScopes : 0=/
|
||||
// Actions : 0=*
|
||||
// NotActions : 0=Microsoft.Authorization/*/Delete, 1=Microsoft.Authorization/*/Write
|
||||
// IsCustom : false
|
||||
|
||||
/////////
|
||||
//Owner//
|
||||
/////////
|
||||
// Name : Owner
|
||||
// Id : 8e3af657-a8ff-443c-a75c-2fe8c4bcb635 <<<<<
|
||||
// Description : Lets you manage everything, including access to resources.
|
||||
// AssignableScopes : 0=/
|
||||
// Actions : 0=*
|
||||
// NotActions :
|
||||
// IsCustom : false
|
||||
|
||||
///////////
|
||||
// Reader//
|
||||
///////////
|
||||
// Name : Reader
|
||||
// Id : acdd72a7-3385-48ef-bd42-f606fba81ae7 <<<<<
|
||||
// Description : Lets you view everything, but not make any changes.
|
||||
// AssignableScopes : 0=/
|
||||
// Actions : 0=*/read
|
||||
// NotActions :
|
||||
// IsCustom : false
|
||||
|
||||
|
||||
//////////
|
||||
//Steps://
|
||||
//////////
|
||||
// 1. Validating environment variables.
|
||||
// 2. Creating an AD application
|
||||
// 3. Creating a ServicePrincipal on top of the AD application
|
||||
// 4. Assigning the "Contributor" role to the SP created in step 3 at the subscription scope.
|
||||
// 5. Trying to login as the created SP. We have induced a timeout of 20 seconds. Still this may fail.
|
||||
// However, that is fine. Executing the ServicePrincipal login in a separate script should work after a minute or so.
|
||||
|
||||
validate(function () {
|
||||
var msrestazure = require('ms-rest-azure');
|
||||
var graph = require('azure-graph');
|
||||
var authorization = require('azure-arm-authorization');
|
||||
var util = require('util');
|
||||
var moment = require('moment');
|
||||
|
||||
var tenantId = process.env['AZURE_TENANT_ID'];
|
||||
var subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
|
||||
var passwordForSp = process.env['AZURE_SP_SECRET'];
|
||||
var displayName = process.env['AZURE_SP_DISPLAY_NAME'];
|
||||
var homepage = 'http://' + displayName + ':8080';
|
||||
var identifierUris = [ homepage ];
|
||||
var roleId = 'b24988ac-6180-42a0-ab88-20f7382dd24c'; //that of a contributor
|
||||
var scope = '/subscriptions/' + subscriptionId; // we shall be assigning the sp, a 'contributor' role at the subscription level
|
||||
var roleDefinitionId = scope + '/providers/Microsoft.Authorization/roleDefinitions/' + roleId;
|
||||
var loginOptions = {
|
||||
domain: tenantId
|
||||
};
|
||||
msrestazure.interactiveLogin(loginOptions, function(err, creds) {
|
||||
if (err) {
|
||||
console.log('Error occured in interactive login: \n' + util.inspect(err, { depth: null }));
|
||||
return;
|
||||
}
|
||||
var options = {
|
||||
domain: tenantId,
|
||||
tokenAudience: 'graph',
|
||||
username: creds.username,
|
||||
tokenCache: creds.tokenCache,
|
||||
environment: creds.environment
|
||||
};
|
||||
var credsForGraph = new msrestazure.DeviceTokenCredentials(options);
|
||||
var graphClient = new graph(credsForGraph, tenantId);
|
||||
var startDate = new Date(Date.now());
|
||||
var endDate = new Date(startDate.toISOString());
|
||||
var m = moment(endDate);
|
||||
m.add(1, 'years');
|
||||
endDate = new Date(m.toISOString());
|
||||
var applicationCreateParameters = {
|
||||
availableToOtherTenants: false,
|
||||
displayName: displayName,
|
||||
homepage: homepage,
|
||||
identifierUris: identifierUris,
|
||||
passwordCredentials: [{
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
keyId: msrestazure.generateUuid(),
|
||||
value: passwordForSp
|
||||
}]
|
||||
};
|
||||
graphClient.applications.create(applicationCreateParameters, function (err, application, req, res) {
|
||||
if (err) {
|
||||
console.log('Error occured while creating the application: \n' + util.inspect(err, { depth: null }));
|
||||
return;
|
||||
}
|
||||
|
||||
var servicePrincipalCreateParameters = {
|
||||
appId: application.appId,
|
||||
accountEnabled: true
|
||||
};
|
||||
console.log('Underlying Application objectId: ' + application.objectId);
|
||||
graphClient.servicePrincipals.create(servicePrincipalCreateParameters, function (err, sp, req, res) {
|
||||
if (err) {
|
||||
console.log('Error occured while creating the servicePrincipal: \n' + util.inspect(err, { depth: null }));
|
||||
return;
|
||||
}
|
||||
var authzClient = new authorization(creds, subscriptionId, null);
|
||||
var assignmentGuid = msrestazure.generateUuid();
|
||||
var roleCreateParams = {
|
||||
properties: {
|
||||
principalId: sp.objectId,
|
||||
//have taken this from the comments made above
|
||||
roleDefinitionId: roleDefinitionId,
|
||||
scope: scope
|
||||
}
|
||||
};
|
||||
|
||||
console.log('>>>>>>>>>>>\nSuccessfully created the servicePrincipal: \n' + util.inspect(sp, { depth: null }) + '\n');
|
||||
authzClient.roleAssignments.create(scope, assignmentGuid, roleCreateParams, function (err, roleAssignment, req, res) {
|
||||
if (err) {
|
||||
console.log('\nError occured while creating the roleAssignment: \n' + util.inspect(err, { depth: null }));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('>>>>>>>>>>>\nSuccessfully created the role assignment for the servicePrincipal.\n');
|
||||
console.log('>>>>>>>>>>>\nIn future for login you will need the following info:');
|
||||
console.log('ServicePrincipal Id (SPN): ' + sp.appId);
|
||||
console.log('ServicePincipal Password: ' + passwordForSp);
|
||||
console.log('Tenant Id for ServicePrincipal: ' + tenantId);
|
||||
console.log('>>>>>>>>>>>\n');
|
||||
console.log(util.format('\nTrying to login as the created servicePrincipal.\n\nWaiting for \'20 seconds\' for the changes to reflect. ' +
|
||||
'If this call fails then please try to login as the servicePrincipal by executing the following script:\n\n' +
|
||||
'var msrestazure = require(\'ms-rest-azure\');\n\n' +
|
||||
'msrestazure.loginWithServicePrincipalSecret(\'%s\', \'%s\', \'%s\', function(err, creds) { if (err) { console.log(err); ' +
|
||||
'} else { console.log(creds); } });',
|
||||
sp.appId, passwordForSp, tenantId));
|
||||
setTimeout(function(appId, secret, tenantId, callback) {
|
||||
msrestazure.loginWithServicePrincipalSecret(sp.appId, passwordForSp, tenantId, callback);
|
||||
}, 20000,
|
||||
sp.appId, passwordForSp, tenantId, function (err, spCreds, subs) {
|
||||
if (err) {
|
||||
console.log('\nError occured during servicePrincipal login: \n' + util.inspect(err, { depth: null }));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('\nServicePrincipal login is successful.\n');
|
||||
return;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function validate(callback) {
|
||||
var ids = [];
|
||||
var envs = ['AZURE_TENANT_ID', 'AZURE_SUBSCRIPTION_ID', 'AZURE_SP_SECRET', 'AZURE_SP_DISPLAY_NAME'];
|
||||
envs.forEach(function (item) {
|
||||
if (!process.env[item]) {
|
||||
ids.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
if (ids.length > 0) {
|
||||
console.log('Please set the following environment variables:\n\t' + ids.join(', '));
|
||||
process.exit();
|
||||
}
|
||||
callback();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
Setting up the Node SDK repo
|
||||
|
||||
|
||||
* Create a fork from the [repo](https://github.com/Azure/azure-sdk-for-node)
|
||||
* Clone the forked repo at a location say “D:\sdk”
|
||||
```
|
||||
git clone git@github.com:your-github-username/azure-sdk-for-node.git
|
||||
cd azure-sdk-for-node
|
||||
git checkout master
|
||||
git remote add upstream git@github.com:Azure/azure-sdk-for-node.git
|
||||
git pull upstream master
|
||||
git push origin master (if there are any updates)
|
||||
|
||||
Note: It is a best practice to create a separate branch for your feature from the master branch.
|
||||
In this way the master branch in your fork can always be synced easily with upstream and is
|
||||
not polluted with your current changes.
|
||||
|
||||
git checkout -b myFeatureBranch
|
||||
git push origin myFeatureBranch
|
||||
```
|
||||
|
||||
* Installing the required npm modules from the root directory```npm install```
|
||||
|
||||
Now, the Node SDK is ready for you to make a marvelous contribution :+1
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "azure-sdk-for-js",
|
||||
"author": "Microsoft Corporation",
|
||||
"version": "0.1.0-preview",
|
||||
"description": "Microsoft Azure Client Libraries for Javascript",
|
||||
"tags": [
|
||||
"node",
|
||||
"azure",
|
||||
"sdk",
|
||||
"typescript",
|
||||
"browser"
|
||||
],
|
||||
"keywords": [
|
||||
"node",
|
||||
"azure",
|
||||
"sdk",
|
||||
"typescript",
|
||||
"browser"
|
||||
],
|
||||
"license": "MIT",
|
||||
"homepage": "http://github.com/azure/azure-sdk-for-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/azure/azure-sdk-for-js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/Azure/azure-sdk-for-js/issues"
|
||||
},
|
||||
"scripts": {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"meta": {
|
||||
"autorest_options": {
|
||||
"typescript": "",
|
||||
"license-header": "MICROSOFT_MIT_NO_VERSION",
|
||||
"sdkrel:node-sdks-folder": ".",
|
||||
"use": "@microsoft.azure/autorest.typescript@^2.0.0"
|
||||
},
|
||||
"repotag": "azure-sdk-for-js",
|
||||
"version": "0.3.0"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче