Skip to content

Commit

Permalink
fix: throw error when no temp secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed Apr 21, 2020
1 parent 84929c2 commit fe0b6b0
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ const { MultiApigw, Scf, Apigw, Cos, Cns } = require('tencent-component-toolkit'
const { packageCode, getDefaultProtocol, deleteRecord, prepareInputs } = require('./utils')
const CONFIGS = require('./config')

class CloudComopnent extends Component {
class ServerlessComopnent extends Component {
getCredentials() {
const { tmpSecrets } = this.credentials.tencent

if (!tmpSecrets || !tmpSecrets.TmpSecretId) {
throw new Error(
'Cannot get secretId/Key, your account could be sub-account or does not have access, please check if SLS_QcsRole role exists in your account, and visit https://console.cloud.tencent.com/cam to bind this role to your account.'
)
}

return {
SecretId: tmpSecrets.TmpSecretId,
SecretKey: tmpSecrets.TmpSecretKey,
Token: tmpSecrets.Token
}
}

async uploadCodeToCos(credentials, inputs, region, filePath) {
const { appId } = this.credentials.tencent.tmpSecrets
// 创建cos对象
Expand Down Expand Up @@ -162,13 +178,8 @@ class CloudComopnent extends Component {
async deploy(inputs) {
console.log(`Deploying Express App...`)

// 获取腾讯云密钥信息
const { tmpSecrets } = this.credentials.tencent
const credentials = {
SecretId: tmpSecrets.TmpSecretId,
SecretKey: tmpSecrets.TmpSecretKey,
Token: tmpSecrets.Token
}
// get credentials
const credentials = this.getCredentials()

// 对Inputs内容进行标准化
const { regionList, functionConf, apigatewayConf, cnsConf } = await prepareInputs(
Expand All @@ -177,7 +188,7 @@ class CloudComopnent extends Component {
inputs
)

// 部署函数 + API网关
// deploy scf + apigw
const outputs = {}
if (!functionConf.code.src) {
outputs.templateUrl = CONFIGS.templateUrl
Expand All @@ -198,7 +209,7 @@ class CloudComopnent extends Component {
outputs['scf'] = functionOutputs
}

// 云解析遇到等API网关部署完成才可以继续部署
// add cns for apigw
if (cnsConf.length > 0) {
outputs['cns'] = await this.deployCns(credentials, cnsConf, regionList, apigwOutputs)
}
Expand All @@ -215,12 +226,7 @@ class CloudComopnent extends Component {

const { state } = this
const { regionList = [] } = state
const { tmpSecrets } = this.credentials.tencent
const credentials = {
SecretId: tmpSecrets.TmpSecretId,
SecretKey: tmpSecrets.TmpSecretKey,
Token: tmpSecrets.Token
}
const credentials = this.getCredentials()
const removeHandlers = []
for (let i = 0; i < regionList.length; i++) {
const curRegion = regionList[i]
Expand Down Expand Up @@ -256,4 +262,4 @@ class CloudComopnent extends Component {
}
}

module.exports = CloudComopnent
module.exports = ServerlessComopnent

0 comments on commit fe0b6b0

Please sign in to comment.