Skip to content

Commit 8f409a5

Browse files
CopilotBlankll
andauthored
feat: Migrate Aliyun OSS Bucket to Terraform-like state engine (#145)
- [x] Add `ALIYUN_OSS_BUCKET` to `ResourceTypeEnum` in `src/types/domains/state.ts` - [x] Create `ossOperations.ts` in `src/common/aliyunClient/` - OSS SDK operations wrapper - [x] Update `src/common/aliyunClient/index.ts` to use OSS operations - [x] Create `ossTypes.ts` - Type definitions for OSS bucket config and conversion functions - [x] Create `ossResource.ts` - CRUD lifecycle with state management - [x] Create `ossPlanner.ts` - Plan generation for bucket operations - [x] Create `ossExecutor.ts` - Plan execution for bucket operations - [x] Update `src/stack/aliyunStack/index.ts` to export new OSS modules - [x] Create unit tests for ossTypes and ossPlanner - [x] Run linting and build to verify changes - [x] Run code review and address feedback - [x] Run CodeQL security check (no issues found) ## Code Review Feedback Addressed: - [x] Extracted ACL type to shared `BucketACL` enum in `src/stack/bucketTypes.ts` - [x] Created `CommonBucketConfig`, `CommonBucketInfo`, and `CommonBucketInstance` shared types - [x] Expanded `OssBucketInfo` to include comprehensive bucket information (owner, storage class, data redundancy, CORS, lifecycle, logging, etc.) - [x] Changed `beforeEach` to `afterEach` in `ossPlanner.test.ts` - [x] Removed duplicated property assignments in `ossTypes.ts` ## Security Summary No security vulnerabilities were discovered by CodeQL analysis. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[MIGRATION] Migrate Aliyun OSS Bucket Resource to Terraform-like State Engine</issue_title> > <issue_description>## Summary > Migrate Aliyun OSS bucket resource management from ROS template-based deployment to the unified Terraform-like state management engine. > > ## Background > Currently, Aliyun OSS buckets are managed via ROS CDK constructs in `src/stack/rosStack/bucket.ts`. This needs to be refactored to use the state-based workflow. > > ## Current Implementation (to be migrated) > - **File**: [`src/stack/rosStack/bucket.ts`](https://github.com/geek-fun/serverlessinsight/blob/master/src/stack/rosStack/bucket.ts) > - Uses `@alicloud/ros-cdk-oss`, `@alicloud/ros-cdk-ossdeployment`, `@alicloud/ros-cdk-dns`, `@alicloud/ros-cdk-ram` > - Handles: ACL configuration, website hosting, static file deployment, custom domains, DNS records > > ## Target Implementation > Create new modules under `src/stack/aliyunStack/`: > - **Provider**: `ossProvider.ts` - Aliyun OSS SDK operations > - **Types**: `ossTypes.ts` - Type definitions and config hash > - **Resource**: `ossResource.ts` - CRUD lifecycle with state management > - **Planner**: `ossPlanner.ts` - Plan generation > - **Executor**: `ossExecutor.ts` - Plan execution > > ## Requirements > > ### 1. Create Aliyun OSS Provider (`ossProvider.ts`) > ```typescript > export const createOssBucket = async (context: Context, config: OssBucketConfig): Promise<void> > export const getOssBucket = async (context: Context, bucketName: string): Promise<OssBucketInfo | null> > export const updateOssBucket = async (context: Context, config: OssBucketConfig): Promise<void> > export const deleteOssBucket = async (context: Context, bucketName: string): Promise<void> > export const uploadStaticFiles = async (context: Context, bucketName: string, sourcePath: string): Promise<void> > ``` > Use `ali-oss` SDK instead of ROS CDK. > > ### 2. Create OSS Types (`ossTypes.ts`) > ```typescript > export type OssBucketConfig = { > BucketName: string; > ACL: 'private' | 'public-read' | 'public-read-write'; > Website?: { IndexDocument: string; ErrorDocument: string; ErrorCode: number }; > Domain?: string; > }; > export const bucketToOssConfig = (bucket: BucketDomain): OssBucketConfig => { ... }; > export const computeBucketConfigHash = (config: OssBucketConfig): string => { ... }; > ``` > > ### 3. Handle Features > - ACL management (private, public-read, public-read-write) > - Website hosting configuration > - Static file deployment from local path > - Custom domain binding with DNS records > - Server-side encryption > > ### 4. Update State Types > Add `ALIYUN_OSS_BUCKET` to `ResourceTypeEnum` in `src/types/domains/state.ts` > > ## Acceptance Criteria > - [ ] OSS buckets can be created, updated, and deleted via state management > - [ ] Website hosting and static file deployment works > - [ ] Custom domain configuration works > - [ ] State file tracks bucket resources with config hash > - [ ] Drift detection works for bucket configuration changes > > ## References > - Current ROS implementation: [`src/stack/rosStack/bucket.ts`](https://github.com/geek-fun/serverlessinsight/blob/master/src/stack/rosStack/bucket.ts) > - Tencent COS pattern: [`src/stack/scfStack/cosPlanner.ts`](https://github.com/geek-fun/serverlessinsight/blob/master/src/stack/scfStack/cosPlanner.ts) > - Aliyun OSS SDK: https://help.aliyun. com/document_detail/32067.html</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #126 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/geek-fun/serverlessinsight/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Blankll <28639911+Blankll@users.noreply.github.com>
1 parent b6c5b47 commit 8f409a5

File tree

12 files changed

+1391
-14
lines changed

12 files changed

+1391
-14
lines changed

package-lock.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/aliyunClient/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import { createRamOperations } from './ramOperations';
1313
import { createEcsOperations } from './ecsOperations';
1414
import { createNasOperations } from './nasOperations';
1515
import { createApigwOperations } from './apigwOperations';
16+
import { createOssOperations } from './ossOperations';
1617

1718
export * from './types';
1819
export * from './apigwOperations';
20+
export * from './ossOperations';
1921

2022
const initializeSdkClients = (context: Context) => {
2123
const baseConfig = {
@@ -76,7 +78,7 @@ export const createAliyunClient = (context: Context) => {
7678
ram: createRamOperations(sdkClients.ram),
7779
ecs: createEcsOperations(sdkClients.ecs, context),
7880
nas: createNasOperations(sdkClients.nas),
79-
oss: sdkClients.oss,
81+
oss: createOssOperations(sdkClients.oss, context.region),
8082
apigw: createApigwOperations(sdkClients.apigw),
8183
};
8284
};

0 commit comments

Comments
 (0)