Skip to content

Commit 1dc662f

Browse files
committed
fix: readOnly、bucketPath、mountDir、rules
1 parent d2f1a3b commit 1dc662f

5 files changed

Lines changed: 28 additions & 10 deletions

File tree

__tests__/e2e/nodejs/s_oss_config_auto.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ resources:
3030
handler: index.handler
3131
memorySize: 128
3232
timeout: 60
33-
ossMountConfig: auto|rules=[{"allowedOrigin":"*","allowedMethod":"GET","allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]
33+
ossMountConfig: auto|readOnly=true|mountDir=/mnt/test-oss-bucket|bucketPath=/|rules=[{"allowedOrigin":"*","allowedMethod":["GET","POST","PUT","DELETE","HEAD"],"allowedHeader":"*","exposeHeader":"Content-Length","maxAgeSeconds":30}]

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,12 @@ describe('Service', () => {
736736

737737
// Mock OSS
738738
const mockOss = {
739-
deploy: jest.fn().mockResolvedValue({ ossBucket: 'test-oss-bucket' }),
739+
deploy: jest.fn().mockResolvedValue({
740+
ossBucket: 'test-oss-bucket',
741+
readOnly: false,
742+
mountDir: '/mnt/test-oss-bucket',
743+
bucketPath: '/',
744+
}),
740745
};
741746

742747
// Mock the OSS constructor to return our mock instance
@@ -759,6 +764,7 @@ describe('Service', () => {
759764
bucketName: 'test-oss-bucket',
760765
endpoint: 'http://oss-cn-hangzhou-internal.aliyuncs.com',
761766
readOnly: false,
767+
bucketPath: '/',
762768
},
763769
],
764770
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@serverless-cd/srm-aliyun-pop-core": "^0.0.8-beta.1",
3030
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",
3131
"@serverless-cd/srm-aliyun-sls20201230": "0.0.5-beta.3",
32-
"@serverless-cd/srm-aliyun-oss": "^0.0.1-beta.7",
32+
"@serverless-cd/srm-aliyun-oss": "^0.0.1-beta.8",
3333
"@serverless-devs/diff": "^0.0.3-beta.6",
3434
"@serverless-devs/downloads": "^0.0.7",
3535
"@serverless-devs/load-component": "^0.0.9",

src/resources/oss/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ export default class OSS {
2121
this.client = new Oss(logger);
2222
}
2323

24-
async deploy(ossMountConfig = 'auto'): Promise<{ ossBucket: string }> {
24+
async deploy(ossMountConfig = 'auto'): Promise<{
25+
ossBucket: string;
26+
readOnly?: boolean;
27+
mountDir?: string;
28+
bucketPath?: string;
29+
}> {
2530
logger.debug(`init oss: ${JSON.stringify(this.config)}`);
2631
const result = await this.client.initOss(this.config, ossMountConfig);
2732
const ossBucket = result?.ossBucket || '';
33+
const readOnly = result?.readOnly || false;
34+
const mountDir = result?.mountDir || `/mnt/${ossBucket}`;
35+
const bucketPath = result?.bucketPath || `/`;
2836
if (isAppCenter()) {
2937
logger.info(`created oss region: ${this.region};`);
3038
} else {
3139
logger.spin('creating', 'oss', `region: ${this.region}; ossBucket: ${ossBucket}`);
3240
}
33-
return { ossBucket };
41+
return { ossBucket, readOnly, mountDir, bucketPath };
3442
}
3543
}

src/subCommands/deploy/impl/function.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,25 +373,29 @@ logConfig:
373373
}
374374
logger.info(`ossAuto code to ${ossEndpoint}`);
375375
const oss = new OSS(region, credential as ICredentials, ossEndpoint);
376-
const { ossBucket } = await oss.deploy(this.inputs.props.ossMountConfig as string);
376+
const { ossBucket, readOnly, mountDir, bucketPath } = await oss.deploy(
377+
this.inputs.props.ossMountConfig as string,
378+
);
377379

378380
logger.write(
379381
yellow(`Created oss resource succeeded, please replace ossMountConfig: auto in yaml with:
380382
ossMountConfig:
381383
mountPoints:
382-
- mountDir: /mnt/${ossBucket}
384+
- mountDir: ${mountDir}
383385
bucketName: ${ossBucket}
384386
endpoint: http://oss-${region}-internal.aliyuncs.com
385-
readOnly: false\n`),
387+
readOnly: ${readOnly}
388+
bucketPath: ${bucketPath}\n`),
386389
);
387390
this.createResource.oss = { ossBucket };
388391
_.set(this.local, 'ossMountConfig', {
389392
mountPoints: [
390393
{
391-
mountDir: `/mnt/${ossBucket}`,
394+
mountDir,
392395
bucketName: ossBucket,
393396
endpoint: `http://oss-${region}-internal.aliyuncs.com`,
394-
readOnly: false,
397+
readOnly,
398+
bucketPath,
395399
},
396400
],
397401
});

0 commit comments

Comments
 (0)