How to use the tencentcloud-sdk-nodejs.scf function in tencentcloud-sdk-nodejs

To help you get started, we’ve selected a few tencentcloud-sdk-nodejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless-components / tencent-scf / library / deployFunction.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const Abstract = require('./abstract')
const utils = require('./utils')
const fs = require('fs')
const _ = require('lodash')
const util = require('util')
const models = tencentcloud.scf.v20180416.Models
const camModels = tencentcloud.cam.v20190116.Models

class DeployFunction extends Abstract {
  async deploy(ns, funcObject) {
    const func = await this.getFunction(ns, funcObject.FuncName)
    if (!func) {
      await this.createFunction(ns, funcObject)
    } else {
      if (func.Runtime != funcObject.Properties.Runtime) {
        throw `Runtime error: Release runtime(${func.Runtime}) and local runtime(${funcObject.Properties.Runtime}) are inconsistent`
      }
      this.context.debug('Updating code... ')
      await this.updateFunctionCode(ns, funcObject)
      // when update code Status is Active, continue
      let status = 'updating'
      while (status != 'Active') {
github serverless-tencent / serverless-tencent-scf / deploy / lib / deployListFunctions.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const AbstractHandler = require('../../shared/handler')
const models = tencentcloud.scf.v20180416.Models
const util = require('util')

class InvokeFunction extends AbstractHandler {
  functionsList(funcName) {
    const req = new models.ListVersionByFunctionRequest()
    req.FunctionName = funcName
    req.Namespace = 'default'
    const handler = util.promisify(this.scfClient.ListVersionByFunction.bind(this.scfClient))
    try {
      return handler(req)
    } catch (e) {
      this.serverless.cli.log('ErrorCode: ' + e.code + ' RequestId: ' + e.requestId)
      throw e
    }
  }
}
github serverless-components / tencent-scf / library / removeFunction.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const Abstract = require('./abstract')
const models = tencentcloud.scf.v20180416.Models
const util = require('util')

class RemoveFunction extends Abstract {
  async remove(funcName) {
    const delFuncRequest = new models.DeleteFunctionRequest()
    delFuncRequest.FunctionName = funcName

    const handler = util.promisify(this.scfClient.DeleteFunction.bind(this.scfClient))
    try {
      this.context.debug('Removing function', funcName)
      const result = await handler(delFuncRequest)
      this.context.debug('Request id', result.RequestId)
    } catch (e) {
      throw e
    }
  }
github serverless-tencent / serverless-tencent-scf / logs / lib / retrieveLogs.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const AbstractHandler = require('../../shared/handler')
const models = tencentcloud.scf.v20180416.Models
const util = require('util')

class LogsFunction extends AbstractHandler {
  async logs(funcName, startTime, endTime, filter) {
    const req = new models.GetFunctionLogsRequest()
    const body = {
      FunctionName: funcName,
      StartTime: startTime,
      EndTime: endTime,
      Namespace: 'default',
      Filter: filter
    }
    req.from_json_string(JSON.stringify(body))
    const handler = util.promisify(this.scfClient.GetFunctionLogs.bind(this.scfClient))
    try {
      return await handler(req)
github serverless-components / tencent-scf / library / abstract.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js')
const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js')
const assert = require('assert')
const COS = require('cos-nodejs-sdk-v5')
const { Credential } = tencentcloud.common
const ScfClient = tencentcloud.scf.v20180416.Client
const CamClient = tencentcloud.cam.v20190116.Client
const TagClient = tencentcloud.tag.v20180813.Client

class AbstractHandler {
  constructor({ appid, secret_id, secret_key, options, context }) {
    this.appid = appid
    this.options = options
    this.context = context
    assert(options, 'Options should not is empty')
    this._scfClient = AbstractHandler.createScfClient(secret_id, secret_key, options)
    this._tagClient = AbstractHandler.createTagClient(secret_id, secret_key, options)
    this._cosClient = AbstractHandler.createCosClient(secret_id, secret_key, options)
    this._camClient = AbstractHandler.createCamClient(secret_id, secret_key, options)
  }

  static getClientInfo(secret_id, secret_key, options) {
github serverless-tencent / serverless-tencent-scf / info / lib / displayServiceInfo.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const AbstractHandler = require('../../shared/handler')
const models = tencentcloud.scf.v20180416.Models
const util = require('util')

class InfoFunction extends AbstractHandler {
  async info(service, stage) {
    const req = new models.ListFunctionsRequest()
    const body = {
      Namespace: 'default',
      Filters: [
        {
          Name: 'tag-Application',
          Values: [service]
        },
        {
          Name: 'tag-Stage',
          Values: [stage]
        }
github serverless-tencent / serverless-tencent-scf / remove / lib / removeFunction.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const AbstractHandler = require('../../shared/handler')
const models = tencentcloud.scf.v20180416.Models
const util = require('util')

class RemoveFunction extends AbstractHandler {
  async remove(funcName) {
    const req = new models.DeleteFunctionRequest()
    const body = {
      FunctionName: funcName
    }
    req.from_json_string(JSON.stringify(body))
    const handler = util.promisify(this.scfClient.DeleteFunction.bind(this.scfClient))
    try {
      return await handler(req)
    } catch (e) {
      this.serverless.cli.log('ErrorCode: ' + e.code + ' RequestId: ' + e.requestId)
      throw e
    }
github serverless-tencent / serverless-tencent-scf / shared / handler.js View on Github external
const tencentcloudcos = require('cos-nodejs-sdk-v5');
const tencentcloud = require('tencentcloud-sdk-nodejs');
const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js');
const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js');
const assert = require('assert');
const COS = require('cos-nodejs-sdk-v5');

const Credential = tencentcloud.common.Credential;
const ScfClient = tencentcloud.scf.v20180416.Client;
const TagClient = tencentcloud.tag.v20180813.Client;
const MonitorClinet = tencentcloud.monitor.v20180724.Client;

class AbstractHandler {
	constructor(appid, secret_id, secret_key, options) {
		this.appid = appid;
		this.secret_id = secret_id;
		this.secret_key = secret_key;
		this.options = options;

		assert(options, 'options should not is empty');
		this._scfClient = AbstractHandler.createScfClient(secret_id, secret_key, options);
		this._cosClient = AbstractHandler.createCosClient(secret_id, secret_key, options);
		this._tagClient = AbstractHandler.createTagClient(secret_id, secret_key, options);
		this._monitorClient = AbstractHandler.createMonitorClient(secret_id, secret_key, options);
	}
github serverless-tencent / serverless-tencent-scf / deploy / lib / deployFunction.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const AbstractHandler = require('../../shared/handler')
const utils = require('../../shared/utils')
const scfModels = tencentcloud.scf.v20180416.Models
const camModels = tencentcloud.cam.v20190116.Models
const fs = require('fs')
const _ = require('lodash')
const util = require('util')

class DeployFunction extends AbstractHandler {
  async deploy(ns, funcObject) {
    if (funcObject.Properties.enableRoleAuth == true) {
      await this.addRole()
    }
    const func = await this.getFunction(ns, funcObject.FuncName)
    if (!func) {
      await this.createFunction(ns, funcObject)
    } else {
      if (func.Runtime != funcObject.Properties.Runtime) {
        throw `Runtime error: Release runtime(${func.Runtime}) and local runtime(${funcObject.Properties.Runtime}) are inconsistent`
github serverless-tencent / serverless-tencent-scf / rollback / lib / rollbackService.js View on Github external
const tencentcloud = require('tencentcloud-sdk-nodejs')
const tencentcloudcos = require('cos-nodejs-sdk-v5')
const AbstractHandler = require('../../shared/handler')
const scf_models = tencentcloud.scf.v20180416.Models
const util = require('util')

class RollbackService extends AbstractHandler {
  async historyList(fileKey, cosBucket) {
    const req = {
      Bucket: cosBucket,
      Region: this.options.region,
      Prefix: fileKey
    }
    const handler = util.promisify(this.cosClient.getBucket.bind(this.cosClient))
    try {
      return await handler(req)
    } catch (e) {
      this.serverless.cli.log('ErrorCode: ' + e.code + ' RequestId: ' + e.requestId)
      throw e
    }