Skip to content

<fix>[vm]: <description#3453

Open
ZStack-Robot wants to merge 1 commit intofeature-zsv-5.0.0-zmigratefrom
sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3
Open

<fix>[vm]: <description#3453
ZStack-Robot wants to merge 1 commit intofeature-zsv-5.0.0-zmigratefrom
sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3

Conversation

@ZStack-Robot
Copy link
Collaborator

APIImpact

Resolves: ZSV-1000

Change-Id: I616767657867766b7170767463756e7777626574

sync from gitlab !9311

@MatheMatrix MatheMatrix force-pushed the sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3 branch 2 times, most recently from ae4446d to 304917a Compare March 10, 2026 14:06
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

将 Ceph 备份存储中的 URL、SSH 用户名和远程路径校验逻辑从 CephBackupStorageBase 中移除并统一委托给新增的公用类 RemotePathValidator,并在相关调用点改为使用该类的校验与提取方法以统一错误信息流。

Changes

Cohort / File(s) Summary
验证工具扩展
utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java
新增公有常量 ALLOWED_URL_SCHEMES,并添加 validateUrlSchemeextractUrlSchemevalidateSshUsernamevalidateFilePaths 等方法,用于统一处理 URL/SSH 用户名/远程路径校验并返回标准错误信息。
备份存储重构
plugin/ceph/src/main/java/org/zstack/storage/ceph/backup/CephBackupStorageBase.java
移除类内硬编码的 URL scheme 常量和 SSH 用户名正则,替换为调用 RemotePathValidator.validateUrlScheme / extractUrlSchemevalidateSshUsernamevalidateFilePathsvalidateRemotePath 等方法;相应地调整上传/下载/删除/软件升级部署等校验与错误流。

Sequence Diagram(s)

(本次变更为校验逻辑集中与调用点调整,未引入新的跨组件顺序流程,故省略序列图。)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 我在代码草原轻跳,
把散落校验编成绳;
一个验证器把门把守,
URL 与用户名安宁,
小步轻点,部署无惊。

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive PR标题不完整且没有有意义的描述信息,仅包含"[vm]: <description",无法清楚表达主要变更内容。 请完成PR标题,提供清晰具体的描述,例如"[vm]: Consolidate RemotePathValidator for URL and SSH validation"以准确反映关键变更。
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed PR描述包含"APIImpact"、"ZSV-1000"和"gitlab !9311"等内容,与代码变更相关,虽然简洁但确实涉及变更内容。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3

Comment @coderabbitai help to get the list of available commands and usage tips.

@MatheMatrix MatheMatrix force-pushed the sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3 branch from 304917a to 36509a3 Compare March 10, 2026 14:07
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java`:
- Around line 70-85: validateUrlScheme currently throws NPE for null input, uses
upload-specific wording, and returns a scheme with original casing that can
mismatch agent expectations; fix by first null/empty-checking the url (trim and
if null/empty return a generic error like "URL [%s] is missing or empty"), then
try new URI(url) catching URISyntaxException and returning "failed to parse URL
[%s]: %s", normalize the extracted scheme to lower-case before validating
against ALLOWED_URL_SCHEMES (use scheme = scheme.toLowerCase(Locale.ROOT)), and
change any "upload URL" wording in validateUrlScheme (and ensure
extractUrlScheme returns the lower-cased scheme) so messages are generic to both
upload/download and consistent with agent-side lower-case comparisons.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f8da8936-6941-4ea1-8af7-3b9d0b40ca8d

📥 Commits

Reviewing files that changed from the base of the PR and between f44f1a0 and 36509a3.

📒 Files selected for processing (2)
  • plugin/ceph/src/main/java/org/zstack/storage/ceph/backup/CephBackupStorageBase.java
  • utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java

@MatheMatrix MatheMatrix force-pushed the sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3 branch from 36509a3 to f01a99e Compare March 11, 2026 01:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java (1)

108-114: 可选优化:null 值时的错误消息格式

usernamenull 时,错误消息会显示 "SSH username [null] is invalid...", 建议分离处理以提供更清晰的错误提示。

♻️ 可选改进
     public static String validateSshUsername(String username) {
-        if (username == null || !SSH_USERNAME_PATTERN.matcher(username).matches()) {
-            return String.format("SSH username [%s] is invalid, only alphanumeric characters, dots, hyphens, underscores and trailing dollar sign are allowed",
-                    username);
+        if (username == null || username.isEmpty()) {
+            return "SSH username cannot be null or empty";
+        }
+        if (!SSH_USERNAME_PATTERN.matcher(username).matches()) {
+            return String.format("SSH username [%s] is invalid, only alphanumeric characters, dots, hyphens, underscores and trailing dollar sign are allowed",
+                    username);
         }
         return null;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java` around
lines 108 - 114, The validateSshUsername method currently embeds the literal
"null" in its error message when username is null; update validateSshUsername to
handle the null case separately (check username == null first) and return a
clearer message like "SSH username is required" or similar, otherwise keep the
existing pattern check using SSH_USERNAME_PATTERN and the current formatted
message for non-null invalid values; reference validateSshUsername and
SSH_USERNAME_PATTERN when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java`:
- Around line 108-114: The validateSshUsername method currently embeds the
literal "null" in its error message when username is null; update
validateSshUsername to handle the null case separately (check username == null
first) and return a clearer message like "SSH username is required" or similar,
otherwise keep the existing pattern check using SSH_USERNAME_PATTERN and the
current formatted message for non-null invalid values; reference
validateSshUsername and SSH_USERNAME_PATTERN when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 10d105ed-9f86-461e-ad64-3e8e75dc3d5d

📥 Commits

Reviewing files that changed from the base of the PR and between 36509a3 and f01a99e.

📒 Files selected for processing (2)
  • plugin/ceph/src/main/java/org/zstack/storage/ceph/backup/CephBackupStorageBase.java
  • utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java

Resolves: ZSV-11449

Change-Id: I616767657867766b7170767463756e7777626574
@MatheMatrix MatheMatrix force-pushed the sync/tao.gan/zmigrate-imagestore-ZSV-1000@@3 branch from f01a99e to 4c20fbc Compare March 11, 2026 02:17
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java (2)

85-85: 建议统一使用 Locale.ROOT 进行大小写转换。

validateUrlScheme 中使用 scheme.toLowerCase()extractUrlScheme 中使用 scheme.toLowerCase(Locale.ROOT),存在不一致。虽然对 ASCII 字符(http/https/ftp/sftp)不会产生实际影响,但为了一致性和避免在某些语言环境下的潜在问题(如土耳其语),建议统一使用 Locale.ROOT

♻️ 建议修改
-        if (!ALLOWED_URL_SCHEMES.contains(scheme.toLowerCase())) {
+        if (!ALLOWED_URL_SCHEMES.contains(scheme.toLowerCase(Locale.ROOT))) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java` at line
85, The code uses different locale-aware lowercasing: replace the call to
scheme.toLowerCase() in validateUrlScheme with scheme.toLowerCase(Locale.ROOT)
so it matches extractUrlScheme and avoids locale-dependent behavior; update any
comparisons against ALLOWED_URL_SCHEMES to use the normalized value (e.g.,
lowercased with Locale.ROOT) to ensure consistency between validateUrlScheme and
extractUrlScheme.

108-114: 实现正确,null 显示可优化。

验证逻辑正确。当 usernamenull 时,错误信息会显示为 "SSH username [null] is invalid",虽然功能上没有问题,但可以考虑优化显示效果。

♻️ 可选优化
     public static String validateSshUsername(String username) {
-        if (username == null || !SSH_USERNAME_PATTERN.matcher(username).matches()) {
-            return String.format("SSH username [%s] is invalid, only alphanumeric characters, dots, hyphens, underscores and trailing dollar sign are allowed",
-                    username);
+        if (username == null) {
+            return "SSH username cannot be null";
+        }
+        if (!SSH_USERNAME_PATTERN.matcher(username).matches()) {
+            return String.format("SSH username [%s] is invalid, only alphanumeric characters, dots, hyphens, underscores and trailing dollar sign are allowed", username);
         }
         return null;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java` around
lines 108 - 114, The error message in validateSshUsername currently prints
"null" when username is null; update the formatting to display a clearer value
(e.g. empty string or placeholder) instead of the literal "null". In the
validateSshUsername method, replace the current String.format usage with a safer
conversion (for example using Objects.toString(username, "") or a ternary
username == null ? "<empty>" : username) so the log shows a friendly placeholder
rather than "null" while keeping the rest of the validation and
SSH_USERNAME_PATTERN logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java`:
- Line 85: The code uses different locale-aware lowercasing: replace the call to
scheme.toLowerCase() in validateUrlScheme with scheme.toLowerCase(Locale.ROOT)
so it matches extractUrlScheme and avoids locale-dependent behavior; update any
comparisons against ALLOWED_URL_SCHEMES to use the normalized value (e.g.,
lowercased with Locale.ROOT) to ensure consistency between validateUrlScheme and
extractUrlScheme.
- Around line 108-114: The error message in validateSshUsername currently prints
"null" when username is null; update the formatting to display a clearer value
(e.g. empty string or placeholder) instead of the literal "null". In the
validateSshUsername method, replace the current String.format usage with a safer
conversion (for example using Objects.toString(username, "") or a ternary
username == null ? "<empty>" : username) so the log shows a friendly placeholder
rather than "null" while keeping the rest of the validation and
SSH_USERNAME_PATTERN logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f5a7ceab-818b-4312-bb4a-165c52d7d987

📥 Commits

Reviewing files that changed from the base of the PR and between f01a99e and 4c20fbc.

📒 Files selected for processing (2)
  • plugin/ceph/src/main/java/org/zstack/storage/ceph/backup/CephBackupStorageBase.java
  • utils/src/main/java/org/zstack/utils/path/RemotePathValidator.java

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.

3 participants