-
Notifications
You must be signed in to change notification settings - Fork 19
fix: unable to access hws ecs #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR refactors ECS instance detail retrieval (replacing outdated models and security-group logic) to fix null pointer errors and upgrades VPC SDK imports and client initialization from v2 to v3 to support deny/allow policies. Class diagram for updated ECS instance detail retrievalclassDiagram
class InstanceDetail {
+ecsModel.ServerDetail ServerDetail
+[]vpcModel.SecurityGroupInfo SecurityGroup
}
class ecsModel.ServerDetail
class vpcModel.SecurityGroupInfo
InstanceDetail --> ecsModel.ServerDetail
InstanceDetail --> vpcModel.SecurityGroupInfo
Class diagram for updated security group retrieval functionclassDiagram
class getSecurityGroup {
+[]vpcModel.SecurityGroupInfo getSecurityGroup([]ecsModel.ServerSecurityGroup, *vpc.VpcClient)
}
class ecsModel.ServerSecurityGroup {
+string Id
}
class vpcModel.ShowSecurityGroupRequest {
+string SecurityGroupId
}
class vpc.VpcClient {
+ShowSecurityGroup(request: vpcModel.ShowSecurityGroupRequest) vpcModel.SecurityGroupInfo
}
getSecurityGroup --> ecsModel.ServerSecurityGroup
getSecurityGroup --> vpc.VpcClient
getSecurityGroup --> vpcModel.SecurityGroupInfo
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @Lyc-heng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the HWS collector by upgrading the Huawei Cloud VPC SDK to its third version and resolving a critical null pointer error that affected ECS host retrieval. The SDK update provides access to more granular security group details, which is vital for building robust security detection capabilities, while the host retrieval fix ensures the reliability of collected data. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- In getSecurityGroup, consider returning an error instead of just logging and returning nil so that callers can detect and handle failures rather than silently getting an empty slice.
- In InitServices under the ECS case, you’re assigning s.ECS and s.VPC back-to-back which may overwrite the first error; separate those calls or check err after each assignment to avoid masking failures.
- Remove the commented-out VPC import in service_for_private_cloud.go to keep the codebase clean and maintainable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In getSecurityGroup, consider returning an error instead of just logging and returning nil so that callers can detect and handle failures rather than silently getting an empty slice.
- In InitServices under the ECS case, you’re assigning s.ECS and s.VPC back-to-back which may overwrite the first error; separate those calls or check err after each assignment to avoid masking failures.
- Remove the commented-out VPC import in service_for_private_cloud.go to keep the codebase clean and maintainable.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses two main issues: it resolves a null pointer error that prevented HWS ECS hosts from being retrieved, and it upgrades the Huawei Cloud VPC SDK from v2 to v3. The SDK upgrade is a significant change affecting multiple collector files. The fix for the null pointer error appears correct, involving the proper initialization of the VPC client. However, I've identified a critical regression in the getSecurityGroup function which could lead to a panic due to a potential nil pointer dereference. Please see my comment for details and a suggested fix.
| result = append(result, response.SecurityGroup) | ||
| if err != nil { | ||
| log.CtxLogger(ctx).Warn("ShowSecurityGroup error", zap.Error(err)) | ||
| return | ||
| log.GetWLogger().Error(fmt.Sprintf("get SecurityGroup error: %s", err.Error())) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a potential nil pointer dereference here. The call to client.ShowSecurityGroup is followed by accessing response.SecurityGroup before checking if err is nil. If an error occurs, response is likely to be nil, which would cause a panic. The error check should be performed immediately after the API call, before attempting to access the response object.
| result = append(result, response.SecurityGroup) | |
| if err != nil { | |
| log.CtxLogger(ctx).Warn("ShowSecurityGroup error", zap.Error(err)) | |
| return | |
| log.GetWLogger().Error(fmt.Sprintf("get SecurityGroup error: %s", err.Error())) | |
| return nil | |
| } | |
| if err != nil { | |
| log.GetWLogger().Error(fmt.Sprintf("get SecurityGroup error: %s", err.Error())) | |
| return nil | |
| } | |
| result = append(result, response.SecurityGroup) |
Thank you for your contribution to CloudRec!
What About:
java)go)opa)Description:
This submission is mainly to fix 2 issues:
Summary by Sourcery
Fix HWS ECS collection issues and upgrade VPC SDK
Bug Fixes:
Enhancements:
Chores: