Skip to content
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: updates for tests #464

Merged
merged 7 commits into from
May 14, 2024
Merged

bridge: updates for tests #464

merged 7 commits into from
May 14, 2024

Conversation

Danielius1922
Copy link
Member

@Danielius1922 Danielius1922 commented Apr 26, 2024

Summary by CodeRabbit

  • New Features

    • Introduced advanced operations for managing Thing Descriptions in devices, enhancing interaction capabilities.
    • Added new functionalities for patching and handling resource property elements in devices.
  • Bug Fixes

    • Removed unused GetOCFThingDescription function to streamline Thing Description management.
  • Documentation

    • Updated documentation to reflect new functionalities and removed features.
  • Refactor

    • Revised codebase in main.go for better structure and efficiency.
    • Changed function signatures to align with updated configurations and TLS handling.
  • Chores

    • Updated config.yaml to use new port numbers for IPv4 and IPv6 loopback addresses, enhancing network configuration.
  • Style

    • Code style adjustments and clean-up across multiple files for improved readability and maintenance.

Copy link

coderabbitai bot commented Apr 26, 2024

Important

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates aim to enhance device and Thing Description management functionality across modules. Changes include adding functions for patching property elements, refining Thing Description handling, and optimizing device configurations. Port numbers for the example API were also adjusted, alongside refactoring efforts to streamline operations and configurations.

Changes

Files Change Summary
.../thingDescription/thingDescription.go
.../thingDescription/ocfResources.go
Introduced functions for patching property elements and managing Thing Descriptions. Deprecated outdated functions.
.../test/test.go
cmd/bridge-device/device/device.go
Expanded test capabilities and added functions for handling test resources and Thing Descriptions.
cmd/bridge-device/config.yaml
cmd/bridge-device/main.go
Updated port numbers and refactored code for improved configuration and resource management.

🐇💻
In the digital fields of code, where bytes frolic and bits abide,
A rabbit hopped through lines so wide, tweaking ports with pride.
With every patch and function new, it crafted realms so vast,
A world where devices smartly talk, in languages that last.
Hop, hop, hop, on silicon they tread, making connections tight,
For in this update, mighty leaps, bring the future bright! 🌟
🐇💻


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Danielius1922 Danielius1922 force-pushed the adam/feature/update-bridge-device branch 2 times, most recently from 7ee8fe1 to 5e257d0 Compare April 30, 2024 11:30
@codecov-commenter
Copy link

codecov-commenter commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 66.17647% with 92 lines in your changes are missing coverage. Please review.

Project coverage is 76.83%. Comparing base (6021006) to head (774e3a7).

Files Patch % Lines
cmd/bridge-device/device/device.go 31.91% 28 Missing and 4 partials ⚠️
bridge/device/thingDescription/thingDescription.go 79.54% 15 Missing and 12 partials ⚠️
bridge/test/test.go 62.29% 13 Missing and 10 partials ⚠️
cmd/bridge-device/device/config.go 60.00% 3 Missing and 3 partials ⚠️
bridge/resources/thingDescription/ocfResources.go 85.71% 1 Missing and 1 partial ⚠️
bridge/resources/thingDescription/resource.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #464      +/-   ##
==========================================
- Coverage   77.90%   76.83%   -1.08%     
==========================================
  Files         118      121       +3     
  Lines        7206     7225      +19     
==========================================
- Hits         5614     5551      -63     
- Misses       1029     1085      +56     
- Partials      563      589      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Danielius1922 Danielius1922 force-pushed the adam/feature/update-bridge-device branch 15 times, most recently from d08a4a0 to aeead31 Compare May 3, 2024 06:50
@Danielius1922
Copy link
Member Author

@coderabbitai review

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: 14

Out of diff range and nitpick comments (7)
cmd/bridge-device/device/device.go (1)

19-21: Ensure consistent resource naming conventions.

The function GetTestResourceHref constructs a resource href using an integer ID. Consider using a more descriptive naming scheme or documenting the expected format and usage of these resource hrefs to improve maintainability.

bridge/resources/thingDescription/ocfResources.go (1)

54-58: Ensure consistency in error messages.

The function PatchCloudResourcePropertyElement should have consistent and descriptive error messages, especially when patch operations fail. This helps in debugging and maintaining the code.

cmd/bridge-device/device/config.go (1)

36-36: Document the purpose of new configuration fields.

The addition of the CloudID field in the CloudConfig struct is not documented. Adding comments to explain the purpose and usage of new configuration fields can aid in understanding and maintaining the code.

cmd/bridge-device/main.go (1)

Line range hint 72-120: Refactor configuration options retrieval to improve readability.

The function getOpts retrieves various configuration options in a complex and nested manner. Refactoring this function to separate concerns and simplify the logic can improve readability and maintainability.

bridge/resources/thingDescription/resource_test.go (1)

Line range hint 110-246: Refactor tests to use mock frameworks for better isolation.

The tests in TestObserveThingDescription and TestGetThingDescription rely heavily on actual implementations rather than mocks. Refactoring these tests to use a mocking framework can improve test isolation and reliability.

Makefile (2)

17-18: Update documentation to reflect changes in test images.

The HUB_TEST_DEVICE_IMAGE variable has been updated to a new test image version. Ensure that all documentation and CI/CD scripts are updated to reflect this change to avoid inconsistencies and potential build failures.


Line range hint 127-202: Optimize test environment setup and teardown.

The test setup and teardown commands in the Makefile are verbose and repetitive. Consider creating reusable make targets or scripts to simplify these operations, which can improve maintainability and reduce the potential for errors.

bridge/test/test.go Outdated Show resolved Hide resolved
cmd/bridge-device/device/device.go Outdated Show resolved Hide resolved
cmd/bridge-device/device/device.go Show resolved Hide resolved
cmd/bridge-device/device/device.go Outdated Show resolved Hide resolved
bridge/resources/thingDescription/ocfResources.go Outdated Show resolved Hide resolved
cmd/bridge-device/device.go Show resolved Hide resolved
cmd/bridge-device/device.go Show resolved Hide resolved
bridge/device/thingDescription/thingDescription.go Outdated Show resolved Hide resolved
bridge/device/thingDescription/thingDescription.go Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 force-pushed the adam/feature/update-bridge-device branch from aeead31 to 0107fb4 Compare May 3, 2024 09:15
Makefile Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 marked this pull request as ready for review May 3, 2024 09:19
@Danielius1922 Danielius1922 requested a review from jkralik May 3, 2024 09:19
@Danielius1922 Danielius1922 force-pushed the adam/feature/update-bridge-device branch from 0107fb4 to e9a8c55 Compare May 3, 2024 09:31
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: 2

Out of diff range and nitpick comments (1)
cmd/bridge-device/main.go (1)

Line range hint 104-115: Consider refactoring the lambda function in getTDOpts into a named function for better readability and potential reuse.

cmd/bridge-device/main.go Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 force-pushed the adam/feature/update-bridge-device branch from e9a8c55 to 50d52f0 Compare May 3, 2024 10:11
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

Out of diff range and nitpick comments (1)
bridge/resources/thingDescription/resource.go (1)

Line range hint 44-63: Consider optimizing the CBOR conversion process to avoid double marshaling.

-		err := json.Unmarshal(dataJson, &v)
-		if err != nil {
-			return resources.CreateErrorResponse(request.Context(), codes.InternalServerError, err)
-		}
-		return resources.CreateResponseContent(request.Context(), v, codes.Content)
+		// Directly convert ThingDescription to CBOR if possible
+		// This avoids the inefficiency of double marshaling
+		// Example: directCBOR, err := cbor.Marshal(thingDescription)
+		// if err != nil {
+		//     return resources.CreateErrorResponse(request.Context(), codes.InternalServerError, err)
+		// }
+		// return resources.CreateResponseContent(request.Context(), directCBOR, codes.Content)
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1770913 and ed9e661.
Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • bridge/resources/thingDescription/resource.go (1 hunks)
Additional comments not posted (2)
bridge/resources/thingDescription/resource.go (2)

Line range hint 65-82: Implementation of Get and CreateSubscription functions looks good.


Line range hint 84-95: Initialization of Resource in the New function is correctly implemented.

bridge/resources/thingDescription/resource.go Show resolved Hide resolved
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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ed9e661 and b1e6717.
Files selected for processing (8)
  • .github/workflows/build-with-cfg.yml (1 hunks)
  • .github/workflows/builds.yml (1 hunks)
  • .github/workflows/golangci-lint.yml (1 hunks)
  • .github/workflows/test-with-cfg.yml (1 hunks)
  • .golangci.yml (1 hunks)
  • README.md (1 hunks)
  • cmd/bridge-device/Dockerfile (1 hunks)
  • test/cloud-server/Dockerfile (1 hunks)
Files skipped from review due to trivial changes (7)
  • .github/workflows/build-with-cfg.yml
  • .github/workflows/builds.yml
  • .github/workflows/golangci-lint.yml
  • .github/workflows/test-with-cfg.yml
  • .golangci.yml
  • cmd/bridge-device/Dockerfile
  • test/cloud-server/Dockerfile
Additional Context Used
LanguageTool (1)
README.md (1)

Near line 1: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 839 characters long)
Context: CI Coverage Status Go Report Card [![Gitter](https://badges.gitter.im/ocfclo...

Additional comments not posted (1)
README.md (1)

19-19: Update to Go 1.21 aligns with modern standards and likely supports new features or optimizations used in the project.

@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch from b1e6717 to 8c2b0bc Compare May 10, 2024 11:13
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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b1e6717 and 8c2b0bc.
Files selected for processing (9)
  • .github/workflows/build-with-cfg.yml (1 hunks)
  • .github/workflows/builds.yml (1 hunks)
  • .github/workflows/golangci-lint.yml (1 hunks)
  • .github/workflows/test-with-cfg.yml (1 hunks)
  • .golangci.yml (1 hunks)
  • README.md (1 hunks)
  • bridge/resources/thingDescription/resource_test.go (7 hunks)
  • cmd/bridge-device/Dockerfile (1 hunks)
  • test/cloud-server/Dockerfile (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • .github/workflows/build-with-cfg.yml
  • .github/workflows/builds.yml
  • .github/workflows/golangci-lint.yml
  • .github/workflows/test-with-cfg.yml
  • .golangci.yml
  • bridge/resources/thingDescription/resource_test.go
  • cmd/bridge-device/Dockerfile
  • test/cloud-server/Dockerfile
Additional Context Used
LanguageTool (1)
README.md (1)

Near line 1: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 839 characters long)
Context: CI Coverage Status Go Report Card [![Gitter](https://badges.gitter.im/ocfclo...

Additional comments not posted (1)
README.md (1)

19-19: Update to Go 1.21 is noted. Ensure that all dependencies and CI pipelines are compatible with this version.

Verification successful

All dependencies and CI pipelines in the codebase are specified to use Go 1.21, as confirmed by the go.mod file. The toolchain is set to Go 1.22.0, which should not pose any compatibility issues due to Go's backward compatibility. No other conflicting Go version specifications were found in the codebase.

  • go.mod: Specifies Go 1.21 and toolchain Go 1.22.0
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify compatibility of dependencies and CI pipelines with Go 1.21.

# Test: Search for Go version specifications in CI configuration files and dependency files.
fd '(\.yml|go\.mod)$' --exec rg 'go 1\.[0-9]+'

Length of output: 56



Script:

#!/bin/bash
# Description: Locate and display the contents around the Go version specifications in CI configuration files and dependency files.

# Search for Go version specifications and display the file names and relevant lines.
fd '(\.yml|go\.mod)$' --exec rg -C 3 'go 1\.[0-9]+' --with-filename

Length of output: 190

@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch from 8c2b0bc to f960580 Compare May 10, 2024 11:34
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: 0

Out of diff range and nitpick comments (1)
README.md (1)

19-19: Update the Go version requirement to reflect the latest stable release.

Considering the rapid development and frequent updates in Go, it might be beneficial to specify that Go 1.22 or higher is required, ensuring compatibility with the latest features and security patches.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8c2b0bc and f960580.
Files ignored due to path filters (1)
  • go.mod is excluded by !**/*.mod
Files selected for processing (9)
  • .github/workflows/build-with-cfg.yml (1 hunks)
  • .github/workflows/builds.yml (1 hunks)
  • .github/workflows/golangci-lint.yml (1 hunks)
  • .github/workflows/test-with-cfg.yml (1 hunks)
  • .golangci.yml (1 hunks)
  • README.md (1 hunks)
  • bridge/resources/thingDescription/resource_test.go (7 hunks)
  • cmd/bridge-device/Dockerfile (1 hunks)
  • test/cloud-server/Dockerfile (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • .github/workflows/build-with-cfg.yml
  • .github/workflows/builds.yml
  • .github/workflows/golangci-lint.yml
  • .github/workflows/test-with-cfg.yml
  • .golangci.yml
  • bridge/resources/thingDescription/resource_test.go
  • cmd/bridge-device/Dockerfile
  • test/cloud-server/Dockerfile
Additional Context Used
LanguageTool (1)
README.md (1)

Near line 1: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 839 characters long)
Context: CI Coverage Status Go Report Card [![Gitter](https://badges.gitter.im/ocfclo...

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: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f960580 and f9c41c3.
Files selected for processing (6)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/resources/thingDescription/resource_test.go (7 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files skipped from review as they are similar to previous changes (4)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/resources/thingDescription/resource_test.go
  • bridge/test/test.go
  • cmd/bridge-device/device/device.go
Additional comments not posted (3)
cmd/bridge-device/main.go (1)

29-29: The changes in getCloudTLS look good and address the previous comment about checking the CertPath. Ensure that this change is tested thoroughly.

Verification successful

The verification process has successfully identified that the function getCloudTLS does include checks for CertPath as part of its implementation. The unit tests or code snippets provided in the output show that the CertPath is being used to load certificates and there is error handling associated with it. This confirms that the new check for CertPath is indeed covered and implemented correctly.

Final Verification:

  • The function getCloudTLS correctly handles the CertPath by attempting to load certificates using this path.
  • Error handling is in place to manage issues that might arise during the certificate loading process, which is a good practice in TLS configuration management.

This verification confirms that the implementation and the associated checks for CertPath are correctly handled in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new check for `CertPath` is covered by unit tests.

# Test: Search for the unit tests covering `getCloudTLS`. Expect: Tests that cover the new check.
rg --type go $'getCloudTLS' --exec cat {} | grep 'CertPath'

Length of output: 467



Script:

#!/bin/bash
# Description: Verify that the new check for `CertPath` is covered by unit tests.

# Corrected script: Search for the unit tests covering `getCloudTLS`. Expect: Tests that cover the new check.
rg --type go 'getCloudTLS' | xargs grep 'CertPath'

Length of output: 810



Script:

#!/bin/bash
# Description: Verify that the new check for `CertPath` is covered by unit tests.

# Further corrected script: Search for the unit tests covering `getCloudTLS`. Expect: Tests that cover the new check.
rg --type go 'getCloudTLS' --files-with-matches | xargs grep 'CertPath'

Length of output: 251

bridge/device/thingDescription/thingDescription.go (2)

27-47: The refactoring of SupportedOperationToTDOperations using a translation table is a significant improvement in clarity and maintainability.


137-168: The addition of a check for empty types in PatchPropertyElement is a crucial improvement for robustness and error prevention.

cmd/bridge-device/main.go Outdated Show resolved Hide resolved
@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch from f9c41c3 to 8583c11 Compare May 10, 2024 12:47
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: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f9c41c3 and 8583c11.
Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum
Files selected for processing (6)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/resources/thingDescription/resource_test.go (7 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files not reviewed due to errors (1)
  • bridge/device/thingDescription/thingDescription.go (no review received)
Files skipped from review as they are similar to previous changes (4)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/resources/thingDescription/resource_test.go
  • bridge/test/test.go
  • cmd/bridge-device/device/device.go
Additional comments not posted (4)
cmd/bridge-device/main.go (4)

72-72: The integration of TLS settings into cloud options is handled correctly.


86-102: Ensure the endpoint parameter is validated to prevent potential security issues.


104-104: The configuration of thing description options is correctly implemented.


121-121: The aggregation of options from different sources is handled correctly.

@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch from 8583c11 to e10f602 Compare May 10, 2024 13:11
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: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8583c11 and e10f602.
Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum
Files selected for processing (6)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/resources/thingDescription/resource_test.go (7 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files not reviewed due to errors (1)
  • bridge/device/thingDescription/thingDescription.go (no review received)
Files skipped from review as they are similar to previous changes (4)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/resources/thingDescription/resource_test.go
  • bridge/test/test.go
  • cmd/bridge-device/device/device.go
Additional comments not posted (4)
cmd/bridge-device/main.go (4)

72-72: Good error handling and certificate check in getCloudOpts.


86-102: Well-handled property element patching and addition in patchPropertyElement.


104-104: Proper error handling and usage of thing description functions in getTDOpts.


121-121: Effective aggregation and error handling in getOpts.

cmd/bridge-device/main.go Show resolved Hide resolved
cmd/bridge-device/main.go Show resolved Hide resolved
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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e10f602 and 6cd2643.
Files selected for processing (5)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files not reviewed due to errors (1)
  • bridge/device/thingDescription/thingDescription.go (no review received)
Files skipped from review as they are similar to previous changes (3)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/test/test.go
  • cmd/bridge-device/device/device.go
Additional comments not posted (6)
cmd/bridge-device/main.go (6)

29-29: Consider adding validation for the certificate and key paths to ensure they are not only non-empty but also valid paths.

+ if !isValidPath(cfg.TLS.CAPoolPath) || !isValidPath(cfg.TLS.CertPath) || !isValidPath(cfg.TLS.KeyPath) {
+   return cloud.CAPool{}, nil, fmt.Errorf("invalid path provided")
+ }

72-72: LGTM! Proper error handling and option construction.


86-86: Consider validating or sanitizing the endpoint parameter in patchPropertyElement to ensure it is safe to use, especially since it's incorporated directly into the logic without checks beyond non-emptiness.

+ if endpoint != "" && !isValidEndpoint(endpoint) {
+   return wotTD.PropertyElement{}, false
+ }

108-108: LGTM! Proper error handling and option construction.


125-125: LGTM! Proper error handling and option aggregation.


149-149: Replace panic with more graceful error handling to improve robustness and user experience.

- panic(err)
+ log.Fatal("Configuration load failed:", err)

@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch 3 times, most recently from 9604b26 to b553d1a Compare May 13, 2024 06:48
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

Out of diff range and nitpick comments (1)
cmd/bridge-device/main.go (1)

Line range hint 29-41: Ensure proper error handling for certificate loading.

+ if cfg.TLS.CertPath == "" || cfg.TLS.KeyPath == "" {
+   return cloud.CAPool{}, nil, errors.New("certificate path or key path is empty")
+ }

This addition ensures that both the certificate and key paths are checked for emptiness before attempting to load them, preventing potential runtime errors.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6a9dce1 and b553d1a.
Files selected for processing (6)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/config.yaml (1 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files skipped from review due to trivial changes (1)
  • cmd/bridge-device/config.yaml
Files skipped from review as they are similar to previous changes (3)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/test/test.go
  • cmd/bridge-device/device/device.go
Additional Context Used
GitHub Check Runs (1)
lint failure (2)

bridge/device/thingDescription/thingDescription.go: [failure] 162-162:
fmt.Errorf can be replaced with errors.New (perfsprint)

Additional comments not posted (6)
cmd/bridge-device/main.go (4)

29-29: Consider adding validation for the certificate and key paths to ensure they are not only non-empty but also valid paths.


149-149: Replace panic with more graceful error handling to improve robustness and user experience.


86-106: Refactor patchPropertyElement to improve clarity and maintainability. Consider extracting the property modification logic into a separate function.


86-106: Consider validating or sanitizing the endpoint parameter in patchPropertyElement to ensure it is safe to use, especially since it's incorporated directly into the logic without checks beyond non-emptiness.

bridge/device/thingDescription/thingDescription.go (2)

171-194: Ensure comprehensive validation of inputs in patch operations.


200-235: Add error handling for the url.Parse operation in PatchThingDescription to ensure that malformed endpoints are properly managed and do not cause runtime errors.

bridge/device/thingDescription/thingDescription.go Outdated Show resolved Hide resolved
@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch from b553d1a to f3ffa5a Compare May 13, 2024 07:42
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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b553d1a and f3ffa5a.
Files selected for processing (6)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/config.yaml (1 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files skipped from review as they are similar to previous changes (4)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/test/test.go
  • cmd/bridge-device/config.yaml
  • cmd/bridge-device/device/device.go
Additional comments not posted (10)
cmd/bridge-device/main.go (6)

29-29: Consider adding validation for the certificate and key paths to ensure they are not only non-empty but also valid paths.


72-72: LGTM! The cloud options are correctly constructed based on the TLS configuration.


86-106: Consider validating the endpoint parameter in patchPropertyElement to ensure it is safe to use, especially since it's incorporated directly into the logic without checks beyond non-emptiness.


108-108: LGTM! The Thing Description options are correctly generated and integrated with the device configuration.


125-125: LGTM! The overall device options are correctly aggregated based on the configuration.


149-149: Replace panic with more graceful error handling to improve robustness and user experience.

bridge/device/thingDescription/thingDescription.go (4)

50-55: LGTM! The conversion of boolean values to pointers is correctly implemented.


57-62: LGTM! The conversion of string values to pointers is correctly implemented.


70-76: LGTM! The conversion of supported operations to PropertyElementOperations is efficiently implemented.


171-193: Ensure comprehensive validation of inputs in patch operations.

@jkralik jkralik force-pushed the adam/feature/update-bridge-device branch from f3ffa5a to 774e3a7 Compare May 13, 2024 08:51
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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f3ffa5a and 774e3a7.
Files selected for processing (7)
  • bridge/device/thingDescription/thingDescription.go (1 hunks)
  • bridge/resources/thingDescription/ocfResources.go (2 hunks)
  • bridge/resources/thingDescription/resource.go (2 hunks)
  • bridge/test/test.go (3 hunks)
  • cmd/bridge-device/config.yaml (1 hunks)
  • cmd/bridge-device/device/device.go (1 hunks)
  • cmd/bridge-device/main.go (7 hunks)
Files skipped from review as they are similar to previous changes (5)
  • bridge/resources/thingDescription/ocfResources.go
  • bridge/resources/thingDescription/resource.go
  • bridge/test/test.go
  • cmd/bridge-device/config.yaml
  • cmd/bridge-device/device/device.go
Additional comments not posted (19)
cmd/bridge-device/main.go (7)

29-29: Consider adding validation for the certificate and key paths to ensure they are not only non-empty but also valid paths.

+ if !isValidPath(cfg.TLS.CAPoolPath) || !isValidPath(cfg.TLS.CertPath) || !isValidPath(cfg.TLS.KeyPath) {
+   return cloud.CAPool{}, nil, fmt.Errorf("invalid path provided")
+ }

29-29: The signal handling logic is appropriate and follows best practices for graceful shutdown.


72-72: Cloud options configuration is correctly implemented and handles potential errors appropriately.


86-106: Consider validating or sanitizing the endpoint parameter in patchPropertyElement to ensure it is safe to use, especially since it's incorporated directly into the logic without checks beyond non-emptiness.

+ if endpoint != "" && !isValidEndpoint(endpoint) {
+   return wotTD.PropertyElement{}, false
+ }

108-108: Thing Description options configuration is correctly implemented and integrates well with other components.


125-125: Options aggregation is correctly implemented, ensuring all configurations are included and errors are handled.


149-149: Replace panic with more graceful error handling to improve robustness and user experience.

- panic(err)
+ log.Fatal("Configuration load failed:", err)
bridge/device/thingDescription/thingDescription.go (12)

28-48: Consider returning an empty slice instead of nil when no operations are found to ensure consistency and prevent potential nil dereferences.

- return nil
+ return []string{}

50-55: The BoolToPtr function is correctly implemented, following common patterns for optional boolean fields.


57-61: The StringToPtr function is correctly implemented, following common patterns for optional string fields.


70-76: The conversion of supported operations to property element operations is efficiently implemented using bitwise operations.


78-87: The retrieval of property element operations from a property element is efficiently implemented with clean handling of optional boolean fields.


89-101: Conversion of property element operations back to supported operations is correctly implemented using bitwise operations.


105-133: The CreateCOAPForm function is efficiently implemented, correctly handling different operations and special cases for the observe property.


137-158: The CreateCOAPForms function is correctly implemented, efficiently creating multiple COAP forms based on the supported operations.


160-169: The GetPropertyHref function is correctly implemented, efficiently constructing URLs with appropriate validation and handling of device IDs.


171-194: Ensure comprehensive validation of inputs in patch operations.

+ if len(types) == 0 {
+   return thingDescription.PropertyElement{}, errors.New("types cannot be empty")
+ }

The function PatchPropertyElement uses the types parameter without validating it. Adding a check to ensure that types is not empty can prevent runtime errors and ensure that the function behaves as expected.


196-198: The GetThingDescriptionID function is correctly implemented, efficiently constructing URIs from device IDs.


200-235: Add error handling for the url.Parse operation in PatchThingDescription to ensure that malformed endpoints are properly managed and do not cause runtime errors.

+ if err != nil {
+   return thingDescription.ThingDescription{}, fmt.Errorf("failed to parse endpoint URL: %w", err)
+ }

Copy link

sonarcloud bot commented May 13, 2024

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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 774e3a7 and f3ecdcf.
Files selected for processing (1)
  • Makefile (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Makefile

@jkralik jkralik merged commit 13e2819 into main May 14, 2024
12 of 13 checks passed
@jkralik jkralik deleted the adam/feature/update-bridge-device branch May 14, 2024 06:28
@coderabbitai coderabbitai bot mentioned this pull request Sep 13, 2024
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