-
Notifications
You must be signed in to change notification settings - Fork 0
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
bridge: Fix credential reset after unauthorized sign-in #454
Conversation
WalkthroughThis update introduces enhancements and new features to the device-cloud bridge management, focusing on connection resilience and configuration flexibility. Key additions include configurable reconnection logic, token refreshment on demand, and dynamic tick interval settings. It also brings more customizable handling for device-cloud interactions and error responses in the CoAP gateway tests, aiming to improve reliability and adaptability in device communication with cloud services. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- bridge/device/cloud/manager.go (3 hunks)
- bridge/device/cloud/signIn.go (1 hunks)
Additional comments: 4
bridge/device/cloud/signIn.go (1)
- 74-79: The logic for handling unauthorized sign-in attempts and setting
forceRefreshToken
based on the presence of aRefreshToken
is correctly implemented.Ensure that
forceRefreshToken
is reset appropriately after it's used to avoid unintended behavior in subsequent operations.bridge/device/cloud/manager.go (3)
- 99-99: The addition of
forceRefreshToken
to theManager
struct aligns with the objectives of improving the handling of unauthorized sign-in attempts.- 249-249: Resetting
forceRefreshToken
inresetCredentials
is a good practice to ensure it does not affect subsequent operations unintentionally.- 508-510: Conditionally refreshing the token in
connect
based onforceRefreshToken
is a good practice to only refresh the token when necessary.
d849502
to
8cfadb0
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (9)
- bridge/device/cloud/manager.go (15 hunks)
- bridge/device/cloud/manager_test.go (3 hunks)
- bridge/device/cloud/options.go (3 hunks)
- bridge/device/cloud/signIn.go (1 hunks)
- bridge/device/device.go (1 hunks)
- bridge/device/options.go (2 hunks)
- test/coap-gateway/customHandler.go (1 hunks)
- test/coap-gateway/service/client.go (2 hunks)
- test/coap-gateway/service/refreshToken.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- bridge/device/cloud/signIn.go
Additional comments: 16
bridge/device/cloud/options.go (2)
- 32-32: The addition of the
tickInterval
field to theOptionsCfg
struct is appropriate and enhances the configuration capabilities of the cloud component.- 63-67: The
WithTickInterval
function is correctly implemented and follows the established pattern for option-setting functions in theOptionsCfg
struct.test/coap-gateway/service/refreshToken.go (2)
- 23-23: The import of the
time
package is necessary for the introduced delay and is correctly placed.- 36-36: Introducing a 10-millisecond delay before closing the client connection is a common practice to ensure pending operations complete. However, it's important to verify the necessity and appropriateness of this delay for the specific context of the
refreshTokenPostHandler
function.bridge/device/options.go (2)
- 45-45: The addition of the
cloudOptions
field to theOptionsCfg
struct allows for flexible and modular configuration of cloud-related options, following the pattern of using functional options in Go.- 87-91: The
WithCloudOptions
function is correctly implemented, following the established pattern for option-setting functions in theOptionsCfg
struct and allowing for flexible configuration of cloud-related options.test/coap-gateway/service/client.go (2)
- 30-30: The import of the
coapStatus
package is necessary for the enhancements in error handling and is correctly placed.- 121-127: The modifications to the
sendErrorResponse
function, including the introduction of adefaultCode
parameter and conditional override based on the error, improve its flexibility and accuracy in error handling.test/coap-gateway/customHandler.go (1)
- 1-133: The implementation of the
CustomHandler
struct and its methods, including the use of atomic pointers for function types, is correct and follows best practices for concurrency in Go. This approach allows for dynamic and thread-safe updates to handler functions.bridge/device/device.go (1)
- 163-163: Appending
o.cloudOptions
tocloudOpts
before initializing the cloud manager enhances flexibility and configurability. This change is correctly implemented using theappend
function in Go.bridge/device/cloud/manager_test.go (3)
- 30-30: The imports for the
ocfCloud
andstatus
packages are necessary for the introduced test functionalities, facilitating the simulation and verification of unauthorized device behavior and handling of CoAP status codes.Also applies to: 47-47
- 74-78: The implementation of the
getUnauthorizedError
function is correct, serving its purpose of generating a standardized unauthorized error for testing using CoAP status codes.- 81-144: The
TestManagerDeviceBecomesUnauthorized
function is well-structured and effectively tests the device's behavior when it becomes unauthorized, using thegetUnauthorizedError
function to simulate unauthorized errors.bridge/device/cloud/manager.go (3)
- 102-102: The addition of the
reconnect
field usingatomic.Bool
to theManager
struct is appropriate for thread-safe operations, enhancing the capability to handle reconnection logic.- 193-199: The modifications to the
handleTrigger
method to include reconnection logic based on thereconnect
flag are correctly implemented, improving the resilience and responsiveness of the cloud connection process.- 622-625: The introduction of the
Reconnect
method, which sets thereconnect
flag and triggers the reconnection process, is a useful and correctly implemented addition, enhancing the cloud manager's flexibility.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #454 +/- ##
==========================================
+ Coverage 76.87% 76.97% +0.10%
==========================================
Files 115 115
Lines 6710 6750 +40
==========================================
+ Hits 5158 5196 +38
+ Misses 1013 1011 -2
- Partials 539 543 +4 ☔ View full report in Codecov by Sentry. |
8cfadb0
to
f7aa005
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (9)
- bridge/device/cloud/manager.go (16 hunks)
- bridge/device/cloud/manager_test.go (3 hunks)
- bridge/device/cloud/options.go (3 hunks)
- bridge/device/cloud/signIn.go (1 hunks)
- bridge/device/device.go (1 hunks)
- bridge/device/options.go (2 hunks)
- test/coap-gateway/customHandler.go (1 hunks)
- test/coap-gateway/service/client.go (2 hunks)
- test/coap-gateway/service/refreshToken.go (2 hunks)
Files skipped from review as they are similar to previous changes (9)
- bridge/device/cloud/manager.go
- bridge/device/cloud/manager_test.go
- bridge/device/cloud/options.go
- bridge/device/cloud/signIn.go
- bridge/device/device.go
- bridge/device/options.go
- test/coap-gateway/customHandler.go
- test/coap-gateway/service/client.go
- test/coap-gateway/service/refreshToken.go
f7aa005
to
1ab6318
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (9)
- bridge/device/cloud/manager.go (16 hunks)
- bridge/device/cloud/manager_test.go (3 hunks)
- bridge/device/cloud/options.go (3 hunks)
- bridge/device/cloud/signIn.go (1 hunks)
- bridge/device/device.go (1 hunks)
- bridge/device/options.go (2 hunks)
- test/coap-gateway/customHandler.go (1 hunks)
- test/coap-gateway/service/client.go (2 hunks)
- test/coap-gateway/service/refreshToken.go (2 hunks)
Files skipped from review as they are similar to previous changes (9)
- bridge/device/cloud/manager.go
- bridge/device/cloud/manager_test.go
- bridge/device/cloud/options.go
- bridge/device/cloud/signIn.go
- bridge/device/device.go
- bridge/device/options.go
- test/coap-gateway/customHandler.go
- test/coap-gateway/service/client.go
- test/coap-gateway/service/refreshToken.go
1ab6318
to
40462fa
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (11)
- bridge/device/cloud/manager.go (14 hunks)
- bridge/device/cloud/manager_test.go (3 hunks)
- bridge/device/cloud/options.go (3 hunks)
- bridge/device/cloud/refreshToken.go (1 hunks)
- bridge/device/cloud/signIn.go (2 hunks)
- bridge/device/cloud/signUp.go (1 hunks)
- bridge/device/device.go (1 hunks)
- bridge/device/options.go (2 hunks)
- test/coap-gateway/customHandler.go (1 hunks)
- test/coap-gateway/service/client.go (2 hunks)
- test/coap-gateway/service/refreshToken.go (2 hunks)
Files skipped from review as they are similar to previous changes (9)
- bridge/device/cloud/manager.go
- bridge/device/cloud/manager_test.go
- bridge/device/cloud/options.go
- bridge/device/cloud/signIn.go
- bridge/device/device.go
- bridge/device/options.go
- test/coap-gateway/customHandler.go
- test/coap-gateway/service/client.go
- test/coap-gateway/service/refreshToken.go
Additional comments: 2
bridge/device/cloud/refreshToken.go (1)
- 72-76: The changes in the
updateCredsByRefreshTokenResponse
method introduce a more flexible way of updating credentials, which aligns well with the PR objectives. However, setting thesignedIn
flag tofalse
is a significant change. It would be beneficial to add a comment explaining the rationale behind this decision to aid future maintainability.bridge/device/cloud/signUp.go (1)
- 83-83: The simplification of the
ValidUntil
field assignment in thesignUp
function improves code readability and maintainability. This change aligns well with the PR objectives of enhancing system resilience and user experience by ensuring efficient token management.
40462fa
to
e47a6ed
Compare
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (11)
- bridge/device/cloud/manager.go (14 hunks)
- bridge/device/cloud/manager_test.go (3 hunks)
- bridge/device/cloud/options.go (3 hunks)
- bridge/device/cloud/refreshToken.go (1 hunks)
- bridge/device/cloud/signIn.go (2 hunks)
- bridge/device/cloud/signUp.go (1 hunks)
- bridge/device/device.go (1 hunks)
- bridge/device/options.go (2 hunks)
- test/coap-gateway/customHandler.go (1 hunks)
- test/coap-gateway/service/client.go (2 hunks)
- test/coap-gateway/service/refreshToken.go (2 hunks)
Files skipped from review as they are similar to previous changes (11)
- bridge/device/cloud/manager.go
- bridge/device/cloud/manager_test.go
- bridge/device/cloud/options.go
- bridge/device/cloud/refreshToken.go
- bridge/device/cloud/signIn.go
- bridge/device/cloud/signUp.go
- bridge/device/device.go
- bridge/device/options.go
- test/coap-gateway/customHandler.go
- test/coap-gateway/service/client.go
- test/coap-gateway/service/refreshToken.go
|
Summary by CodeRabbit
ValidUntil
field during device sign-up.