How to use the tencentcloud-sdk-nodejs.cam 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') {
        const tempFunc = await this.getFunction(ns, funcObject.FuncName)
github serverless-components / tencent-cam-policy / serverless.js View on Github external
const { mergeDeepRight } = require('ramda')
const util = require('util')
const { utils } = require('@serverless/core')
const { Component } = require('@serverless/core')
const tencentcloud = require('tencentcloud-sdk-nodejs')
const CamClient = tencentcloud.cam.v20190116.Client
const camModels = tencentcloud.cam.v20190116.Models
const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js')
const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js')

class TencentCamPolicy extends Component {
  getCamClient(credentials, region) {
    // create cam client

    const secret_id = credentials.SecretId
    const secret_key = credentials.SecretKey
    const cred = new tencentcloud.common.Credential(secret_id, secret_key)
    const httpProfile = new HttpProfile()
    httpProfile.reqTimeout = 30
    const clientProfile = new ClientProfile('HmacSHA256', httpProfile)
    return new CamClient(cred, region, clientProfile)
  }
github serverless-components / tencent-cam-policy / serverless.js View on Github external
const { mergeDeepRight } = require('ramda')
const util = require('util')
const { utils } = require('@serverless/core')
const { Component } = require('@serverless/core')
const tencentcloud = require('tencentcloud-sdk-nodejs')
const CamClient = tencentcloud.cam.v20190116.Client
const camModels = tencentcloud.cam.v20190116.Models
const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js')
const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js')

class TencentCamPolicy extends Component {
  getCamClient(credentials, region) {
    // create cam client

    const secret_id = credentials.SecretId
    const secret_key = credentials.SecretKey
    const cred = new tencentcloud.common.Credential(secret_id, secret_key)
    const httpProfile = new HttpProfile()
    httpProfile.reqTimeout = 30
    const clientProfile = new ClientProfile('HmacSHA256', httpProfile)
    return new CamClient(cred, region, clientProfile)
  }
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) {
    const cred = options.token
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-components / tencent-cam-role / serverless.js View on Github external
const { mergeDeepRight } = require('ramda')
const { Component } = require('@serverless/core')
const tencentcloud = require('tencentcloud-sdk-nodejs')
const CamClient = tencentcloud.cam.v20190116.Client
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 {
  createRole,
  deleteRole,
  getRole,
  addRolePolicy,
  removeRolePolicy,
  updateAssumeRolePolicy,
  inputsChanged,
  fullPolicyId
} = require('./utils')

const defaults = {
  service: ['scf.qcloud.com'],
github serverless-components / tencent-cam-role / utils.js View on Github external
const { utils } = require('@serverless/core')
const util = require('util')
const { equals, pick, type } = require('ramda')
const tencentcloud = require('tencentcloud-sdk-nodejs')
const camModels = tencentcloud.cam.v20190116.Models

const AttachRolePolicyAction = async ({ cam, roleName, policyId }) => {
  const req = new camModels.AttachRolePolicyRequest()
  const body = {
    AttachRoleName: roleName,
    PolicyId: policyId
  }
  req.from_json_string(JSON.stringify(body))
  const handler = util.promisify(cam.AttachRolePolicy.bind(cam))
  try {
    await handler(req)
  } catch (e) {
    throw 'AttachRolePolicyActionError: ' + e
  }
}