Skip to content

Commit 344626d

Browse files
authored
Merge pull request #107 from devsapp/fix-userAgent
fix: userAgent and Convert a running instance to an elastic instance
2 parents ec0af03 + 8fa2ce3 commit 344626d

File tree

24 files changed

+1062
-115
lines changed

24 files changed

+1062
-115
lines changed

__tests__/ut/commands/deploy/impl/provision_config_test.ts

Lines changed: 301 additions & 33 deletions
Large diffs are not rendered by default.

__tests__/ut/commands/deploy/impl/scaling_config_test.ts

Lines changed: 613 additions & 16 deletions
Large diffs are not rendered by default.

__tests__/ut/commands/layer_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ jest.mock('../../../src/utils', () => ({
122122
tableShow: jest.fn(),
123123
calculateCRC64: jest.fn(),
124124
getFileSize: jest.fn(),
125+
isAppCenter: jest.fn(),
125126
}));
126127

127128
describe('Layer', () => {
@@ -264,6 +265,7 @@ describe('Layer', () => {
264265
_: ['list'],
265266
region: 'cn-hangzhou',
266267
});
268+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
267269
});
268270

269271
it('should list layers successfully', async () => {
@@ -394,6 +396,7 @@ describe('Layer', () => {
394396
'layer-name': 'test-layer',
395397
'version-id': '1',
396398
});
399+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
397400
});
398401

399402
it('should get layer info successfully', async () => {
@@ -457,6 +460,7 @@ describe('Layer', () => {
457460
region: 'cn-hangzhou',
458461
'layer-name': 'test-layer',
459462
});
463+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
460464
});
461465

462466
it('should list layer versions successfully', async () => {
@@ -508,6 +512,7 @@ describe('Layer', () => {
508512
code: './code',
509513
'compatible-runtime': 'nodejs12,nodejs14',
510514
});
515+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
511516
});
512517

513518
it('should publish layer successfully', async () => {
@@ -650,6 +655,7 @@ describe('Layer', () => {
650655
'layer-name': 'test-layer',
651656
'assume-yes': true,
652657
});
658+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
653659
});
654660

655661
it('should remove all layer versions successfully', async () => {
@@ -728,6 +734,7 @@ describe('Layer', () => {
728734
'layer-name': 'test-layer',
729735
'version-id': '1',
730736
});
737+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
731738
});
732739

733740
it('should download layer successfully', async () => {
@@ -795,6 +802,7 @@ describe('Layer', () => {
795802
'layer-name': 'test-layer',
796803
public: true,
797804
});
805+
(require('../../../src/utils').isAppCenter as jest.Mock).mockReturnValue(false);
798806
});
799807

800808
it('should set layer acl successfully', async () => {

__tests__/ut/commands/scaling/index_test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jest.mock('../../../../src/resources/fc', () => {
1919
// Mock utils
2020
jest.mock('../../../../src/utils', () => ({
2121
promptForConfirmOrDetails: jest.fn(),
22+
isAppCenter: jest.fn(),
2223
}));
2324

2425
describe('Scaling', () => {

__tests__/ut/commands/session_test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jest.mock('../../../src/logger', () => ({
1616
}));
1717
jest.mock('../../../src/utils', () => ({
1818
promptForConfirmOrDetails: jest.fn(),
19+
isAppCenter: jest.fn(),
1920
}));
2021

2122
describe('Session', () => {

__tests__/ut/commands/version_test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jest.mock('../../../src/logger', () => {
2929

3030
jest.mock('../../../src/utils', () => ({
3131
promptForConfirmOrDetails: jest.fn(),
32+
isAppCenter: jest.fn(),
3233
}));
3334

3435
describe('Version', () => {

src/subCommands/alias/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import _ from 'lodash';
44
import logger from '../../logger';
55
import FC from '../../resources/fc';
66
import commandsHelp from '../../commands-help/alias';
7-
import { promptForConfirmOrDetails, tableShow } from '../../utils';
7+
import { isAppCenter, promptForConfirmOrDetails, tableShow } from '../../utils';
88

99
const commandsList = Object.keys(commandsHelp.subCommands);
1010

@@ -70,11 +70,12 @@ export default class Alias {
7070
this.versionId = versionId;
7171
this.additionalVersionWeight = additionalVersionWeight;
7272

73+
const function_ai = isAppCenter() ? 'function_ai;' : '';
7374
this.fcSdk = new FC(this.region, inputs.credential, {
7475
endpoint: inputs.props.endpoint,
7576
userAgent: `${
7677
inputs.userAgent ||
77-
`Component:fc3;Nodejs:${process.version};OS:${process.platform}-${process.arch}`
78+
`${function_ai}Component:fc3;Nodejs:${process.version};OS:${process.platform}-${process.arch}`
7879
}command:alias`,
7980
});
8081
}

src/subCommands/build/impl/defaultBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ export class DefaultBuilder extends Builder {
112112
logger.debug(`${region}`);
113113
checkRegion(region);
114114
const credential = (await this.inputs.getCredential()) as ICredentials;
115+
const function_ai = isAppCenter() ? 'function_ai;' : '';
115116
const fcSdk = new FC(region, credential, {
116117
endpoint: this.getProps().endpoint,
117118
userAgent: `${
118119
this.inputs.userAgent ||
119-
`Component:fc3;Nodejs:${process.version};OS:${process.platform}-${process.arch}`
120+
`${function_ai}Component:fc3;Nodejs:${process.version};OS:${process.platform}-${process.arch}`
120121
}command:build-publish-layer`,
121122
});
122123
let buildDir: string = this.getBuildDir();

src/subCommands/deploy/impl/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { ICredentials } from '@serverless-devs/component-interface';
22
import { IInputs } from '../../../interface';
33
import FC from '../../../resources/fc';
4+
import { isAppCenter } from '../../../utils';
45

56
export default abstract class Base {
67
readonly fcSdk: FC;
78
needDeploy: boolean | undefined;
89

910
constructor(readonly inputs: IInputs, needDeploy: boolean | undefined) {
1011
this.needDeploy = needDeploy;
12+
const function_ai = isAppCenter() ? 'function_ai;' : '';
1113
this.fcSdk = new FC(inputs.props.region, inputs.credential as ICredentials, {
1214
endpoint: inputs.props.endpoint,
1315
userAgent: `${
1416
inputs.userAgent ||
15-
`Component:fc3;Nodejs:${process.version};OS:${process.platform}-${process.arch}`
17+
`${function_ai}Component:fc3;Nodejs:${process.version};OS:${process.platform}-${process.arch}`
1618
}command:deploy`,
1719
});
1820
}

src/subCommands/deploy/impl/provision_config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { IInputs } from '../../../interface';
66
import logger from '../../../logger';
77
import Base from './base';
88
import { sleep } from '../../../utils';
9+
import ScalingConfig from './scaling_config';
910
// import Logs from '../../logs';
1011

1112
interface IOpts {
@@ -17,6 +18,7 @@ export default class ProvisionConfig extends Base {
1718
remote: any;
1819
ProvisionMode: string;
1920
readonly functionName: string;
21+
scalingConfig: ScalingConfig;
2022

2123
constructor(inputs: IInputs, opts: IOpts) {
2224
super(inputs, opts.yes);
@@ -28,6 +30,9 @@ export default class ProvisionConfig extends Base {
2830
this.ProvisionMode = _.get(this.local, 'mode', 'sync');
2931
_.unset(this.local, 'mode');
3032
logger.debug(`need deploy provisionConfig: ${JSON.stringify(provisionConfig)}`);
33+
this.scalingConfig = new ScalingConfig(inputs, {
34+
yes: opts.yes,
35+
});
3136
}
3237

3338
async before() {
@@ -46,7 +51,11 @@ export default class ProvisionConfig extends Base {
4651

4752
if (!_.isEmpty(localConfig)) {
4853
if (this.needDeploy) {
49-
await this.fcSdk.putFunctionProvisionConfig(this.functionName, qualifier, localConfig);
54+
await this.scalingConfig.provisionConfigErrorRetry(
55+
'ProvisionConfig',
56+
qualifier,
57+
localConfig,
58+
);
5059

5160
if (this.ProvisionMode === 'sync' || this.ProvisionMode === 'drain') {
5261
await this.waitForProvisionReady(qualifier, localConfig);

0 commit comments

Comments
 (0)