Skip to content

Comments

Sugarst is myself @zfchai.#17

Open
sugarst wants to merge 10 commits intorustfs:mainfrom
sugarst:zfchai
Open

Sugarst is myself @zfchai.#17
sugarst wants to merge 10 commits intorustfs:mainfrom
sugarst:zfchai

Conversation

@sugarst
Copy link

@sugarst sugarst commented Jan 30, 2026

Disclaimer: Sugarst is myself @ zfchai. Due to the GitHub two factor authentication enabled on my previous account, my Android phone was unable to use the key, resulting in the inability to log in and use my account. I am truly sorry, but I am currently unsure how to retrieve it.

Optimize and adjust some methods.

Copy link

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 refactors the RustFS Demo application to use modern C# features and improves the configuration management approach. The changes modernize the codebase by adopting primary constructors, global usings, and improved configuration binding patterns.

Changes:

  • Adopted C# 12 features including primary constructors and collection expressions throughout the codebase
  • Moved configuration classes from Models to Options namespace and enhanced validation
  • Added global usings to reduce code duplication and improve maintainability
  • Updated NuGet package versions (AWSSDK.S3, OpenTelemetry packages, Scalar.AspNetCore)
  • Added logging statements to controller actions
  • Improved XML documentation in the IRustFSService interface
  • Updated Bootstrap version from 5.3.0 to 5.3.8 with SRI hash
  • Configured explicit port bindings (59000, 59001) for the RustFS container

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/RustFS.Demo.Tests/RustFSServiceTests.cs Reordered imports alphabetically and updated namespace reference from Models to Options
src/RustFS.Demo.Web/wwwroot/index.html Updated Bootstrap CDN link to version 5.3.8 with integrity hash for security
src/RustFS.Demo.Web/appsettings.json Added S3Storage configuration section with default values
src/RustFS.Demo.Web/Validation/BucketNameAttribute.cs Made class sealed and removed explicit using statement (now using global usings)
src/RustFS.Demo.Web/Using.cs New file defining global using directives for commonly used namespaces
src/RustFS.Demo.Web/Services/RustFSService.cs Converted to primary constructor pattern with injected dependencies
src/RustFS.Demo.Web/Services/RustFSService.File.cs Removed explicit usings and XML comments, updated field references to use primary constructor parameters
src/RustFS.Demo.Web/Services/RustFSService.Bucket.cs Same refactoring as File.cs, added collection expression syntax
src/RustFS.Demo.Web/Services/IRustFSService.cs Enhanced XML documentation with detailed parameter and return value descriptions
src/RustFS.Demo.Web/Program.cs Refactored configuration binding to use AddOptions pattern with validation
src/RustFS.Demo.Web/Options/S3StorageOptions.cs Moved from Models namespace, added SectionName constant and IsValid validation method
src/RustFS.Demo.Web/Options/PresignedUrlOptions.cs Moved from Models namespace, removed explicit using statements
src/RustFS.Demo.Web/Models/S3StorageOptions.cs Deleted (moved to Options folder)
src/RustFS.Demo.Web/Infrastructure/GlobalExceptionHandler.cs Converted to primary constructor pattern
src/RustFS.Demo.Web/Controllers/FileController.cs Converted to primary constructor, added logging for operations
src/RustFS.Demo.Web/Controllers/BucketController.cs Converted to primary constructor, added logging for operations
src/RustFS.Demo.AppHost/Program.cs Changed from dynamic to explicit port bindings for predictable endpoint URLs
Directory.Packages.props Updated package versions for AWSSDK.S3, OpenTelemetry packages, and Scalar.AspNetCore

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (!await _s3Service.BucketExistsAsync(bucketName))
if (!await s3Service.BucketExistsAsync(bucketName))
{
logger.LogError($"Bucket not found, name {bucketName}");
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The log message uses string interpolation instead of structured logging. This prevents proper log indexing and querying. Use structured logging with a template and parameters instead: logger.LogError("Bucket not found, name {BucketName}", bucketName)

Suggested change
logger.LogError($"Bucket not found, name {bucketName}");
logger.LogError("Bucket not found, name {BucketName}", bucketName);

Copilot uses AI. Check for mistakes.
/// </summary>
public partial class RustFSService : IRustFSService
public partial class RustFSService(
ILogger<RustFSService> logger,
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The logger parameter is injected into RustFSService through the primary constructor but is never used in the service implementation. Either remove the unused parameter or add logging statements to track important operations and errors in the service methods.

Copilot uses AI. Check for mistakes.
public async Task<IActionResult> Create([FromBody] CreateBucketRequest request)
{
await _s3Service.CreateBucketAsync(request.Name);
logger.LogWarning("Create a new bucket.");
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Creating a new bucket is a normal operation, not a warning condition. Consider changing this to LogInformation instead of LogWarning, or remove the log statement entirely if the operation is being tracked elsewhere.

Suggested change
logger.LogWarning("Create a new bucket.");
logger.LogInformation("Create a new bucket.");

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +15
"AccessKey": "admin", // production-access-key
"SecretKey": "admin123" // production-secret-key
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

Hardcoded credentials should not be committed to version control in appsettings.json. These default values should be stored in appsettings.Development.json, user secrets, or environment variables. Consider removing the default AccessKey and SecretKey values from this file and providing them through secure configuration sources.

Suggested change
"AccessKey": "admin", // production-access-key
"SecretKey": "admin123" // production-secret-key
"AccessKey": "", // Set via environment variables, user secrets, or appsettings.Development.json
"SecretKey": "" // Set via environment variables, user secrets, or appsettings.Development.json

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +25
!string.IsNullOrWhiteSpace(AccessKey) &&
!string.IsNullOrWhiteSpace(SecretKey) &&
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The validation logic requires AccessKey and SecretKey even when UseInstanceProfile is true. When using instance profiles or assume role authentication, credentials should not be required. Consider updating the validation to: UseInstanceProfile || !string.IsNullOrWhiteSpace(AssumeRoleArn) || (!string.IsNullOrWhiteSpace(AccessKey) && !string.IsNullOrWhiteSpace(SecretKey))

Suggested change
!string.IsNullOrWhiteSpace(AccessKey) &&
!string.IsNullOrWhiteSpace(SecretKey) &&
(UseInstanceProfile ||
!string.IsNullOrWhiteSpace(AssumeRoleArn) ||
(!string.IsNullOrWhiteSpace(AccessKey) && !string.IsNullOrWhiteSpace(SecretKey))) &&

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +27
// 验证配置项有效性
public bool IsValid() =>
!string.IsNullOrWhiteSpace(AccessKey) &&
!string.IsNullOrWhiteSpace(SecretKey) &&
Endpoint != null;

Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The validation message error format is inconsistent with the overall validation approach. The IsValid method returns a boolean but the error message is defined in the configuration binding. Consider adding an error message property or method that provides more specific validation error details, such as which fields are missing or invalid.

Suggested change
// 验证配置项有效性
public bool IsValid() =>
!string.IsNullOrWhiteSpace(AccessKey) &&
!string.IsNullOrWhiteSpace(SecretKey) &&
Endpoint != null;
/// <summary>
/// 最近一次验证失败时的错误描述;如果验证通过则为 null。
/// </summary>
public string? ValidationError { get; private set; }
// 验证配置项有效性
public bool IsValid()
{
var errors = new System.Collections.Generic.List<string>();
if (string.IsNullOrWhiteSpace(AccessKey))
{
errors.Add("AccessKey is required.");
}
if (string.IsNullOrWhiteSpace(SecretKey))
{
errors.Add("SecretKey is required.");
}
if (Endpoint == null)
{
errors.Add("Endpoint is required.");
}
if (errors.Count == 0)
{
ValidationError = null;
return true;
}
ValidationError = string.Join(" ", errors);
return false;
}

Copilot uses AI. Check for mistakes.
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.

1 participant