Skip to content

Commit

Permalink
fix: missing credentials token bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun authored and Yuga Sun committed Oct 23, 2020
1 parent 9786195 commit e966e6f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bin/slsplus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node

require('dotenv').config()
require('../dist/src/cli')
require('dotenv').config();
require('../dist/src/cli');
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config = {
testEnvironment: 'node',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$',
// testRegex: '(/__tests__/ci/ci.ssr\.(test|spec))\\.(js|ts)$',
testPathIgnorePatterns: ['/node_modules/','/dist/'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-commit": "ygsec && lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-push": "npm run lint:fix && npm run prettier:fix"
"pre-push": "ygsec && npm run lint:fix && npm run prettier:fix"
}
},
"lint-staged": {
Expand Down Expand Up @@ -81,6 +81,7 @@
"@types/jest": "^26.0.13",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"@ygkit/secure": "^0.0.3",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
Expand Down
3 changes: 2 additions & 1 deletion src/cli/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { Credential } from '../typings';
const configPath = join(homedir(), '.slsplus.conf');

const getCredential = (): Credential | null => {
const { TENCENT_SECRET_ID, TENCENT_SECRET_KEY } = process.env;
const { TENCENT_SECRET_ID, TENCENT_SECRET_KEY, TENCENT_SECRET_TOKEN } = process.env;
if (TENCENT_SECRET_ID && TENCENT_SECRET_KEY) {
return {
secretId: TENCENT_SECRET_ID,
secretKey: TENCENT_SECRET_KEY,
token: TENCENT_SECRET_TOKEN,
};
}
return null;
Expand Down
12 changes: 10 additions & 2 deletions src/cli/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import YAML from 'js-yaml';
import fse from 'fs-extra';
import { configPath } from './constants';
import chalk from 'chalk';
import { configPath, getCredential } from './constants';

async function initialize(): Promise<void> {
try {
const configs = YAML.load(fse.readFileSync(configPath, 'utf-8'));
process.env.TENCENT_SECRET_ID = configs.tencent.secretId;
process.env.TENCENT_SECRET_KEY = configs.tencent.secretKey;
} catch (e) {}
} catch (e) {
const credentials = getCredential();
if (!credentials) {
console.log(
chalk.yellow(`[Warning] Missing Global credentials, run "slsplus config" to config.`),
);
}
}
}

export { initialize };

0 comments on commit e966e6f

Please sign in to comment.