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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
"semantic-release": "^17.0.4"
},
"dependencies": {
"@tencent-sdk/capi": "0.2.15",
"@tencent-sdk/capi": "^0.2.17",
"@ygkit/request": "^0.0.6",
"klaw-sync": "^6.0.0",
"moment": "^2.25.3",
"tencent-cloud-sdk": "^0.1.5"
"tencent-cloud-sdk": "^0.1.6"
}
}
29 changes: 16 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const Apigw = require('./baas/apigw');
const Cdn = require('./baas/cdn');
const Cns = require('./baas/cns');
const Cos = require('./baas/cos');
const Domain = require('./baas/domain');
const MultiApigw = require('./baas/multi-apigw');
const MultiScf = require('./baas/multi-scf');
const Scf = require('./baas/scf');
const Tag = require('./baas/tag');
const Postgresql = require('./baas/postgresql');
const Vpc = require('./baas/vpc');
const Cam = require('./baas/cam');
const Metrics = require('./baas/metrics');
const Apigw = require('./modules/apigw');
const Cdn = require('./modules/cdn');
const Cns = require('./modules/cns');
const Cos = require('./modules/cos');
const Domain = require('./modules/domain');
const MultiApigw = require('./modules/multi-apigw');
const MultiScf = require('./modules/multi-scf');
const Scf = require('./modules/scf');
const Tag = require('./modules/tag');
const Postgresql = require('./modules/postgresql');
const Vpc = require('./modules/vpc');
const Cam = require('./modules/cam');
const Metrics = require('./modules/metrics');
const Layer = require('./modules/layer');

module.exports = {
Apigw,
Cdn,
Expand All @@ -25,4 +27,5 @@ module.exports = {
Vpc,
Cam,
Metrics,
Layer,
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/baas/cdn/apis.js → src/modules/cdn/apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function apiFactory(actions) {
}
return Response;
} catch (e) {
throw new TypeError(`API_CDN_${action}`, JSON.stringify(e), e.stack);
throw new TypeError(`API_CDN_${action}`, e.message, e.stack);
}
};
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/baas/cns/index.js → src/modules/cns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Cns {
throw new TypeError(`API_CNS_RecordModify`, JSON.stringify(modifyResult));
}
} catch (e) {
throw new TypeError(`API_CNS_RecordModify`, JSON.stringify(e), e.stack);
throw new TypeError(`API_CNS_RecordModify`, e.message, e.stack);
}
console.log(`Modified (recordId is ${tempInputs.recordId}) `);
} else {
Expand Down Expand Up @@ -177,7 +177,7 @@ class Cns {
throw new TypeError(`API_CNS_RecordStatus`, JSON.stringify(statusResult));
}
} catch (e) {
throw new TypeError(`API_CNS_RecordStatus`, JSON.stringify(e), e.stack);
throw new TypeError(`API_CNS_RecordStatus`, e.message, e.stack);
}
console.log(`Modified status to ${tempInputs.status} `);
}
Expand Down
File renamed without changes.
28 changes: 14 additions & 14 deletions src/baas/cos/index.js → src/modules/cos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Cos {
try {
await setTagsHandler(setTagsParams);
} catch (e) {
throw new TypeError(`API_COS_putBucketTagging`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putBucketTagging`, e.message, e.stack);
}
}

Expand All @@ -162,7 +162,7 @@ class Cos {
Region: this.region,
});
} catch (e) {
throw new TypeError(`API_COS_deleteBucketTagging`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_deleteBucketTagging`, e.message, e.stack);
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ class Cos {
try {
await setCorsHandler(setCorsParams);
} catch (e) {
throw new TypeError(`API_COS_putBucketCors`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putBucketCors`, e.message, e.stack);
}
}

Expand All @@ -210,7 +210,7 @@ class Cos {
Region: this.region,
});
} catch (e) {
throw new TypeError(`API_COS_deleteBucketCors`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_deleteBucketCors`, e.message, e.stack);
}
}

Expand Down Expand Up @@ -266,7 +266,7 @@ class Cos {
try {
await setLifecycleHandler(JSON.parse(JSON.stringify(setLifecycleParams)));
} catch (e) {
throw new TypeError(`API_COS_putBucketLifecycle`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putBucketLifecycle`, e.message, e.stack);
}
}

Expand All @@ -281,7 +281,7 @@ class Cos {
Region: this.region,
});
} catch (e) {
throw new TypeError(`API_COS_deleteBucketLifecycle`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_deleteBucketLifecycle`, e.message, e.stack);
}
}

Expand All @@ -301,7 +301,7 @@ class Cos {
try {
await setVersioningHandler(setVersioningParams);
} catch (e) {
throw new TypeError(`API_COS_putBucketVersioning`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putBucketVersioning`, e.message, e.stack);
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ class Cos {
try {
await setWebsiteHandler(staticHostParams);
} catch (e) {
throw new TypeError(`API_COS_putBucketWebsite`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putBucketWebsite`, e.message, e.stack);
}
}

Expand All @@ -345,7 +345,7 @@ class Cos {
});
return res;
} catch (e) {
throw new TypeError(`API_COS_getBucket`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_getBucket`, e.message, e.stack);
}
}

Expand All @@ -365,7 +365,7 @@ class Cos {
});
return Url;
} catch (e) {
throw new TypeError(`API_COS_getObjectUrl`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_getObjectUrl`, e.message, e.stack);
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ class Cos {
try {
await Promise.all(uploadItems);
} catch (e) {
throw new TypeError(`API_COS_putObject`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putObject`, e.message, e.stack);
}
} else if (inputs.file && (await fs.existsSync(inputs.file))) {
const itemParams = {
Expand All @@ -434,7 +434,7 @@ class Cos {
try {
await handler(itemParams);
} catch (e) {
throw new TypeError(`API_COS_putObject`, JSON.stringify(e), e.stack);
throw new TypeError(`API_COS_putObject`, e.message, e.stack);
}
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ class Cos {
try {
await fs.writeFileSync(envFilePath, script);
} catch (e) {
throw new TypeError(`DEPLOY_COS_CREATE_ENV_FILE`, JSON.stringify(e), e.stack);
throw new TypeError(`DEPLOY_COS_CREATE_ENV_FILE`, e.message, e.stack);
}
}

Expand Down Expand Up @@ -592,7 +592,7 @@ class Cos {
if (e.error && e.error.Code && e.error.Code === 'NoSuchBucket') {
console.log(`Bucket ${inputs.bucket} not exist`);
} else {
throw new TypeError(`DEPLOY_COS_EXEC_HOOK`, JSON.stringify(e), e.stack);
throw new TypeError(`DEPLOY_COS_EXEC_HOOK`, e.message, e.stack);
}
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions src/modules/layer/apis/apis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const { TypeError } = require('../../../utils/error');

function apiFactory(actions) {
const apis = {};
actions.forEach((action) => {
apis[action] = async (capi, inputs) => {
const data = {
Version: '2018-04-16',
Action: action,
// RequestClient: 'ServerlessComponent',
...inputs,
};
if (capi.options.Token) {
data.Token = capi.options.Token;
}
try {
const { Response } = await capi.request(
data,
// this is preset options for capiateway
{
debug: false,
ServiceType: 'scf',
// baseHost: 'tencentcloudapi.com'
host: 'scf.tencentcloudapi.com',
},
true,
);

if (Response && Response.Error && Response.Error.Code) {
throw new TypeError(
`API_LAYER_${action}`,
Response.Error.Message,
null,
Response.RequestId,
);
}
return Response;
} catch (e) {
throw new TypeError(`API_LAYER_${action}`, e.message, e.stack);
}
};
});

return apis;
}

const ACTIONS = [
'PublishLayerVersion',
'DeleteLayerVersion',
'GetLayerVersion',
'ListLayers',
'ListLayerVersions',
];
const APIS = apiFactory(ACTIONS);

module.exports = APIS;
75 changes: 75 additions & 0 deletions src/modules/layer/apis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const {
PublishLayerVersion,
DeleteLayerVersion,
GetLayerVersion,
ListLayerVersions,
} = require('./apis');

const utils = {
/**
* get target version layer detail
* @param {object} capi capi instance
* @param {string} LayerName
* @param {string} LayerVersion
*/
async getLayerDetail(capi, LayerName, LayerVersion) {
// get instance detail
try {
const res = await GetLayerVersion(capi, {
LayerName,
LayerVersion,
});
return res;
} catch (e) {
return {};
}
},

/**
* get layer versiosn
* @param {object} capi capi instance
* @param {string} LayerName
*/
async getLayerVersions(capi, LayerName) {
// get instance detail
const res = await ListLayerVersions(capi, {
LayerName,
});
if (res.LayerVersions) {
const { LayerVersions } = res;
return LayerVersions;
}
return null;
},

/**
*
* @param {object} capi capi instance
* @param {object} params publish layer parameters
*/
async publishLayer(capi, params) {
const res = await PublishLayerVersion(capi, {
LayerName: params.LayerName,
CompatibleRuntimes: params.CompatibleRuntimes,
Content: params.Content,
Description: params.Description,
LicenseInfo: params.licenseInfo || '',
});
return res.LayerVersion ? res.LayerVersion : null;
},

/**
* delete layer version
* @param {object} capi capi instance
* @param {*} LayerName layer name
* @param {*} LayerVersion layer version
*/
async deleteLayerVersion(capi, LayerName, LayerVersion) {
await DeleteLayerVersion(capi, {
LayerName,
LayerVersion,
});
},
};

module.exports = utils;
Loading