Implement Aliyun CDN API V3 signature with DescribeRefreshTasks and RefreshObjectCaches endpoints#6
Conversation
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Implemented RefreshObjectCaches API in commit bdef3c4. The endpoint is available at
The API is JWT-protected and fully documented in the OpenAPI schema. |
There was a problem hiding this comment.
Pull request overview
This PR implements Aliyun CDN API integration with V3 signature authentication, enabling CDN cache refresh task querying and submission. The implementation follows Aliyun's official API documentation and adds comprehensive API endpoints with JWT authentication.
Changes:
- Implements ACS3-HMAC-SHA256 signature algorithm for Aliyun API authentication
- Adds CDN client with
DescribeRefreshTasksandRefreshObjectCachesendpoints - Integrates JWT-protected HTTP handlers with OpenAPI documentation
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/aliyun/signature.rs | Implements V3 signature algorithm with RFC 3986 percent encoding and HMAC-SHA256 |
| src/aliyun/cdn.rs | CDN client with methods for querying and submitting cache refresh tasks |
| src/aliyun/mod.rs | Module structure exposing public API types |
| src/routes/aliyun_handlers.rs | JWT-protected HTTP handlers for CDN API endpoints |
| src/routes/mod.rs | Route registration and OpenAPI schema integration |
| src/config.rs | Aliyun configuration with access key credentials |
| src/state.rs | Application state updated with Aliyun config |
| src/lib.rs | Module visibility for aliyun package |
| src/tracing.rs | Updates module whitelist from template name to actual project name |
| example.toml | Configuration example for Aliyun credentials |
| Cargo.toml | Adds sha2 and hmac dependencies |
| Cargo.lock | Dependency lock file updates |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Request payload for refresh object caches endpoint | ||
| #[derive(ToSchema, Serialize, Deserialize, Debug)] | ||
| pub struct RefreshObjectCachesPayload { | ||
| /// Object paths to refresh (separated by newlines, max 1000 URLs or 100 directories per request) |
There was a problem hiding this comment.
The documentation states paths are 'separated by newlines', but the field is a single String without validation or parsing logic. This could be misleading. Consider either adding validation to ensure the format is correct, or clarifying in the documentation that the caller is responsible for formatting multiple paths correctly.
| /// Reference: https://help.aliyun.com/zh/cdn/developer-reference/api-cdn-2018-05-10-refreshobjectcaches | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct RefreshObjectCachesRequest { | ||
| /// Object paths to refresh (separated by newlines, max 1000 URLs or 100 directories per request) |
There was a problem hiding this comment.
Same as Comment 1 - the documentation mentions newline separation but there's no validation or parsing. The documentation should clarify that formatting is the caller's responsibility, or validation should be added.
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub object_type: Option<String>, | ||
|
|
||
| /// Whether to directly delete CDN cache nodes (default false) |
There was a problem hiding this comment.
The documentation states 'default false', but this is an Option field with no actual default value applied. If false is truly the default, consider using #[serde(default)] to apply it automatically, or update the documentation to clarify this is Aliyun's API default, not the struct's default.
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub object_type: Option<String>, | ||
|
|
||
| /// Whether to directly delete CDN cache nodes (default false) |
There was a problem hiding this comment.
Same as Comment 3 - documentation mentions 'default false' but no #[serde(default)] is applied to enforce this default.
|
close #4 |
… and RefreshObjectCaches endpoints (#6) * Initial plan * Implement Aliyun API signature and DescribeRefreshTasks API Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com> * Fix double URL encoding in CDN query string Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com> * Apply rustfmt formatting Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com> * fix: tracing whitelist * fix: aliyun signature * refactor: aliyun signature * fmt * Add RefreshObjectCaches API implementation Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com> * fix * fix --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com> Co-authored-by: 夕舞八弦 <1677759063@qq.com>
Adds Aliyun CDN API integration with V3 signature authentication for querying and managing CDN refresh tasks.
Core Changes
Signature Module (
src/aliyun/signature.rs)BTreeMap(Aliyun requirement){AccessKeySecret}&CDN Client (
src/aliyun/cdn.rs)AliyunCdnClient::describe_refresh_tasks()with full parameter support for querying refresh tasksAliyunCdnClient::refresh_object_caches()for submitting new CDN cache refresh requestsAPI Endpoints (
src/routes/aliyun_handlers.rs)POST /api/aliyun/describeRefreshTasksfor querying refresh tasksPOST /api/aliyun/refreshObjectCachesfor submitting cache refresh requestsConfiguration (
src/config.rs)AliyunConfigwithaccess_key_idandaccess_key_secretUsage
Dependencies
sha2,hmac,base64: Signature cryptographyurlencoding: URL encoding utilitiesNotes
r#gen()due to Rust 2024 editiongenkeyword reservationAliyunSignercan be reused for other Aliyun APIsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.