├── .gitignore ├── .jshintrc ├── .npmignore ├── API_CONVENTION.md ├── README.md ├── apis ├── afs-2018-01-12.json ├── batchcompute-2015-06-30.json ├── batchcompute-2015-11-11.json ├── cdn-2014-11-11.json ├── cms-2015-10-20.json ├── cs-2015-12-15.json ├── dayu-2015-12-16.json ├── dm-2015-11-23.json ├── dns-2015-01-09.json ├── drds-2015-04-13.json ├── dyvmsapi-2017-05-25.json ├── ecs-2014-05-26.json ├── ess-2014-08-28.json ├── green-2016-12-16.json ├── jaq-2016-11-23.json ├── mts-2014-06-18.json ├── opensearch-2015-01-01.json ├── oss-2013-10-15.json ├── ots-2014-08-08.json ├── push-2015-08-27.json ├── push-2016-08-01.json ├── ram-2015-05-01.json ├── rds-2014-08-15.json ├── slb-2014-05-15.json ├── sls-2014-11-18.json ├── sls-2015-06-01.json ├── sts-2015-04-01.json └── yundun-2015-04-16.json ├── bower.json ├── browser.js ├── browser.md ├── dist ├── aliyun-sdk.js └── aliyun-sdk.min.js ├── index.js ├── lib ├── aly.js ├── api_loader.js ├── config.js ├── core.js ├── event_listeners.js ├── http.js ├── http │ ├── node.js │ └── xhr.js ├── json │ └── builder.js ├── param_validator.js ├── request.js ├── sequential_executor.js ├── service.js ├── service_interface │ ├── json.js │ ├── pop.js │ ├── query.js │ ├── rest.js │ ├── rest_json.js │ ├── rest_xml.js │ └── top.js ├── services.js ├── services │ ├── batchcompute.js │ ├── cms.js │ ├── opensearch.js │ ├── oss.js │ ├── ots.js │ └── sls.js ├── signers │ ├── batchcompute.js │ ├── cms.js │ ├── opensearch.js │ ├── oss.js │ ├── ots.js │ ├── pop.js │ ├── pop_json.js │ ├── request_signer.js │ ├── sls.js │ └── top.js ├── util-browser.js ├── util.js └── xml │ ├── builder.js │ └── parser.js ├── package-lock.json ├── package.json ├── samples ├── batchcompute │ ├── 2015-06-30 │ │ ├── CreateJob.js │ │ ├── DeleteJob.js │ │ ├── GetJob.js │ │ ├── GetJobDescription.js │ │ ├── ListImages.js │ │ ├── ListJobs.js │ │ ├── ListTasks.js │ │ ├── StartJob.js │ │ ├── StopJob.js │ │ ├── UpdateJobPriority.js │ │ └── batchcompute.js │ └── 2015-11-11 │ │ ├── ChangeClusterDesiredVMCount.js │ │ ├── ChangeJobPriority.js │ │ ├── CreateCluster.js │ │ ├── CreateJob.js │ │ ├── DeleteCluster.js │ │ ├── DeleteJob.js │ │ ├── GetCluster.js │ │ ├── GetInstance.js │ │ ├── GetJob.js │ │ ├── GetJobDescription.js │ │ ├── GetTask.js │ │ ├── ListClusters.js │ │ ├── ListInstances.js │ │ ├── ListJobs.js │ │ ├── ListTasks.js │ │ ├── StartJob.js │ │ ├── StopJob.js │ │ └── batchcompute.js ├── browser │ └── browser.html ├── cdn │ └── test.js ├── cms │ ├── BatchQueryMetric.js │ ├── DescribeMetricDatum.js │ ├── GetMetricStatistics.js │ ├── QueryMetric.js │ └── cms.js ├── dayu │ └── test.js ├── dns │ └── test.js ├── ecs │ └── test.js ├── ess │ └── test.js ├── green │ ├── AsyncImageDetectionResultSample.js │ ├── AsyncImageDetectionSample.js │ ├── FeedbackSample.js │ ├── SyncImageDetectionSample.js │ ├── TexrtAntispamDetectionSample.js │ ├── TextKeywordFilter.js │ └── TextWordCorrect.js ├── jaq │ ├── ActivityPrevention.js │ ├── AfsAppCheck.js │ ├── AfsCheck.js │ ├── BbsPrevention.js │ ├── LoginPrevention.js │ ├── OtherPrevention.js │ └── SpamRegisterPrevention.js ├── memcached │ ├── Add.js │ ├── Decrement.js │ ├── Delete.js │ ├── Get.js │ ├── Increment.js │ ├── Replace.js │ ├── Set.js │ └── memcached.js ├── opensearch │ └── opensearch.js ├── oss │ ├── CopyObject.js │ ├── DeleteBucket.js │ ├── DeleteMultipleObjects.js │ ├── DeleteObject.js │ ├── GetBucket.js │ ├── GetBucketAcl.js │ ├── GetBucketLocation.js │ ├── GetObject.js │ ├── GetObjectWithCname.js │ ├── GetObjectWithRequestPayer.js │ ├── GetSignedUrl.js │ ├── HeadObject.js │ ├── ListBucket.js │ ├── PutBucket.js │ ├── PutBucketAcl.js │ ├── PutObject.js │ ├── multipartUpload.js │ ├── not-ready │ │ ├── DeleteBucketLogging.js │ │ ├── DeleteBucketWebsite.js │ │ ├── GetBucketLogging.js │ │ ├── GetBucketWebsite.js │ │ ├── PutBucketLogging.js │ │ └── PutBucketWebsite.js │ └── oss.js ├── ots │ ├── CreateTable.js │ ├── DeleteRow.js │ ├── DeleteTable.js │ ├── DescribeTable.js │ ├── GetRange.js │ ├── GetRow.js │ ├── ListTable.js │ ├── PutRow.js │ ├── UpdateRow.js │ ├── UpdateTable.js │ └── ots.js ├── push │ └── push.js ├── rds │ └── test.js ├── slb │ └── test.js ├── sls │ ├── All.js │ ├── BatchGetLogs.js │ ├── CreateLogStore.js │ ├── DeleteLogStore.js │ ├── GetHistograms.js │ ├── GetLogStore.js │ ├── GetLogs.js │ ├── Index.js │ ├── ListLogStores.js │ ├── ListProject.js │ ├── ListTopics.js │ ├── PutLogs.js │ ├── Readme.md │ ├── Shard.js │ ├── sls.js │ └── sql.js └── sts │ └── test.js ├── test ├── batchcompute │ ├── 2015-06-30.js │ ├── 2015-11-11.js │ ├── README.md │ └── testConfig.json ├── cms │ ├── cms.js │ └── testConfig.json ├── index.js └── sls │ ├── 2014-11-18.js │ ├── 2015-06-01.js │ └── config.js └── tools └── open_api_translator.js /.gitignore: -------------------------------------------------------------------------------- 1 | configuration 2 | node_modules 3 | bower_components 4 | npm-debug.log 5 | coverage.html 6 | vendor 7 | .yardoc 8 | doc 9 | dist/appinfo.js 10 | dist/tests.js 11 | 12 | .idea 13 | .DS_Store 14 | config.json 15 | 16 | t.js 17 | t.html 18 | test_* 19 | 20 | tools 21 | !tools/open_api_translator.js 22 | 23 | test/*/testConfig.js -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "browser": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": false, 7 | "eqeqeq": false, 8 | "forin": true, 9 | "immed": true, 10 | "indent": 2, 11 | "latedef": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "noempty": true, 15 | "nonew": true, 16 | "plusplus": false, 17 | "quotmark": "single", 18 | "regexp": true, 19 | "undef": true, 20 | "unused": true, 21 | "strict": false, 22 | "trailing": true, 23 | "maxparams": false, 24 | "maxdepth": false, 25 | "maxstatements": 40, 26 | "maxcomplexity": 10, 27 | "sub": true, 28 | "indent": false 29 | 30 | } 31 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | samples/ 2 | test/ 3 | tools/ 4 | bower_components/ 5 | 6 | test* 7 | 8 | .idea 9 | .DS_Store 10 | .jshintrc 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 安装 2 | 3 | ### Node.js 安装 4 | 5 | ```sh 6 | npm install aliyun-sdk 7 | ``` 8 | 9 | ### 浏览器端安装 10 | 11 | https://github.com/aliyun-UED/aliyun-sdk-js/blob/master/browser.md 12 | 13 | ## 使用方法及代码示例 14 | 15 | ### OSS 16 | 在 samples/oss 目录下的代码示例,使用方法: 17 | - 将 sample/oss/oss.js 中需要的参数修改 18 | - 打开需要执行的某个实例文件,如 GetBucket.js,将其中的参数改成你自己的 oss 实例参数 19 | - 执行示例文件即可, 如: 20 | 21 | ```javascript 22 | cd samples/oss 23 | node GetBucket.js 24 | ``` 25 | 26 | ***oss 支持 stream 请使用 https://github.com/berwin/aliyun-oss-upload-stream*** 27 | 28 | ## 目前支持的服务 29 | 30 | SDK 目前支持下列服务: 31 | 32 | | 服务名 | 类名 | API 版本 | API 文档 33 | | :------------ |:---------------:| -----:| -----:| 34 | | Aliyun ECS | ALY.ECS | 2014-05-26 | [ECS API手册](http://aliyunecs.oss.aliyuncs.com/ECS-API-Reference%202014-05-26.pdf) | 35 | | Aliyun RDS | ALY.RDS | 2014-08-15 | [RDS API手册](http://imgs-storage.cdn.aliyuncs.com/help/rds/RDS-API-Reference.pdf) | 36 | | Aliyun SLB | ALY.SLB | 2014-05-15 | [SLB API手册](http://imgs-storage.cdn.aliyuncs.com/help/slb/SLB-API-Reference_2014-05-15.pdf) | 37 | | Aliyun ESS | ALY.SLB | 2014-08-28 | [ESS API手册](https://help.aliyun.com/product/25855.html) | 38 | | Aliyun OSS | ALY.OSS | 2013-10-15 | [OSS API手册](http://imgs-storage.cdn.aliyuncs.com/help/oss/oss%20api%2020140828.pdf) | 39 | | Aliyun OTS | ALY.OTS | 2014-08-08 | [OTS API手册](https://help.aliyun.com/document_detail/ots/APIReference) | 40 | | Aliyun CDN | ALY.CDN | 2014-11-11 | [CDN API手册](http://imgs-storage.cdn.aliyuncs.com/help/cdn/cdn%20open%20api%20v1.6.pdf) | 41 | | Aliyun CMS | ALY.CMS | 2015-10-20 | [CMS API手册](https://help.aliyun.com/document_detail/cms/API_References/New_Metric_OpenAPI_Reference.html?spm=5176.product8314972_cms.6.89.O1ENDP) | 42 | | Aliyun SLS | ALY.SLS | 2014-11-18 | [SLS API手册](https://help.aliyun.com/document_detail/29007.html) | 43 | | Aliyun RAM | ALY.RAM | 2015-05-15 | [RAM API手册](https://help.aliyun.com/document_detail/28672.html) | 44 | | Aliyun STS | ALY.STS | 2015-04-01 | [STS API手册](https://help.aliyun.com/document_detail/28756.html) | 45 | | Aliyun MTS | ALY.MTS | 2014-06-18 | [MTS API手册](https://help.aliyun.com/document_detail/29212.html) | 46 | | Aliyun PUSH | ALY.PUSH | 2015-08-27 | [PUSH API手册](https://help.aliyun.com/document_detail/mobilepush/api-reference/openapi.html) | 47 | | Alidayu | ALY.DAYU | 2015-12-16 | [阿里大于 API手册](https://api.alidayu.com/doc2/apiList.htm) | 48 | | Alyun GREEN | ALY.GREEN | 2016-11-24 | [阿里绿网 API手册](https://help.aliyun.com/document_detail/28427.html) | 49 | | Aliyun OpenSearch | ALY.OpenSearch | 2015-01-01 | [OpenSearch API手册](http://docs.aliyun.com/#/opensearch/api-reference/terminology) | 50 | | Aliyun BatchCompute | ALY.BatchCompute | 2015-06-30 | [BatchCompute API手册](http://docs.aliyun.com/#/pub/batchcompute) | 51 | | Aliyun OCS memcached | ALY.MEMCACHED | | [BinaryProtocolRevamped](https://code.google.com/p/memcached/wiki/BinaryProtocolRevamped) | 52 | | Aliyun JAQ | ALY.JAQ | | [数控风险](https://help.aliyun.com/product/28308.html) | 53 | 54 | #### 我们在代码中参考了 AWS SDK,在此声明。 55 | 56 | ## License 57 | 58 | This SDK is distributed under the 59 | [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 60 | -------------------------------------------------------------------------------- /apis/afs-2018-01-12.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pop", 3 | "apiVersion": "2018-01-12", 4 | "checksumFormat": "md5", 5 | "endpointPrefix": "afs", 6 | "serviceAbbreviation": "AFS", 7 | "serviceFullName": "Aliyun AFS", 8 | "signatureVersion": "pop", 9 | "timestampFormat": "top", 10 | "xmlnamespace": "", 11 | "operations": { 12 | "authenticateSig": { 13 | "name": "AuthenticateSig", 14 | "http": { 15 | "method": "POST", 16 | "uri": "/" 17 | }, 18 | "input": { 19 | "type": "structure", 20 | "members": { 21 | "Action": { 22 | "required": true, 23 | "default": "AuthenticateSig" 24 | }, 25 | "ResourceOwnerId": { 26 | "type": "string" 27 | }, 28 | "RemoteIp": { 29 | "required": true, 30 | "type": "string" 31 | }, 32 | "SourceIp": { 33 | "type": "string" 34 | }, 35 | "AppKey": { 36 | "required": true, 37 | "type": "string" 38 | }, 39 | "SessionId": { 40 | "required": true, 41 | "type": "string" 42 | }, 43 | "Token": { 44 | "required": true, 45 | "type": "string" 46 | }, 47 | "Sig": { 48 | "required": true, 49 | "type": "string" 50 | }, 51 | "Scene": { 52 | "required": true, 53 | "type": "string" 54 | } 55 | } 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /apis/dayu-2015-12-16.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": "top", 3 | "apiVersion": "2015-12-16", 4 | "checksumFormat": "md5", 5 | "endpointPrefix": "dayu", 6 | "serviceAbbreviation": "DAYU", 7 | "serviceFullName": "Alidayu", 8 | "signatureVersion": "top", 9 | "timestampFormat": "rfc822", 10 | "xmlnamespace": "", 11 | "operations": { 12 | "sendSMS": { 13 | "name": "alibaba.aliqin.fc.sms.num.send", 14 | "http": { 15 | "method": "POST", 16 | "uri": "/" 17 | }, 18 | "input": { 19 | "type": "structure", 20 | "members": { 21 | "method": { 22 | "required": true, 23 | "default": "alibaba.aliqin.fc.sms.num.send" 24 | }, 25 | "extend": { 26 | }, 27 | "sms_type": { 28 | "required": true, 29 | "default": "normal" 30 | }, 31 | "sms_free_sign_name": { 32 | "required": true 33 | }, 34 | "sms_param": { 35 | "type": "map" 36 | }, 37 | "rec_num": { 38 | "required": true 39 | }, 40 | "sms_template_code": { 41 | "required": true 42 | } 43 | } 44 | }, 45 | "output": { 46 | } 47 | }, 48 | "doublecall": { 49 | "name": "alibaba.aliqin.fc.voice.num.doublecall", 50 | "http": { 51 | "method": "POST", 52 | "uri": "/" 53 | }, 54 | "input": { 55 | "type": "structure", 56 | "members": { 57 | "method": { 58 | "required": true, 59 | "default": "alibaba.aliqin.fc.voice.num.doublecall" 60 | }, 61 | "session_time_out": { 62 | }, 63 | "extend": { 64 | }, 65 | "caller_num": { 66 | "required": true 67 | }, 68 | "caller_show_num": { 69 | "required": true 70 | }, 71 | "called_num": { 72 | "required": true 73 | }, 74 | "called_show_num": { 75 | "required": true 76 | } 77 | } 78 | }, 79 | "output": { 80 | } 81 | }, 82 | "singlecall": { 83 | "name": "alibaba.aliqin.fc.tts.num.singlecall", 84 | "http": { 85 | "method": "POST", 86 | "uri": "/" 87 | }, 88 | "input": { 89 | "type": "structure", 90 | "members": { 91 | "method": { 92 | "required": true, 93 | "default": "alibaba.aliqin.fc.tts.num.singlecall" 94 | }, 95 | "extend": { 96 | }, 97 | "tts_param": { 98 | "type": "map" 99 | }, 100 | "called_num": { 101 | "required": true 102 | }, 103 | "called_show_num": { 104 | "required": true 105 | }, 106 | "tts_code": { 107 | "required": true 108 | } 109 | } 110 | }, 111 | "output": { 112 | } 113 | }, 114 | "voiceNotification": { 115 | "name": "alibaba.aliqin.fc.voice.num.singlecall", 116 | "http": { 117 | "method": "POST", 118 | "uri": "/" 119 | }, 120 | "input": { 121 | "type": "structure", 122 | "members": { 123 | "method": { 124 | "required": true, 125 | "default": "alibaba.aliqin.fc.voice.num.singlecall" 126 | }, 127 | "extend": { 128 | }, 129 | "called_num": { 130 | "required": true 131 | }, 132 | "called_show_num": { 133 | "required": true 134 | }, 135 | "voice_code": { 136 | "required": true 137 | } 138 | } 139 | }, 140 | "output": { 141 | } 142 | }, 143 | "querySMS": { 144 | "name": "alibaba.aliqin.fc.sms.num.query", 145 | "http": { 146 | "method": "POST", 147 | "uri": "/" 148 | }, 149 | "input": { 150 | "type": "structure", 151 | "members": { 152 | "method": { 153 | "required": true, 154 | "default": "alibaba.aliqin.fc.sms.num.query" 155 | }, 156 | "biz_id": { 157 | }, 158 | "rec_num": { 159 | "required": true 160 | }, 161 | "query_date": { 162 | "required": true 163 | }, 164 | "current_page": { 165 | "required": true 166 | }, 167 | "page_size": { 168 | "required": true 169 | } 170 | } 171 | }, 172 | "output": { 173 | } 174 | } 175 | 176 | } 177 | } -------------------------------------------------------------------------------- /apis/dns-2015-01-09.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pop", 3 | "apiVersion": "2015-01-09", 4 | "checksumFormat": "md5", 5 | "endpointPrefix": "alidns", 6 | "serviceAbbreviation": "DNS", 7 | "serviceFullName": "Aliyun DNS", 8 | "signatureVersion": "pop", 9 | "timestampFormat": "top", 10 | "xmlnamespace": "", 11 | "operations": { 12 | "describeDomains": { 13 | "name": "DescribeDomains", 14 | "http": { 15 | "method": "POST", 16 | "uri":"/" 17 | }, 18 | "input": { 19 | "type": "structure", 20 | "members": { 21 | "Action": { 22 | "required": true, 23 | "default": "DescribeDomains" 24 | }, 25 | "PageNumber": { 26 | "type": "integer" 27 | }, 28 | "PageSize": { 29 | "type": "integer" 30 | }, 31 | "KeyWord": { 32 | "type": "string" 33 | }, 34 | "GroupId": { 35 | "type": "string" 36 | } 37 | } 38 | } 39 | }, 40 | "describeDomainInfo": { 41 | "name": "DescribeDomainInfo", 42 | "http": { 43 | "method": "POST", 44 | "uri":"/" 45 | }, 46 | "input": { 47 | "type": "structure", 48 | "members": { 49 | "Action": { 50 | "required": true, 51 | "default": "DescribeDomainInfo" 52 | }, 53 | "DomainName": { 54 | "type": "string" 55 | } 56 | } 57 | } 58 | }, 59 | "describeDomainRecords": { 60 | "name": "DescribeDomainRecords", 61 | "http": { 62 | "method": "POST", 63 | "uri":"/" 64 | }, 65 | "input": { 66 | "type": "structure", 67 | "members": { 68 | "Action": { 69 | "required": true, 70 | "default": "DescribeDomainRecords" 71 | }, 72 | "DomainName": { 73 | "required": true, 74 | "type": "string" 75 | }, 76 | "PageNumber": { 77 | "type": "integer" 78 | }, 79 | "PageSize": { 80 | "type": "integer" 81 | }, 82 | "RRKeyWord": { 83 | "type": "string" 84 | }, 85 | "TypeKeyWord": { 86 | "type": "string" 87 | }, 88 | "ValueKeyWord": { 89 | "type": "string" 90 | } 91 | } 92 | } 93 | }, 94 | "addDomainRecord": { 95 | "name": "AddDomainRecord", 96 | "http": { 97 | "method": "POST", 98 | "uri":"/" 99 | }, 100 | "input": { 101 | "type": "structure", 102 | "members": { 103 | "Action": { 104 | "required": true, 105 | "default": "AddDomainRecord" 106 | }, 107 | "DomainName": { 108 | "required": true, 109 | "type": "string" 110 | }, 111 | "RR": { 112 | "required": true, 113 | "type": "string" 114 | }, 115 | "Type": { 116 | "required": true, 117 | "type": "string" 118 | }, 119 | "Value": { 120 | "required": true, 121 | "type": "string" 122 | }, 123 | "TTL": { 124 | "type": "integer" 125 | }, 126 | "Priority": { 127 | "type": "integer" 128 | }, 129 | "Line": { 130 | "type": "string" 131 | } 132 | } 133 | } 134 | }, 135 | "describeDomainRecordInfo": { 136 | "name": "DescribeDomainRecordInfo", 137 | "http": { 138 | "method": "POST", 139 | "uri":"/" 140 | }, 141 | "input": { 142 | "type": "structure", 143 | "members": { 144 | "Action": { 145 | "required": true, 146 | "default": "DescribeDomainRecordInfo" 147 | }, 148 | "RecordId": { 149 | "required": true, 150 | "type": "string" 151 | } 152 | } 153 | } 154 | }, 155 | "deleteDomainRecord": { 156 | "name": "DeleteDomainRecord", 157 | "http": { 158 | "method": "POST", 159 | "uri":"/" 160 | }, 161 | "input": { 162 | "type": "structure", 163 | "members": { 164 | "Action": { 165 | "required": true, 166 | "default": "DeleteDomainRecord" 167 | }, 168 | "RecordId": { 169 | "required": true, 170 | "type": "string" 171 | } 172 | } 173 | } 174 | } 175 | } 176 | } -------------------------------------------------------------------------------- /apis/dyvmsapi-2017-05-25.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": "pop", 3 | "apiVersion": "2017-05-25", 4 | "checksumFormat": "md5", 5 | "endpointPrefix": "dyvmsapi", 6 | "serviceAbbreviation": "DYVMSAPI", 7 | "serviceFullName": "Aliyun DYVMSAPI", 8 | "signatureVersion": "pop", 9 | "timestampFormat": "top", 10 | "xmlnamespace": "", 11 | "operations": { 12 | "singleCallByTts": { 13 | "name": "SingleCallByTts", 14 | "http": { 15 | "method": "POST", 16 | "uri": "/" 17 | }, 18 | "input": { 19 | "type": "structure", 20 | "members": { 21 | "Action": { 22 | "required": true, 23 | "default": "SingleCallByTts" 24 | }, 25 | "CalledNumber": { 26 | "required": true, 27 | "type": "string" 28 | }, 29 | "ResourceOwnerAccount": { 30 | "type": "string" 31 | }, 32 | "TtsParam": { 33 | "type": "string" 34 | }, 35 | "TtsCode": { 36 | "required": true, 37 | "type": "string" 38 | }, 39 | "CalledShowNumber": { 40 | "required": true, 41 | "type": "string" 42 | }, 43 | "ResourceOwnerId": { 44 | "type": "integer" 45 | }, 46 | "OwnerId": { 47 | "type": "integer" 48 | }, 49 | "OutId": { 50 | "type": "string" 51 | } 52 | } 53 | } 54 | }, 55 | "singleCallByVoice": { 56 | "name": "SingleCallByVoice", 57 | "http": { 58 | "method": "POST", 59 | "uri": "/" 60 | }, 61 | "input": { 62 | "type": "structure", 63 | "members": { 64 | "Action": { 65 | "required": true, 66 | "default": "SingleCallByVoice" 67 | }, 68 | "CalledNumber": { 69 | "required": true, 70 | "type": "string" 71 | }, 72 | "ResourceOwnerAccount": { 73 | "type": "string" 74 | }, 75 | "VoiceCode": { 76 | "required": true, 77 | "type": "string" 78 | }, 79 | "CalledShowNumber": { 80 | "required": true, 81 | "type": "string" 82 | }, 83 | "ResourceOwnerId": { 84 | "type": "integer" 85 | }, 86 | "OwnerId": { 87 | "type": "integer" 88 | }, 89 | "OutId": { 90 | "type": "string" 91 | } 92 | } 93 | } 94 | }, 95 | "ivrCall": { 96 | "name": "IvrCall", 97 | "http": { 98 | "method": "POST", 99 | "uri": "/" 100 | }, 101 | "input": { 102 | "type": "structure", 103 | "members": { 104 | "Action": { 105 | "required": true, 106 | "default": "IvrCall" 107 | }, 108 | "StartCode": { 109 | "required": true, 110 | "type": "string" 111 | }, 112 | "StartTtsParams": { 113 | "type": "string" 114 | }, 115 | "PlayTimes": { 116 | "type": "integer" 117 | }, 118 | "OwnerId": { 119 | "type": "integer" 120 | }, 121 | "OutId": { 122 | "type": "string" 123 | }, 124 | "CalledNumber": { 125 | "required": true, 126 | "type": "string" 127 | }, 128 | "MenuKeyMap": { 129 | "type": "repeatlist" 130 | }, 131 | "ResourceOwnerAccount": { 132 | "type": "string" 133 | }, 134 | "CalledShowNumber": { 135 | "required": true, 136 | "type": "string" 137 | }, 138 | "ResourceOwnerId": { 139 | "type": "integer" 140 | }, 141 | "ByeCode": { 142 | "type": "string" 143 | } 144 | } 145 | } 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /apis/opensearch-2015-01-01.json: -------------------------------------------------------------------------------- 1 | { 2 | "format": "rest", 3 | "apiVersion": "v2", 4 | "checksumFormat": "md5", 5 | "endpointPrefix": "opensearch", 6 | "serviceAbbreviation": "OpenSearch", 7 | "serviceFullName": "Aliyun OpenSearch", 8 | "signatureVersion": "opensearch", 9 | "timestampFormat": "rfc822", 10 | "xmlnamespace": "", 11 | "operations": { 12 | "listApp": { 13 | "name": "ListApp", 14 | "http": { 15 | "method": "GET", 16 | "uri": "/index" 17 | }, 18 | "input": { 19 | "type": "structure", 20 | "members": { 21 | "projectName":{ 22 | "type": "string", 23 | "location": "header" 24 | } 25 | } 26 | } 27 | }, 28 | "uploadDoc": { 29 | "name": "UploadDoc", 30 | "http": { 31 | "method": "POST", 32 | "uri": "/index/doc/{app_name}" 33 | }, 34 | "input": { 35 | "payload": ["action", "items", "table_name"], 36 | "type": "structure", 37 | "members": { 38 | "app_name": { 39 | "required": true, 40 | "location": "uri" 41 | }, 42 | "action": { 43 | "type": "string", 44 | "required": true 45 | }, 46 | "items": { 47 | "type": "list", 48 | "required": true, 49 | "members": { 50 | "type": "structure", 51 | "members": { 52 | "cmd": { 53 | "type": "string", 54 | "required": true 55 | }, 56 | "timestamp": { 57 | "format": "unixMilliseconds", 58 | "type": "timestamp" 59 | }, 60 | "fields": { 61 | "type": "map", 62 | "required": true 63 | } 64 | } 65 | } 66 | }, 67 | "table_name": { 68 | "required": true 69 | } 70 | } 71 | } 72 | }, 73 | "search": { 74 | "name": "Search", 75 | "http": { 76 | "method": "GET", 77 | "uri": "/search?query={query}&index_name={index_name}&fetch_fields={fetch_fields}&qp={qp}&disable={disable}&first_formula_name={first_formula_name}&formula_name={formula_name}&summary={summary}&search_type={search_type}&scroll={scroll}&scroll_id={scroll_id}" 78 | }, 79 | "input": { 80 | "type": "structure", 81 | "members": { 82 | "query":{ 83 | "type": "string", 84 | "required": true, 85 | "location": "uri" 86 | }, 87 | "index_name": { 88 | "type": "string", 89 | "required": true, 90 | "location": "uri" 91 | }, 92 | "fetch_fields": { 93 | "type": "string", 94 | "location": "uri" 95 | }, 96 | "qp": { 97 | "type": "string", 98 | "location": "uri" 99 | }, 100 | "disable": { 101 | "type": "string", 102 | "location": "uri" 103 | }, 104 | "first_formula_name": { 105 | "type": "string", 106 | "location": "uri" 107 | }, 108 | "formula_name": { 109 | "type": "string", 110 | "location": "uri" 111 | }, 112 | "summary": { 113 | "type": "string", 114 | "location": "uri" 115 | }, 116 | "search_type": { 117 | "type": "string", 118 | "location": "uri" 119 | }, 120 | "scroll": { 121 | "type": "string", 122 | "location": "uri" 123 | }, 124 | "scroll_id": { 125 | "type": "string", 126 | "location": "uri" 127 | } 128 | } 129 | } 130 | }, 131 | "suggest": { 132 | "name": "suggest", 133 | "http": { 134 | "method": "GET", 135 | "uri": "/suggest?query={query}&index_name={index_name}&suggest_name={suggest_name}&hit={hit}" 136 | }, 137 | "input": { 138 | "type": "structure", 139 | "members": { 140 | "query":{ 141 | "type": "string", 142 | "required": true, 143 | "location": "uri" 144 | }, 145 | "index_name": { 146 | "type": "string", 147 | "required": true, 148 | "location": "uri" 149 | }, 150 | "suggest_name": { 151 | "type": "string", 152 | "required": true, 153 | "location": "uri" 154 | }, 155 | "hit": { 156 | "type": "integer", 157 | "required": false, 158 | "location": "uri" 159 | } 160 | } 161 | } 162 | } 163 | }, 164 | "pagination": { 165 | 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /apis/sts-2015-04-01.json: -------------------------------------------------------------------------------- 1 | { 2 | "format":"pop", 3 | "apiVersion":"2015-04-01", 4 | "checksumFormat":"md5", 5 | "endpointPrefix":"sts", 6 | "serviceAbbreviation":"STS", 7 | "serviceFullName":"Aliyun STS", 8 | "signatureVersion":"pop", 9 | "timestampFormat":"top", 10 | "xmlnamespace":"", 11 | "operations":{ 12 | "assumeRole":{ 13 | "name":"AssumeRole", 14 | "http":{ 15 | "method":"POST", 16 | "uri":"/" 17 | }, 18 | "input":{ 19 | "type":"structure", 20 | "members":{ 21 | "Action":{ 22 | "required":true, 23 | "default":"AssumeRole" 24 | }, 25 | "DurationSeconds":{ 26 | "type":"integer" 27 | }, 28 | "Policy":{ 29 | "type":"string" 30 | }, 31 | "RoleArn":{ 32 | "required":true, 33 | "type":"string" 34 | }, 35 | "RoleSessionName":{ 36 | "required":true, 37 | "type":"string" 38 | } 39 | } 40 | } 41 | }, 42 | "getCallerIdentity":{ 43 | "name":"AssumeRole", 44 | "http":{ 45 | "method":"POST", 46 | "uri":"/" 47 | }, 48 | "input":{ 49 | "type":"structure", 50 | "members":{ 51 | "Action":{ 52 | "required":true, 53 | "default":"GetCallerIdentity" 54 | } 55 | } 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aliyun-sdk-js", 3 | "main": "dist/aliyun-sdk.js", 4 | "version": "1.8.0", 5 | "homepage": "https://github.com/aliyun-UED/aliyun-sdk-js", 6 | "authors": [ 7 | "chylvina@gmail.com" 8 | ], 9 | "description": "Aliyun SDK for JavaScript", 10 | "license": "MIT", 11 | "ignore": [ 12 | "apis", 13 | "node_modules", 14 | "bower_components", 15 | "lib", 16 | "samples", 17 | "test*", 18 | "tools", 19 | "browser.js", 20 | "index.js" 21 | ], 22 | "devDependencies": { 23 | "spark-md5": "~1.0.0", 24 | "jsSHA": "~2.0.1" 25 | }, 26 | "moduleType": [ 27 | "globals" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /browser.js: -------------------------------------------------------------------------------- 1 | window.ALY = module.exports = require('./lib/core'); 2 | require('./lib/http/xhr'); 3 | 4 | require('./lib/services/oss'); 5 | require('./lib/services/opensearch'); 6 | require('./lib/services/batchcompute'); 7 | 8 | ALY.ECS = ALY.Service.defineService('ecs', ['2014-05-26']); 9 | ALY.RDS = ALY.Service.defineService('rds', ['2014-08-15']); 10 | ALY.SLB = ALY.Service.defineService('slb', ['2014-05-15']); 11 | ALY.CDN = ALY.Service.defineService('cdn', ['2014-11-11']); 12 | ALY.STS = ALY.Service.defineService('sts', ['2015-04-01']); 13 | ALY.ESS = ALY.Service.defineService('ess', ['2014-08-28']); 14 | -------------------------------------------------------------------------------- /browser.md: -------------------------------------------------------------------------------- 1 | ## 在浏览器端使用 2 | 3 | 现在 aliyun sdk 支持在浏览器端调用, 只需要引入 dist/aliyun-sdk.js 即可, 使用参考 sample/browser/browser.html 4 | 5 | 目前支持在浏览器端调用除了 sls, ocs 以外的所有服务, 不过目前只有 oss 支持 sts 和 cors , 非 oss 服务只能使用根 accessKey 和 accessSecret 进行初始化, 存在泄露风险. 6 | 7 | ### 如何 build 8 | 9 | 考虑到文件大小, 目前 dist/aliyun-sdk.js 中仅包含 oss 服务, 如果需要 build 其他服务, 请按照以下步骤操作: 10 | 11 | 12 | - git clone git@github.com:aliyun-UED/aliyun-sdk-js.git 13 | - cd aliyun-sdk-js 14 | - npm install 15 | - bower install 16 | - npm install -g browserify 17 | - 构建仅包含 oss 的 aliyun-sdk.js 18 | 19 | ```sh 20 | browserify -r oss-2013-10-15.json browser.js > dist/aliyun-sdk.js 21 | ``` 22 | 23 | - 如果需要编译多个服务, 如 oss, batchCompute 24 | 25 | ```sh 26 | browserify -r oss-2013-10-15.json -r batchcompute-2015-06-30.json browser.js > dist/aliyun-sdk.js 27 | ``` 28 | 29 | 目前在浏览器端运行的 sdk 还在测试阶段, 如果有问题请随时提出. 30 | 31 | ## 初始化 32 | 33 | ```javascript 34 | var oss = new ALY.OSS({ 35 | accessKeyId: "在阿里云OSS申请的 accessKeyId", 36 | secretAccessKey: "在阿里云OSS申请的 secretAccessKey", 37 | securityToken: "", 38 | endpoint: 'http://oss-cn-hangzhou.aliyuncs.com', 39 | apiVersion: '2013-10-15' 40 | }); 41 | ``` 42 | 43 | 可以使用 STS token 初始化 OSS, 后续 sts 会支持其他服务 44 | 45 | ```javascript 46 | var oss = new ALY.OSS({ 47 | accessKeyId: "sts token 中的 accessKeyId", 48 | secretAccessKey: "sts token 中的 secretAccessKey", 49 | securityToken: "sts token 中的 securityToken", 50 | endpoint: 'http://oss-cn-hangzhou.aliyuncs.com', 51 | apiVersion: '2013-10-15' 52 | }); 53 | ``` 54 | 55 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var ALY = require('./lib/aly'); 2 | 3 | ALY.MEMCACHED = require('node_memcached'); 4 | 5 | module.exports = ALY; 6 | -------------------------------------------------------------------------------- /lib/aly.js: -------------------------------------------------------------------------------- 1 | var ALY = require('./core'); 2 | module.exports = ALY; 3 | 4 | // Load Node HTTP client 5 | require('./http/node'); 6 | 7 | // Load all service classes 8 | require('./services'); 9 | -------------------------------------------------------------------------------- /lib/api_loader.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | 4 | var apiRoot = path.join(__dirname, '..', 'apis'); 5 | var serviceMap = {}; 6 | var serviceIdentifiers = []; 7 | var serviceNames = []; 8 | 9 | function buildServiceMap() { 10 | var prefixMap = {}; 11 | Object.keys(serviceMap).forEach(function(identifier) { 12 | serviceMap[identifier].prefix = serviceMap[identifier].prefix || identifier; 13 | prefixMap[serviceMap[identifier].prefix] = identifier; 14 | }); 15 | 16 | fs.readdirSync(apiRoot).forEach(function (file) { 17 | var match = file.match(/^(.+?)-(\d+-\d+-\d+)\.json$/); 18 | if (match) { 19 | var id = match[1], version = match[2]; 20 | if (!serviceMap[id]) { 21 | serviceMap[id] = {}; 22 | } 23 | 24 | //console.log("loading", file); 25 | serviceMap[id].name = require(apiRoot + "/" + file).serviceAbbreviation; 26 | 27 | serviceMap[id].versions = serviceMap[id].versions || []; 28 | if (serviceMap[id].versions.indexOf(version) < 0) { 29 | serviceMap[id].versions.push(version); 30 | } 31 | } 32 | }); 33 | 34 | Object.keys(serviceMap).forEach(function(identifier) { 35 | serviceMap[identifier].versions = serviceMap[identifier].versions.sort(); 36 | serviceIdentifiers.push(identifier); 37 | serviceNames.push(serviceMap[identifier].name); 38 | }); 39 | } 40 | 41 | function getServices() { 42 | buildServiceMap(); 43 | return serviceIdentifiers; 44 | } 45 | 46 | function getServiceNames() { 47 | buildServiceMap(); 48 | return serviceNames; 49 | } 50 | 51 | function serviceVersions(svc) { 52 | buildServiceMap(); 53 | svc = serviceIdentifier(svc); 54 | return serviceMap[svc] ? serviceMap[svc].versions : null; 55 | } 56 | 57 | function serviceName(svc) { 58 | buildServiceMap(); 59 | svc = serviceIdentifier(svc); 60 | return serviceMap[svc] ? serviceMap[svc].name : null; 61 | } 62 | 63 | function serviceFile(svc, version) { 64 | buildServiceMap(); 65 | svc = serviceIdentifier(svc); 66 | if (!serviceMap[svc]) return null; 67 | 68 | var prefix = serviceMap[svc].prefix || svc; 69 | var filePath; 70 | ['min', 'api', 'normal'].some(function(testSuffix) { 71 | filePath = apiRoot + '/' + prefix.toLowerCase() + '-' + version + '.' + 72 | testSuffix + '.json'; 73 | 74 | return fs.existsSync(filePath); 75 | }); 76 | return filePath; 77 | } 78 | 79 | function serviceIdentifier(svc) { 80 | return svc.toLowerCase(); 81 | } 82 | 83 | module.exports = { 84 | serviceVersions: serviceVersions, 85 | serviceName: serviceName, 86 | serviceIdentifier: serviceIdentifier, 87 | serviceFile: serviceFile 88 | }; 89 | 90 | Object.defineProperty(module.exports, 'services', { 91 | enumerable: true, get: getServices 92 | }); 93 | 94 | Object.defineProperty(module.exports, 'serviceNames', { 95 | enumerable: true, get: getServiceNames 96 | }); 97 | -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | var ALY = require('./core'); 2 | 3 | ALY.Config = ALY.util.inherit({ 4 | 5 | constructor: function Config(options) { 6 | if (options === undefined) options = {}; 7 | 8 | ALY.util.each.call(this, this.keys, function (key, value) { 9 | this.set(key, options[key], value); 10 | }); 11 | }, 12 | 13 | clear: function clear() { 14 | /*jshint forin:false */ 15 | ALY.util.each.call(this, this.keys, function (key) { 16 | delete this[key]; 17 | }); 18 | 19 | // reset credential provider 20 | this.set('credentials', undefined); 21 | this.set('credentialProvider', undefined); 22 | }, 23 | 24 | getCredentials: function getCredentials() { 25 | return { 26 | accessKeyId: this.accessKeyId, 27 | secretAccessKey: this.secretAccessKey, 28 | securityToken: this.securityToken 29 | }; 30 | }, 31 | 32 | /** 33 | * Sets a property on the configuration object, allowing for a 34 | * default value 35 | * @api private 36 | */ 37 | set: function set(property, value, defaultValue) { 38 | if (value === undefined) { 39 | if (defaultValue === undefined) { 40 | defaultValue = this.keys[property]; 41 | } 42 | if (typeof defaultValue === 'function') { 43 | this[property] = defaultValue.call(this); 44 | } else { 45 | this[property] = defaultValue; 46 | } 47 | } else { 48 | this[property] = value; 49 | } 50 | }, 51 | 52 | keys: { 53 | accessKeyId: null, 54 | secretAccessKey: null, 55 | region: null, 56 | logger: null, 57 | apiVersions: {}, 58 | apiVersion: null, 59 | endpoint: undefined, 60 | endpointFixed: undefined, // 目前仅对 ots 有效 61 | httpOptions: {}, 62 | maxRetries: undefined, 63 | maxRedirects: 10, 64 | paramValidation: true, 65 | sslEnabled: true, 66 | computeChecksums: true, 67 | securityToken: '', 68 | cname: false, 69 | isRequestPayer: false 70 | } 71 | }); 72 | -------------------------------------------------------------------------------- /lib/core.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The main ALY namespace 3 | * 4 | * @!macro [new] nobrowser 5 | * @note This feature is not supported in the browser environment of the SDK. 6 | */ 7 | var ALY = {}; 8 | module.exports = ALY; 9 | require('./util'); 10 | 11 | ALY.util.update(ALY, { 12 | 13 | VERSION: '1.0.0', 14 | 15 | ServiceInterface: {}, 16 | 17 | Signers: {}, 18 | 19 | XML: {} 20 | 21 | }); 22 | 23 | require('./service'); 24 | 25 | require('./config'); 26 | require('./http'); 27 | require('./sequential_executor'); 28 | require('./event_listeners'); 29 | require('./request'); 30 | require('./signers/request_signer'); 31 | require('./param_validator'); 32 | 33 | ALY.events = new ALY.SequentialExecutor(); 34 | -------------------------------------------------------------------------------- /lib/http.js: -------------------------------------------------------------------------------- 1 | var ALY = require('./core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | ALY.Endpoint = inherit({ 5 | 6 | constructor: function Endpoint(endpoint) { 7 | ALY.util.hideProperties(this, ['slashes', 'auth', 'hash', 'search', 'query']); 8 | 9 | if (typeof endpoint === 'undefined' || endpoint === null) { 10 | throw new Error('Invalid endpoint: ' + endpoint); 11 | } 12 | 13 | if (!endpoint.match(/^http/)) { 14 | throw new Error('错误的 endpoint 格式, 需要以 http 或者 https 开头'); 15 | } 16 | 17 | ALY.util.update(this, ALY.util.urlParse(endpoint)); 18 | 19 | // Ensure the port property is set as an integer 20 | if (this.port) { 21 | this.port = parseInt(this.port, 10); 22 | } else { 23 | this.port = this.protocol === 'https:' ? 443 : 80; 24 | } 25 | } 26 | 27 | }); 28 | 29 | ALY.HttpRequest = inherit({ 30 | 31 | constructor: function HttpRequest(endpoint, region) { 32 | this.method = 'POST'; 33 | this.path = endpoint.path || '/'; 34 | this.headers = {}; 35 | this.body = ''; 36 | this.endpoint = endpoint; 37 | this.region = region; 38 | this.setUserAgent(); 39 | }, 40 | 41 | setUserAgent: function setUserAgent() { 42 | //var prefix = ALY.util.isBrowser() ? 'X-Aly-' : ''; 43 | //this.headers[prefix + 'User-Agent'] = ALY.util.userAgent(); 44 | //this.headers['x-sdk-client'] = this.headers['User-Agent'] = ALY.util.userAgent(); 45 | // pop 现在不支持 x-sdk-client 在浏览器设置 46 | this.headers['User-Agent'] = ALY.util.userAgent(); 47 | }, 48 | 49 | pathname: function pathname() { 50 | return this.path.split('?', 1)[0]; 51 | }, 52 | 53 | search: function search() { 54 | return this.path.split('?', 2)[1] || ''; 55 | }, 56 | 57 | debug: function () { 58 | if(process.env.DEBUG == 'aliyun') { 59 | console.log('-------- HttpRequest Start: --------'); 60 | console.log('method:', this.method); 61 | console.log('path:', this.path); 62 | console.log('headers:'); 63 | for(var i in this.headers) { 64 | if (i == 'constructor') 65 | continue; 66 | console.log(i, ':', this.headers[i]); 67 | }; 68 | } 69 | } 70 | }); 71 | 72 | ALY.HttpResponse = inherit({ 73 | 74 | constructor: function HttpResponse() { 75 | this.statusCode = undefined; 76 | this.headers = {}; 77 | this.body = undefined; 78 | } 79 | }); 80 | 81 | 82 | ALY.HttpClient = inherit({}); 83 | 84 | ALY.HttpClient.getInstance = function getInstance() { 85 | /*jshint newcap:false */ 86 | if (this.singleton === undefined) { 87 | this.singleton = new this(); 88 | } 89 | return this.singleton; 90 | }; 91 | -------------------------------------------------------------------------------- /lib/http/node.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var Stream = require('stream').Stream; 3 | var WritableStream = require('stream').Writable; 4 | var ReadableStream = require('stream').Readable; 5 | require('../http'); 6 | 7 | /** 8 | * @api private 9 | */ 10 | ALY.NodeHttpClient = ALY.util.inherit({ 11 | handleRequest: function handleRequest(httpRequest, httpOptions, callback, errCallback) { 12 | var endpoint = httpRequest.endpoint; 13 | var pathPrefix = ''; 14 | if (!httpOptions) httpOptions = {}; 15 | 16 | var useSSL = endpoint.protocol === 'https:'; 17 | var http = useSSL ? require('https') : require('http'); 18 | var options = { 19 | host: endpoint.hostname, 20 | port: endpoint.port, 21 | method: httpRequest.method, 22 | headers: httpRequest.headers, 23 | path: pathPrefix + httpRequest.path 24 | }; 25 | 26 | if (useSSL && !httpOptions.agent) { 27 | options.agent = this.sslAgent(); 28 | } 29 | 30 | ALY.util.update(options, httpOptions); 31 | delete options.proxy; // proxy isn't an HTTP option 32 | delete options.timeout; // timeout isn't an HTTP option 33 | 34 | var stream = http.request(options, function (httpResp) { 35 | callback(httpResp); 36 | httpResp.emit('headers', httpResp.statusCode, httpResp.headers); 37 | }); 38 | httpRequest.stream = stream; // attach stream to httpRequest 39 | 40 | // timeout support 41 | stream.setTimeout(httpOptions.timeout || 0); 42 | stream.once('timeout', function() { 43 | var msg = 'Connection timed out after ' + httpOptions.timeout + 'ms'; 44 | errCallback(ALY.util.error(new Error(msg), {code: 'TimeoutError'})); 45 | 46 | // HACK - abort the connection without tripping our error handler 47 | // since we already raised our TimeoutError. Otherwise the connection 48 | // comes back with ECONNRESET, which is not a helpful error message 49 | stream.removeListener('error', errCallback); 50 | stream.on('error', function() { }); 51 | stream.abort(); 52 | }); 53 | 54 | stream.on('error', errCallback); 55 | this.writeBody(stream, httpRequest); 56 | return stream; 57 | }, 58 | 59 | writeBody: function writeBody(stream, httpRequest) { 60 | var body = httpRequest.body; 61 | 62 | if (body && WritableStream && ReadableStream) { // progress support 63 | if (!(body instanceof Stream)) body = this.bufferToStream(body); 64 | body.pipe(this.progressStream(stream, httpRequest)); 65 | } 66 | 67 | if (body instanceof Stream) { 68 | body.pipe(stream); 69 | } else if (body) { 70 | stream.end(body); 71 | } else { 72 | stream.end(); 73 | } 74 | }, 75 | 76 | sslAgent: function sslAgent() { 77 | var https = require('https'); 78 | 79 | if (!ALY.NodeHttpClient.sslAgent) { 80 | ALY.NodeHttpClient.sslAgent = new https.Agent({}); 81 | ALY.NodeHttpClient.sslAgent.setMaxListeners(0); 82 | 83 | // delegate maxSockets to globalAgent 84 | Object.defineProperty(ALY.NodeHttpClient.sslAgent, 'maxSockets', { 85 | enumerable: true, 86 | get: function() { return https.globalAgent.maxSockets; } 87 | }); 88 | } 89 | return ALY.NodeHttpClient.sslAgent; 90 | }, 91 | 92 | progressStream: function progressStream(stream, httpRequest) { 93 | var numBytes = 0; 94 | var totalBytes = httpRequest.headers['Content-Length']; 95 | var writer = new WritableStream(); 96 | writer._write = function(chunk, encoding, callback) { 97 | if (chunk) { 98 | numBytes += chunk.length; 99 | stream.emit('sendProgress', { 100 | loaded: numBytes, total: totalBytes 101 | }); 102 | } 103 | callback(); 104 | }; 105 | return writer; 106 | }, 107 | 108 | bufferToStream: function bufferToStream(buffer) { 109 | if (!ALY.util.Buffer.isBuffer(buffer)) buffer = new ALY.util.Buffer(buffer); 110 | 111 | var readable = new ReadableStream(); 112 | var pos = 0; 113 | readable._read = function(size) { 114 | if (pos >= buffer.length) return readable.push(null); 115 | 116 | var end = pos + size; 117 | if (end > buffer.length) end = buffer.length; 118 | readable.push(buffer.slice(pos, end)); 119 | pos = end; 120 | }; 121 | 122 | return readable; 123 | }, 124 | 125 | emitter: null 126 | }); 127 | 128 | /** 129 | * @!ignore 130 | */ 131 | 132 | /** 133 | * @api private 134 | */ 135 | ALY.HttpClient.prototype = ALY.NodeHttpClient.prototype; 136 | 137 | /** 138 | * @api private 139 | */ 140 | ALY.HttpClient.streamsApiVersion = ReadableStream ? 2 : 1; 141 | -------------------------------------------------------------------------------- /lib/http/xhr.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var EventEmitter = require('events').EventEmitter; 3 | require('../http'); 4 | 5 | /** 6 | * @api private 7 | */ 8 | ALY.XHRClient = ALY.util.inherit({ 9 | handleRequest: function handleRequest(httpRequest, httpOptions, callback, errCallback) { 10 | var self = this; 11 | var endpoint = httpRequest.endpoint; 12 | var emitter = new EventEmitter(); 13 | var href = endpoint.protocol + '//' + endpoint.hostname; 14 | if (endpoint.port != 80 && endpoint.port != 443) { 15 | href += ':' + endpoint.port; 16 | } 17 | href += httpRequest.path; 18 | 19 | var xhr = new XMLHttpRequest(); 20 | httpRequest.stream = xhr; 21 | 22 | if (httpOptions.timeout) { 23 | xhr.timeout = httpOptions.timeout; 24 | } 25 | 26 | xhr.addEventListener('readystatechange', function() { 27 | try { 28 | if (xhr.status === 0) return; // 0 code is invalid 29 | } 30 | catch (e) { return; } 31 | 32 | if (this.readyState === this.HEADERS_RECEIVED) { 33 | try { xhr.responseType = 'arraybuffer'; } catch (e) {} 34 | emitter.statusCode = xhr.status; 35 | emitter.headers = self.parseHeaders(xhr.getAllResponseHeaders()); 36 | emitter.emit('headers', emitter.statusCode, emitter.headers); 37 | } else if (this.readyState === this.DONE) { 38 | self.finishRequest(xhr, emitter); 39 | } 40 | }, false); 41 | xhr.upload.addEventListener('progress', function (evt) { 42 | emitter.emit('sendProgress', evt); 43 | }); 44 | xhr.addEventListener('progress', function (evt) { 45 | emitter.emit('receiveProgress', evt); 46 | }, false); 47 | xhr.addEventListener('timeout', function () { 48 | errCallback(ALY.util.error(new Error('Timeout'), {code: 'TimeoutError'})); 49 | }, false); 50 | xhr.addEventListener('error', function () { 51 | errCallback(ALY.util.error(new Error('Network Failure'), { 52 | code: 'NetworkingError' 53 | })); 54 | }, false); 55 | 56 | callback(emitter); 57 | xhr.open(httpRequest.method, href, true); 58 | ALY.util.each(httpRequest.headers, function (key, value) { 59 | if (key !== 'Content-Length' && key !== 'User-Agent' && key !== 'Host' && key !== 'Date') { 60 | xhr.setRequestHeader(key, value); 61 | } 62 | }); 63 | 64 | if (httpRequest.body && typeof httpRequest.body.buffer === 'object') { 65 | xhr.send(httpRequest.body.buffer); // typed arrays sent as ArrayBuffer 66 | } else { 67 | xhr.send(httpRequest.body); 68 | } 69 | 70 | return emitter; 71 | }, 72 | 73 | parseHeaders: function parseHeaders(rawHeaders) { 74 | var headers = {}; 75 | ALY.util.arrayEach(rawHeaders.split(/\r?\n/), function (line) { 76 | var key = line.split(':', 1)[0]; 77 | var value = line.substring(key.length + 2); 78 | if (key.length > 0) headers[key] = value; 79 | }); 80 | return headers; 81 | }, 82 | 83 | finishRequest: function finishRequest(xhr, emitter) { 84 | var buffer; 85 | if (xhr.responseType === 'arraybuffer' && xhr.response) { 86 | var ab = xhr.response; 87 | buffer = new ALY.util.Buffer(ab.byteLength); 88 | var view = new Uint8Array(ab); 89 | for (var i = 0; i < buffer.length; ++i) { 90 | buffer[i] = view[i]; 91 | } 92 | } 93 | 94 | try { 95 | if (!buffer && typeof xhr.responseText === 'string') { 96 | buffer = new ALY.util.Buffer(xhr.responseText); 97 | } 98 | } catch (e) {} 99 | 100 | if (buffer) emitter.emit('data', buffer); 101 | emitter.emit('end'); 102 | } 103 | }); 104 | 105 | /** 106 | * @api private 107 | */ 108 | ALY.HttpClient.prototype = ALY.XHRClient.prototype; 109 | 110 | /** 111 | * @api private 112 | */ 113 | ALY.HttpClient.streamsApiVersion = 1; 114 | -------------------------------------------------------------------------------- /lib/json/builder.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | /** 5 | * @api private 6 | */ 7 | ALY.JSON = {}; 8 | 9 | /** 10 | * @api private 11 | */ 12 | ALY.JSON.Builder = inherit({ 13 | 14 | constructor: function JSONBuilder(rules, options) { 15 | this.rules = rules; 16 | this.timestampFormat = options.timestampFormat; 17 | }, 18 | 19 | build: function build(params) { 20 | return JSON.stringify(this.translate(this.rules, params)); 21 | }, 22 | 23 | translate: function translate(rules, value) { 24 | if (value === null || value === undefined) return undefined; 25 | 26 | if (rules.type == 'structure') { 27 | 28 | // translate structures (hashes with pre-defined keys) 29 | var struct = {}; 30 | ALY.util.each.call(this, value, function (memberName, memberValue) { 31 | var memberRules = rules.members[memberName] || {}; 32 | var result = this.translate(memberRules, memberValue); 33 | if (result !== undefined) struct[memberName] = result; 34 | }); 35 | return struct; 36 | 37 | } else if (rules.type == 'list') { 38 | 39 | // translate each member of the list 40 | var list = []; 41 | ALY.util.arrayEach.call(this, value, function (memberValue) { 42 | var memberRules = rules.members || {}; 43 | var result = this.translate(memberRules, memberValue); 44 | if (result !== undefined) list.push(result); 45 | }); 46 | return list; 47 | 48 | } else if (rules.type == 'map') { 49 | 50 | // translate maps (hashes with user supplied keys) 51 | var map = {}; 52 | ALY.util.each.call(this, value, function (memberName, memberValue) { 53 | var memberRules = rules.members || {}; 54 | var result = this.translate(memberRules, memberValue); 55 | if (result !== undefined) map[memberName] = result; 56 | }); 57 | return map; 58 | 59 | } else if (rules.type == 'timestamp') { 60 | 61 | var timestampFormat = rules.format || this.timestampFormat; 62 | return ALY.util.date.format(value, timestampFormat); 63 | 64 | } else if (rules.type == 'integer') { 65 | return parseInt(value, 10); 66 | } else if (rules.type == 'float') { 67 | return parseFloat(value); 68 | } else { 69 | 70 | // all other shapes 71 | return value; 72 | 73 | } 74 | } 75 | 76 | }); 77 | -------------------------------------------------------------------------------- /lib/service_interface/json.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | require('../json/builder'); 3 | 4 | /** 5 | * @api private 6 | */ 7 | ALY.ServiceInterface.Json = { 8 | buildRequest: function buildRequest(req) { 9 | var httpRequest = req.httpRequest; 10 | var api = req.service.api; 11 | var target = api.targetPrefix + '.' + api.operations[req.operation].name; 12 | var version = api.jsonVersion || '1.0'; 13 | 14 | var rules = api.operations[req.operation].input; 15 | var builder = new ALY.JSON.Builder(rules, api); 16 | 17 | httpRequest.path = '/'; 18 | httpRequest.body = builder.build(req.params || {}); 19 | }, 20 | 21 | extractError: function extractError(resp) { 22 | var error = {}; 23 | var httpResponse = resp.httpResponse; 24 | 25 | if (httpResponse.body.length > 0) { 26 | var e = JSON.parse(httpResponse.body.toString()); 27 | if (e.__type || e.code || e.Code) { 28 | error.code = (e.__type || e.code || e.Code).split('#').pop(); 29 | } else { 30 | error.code = 'UnknownError'; 31 | } 32 | if (error.code === 'RequestEntityTooLarge') { 33 | error.message = 'Request body must be less than 1 MB'; 34 | } else { 35 | error.message = (e.message || e.Message || null); 36 | } 37 | } else { 38 | error.code = httpResponse.statusCode; 39 | error.message = null; 40 | } 41 | 42 | resp.error = ALY.util.error(new Error(), error); 43 | }, 44 | 45 | extractData: function extractData(resp) { 46 | resp.data = JSON.parse(resp.httpResponse.body.toString() || '{}'); 47 | } 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /lib/service_interface/pop.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | require('./rest'); 3 | require('./json'); 4 | 5 | function randomNumbers(count) { 6 | var num = ''; 7 | for (var i = 0; i < count; i++) { 8 | num += Math.floor(Math.random() * 10); 9 | } 10 | return num; 11 | } 12 | 13 | /** 14 | * @api private 15 | */ 16 | ALY.ServiceInterface.Pop = { 17 | buildRequest: function buildRequest(req) { 18 | ALY.ServiceInterface.Rest.buildRequest(req); 19 | ALY.ServiceInterface.Pop.populateBody(req); 20 | }, 21 | 22 | extractError: function extractError(resp) { 23 | ALY.ServiceInterface.Json.extractError(resp); 24 | }, 25 | 26 | extractData: function extractData(resp) { 27 | resp.data = JSON.parse(resp.httpResponse.body.toString()); 28 | }, 29 | 30 | populateBody: function populateBody(req) { 31 | req.httpRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; 32 | 33 | var body = req.params; 34 | var date = ALY.util.date.getDate(); 35 | 36 | body.Format = "JSON"; 37 | body.Version = req.service.api.apiVersion; 38 | body.AccessKeyId = req.service.config.accessKeyId; 39 | body.SignatureVersion = "1.0"; 40 | body.SignatureMethod = "HMAC-SHA1"; 41 | body.SignatureNonce = String(date.getTime()) + randomNumbers(4); 42 | body.Timestamp = ALY.util.date.iso8601(date); 43 | 44 | // sign 45 | var headers = []; 46 | 47 | ALY.util.each(body, function (name) { 48 | headers.push(name); 49 | }); 50 | 51 | headers.sort(function (a, b) { 52 | return a < b ? -1 : 1; 53 | }); 54 | 55 | var canonicalizedQueryString = ""; 56 | ALY.util.arrayEach.call(this, headers, function (name) { 57 | canonicalizedQueryString += "&" + name + "=" + ALY.util.popEscape(body[name]); 58 | }); 59 | 60 | var stringToSign = 'POST&%2F&' + ALY.util.popEscape(canonicalizedQueryString.substr(1)); 61 | body.Signature = ALY.util.crypto.hmac(req.service.config.secretAccessKey + '&', stringToSign, 'base64', 'sha1'); 62 | 63 | // body 64 | var bodyString = ALY.util.queryParamsToString(body); 65 | 66 | req.httpRequest.body = bodyString; 67 | }, 68 | 69 | buildJSON: function buildJSON(params, rules, api) { 70 | var builder = new ALY.JSON.Builder(rules, api); 71 | return builder.build(params); 72 | } 73 | 74 | }; 75 | -------------------------------------------------------------------------------- /lib/service_interface/query.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | // 目前 query 是针对 top 调用的 5 | ALY.ServiceInterface.Query = { 6 | buildRequest: function buildRequest(req) { 7 | var operation = req.service.api.operations[req.operation]; 8 | var httpRequest = req.httpRequest; 9 | httpRequest.method = 'GET'; 10 | httpRequest.headers['Content-Type'] = 11 | 'application/x-www-form-urlencoded; charset=utf-8'; 12 | httpRequest.params = { 13 | Action: operation.name, 14 | Version: req.service.api.apiVersion, 15 | Timestamp: ALY.util.date.iso8601(ALY.util.date.getDate()), 16 | Format: 'json', 17 | AccessKeyId: req.service.config.accessKeyId, 18 | SignatureVersion: '1.0', 19 | SignatureMethod: 'HMAC-SHA1', 20 | SignatureNonce: ALY.util.uuid() 21 | }; 22 | 23 | // convert the request parameters into a list of query params, 24 | // e.g. Deeply.NestedParam.0.Name=value 25 | var rules = operation.input; 26 | if (rules) rules = rules.members; 27 | var builder = new ALY.QueryParamSerializer(rules, req.service.api); 28 | builder.serialize(req.params, function(name, value) { 29 | httpRequest.params[name] = value; 30 | }); 31 | httpRequest.path = '/?' + ALY.util.queryParamsToString(httpRequest.params); 32 | }, 33 | 34 | extractError: function extractError(resp) { 35 | var data = JSON.parse(resp.httpResponse.body.toString()); 36 | 37 | if (data.Code) { 38 | resp.error = ALY.util.error(new Error(), { 39 | code: data.Code, 40 | message: data.Message, 41 | RequestId: data.RequestId 42 | }); 43 | } else { 44 | resp.error = ALY.util.error(new Error(), { 45 | code: resp.httpResponse.statusCode, 46 | message: null, 47 | RequestId: data.RequestId 48 | }); 49 | } 50 | }, 51 | 52 | extractData: function extractData(resp) { 53 | resp.data = resp.httpResponse.body.toString(); 54 | } 55 | }; 56 | 57 | /** 58 | * @api private 59 | */ 60 | ALY.QueryParamSerializer = inherit({ 61 | 62 | constructor: function QueryParamSerializer(rules, options) { 63 | this.rules = rules; 64 | this.timestampFormat = options ? options.timestampFormat : 'iso8601'; 65 | }, 66 | 67 | serialize: function serialize(params, fn) { 68 | this.serializeStructure('', params, this.rules, fn); 69 | }, 70 | 71 | serializeStructure: function serializeStructure(prefix, struct, rules, fn) { 72 | var that = this; 73 | ALY.util.each(struct, function (name, member) { 74 | var n = rules[name].name || name; 75 | var memberName = prefix ? prefix + '.' + n : n; 76 | that.serializeMember(memberName, member, rules[name], fn); 77 | }); 78 | }, 79 | 80 | serializeMap: function serialzeMap(name, map, rules, fn) { 81 | var i = 1; 82 | var that = this; 83 | ALY.util.each(map, function (key, value) { 84 | var prefix = rules.flattened ? '.' : '.entry.'; 85 | var position = prefix + (i++) + '.'; 86 | var keyName = position + (rules.keys.name || 'key'); 87 | var valueName = position + (rules.members.name || 'value'); 88 | that.serializeMember(name + keyName, key, rules.keys, fn); 89 | that.serializeMember(name + valueName, value, rules.members, fn); 90 | }); 91 | }, 92 | 93 | serializeList: function serializeList(name, list, rules, fn) { 94 | var that = this; 95 | var memberRules = rules.members || {}; 96 | ALY.util.arrayEach(list, function (v, n) { 97 | var suffix = '.' + (n + 1); 98 | if (rules.flattened) { 99 | if (memberRules.name) { 100 | var parts = name.split('.'); 101 | parts.pop(); 102 | parts.push(memberRules.name); 103 | name = parts.join('.'); 104 | } 105 | } else { 106 | suffix = '.member' + suffix; 107 | } 108 | that.serializeMember(name + suffix, v, memberRules, fn); 109 | }); 110 | }, 111 | 112 | serializeMember: function serializeMember(name, value, rules, fn) { 113 | if (value === null || value === undefined) return; 114 | if (rules.type === 'structure') { 115 | this.serializeStructure(name, value, rules.members, fn); 116 | } else if (rules.type === 'list') { 117 | this.serializeList(name, value, rules, fn); 118 | } else if (rules.type === 'map') { 119 | this.serializeMap(name, value, rules, fn); 120 | } else if (rules.type === 'timestamp') { 121 | var timestampFormat = rules.format || this.timestampFormat; 122 | fn.call(this, name, ALY.util.date.format(value, timestampFormat)); 123 | } else { 124 | fn.call(this, name, String(value)); 125 | } 126 | } 127 | 128 | }); 129 | -------------------------------------------------------------------------------- /lib/service_interface/rest.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | 3 | /** 4 | * @api private 5 | */ 6 | ALY.ServiceInterface.Rest = { 7 | buildRequest: function buildRequest(req) { 8 | ALY.ServiceInterface.Rest.populateMethod(req); 9 | ALY.ServiceInterface.Rest.populateURI(req); 10 | ALY.ServiceInterface.Rest.populateHeaders(req); 11 | }, 12 | 13 | extractError: function extractError() { 14 | }, 15 | 16 | extractData: function extractData(resp) { 17 | var req = resp.request; 18 | var data = {}; 19 | var r = resp.httpResponse; 20 | var operation = req.service.api.operations[req.operation]; 21 | var rules = (operation.output || {}).members || {}; 22 | 23 | // normalize headers names to lower-cased keys for matching 24 | var headers = {}; 25 | ALY.util.each(r.headers, function (k, v) { 26 | headers[k.toLowerCase()] = v; 27 | }); 28 | 29 | ALY.util.each(rules, function (name, rule) { 30 | if (rule.location === 'header') { 31 | var header = (rule.name || name).toLowerCase(); 32 | if (rule.type == 'map') { 33 | data[name] = {}; 34 | ALY.util.each(r.headers, function (k, v) { 35 | var result = k.match(new RegExp('^' + rule.name + '(.+)', 'i')); 36 | if (result !== null) { 37 | data[name][result[1]] = v; 38 | } 39 | }); 40 | } 41 | if (headers[header] !== undefined) { 42 | data[name] = headers[header]; 43 | } 44 | } 45 | if (rule.location === 'status') { 46 | data[name] = parseInt(r.statusCode, 10); 47 | } 48 | }); 49 | 50 | resp.data = data; 51 | }, 52 | 53 | populateMethod: function populateMethod(req) { 54 | req.httpRequest.method = req.service.api.operations[req.operation].http.method; 55 | }, 56 | 57 | populateURI: function populateURI(req) { 58 | var operation = req.service.api.operations[req.operation]; 59 | var uri = operation.http.uri; 60 | var pathPattern = uri.split(/\?/)[0]; 61 | var rules = (operation.input || {}).members || {}; 62 | 63 | var escapePathParam = req.service.escapePathParam || 64 | ALY.ServiceInterface.Rest.escapePathParam; 65 | var escapeQuerystringParam = req.service.escapeQuerystringParam || 66 | ALY.ServiceInterface.Rest.escapeQuerystringParam; 67 | 68 | ALY.util.each.call(this, rules, function (name, rule) { 69 | if (rule.location == 'uri' && req.params[name] != null) { 70 | // if the value is being inserted into the path portion of the 71 | // URI, then we need to use a different (potentially) escaping 72 | // pattern, this is especially true for S3 path params like Key. 73 | var value = pathPattern.match('{' + name + '}') ? 74 | escapePathParam(req.params[name]) : 75 | escapeQuerystringParam(req.params[name]); 76 | 77 | uri = uri.replace('{' + name + '}', value); 78 | } 79 | }); 80 | 81 | var path = uri.split('?')[0]; 82 | var querystring = uri.split('?')[1]; 83 | 84 | if (querystring) { 85 | var parts = []; 86 | ALY.util.arrayEach(querystring.split('&'), function (part) { 87 | if (!part.match('{\\w+}')) parts.push(part); 88 | }); 89 | uri = (parts.length > 0 ? path + '?' + parts.join('&') : path); 90 | } else { 91 | uri = path; 92 | } 93 | 94 | req.httpRequest.path = uri; 95 | }, 96 | 97 | escapePathParam: function escapePathParam(value) { 98 | return ALY.util.uriEscape(String(value)); 99 | }, 100 | 101 | escapeQuerystringParam: function escapeQuerystringParam(value) { 102 | return ALY.util.uriEscape(String(value)); 103 | }, 104 | 105 | populateHeaders: function populateHeaders(req) { 106 | var operation = req.service.api.operations[req.operation]; 107 | var rules = (operation.input || {}).members || {}; 108 | 109 | ALY.util.each.call(this, rules, function (name, rule) { 110 | if (rule.location === 'header' && req.params[name]) { 111 | if (rule.type === 'map') { 112 | ALY.util.each(req.params[name], function (key, value) { 113 | req.httpRequest.headers[rule.name + key] = value; 114 | }); 115 | } else { 116 | var value = req.params[name]; 117 | if (rule.type === 'timestamp') { 118 | var timestampFormat = rule.format || req.service.api.timestampFormat; 119 | value = ALY.util.date.format(value, timestampFormat); 120 | } 121 | req.httpRequest.headers[rule.name || name] = value; 122 | } 123 | } 124 | }); 125 | 126 | if(req.service.config.securityToken) { 127 | req.httpRequest.headers["x-oss-security-token"] = req.service.config.securityToken; 128 | } 129 | 130 | } 131 | }; 132 | -------------------------------------------------------------------------------- /lib/service_interface/rest_json.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | require('./rest'); 3 | require('./json'); 4 | 5 | /** 6 | * @api private 7 | */ 8 | ALY.ServiceInterface.RestJson = { 9 | buildRequest: function buildRequest(req) { 10 | ALY.ServiceInterface.Rest.buildRequest(req); 11 | ALY.ServiceInterface.RestJson.populateBody(req); 12 | }, 13 | 14 | extractError: function extractError(resp) { 15 | ALY.ServiceInterface.Json.extractError(resp); 16 | }, 17 | 18 | extractData: function extractData(resp) { 19 | var req = resp.request; 20 | var rules = req.service.api.operations[req.operation].output || {}; 21 | if (rules.payload && rules.members[rules.payload]) { 22 | if (rules.members[rules.payload].streaming) { 23 | resp.data[rules.payload] = resp.httpResponse.body; 24 | } else { 25 | resp.data[rules.payload] = resp.httpResponse.body.toString(); 26 | } 27 | } else { 28 | var data = resp.data; 29 | ALY.ServiceInterface.Json.extractData(resp); 30 | resp.data = ALY.util.merge(data, resp.data); 31 | } 32 | }, 33 | 34 | populateBody: function populateBody(req) { 35 | var input = req.service.api.operations[req.operation].input; 36 | var payload = input.payload; 37 | var params = {}; 38 | 39 | if (typeof payload === 'string') { 40 | 41 | var rules = input.members[payload]; 42 | params = req.params[payload]; 43 | 44 | if (params === undefined) return; 45 | 46 | if (rules.type === 'structure') { 47 | req.httpRequest.body = this.buildJSON(params, input, req.service.api); 48 | } else { 49 | // non-xml paylaod 50 | req.httpRequest.body = params; 51 | } 52 | 53 | } else if (payload) { 54 | 55 | ALY.util.arrayEach(payload, function (param) { 56 | if (req.params[param] !== undefined) { 57 | params[param] = req.params[param]; 58 | } 59 | }); 60 | req.httpRequest.body = this.buildJSON(params, input, req.service.api); 61 | 62 | } 63 | }, 64 | 65 | buildJSON: function buildJSON(params, rules, api) { 66 | var builder = new ALY.JSON.Builder(rules, api); 67 | return builder.build(params); 68 | } 69 | 70 | }; 71 | -------------------------------------------------------------------------------- /lib/service_interface/rest_xml.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | require('../xml/builder'); 3 | require('../xml/parser'); 4 | require('./rest'); 5 | 6 | /** 7 | * @api private 8 | */ 9 | ALY.ServiceInterface.RestXml = { 10 | buildRequest: function buildRequest(req) { 11 | ALY.ServiceInterface.Rest.buildRequest(req); 12 | ALY.ServiceInterface.RestXml.populateBody(req); 13 | }, 14 | 15 | extractError: function extractError(resp) { 16 | try { 17 | var data = new ALY.XML.Parser({}).parse(resp.httpResponse.body.toString()); 18 | if (data.Errors) data = data.Errors; 19 | if (data.Error) data = data.Error; 20 | if (data.Code) { 21 | resp.error = ALY.util.error(new Error(), { 22 | code: data.Code, 23 | message: data.Message 24 | }); 25 | } else { 26 | resp.error = ALY.util.error(new Error(), { 27 | code: resp.httpResponse.statusCode, 28 | message: null 29 | }); 30 | } 31 | } 32 | catch(err) { 33 | resp.error = ALY.util.error(new Error(), { 34 | code: resp.httpResponse.statusCode, 35 | message: resp.httpResponse.body.toString() 36 | }); 37 | } 38 | }, 39 | 40 | extractData: function extractData(resp) { 41 | ALY.ServiceInterface.Rest.extractData(resp); 42 | 43 | var req = resp.request; 44 | var httpResponse = resp.httpResponse; 45 | var operation = req.service.api.operations[req.operation]; 46 | var rules = operation.output.members; 47 | 48 | var output = operation.output; 49 | var payload = output.payload; 50 | 51 | if (payload) { 52 | if (rules[payload].streaming) { 53 | resp.data[payload] = httpResponse.body; 54 | } else { 55 | resp.data[payload] = httpResponse.body.toString(); 56 | } 57 | } else if (httpResponse.body.length > 0) { 58 | try { 59 | var parser = new ALY.XML.Parser(operation.output || {}); 60 | ALY.util.update(resp.data, parser.parse(httpResponse.body.toString())); 61 | } 62 | catch(err) { 63 | // ignore parse error 64 | } 65 | } 66 | 67 | // extract request id 68 | resp.data.RequestId = httpResponse.headers['x-oss-request-id'] || 69 | httpResponse.headers['x-oss-requestid']; 70 | }, 71 | 72 | populateBody: function populateBody(req) { 73 | var input = req.service.api.operations[req.operation].input; 74 | var payload = input.payload; 75 | var rules = {}; 76 | var builder = null; 77 | var params = req.params; 78 | 79 | if (typeof payload === 'string') { 80 | 81 | rules = input.members[payload]; 82 | params = params[payload]; 83 | 84 | if (params === undefined) return; 85 | 86 | if (rules.type === 'structure') { 87 | builder = new ALY.XML.Builder(payload, rules.members, req.service.api); 88 | req.httpRequest.body = builder.toXML(params); 89 | } else { 90 | // non-xml paylaod 91 | req.httpRequest.body = params; 92 | } 93 | 94 | } else if (payload) { 95 | 96 | ALY.util.arrayEach(payload, function (member) { 97 | rules[member] = input.members[member]; 98 | }); 99 | 100 | builder = new ALY.XML.Builder(input.wrapper, rules, req.service.api); 101 | req.httpRequest.body = builder.toXML(params); 102 | 103 | } 104 | 105 | } 106 | }; 107 | -------------------------------------------------------------------------------- /lib/service_interface/top.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | require('./rest'); 3 | require('./json'); 4 | 5 | /** 6 | * @api private 7 | */ 8 | ALY.ServiceInterface.Top = { 9 | buildRequest: function buildRequest(req) { 10 | ALY.ServiceInterface.Top.populateMethod(req); 11 | ALY.ServiceInterface.Top.populateBodyAndURI(req); 12 | }, 13 | 14 | extractError: function extractError(resp) { 15 | ALY.ServiceInterface.Json.extractError(resp); 16 | }, 17 | 18 | extractData: function extractData(resp) { 19 | resp.data = JSON.parse(resp.httpResponse.body.toString()); 20 | }, 21 | 22 | populateMethod: function populateBodyAndURI(req) { 23 | req.httpRequest.method = req.service.api.operations[req.operation].http.method; 24 | }, 25 | 26 | populateBodyAndURI: function populateBody(req) { 27 | req.httpRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; 28 | req.httpRequest.headers['Cache-Control'] = "no-cache"; 29 | req.httpRequest.headers['Connection'] = "Keep-Alive"; 30 | 31 | var application_parameter = req.params; 32 | 33 | // convert json object to json string 34 | ALY.util.each(application_parameter, function (name) { 35 | var value = application_parameter[name]; 36 | if(value !== null && typeof value === 'object') { 37 | application_parameter[name] = JSON.stringify(value); 38 | } 39 | }); 40 | 41 | var sys_parameters = { 42 | format: "json", 43 | app_key: req.service.config.accessKeyId, 44 | sign_method: "md5", 45 | v: "2.0", 46 | timestamp: ALY.util.date.unixMilliseconds(ALY.util.date.getDate()), 47 | partner_id: "taobao-sdk-python-20151223", 48 | method: application_parameter.method 49 | }; 50 | 51 | delete application_parameter.method; 52 | 53 | // sign 54 | var sign_parameter = []; 55 | 56 | ALY.util.each(sys_parameters, function (name) { 57 | sign_parameter.push(name); 58 | }); 59 | 60 | ALY.util.each(application_parameter, function (name) { 61 | sign_parameter.push(name); 62 | }); 63 | 64 | sign_parameter.sort(function (a, b) { 65 | return a.toLowerCase() < b.toLowerCase() ? -1 : 1; 66 | }); 67 | 68 | var canonicalizedQueryString = ""; 69 | ALY.util.arrayEach.call(this, sign_parameter, function (name) { 70 | canonicalizedQueryString += name + (sys_parameters[name] || application_parameter[name]); 71 | }); 72 | 73 | var stringToSign = req.service.config.secretAccessKey + canonicalizedQueryString + req.service.config.secretAccessKey; 74 | 75 | sys_parameters.sign = ALY.util.crypto.md5(stringToSign, 'hex').toUpperCase(); 76 | 77 | req.httpRequest.body = ALY.util.queryParamsToString(application_parameter); 78 | 79 | req.httpRequest.path = "/router/rest?" + ALY.util.queryParamsToString(sys_parameters); 80 | }, 81 | 82 | buildJSON: function buildJSON(params, rules, api) { 83 | var builder = new ALY.JSON.Builder(rules, api); 84 | return builder.build(params); 85 | } 86 | 87 | }; 88 | -------------------------------------------------------------------------------- /lib/services.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fs = require('fs'); 3 | var ALY = require('./core'); 4 | 5 | //require('./services/oss'); 6 | //require('./services/sls'); 7 | //require('./services/opensearch'); 8 | //require('./services/batchcompute'); 9 | 10 | //ALY.ECS = ALY.Service.defineService('ecs', ['2014-05-26']); 11 | //ALY.RDS = ALY.Service.defineService('rds', ['2014-08-15']); 12 | //ALY.SLB = ALY.Service.defineService('slb', ['2014-05-15']); 13 | //ALY.CDN = ALY.Service.defineService('cdn', ['2014-11-11']); 14 | //ALY.STS = ALY.Service.defineService('sts', ['2015-04-01']); 15 | 16 | var apis = require('./api_loader'); 17 | 18 | // define services using map 19 | apis.services.forEach(function(identifier) { 20 | var name = apis.serviceName(identifier); 21 | var versions = apis.serviceVersions(identifier); 22 | ALY[name] = ALY.Service.defineService(identifier, versions); 23 | 24 | // load any customizations from lib/services/.js 25 | var svcFile = path.join(__dirname, 'services', identifier + '.js'); 26 | if (fs.existsSync(svcFile)) require('./services/' + identifier); 27 | }); 28 | -------------------------------------------------------------------------------- /lib/services/cms.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var parseURL = require('url').parse; 3 | 4 | ALY.CMS = ALY.Service.defineService('cms', ['2015-10-20'], { 5 | /** 6 | * @api private 7 | */ 8 | initialize: function initialize(options) { 9 | ALY.Service.prototype.initialize.call(this, options); 10 | }, 11 | setupRequestListeners: function setupRequestListeners(request) { 12 | 13 | //request.addListener('build', this.addContentType); 14 | request.addListener('extractError', this.extractError); 15 | request.addListener('extractData', this.extractData); 16 | }, 17 | 18 | 19 | //addContentType: function(req){ 20 | // var httpRequest = req.httpRequest; 21 | // var headers = httpRequest.headers; 22 | // headers['x-acs-version'] = req.service.config.apiVersion; 23 | //}, 24 | 25 | extractData: function extractData(resp) { 26 | 27 | if(process.env.DEBUG == 'aliyun') { 28 | console.log("-------response status-------"); 29 | console.log(resp.httpResponse.statusCode); 30 | 31 | console.log("-------response header-------"); 32 | console.log(resp.httpResponse.headers); 33 | 34 | console.log("-------response body-------"); 35 | console.log(resp.httpResponse.body.toString()); 36 | console.log("-------response end-------"); 37 | } 38 | 39 | 40 | resp.data = JSON.parse(resp.httpResponse.body.toString().trim() || '{}'); 41 | 42 | var result = resp.data; 43 | //delete result['RequestId']; 44 | 45 | //var reqId = resp.httpResponse.headers['request-id']; 46 | 47 | resp.data = { 48 | code: resp.httpResponse.statusCode, 49 | //message: resp.httpResponse.headers.status, 50 | headers: resp.httpResponse.headers 51 | }; 52 | 53 | resp.data.data = result; 54 | }, 55 | 56 | 57 | 58 | extractError: function extractError(resp) { 59 | if(process.env.DEBUG == 'aliyun') { 60 | console.log("-------response status-------"); 61 | console.log(resp.httpResponse.statusCode); 62 | 63 | console.log("-------response header-------"); 64 | console.log(resp.httpResponse.headers); 65 | 66 | console.log("-------response error-------"); 67 | console.log(resp.httpResponse.body.toString()); 68 | console.log("-------response end-------"); 69 | } 70 | 71 | var headers = resp.httpResponse.headers; 72 | 73 | var error = resp.httpResponse.body.toString(); 74 | 75 | try { 76 | error = JSON.parse(error); 77 | } catch (e) { 78 | error = {}; 79 | } 80 | 81 | 82 | resp.error = ALY.util.error(new Error(), { 83 | code: error.Code, 84 | headers: headers 85 | //requestId: headers['request-id'] 86 | }); 87 | } 88 | }); 89 | 90 | module.exports = ALY.CMS; 91 | -------------------------------------------------------------------------------- /lib/signers/batchcompute.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | //var API_VERSION = '2015-11-11'; 4 | //var API_VERSION = '2015-06-30'; 5 | 6 | /** 7 | * @api private 8 | */ 9 | ALY.Signers.BatchCompute = inherit(ALY.Signers.RequestSigner, { 10 | 11 | //entry 12 | addAuthorization: function addAuthorization(credentials, date) { 13 | var headers = this.request.headers; 14 | 15 | //headers['Date'] = ALY.util.date.rfc822(date); 16 | headers['x-acs-date'] = ALY.util.date.rfc822(date); 17 | //headers['Date'] = new Date().toGMTString(); 18 | 19 | 20 | //var bodyStr; 21 | //var body = this.request.body; 22 | //if(body){ 23 | // bodyStr = typeof(body)=='object'? JSON.stringify(body):body; 24 | // headers['Content-MD5'] = ALY.util.crypto.md5(bodyStr,'hex').toUpperCase(); 25 | //} 26 | 27 | headers['x-acs-signature-method'] = 'HMAC-SHA1'; 28 | headers['x-acs-signature-version'] = '1.0'; 29 | //headers['x-acs-version'] = API_VERSION; 30 | headers['x-sdk-client'] = 'node.js/1.0.0'; 31 | headers['Accept'] = 'application/json'; 32 | 33 | var signature = this.sign(credentials.secretAccessKey, this.stringToSign()); 34 | var auth = 'acs ' + credentials.accessKeyId + ':' + signature; 35 | 36 | headers['Authorization'] = auth; 37 | }, 38 | 39 | stringToSign: function stringToSign() { 40 | var r = this.request; 41 | 42 | //fix signature not match in browser 43 | if (r.method !== 'GET' && r.method !== 'HEAD') { 44 | r.headers['Content-Type'] = r.headers['Content-Type'] || 'text/plain;charset=UTF-8'; 45 | } 46 | 47 | var parts = []; 48 | parts.push(r.method); 49 | parts.push(r.headers['Accept'] || ''); 50 | parts.push(r.headers['Content-MD5'] || ''); 51 | parts.push(r.headers['Content-Type'] || ''); 52 | parts.push(r.headers['x-acs-date'] || r.headers['Date'] || ''); 53 | 54 | var headers = this.canonicalizedAmzHeaders(); 55 | if (headers) parts.push(headers); 56 | parts.push(this.canonicalizedResource()); 57 | 58 | return parts.join('\n'); 59 | }, 60 | 61 | canonicalizedAmzHeaders: function canonicalizedAmzHeaders() { 62 | 63 | var acsHeaders = []; 64 | 65 | ALY.util.each(this.request.headers, function (name) { 66 | if (name.match(/^x-acs-/i)) 67 | acsHeaders.push(name); 68 | }); 69 | 70 | acsHeaders.sort(function (a, b) { 71 | return a.toLowerCase() < b.toLowerCase() ? -1 : 1; 72 | }); 73 | 74 | var parts = []; 75 | ALY.util.arrayEach.call(this, acsHeaders, function (name) { 76 | parts.push(name.toLowerCase() + ':' + String(this.request.headers[name])); 77 | }); 78 | 79 | return parts.join('\n'); 80 | 81 | }, 82 | 83 | canonicalizedResource: function canonicalizedResource() { 84 | 85 | var r = this.request; 86 | 87 | var parts = r.path.split('?'); 88 | var path = parts[0]; 89 | var querystring = parts[1]; 90 | 91 | var resource = ''; 92 | 93 | 94 | resource += decodeURIComponent(path); 95 | 96 | 97 | if (querystring) { 98 | 99 | // collect a list of sub resources and query params that need to be signed 100 | var resources = []; 101 | 102 | var arr = querystring.replace(/(^&*)|(&*$)/g, '').split('&'); 103 | 104 | 105 | ALY.util.arrayEach.call(this, arr, function (param) { 106 | var kv = param.split('='); 107 | 108 | var name = kv[0]; 109 | 110 | var value = (kv.length > 1) ? decodeURIComponent(kv[1]) : ''; 111 | /*jshint undef:false */ 112 | 113 | var resource = {name: name}; 114 | if (value !== undefined) { 115 | resource.value = value; 116 | } 117 | resources.push(resource); 118 | 119 | }); 120 | 121 | resources.sort(function (a, b) { 122 | return a.name < b.name ? -1 : 1; 123 | }); 124 | 125 | if (resources.length) { 126 | 127 | querystring = []; 128 | ALY.util.arrayEach(resources, function (resource) { 129 | if (resource.value === undefined) 130 | querystring.push(resource.name); 131 | else { 132 | 133 | if (resource.value != null && resource.value != '') { 134 | querystring.push(resource.name + '=' + resource.value); 135 | } else { 136 | querystring.push(resource.name); 137 | } 138 | } 139 | }); 140 | 141 | resource += '?' + querystring.join('&'); 142 | } 143 | 144 | } 145 | 146 | return resource; 147 | 148 | }, 149 | 150 | sign: function sign(secret, string) { 151 | if (process.env.DEBUG == 'aliyun') { 152 | console.log('----------- sign string start -----------'); 153 | console.log(string); 154 | console.log('----------- sign string end -----------'); 155 | } 156 | return ALY.util.crypto.hmac(secret, string, 'base64', 'sha1'); 157 | } 158 | }); 159 | 160 | module.exports = ALY.Signers.BatchCompute; 161 | -------------------------------------------------------------------------------- /lib/signers/cms.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | function randomNumbers(count) { 5 | var num = ''; 6 | for (var i = 0; i < count; i++) { 7 | num += Math.floor(Math.random() * 10); 8 | } 9 | return num; 10 | } 11 | 12 | /** 13 | * @api private 14 | */ 15 | ALY.Signers.CMS = inherit(ALY.Signers.RequestSigner, { 16 | 17 | addAuthorization: function addAuthorization(credentials, date) { 18 | // if (!this.request.headers['presigned-expires']) { 19 | // this.request.headers['Date'] = ALY.util.date.rfc822(date); 20 | // } 21 | 22 | // if (credentials.sessionToken) { 23 | // // presigned URLs require this header to be lowercased 24 | // this.request.headers['x-amz-security-token'] = credentials.sessionToken; 25 | // } 26 | var date = new Date(); 27 | 28 | var globalQuery = { 29 | 'Format': 'JSON', 30 | 'Version': '2015-10-20', 31 | 'AccessKeyId': credentials.accessKeyId, 32 | 'SignatureMethod': 'HMAC-SHA1', 33 | 'SignatureVersion': '1.0', 34 | 'SignatureNonce': String(date.getTime()) + randomNumbers(4), 35 | 'Timestamp': date.toISOString().replace(/\.\d{3}/, '') 36 | }; 37 | 38 | var parts = []; 39 | Object.keys(globalQuery).forEach(function(key) { 40 | parts.push(key + '=' + encodeURIComponent(globalQuery[key])); 41 | }); 42 | this.request.path += (this.request.path.indexOf('?') == -1? '?' : '&') + parts.join('&'); 43 | 44 | var signature = this.sign(credentials.secretAccessKey, this.stringToSign()); 45 | this.request.path += '&Signature=' + encodeURIComponent(signature); 46 | // var auth = 'OSS ' + credentials.accessKeyId + ':' + signature; 47 | 48 | // this.request.headers['Authorization'] = auth; 49 | }, 50 | 51 | stringToSign: function stringToSign() { 52 | var r = this.request; 53 | 54 | var s = r.method + '&%2F&' + encodeURIComponent(this.canonicalizedQueryString()); 55 | 56 | return s; 57 | }, 58 | 59 | canonicalizedQueryString: function canonicalizedQueryString() { 60 | var that = this; 61 | var r = this.request; 62 | var querystring = r.path.split('?')[1]; 63 | var resource = ''; 64 | if (r.body) { 65 | querystring += '&' + r.body; 66 | } 67 | 68 | if (querystring) { 69 | 70 | // collect a list of sub resources and query params that need to be signed 71 | var resources = []; 72 | 73 | ALY.util.arrayEach.call(this, querystring.split('&'), function (param) { 74 | var pos = param.indexOf('='); 75 | var name = param.slice(0, pos); 76 | var value = param.slice(pos + 1); 77 | 78 | var resource = { name: name }; 79 | if (value !== undefined) { 80 | resource.value = decodeURIComponent(value); 81 | } 82 | 83 | resources.push(resource); 84 | }); 85 | 86 | resources.sort(function (a, b) { return a.name < b.name ? -1 : 1; }); 87 | 88 | if (resources.length) { 89 | 90 | querystring = []; 91 | ALY.util.arrayEach(resources, function (resource) { 92 | if (resource.value === undefined) 93 | querystring.push(that.cmsEscape(resource.name)); 94 | else 95 | querystring.push(that.cmsEscape(resource.name) + '=' + that.cmsEscape(resource.value)); 96 | }); 97 | 98 | resource += querystring.join('&'); 99 | } 100 | } 101 | 102 | return resource; 103 | }, 104 | 105 | cmsEscape: function(clearString) { 106 | // http://v8.googlecode.com/svn/trunk/src/uri.js 107 | return encodeURIComponent(clearString) 108 | .replace(/\!/gi, '%21') 109 | .replace(/\'/gi, '%27') 110 | .replace(/\(/gi, '%28') 111 | .replace(/\)/gi, '%29') 112 | .replace(/\*/gi, '%2A') 113 | }, 114 | 115 | sign: function sign(secret, string) { 116 | if(process.env.DEBUG == 'aliyun') { 117 | console.log('----------- sign string start -----------'); 118 | console.log(string); 119 | console.log('----------- sign string end -----------'); 120 | } 121 | return ALY.util.crypto.hmac(secret + '&', string, 'base64', 'sha1'); 122 | } 123 | }); 124 | 125 | module.exports = ALY.Signers.CMS; -------------------------------------------------------------------------------- /lib/signers/opensearch.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | function randomNumbers(count) { 5 | var num = ''; 6 | for (var i = 0; i < count; i++) { 7 | num += Math.floor(Math.random() * 10); 8 | } 9 | return num; 10 | } 11 | 12 | /** 13 | * @api private 14 | */ 15 | ALY.Signers.OpenSearch = inherit(ALY.Signers.RequestSigner, { 16 | 17 | addAuthorization: function addAuthorization(credentials, date) { 18 | // if (!this.request.headers['presigned-expires']) { 19 | // this.request.headers['Date'] = ALY.util.date.rfc822(date); 20 | // } 21 | 22 | // if (credentials.sessionToken) { 23 | // // presigned URLs require this header to be lowercased 24 | // this.request.headers['x-amz-security-token'] = credentials.sessionToken; 25 | // } 26 | var date = new Date(); 27 | 28 | var globalQuery = { 29 | 'Version': 'v2', 30 | 'AccessKeyId': credentials.accessKeyId, 31 | 'SignatureMethod': 'HMAC-SHA1', 32 | 'SignatureVersion': '1.0', 33 | 'SignatureNonce': String(date.getTime()) + randomNumbers(4), 34 | 'Timestamp': date.toISOString().replace(/\.\d{3}/, '') 35 | }; 36 | 37 | var parts = []; 38 | Object.keys(globalQuery).forEach(function(key) { 39 | parts.push(key + '=' + encodeURIComponent(globalQuery[key])); 40 | }); 41 | this.request.path += (this.request.path.indexOf('?') == -1? '?' : '&') + parts.join('&'); 42 | 43 | var signature = this.sign(credentials.secretAccessKey, this.stringToSign()); 44 | this.request.path += '&Signature=' + encodeURIComponent(signature); 45 | // var auth = 'OSS ' + credentials.accessKeyId + ':' + signature; 46 | 47 | // this.request.headers['Authorization'] = auth; 48 | }, 49 | 50 | stringToSign: function stringToSign() { 51 | var r = this.request; 52 | 53 | var s = r.method + '&%2F&' + encodeURIComponent(this.canonicalizedQueryString()); 54 | 55 | return s; 56 | }, 57 | 58 | canonicalizedQueryString: function canonicalizedQueryString() { 59 | 60 | var r = this.request; 61 | var querystring = r.path.split('?')[1]; 62 | var resource = ''; 63 | if (r.body) { 64 | querystring += '&' + r.body; 65 | } 66 | 67 | if (querystring) { 68 | 69 | // collect a list of sub resources and query params that need to be signed 70 | var resources = []; 71 | 72 | ALY.util.arrayEach.call(this, querystring.split('&'), function (param) { 73 | var pos = param.indexOf('='); 74 | var name = param.slice(0, pos); 75 | var value = param.slice(pos + 1); 76 | 77 | var resource = { name: name }; 78 | if (value !== undefined) { 79 | resource.value = decodeURIComponent(value); 80 | } 81 | 82 | resources.push(resource); 83 | }); 84 | 85 | resources.sort(function (a, b) { return a.name < b.name ? -1 : 1; }); 86 | 87 | if (resources.length) { 88 | 89 | querystring = []; 90 | ALY.util.arrayEach(resources, function (resource) { 91 | if (resource.value === undefined) 92 | querystring.push(ALY.util.opensearchEscape(resource.name)); 93 | else 94 | querystring.push(ALY.util.opensearchEscape(resource.name) + '=' + ALY.util.opensearchEscape(resource.value)); 95 | }); 96 | 97 | resource += querystring.join('&'); 98 | } 99 | } 100 | 101 | return resource; 102 | }, 103 | 104 | sign: function sign(secret, string) { 105 | if(process.env.DEBUG == 'aliyun') { 106 | console.log('----------- sign string start -----------'); 107 | console.log(string); 108 | console.log('----------- sign string end -----------'); 109 | } 110 | return ALY.util.crypto.hmac(secret + '&', string, 'base64', 'sha1'); 111 | } 112 | }); 113 | 114 | module.exports = ALY.Signers.OpenSearch; -------------------------------------------------------------------------------- /lib/signers/ots.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | /** 5 | * @api private 6 | */ 7 | ALY.Signers.OTS = inherit(ALY.Signers.RequestSigner, { 8 | 9 | subResources: { 10 | 'acl': 1, 11 | 'cors': 1, 12 | 'lifecycle': 1, 13 | 'delete': 1, 14 | 'location': 1, 15 | 'logging': 1, 16 | 'notification': 1, 17 | 'partNumber': 1, 18 | 'policy': 1, 19 | 'requestPayment': 1, 20 | 'restore': 1, 21 | 'tagging': 1, 22 | 'torrent': 1, 23 | 'uploadId': 1, 24 | 'uploads': 1, 25 | 'versionId': 1, 26 | 'versioning': 1, 27 | 'versions': 1, 28 | 'website': 1 29 | }, 30 | 31 | // when building the stringToSign, these querystring params should be 32 | // part of the canonical resource string with their NON-encoded values 33 | responseHeaders: { 34 | 'response-content-type': 1, 35 | 'response-content-language': 1, 36 | 'response-expires': 1, 37 | 'response-cache-control': 1, 38 | 'response-content-disposition': 1, 39 | 'response-content-encoding': 1 40 | }, 41 | 42 | addAuthorization: function addAuthorization(credentials, date) { 43 | this.request.headers['x-ots-date'] = ALY.util.date.rfc822(date); 44 | this.request.headers['x-ots-accesskeyid'] = credentials.accessKeyId; 45 | 46 | var signature = this.sign(credentials.secretAccessKey, this.stringToSign()); 47 | 48 | this.request.headers['x-ots-signature'] = signature; 49 | }, 50 | 51 | stringToSign: function stringToSign() { 52 | var r = this.request; 53 | 54 | var parts = []; 55 | 56 | parts.push(r.path); 57 | 58 | parts.push(r.method + '\n'); 59 | 60 | var headers = this.canonicalizedHeaders(); 61 | if (headers) parts.push(headers); 62 | //parts.push(this.canonicalizedResource()); 63 | 64 | return parts.join('\n') + '\n'; 65 | }, 66 | 67 | canonicalizedHeaders: function canonicalizedHeaders() { 68 | 69 | var headers = []; 70 | 71 | ALY.util.each(this.request.headers, function (name) { 72 | if (name.match(/^x-ots-/i)) 73 | headers.push(name); 74 | }); 75 | 76 | headers.sort(function (a, b) { 77 | return a.toLowerCase() < b.toLowerCase() ? -1 : 1; 78 | }); 79 | 80 | var parts = []; 81 | ALY.util.arrayEach.call(this, headers, function (name) { 82 | parts.push(name.toLowerCase() + ':' + String(this.request.headers[name])); 83 | }); 84 | 85 | return parts.join('\n'); 86 | 87 | }, 88 | 89 | canonicalizedResource: function canonicalizedResource() { 90 | 91 | var r = this.request; 92 | 93 | var parts = r.path.split('?'); 94 | var path = parts[0]; 95 | var querystring = parts[1]; 96 | 97 | var resource = ''; 98 | 99 | if (r.virtualHostedBucket) 100 | resource += '/' + r.virtualHostedBucket; 101 | 102 | // OSS 遗留问题,header 中的 Key 不能 url encode 103 | resource += decodeURIComponent(path); 104 | 105 | if (querystring) { 106 | 107 | // collect a list of sub resources and query params that need to be signed 108 | var resources = []; 109 | 110 | ALY.util.arrayEach.call(this, querystring.split('&'), function (param) { 111 | var name = param.split('=')[0]; 112 | var value = param.split('=')[1]; 113 | if (this.subResources[name] || this.responseHeaders[name]) { 114 | var subresource = { name: name }; 115 | if (value !== undefined) { 116 | if (this.subResources[name]) { 117 | subresource.value = value; 118 | } else { 119 | subresource.value = decodeURIComponent(value); 120 | } 121 | } 122 | resources.push(subresource); 123 | } 124 | }); 125 | 126 | resources.sort(function (a, b) { return a.name < b.name ? -1 : 1; }); 127 | 128 | if (resources.length) { 129 | 130 | querystring = []; 131 | ALY.util.arrayEach(resources, function (res) { 132 | if (res.value === undefined) 133 | querystring.push(res.name); 134 | else 135 | querystring.push(res.name + '=' + res.value); 136 | }); 137 | 138 | resource += '?' + querystring.join('&'); 139 | } 140 | 141 | } 142 | 143 | return resource; 144 | 145 | }, 146 | 147 | sign: function sign(secret, string) { 148 | if(process.env.DEBUG == 'aliyun') { 149 | console.log('----------- sign string start -----------'); 150 | console.log(string); 151 | console.log('----------- sign string end -----------'); 152 | } 153 | return ALY.util.crypto.hmac(secret, string, 'base64', 'sha1'); 154 | } 155 | }); 156 | 157 | module.exports = ALY.Signers.OSS; 158 | -------------------------------------------------------------------------------- /lib/signers/pop.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | ALY.Signers.POP = inherit(ALY.Signers.RequestSigner, { 5 | 6 | addAuthorization: function addAuthorization(credentials, date) { 7 | }, 8 | 9 | }); 10 | 11 | module.exports = ALY.Signers.POP; 12 | -------------------------------------------------------------------------------- /lib/signers/pop_json.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | /** 5 | * @api private 6 | */ 7 | ALY.Signers.PopJson = inherit(ALY.Signers.RequestSigner, { 8 | 9 | //entry 10 | addAuthorization: function addAuthorization(credentials, date) { 11 | var headers = this.request.headers; 12 | 13 | headers['x-acs-date'] = ALY.util.date.rfc822(date); 14 | 15 | headers['x-acs-signature-method'] = 'HMAC-SHA1'; 16 | headers['x-acs-signature-version'] = '1.0'; 17 | //headers['x-acs-version'] = API_VERSION; 18 | headers['x-sdk-client'] = 'node.js/1.0.0'; 19 | headers['Accept'] = 'application/json'; 20 | 21 | var signature = this.sign(credentials.secretAccessKey, this.stringToSign()); 22 | 23 | headers['Authorization'] = 'acs ' + credentials.accessKeyId + ':' + signature; 24 | }, 25 | 26 | stringToSign: function stringToSign() { 27 | var r = this.request; 28 | 29 | //fix signature not match in browser 30 | if (r.method !== 'GET' && r.method !== 'HEAD') { 31 | r.headers['Content-Type'] = 'application/json;charset=utf-8'; 32 | } 33 | 34 | var parts = []; 35 | parts.push(r.method); 36 | parts.push(r.headers['Accept'] || ''); 37 | parts.push(r.headers['Content-MD5'] || ''); 38 | parts.push(r.headers['Content-Type'] || ''); 39 | parts.push(r.headers['x-acs-date'] || r.headers['Date'] || ''); 40 | 41 | var headers = this.canonicalizedAcsHeaders(); 42 | if (headers) parts.push(headers); 43 | parts.push(this.canonicalizedResource()); 44 | 45 | return parts.join('\n'); 46 | }, 47 | 48 | canonicalizedAcsHeaders: function canonicalizedAcsHeaders() { 49 | 50 | var acsHeaders = []; 51 | 52 | ALY.util.each(this.request.headers, function (name) { 53 | if (name.match(/^x-acs-/i)) 54 | acsHeaders.push(name); 55 | }); 56 | 57 | acsHeaders.sort(function (a, b) { 58 | return a.toLowerCase() < b.toLowerCase() ? -1 : 1; 59 | }); 60 | 61 | var parts = []; 62 | ALY.util.arrayEach.call(this, acsHeaders, function (name) { 63 | parts.push(name.toLowerCase() + ':' + String(this.request.headers[name])); 64 | }); 65 | 66 | return parts.join('\n'); 67 | 68 | }, 69 | 70 | canonicalizedResource: function canonicalizedResource() { 71 | 72 | var r = this.request; 73 | 74 | var parts = r.path.split('?'); 75 | var path = parts[0]; 76 | var querystring = parts[1]; 77 | 78 | var resource = ''; 79 | 80 | resource += decodeURIComponent(path); 81 | 82 | if (querystring) { 83 | 84 | // collect a list of sub resources and query params that need to be signed 85 | var resources = []; 86 | 87 | var arr = querystring.replace(/(^&*)|(&*$)/g, '').split('&'); 88 | 89 | ALY.util.arrayEach.call(this, arr, function (param) { 90 | var kv = param.split('='); 91 | 92 | var name = kv[0]; 93 | 94 | var value = (kv.length > 1) ? decodeURIComponent(kv[1]) : ''; 95 | /*jshint undef:false */ 96 | 97 | var resource = {name: name}; 98 | if (value !== undefined) { 99 | resource.value = value; 100 | } 101 | resources.push(resource); 102 | 103 | }); 104 | 105 | resources.sort(function (a, b) { 106 | return a.name < b.name ? -1 : 1; 107 | }); 108 | 109 | if (resources.length) { 110 | 111 | querystring = []; 112 | ALY.util.arrayEach(resources, function (resource) { 113 | if (resource.value === undefined) 114 | querystring.push(resource.name); 115 | else { 116 | 117 | if (resource.value !== null && resource.value !== '') { 118 | querystring.push(resource.name + '=' + resource.value); 119 | } else { 120 | querystring.push(resource.name); 121 | } 122 | } 123 | }); 124 | 125 | resource += '?' + querystring.join('&'); 126 | } 127 | 128 | } 129 | 130 | return resource; 131 | 132 | }, 133 | 134 | sign: function sign(secret, string) { 135 | if (process.env.DEBUG === 'aliyun') { 136 | console.log('----------- sign string start -----------'); 137 | console.log(string); 138 | console.log('----------- sign string end -----------'); 139 | } 140 | return ALY.util.crypto.hmac(secret, string, 'base64', 'sha1'); 141 | } 142 | }); 143 | 144 | module.exports = ALY.Signers.PopJson; -------------------------------------------------------------------------------- /lib/signers/request_signer.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | /** 5 | * @api private 6 | */ 7 | ALY.Signers.RequestSigner = inherit({ 8 | constructor: function RequestSigner(request) { 9 | this.request = request; 10 | } 11 | }); 12 | 13 | ALY.Signers.RequestSigner.getVersion = function getVersion(version) { 14 | switch (version) { 15 | case 'oss': return ALY.Signers.OSS; 16 | case 'ots': return ALY.Signers.OTS; 17 | case 'sls': return ALY.Signers.SLS; 18 | case 'top': return ALY.Signers.TOP; 19 | case 'pop': return ALY.Signers.POP; 20 | case 'pop-json': return ALY.Signers.PopJson; 21 | case 'opensearch': return ALY.Signers.OpenSearch; 22 | case 'batchcompute': return ALY.Signers.BatchCompute; 23 | case 'cms': return ALY.Signers.CMS; 24 | } 25 | throw new Error('Unknown signing version ' + version); 26 | }; 27 | 28 | require('./oss'); 29 | require('./ots'); 30 | require('./sls'); 31 | require('./opensearch'); 32 | require('./top'); 33 | require('./pop'); 34 | require('./pop_json'); 35 | require('./batchcompute'); 36 | require('./cms'); -------------------------------------------------------------------------------- /lib/signers/sls.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | /** 4 | * @api private 5 | */ 6 | ALY.Signers.SLS = inherit(ALY.Signers.RequestSigner, { 7 | 8 | 9 | // when building the stringToSign, these querystring params should be 10 | // part of the canonical resource string with their NON-encoded values 11 | responseHeaders: { 12 | 'response-content-type': 1, 13 | 'response-content-language': 1, 14 | 'response-expires': 1, 15 | 'response-cache-control': 1, 16 | 'response-content-disposition': 1, 17 | 'response-content-encoding': 1 18 | }, 19 | 20 | addAuthorization: function addAuthorization(credentials, date) { 21 | this.request.headers['Date'] = ALY.util.date.rfc822(date); 22 | if(credentials.securityToken) 23 | this.request.headers['x-acs-security-token'] = credentials.securityToken; 24 | 25 | var signature = this.sign(credentials.secretAccessKey, this.stringToSign()); 26 | var auth = 'LOG ' + credentials.accessKeyId + ':' + signature; 27 | 28 | this.request.headers['Authorization'] = auth; 29 | }, 30 | 31 | stringToSign: function stringToSign() { 32 | var r = this.request; 33 | 34 | var parts = []; 35 | parts.push(r.method); 36 | parts.push(r.headers['Content-MD5'] || ''); 37 | parts.push(r.headers['Content-Type'] || ''); 38 | 39 | // This is the "Date" header, but we use X-Amz-Date. 40 | // The S3 signing mechanism requires us to pass an empty 41 | // string for this Date header regardless. 42 | // this works: 43 | // getSignedUrl use 'presigned-expires' 44 | // other request use 'Date' 45 | parts.push(r.headers['Date'] || ''); 46 | 47 | var headers = this.canonicalizedAmzHeaders(); 48 | if (headers) parts.push(headers); 49 | parts.push(this.canonicalizedResource()); 50 | 51 | return parts.join('\n'); 52 | 53 | }, 54 | 55 | canonicalizedAmzHeaders: function canonicalizedAmzHeaders() { 56 | 57 | var amzHeaders = []; 58 | 59 | ALY.util.each(this.request.headers, function (name) { 60 | if (name.match(/^x-log-/i) || name=='x-acs-security-token') 61 | amzHeaders.push(name); 62 | }); 63 | 64 | amzHeaders.sort(function (a, b) { 65 | return a.toLowerCase() < b.toLowerCase() ? -1 : 1; 66 | }); 67 | 68 | var parts = []; 69 | ALY.util.arrayEach.call(this, amzHeaders, function (name) { 70 | parts.push(name.toLowerCase() + ':' + String(this.request.headers[name])); 71 | }); 72 | 73 | return parts.join('\n'); 74 | 75 | }, 76 | 77 | canonicalizedResource: function canonicalizedResource() { 78 | 79 | var r = this.request; 80 | 81 | var parts = r.path.split('?'); 82 | var path = parts[0]; 83 | var querystring = parts[1]; 84 | 85 | var resource = ''; 86 | 87 | 88 | resource += decodeURIComponent(path); 89 | 90 | 91 | if (querystring) { 92 | 93 | // collect a list of sub resources and query params that need to be signed 94 | var resources = []; 95 | 96 | var arr = querystring.replace(/(^&*)|(&*$)/g,'').split('&'); 97 | 98 | 99 | ALY.util.arrayEach.call(this, arr, function (param) { 100 | var kv = param.split('='); 101 | 102 | var name = kv[0]; 103 | //修复topic中带有 / 等字符,签名报错 104 | var value = (kv.length>1)? decodeURIComponent(kv[1]):''; 105 | /*jshint undef:false */ 106 | 107 | var resource = { name: name }; 108 | if (value !== undefined) { 109 | resource.value = value; 110 | } 111 | resources.push(resource); 112 | 113 | }); 114 | 115 | resources.sort(function (a, b) { return a.name < b.name ? -1 : 1; }); 116 | 117 | if (resources.length) { 118 | 119 | querystring = []; 120 | ALY.util.arrayEach(resources, function (resource) { 121 | if (resource.value === undefined) 122 | querystring.push(resource.name); 123 | else 124 | querystring.push(resource.name + '=' + resource.value); 125 | }); 126 | 127 | resource += '?' + querystring.join('&'); 128 | } 129 | 130 | } 131 | 132 | return resource; 133 | 134 | }, 135 | 136 | sign: function sign(secret, string) { 137 | if(process.env.DEBUG == 'aliyun') { 138 | console.log('----------- sign string start -----------'); 139 | console.log(string); 140 | console.log('----------- sign string end -----------'); 141 | } 142 | return ALY.util.crypto.hmac(secret, string, 'base64', 'sha1'); 143 | } 144 | }); 145 | 146 | module.exports = ALY.Signers.SLS; 147 | -------------------------------------------------------------------------------- /lib/signers/top.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var inherit = ALY.util.inherit; 3 | 4 | ALY.Signers.TOP = inherit(ALY.Signers.RequestSigner, { 5 | 6 | // sign 已经在 service_interface/top 中实现了 7 | addAuthorization: function addAuthorization(credentials, date) { 8 | 9 | } 10 | 11 | }); 12 | 13 | module.exports = ALY.Signers.TOP; 14 | -------------------------------------------------------------------------------- /lib/xml/builder.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../core'); 2 | var builder = require('xmlbuilder'); 3 | var inherit = ALY.util.inherit; 4 | 5 | /** 6 | * @api private 7 | */ 8 | ALY.XML.Builder = inherit({ 9 | 10 | constructor: function XMLBuilder(root, rules, options) { 11 | this.root = root; 12 | this.rules = rules; 13 | this.xmlns = options.xmlnamespace; 14 | this.timestampFormat = options.timestampFormat; 15 | }, 16 | 17 | toXML: function toXML(params) { 18 | var xml = builder.create(this.root); 19 | if (this.xmlns) xml.att('xmlns', this.xmlns); 20 | this.serializeStructure(this.rules, params, xml); 21 | return xml.root().toString(); 22 | }, 23 | 24 | serializeStructure: function serializeStructure(rules, params, xml) { 25 | ALY.util.each.call(this, rules || {}, function (memberName, memberRules) { 26 | var value = params[memberName]; 27 | if (value !== undefined) { 28 | if (memberRules.attribute) { 29 | xml.att(memberRules.name, value); 30 | } else { 31 | this.serializeMember(memberName, memberRules, value, xml); 32 | } 33 | } 34 | }); 35 | }, 36 | 37 | serializeList: function serializeList(name, rules, list, xml) { 38 | if (rules.flattened) { 39 | ALY.util.arrayEach.call(this, list, function (value) { 40 | this.serializeMember(rules.name || name, rules.members, value, xml); 41 | }); 42 | } else { 43 | xml = xml.ele(rules.name || name); 44 | ALY.util.arrayEach.call(this, list, function (value) { 45 | var memberName = rules.members.name || 'member'; 46 | this.serializeMember(memberName, rules.members, value, xml); 47 | }); 48 | } 49 | }, 50 | 51 | serializeMember: function serializeMember(memberName, rules, params, xml) { 52 | if (params === null || params === undefined) return; 53 | 54 | var name = memberName; 55 | if (rules.type === 'structure') { 56 | xml = xml.ele(name); 57 | this.serializeStructure(rules.members, params, xml); 58 | } else if (rules.type === 'list') { 59 | this.serializeList(name, rules, params, xml); 60 | } else if (rules.type === 'timestamp') { 61 | var timestampFormat = rules.format || this.timestampFormat; 62 | var date = ALY.util.date.format(params, timestampFormat); 63 | xml = xml.ele(name, String(date)); 64 | } else { 65 | xml = xml.ele(name, String(params)); 66 | } 67 | this.applyNamespaces(xml, rules); 68 | }, 69 | 70 | applyNamespaces: function applyNamespaces(xml, rules) { 71 | if (rules.xmlns) { 72 | var attr = 'xmlns'; 73 | if (rules.xmlns.prefix) attr += ':' + rules.xmlns.prefix; 74 | xml.att(attr, rules.xmlns.uri); 75 | } 76 | } 77 | 78 | 79 | }); 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aliyun-sdk", 3 | "description": "Aliyun SDK for JavaScript", 4 | "version": "1.12.10", 5 | "author": { 6 | "name": "chylvina", 7 | "email": "chylvina@gmail.com" 8 | }, 9 | "homepage": "https://github.com/aliyun-UED/aliyun-sdk-js.git", 10 | "contributors": [], 11 | "devDependencies": { 12 | "coffee-script": "1.6.3", 13 | "coffeeify": "", 14 | "cucumber": "^5.1.0", 15 | "jasmine-node": "^3.0.0", 16 | "jshint": "^2.10.2", 17 | "mocha": "^6.2.0", 18 | "repl.history": "", 19 | "semver": "^6.3.0", 20 | "should": "~4.6.3" 21 | }, 22 | "dependencies": { 23 | "node_memcached": "1.1.3", 24 | "pomelo-protobuf": "^0.4.0", 25 | "protobufjs": ">=5.0.3", 26 | "xml2js": "0.4.4", 27 | "xmlbuilder": "^13.0.2" 28 | }, 29 | "main": "index.js", 30 | "browser": { 31 | "./lib/util.js": "./lib/util-browser.js", 32 | "cdn-2014-11-11.json": "./apis/cdn-2014-11-11.json", 33 | "ecs-2014-05-26.json": "./apis/ecs-2014-05-26.json", 34 | "opensearch-2015-01-01.json": "./apis/opensearch-2015-01-01.json", 35 | "batchcompute-2015-06-30.json": "./apis/batchcompute-2015-06-30.json", 36 | "batchcompute-2015-11-11.json": "./apis/batchcompute-2015-11-11.json", 37 | "oss-2013-10-15.json": "./apis/oss-2013-10-15.json", 38 | "rds-2014-08-15.json": "./apis/rds-2014-08-15.json", 39 | "slb-2014-05-15.json": "./apis/slb-2014-05-15.json", 40 | "sls-2014-11-18.json": "./apis/sls-2014-11-18.json", 41 | "sts-2015-04-01.json": "./apis/sts-2015-04-01.json", 42 | "ram-2015-05-01.json": "./apis/ram-2015-05-01.json" 43 | }, 44 | "directories": { 45 | "lib": "lib" 46 | }, 47 | "engines": { 48 | "node": ">= 0.6.0" 49 | }, 50 | "repository": { 51 | "type": "git", 52 | "url": "git@github.com:aliyun-UED/aliyun-sdk-js.git" 53 | }, 54 | "bugs": { 55 | "url": "https://github.com/aliyun-UED/aliyun-sdk-js/issues", 56 | "mail": "" 57 | }, 58 | "keywords": [], 59 | "scripts": { 60 | "test": "mocha test" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/CreateJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | 7 | var jobDesc = { 8 | "JobName": "TestScene", 9 | "JobTag": "JobTag", 10 | "Priority": 0, 11 | "TaskDag": { 12 | "TaskDescMap": { 13 | "CountTask": { 14 | "InstanceCount": 1, 15 | "PackageUri": "oss://my-bucket/diku_simple_test/program_package.tar.gz", 16 | "ProgramName": "count_all_num.py", 17 | "ResourceDescription": { 18 | "Cpu": 1200, 19 | "Memory": 16000 20 | }, 21 | "StderrRedirectPath": "oss://my-bucket/diku_simple_test/log", 22 | "StdoutRedirectPath": "oss://my-bucket/diku_simple_test/log", 23 | "ImageId": "img-00000000558D1D5A000079FA0000001F", 24 | "EnvironmentVariables": {}, 25 | "Timeout": 21600, 26 | "ProgramType": "python" 27 | } 28 | }, 29 | "Dependencies": { 30 | "CountTask": [] 31 | } 32 | } 33 | }; 34 | 35 | batchcompute.createJob(jobDesc,function(err, data) { 36 | if(err) { 37 | console.log(err); 38 | return; 39 | } 40 | console.log(data); 41 | }); 42 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/DeleteJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.deleteJob({jobId:jobId},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/GetJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.getJob({ 9 | jobId:jobId 10 | },function(err, data) { 11 | if(err) { 12 | console.log(err); 13 | return; 14 | } 15 | console.log(data); 16 | }); 17 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/GetJobDescription.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.getJobDescription({ 9 | jobId:jobId 10 | 11 | },function(err, data) { 12 | if(err) { 13 | console.log(err); 14 | return; 15 | } 16 | console.log(data); 17 | }); 18 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/ListImages.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | batchcompute.listImages(function(err, data) { 7 | if(err) { 8 | console.log(err); 9 | return; 10 | } 11 | console.log(data); 12 | }); 13 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/ListJobs.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | batchcompute.listJobs(function(err, data) { 7 | if(err) { 8 | console.log(err); 9 | return; 10 | } 11 | console.log(data); 12 | }); 13 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/ListTasks.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.listTasks({jobId:jobId},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/StartJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.startJob({jobId:jobId},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/StopJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.stopJob({jobId:jobId},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/UpdateJobPriority.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.updateJobPriority({jobId:jobId,priority:10},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-06-30/batchcompute.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../../'); 2 | 3 | var batchCompute = new ALY.BatchCompute({ 4 | "accessKeyId": "在阿里云官网申请的 accessKeyId", 5 | "secretAccessKey": "在阿里云官网申请的 secretAccessKey", 6 | 7 | 8 | endpoint: 'http://batchcompute.cn-qingdao.aliyuncs.com', 9 | 10 | // 这是 batchcompute sdk 的 api 版本 11 | apiVersion: '2015-06-30' 12 | 13 | //以下是可选配置 14 | //,httpOptions: { 15 | // timeout: 1000 //1sec, 默认没有timeout 16 | //} 17 | }); 18 | 19 | module.exports = batchCompute; 20 | 21 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/ChangeClusterDesiredVMCount.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var clusterId = 'cls-5F780000069A'; 7 | 8 | 9 | batchcompute.changeClusterDesiredVMCount({ClusterId:clusterId, Groups:{"group1":{DesiredVMCount:3}}},function(err, data) { 10 | console.log(err || data); 11 | }); 12 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/ChangeJobPriority.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.changeJobPriority({JobId:jobId,Priority:10},function(err, data) { 9 | 10 | console.log(err || data); 11 | }); 12 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/CreateCluster.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | var clusterDesc = { 4 | "Name": "node-sdk-test-cluster", 5 | "Description": "node-sdk test", 6 | "ImageId": "", //ecs image id 7 | "Groups": { 8 | "group1": { 9 | "DesiredVMCount": 3, 10 | "InstanceType": 'ecs.s3.large', 11 | "ResourceType": "OnDemand" 12 | } 13 | } 14 | }; 15 | 16 | batchcompute.createCluster(clusterDesc, function (err, result) { 17 | 18 | console.log(err || result); 19 | 20 | /** 21 | result.data: 22 | { 23 | "Id":"cls-6kilcg94rdtk004d" 24 | } 25 | */ 26 | }); 27 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/CreateJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | var jobDesc = { 4 | "Name": "node-sdk-test-job", 5 | "Description": "test job", 6 | "Priority": 0, 7 | "JobFailOnInstanceFail": true, 8 | "Type": "DAG", 9 | "DAG": { 10 | "Tasks": { 11 | "CountTask": { 12 | "Parameters": { 13 | "Command": { 14 | "CommandLine": "python count_all_num.py", 15 | "PackagePath": "oss://my-bucket/diku_simple_test/program_package.tar.gz", 16 | "EnvVars":{} 17 | }, 18 | //"InputMappingConfig": { 19 | // "Locale": "GBK", 20 | // "Lock": false 21 | //}, 22 | "StdoutRedirectPath": "oss://my-bucket/diku_simple_test/log/", 23 | "StderrRedirectPath": "oss://my-bucket/diku_simple_test/log/" 24 | }, 25 | //"InputMapping": { 26 | // "oss path": "guest os path" 27 | //}, 28 | //"OutputMapping": { 29 | // "guest os path": "oss path" 30 | //}, 31 | //"LogMapping": { 32 | // "guest os path": "oss path" 33 | //}, 34 | "Timeout": 21600, 35 | "InstanceCount": 1, 36 | "MaxRetryCount": 0, 37 | "ClusterId": "cls-6kilcg94rdtk004d" //没有请先创建 Cluster, 或者可以直接用autoCluster 38 | //"AutoCluster": { 39 | // "InstanceType": 'ecs.s3.large', 40 | // "ResourceType": "OnDemand", 41 | // "ECSImageId": "m-xxxx" //ecs image id 42 | //} 43 | } 44 | }, 45 | "Dependencies": { 46 | "CountTask": [] 47 | } 48 | } 49 | }; 50 | 51 | 52 | batchcompute.createJob(jobDesc, function (err, result) { 53 | 54 | console.log(err || result); 55 | 56 | /** 57 | result.data: 58 | { 59 | "Id":"job-00000000564ECC3F0000A25D0000006A" 60 | } 61 | */ 62 | }); 63 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/DeleteCluster.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var clusterId = 'cls-6kilcg94rdtk004d'; 7 | 8 | batchcompute.deleteCluster({ClusterId:clusterId},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/DeleteJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.deleteJob({JobId:jobId},function(err, data) { 9 | if(err) { 10 | console.log(err); 11 | return; 12 | } 13 | console.log(data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/GetCluster.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | 4 | batchcompute.getCluster({ClusterId: "cls-6kilcg94rdtk004d"}, function(err, result) { 5 | console.log(err || result); 6 | }); 7 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/GetInstance.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | var opt = { 4 | JobId: 'job-00000000559638EC00005F780000069A', 5 | TaskName: 'TaskName1', 6 | InstanceId: '0' 7 | }; 8 | 9 | batchcompute.getInstance(opt, function (err, result) { 10 | 11 | console.log(err || result); 12 | 13 | /** 14 | result.data: 15 | { EndTime: '', 16 | InstanceId: 0, 17 | Progress: 0, 18 | Result: { Detail: '', ErrorCode: '', ErrorMessage: '', ExitCode: 0 }, 19 | RetryCount: 0, 20 | StartTime: '', 21 | State: 'Waiting', 22 | StderrRedirectPath: 'oss://my-bucket/diku_simple_test/log/0.stderr', 23 | StdoutRedirectPath: 'oss://my-bucket/diku_simple_test/log/0.stdout' } 24 | */ 25 | }); 26 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/GetJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var opt = { 7 | JobId:'job-00000000559638EC00005F780000069A' 8 | }; 9 | batchcompute.getJob(opt, function(err, result) { 10 | console.log(err || result); 11 | }); 12 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/GetJobDescription.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | 7 | var opt = { 8 | JobId:'job-00000000559638EC00005F780000069A' 9 | }; 10 | 11 | batchcompute.getJobDescription(opt,function(err, result) { 12 | console.log(err || result); 13 | }); 14 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/GetTask.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | 7 | var opt = { 8 | JobId: 'job-00000000559638EC00005F780000069A', 9 | TaskName: 'TaskName1' 10 | }; 11 | 12 | batchcompute.getTask(opt, function (err, result) { 13 | 14 | console.log(err || result); 15 | 16 | /** 17 | result.data: 18 | { EndTime: '', 19 | InstanceMetrics: 20 | { FailedCount: 0, 21 | FinishedCount: 0, 22 | RunningCount: 0, 23 | StoppedCount: 0, 24 | WaitingCount: 1 }, 25 | StartTime: '', 26 | State: 'Waiting', 27 | TaskName: 'CountTask' } 28 | */ 29 | }); 30 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/ListClusters.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var opt= { 7 | Marker: "", //本页起始资源标识符。默认为空字符串。 8 | MaxItemCount: 100 //实际返回最大资源数量。默认值50,最大值100。 9 | }; 10 | 11 | batchcompute.listClusters(opt, function(err, result) { 12 | 13 | console.log(err || result); 14 | 15 | /** 16 | result.data: 17 | [ { EndTime: '', 18 | InstanceMetrics: 19 | { FailedCount: 0, 20 | FinishedCount: 0, 21 | RunningCount: 0, 22 | StoppedCount: 0, 23 | WaitingCount: 1 }, 24 | StartTime: '', 25 | State: 'Waiting', 26 | TaskName: 'CountTask' } ] 27 | */ 28 | }); 29 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/ListInstances.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | 7 | var opt= { 8 | JobId:'job-00000000559638EC00005F780000069A', 9 | TaskName: 'taskName1', 10 | Marker: "", //本页起始资源标识符。默认为空字符串。 11 | MaxItemCount: 100 //实际返回最大资源数量。默认值50,最大值100。 12 | }; 13 | 14 | 15 | batchcompute.listInstances(opt,function(err, result) { 16 | 17 | console.log(err || result); 18 | 19 | /** 20 | result.data: 21 | [ { EndTime: '', 22 | InstanceId: 0, 23 | Progress: 0, 24 | Result: { Detail: '', ErrorCode: '', ErrorMessage: '', ExitCode: 0 }, 25 | RetryCount: 0, 26 | StartTime: '', 27 | State: 'Waiting', 28 | StderrRedirectPath: 'oss://my-bucket/diku_simple_test/log/0.stderr', 29 | StdoutRedirectPath: 'oss://my-bucket/diku_simple_test/log/0.stdout' } ] 30 | */ 31 | }); 32 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/ListJobs.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | 7 | var opt= { 8 | Marker: "", //本页起始资源标识符。默认为空字符串。 9 | MaxItemCount: 100 //实际返回最大资源数量。默认值50,最大值100。 10 | }; 11 | 12 | batchcompute.listJobs(opt,function(err, result) { 13 | 14 | console.log(err || result); 15 | 16 | /** 17 | result.data: 18 | [ { EndTime: '', 19 | InstanceMetrics: 20 | { FailedCount: 0, 21 | FinishedCount: 0, 22 | RunningCount: 0, 23 | StoppedCount: 0, 24 | WaitingCount: 1 }, 25 | StartTime: '', 26 | State: 'Waiting', 27 | TaskName: 'CountTask' } ] 28 | */ 29 | }); 30 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/ListTasks.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | 7 | var opt= { 8 | JobId:'job-00000000559638EC00005F780000069A', 9 | Marker: "", //本页起始资源标识符。默认为空字符串。 10 | MaxItemCount: 100 //实际返回最大资源数量。默认值50,最大值100。 11 | }; 12 | 13 | 14 | batchcompute.listTasks(opt,function(err, result) { 15 | 16 | console.log(err || result); 17 | 18 | /** 19 | result.data: 20 | [ { EndTime: '', 21 | InstanceMetrics: 22 | { FailedCount: 0, 23 | FinishedCount: 0, 24 | RunningCount: 0, 25 | StoppedCount: 0, 26 | WaitingCount: 1 }, 27 | StartTime: '', 28 | State: 'Waiting', 29 | TaskName: 'CountTask' } ] 30 | */ 31 | }); 32 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/StartJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.startJob({JobId:jobId},function(err, data) { 9 | console.log(err || data); 10 | }); 11 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/StopJob.js: -------------------------------------------------------------------------------- 1 | var batchcompute = require('./batchcompute'); 2 | 3 | /** 4 | * 5 | */ 6 | var jobId = 'job-00000000559638EC00005F780000069A'; 7 | 8 | batchcompute.stopJob({JobId:jobId},function(err, data) { 9 | console.log(err || data); 10 | }); 11 | -------------------------------------------------------------------------------- /samples/batchcompute/2015-11-11/batchcompute.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../../'); 2 | 3 | var batchCompute = new ALY.BatchCompute({ 4 | "accessKeyId": "在阿里云官网申请的 accessKeyId", 5 | "secretAccessKey": "在阿里云官网申请的 secretAccessKey", 6 | 7 | 8 | endpoint: 'http://batchcompute.cn-qingdao.aliyuncs.com', 9 | 10 | // 这是batchcompute sdk 目前支持最新的 api 版本 11 | apiVersion: '2015-11-11' 12 | 13 | //以下是可选配置 14 | //,httpOptions: { 15 | // timeout: 1000 //1sec, 默认没有timeout 16 | //} 17 | }); 18 | 19 | module.exports = batchCompute; 20 | 21 | -------------------------------------------------------------------------------- /samples/browser/browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 57 | 58 | -------------------------------------------------------------------------------- /samples/cdn/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var cdn = new ALY.CDN({ 4 | accessKeyId: "在阿里云OSS申请的 accessKeyId", 5 | secretAccessKey: "在阿里云OSS申请的 secretAccessKey", 6 | endpoint: 'https://cdn.aliyuncs.com', 7 | apiVersion: '2014-11-11' 8 | } 9 | ); 10 | 11 | cdn.refreshObjectCaches({ 12 | ObjectType: 'File', 13 | ObjectPath: 'http://cdn.test.com/test.jpg' 14 | }, function(err, res) { 15 | console.log(err, res); 16 | }); 17 | 18 | cdn.describeCdnMonitorData({ 19 | DomainName: "cdn.test.com", 20 | // 注意, 之前是传入 Date 对象, 现在改为一个 ISO 时间字符串, 而且时间精确到秒而不是毫秒 21 | StartTime: "2014-12-10T00:00:00Z", 22 | EndTime: "2014-13-10T00:10:00Z" 23 | }, function(err, res) { 24 | console.log(err, res); 25 | }); -------------------------------------------------------------------------------- /samples/cms/BatchQueryMetric.js: -------------------------------------------------------------------------------- 1 | var client= require('./cms'); 2 | 3 | var opt= { 4 | Dimensions: '', 5 | Project: "", 6 | Metric: "", 7 | Period:"", 8 | StartTime: "", 9 | EndTime: "" 10 | }; 11 | 12 | client.batchQueryMetric(opt,function(err,result){ 13 | console.log(err, result); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/cms/DescribeMetricDatum.js: -------------------------------------------------------------------------------- 1 | var client= require('./cms'); 2 | 3 | var opt= { 4 | Dimensions: "", 5 | Project: "", 6 | Metric: "", 7 | Period:"", 8 | StartTime: "", 9 | EndTime: "", 10 | Length: "", 11 | Page: "" 12 | }; 13 | 14 | client.describeMetricDatum(opt,function(err,result){ 15 | console.log(err, result); 16 | }); 17 | -------------------------------------------------------------------------------- /samples/cms/GetMetricStatistics.js: -------------------------------------------------------------------------------- 1 | var client= require('./cms'); 2 | 3 | var opt= { 4 | Dimensions: '', 5 | StartTime: "", 6 | MetricName: "", 7 | EndTime: "", 8 | Namespace: "", 9 | Interval: "", 10 | NextToken: "", 11 | Length: "" 12 | }; 13 | 14 | client.getMetricStatistics(opt, function(err,result){ 15 | console.log(err,result); 16 | }); 17 | -------------------------------------------------------------------------------- /samples/cms/QueryMetric.js: -------------------------------------------------------------------------------- 1 | var client= require('./cms'); 2 | 3 | var opt= { 4 | Project:"", 5 | Metric:"", 6 | Period:"", 7 | Dimensions: "", 8 | StartTime:"", 9 | EndTime: "", 10 | Page: "", 11 | Length: '' 12 | }; 13 | 14 | 15 | client.queryMetric(opt,function(err,result){ 16 | console.log(err, result); 17 | }); 18 | -------------------------------------------------------------------------------- /samples/cms/cms.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../../'); 2 | 3 | var cms = new ALY.CMS({ 4 | "accessKeyId": "在阿里云官网申请的 accessKeyId", 5 | "secretAccessKey": "在阿里云官网申请的 secretAccessKey", 6 | 7 | 8 | endpoint: 'http://metrics.aliyuncs.com', 9 | apiVersion: '2015-10-20' 10 | }); 11 | 12 | module.exports = cms; -------------------------------------------------------------------------------- /samples/dayu/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var dayu = new ALY.DAYU({ 4 | accessKeyId: "在阿里云申请的 accessKeyId", 5 | secretAccessKey: "在阿里云申请的 secretAccessKey", 6 | endpoint: 'http://gw.api.taobao.com', 7 | apiVersion: '2015-12-16' 8 | } 9 | ); 10 | 11 | dayu.sendSMS({ 12 | sms_free_sign_name: "xxxx", 13 | rec_num: "12345678901", 14 | sms_template_code: "SMS_xxxxxx", 15 | sms_param: { 16 | code: "xxx", 17 | date: "xxx" 18 | } 19 | }, function(err, res) { 20 | console.log(err, res); 21 | }); 22 | -------------------------------------------------------------------------------- /samples/dns/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var cdn = new ALY.DNS({ 4 | accessKeyId: "在阿里云OSS申请的 accessKeyId", 5 | secretAccessKey: "在阿里云OSS申请的 secretAccessKey", 6 | endpoint: 'http://alidns.aliyuncs.com', 7 | apiVersion: '2015-01-09' 8 | } 9 | ); 10 | 11 | cdn.describeDomains({}, function(err, res) { 12 | console.log(err, res); 13 | }); -------------------------------------------------------------------------------- /samples/ecs/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var ecs = new ALY.ECS({ 4 | accessKeyId: "在阿里云ECS申请的 accessKeyId", 5 | secretAccessKey: "在阿里云ECS申请的 secretAccessKey", 6 | endpoint: 'https://ecs.aliyuncs.com', 7 | apiVersion: '2014-05-26' 8 | } 9 | ); 10 | 11 | ecs.describeDisks({ 12 | RegionId: 'cn-beijing' 13 | }, function(err, res) { 14 | console.log(err, res); 15 | }); 16 | 17 | ecs.describeInstanceTypes({ 18 | }, function(err, res) { 19 | console.log(err, res); 20 | }); 21 | 22 | ecs.describeZones({ 23 | RegionId: 'cn-beijing' 24 | }, function(err, res) { 25 | console.log(err, res); 26 | }); -------------------------------------------------------------------------------- /samples/ess/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var ess = new ALY.ESS({ 4 | accessKeyId: "在阿里云ECS申请的 accessKeyId", 5 | secretAccessKey: "在阿里云ECS申请的 secretAccessKey", 6 | endpoint: 'https://ess.aliyuncs.com', 7 | apiVersion: '2014-08-28', 8 | } 9 | ); 10 | 11 | ess.describeScalingGroups({ 12 | RegionId: 'cn-beijing' 13 | }, function(err, res) { 14 | console.log(err, res); 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /samples/green/AsyncImageDetectionResultSample.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hyliu on 16/12/16. 3 | */ 4 | 5 | var ALY = require("aliyun-sdk") 6 | 7 | var green = new ALY.GREEN({ 8 | accessKeyId: '你的accessKeyId', 9 | secretAccessKey: '你的accessKeySecret', 10 | endpoint: 'http://green.cn-hangzhou.aliyuncs.com', 11 | apiVersion: '2016-12-16', 12 | }) 13 | 14 | var taskIds = ['55b1a3fe-7671-43a8-84b9-c7aa3438bff9-1486545144026']; 15 | 16 | 17 | green.imageResults({ 18 | TaskId: JSON.stringify(taskIds) 19 | }, function(err, data){ 20 | if(err) { 21 | console.log('error:', err); 22 | return; 23 | } 24 | console.log('success:', JSON.stringify(data)); 25 | 26 | //判断是否成功 27 | if(data.Code === 'Success') { 28 | 29 | var imageDetectResults = data.ImageDetectResults.ImageDetectResult; 30 | 31 | for( var i = 0;i 0) { 47 | var imageResult = data.ImageResults.ImageResult[0]; 48 | var imageUrl = imageResult.ImageName; 49 | var taskId = imageResult.TaskId; 50 | 51 | //获取结果 52 | var pornResult = imageResult.PornResult; 53 | var ocrResult = imageResult.OcrResult; 54 | var illegalResult = imageResult.IllegalResult; 55 | var sensitiveFaceResult = imageResult.SensitiveFaceResult; 56 | var adResult = imageResult.AdResult; 57 | var qrcodeResult = imageResult.QrcodeResult; 58 | 59 | /** 60 | * 黄图检测结果 61 | */ 62 | if(contains(scenes, "porn")){ 63 | /** 64 | * 黄图分值, 0-100 65 | */ 66 | console.log(pornResult.Rate); 67 | /** 68 | * 绿网给出的建议值, 0表示正常,1表示色情,2表示需要review 69 | */ 70 | console.log(pornResult.Label); 71 | } 72 | 73 | /** 74 | * ocr识别结果 75 | */ 76 | if(contains(scenes, "ocr")){ 77 | console.log(ocrResult.Text); 78 | } 79 | 80 | /** 81 | * 暴恐敏感识别结果 82 | */ 83 | if(contains(scenes, "illegal")){ 84 | /** 85 | * 分值, 0-100 86 | */ 87 | console.log(illegalResult.Rate); 88 | /** 89 | * 绿网给出的建议值, 0表示正常,1表示命中暴恐渉政,2表示需要review 90 | */ 91 | console.log(illegalResult.Label); 92 | } 93 | 94 | /** 95 | * 牛皮藓广告识别结果 96 | */ 97 | if(contains(scenes, "ad")){ 98 | /** 99 | * 分值, 0-100 100 | */ 101 | console.log(adResult.Rate); 102 | /** 103 | * 绿网给出的建议值, 0表示正常,1表示广告,2表示需要review 104 | */ 105 | console.log(adResult.Label); 106 | /** 107 | * 风险: 0:正常, 1:图片带文字, 2:二维码, 3: 图片有文字且有二维码 108 | */ 109 | console.log(adResult.RiskType); 110 | 111 | //如果是二维码, 可获取到二维码内容 112 | console.log(adResult.RiskDetails); 113 | } 114 | 115 | /** 116 | * 二维码识别结果 117 | */ 118 | if(contains(scenes, "qrcode")){ 119 | console.log(qrcodeResult.QrcodeList); 120 | } 121 | 122 | /** 123 | * 人脸识别结果 124 | */ 125 | if(contains(scenes, "sensitiveFace")){ 126 | console.log(sensitiveFaceResult.Items.ImageSensitiveFaceHitItem); 127 | } 128 | }else{ 129 | //出错情况下打印出结果 130 | console.log(data.Code); 131 | console.log(data.Msg); 132 | } 133 | 134 | } 135 | ); 136 | 137 | 138 | function contains(a, obj) { 139 | var i = a.length; 140 | while (i--) { 141 | if (a[i] === obj) { 142 | return true; 143 | } 144 | } 145 | return false; 146 | } -------------------------------------------------------------------------------- /samples/green/TexrtAntispamDetectionSample.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by hyliu on 16/12/16. 3 | */ 4 | 5 | var ALY = require("aliyun-sdk") 6 | 7 | // 构建一个 Aliyun Client, 用于发起请求 8 | // 构建Aliyun Client时需要设置AccessKeyId和AccessKeySevcret 9 | var green = new ALY.GREEN({ 10 | accessKeyId: '你的accessKeyId', 11 | secretAccessKey: '你的accessKeySecret', 12 | endpoint: 'http://green.cn-hangzhou.aliyuncs.com', 13 | apiVersion: '2016-12-16' 14 | }); 15 | 16 | var dataItem1 = { 17 | 'content':'你好', //要检测的文本内容, 必填 18 | 'dataId': 'BB85A15B-BF61-4023-80BE-1ACD1267D5ED', //数据id,请生成一个唯一数据id, 比如用uuid生成, 可选,不填服务端自动生成 19 | 'postId': '1234567890', //发贴人的id, 可选, postId与postTime需同时填或者不填 20 | 'postTime':Date.now() //发帖时间, 可选, postId与postTime需同时填后者不填 21 | }; 22 | var dataItem2 = { 23 | 'content':'我好', //要检测的文本内容, 必填 24 | 'dataId': '485F5029-A0EE-4694-97F3-3596B14EF5CA', //数据id,请生成一个唯一数据id, 比如用uuid生成, 可选,不填服务端自动生成 25 | 'postId': '1234567890',//发贴人的id, 可选, postId与postTime需同时填或者不填 26 | 'postTime':Date.now() //发帖时间, 可选, postId与postTime需同时填后者不填 27 | }; 28 | var dataItems = [dataItem1, dataItem2]; 29 | 30 | green.textAntispamDetection({ 31 | DataItems:JSON.stringify(dataItems) 32 | }, 33 | function(err, data){ 34 | if(err) { 35 | console.log('error:', err); 36 | return; 37 | } 38 | console.log('success:', JSON.stringify(data)); 39 | 40 | //判断是否成功 41 | if(data.Code === 'Success') { 42 | var textAntispamResults = data.TextAntispamResults.TextAntispamResult; 43 | for( var i = 0;i 0) return; // complete only when all parts uploaded 64 | 65 | var doneParams = { 66 | Bucket: bucket, 67 | Key: fileKey, 68 | CompleteMultipartUpload: multipartMap, 69 | UploadId: multipart.UploadId 70 | }; 71 | 72 | console.log("Completing upload..."); 73 | completeMultipartUpload(oss, doneParams); 74 | }); 75 | } 76 | 77 | // Multipart 78 | console.log("Creating multipart upload for:", fileKey); 79 | oss.createMultipartUpload({ 80 | ACL: 'public-read', 81 | Bucket: bucket, 82 | Key: fileKey, 83 | ContentType: 'audio/mpeg', 84 | ContentDisposition: '' 85 | //CacheControl: '', 86 | //ContentEncoding: '', 87 | //Expires: '', 88 | //ServerSideEncryption: '' 89 | }, function (mpErr, multipart) { 90 | if (mpErr) { 91 | console.log('Error!', mpErr); 92 | return; 93 | } 94 | console.log("Got upload ID", multipart.UploadId); 95 | 96 | // Grab each partSize chunk and upload it as a part 97 | for (var rangeStart = 0; rangeStart < buffer.length; rangeStart += partSize) { 98 | partNum++; 99 | var end = Math.min(rangeStart + partSize, buffer.length), 100 | partParams = { 101 | Body: buffer.slice(rangeStart, end), 102 | Bucket: bucket, 103 | Key: fileKey, 104 | PartNumber: String(partNum), 105 | UploadId: multipart.UploadId 106 | }; 107 | 108 | // Send a single part 109 | console.log('Uploading part: #', partParams.PartNumber, ', Range start:', rangeStart); 110 | uploadPart(oss, multipart, partParams); 111 | } 112 | }); -------------------------------------------------------------------------------- /samples/oss/not-ready/DeleteBucketLogging.js: -------------------------------------------------------------------------------- 1 | var oss = require('./oss'); 2 | 3 | // ------------------------------- 4 | // 5.3.2 Delete Bucket Logging 5 | // ------------------------------- 6 | 7 | // todo: not ready 8 | 9 | oss.deleteBucketLogging({ 10 | Bucket: 'chylvina' 11 | }, 12 | function (err, data) { 13 | if (err) { 14 | console.log('error:', err); 15 | return; 16 | } 17 | 18 | console.log('success:', data); 19 | }); -------------------------------------------------------------------------------- /samples/oss/not-ready/DeleteBucketWebsite.js: -------------------------------------------------------------------------------- 1 | var oss = require('./oss'); 2 | 3 | // ------------------------------- 4 | // 5.3.3 Delete Bucket Website 5 | // ------------------------------- 6 | 7 | // todo: not ready 8 | 9 | oss.deleteBucketWebsite({ 10 | Bucket: 'chylvina' 11 | }, 12 | function (err, data) { 13 | if (err) { 14 | console.log('error:', err); 15 | return; 16 | } 17 | 18 | console.log('success:', data); 19 | }); -------------------------------------------------------------------------------- /samples/oss/not-ready/GetBucketLogging.js: -------------------------------------------------------------------------------- 1 | var oss = require('./oss'); 2 | 3 | // ------------------------------- 4 | // 5.3.7 Get Bucket Logging 5 | // ------------------------------- 6 | 7 | // todo: not ready 8 | 9 | oss.getBucketLogging({ 10 | Bucket: 'chylvina' 11 | }, 12 | function (err, data) { 13 | if (err) { 14 | console.log('error:', err); 15 | return; 16 | } 17 | 18 | console.log('success:', data); 19 | }); -------------------------------------------------------------------------------- /samples/oss/not-ready/GetBucketWebsite.js: -------------------------------------------------------------------------------- 1 | var oss = require('./oss'); 2 | 3 | // ------------------------------- 4 | // 5.3.8 Get Bucket Website 5 | // ------------------------------- 6 | 7 | // todo: not ready 8 | 9 | oss.getBucketWebsite({ 10 | Bucket: 'chylvina' 11 | }, 12 | function (err, data) { 13 | if (err) { 14 | console.log('error:', err); 15 | return; 16 | } 17 | 18 | console.log('success:', data); 19 | }); -------------------------------------------------------------------------------- /samples/oss/not-ready/PutBucketLogging.js: -------------------------------------------------------------------------------- 1 | var oss = require('./oss'); 2 | 3 | // ------------------------------- 4 | // 5.3.10 Put Bucket Acl 5 | // ------------------------------- 6 | 7 | // todo: not ready 8 | 9 | oss.putBucketLogging({ 10 | Bucket: 'chylvina', 11 | BucketLoggingStatus: { 12 | LoggingEnabled: { 13 | TargetBucket: 'chylvina', 14 | TargetPrefix: 'log' 15 | } 16 | } 17 | }, function (err, data) { 18 | if (err) { 19 | console.log('error:', err); 20 | return; 21 | } 22 | 23 | console.log('success:', data); 24 | }); -------------------------------------------------------------------------------- /samples/oss/not-ready/PutBucketWebsite.js: -------------------------------------------------------------------------------- 1 | var oss = require('./oss'); 2 | 3 | // ------------------------------- 4 | // 5.3.10 Put Bucket Acl 5 | // ------------------------------- 6 | 7 | // todo: not ready, 文档没有给出正确的请求示例 8 | 9 | oss.putBucketWebsite({ 10 | Bucket: 'chylvina', 11 | BucketLoggingStatus: { 12 | WebsiteConfiguration: { 13 | Bucket: 'chylvina', 14 | WebsiteConfiguration: { 15 | ErrorDocument: { 16 | Key: '' 17 | } 18 | } 19 | } 20 | } 21 | }, function (err, data) { 22 | if (err) { 23 | console.log('error:', err); 24 | return; 25 | } 26 | 27 | console.log('success:', data); 28 | }); -------------------------------------------------------------------------------- /samples/oss/oss.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var oss = new ALY.OSS({ 4 | "accessKeyId": "在阿里云OSS申请的 accessKeyId", 5 | "secretAccessKey": "在阿里云OSS申请的 secretAccessKey", 6 | // 根据你的 oss 实例所在地区选择填入 7 | // 杭州:http://oss-cn-hangzhou.aliyuncs.com 8 | // 北京:http://oss-cn-beijing.aliyuncs.com 9 | // 青岛:http://oss-cn-qingdao.aliyuncs.com 10 | // 深圳:http://oss-cn-shenzhen.aliyuncs.com 11 | // 香港:http://oss-cn-hongkong.aliyuncs.com 12 | // 注意:如果你是在 ECS 上连接 OSS,可以使用内网地址,速度快,没有带宽限制。 13 | // 杭州:http://oss-cn-hangzhou-internal.aliyuncs.com 14 | // 北京:http://oss-cn-beijing-internal.aliyuncs.com 15 | // 青岛:http://oss-cn-qingdao-internal.aliyuncs.com 16 | // 深圳:http://oss-cn-shenzhen-internal.aliyuncs.com 17 | // 香港:http://oss-cn-hongkong-internal.aliyuncs.com 18 | endpoint: 'http://oss-cn-hangzhou.aliyuncs.com', 19 | // 这是 oss sdk 目前支持最新的 api 版本, 不需要修改 20 | apiVersion: '2013-10-15' 21 | }); 22 | 23 | module.exports = oss; 24 | -------------------------------------------------------------------------------- /samples/ots/CreateTable.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.createTable({ 4 | instance_name: 'chylvina', 5 | table_meta: { 6 | table_name: 'table1', 7 | primary_key: [ 8 | { 9 | name: 'key1', 10 | type: 'STRING' 11 | } 12 | ] 13 | }, 14 | reserved_throughput: { 15 | capacity_unit: { 16 | read: 1, 17 | write: 1 18 | } 19 | } 20 | }, 21 | function (err, data) { 22 | if (err) { 23 | console.log('error:', err); 24 | return; 25 | } 26 | 27 | console.log('success:', data); 28 | }); 29 | -------------------------------------------------------------------------------- /samples/ots/DeleteRow.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.deleteRow({ 4 | instance_name: 'chylvina', 5 | table_name: "table1", 6 | condition: { 7 | row_existence: "IGNORE" 8 | }, 9 | primary_key: [ 10 | { 11 | name: "key1", 12 | value: { 13 | type: 'STRING', 14 | v_string: 'value string' 15 | } 16 | } 17 | ] 18 | }, 19 | function (err, data) { 20 | if (err) { 21 | console.log('error:', err); 22 | return; 23 | } 24 | 25 | console.log('success:', data); 26 | }); 27 | -------------------------------------------------------------------------------- /samples/ots/DeleteTable.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.deleteTable({ 4 | instance_name: 'chylvina', 5 | table_name: "table1" 6 | }, 7 | function (err, data) { 8 | if (err) { 9 | console.log('error:', err); 10 | return; 11 | } 12 | 13 | console.log('success:', data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/ots/DescribeTable.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.describeTable({ 4 | instance_name: 'chylvina', 5 | table_name: "table1" 6 | }, 7 | function (err, data) { 8 | if (err) { 9 | console.log('error:', err); 10 | return; 11 | } 12 | 13 | console.log('success:', data); 14 | }); 15 | -------------------------------------------------------------------------------- /samples/ots/GetRange.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.getRange({ 4 | instance_name: 'chylvina', 5 | table_name: "table1", 6 | direction: "FORWARD", 7 | inclusive_start_primary_key: [{ 8 | name: "key1", 9 | value: { 10 | type: 'STRING', 11 | v_string: 'value string' 12 | } 13 | }], 14 | exclusive_end_primary_key: [{ 15 | name: "key1", 16 | value: { 17 | type: 'STRING', 18 | v_string: 'value string1' 19 | } 20 | }] 21 | }, 22 | function (err, data) { 23 | if (err) { 24 | console.log('error:', err); 25 | return; 26 | } 27 | 28 | console.log('success:', data); 29 | }); 30 | -------------------------------------------------------------------------------- /samples/ots/GetRow.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.getRow({ 4 | instance_name: 'chylvina', 5 | table_name: "table1", 6 | primary_key: [ 7 | { 8 | name: "key1", 9 | value: { 10 | type: 'STRING', 11 | v_string: 'value string' 12 | } 13 | } 14 | ] 15 | }, 16 | function (err, data) { 17 | if (err) { 18 | console.log('error:', err); 19 | return; 20 | } 21 | 22 | console.log('success:', data); 23 | }); 24 | -------------------------------------------------------------------------------- /samples/ots/ListTable.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.listTable({ 4 | instance_name: 'chylvina' 5 | }, 6 | function (err, data) { 7 | if (err) { 8 | console.log('error:', err); 9 | return; 10 | } 11 | 12 | console.log('success:', data); 13 | }); 14 | -------------------------------------------------------------------------------- /samples/ots/PutRow.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.putRow({ 4 | instance_name: 'chylvina', 5 | table_name: "table1", 6 | condition: { 7 | row_existence: "IGNORE" 8 | }, 9 | primary_key: [ 10 | { 11 | name: "key1", 12 | value: { 13 | type: 'STRING', 14 | v_string: 'value string' 15 | } 16 | } 17 | ] 18 | }, 19 | function (err, data) { 20 | if (err) { 21 | console.log('error:', err); 22 | return; 23 | } 24 | 25 | console.log('success:', data); 26 | }); 27 | -------------------------------------------------------------------------------- /samples/ots/UpdateRow.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.updateRow({ 4 | instance_name: 'chylvina', 5 | table_name: "table1", 6 | condition: { 7 | row_existence: "IGNORE" 8 | }, 9 | primary_key: [ 10 | { 11 | name: "key1", 12 | value: { 13 | type: 'STRING', 14 | v_string: 'value string' 15 | } 16 | } 17 | ], 18 | attribute_columns: [ 19 | { 20 | name: "key2", 21 | type: "PUT", 22 | value: { 23 | type: 'STRING', 24 | v_string: 'value string' 25 | } 26 | } 27 | ] 28 | }, 29 | function (err, data) { 30 | if (err) { 31 | console.log('error:', err); 32 | return; 33 | } 34 | 35 | console.log('success:', data); 36 | }); 37 | -------------------------------------------------------------------------------- /samples/ots/UpdateTable.js: -------------------------------------------------------------------------------- 1 | var ots = require('./ots'); 2 | 3 | ots.updateTable({ 4 | instance_name: 'chylvina', 5 | table_name: "table1", 6 | reserved_throughput: { 7 | capacity_unit: { 8 | read: 1, 9 | write: 1 10 | } 11 | } 12 | }, 13 | function (err, data) { 14 | if (err) { 15 | console.log('error:', err); 16 | return; 17 | } 18 | 19 | console.log('success:', data); 20 | }); 21 | -------------------------------------------------------------------------------- /samples/ots/ots.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var ots = new ALY.OTS({ 4 | "accessKeyId": "在阿里云OSS申请的 accessKeyId", 5 | "secretAccessKey": "在阿里云OSS申请的 secretAccessKey", 6 | // 根据你的 oss 实例所在地区选择填入 7 | endpoint: 'http://cn-hangzhou.ots.aliyuncs.com', 8 | // 这是 ots sdk 目前支持最新的 api 版本, 不需要修改 9 | apiVersion: '2014-08-08' 10 | }); 11 | 12 | module.exports = ots; 13 | -------------------------------------------------------------------------------- /samples/push/push.js: -------------------------------------------------------------------------------- 1 | // 更详细 sample 请参考 https://help.aliyun.com/document_detail/32402.html 2 | var ALY = require('../../index.js'); 3 | 4 | var push = new ALY.PUSH({ 5 | accessKeyId: "在阿里云申请的 accessKeyId", 6 | secretAccessKey: "在阿里云申请的 secretAccessKey", 7 | endpoint: 'http://cloudpush.aliyuncs.com', 8 | apiVersion: '2015-08-27' 9 | } 10 | ); 11 | 12 | push.pushNoticeToiOS({ 13 | AppKey: '在移动推送申请的 appKey', 14 | Target: 'all', 15 | TargetValue: '', 16 | Env: 'DEV', 17 | Ext: '{}', 18 | Summary: 'message' + i 19 | }, function (err, res) { 20 | console.log(err, res); 21 | }); 22 | 23 | -------------------------------------------------------------------------------- /samples/rds/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var rds = new ALY.RDS({ 4 | accessKeyId: "在阿里云RDS申请的 accessKeyId", 5 | secretAccessKey: "在阿里云RDS申请的 secretAccessKey", 6 | endpoint: 'https://rds.aliyuncs.com', 7 | apiVersion: '2014-08-15' 8 | } 9 | ); 10 | 11 | rds.describeResourceUsage({ 12 | DBInstanceId: '对应的DBInstanceId' 13 | }, function(err, res) { 14 | console.log(err, res); 15 | }); 16 | 17 | rds.describeSlowLogs({ 18 | DBInstanceId: '对应的DBInstanceId', 19 | StartTime: '2014-11-11Z', 20 | EndTime: '2014-11-12Z' 21 | }, function(err, res) { 22 | console.log(err, res); 23 | }); 24 | 25 | rds.describeDatabases({ 26 | DBInstanceId: '对应的rdsfef2izjqnemv' 27 | }, function(err, res) { 28 | console.log(err, res); 29 | }); -------------------------------------------------------------------------------- /samples/slb/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var slb = new ALY.SLB({ 4 | accessKeyId: "在阿里云SLB申请的 accessKeyId", 5 | secretAccessKey: "在阿里云SLB申请的 secretAccessKey", 6 | endpoint: 'https://slb.aliyuncs.com', 7 | apiVersion: '2014-05-15' 8 | } 9 | ); 10 | 11 | slb.describeLoadBalancers({ 12 | RegionId: 'cn-hangzhou' 13 | }, function(err, res) { 14 | console.log(err, res); 15 | }); -------------------------------------------------------------------------------- /samples/sls/All.js: -------------------------------------------------------------------------------- 1 | 2 | var sls = require('./sls'); 3 | 4 | var projectName = "project_name1"; 5 | 6 | 7 | var listLogStores = function(fn) { 8 | sls.listLogStores({ 9 | projectName: projectName 10 | }, function (err, data) { 11 | console.log('----listLogStores----'); 12 | if(err) console.error('error:',err); 13 | else{ 14 | console.log(data); 15 | fn(data); 16 | } 17 | }); 18 | }; 19 | 20 | var putLogs = function(logStoreName,fn){ 21 | 22 | var logGroup = { 23 | logs : [{ 24 | time: Math.floor(new Date().getTime()/1000), 25 | contents: [{ 26 | key: 'a', 27 | value: '1' 28 | },{ 29 | key: 'a', 30 | value: '2' 31 | },{ 32 | key: 'a', 33 | value: '3' 34 | }] 35 | }], 36 | topic: 'vv', 37 | source: '127.0.0.1' 38 | }; 39 | 40 | sls.putLogs({ 41 | projectName: projectName, 42 | logStoreName: logStoreName, 43 | logGroup: logGroup 44 | }, function (err, data) { 45 | console.log('----putLogs----'); 46 | if(err) console.error('error:',err); 47 | else{ 48 | console.log(data); 49 | fn(data); 50 | } 51 | }); 52 | }; 53 | 54 | var listTopics = function(logStoreName, fn) { 55 | 56 | sls.listTopics({ 57 | projectName: projectName, 58 | logStoreName: logStoreName, 59 | line: 10 60 | }, function (err, data) { 61 | console.log('----listTopics----'); 62 | if(err) console.error('error:',err); 63 | else{ 64 | console.log(data); 65 | fn(data); 66 | } 67 | }); 68 | }; 69 | var getHistograms = function(logStoreName, topic, fn){ 70 | sls.getHistograms({ 71 | projectName: projectName, 72 | logStoreName: logStoreName, 73 | topic: topic, 74 | from: from, 75 | to: to 76 | }, function (err, data) { 77 | console.log('----getHistograms----'); 78 | if(err) console.error('error:',err); 79 | else{ 80 | console.log(data); 81 | fn(data); 82 | } 83 | }); 84 | }; 85 | 86 | var getLogs = function(logStoreName, topic, fn){ 87 | sls.getLogs({ 88 | projectName: projectName, 89 | logStoreName: logStoreName, 90 | topic: topic, 91 | from: from, 92 | to: to 93 | }, function (err, data) { 94 | console.log('----getLogs----'); 95 | if(err) console.error('error:',err); 96 | else{ 97 | console.log(data); 98 | fn(data); 99 | } 100 | }); 101 | }; 102 | 103 | 104 | var to = Math.floor(new Date().getTime()/1000)+10; 105 | var from = to-3600; 106 | 107 | listLogStores(function(result1){ 108 | var logStoreName = result1.logstores[0]; 109 | 110 | putLogs(logStoreName, function(result2){ 111 | 112 | listTopics(logStoreName,function(result3){ 113 | var topic = result3.topics[0]; 114 | getHistograms(logStoreName,topic, function(result4){ 115 | getLogs(logStoreName,topic, function(result5){ 116 | 117 | }); 118 | }); 119 | }); 120 | }); 121 | }); -------------------------------------------------------------------------------- /samples/sls/BatchGetLogs.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | 7 | var projectName = "your_project_name"; 8 | 9 | var logStoreName="your_logstore"; 10 | var batchGetLogsCallback = function(shardId,cursor1) 11 | { 12 | sls.batchGetLogs({ 13 | projectName:projectName, 14 | logStoreName:logStoreName, 15 | ShardId:shardId, 16 | cursor:cursor1, 17 | count:10 18 | },function(err,res) 19 | { 20 | if(err) 21 | console.log(err); 22 | if(res == null)return; 23 | for(var i in res.body.logGroupList) 24 | { 25 | var logGroup = res.body.logGroupList[i]; 26 | console.log(logGroup); 27 | } 28 | if(res.headers["x-log-cursor"]== cursor1) 29 | return; 30 | batchGetLogsCallback(shardId,res.headers["x-log-cursor"]); 31 | }); 32 | } 33 | function batchGetLogs(shardId) 34 | { 35 | var param = { 36 | projectName:projectName, 37 | logStoreName:logStoreName, 38 | ShardId:shardId, 39 | FromTime: parseInt( (new Date()).getTime()/1000)-900 40 | }; 41 | console.log(param); 42 | sls.getCursor(param,function(err,data) 43 | { 44 | if(err) 45 | console.log(err); 46 | if(data) 47 | batchGetLogsCallback(shardId,data.body.cursor); 48 | }); 49 | }; 50 | sls.listShards({ 51 | projectName:projectName, 52 | logStoreName:logStoreName 53 | },function(err,data) 54 | { 55 | for(var i in data.body) 56 | { 57 | batchGetLogs(data.body[i].shardID); 58 | } 59 | }); 60 | -------------------------------------------------------------------------------- /samples/sls/CreateLogStore.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | 8 | sls.createLogstore({ 9 | //必选字段 10 | projectName: projectName , 11 | logstoreDetail:{ 12 | logstoreName:"your_logstore", 13 | ttl:3, 14 | shardCount:2 15 | } 16 | },function(err,data) 17 | { 18 | if (err) { 19 | console.log('error:', err); 20 | return; 21 | } 22 | 23 | console.log('success:', data); 24 | 25 | sls.updateLogstore( 26 | { 27 | projectName: projectName , 28 | logstoreName : "your_logstore", 29 | logstoreDetail:{ 30 | logstoreName:"your_logstore", 31 | ttl:4, 32 | shardCount:2 33 | } 34 | 35 | }, 36 | function(err,data) 37 | { 38 | if (err) { 39 | console.log('error:', err); 40 | return; 41 | } 42 | 43 | console.log('success:', data); 44 | }); 45 | 46 | }); 47 | 48 | -------------------------------------------------------------------------------- /samples/sls/DeleteLogStore.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | 8 | sls.deleteLogstore({ 9 | //必选字段 10 | projectName: projectName , 11 | LogStoreName : "your_logstore" 12 | },function(err,data) 13 | { 14 | 15 | if (err) { 16 | console.log('error:', err); 17 | return; 18 | } 19 | 20 | console.log('success:', data); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /samples/sls/GetHistograms.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // get Histogram 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | var logStoreName = "your_logstore"; 8 | var to = Math.floor(new Date().getTime() / 1000); 9 | var from = to - 900; //15min 10 | 11 | sls.getHistograms({ 12 | 13 | //必选字段 14 | projectName: projectName, 15 | logStoreName: logStoreName, 16 | from: from, //开始时间(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数) 17 | to: to, //结束时间(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数) 18 | 19 | //以下为可选字段 20 | topic: '', //指定日志主题(用户所有主题可以通过listTopics获得) 21 | query: '' //查询的关键词,不输入关键词,则查询全部日志数据 22 | },function (err, data) { 23 | 24 | if (err) { 25 | console.log('error:', err); 26 | return; 27 | } 28 | 29 | console.log('success:', data); 30 | 31 | }); 32 | -------------------------------------------------------------------------------- /samples/sls/GetLogStore.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | 8 | sls.getLogstore({ 9 | //必选字段 10 | projectName: projectName , 11 | LogStoreName : "your_logstore" 12 | },function(err,data) 13 | { 14 | 15 | if (err) { 16 | console.log('error:', err); 17 | return; 18 | } 19 | 20 | console.log('success:', data); 21 | 22 | }); 23 | -------------------------------------------------------------------------------- /samples/sls/GetLogs.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // get Logs 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | var logStoreName="your_logstore"; 8 | var to = Math.floor(new Date().getTime() / 1000); 9 | var from = to - 900; //15min 10 | sls.getLogs({ 11 | 12 | //必选字段 13 | projectName: projectName, 14 | logStoreName: logStoreName, 15 | from: from, //开始时间(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数) 16 | to: to, //结束时间(精度为秒,从 1970-1-1 00:00:00 UTC 计算起的秒数) 17 | 18 | //以下为可选字段 19 | topic: '', //指定日志主题(用户所有主题可以通过listTopics获得) 20 | reverse: false,//是否反向读取,只能为 true 或者 false,不区分大小写(默认 false,为正向读取,即从 from 开始到 to 之间读取 Line 条) 21 | query: '', //查询的关键词,不输入关键词,则查询全部日志数据 22 | line: 10, //读取的行数,默认值为 100,取值范围为 0-100 23 | offset: 0 //读取起始位置,默认值为 0,取值范围>0 24 | },function (err, data) { 25 | 26 | if (err) { 27 | console.log('error:', err); 28 | return; 29 | } 30 | 31 | console.log('success:', data); 32 | 33 | }); 34 | -------------------------------------------------------------------------------- /samples/sls/Index.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | 7 | var projectName = "your_project_name"; 8 | 9 | var logStoreName="your_logstore"; 10 | var param ={ 11 | projectName:projectName, 12 | logstoreName : logStoreName, 13 | indexDetail:{ 14 | line:{ 15 | token: [";"], 16 | include_keys: ["key2", "key3"], 17 | caseSensitive:false 18 | }, 19 | ttl:30 20 | } 21 | }; 22 | sls.createIndex(param,function(err,data) 23 | { 24 | console.log(err,data); 25 | sls.updateIndex(param,function(err,data) 26 | { 27 | console.log(err,data); 28 | delete param.indexDetail; 29 | sls.getIndex(param,function(err,data) 30 | { 31 | console.log(err,data); 32 | sls.deleteIndex(param,function(err,data1) 33 | { 34 | console.log(err,data1); 35 | }); 36 | }); 37 | }); 38 | } 39 | ); 40 | -------------------------------------------------------------------------------- /samples/sls/ListLogStores.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | 8 | sls.listLogStores({ 9 | //必选字段 10 | projectName: projectName 11 | }, function (err, data) { 12 | 13 | if (err) { 14 | console.log('error:', err); 15 | return; 16 | } 17 | 18 | console.log('success:', data); 19 | 20 | }); 21 | -------------------------------------------------------------------------------- /samples/sls/ListProject.js: -------------------------------------------------------------------------------- 1 | var sls = require("./sls"); 2 | 3 | // ------------------------------- 4 | // list project 5 | // ------------------------------- 6 | var projectName = ""; 7 | 8 | sls.listProject( 9 | { 10 | projectName: projectName, 11 | offset: 0, 12 | size: 10 13 | }, 14 | function (err, data) { 15 | if (err) { 16 | console.log("error:", err); 17 | return; 18 | } 19 | 20 | console.log("success:", data.body.projects); 21 | } 22 | ); 23 | -------------------------------------------------------------------------------- /samples/sls/ListTopics.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list topics 5 | // ------------------------------- 6 | var projectName = "project_name1"; 7 | var logStoreName = "logstore_name1"; 8 | 9 | sls.listTopics({ 10 | //必选字段 11 | projectName: projectName, 12 | logStoreName: logStoreName, 13 | 14 | //token: '', //可选参数,从某个 topic 开始列出,按照字典序,默认为空 6 15 | line: 100 //可选参数,读取的行数,默认值为 100;范围 0-100 16 | },function (err, data) { 17 | 18 | if (err) { 19 | console.log('error:', err); 20 | return; 21 | } 22 | 23 | console.log('success:', data); 24 | 25 | }); -------------------------------------------------------------------------------- /samples/sls/PutLogs.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // put logs 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | var logStoreName = "your_logstore"; 8 | 9 | var logGroup = { 10 | logs : [{ 11 | time: Math.floor(new Date().getTime()/1000), 12 | contents: [{ 13 | key: 'a', 14 | value: '1' 15 | },{ 16 | key: 'a', 17 | value: '2' 18 | },{ 19 | key: 'a', 20 | value: '3' 21 | }] 22 | }], 23 | topic: 'vv', 24 | source: '127.0.0.1' 25 | }; 26 | 27 | sls.putLogs({ 28 | //必选字段 29 | projectName: projectName, 30 | logStoreName: logStoreName, 31 | logGroup: logGroup 32 | }, function (err, data) { 33 | 34 | if (err) { 35 | console.log('error:', err); 36 | return; 37 | } 38 | 39 | console.log('success:', data); 40 | 41 | }); 42 | -------------------------------------------------------------------------------- /samples/sls/Shard.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // list logStores 5 | // ------------------------------- 6 | var projectName = "your_project_name"; 7 | var getMiddleHash = function(b,e) 8 | { 9 | var mid = ""; 10 | var parse16 = function(st){ 11 | if(st == "g") 12 | return 15; 13 | else 14 | return parseInt(st,16); 15 | } 16 | var sumArr = new Array(32); 17 | var rem = 0; 18 | for(var index = 31;index >=0;--index) 19 | { 20 | sumArr [index] = parseInt(b[index],16)+ parse16(e[index])+rem; 21 | rem = parseInt(sumArr [index]/16); 22 | if(index >0) 23 | sumArr[index] = sumArr[index] % 16; 24 | } 25 | rem = 0; 26 | for(var index in sumArr) 27 | { 28 | var value = sumArr[index] + rem*16; 29 | mid += (parseInt((value)/2)).toString(16); 30 | rem = value %2; 31 | } 32 | return mid; 33 | }; 34 | 35 | sls.listShards({ 36 | projectName:projectName, 37 | logStoreName:"your_logstore" 38 | },function(err,data) 39 | { 40 | if (err) { 41 | console.log('error:', err); 42 | return; 43 | } 44 | 45 | console.log('success:', data); 46 | var mergeshard = function(shardID,fn) 47 | { 48 | console.log("merge:"+shardID); 49 | sls.mergeShards({ 50 | projectName:projectName, 51 | logStoreName:"your_logstore", 52 | ShardId : shardID 53 | },function(err1,data1) 54 | { 55 | console.log(err1,data1); 56 | fn(data1.body); 57 | } 58 | ); 59 | } 60 | var deleteshard = function(shardID,fn) 61 | { 62 | console.log("delete:"+shardID); 63 | sls.deleteShard({ 64 | projectName:projectName, 65 | logStoreName:"your_logstore", 66 | ShardId : shardID 67 | },function(err1,data1) 68 | { 69 | console.log(err1,data1); 70 | if(fn != null) 71 | fn(data1.body); 72 | } 73 | ); 74 | } 75 | 76 | var shard = data.body[0]; 77 | sls.splitShard( 78 | { 79 | projectName:projectName, 80 | logStoreName:"your_logstore", 81 | ShardId : ""+shard.shardID, 82 | HashKey : getMiddleHash(shard.inclusiveBeginKey,shard.exclusiveEndKey) 83 | },function(err1,data1) 84 | { 85 | console.log(err1,data1); 86 | mergeshard(data.body[1].shardID,function(mergeResult){ 87 | for(var i in mergeResult) 88 | { 89 | if(mergeResult[i].status == "readonly") 90 | { 91 | deleteshard(mergeResult[i].shardID); 92 | } 93 | } 94 | }); 95 | } 96 | ); 97 | 98 | }); 99 | 100 | -------------------------------------------------------------------------------- /samples/sls/sls.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var sls = new ALY.SLS({ 4 | "accessKeyId": "", 5 | "secretAccessKey": "=", 6 | "securityToken" :"tokens", 7 | 8 | // 根据你的 sls project所在地区选择填入,更多地域请参考https://help.aliyun.com/document_detail/29008.html?spm=a2c4g.11186623.6.1369.40e448242wou9i 9 | // 北京:http://cn-beijing.log.aliyuncs.com 10 | // 杭州:http://cn-hangzhou.log.aliyuncs.com 11 | // 青岛:http://cn-qingdao.log.aliyuncs.com 12 | // 深圳:http://cn-shenzhen.log.aliyuncs.com 13 | 14 | // 注意:如果你是在 ECS 上连接 SLS,可以使用内网地址,速度快,没有带宽限制。 15 | // 杭州:cn-hangzhou-intranet.log.aliyuncs.com 16 | // 北京:cn-beijing-intranet.log.aliyuncs.com 17 | // 青岛:cn-qingdao-intranet.log.aliyuncs.com 18 | // 深圳:cn-shenzhen-intranet.log.aliyuncs.com 19 | endpoint: 'http://cn-hangzhou.log.aliyuncs.com', 20 | 21 | // 这是 sls sdk 目前支持最新的 api 版本, 不需要修改 22 | apiVersion: '2015-06-01' 23 | 24 | //以下是可选配置 25 | //,httpOptions: { 26 | // timeout: 1000 //1sec, 默认没有timeout 27 | //} 28 | }); 29 | 30 | module.exports = sls; 31 | -------------------------------------------------------------------------------- /samples/sls/sql.js: -------------------------------------------------------------------------------- 1 | var sls = require('./sls'); 2 | 3 | // ------------------------------- 4 | // get Logs 5 | // ------------------------------- 6 | var projectName = 'ali-cn-yunlei-sls-admin'; 7 | var logStoreName = 'sls_operation_log'; 8 | var to = Math.floor(new Date().getTime() / 1000); 9 | var from = to - 900; //15min 10 | 11 | new Promise((resolve, reject) => { 12 | 13 | sls.executeLogStoreSql({ 14 | projectName: projectName, 15 | logStoreName: logStoreName, 16 | from: from, 17 | to: to, 18 | query: '*|select count(method)', 19 | powerSql:true 20 | }, function(err, data) { 21 | if (err) { 22 | console.log('error:', err); 23 | reject(err); 24 | return; 25 | } 26 | console.log(data); 27 | // console.log('success:', data); 28 | resolve(data); 29 | }); 30 | }); 31 | sls.createSqlInstance({ 32 | projectName:projectName, 33 | sqlinstanceDetail: 34 | { 35 | cu:5 36 | } 37 | }, function(err, data){ 38 | console.log("createSqlInstance", err,data); 39 | sls.updateSqlInstance({ 40 | projectName:projectName, 41 | sqlinstanceDetail: 42 | { 43 | cu:1000 44 | } 45 | }, function(err, data){ 46 | console.log("updateSqlInstance", err,data); 47 | sls.getSqlInstance({ 48 | projectName:projectName 49 | }, function(err, data){ 50 | console.log("listSqlInstance", err,data); 51 | }); 52 | }); 53 | }); 54 | return new Promise((resolve, reject) => { 55 | 56 | sls.executeProjectSql({ 57 | projectName: projectName, 58 | query: 'select count(method) from sls_operation_log where __time__ > to_unixtime(now()) - 300 and __time__ < to_unixtime(now())', 59 | powerSql:true 60 | }, function(err, data) { 61 | if (err) { 62 | console.log('error:', err); 63 | reject(err); 64 | return; 65 | } 66 | console.log(data); 67 | // console.log('success:', data); 68 | resolve(data); 69 | }); 70 | }); 71 | 72 | -------------------------------------------------------------------------------- /samples/sts/test.js: -------------------------------------------------------------------------------- 1 | var ALY = require('../../index.js'); 2 | 3 | var sts = new ALY.STS({ 4 | accessKeyId: "在阿里云申请的 accessKeyId", 5 | secretAccessKey: "在阿里云申请的 secretAccessKey", 6 | endpoint: 'https://sts.aliyuncs.com', 7 | apiVersion: '2015-04-01' 8 | } 9 | ); 10 | 11 | // 构造AssumeRole请求 12 | sts.assumeRole({ 13 | Action: 'AssumeRole', 14 | // 指定角色Arn 15 | RoleArn: '', 16 | //设置Token的附加Policy,可以在获取Token时,通过额外设置一个Policy进一步减小Token的权限; 17 | //Policy: '{"Version":"1","Statement":[{"Effect":"Allow", "Action":"*", "Resource":"*"}]}', 18 | //设置Token有效期,可选参数,默认3600秒; 19 | //DurationSeconds: 3600, 20 | RoleSessionName: 'RoleSessionName' 21 | }, function (err, res) { 22 | console.log(err, res); 23 | }); 24 | 25 | //构造GetCallerIdentity请求 26 | sts.getCallerIdentity({ 27 | Action : 'GetCallerIdentity' 28 | }, function (err, res) { 29 | console.log(err, res); 30 | }); 31 | -------------------------------------------------------------------------------- /test/batchcompute/README.md: -------------------------------------------------------------------------------- 1 | batchcompute test 2 | ----------------------- 3 | 4 | 5 | ### 1. 如何使用 6 | 7 | #### (1) 配置 testConfig.js 8 | 9 | ``` 10 | cp testConfig.json testConfig.js 11 | vim testConfig.js #这里配置你的AK, 运行时会先找 testConfig.js , 如果不存在,再找 testConfig.json 12 | ``` 13 | 14 | #### (2) 运行 15 | 16 | ```bash 17 | mocha 2015-11-11 # 使用mocha命令,请先安装到全局: npm i -g mocha 18 | 19 | #DEBUG=aliyun mocha 2015-11-11 #使用 DEBUG=aliyun, 可以得到更加详细的信息 20 | ``` 21 | -------------------------------------------------------------------------------- /test/batchcompute/testConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "accessKeyId": "", 3 | "secretAccessKey": "", 4 | "endpoint": "http://batchcompute.cn-qingdao.aliyuncs.com", 5 | "ecsImageId": "" 6 | } -------------------------------------------------------------------------------- /test/cms/testConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "", 3 | "key": "" 4 | } -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 2 | //使用mocha运行: mocha index 3 | //如果没有mocha请先安装: npm i -g mocha 4 | 5 | require('./sls/2014-11-18'); 6 | require('./sls/2015-06-01'); 7 | require('./batchcompute/2015-06-30'); 8 | require('./batchcompute/2015-11-11'); -------------------------------------------------------------------------------- /test/sls/config.js: -------------------------------------------------------------------------------- 1 | var conf = { 2 | accessKeyId: '', 3 | secretAccessKey: '', 4 | endpoint: 'http://cn-hangzhou.sls.aliyuncs.com', 5 | projectName: '', 6 | logStoreName: '' 7 | }; 8 | 9 | try{ 10 | module.exports = require('../configuration/sls_config'); 11 | }catch(e){ 12 | //if '../configuration/config' does not exists 13 | module.exports = conf; 14 | } --------------------------------------------------------------------------------