Skip to content

Commit

Permalink
feat: 🎸 #336 θŽ·ε–ε―†ι’₯εˆ—θ‘¨ηš„ζ—Άε€™δΉŸθ¦ζŒ‰η…§θΏ™δΈͺθ§„θŒƒεŽ»θ―»ηŽ―ε’ƒε˜ι‡οΌŒε―δ»₯ι€‰ζ‹©ηŽ―ε’ƒε˜ι‡ηš„ε―†ι’₯
Browse files Browse the repository at this point in the history
  • Loading branch information
xsahxl committed Dec 7, 2021
1 parent 1c72e2b commit 2d68805
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/common/credential/getCredential/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import getYamlContent from '../../getYamlContent';
import { logger } from '../../../libs/utils';
import { getRootHome } from '../../../libs/common';
import chalk from 'chalk';
import { transformInputs, trim, getServerlessDevsAccessFromEnv } from './utils'
import { transformInputs, trim, getServerlessDevsAccessFromEnv } from './utils';

const Crypto = require('crypto-js');

Expand Down Expand Up @@ -78,9 +78,9 @@ async function getCredentialWithAccess(access?: string, ...args: any[]) {
SecurityToken: get(process, 'env.SecurityToken'),
});
}
const serverlessDevsAccessFromEnv = getServerlessDevsAccessFromEnv()
const serverlessDevsAccessFromEnv = getServerlessDevsAccessFromEnv(access);
if (serverlessDevsAccessFromEnv) {
return trim(serverlessDevsAccessFromEnv)
return trim(serverlessDevsAccessFromEnv);
}

const accessContent = await getAccess(accessAlias);
Expand Down
27 changes: 23 additions & 4 deletions src/common/credential/getCredential/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { jsonparse } from '../../../libs/utils';

export function transformInputs(inputs, result) {
if (!inputs || !result) return;
const { Alias } = result;
Expand All @@ -18,8 +16,29 @@ export function trim(obj) {
return obj;
}

export function getServerlessDevsAccessFromEnv() {
function parse(key: string) {
try {
const params = JSON.parse(process.env[key]);
return Object.keys(params).length > 0 ? params : undefined;
} catch (error) {}
}

export function getServerlessDevsAccessFromEnv(access?: string) {
if (access) {
const data = parse(access);
return data
? {
Alias: access,
...parse(access),
}
: undefined;
}
for (const key in process.env) {
if (key.endsWith('serverless_devs_access')) return jsonparse(process.env[key]);
if (key.endsWith('serverless_devs_access')) {
return {
Alias: key,
...parse(key),
};
}
}
}
6 changes: 3 additions & 3 deletions src/common/credential/setCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import yaml from 'js-yaml';
import { providerCollection, checkProviderList } from './constant';
import getYamlContent from '../getYamlContent';
import { jsonparse } from '../../libs/utils';
import { getServerlessDevsTempArgv } from '../../libs/utils';
import { getRootHome } from '../../libs/common';

const Crypto = require('crypto-js');
Expand Down Expand Up @@ -65,8 +65,8 @@ async function writeData(data: any) {
const content = await getYamlContent(filePath);
if (content) {
const providerAliasKeys = Object.keys(content);
const Temp_Params = jsonparse(process.env.Temp_Params);
if (providerAliasKeys.includes(accessAlias) && !Temp_Params.f) {
const tempArgv = getServerlessDevsTempArgv();
if (providerAliasKeys.includes(accessAlias) && !tempArgv.find((i) => i === '-f')) {
const option = [
{
type: 'list',
Expand Down
10 changes: 4 additions & 6 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import report from '../common/report';

export const logger = new Logger('S-CORE');

export const jsonparse = (value) => {
export function getServerlessDevsTempArgv() {
try {
const data = JSON.parse(value);
return typeof data === 'object' ? data : {};
return JSON.parse(process.env.serverless_devs_temp_argv);
} catch (error) {
return {};
return [];
}
};

}
export const merge = require('lodash.merge');

export const isUndefined = (obj: any): obj is undefined => typeof obj === 'undefined';
Expand Down

0 comments on commit 2d68805

Please sign in to comment.