Skip to content

Implement Aliyun CDN API V3 signature with DescribeRefreshTasks and RefreshObjectCaches endpoints#6

Merged
daflyinbed merged 11 commits intoaliyunfrom
copilot/implement-aliyun-api-signature
Jan 15, 2026
Merged

Implement Aliyun CDN API V3 signature with DescribeRefreshTasks and RefreshObjectCaches endpoints#6
daflyinbed merged 11 commits intoaliyunfrom
copilot/implement-aliyun-api-signature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 11, 2026

Adds Aliyun CDN API integration with V3 signature authentication for querying and managing CDN refresh tasks.

Core Changes

Signature Module (src/aliyun/signature.rs)

  • HMAC-SHA256 V3 signature algorithm with RFC 3986 percent encoding
  • Automatic parameter sorting via BTreeMap (Aliyun requirement)
  • Signature key format: {AccessKeySecret}&

CDN Client (src/aliyun/cdn.rs)

  • AliyunCdnClient::describe_refresh_tasks() with full parameter support for querying refresh tasks
  • AliyunCdnClient::refresh_object_caches() for submitting new CDN cache refresh requests
  • Response parsing with proper field mapping for Aliyun's response structure

API Endpoints (src/routes/aliyun_handlers.rs)

  • JWT-protected POST /api/aliyun/describeRefreshTasks for querying refresh tasks
  • JWT-protected POST /api/aliyun/refreshObjectCaches for submitting cache refresh requests
  • OpenAPI documentation with complete schemas for both endpoints

Configuration (src/config.rs)

  • Added AliyunConfig with access_key_id and access_key_secret

Usage

// Configuration
[aliyun]
access_key_id = "LTAI5t..."
access_key_secret = "xxxxx"

// Query refresh tasks
POST /api/aliyun/describeRefreshTasks
Authorization: Bearer <jwt_token>
{
  "page_number": 1,
  "page_size": 20,
  "status": "Complete"
}

// Submit refresh request
POST /api/aliyun/refreshObjectCaches
Authorization: Bearer <jwt_token>
{
  "object_path": "http://example.com/path/to/file.js",
  "object_type": "File",
  "area": "domestic"
}

Dependencies

  • sha2, hmac, base64: Signature cryptography
  • urlencoding: URL encoding utilities

Notes

  • Uses r#gen() due to Rust 2024 edition gen keyword reservation
  • Fixed double URL encoding in query string construction (parameters pre-encoded during signing)
  • Designed for extensibility—AliyunSigner can be reused for other Aliyun APIs
Original prompt

This section details on the original issue you should resolve

<issue_title>实现阿里云接口签名及DescribeRefreshTasks API</issue_title>
<issue_description>## 目标
实现阿里云接口的签名方法和"刷新任务查询"的API调用。

参考文档

要求

  1. 完成阿里云标准V3接口签名算法的实现(处理时间戳、AccessKey、签名字符串构建与加密等)。
  2. 封装DescribeRefreshTasks的API,允许调用并传递请求参数,处理返回结果。
  3. 代码需有适当注释,并考虑后续扩展支持更多接口。</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes daflyinbed/janus#4

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Jan 11, 2026
Copilot AI and others added 3 commits January 11, 2026 15:23
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>
Copilot AI changed the title [WIP] Implement Alibaba Cloud API signature and DescribeRefreshTasks Implement Aliyun CDN API V3 signature and DescribeRefreshTasks endpoint Jan 11, 2026
Copilot AI requested a review from daflyinbed January 11, 2026 15:32
@daflyinbed
Copy link
Copy Markdown
Collaborator

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 14, 2026

@copilot https://help.aliyun.com/zh/cdn/developer-reference/api-cdn-2018-05-10-refreshobjectcaches 实现这个接口

Implemented RefreshObjectCaches API in commit bdef3c4. The endpoint is available at POST /api/aliyun/refreshObjectCaches with the following parameters:

  • object_path (required): Object paths to refresh (separated by newlines, max 1000 URLs or 100 directories)
  • object_type (optional): "File" for file refresh or "Directory" for directory refresh
  • area (optional): "domestic" or "overseas" for region-specific refresh

The API is JWT-protected and fully documented in the OpenAPI schema.

Copilot AI changed the title Implement Aliyun CDN API V3 signature and DescribeRefreshTasks endpoint Implement Aliyun CDN API V3 signature with DescribeRefreshTasks and RefreshObjectCaches endpoints Jan 14, 2026
@daflyinbed daflyinbed requested a review from Copilot January 14, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DescribeRefreshTasks and RefreshObjectCaches endpoints
  • 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
/// 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)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
#[serde(skip_serializing_if = "Option::is_none")]
pub object_type: Option<String>,

/// Whether to directly delete CDN cache nodes (default false)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
#[serde(skip_serializing_if = "Option::is_none")]
pub object_type: Option<String>,

/// Whether to directly delete CDN cache nodes (default false)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as Comment 3 - documentation mentions 'default false' but no #[serde(default)] is applied to enforce this default.

Copilot uses AI. Check for mistakes.
@daflyinbed daflyinbed changed the base branch from main to aliyun January 15, 2026 03:15
@daflyinbed daflyinbed marked this pull request as ready for review January 15, 2026 03:15
@daflyinbed daflyinbed merged commit 2235925 into aliyun Jan 15, 2026
8 checks passed
@daflyinbed
Copy link
Copy Markdown
Collaborator

close #4

@daflyinbed daflyinbed deleted the copilot/implement-aliyun-api-signature branch January 19, 2026 06:17
daflyinbed added a commit that referenced this pull request Jan 19, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

实现阿里云接口签名及DescribeRefreshTasks API

3 participants