Skip to content

Commit

Permalink
add custom domain support and fix bad case
Browse files Browse the repository at this point in the history
  • Loading branch information
CiCi503 committed Sep 19, 2018
1 parent 5f02a0a commit 8b65654
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 103 deletions.
83 changes: 82 additions & 1 deletion es5/client.js
Expand Up @@ -642,7 +642,88 @@ var Client = function () {
* @param {json} headers : {headerKey1 : 'headValue1'}
*/

}], [{
}, {
key: 'createCustomDomain',
value: function createCustomDomain(domainName, options = {}, headers) {
return this.post('/custom-domains', Object.assign({
domainName,
}, options), headers);
}

/**
* 创建CustomDomain
*
* Options:
* - protocol
* - routeConfig
*
* @param {String} domainName 域名
* @param {Object} options 选项,optional
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomainResponse])
*/

}, {
key: 'updateCustomDomain',
value: function updateCustomDomain(domainName, options = {}, headers) {
return this.put(`/custom-domains/${domainName}`, options, headers);
}

/**
* 更新CustomDomain信息
*
* Options:
* - protocol
* - routeConfig
*
* @param {String} domainName
* @param {Object} options 选项,optional
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomainResponse])
*/
}, {
key: 'getCustomDomain',
value: function getCustomDomain(domainName, headers) {
return this.get(`/custom-domains/${domainName}`, null, headers);
}

/**
* 获取CustomDomain信息
*
* @param {String} domainName
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomain 信息])
*/
}, {
key: 'deleteCustomDomain',
value: function deleteCustomDomain(domainName, options = {}, headers) {
return this.delete(`/custom-domains/${domainName}`, null, options, headers);
}

/**
* 删除CustomDomain
*
* @param {String} domainName
* @return {Promise} 返回 Object(包含headers和data属性)
*/

}, {
key: 'listCustomDomains',
value: function listCustomDomain(options = {}, headers) {
return this.get('/custom-domains', options, headers);
}

/**
* 获取CustomDomain列表
*
* Options:
* - limit
* - prefix
* - startKey
* - nextToken
*
* @param {Object} options 选项,optional
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomain 列表])
*/

},], [{
key: 'getSignature',
value: function getSignature(accessKeyID, accessKeySecret, method, path, headers, queries) {
var stringToSign = helper.composeStringToSign(method, path, headers, queries);
Expand Down
85 changes: 76 additions & 9 deletions lib/client.js
Expand Up @@ -56,13 +56,13 @@ class Client {

const protocol = config.secure ? 'https' : 'http';

const internal = config.internal ? '-internal': '';
const internal = config.internal ? '-internal' : '';

this.endpoint = `${protocol}://${accountid}.${region}${internal}.fc.aliyuncs.com`;
this.host = `${accountid}.${region}${internal}.fc.aliyuncs.com`;
this.version = '2016-08-15';
this.timeout = Number.isFinite(config.timeout) ? config.timeout : 60000; // default is 60s

this.headers = config.headers || {};
}

Expand Down Expand Up @@ -90,7 +90,6 @@ class Client {

headers = Object.assign(this.buildHeaders(), this.headers, headers);
var postBody;

if (body) {
debug('request body: %s', body);
var buff = null;
Expand All @@ -113,7 +112,7 @@ class Client {

var queriesToSign = null;
if (path.startsWith('/proxy/')) {
queriesToSign = query || {}
queriesToSign = query || {}
}
var signature = Client.getSignature(this.accessKeyID, this.accessKeySecret, method, `/${this.version}${path}`, headers, queriesToSign);
headers['authorization'] = signature;
Expand Down Expand Up @@ -300,23 +299,23 @@ class Client {
}

normalizeParams(opts) {
if (opts.functionName){
if (opts.functionName) {
opts.functionName = String(opts.functionName);
}

if (opts.runtime){
if (opts.runtime) {
opts.runtime = String(opts.runtime);
}

if (opts.handler){
if (opts.handler) {
opts.handler = String(opts.handler);
}

if (opts.memorySize){
if (opts.memorySize) {
opts.memorySize = parseInt(opts.memorySize, 10);
}

if (opts.timeout){
if (opts.timeout) {
opts.timeout = parseInt(opts.timeout, 10);

}
Expand Down Expand Up @@ -482,6 +481,74 @@ class Client {
return this.delete(path, options, headers);
}

/**
* 创建CustomDomain
*
* Options:
* - protocol
* - routeConfig
*
* @param {String} domainName 域名
* @param {Object} options 选项,optional
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomainResponse])
*/
createCustomDomain(domainName, options = {}, headers) {
return this.post('/custom-domains', Object.assign({
domainName,
}, options), headers);
}

/**
* 获取CustomDomain列表
*
* Options:
* - limit
* - prefix
* - startKey
* - nextToken
*
* @param {Object} options 选项,optional
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomain 列表])
*/
listCustomDomains(options = {}, headers) {
return this.get('/custom-domains', options, headers);
}

/**
* 获取CustomDomain信息
*
* @param {String} domainName
* @return {Promise} 返回 Object(包含headers和data属性[CustomDomain 信息])
*/
getCustomDomain(domainName, headers) {
return this.get(`/custom-domains/${domainName}`, null, headers);
}

/**
* 更新CustomDomain信息
*
* Options:
* - protocol
* - routeConfig
*
* @param {String} domainName
* @param {Object} options 选项,optional
* @return {Promise} 返回 Object(包含headers和data属性[Service 信息])
*/
updateCustomDomain(domainName, options = {}, headers) {
return this.put(`/custom-domains/${domainName}`, options, headers);
}

/**
* 删除CustomDomain
*
* @param {String} domainName
* @return {Promise} 返回 Object(包含headers和data属性)
*/
deleteCustomDomain(domainName, options = {}, headers) {
return this.delete(`/custom-domains/${domainName}`, null, options, headers);
}

/**
* 获得Header 签名
*
Expand Down

0 comments on commit 8b65654

Please sign in to comment.