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

snippet-service: Extend plgd/snippet-service #1309

Open
wants to merge 58 commits into
base: main
Choose a base branch
from

Conversation

Danielius1922
Copy link
Member

No description provided.

Copy link

coderabbitai bot commented May 16, 2024

Walkthrough

The latest update integrates a new service called snippet-service into various aspects of the project. The changes support its build, testing, deployment, and configuration. Existing functionalities were updated to include this new service, ensuring comprehensive integration from Docker configurations to Kubernetes templates.

Changes

File(s) Changes Summary
.github/workflows/build-publish.yaml, .github/workflows/test.yml Added jobs and logging configurations specific to snippet-service.
.vscode/settings.json, Makefile Configurations for TEST_SNIPPET_SERVICE_LOG_LEVEL and TEST_SNIPPET_SERVICE_LOG_DUMP_BODY, and expanded directory listings.
bundle/Dockerfile, bundle/nginx/nginx.conf.template Integrates snippet-service including build processes and proxy settings.
bundle/run.sh, charts/plgd-hub/templates/.../_helpers.tpl Adds environment variables for snippet-service addresses and configuration settings.
cloud2cloud-gateway/..., coap-gateway/..., grpc-gateway/... Replaced deprecated import functions, added new methods for device subscribers, and refactored init methods for test clients.
snippet-service/store/configuration.go Introduced new configuration management functions for snippet-service.
http-gateway/test/test.go Configs updated for SnippetService setup.
... (Rest are similar minor updates across various files)

Poem

In code we found a snippet's beat,
A service new and oh so neat,
With logs and tests, in Makefile set,
A perfect symphony we'll never forget.
We'll serve and build, a seamless flight,
Our snippet-service shines so 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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/snapshot-service branch from 6a85258 to 3cc79fb Compare May 16, 2024 08:34
@Danielius1922 Danielius1922 changed the title snapshot-service: Introduce plgd/snapshot-service snapshot-service: Extend plgd/snapshot-service May 16, 2024
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch 4 times, most recently from 835a887 to 02a9ec7 Compare May 17, 2024 18:01
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch from e24ed0e to 5341f2c Compare May 24, 2024 08:52
@Danielius1922 Danielius1922 changed the title snapshot-service: Extend plgd/snapshot-service snippet-service: Extend plgd/snippet-service May 24, 2024
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch 5 times, most recently from 96722e8 to e438968 Compare May 27, 2024 15:21
@Danielius1922
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented May 27, 2024

Actions Performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Outside diff range and nitpick comments (9)
snippet-service/store/configuration.go (1)

34-41: Consider using a more efficient cloning method if available.

While the Clone method is correct, using slices.Clone might not be the most efficient way to clone complex nested structures if the library does not handle deep copies well. If performance becomes a concern, consider implementing a more tailored deep copy method.

snippet-service/cmd/service/main.go (1)

35-48: Review configuration loading and logging setup.

The main function handles configuration loading and logging setup. It's generally well-implemented, but consider adding more detailed error messages and possibly a recovery mechanism if the configuration fails to load, to enhance the robustness of the service startup process.

test/iotivity-lite/service/republish_test.go (1)

Line range hint 59-61: The TLS configuration is missing a minimum version specification. This is a security best practice to ensure the use of up-to-date and secure TLS protocols.

- RootCAs: test.GetRootCertificatePool(t),
+ RootCAs: test.GetRootCertificatePool(t), MinVersion: tls.VersionTLS13,
cloud2cloud-gateway/service/subscribeToDevices_test.go (1)

Line range hint 57-59: Update TLS configuration to use TLS 1.3.

The TLS configuration used in the test setup does not specify a minimum version, which could lead to the use of less secure protocols. Update this to use TLS 1.3.

- credentials.NewTLS(&tls.Config{ RootCAs: test.GetRootCertificatePool(t) })
+ credentials.NewTLS(&tls.Config{ RootCAs: test.GetRootCertificatePool(t), MinVersion: tls.VersionTLS13 })
snippet-service/pb/README.md (1)

Line range hint 1-416: The protocol documentation is comprehensive but contains several TODO comments which should be addressed to complete the documentation. Additionally, consider fixing the formatting inconsistencies in the unordered list indentation and the excessive blank lines throughout the document.

- TODO naming
+ Provide specific names for the fields and entities marked with TODO.
test/iotivity-lite/service/offboard_test.go (1)

Line range hint 66-68: Add MinVersion: tls.VersionTLS13 to the TLS configurations to ensure the use of a secure protocol version.

- RootCAs: test.GetRootCertificatePool(t),
+ RootCAs: test.GetRootCertificatePool(t), MinVersion: tls.VersionTLS13

Also applies to: 222-224, 285-287, 350-352, 421-423, 486-488

snippet-service/pb/doc.html (3)

276-276: Consider finalizing the naming for AppliedDeviceConfiguration.

It appears there is a placeholder comment "TODO naming" which suggests that the naming for AppliedDeviceConfiguration is not yet finalized. It would be beneficial to resolve this to ensure clarity in the documentation.


880-880: Clarify the humorous comment in IDFilter.

The comment "configuration/123?version=latest :) Jozko spravi :)" in the IDFilter section seems to be informal and possibly a placeholder. It would be appropriate to replace it with a more formal and informative description.


1078-1078: Clarify the description for the InvokeConfiguration method in SnippetService.

The description "streaming process of update configuration to invoker" could be expanded to provide more details about what the method does, how it should be used, and what the expected outcomes are.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3d487bf and e438968.
Files ignored due to path filters (5)
  • snippet-service/config.yaml is excluded by !**/*.yaml
  • snippet-service/pb/service.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • snippet-service/pb/service.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
  • snippet-service/pb/service.swagger.json is excluded by !**/*.json
  • snippet-service/pb/service_grpc.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (47)
  • .github/workflows/build-publish.yaml (1 hunks)
  • .golangci.yml (2 hunks)
  • Makefile (1 hunks)
  • bundle/Dockerfile (3 hunks)
  • bundle/nginx/nginx.conf.template (1 hunks)
  • bundle/run.sh (6 hunks)
  • cloud2cloud-gateway/service/subscribeToDevices_test.go (2 hunks)
  • cloud2cloud-gateway/test/events.go (1 hunks)
  • snippet-service/Makefile (1 hunks)
  • snippet-service/cmd/service/main.go (1 hunks)
  • snippet-service/pb/README.md (1 hunks)
  • snippet-service/pb/configuration.go (1 hunks)
  • snippet-service/pb/doc.html (1 hunks)
  • snippet-service/pb/service.proto (1 hunks)
  • snippet-service/service/config.go (1 hunks)
  • snippet-service/service/grpc/config.go (1 hunks)
  • snippet-service/service/grpc/server.go (1 hunks)
  • snippet-service/service/grpc/service.go (1 hunks)
  • snippet-service/service/http/config.go (1 hunks)
  • snippet-service/service/http/createConfiguration_test.go (1 hunks)
  • snippet-service/service/http/getConfigurations_test.go (1 hunks)
  • snippet-service/service/http/requestHandler.go (1 hunks)
  • snippet-service/service/http/service.go (1 hunks)
  • snippet-service/service/http/updateConfiguration_test.go (1 hunks)
  • snippet-service/service/http/uri.go (1 hunks)
  • snippet-service/service/service.go (1 hunks)
  • snippet-service/service/service_test.go (1 hunks)
  • snippet-service/store/condition.go (1 hunks)
  • snippet-service/store/config/config.go (1 hunks)
  • snippet-service/store/configuration.go (1 hunks)
  • snippet-service/store/cqldb/config.go (1 hunks)
  • snippet-service/store/cqldb/configuration.go (1 hunks)
  • snippet-service/store/cqldb/store.go (1 hunks)
  • snippet-service/store/mongodb/config.go (1 hunks)
  • snippet-service/store/mongodb/configuration.go (1 hunks)
  • snippet-service/store/mongodb/configuration_internal_test.go (1 hunks)
  • snippet-service/store/mongodb/configuration_test.go (1 hunks)
  • snippet-service/store/mongodb/store.go (1 hunks)
  • snippet-service/store/store.go (1 hunks)
  • snippet-service/test/configuration.go (1 hunks)
  • snippet-service/test/service.go (1 hunks)
  • snippet-service/test/test.go (1 hunks)
  • test/config/config.go (1 hunks)
  • test/http/request.go (1 hunks)
  • test/http/uri.go (1 hunks)
  • test/iotivity-lite/service/offboard_test.go (2 hunks)
  • test/iotivity-lite/service/republish_test.go (1 hunks)
Files not reviewed due to errors (2)
  • snippet-service/pb/service.proto (no review received)
  • bundle/Dockerfile (no review received)
Files skipped from review due to trivial changes (9)
  • .golangci.yml
  • Makefile
  • cloud2cloud-gateway/test/events.go
  • snippet-service/service/grpc/config.go
  • snippet-service/service/http/uri.go
  • snippet-service/service/service_test.go
  • snippet-service/store/condition.go
  • snippet-service/store/mongodb/config.go
  • test/config/config.go
Additional Context Used
LanguageTool (4)
snippet-service/pb/README.md (4)

Near line 7: Possible typo: you repeated a word
Context: ...nippet-service_pb_service-proto) - AppliedDeviceConfiguration - [AppliedDeviceConfiguration.RelationTo](#snippetservice-pb-AppliedD...
Rule ID: ENGLISH_WORD_REPEAT_RULE


Near line 11: Possible typo: you repeated a word
Context: ...n](#snippetservice-pb-Condition) - Configuration - [Configuration.Resource](#snippetservice-pb-Configurat...
Rule ID: ENGLISH_WORD_REPEAT_RULE


Near line 89: To form a complete sentence, be sure to include a subject.
Context: ...eused from invoke command or generated. Can be used to retrieve corresponding pendi...
Rule ID: MISSING_IT_THERE


Near line 89: Possible missing article found.
Context: ...d or generated. Can be used to retrieve corresponding pending command. | | status | [AppliedD...
Rule ID: AI_HYDRA_LEO_MISSING_THE

ShellCheck (263)
bundle/run.sh (263)

[info] 53-53: Possible misspelling: SCYLLA_PORT may not be assigned. Did you mean SCYLLA_HOST?


[info] 56-56: Possible misspelling: NATS_PORT may not be assigned. Did you mean NATS_HOST?


[info] 108-108: Double quote to prevent globbing and word splitting.


[info] 132-132: Double quote to prevent globbing and word splitting.


[info] 141-141: Double quote to prevent globbing and word splitting.


[info] 141-141: Double quote to prevent globbing and word splitting.


[info] 147-147: Double quote to prevent globbing and word splitting.


[info] 148-148: Double quote to prevent globbing and word splitting.


[info] 148-148: Double quote to prevent globbing and word splitting.


[info] 152-152: Double quote to prevent globbing and word splitting.


[info] 153-153: Double quote to prevent globbing and word splitting.


[info] 154-154: Double quote to prevent globbing and word splitting.


[info] 155-155: Double quote to prevent globbing and word splitting.


[info] 161-161: Double quote to prevent globbing and word splitting.


[info] 162-162: Double quote to prevent globbing and word splitting.


[info] 162-162: Double quote to prevent globbing and word splitting.


[style] 177-177: Use $(...) notation instead of legacy backticks ....


[info] 177-177: Double quote to prevent globbing and word splitting.


[warning] 178-178: Quote this to prevent word splitting.


[style] 178-178: Use $(...) notation instead of legacy backticks ....


[info] 178-178: Double quote to prevent globbing and word splitting.


[info] 180-180: Double quote to prevent globbing and word splitting.


[style] 185-185: Use $(...) notation instead of legacy backticks ....


[info] 185-185: Double quote to prevent globbing and word splitting.


[warning] 186-186: Quote this to prevent word splitting.


[style] 186-186: Use $(...) notation instead of legacy backticks ....


[info] 186-186: Double quote to prevent globbing and word splitting.


[info] 188-188: Double quote to prevent globbing and word splitting.


[style] 193-193: Use $(...) notation instead of legacy backticks ....


[info] 193-193: Double quote to prevent globbing and word splitting.


[warning] 194-194: Quote this to prevent word splitting.


[style] 194-194: Use $(...) notation instead of legacy backticks ....


[info] 194-194: Double quote to prevent globbing and word splitting.


[info] 196-196: Double quote to prevent globbing and word splitting.


[style] 202-202: Use $(...) notation instead of legacy backticks ....


[info] 202-202: Double quote to prevent globbing and word splitting.


[warning] 203-203: Quote this to prevent word splitting.


[style] 203-203: Use $(...) notation instead of legacy backticks ....


[info] 203-203: Double quote to prevent globbing and word splitting.


[info] 205-205: Double quote to prevent globbing and word splitting.


[style] 210-210: Use $(...) notation instead of legacy backticks ....


[info] 210-210: Double quote to prevent globbing and word splitting.


[warning] 211-211: Quote this to prevent word splitting.


[style] 211-211: Use $(...) notation instead of legacy backticks ....


[info] 211-211: Double quote to prevent globbing and word splitting.


[info] 213-213: Double quote to prevent globbing and word splitting.


[style] 218-218: Use $(...) notation instead of legacy backticks ....


[info] 218-218: Double quote to prevent globbing and word splitting.


[warning] 219-219: Quote this to prevent word splitting.


[style] 219-219: Use $(...) notation instead of legacy backticks ....


[info] 219-219: Double quote to prevent globbing and word splitting.


[info] 221-221: Double quote to prevent globbing and word splitting.


[style] 228-228: Use $(...) notation instead of legacy backticks ....


[info] 228-228: Double quote to prevent globbing and word splitting.


[warning] 229-229: Quote this to prevent word splitting.


[style] 229-229: Use $(...) notation instead of legacy backticks ....


[info] 229-229: Double quote to prevent globbing and word splitting.


[info] 231-231: Double quote to prevent globbing and word splitting.


[style] 236-236: Use $(...) notation instead of legacy backticks ....


[info] 236-236: Double quote to prevent globbing and word splitting.


[warning] 237-237: Quote this to prevent word splitting.


[style] 237-237: Use $(...) notation instead of legacy backticks ....


[info] 237-237: Double quote to prevent globbing and word splitting.


[info] 239-239: Double quote to prevent globbing and word splitting.


[style] 244-244: Use $(...) notation instead of legacy backticks ....


[info] 244-244: Double quote to prevent globbing and word splitting.


[warning] 245-245: Quote this to prevent word splitting.


[style] 245-245: Use $(...) notation instead of legacy backticks ....


[info] 245-245: Double quote to prevent globbing and word splitting.


[info] 247-247: Double quote to prevent globbing and word splitting.


[style] 254-254: Use $(...) notation instead of legacy backticks ....


[info] 254-254: Double quote to prevent globbing and word splitting.


[warning] 255-255: Quote this to prevent word splitting.


[style] 255-255: Use $(...) notation instead of legacy backticks ....


[info] 255-255: Double quote to prevent globbing and word splitting.


[info] 257-257: Double quote to prevent globbing and word splitting.


[style] 262-262: Use $(...) notation instead of legacy backticks ....


[info] 262-262: Double quote to prevent globbing and word splitting.


[warning] 263-263: Quote this to prevent word splitting.


[style] 263-263: Use $(...) notation instead of legacy backticks ....


[info] 263-263: Double quote to prevent globbing and word splitting.


[info] 265-265: Double quote to prevent globbing and word splitting.


[style] 270-270: Use $(...) notation instead of legacy backticks ....


[info] 270-270: Double quote to prevent globbing and word splitting.


[warning] 271-271: Quote this to prevent word splitting.


[style] 271-271: Use $(...) notation instead of legacy backticks ....


[info] 271-271: Double quote to prevent globbing and word splitting.


[info] 273-273: Double quote to prevent globbing and word splitting.


[style] 280-280: Use $(...) notation instead of legacy backticks ....


[info] 280-280: Double quote to prevent globbing and word splitting.


[warning] 281-281: Quote this to prevent word splitting.


[style] 281-281: Use $(...) notation instead of legacy backticks ....


[info] 281-281: Double quote to prevent globbing and word splitting.


[info] 283-283: Double quote to prevent globbing and word splitting.


[style] 288-288: Use $(...) notation instead of legacy backticks ....


[info] 288-288: Double quote to prevent globbing and word splitting.


[warning] 289-289: Quote this to prevent word splitting.


[style] 289-289: Use $(...) notation instead of legacy backticks ....


[info] 289-289: Double quote to prevent globbing and word splitting.


[info] 291-291: Double quote to prevent globbing and word splitting.


[style] 296-296: Use $(...) notation instead of legacy backticks ....


[info] 296-296: Double quote to prevent globbing and word splitting.


[warning] 297-297: Quote this to prevent word splitting.


[style] 297-297: Use $(...) notation instead of legacy backticks ....


[info] 297-297: Double quote to prevent globbing and word splitting.


[info] 299-299: Double quote to prevent globbing and word splitting.


[style] 306-306: Use $(...) notation instead of legacy backticks ....


[info] 306-306: Double quote to prevent globbing and word splitting.


[warning] 307-307: Quote this to prevent word splitting.


[style] 307-307: Use $(...) notation instead of legacy backticks ....


[info] 307-307: Double quote to prevent globbing and word splitting.


[info] 309-309: Double quote to prevent globbing and word splitting.


[style] 314-314: Use $(...) notation instead of legacy backticks ....


[info] 314-314: Double quote to prevent globbing and word splitting.


[warning] 315-315: Quote this to prevent word splitting.


[style] 315-315: Use $(...) notation instead of legacy backticks ....


[info] 315-315: Double quote to prevent globbing and word splitting.


[info] 317-317: Double quote to prevent globbing and word splitting.


[style] 322-322: Use $(...) notation instead of legacy backticks ....


[info] 322-322: Double quote to prevent globbing and word splitting.


[warning] 323-323: Quote this to prevent word splitting.


[style] 323-323: Use $(...) notation instead of legacy backticks ....


[info] 323-323: Double quote to prevent globbing and word splitting.


[info] 325-325: Double quote to prevent globbing and word splitting.


[style] 332-332: Use $(...) notation instead of legacy backticks ....


[info] 332-332: Double quote to prevent globbing and word splitting.


[warning] 333-333: Quote this to prevent word splitting.


[style] 333-333: Use $(...) notation instead of legacy backticks ....


[info] 333-333: Double quote to prevent globbing and word splitting.


[info] 335-335: Double quote to prevent globbing and word splitting.


[style] 340-340: Use $(...) notation instead of legacy backticks ....


[info] 340-340: Double quote to prevent globbing and word splitting.


[warning] 341-341: Quote this to prevent word splitting.


[style] 341-341: Use $(...) notation instead of legacy backticks ....


[info] 341-341: Double quote to prevent globbing and word splitting.


[info] 343-343: Double quote to prevent globbing and word splitting.


[style] 348-348: Use $(...) notation instead of legacy backticks ....


[info] 348-348: Double quote to prevent globbing and word splitting.


[warning] 349-349: Quote this to prevent word splitting.


[style] 349-349: Use $(...) notation instead of legacy backticks ....


[info] 349-349: Double quote to prevent globbing and word splitting.


[info] 351-351: Double quote to prevent globbing and word splitting.


[style] 358-358: Use $(...) notation instead of legacy backticks ....


[info] 358-358: Double quote to prevent globbing and word splitting.


[warning] 359-359: Quote this to prevent word splitting.


[style] 359-359: Use $(...) notation instead of legacy backticks ....


[info] 359-359: Double quote to prevent globbing and word splitting.


[info] 361-361: Double quote to prevent globbing and word splitting.


[style] 366-366: Use $(...) notation instead of legacy backticks ....


[info] 366-366: Double quote to prevent globbing and word splitting.


[warning] 367-367: Quote this to prevent word splitting.


[style] 367-367: Use $(...) notation instead of legacy backticks ....


[info] 367-367: Double quote to prevent globbing and word splitting.


[info] 369-369: Double quote to prevent globbing and word splitting.


[style] 374-374: Use $(...) notation instead of legacy backticks ....


[info] 374-374: Double quote to prevent globbing and word splitting.


[warning] 375-375: Quote this to prevent word splitting.


[style] 375-375: Use $(...) notation instead of legacy backticks ....


[info] 375-375: Double quote to prevent globbing and word splitting.


[info] 377-377: Double quote to prevent globbing and word splitting.


[style] 384-384: Use $(...) notation instead of legacy backticks ....


[info] 384-384: Double quote to prevent globbing and word splitting.


[warning] 385-385: Quote this to prevent word splitting.


[style] 385-385: Use $(...) notation instead of legacy backticks ....


[info] 385-385: Double quote to prevent globbing and word splitting.


[info] 387-387: Double quote to prevent globbing and word splitting.


[style] 392-392: Use $(...) notation instead of legacy backticks ....


[info] 392-392: Double quote to prevent globbing and word splitting.


[warning] 393-393: Quote this to prevent word splitting.


[style] 393-393: Use $(...) notation instead of legacy backticks ....


[info] 393-393: Double quote to prevent globbing and word splitting.


[info] 395-395: Double quote to prevent globbing and word splitting.


[style] 400-400: Use $(...) notation instead of legacy backticks ....


[info] 400-400: Double quote to prevent globbing and word splitting.


[warning] 401-401: Quote this to prevent word splitting.


[style] 401-401: Use $(...) notation instead of legacy backticks ....


[info] 401-401: Double quote to prevent globbing and word splitting.


[info] 403-403: Double quote to prevent globbing and word splitting.


[style] 410-410: Use $(...) notation instead of legacy backticks ....


[info] 410-410: Double quote to prevent globbing and word splitting.


[warning] 411-411: Quote this to prevent word splitting.


[style] 411-411: Use $(...) notation instead of legacy backticks ....


[info] 411-411: Double quote to prevent globbing and word splitting.


[info] 413-413: Double quote to prevent globbing and word splitting.


[style] 418-418: Use $(...) notation instead of legacy backticks ....


[info] 418-418: Double quote to prevent globbing and word splitting.


[warning] 419-419: Quote this to prevent word splitting.


[style] 419-419: Use $(...) notation instead of legacy backticks ....


[info] 419-419: Double quote to prevent globbing and word splitting.


[info] 421-421: Double quote to prevent globbing and word splitting.


[style] 426-426: Use $(...) notation instead of legacy backticks ....


[info] 426-426: Double quote to prevent globbing and word splitting.


[warning] 427-427: Quote this to prevent word splitting.


[style] 427-427: Use $(...) notation instead of legacy backticks ....


[info] 427-427: Double quote to prevent globbing and word splitting.


[info] 429-429: Double quote to prevent globbing and word splitting.


[info] 504-504: Double quote to prevent globbing and word splitting.


[style] 521-521: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 537-537: Double quote to prevent globbing and word splitting.


[info] 549-549: Double quote to prevent globbing and word splitting.


[info] 552-552: Consider using pgrep instead of grepping ps output.


[style] 553-553: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 571-571: Double quote to prevent globbing and word splitting.


[info] 585-585: Double quote to prevent globbing and word splitting.


[info] 607-607: Double quote to prevent globbing and word splitting.


[style] 619-619: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 649-649: Double quote to prevent globbing and word splitting.


[style] 659-659: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 696-696: Double quote to prevent globbing and word splitting.


[style] 708-708: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 747-747: Double quote to prevent globbing and word splitting.


[style] 757-757: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 799-799: Double quote to prevent globbing and word splitting.


[style] 810-810: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[style] 863-863: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[style] 916-916: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 953-953: Double quote to prevent globbing and word splitting.


[style] 964-964: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 997-997: Double quote to prevent globbing and word splitting.


[style] 1008-1008: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 1048-1048: Double quote to prevent globbing and word splitting.


[style] 1058-1058: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 1093-1093: Double quote to prevent globbing and word splitting.


[style] 1103-1103: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 1145-1145: Double quote to prevent globbing and word splitting.


[style] 1156-1156: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


[info] 1191-1191: Double quote to prevent globbing and word splitting.


[info] 1206-1206: Consider using pgrep instead of grepping ps output.


[style] 1207-1207: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1213-1213: Consider using pgrep instead of grepping ps output.


[style] 1214-1214: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1220-1220: Consider using pgrep instead of grepping ps output.


[style] 1221-1221: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1227-1227: Consider using pgrep instead of grepping ps output.


[style] 1228-1228: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1234-1234: Consider using pgrep instead of grepping ps output.


[style] 1235-1235: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[style] 1241-1241: Use -n instead of ! -z.


[info] 1242-1242: Consider using pgrep instead of grepping ps output.


[info] 1242-1242: Double quote to prevent globbing and word splitting.


[style] 1243-1243: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1250-1250: Consider using pgrep instead of grepping ps output.


[style] 1251-1251: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1257-1257: Consider using pgrep instead of grepping ps output.


[style] 1258-1258: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1264-1264: Consider using pgrep instead of grepping ps output.


[style] 1265-1265: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1271-1271: Consider using pgrep instead of grepping ps output.


[style] 1272-1272: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1278-1278: Consider using pgrep instead of grepping ps output.


[style] 1279-1279: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1285-1285: Consider using pgrep instead of grepping ps output.


[style] 1286-1286: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1292-1292: Consider using pgrep instead of grepping ps output.


[style] 1293-1293: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1299-1299: Consider using pgrep instead of grepping ps output.


[style] 1300-1300: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[style] 1306-1306: Use -n instead of ! -z.


[info] 1307-1307: Consider using pgrep instead of grepping ps output.


[info] 1307-1307: Double quote to prevent globbing and word splitting.


[style] 1308-1308: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.


[info] 1315-1315: Consider using pgrep instead of grepping ps output.


[style] 1316-1316: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.

Markdownlint (168)
snippet-service/pb/README.md (168)

7: Expected: 2; Actual: 4
Unordered list indentation


8: Expected: 2; Actual: 4
Unordered list indentation


9: Expected: 2; Actual: 4
Unordered list indentation


10: Expected: 2; Actual: 4
Unordered list indentation


11: Expected: 2; Actual: 4
Unordered list indentation


12: Expected: 2; Actual: 4
Unordered list indentation


13: Expected: 2; Actual: 4
Unordered list indentation


14: Expected: 2; Actual: 4
Unordered list indentation


15: Expected: 2; Actual: 4
Unordered list indentation


16: Expected: 2; Actual: 4
Unordered list indentation


17: Expected: 2; Actual: 4
Unordered list indentation


18: Expected: 2; Actual: 4
Unordered list indentation


19: Expected: 2; Actual: 4
Unordered list indentation


20: Expected: 2; Actual: 4
Unordered list indentation


21: Expected: 2; Actual: 4
Unordered list indentation


22: Expected: 2; Actual: 4
Unordered list indentation


23: Expected: 2; Actual: 4
Unordered list indentation


25: Expected: 2; Actual: 4
Unordered list indentation


27: Expected: 2; Actual: 4
Unordered list indentation


352: Expected: 0 or 2; Actual: 1
Trailing spaces


368: Expected: 0 or 2; Actual: 1
Trailing spaces


370: Expected: 0 or 2; Actual: 1
Trailing spaces


392: Expected: 0 or 2; Actual: 1
Trailing spaces


31: Expected: 1; Actual: 2
Multiple consecutive blank lines


32: Expected: 1; Actual: 3
Multiple consecutive blank lines


38: Expected: 1; Actual: 2
Multiple consecutive blank lines


39: Expected: 1; Actual: 3
Multiple consecutive blank lines


45: Expected: 1; Actual: 2
Multiple consecutive blank lines


59: Expected: 1; Actual: 2
Multiple consecutive blank lines


60: Expected: 1; Actual: 3
Multiple consecutive blank lines


61: Expected: 1; Actual: 4
Multiple consecutive blank lines


62: Expected: 1; Actual: 5
Multiple consecutive blank lines


63: Expected: 1; Actual: 6
Multiple consecutive blank lines


69: Expected: 1; Actual: 2
Multiple consecutive blank lines


75: Expected: 1; Actual: 2
Multiple consecutive blank lines


76: Expected: 1; Actual: 3
Multiple consecutive blank lines


77: Expected: 1; Actual: 4
Multiple consecutive blank lines


78: Expected: 1; Actual: 5
Multiple consecutive blank lines


79: Expected: 1; Actual: 6
Multiple consecutive blank lines


84: Expected: 1; Actual: 2
Multiple consecutive blank lines


85: Expected: 1; Actual: 3
Multiple consecutive blank lines


93: Expected: 1; Actual: 2
Multiple consecutive blank lines


94: Expected: 1; Actual: 3
Multiple consecutive blank lines


95: Expected: 1; Actual: 4
Multiple consecutive blank lines


96: Expected: 1; Actual: 5
Multiple consecutive blank lines


97: Expected: 1; Actual: 6
Multiple consecutive blank lines


103: Expected: 1; Actual: 2
Multiple consecutive blank lines


133: Expected: 1; Actual: 2
Multiple consecutive blank lines


134: Expected: 1; Actual: 3
Multiple consecutive blank lines


135: Expected: 1; Actual: 4
Multiple consecutive blank lines


136: Expected: 1; Actual: 5
Multiple consecutive blank lines


137: Expected: 1; Actual: 6
Multiple consecutive blank lines


142: Expected: 1; Actual: 2
Multiple consecutive blank lines


143: Expected: 1; Actual: 3
Multiple consecutive blank lines


157: Expected: 1; Actual: 2
Multiple consecutive blank lines


158: Expected: 1; Actual: 3
Multiple consecutive blank lines


159: Expected: 1; Actual: 4
Multiple consecutive blank lines


160: Expected: 1; Actual: 5
Multiple consecutive blank lines


161: Expected: 1; Actual: 6
Multiple consecutive blank lines


166: Expected: 1; Actual: 2
Multiple consecutive blank lines


167: Expected: 1; Actual: 3
Multiple consecutive blank lines


174: Expected: 1; Actual: 2
Multiple consecutive blank lines


175: Expected: 1; Actual: 3
Multiple consecutive blank lines


176: Expected: 1; Actual: 4
Multiple consecutive blank lines


177: Expected: 1; Actual: 5
Multiple consecutive blank lines


178: Expected: 1; Actual: 6
Multiple consecutive blank lines


183: Expected: 1; Actual: 2
Multiple consecutive blank lines


184: Expected: 1; Actual: 3
Multiple consecutive blank lines


189: Expected: 1; Actual: 2
Multiple consecutive blank lines


190: Expected: 1; Actual: 3
Multiple consecutive blank lines


191: Expected: 1; Actual: 4
Multiple consecutive blank lines


192: Expected: 1; Actual: 5
Multiple consecutive blank lines


193: Expected: 1; Actual: 6
Multiple consecutive blank lines


198: Expected: 1; Actual: 2
Multiple consecutive blank lines


199: Expected: 1; Actual: 3
Multiple consecutive blank lines


204: Expected: 1; Actual: 2
Multiple consecutive blank lines


205: Expected: 1; Actual: 3
Multiple consecutive blank lines


206: Expected: 1; Actual: 4
Multiple consecutive blank lines


207: Expected: 1; Actual: 5
Multiple consecutive blank lines


208: Expected: 1; Actual: 6
Multiple consecutive blank lines


213: Expected: 1; Actual: 2
Multiple consecutive blank lines


214: Expected: 1; Actual: 3
Multiple consecutive blank lines


219: Expected: 1; Actual: 2
Multiple consecutive blank lines


220: Expected: 1; Actual: 3
Multiple consecutive blank lines


221: Expected: 1; Actual: 4
Multiple consecutive blank lines


222: Expected: 1; Actual: 5
Multiple consecutive blank lines


223: Expected: 1; Actual: 6
Multiple consecutive blank lines


228: Expected: 1; Actual: 2
Multiple consecutive blank lines


229: Expected: 1; Actual: 3
Multiple consecutive blank lines


234: Expected: 1; Actual: 2
Multiple consecutive blank lines


235: Expected: 1; Actual: 3
Multiple consecutive blank lines


236: Expected: 1; Actual: 4
Multiple consecutive blank lines


237: Expected: 1; Actual: 5
Multiple consecutive blank lines


238: Expected: 1; Actual: 6
Multiple consecutive blank lines


243: Expected: 1; Actual: 2
Multiple consecutive blank lines


244: Expected: 1; Actual: 3
Multiple consecutive blank lines


249: Expected: 1; Actual: 2
Multiple consecutive blank lines


250: Expected: 1; Actual: 3
Multiple consecutive blank lines


251: Expected: 1; Actual: 4
Multiple consecutive blank lines


252: Expected: 1; Actual: 5
Multiple consecutive blank lines


253: Expected: 1; Actual: 6
Multiple consecutive blank lines


258: Expected: 1; Actual: 2
Multiple consecutive blank lines


259: Expected: 1; Actual: 3
Multiple consecutive blank lines


264: Expected: 1; Actual: 2
Multiple consecutive blank lines


265: Expected: 1; Actual: 3
Multiple consecutive blank lines


266: Expected: 1; Actual: 4
Multiple consecutive blank lines


267: Expected: 1; Actual: 5
Multiple consecutive blank lines


268: Expected: 1; Actual: 6
Multiple consecutive blank lines


274: Expected: 1; Actual: 2
Multiple consecutive blank lines


282: Expected: 1; Actual: 2
Multiple consecutive blank lines


283: Expected: 1; Actual: 3
Multiple consecutive blank lines


284: Expected: 1; Actual: 4
Multiple consecutive blank lines


285: Expected: 1; Actual: 5
Multiple consecutive blank lines


286: Expected: 1; Actual: 6
Multiple consecutive blank lines


291: Expected: 1; Actual: 2
Multiple consecutive blank lines


292: Expected: 1; Actual: 3
Multiple consecutive blank lines


297: Expected: 1; Actual: 2
Multiple consecutive blank lines


298: Expected: 1; Actual: 3
Multiple consecutive blank lines


299: Expected: 1; Actual: 4
Multiple consecutive blank lines


300: Expected: 1; Actual: 5
Multiple consecutive blank lines


301: Expected: 1; Actual: 6
Multiple consecutive blank lines


306: Expected: 1; Actual: 2
Multiple consecutive blank lines


307: Expected: 1; Actual: 3
Multiple consecutive blank lines


312: Expected: 1; Actual: 2
Multiple consecutive blank lines


313: Expected: 1; Actual: 3
Multiple consecutive blank lines


314: Expected: 1; Actual: 4
Multiple consecutive blank lines


315: Expected: 1; Actual: 5
Multiple consecutive blank lines


316: Expected: 1; Actual: 6
Multiple consecutive blank lines


322: Expected: 1; Actual: 2
Multiple consecutive blank lines


330: Expected: 1; Actual: 2
Multiple consecutive blank lines


331: Expected: 1; Actual: 3
Multiple consecutive blank lines


332: Expected: 1; Actual: 4
Multiple consecutive blank lines


333: Expected: 1; Actual: 5
Multiple consecutive blank lines


334: Expected: 1; Actual: 6
Multiple consecutive blank lines


339: Expected: 1; Actual: 2
Multiple consecutive blank lines


340: Expected: 1; Actual: 3
Multiple consecutive blank lines


348: Expected: 1; Actual: 2
Multiple consecutive blank lines


349: Expected: 1; Actual: 3
Multiple consecutive blank lines


350: Expected: 1; Actual: 4
Multiple consecutive blank lines


351: Expected: 1; Actual: 5
Multiple consecutive blank lines


352: Expected: 1; Actual: 6
Multiple consecutive blank lines


353: Expected: 1; Actual: 7
Multiple consecutive blank lines


354: Expected: 1; Actual: 8
Multiple consecutive blank lines


359: Expected: 1; Actual: 2
Multiple consecutive blank lines


367: Expected: 1; Actual: 2
Multiple consecutive blank lines


368: Expected: 1; Actual: 3
Multiple consecutive blank lines


369: Expected: 1; Actual: 4
Multiple consecutive blank lines


370: Expected: 1; Actual: 5
Multiple consecutive blank lines


371: Expected: 1; Actual: 6
Multiple consecutive blank lines


372: Expected: 1; Actual: 7
Multiple consecutive blank lines


377: Expected: 1; Actual: 2
Multiple consecutive blank lines


392: Expected: 1; Actual: 2
Multiple consecutive blank lines


393: Expected: 1; Actual: 3
Multiple consecutive blank lines


394: Expected: 1; Actual: 4
Multiple consecutive blank lines


395: Expected: 1; Actual: 5
Multiple consecutive blank lines


416: Expected: 1; Actual: 2
Multiple consecutive blank lines


1: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


42: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


66: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


100: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


271: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


319: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


88: null
Link fragments should be valid


91: null
Link fragments should be valid


171: null
Link fragments should be valid


55: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style


106: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style


148: Expected: leading_and_trailing; Actual: leading_only; Missing trailing pipe
Table pipe style

Hadolint (17)
bundle/Dockerfile (17)

3: Pin versions in apk add. Instead of apk add <package> use apk add <package>=<version>


128: Multiple consecutive RUN instructions. Consider consolidation.


129: Multiple consecutive RUN instructions. Consider consolidation.


131: Multiple consecutive RUN instructions. Consider consolidation.


132: Multiple consecutive RUN instructions. Consider consolidation.


133: Multiple consecutive RUN instructions. Consider consolidation.


140: Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version>


140: Do not use apt as it is meant to be a end-user tool, use apt-get or apt-cache instead


144: Quote this to prevent word splitting.


144: Avoid use of wget without progress bar. Use wget --progress=dot:giga <url>. Or consider using -q or -nv (shorthands for --quiet or --no-verbose).


145: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check


146: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check


147: Do not use apt as it is meant to be a end-user tool, use apt-get or apt-cache instead


147: Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version>


182: Either use Wget or Curl but not both


182: Do not use sudo as it leads to unpredictable behavior. Use a tool like gosu to enforce root


182: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Additional comments not posted (51)
test/http/uri.go (1)

6-10: The addition of IDKey and ConfigurationIDKey aligns well with existing URI constants and supports the new functionality in snippet-service.

snippet-service/store/config/config.go (1)

1-9: The configuration type definition for integrating MongoDB and CQLDB is clear and follows good practices for structuring configurations in Go.

snippet-service/store/cqldb/config.go (1)

7-15: The configuration struct for CQLDB is well-defined, and the validation method is appropriately implemented.

snippet-service/service/http/config.go (1)

11-22: The HTTP configuration struct is robustly defined, and the validation method ensures all components are correctly configured.

snippet-service/pb/configuration.go (1)

12-25: The method for validating and normalizing Configuration objects is comprehensive, ensuring data integrity and consistency.

snippet-service/store/cqldb/configuration.go (1)

10-24: All CRUD operation methods in the CQLDB store return ErrNotSupported. Please verify if this is intentional and consider documenting the reason for these limitations to improve code clarity.

Would you like me to document these limitations in the code or open a GitHub issue to track this task?

snippet-service/store/configuration.go (3)

13-16: LGTM! The ConfigurationVersion struct is well-defined with appropriate BSON tags.


18-23: LGTM! The Configuration struct is well-defined with appropriate BSON tags.


25-31: LGTM! The MakeConfiguration function correctly initializes a Configuration instance from a protobuf message.

snippet-service/test/test.go (2)

13-19: LGTM! The CmpJSON function correctly compares JSON representations of objects.


35-42: LGTM! The CmpConfiguration function correctly compares configurations, handling resources separately.

snippet-service/store/mongodb/store.go (3)

19-21: The Store struct is correctly defined to embed the pkgMongo.Store. This allows leveraging existing MongoDB functionalities.


28-34: The creation of a unique index on _id and version is crucial for ensuring data integrity. This prevents duplicate configurations with the same version.


66-68: Simple and effective closure of the MongoDB store. It ensures that all resources are properly released.

test/iotivity-lite/service/republish_test.go (1)

48-48: The change from require.Greater to require.Positive is appropriate as it simplifies the assertion while ensuring that the count is above zero.

snippet-service/store/cqldb/store.go (1)

37-39: The Store struct is correctly defined to embed the cqldb.Store. This allows leveraging existing CQLDB functionalities.

snippet-service/store/store.go (2)

29-32: The Iterator interface is well-defined, providing a clear contract for iteration over collections.


69-79: The methods added to the Store interface for managing configurations are clear and concise. Ensure that the implementations of these methods handle errors appropriately and log significant events.

snippet-service/Makefile (2)

19-35: The build-docker-image definition is robust, incorporating dynamic tags and build arguments. Ensure that the Docker build context is correctly set to include all necessary files.


49-63: The proto/generate target is comprehensive, covering all necessary steps for generating protocol buffers, gRPC, and documentation. Ensure that all paths and dependencies are correctly configured to avoid build failures.

Verification successful

The paths for the googleapis directory and the service.proto file have been identified:

  • dependency/googleapis/
  • snippet-service/pb/service.proto

Let's verify the existence of these paths and files using the correct paths.


The necessary directories and files for the proto/generate target have been verified:

  • The googleapis directory exists at dependency/googleapis/.
  • The service.proto file exists at snippet-service/pb/service.proto.

This confirms that the paths and dependencies in the proto/generate target are correctly configured.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all paths and dependencies in the proto/generate target are correctly configured.

# Test: Check for the existence of necessary directories and files.
ls -l $(REPOSITORY_DIRECTORY)/dependency/googleapis $(REPOSITORY_DIRECTORY)/pb/service.proto

Length of output: 407



Script:

#!/bin/bash
# Description: Locate the necessary directories and files for the proto/generate target.

# Locate the googleapis directory
fd -t d googleapis

# Locate the service.proto file
fd -t f service.proto

Length of output: 273



Script:

#!/bin/bash
# Description: Verify the existence of necessary directories and files for the proto/generate target.

# Check for the existence of the googleapis directory
ls -l dependency/googleapis/

# Check for the existence of the service.proto file
ls -l snippet-service/pb/service.proto

Length of output: 162

snippet-service/test/service.go (4)

22-24: The HTTPURI function correctly constructs URIs for HTTP requests. This is a useful utility for tests that need to make network requests.


26-44: The MakeConfig function is well-implemented, setting up necessary configurations for testing. It's important to validate the configuration to catch any misconfigurations early.


46-73: The SetUp and New functions provide a clean way to set up and tear down the snippet-service for tests. The use of a sync.WaitGroup ensures that the service is properly shut down before the test exits.


75-97: The MakeStorageConfig function sets up storage configurations with options for MongoDB and CQLDB. Ensure that the configurations are tested to handle different storage scenarios effectively.

snippet-service/service/grpc/server.go (6)

25-33: Constructor implementation looks good and correctly initializes all fields.


36-44: Owner verification logic is correctly implemented to ensure security.


47-58: Method for creating configurations is well-implemented with appropriate error handling.


61-72: Update configuration method is correctly implemented with necessary owner checks and error handling.


75-102: Method for retrieving configurations is implemented correctly with streaming support and robust error handling.


105-107: Close method is simple and effective for cleaning up resources.

snippet-service/service/config.go (5)

18-39: Configuration struct and its validation method are correctly implemented, ensuring all fields are properly validated.


43-55: APIs configuration and validation are well-defined, ensuring both gRPC and HTTP configurations are validated.


58-67: HTTP configuration and its validation are properly implemented, ensuring the address is in a valid TCP format.


70-99: Storage configuration includes comprehensive validation, ensuring both embedded config and cleanup records are correctly formatted.


102-114: Clients configuration is well-structured with thorough validation for each client configuration.

snippet-service/store/mongodb/configuration_internal_test.go (1)

10-111: The test function for normalizing ID filters is well-implemented, covering various scenarios to ensure correct behavior.

.github/workflows/build-publish.yaml (1)

112-115: The GitHub Actions job for building and publishing the snippet-service image is correctly configured with appropriate directory and Dockerfile paths.

test/http/request.go (1)

105-111: The method ID in RequestBuilder is correctly implemented to add ID parameters to the URI. Consider enhancing the security of the TLS configuration.

- InsecureSkipVerify: true,
+ InsecureSkipVerify: true, MinVersion: tls.VersionTLS13

Likely invalid or redundant comment.

snippet-service/test/configuration.go (1)

22-29: Ensure consistent ID generation for configurations.

The function ConfigurationID ensures that each configuration ID is generated once and reused, which is crucial for consistency in tests that may rely on the ID being the same across different calls.

bundle/nginx/nginx.conf.template (1)

110-123: Ensure proper configuration for the new snippet service endpoint.

The configuration for the new /api/v1/snippets endpoint in the NGINX template is correctly set up to route traffic to the snippet service. This includes proper SSL configuration and CORS headers.

snippet-service/store/mongodb/configuration.go (1)

16-26: Ensure proper error handling for MongoDB operations.

Verification successful

The CreateConfiguration function in snippet-service/store/mongodb/configuration.go does handle errors returned by MongoDB operations. Specifically, it checks for errors after attempting to insert a document into the MongoDB collection and returns the error if one occurs.

  • snippet-service/store/mongodb/configuration.go:16-26

The function includes proper error handling for the MongoDB InsertOne operation, returning any errors encountered during the insertion process.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify MongoDB error handling in the `CreateConfiguration` function.

# Test: Search for MongoDB error handling patterns. Expect: Proper error handling.
rg --type python $'CreateConfiguration'

Length of output: 69



Script:

#!/bin/bash
# Description: Verify MongoDB error handling in the `CreateConfiguration` function.

# Test: Search for the `CreateConfiguration` function in Go files and check for proper error handling.
rg --type go 'func (s \*Store) CreateConfiguration' -A 10

Length of output: 59



Script:

#!/bin/bash
# Description: Verify MongoDB error handling in the `CreateConfiguration` function.

# Test: Search for the `CreateConfiguration` function in Go files and check for proper error handling.
rg 'func (s \*Store) CreateConfiguration' -t go -A 20

Length of output: 55



Script:

#!/bin/bash
# Description: Verify MongoDB error handling in the `CreateConfiguration` function.

# Test: Search for the `CreateConfiguration` function across the entire repository and check for proper error handling.
rg 'CreateConfiguration' -A 20

Length of output: 60097

snippet-service/store/mongodb/configuration_test.go (3)

34-141: The function TestStoreCreateConfiguration is well-structured and covers a comprehensive set of test cases for configuration creation.


143-232: The function TestUpdateConfiguration effectively tests various scenarios for updating configurations, ensuring robust error handling and validation.


234-519: The function TestStoreGetConfigurations is well-implemented, testing a variety of retrieval scenarios and ensuring the correct configurations are fetched based on different filters.

test/iotivity-lite/service/offboard_test.go (2)

52-52: Changes from require.Greater to require.Positive are appropriate and make the assertions clearer.

Also applies to: 58-58


340-340: Change from require.Greater to require.Positive is appropriate and makes the assertion clearer.

bundle/run.sh (5)

27-28: Added environment variables for SNIPPET_SERVICE_ADDRESS and HTTP_SNIPPET_SERVICE_PORT are correctly set.


1315-1321: Monitor the snippet-service process to ensure it does not exit unexpectedly. Consider enhancing the monitoring logic to provide more detailed diagnostics in case of failure.

- ps aux |grep $snippet_service_pid |grep -q -v grep
- if [ $? -ne 0 ]; then
-   echo "snippet-service has already exited."
-   sync
-   cat $LOGS_PATH/snippet-service.log
-   exit 1
- fi
+ if ! ps -p $snippet_service_pid > /dev/null; then
+   echo "snippet-service has already exited."
+   sync
+   cat $LOGS_PATH/snippet-service.log
+   exit 1
+ fi

Likely invalid or redundant comment.


457-457: Ensure the HTTP_SNIPPET_SERVICE_PORT is defined and correctly replaced in the nginx configuration.


18-18: Ensure the environment variable HTTP_CERTIFICATE_AUTHORITY_PORT is defined.

Verification successful

The environment variable HTTP_CERTIFICATE_AUTHORITY_PORT is defined in the bundle/Dockerfile as ENV HTTP_CERTIFICATE_AUTHORITY_PORT=9090.

  • bundle/Dockerfile: ENV HTTP_CERTIFICATE_AUTHORITY_PORT=9090
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if HTTP_CERTIFICATE_AUTHORITY_PORT is defined in the environment or configuration files.

# Test: Search for the definition of HTTP_CERTIFICATE_AUTHORITY_PORT. Expect: At least one occurrence.
rg --type bash 'HTTP_CERTIFICATE_AUTHORITY_PORT'

Length of output: 77



Script:

#!/bin/bash
# Description: Verify if HTTP_CERTIFICATE_AUTHORITY_PORT is defined in the environment or configuration files.

# Test: Search for the definition of HTTP_CERTIFICATE_AUTHORITY_PORT. Expect: At least one occurrence.
rg --type sh 'HTTP_CERTIFICATE_AUTHORITY_PORT'

Length of output: 276



Script:

#!/bin/bash
# Description: Verify if HTTP_CERTIFICATE_AUTHORITY_PORT is defined in common configuration files or environment setup scripts.

# Test: Search for the definition of HTTP_CERTIFICATE_AUTHORITY_PORT in .env, .bashrc, .bash_profile, and other shell scripts.
rg 'HTTP_CERTIFICATE_AUTHORITY_PORT' .env .bashrc .bash_profile
rg --type sh 'HTTP_CERTIFICATE_AUTHORITY_PORT'

Length of output: 487



Script:

#!/bin/bash
# Description: Verify if HTTP_CERTIFICATE_AUTHORITY_PORT is defined in any shell scripts or configuration files in the repository.

# Test: Search for the definition of HTTP_CERTIFICATE_AUTHORITY_PORT in all shell scripts and configuration files.
rg 'HTTP_CERTIFICATE_AUTHORITY_PORT'

Length of output: 459


1153-1185: The configuration and startup sequence for snippet-service is correctly implemented. Ensure that the configuration file /data/snippet-service.yaml is properly formatted and contains all necessary settings.

snippet-service/pb/doc.html Outdated Show resolved Hide resolved
snippet-service/pb/doc.html Outdated Show resolved Hide resolved
snippet-service/test/configuration.go Outdated Show resolved Hide resolved
snippet-service/service/service.go Show resolved Hide resolved
snippet-service/service/service.go Outdated Show resolved Hide resolved
snippet-service/test/test.go Show resolved Hide resolved
snippet-service/store/cqldb/store.go Outdated Show resolved Hide resolved
snippet-service/store/mongodb/configuration.go Outdated Show resolved Hide resolved
snippet-service/store/mongodb/configuration.go Outdated Show resolved Hide resolved
snippet-service/store/mongodb/configuration.go Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

TODO: remove values which are not used

@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch 3 times, most recently from f965fe1 to 3030d53 Compare May 28, 2024 20:28
{{- end }}
labels:
{{- include "plgd-hub.snippetservice.selectorLabels" . | nindent 8 }}
spec:

Check warning

Code scanning / SonarCloud

Service account tokens should not be mounted in pods Medium

Set automountServiceAccountToken to false for this specification of kind Deployment. See more on SonarCloud
{{- tpl .Values.snippetservice.initContainersTpl . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Values.snippetservice.name }}

Check warning

Code scanning / SonarCloud

Storage limits should be enforced Medium

Specify a storage limit for this container. See more on SonarCloud
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch 4 times, most recently from 9a88892 to a809956 Compare June 6, 2024 12:04
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch 4 times, most recently from e8bfe80 to df593f4 Compare June 12, 2024 12:46
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch 2 times, most recently from 687662b to b0eb4b5 Compare July 3, 2024 18:22
@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch from b0eb4b5 to cfe0d44 Compare July 3, 2024 18:28
charts/plgd-hub/values.yaml Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 marked this pull request as ready for review July 5, 2024 07:38
charts/plgd-hub/values.yaml Outdated Show resolved Hide resolved
charts/plgd-hub/values.yaml Outdated 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: 6

Outside diff range and nitpick comments (2)
grpc-gateway/client/observeResource_test.go (1)

29-29: Suggest additional assertions to verify correctness of observed resource.

Add assertions to verify the correctness of the observed resource, such as checking the resource's state or properties.

grpc-gateway/client/createResource_test.go (1)

71-71: Suggest additional test cases to cover more scenarios.

Add test cases to cover more scenarios, such as creating resources with different data or handling different error conditions.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e438968 and 37b395c.

Files ignored due to path filters (19)
  • charts/plgd-hub/templates/http-gateway/config.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/config.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/deployment.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/domain-crt.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/grpc-ingress.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/grpc-service.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/http-ingress.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/http-service.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/role.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/service-account.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/snippet-service/service-crt.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/values.yaml is excluded by !**/*.yaml
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • grpc-gateway/pb/devices.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/getPendingCommands.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/hubConfiguration.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • grpc-gateway/pb/service.swagger.json is excluded by !**/*.json
  • http-gateway/config.yaml is excluded by !**/*.yaml
Files selected for processing (54)
  • .github/workflows/build-publish.yaml (1 hunks)
  • .github/workflows/test.yml (5 hunks)
  • .vscode/settings.json (1 hunks)
  • Makefile (7 hunks)
  • bundle/Dockerfile (3 hunks)
  • bundle/nginx/nginx.conf.template (1 hunks)
  • bundle/run.sh (6 hunks)
  • charts/plgd-hub/templates/http-gateway/_helpers.tpl (1 hunks)
  • charts/plgd-hub/templates/snippet-service/_helpers.tpl (1 hunks)
  • cloud2cloud-gateway/service/retrieveDevice.go (2 hunks)
  • cloud2cloud-gateway/test/test.go (4 hunks)
  • coap-gateway/service/clientObserveHandler.go (3 hunks)
  • coap-gateway/service/clientSubscriber.go (1 hunks)
  • coap-gateway/service/observation/deviceObserver.go (3 hunks)
  • coap-gateway/service/resourceDirectory.go (1 hunks)
  • coap-gateway/service/signIn.go (3 hunks)
  • coap-gateway/test/test.go (1 hunks)
  • grpc-gateway/client/client_test.go (2 hunks)
  • grpc-gateway/client/createResource_test.go (2 hunks)
  • grpc-gateway/client/deleteResource_test.go (3 hunks)
  • grpc-gateway/client/deviceSubscriber.go (1 hunks)
  • grpc-gateway/client/deviceSubscriptions_test.go (4 hunks)
  • grpc-gateway/client/getDevice_test.go (2 hunks)
  • grpc-gateway/client/getDevices_test.go (2 hunks)
  • grpc-gateway/client/getResource_test.go (2 hunks)
  • grpc-gateway/client/maintenance.go (2 hunks)
  • grpc-gateway/client/maintenance_test.go (3 hunks)
  • grpc-gateway/client/observeDeviceResources_test.go (2 hunks)
  • grpc-gateway/client/observeDevices_test.go (2 hunks)
  • grpc-gateway/client/observeResource_test.go (2 hunks)
  • grpc-gateway/client/updateResource_test.go (3 hunks)
  • grpc-gateway/pb/README.md (5 hunks)
  • grpc-gateway/pb/createResource.go (2 hunks)
  • grpc-gateway/pb/deleteResource.go (2 hunks)
  • grpc-gateway/pb/devices.proto (3 hunks)
  • grpc-gateway/pb/doc.html (5 hunks)
  • grpc-gateway/pb/getPendingCommands.proto (1 hunks)
  • grpc-gateway/pb/hubConfiguration.proto (1 hunks)
  • grpc-gateway/pb/updateResource.go (2 hunks)
  • grpc-gateway/service/createResource.go (1 hunks)
  • grpc-gateway/service/deleteResource.go (1 hunks)
  • grpc-gateway/service/subscribeToEvents_test.go (4 hunks)
  • grpc-gateway/service/updateResource.go (1 hunks)
  • grpc-gateway/service/updateResource_test.go (2 hunks)
  • grpc-gateway/test/test.go (1 hunks)
  • http-gateway/service/config.go (1 hunks)
  • http-gateway/service/getDevicePendingCommands_test.go (2 hunks)
  • http-gateway/service/getDeviceResourceLinks_test.go (3 hunks)
  • http-gateway/service/getHubConfiguration.go (1 hunks)
  • http-gateway/service/getHubConfiguration_test.go (2 hunks)
  • http-gateway/service/getPendingCommands_test.go (2 hunks)
  • http-gateway/service/getResourcePendingCommands_test.go (2 hunks)
  • http-gateway/test/test.go (2 hunks)
  • http-gateway/uri/uri.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • .vscode/settings.json
Additional context used
Hadolint
bundle/Dockerfile

[error] 192-192: Do not use sudo as it leads to unpredictable behavior. Use a tool like gosu to enforce root

(DL3004)

LanguageTool
grpc-gateway/pb/README.md

[uncategorized] ~225-~225: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...validity in nanoseconds. 0 means forever and minimal value is 100000000 (100ms). | |...

(COMMA_COMPOUND_SENTENCE_2)


[uncategorized] ~225-~225: Possible missing comma found.
Context: ...onds. 0 means forever and minimal value is 100000000 (100ms). | | force | [bool](#...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~288-~288: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...validity in nanoseconds. 0 means forever and minimal value is 100000000 (100ms). | |...

(COMMA_COMPOUND_SENTENCE_2)


[uncategorized] ~288-~288: Possible missing comma found.
Context: ...onds. 0 means forever and minimal value is 100000000 (100ms). | | resource_interfa...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~700-~700: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...validity in nanoseconds. 0 means forever and minimal value is 100000000 (100ms). | |...

(COMMA_COMPOUND_SENTENCE_2)


[uncategorized] ~700-~700: Possible missing comma found.
Context: ...onds. 0 means forever and minimal value is 100000000 (100ms). | | content | [Conte...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~913-~913: Possible missing comma found.
Context: ...uests, use it multiple times as a query parameter like "resourceIdFilter={deviceID}{h...

(AI_HYDRA_LEO_MISSING_COMMA)


[formatting] ~913-~913: These punctuation marks differ from each other. Use only one if you are ending a sentence.
Context: ...34;resourceIdFilter={deviceID}{href}". | | include_hidden_resources | [bool](#...

(DOUBLE_PUNCTUATION_PREMIUM)

Markdownlint
grpc-gateway/pb/README.md

229-229: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


230-230: Expected: 1; Actual: 3
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


293-293: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


294-294: Expected: 1; Actual: 3
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


705-705: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


706-706: Expected: 1; Actual: 3
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


916-916: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


917-917: Expected: 1; Actual: 3
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


1062-1062: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


1063-1063: Expected: 1; Actual: 3
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


1059-1059: null
Bare URL used

(MD034, no-bare-urls)


1060-1060: null
Bare URL used

(MD034, no-bare-urls)

Additional comments not posted (117)
grpc-gateway/service/deleteResource.go (1)

10-18: Verify correctness of handleResourceRequest parameters.

Ensure that the parameters passed to handleResourceRequest are correct and match the expected types and values.

grpc-gateway/service/updateResource.go (1)

10-18: Verify correctness of handleResourceRequest parameters.

Ensure that the parameters passed to handleResourceRequest are correct and match the expected types and values.

Verification successful

The parameters passed to handleResourceRequest in the UpdateResource function are correct.

  • The parameters align with the expected types and values of the handleResourceRequest function.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the parameters passed to `handleResourceRequest` in `UpdateResource`.

# Test: Search for the `handleResourceRequest` function definition. Expect: Correct parameter types and values.
rg --type go 'func handleResourceRequest'

Length of output: 173


Script:

#!/bin/bash
# Description: Extract the `UpdateResource` function definition and check parameters passed to `handleResourceRequest`.

# Find the `UpdateResource` function in `grpc-gateway/service/updateResource.go`.
rg --type go --pcre2 'func UpdateResource' -A 20 grpc-gateway/service/updateResource.go

Length of output: 89


Script:

#!/bin/bash
# Description: Search for the `UpdateResource` function definition in the entire codebase and check parameters passed to `handleResourceRequest`.

# Find the `UpdateResource` function in the entire codebase.
rg --type go --pcre2 'func UpdateResource' -A 20

Length of output: 50


Script:

#!/bin/bash
# Description: Search for all `handleResourceRequest` calls in the codebase to identify where it is being used.

# Find all calls to `handleResourceRequest` in the codebase.
rg --type go 'handleResourceRequest'

Length of output: 397


Script:

#!/bin/bash
# Description: Extract more lines around the `handleResourceRequest` call in `grpc-gateway/service/updateResource.go` to identify the `UpdateResource` function and its parameters.

# Extract lines around the `handleResourceRequest` call in `grpc-gateway/service/updateResource.go`.
rg --type go 'handleResourceRequest' -A 10 -B 10 grpc-gateway/service/updateResource.go

Length of output: 510

coap-gateway/service/clientSubscriber.go (3)

14-18: LGTM!

The function is correctly structured and thread-safe.


20-25: LGTM!

The function is correctly structured and ensures that the deviceSubscriber is not nil before calling the method.


Line range hint 26-34:
LGTM!

The function is correctly structured and ensures proper cleanup of the deviceSubscriber.

grpc-gateway/pb/deleteResource.go (2)

Line range hint 8-34:
LGTM!

The function is correctly structured and includes the new Force field.


38-43: LGTM!

The function is correctly structured and ensures that the response object is not nil before setting the Data field.

grpc-gateway/pb/createResource.go (2)

39-39: LGTM!

The addition of the Force field is consistent with the rest of the function.


43-48: LGTM!

The SetData function correctly sets the Data field and handles the case where the receiver is nil.

grpc-gateway/pb/updateResource.go (2)

40-40: LGTM!

The addition of the Force field is consistent with the rest of the function.


44-49: LGTM!

The SetData function correctly sets the Data field and handles the case where the receiver is nil.

grpc-gateway/pb/getPendingCommands.proto (1)

23-23: LGTM!

The addition of the include_hidden_resources field to the GetPendingCommandsRequest message is consistent with the rest of the message structure.

charts/plgd-hub/templates/snippet-service/_helpers.tpl (7)

1-12: LGTM!

The template plgd-hub.snippetservice.fullname correctly handles the full name based on various conditions.


14-17: LGTM!

The template plgd-hub.snippetservice.configName correctly generates the configuration name based on the full name.


19-26: LGTM!

The template plgd-hub.snippetservice.createServiceCertByCm correctly handles the creation of the service certificate based on the presence of the tls.certFile.


28-34: LGTM!

The template plgd-hub.snippetservice.domain correctly generates the domain based on the presence of the snippetservice.domain value.


36-39: LGTM!

The template plgd-hub.snippetservice.serviceCertName correctly generates the service certificate name based on the full name.


41-48: LGTM!

The template plgd-hub.snippetservice.domainCertName correctly generates the domain certificate name based on the presence of the ingress.secretName.


50-53: LGTM!

The template plgd-hub.snippetservice.selectorLabels correctly generates the selector labels based on the snippetservice.name and Release.Name.

grpc-gateway/service/createResource.go (6)

13-14: LGTM!

The resourceError function is correctly implemented.


17-19: LGTM!

The reqRACommand type constraint is correctly defined.


21-23: LGTM!

The respCommand type constraint is correctly defined.


25-28: LGTM!

The reqCommand type constraint is correctly defined.


35-69: Verify the use of * as the owner in the synchronous call.

The use of * as the owner in the synchronous call to syncFunc might need verification to ensure it is intended and correct.


71-80: LGTM!

The CreateResource function is correctly implemented.

grpc-gateway/test/test.go (2)

20-34: LGTM!

The NewTestClient function is correctly implemented.


Line range hint 35-58: LGTM!

The MakeConfig function is correctly implemented.

grpc-gateway/client/observeDeviceResources_test.go (4)

29-31: Ensure the client is properly closed.

The client is properly closed using defer and error handling is done using require.NoError.


Line range hint 32-32:
Ensure the test logic remains intact.

The test logic remains intact, ensuring that device resources are observed correctly.


9-9: Verify the new import.

The new import grpcgwTest should be verified for correctness and consistency with the rest of the codebase.

Verification successful

The new import is verified and consistent.

The import grpcgwTest "github.com/plgd-dev/hub/v2/grpc-gateway/test" is consistently used across multiple test files in the codebase, indicating it is correct and properly integrated.

  • snippet-service/service/service_test.go
  • snippet-service/service/http/invokeConfiguration_test.go
  • snippet-service/updater/resourceUpdater_test.go
  • test/service/service.go
  • grpc-gateway/client/observeResource_test.go
  • grpc-gateway/client/createResource_test.go
  • grpc-gateway/client/observeDevices_test.go
  • grpc-gateway/client/updateResource_test.go
  • grpc-gateway/client/getDevices_test.go
  • grpc-gateway/client/getDevice_test.go
  • grpc-gateway/client/deleteResource_test.go
  • grpc-gateway/client/getResource_test.go
  • grpc-gateway/client/maintenance_test.go
  • grpc-gateway/client/observeDeviceResources_test.go
  • grpc-gateway/client/deviceSubscriptions_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import `grpcgwTest` is consistent with the codebase.

# Test: Search for the import usage. Expect: Consistent usage across the codebase.
rg --type go 'grpcgwTest "github.com/plgd-dev/hub/v2/grpc-gateway/test"'

Length of output: 1600


28-28: Verify the usage of grpcgwTest.NewTestClient.

Ensure that the usage of grpcgwTest.NewTestClient is correct and efficient.

Verification successful

The implementation of grpcgwTest.NewTestClient in grpc-gateway/test/test.go appears to be correct and efficient. The function sets up a test client with proper TLS configuration and error handling.

  • Correctness: The function correctly configures the TLS settings and creates a new client from the configuration. It ensures that there are no errors during the client creation process.
  • Efficiency: The function does not contain any redundant or inefficient operations.

No changes are necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `grpcgwTest.NewTestClient`.

# Test: Search for the usage of `grpcgwTest.NewTestClient`. Expect: Correct and efficient usage.
rg --type go 'grpcgwTest.NewTestClient'

Length of output: 1651


Script:

#!/bin/bash
# Searching for the implementation of `NewTestClient` in the `grpcgwTest` package.
ast-grep --lang go --pattern 'func NewTestClient($_) $_' 

Length of output: 900

grpc-gateway/client/maintenance.go (3)

69-69: Ensure the logic for updating maintenance resources remains intact.

The logic for updating maintenance resources remains intact, ensuring that the correct resource is updated based on the device ID and resource type.


6-6: Verify the new import.

The new import slices should be verified for correctness and consistency with the rest of the codebase.

Verification successful

The new import slices is correctly and consistently used across the codebase.

  • grpc-gateway/client/maintenance.go: Verified usage of slices.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import `slices` is consistent with the codebase.

# Test: Search for the import usage. Expect: Consistent usage across the codebase.
rg --type go 'slices'

Length of output: 5685


68-68: Verify the usage of slices.Contains.

Ensure that the usage of slices.Contains is correct and efficient for checking resource types.

Verification successful

The usage of slices.Contains is correct.

The method r.GetResourceTypes() returns a slice of strings ([]string), and maintenance.ResourceType is a string. Therefore, using slices.Contains to check if maintenance.ResourceType is in the slice returned by r.GetResourceTypes() is both correct and efficient.

  • grpc-gateway/client/maintenance.go:68
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `slices.Contains`.

# Test: Search for the usage of `slices.Contains`. Expect: Correct and efficient usage.
rg --type go 'slices.Contains'

Length of output: 1267


Script:

#!/bin/bash
# Verify the implementation of `r.GetResourceTypes()` and the definition of `maintenance.ResourceType`.

# Find all Go files and search for the implementation of `GetResourceTypes` method.
rg --type go 'func (.*) GetResourceTypes' 

# Find the definition of `maintenance.ResourceType`.
rg --type go 'ResourceType' 

Length of output: 72267

grpc-gateway/client/getDevices_test.go (4)

74-76: Ensure the client is properly closed.

The client is properly closed using defer and error handling is done using require.NoError.


Line range hint 77-77:
Ensure the test logic remains intact.

The test logic remains intact, ensuring that devices are retrieved correctly.


9-9: Verify the new import.

The new import grpcgwTest should be verified for correctness and consistency with the rest of the codebase.

Verification successful

Verified the new import.

The import statement grpcgwTest "github.com/plgd-dev/hub/v2/grpc-gateway/test" is consistently used across multiple test files in the codebase, indicating correctness.

  • Files with the same import:
    • snippet-service/service/service_test.go
    • snippet-service/updater/resourceUpdater_test.go
    • snippet-service/service/http/invokeConfiguration_test.go
    • test/service/service.go
    • grpc-gateway/client/deviceSubscriptions_test.go
    • grpc-gateway/client/maintenance_test.go
    • grpc-gateway/client/observeDevices_test.go
    • grpc-gateway/client/observeResource_test.go
    • grpc-gateway/client/getDevices_test.go
    • grpc-gateway/client/getDevice_test.go
    • grpc-gateway/client/observeDeviceResources_test.go
    • grpc-gateway/client/deleteResource_test.go
    • grpc-gateway/client/createResource_test.go
    • grpc-gateway/client/getResource_test.go
    • grpc-gateway/client/updateResource_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import `grpcgwTest` is consistent with the codebase.

# Test: Search for the import usage. Expect: Consistent usage across the codebase.
rg --type go 'grpcgwTest "github.com/plgd-dev/hub/v2/grpc-gateway/test"'

Length of output: 1600


73-73: Verify the usage of grpcgwTest.NewTestClient.

Ensure that the usage of grpcgwTest.NewTestClient is correct and efficient.

Verification successful

Verified the usage of grpcgwTest.NewTestClient.

The usage of grpcgwTest.NewTestClient in the test files is correct and efficient. The client is created, used appropriately, and closed with error handling, ensuring proper resource management.

  • No changes needed.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `grpcgwTest.NewTestClient`.

# Test: Search for the usage of `grpcgwTest.NewTestClient`. Expect: Correct and efficient usage.
rg --type go 'grpcgwTest.NewTestClient'

Length of output: 1651


Script:

#!/bin/bash
# Locate the definition of `grpcgwTest.NewTestClient` to understand its implementation.
ast-grep --lang go --pattern 'func NewTestClient($_) $_' --json

Length of output: 1169


Script:

#!/bin/bash
# Check the context of `grpcgwTest.NewTestClient` usage in the test files to ensure correct and efficient usage.
rg --type go -A 5 'grpcgwTest.NewTestClient'

Length of output: 10094

grpc-gateway/client/observeDevices_test.go (4)

28-30: Ensure the client is properly closed.

The client is properly closed using defer and error handling is done using require.NoError.


Line range hint 31-31:
Ensure the test logic remains intact.

The test logic remains intact, ensuring that devices are observed correctly.


10-10: Verify the new import.

The new import grpcgwTest should be verified for correctness and consistency with the rest of the codebase.

Verification successful

The new import is verified for correctness and consistency.

The import grpcgwTest "github.com/plgd-dev/hub/v2/grpc-gateway/test" is consistently used across various test files in the codebase, primarily to create test clients and configure GRPC gateway settings.

  • snippet-service/updater/resourceUpdater_test.go
  • snippet-service/service/service_test.go
  • snippet-service/service/http/invokeConfiguration_test.go
  • test/service/service.go
  • grpc-gateway/client/getDevices_test.go
  • grpc-gateway/client/deleteResource_test.go
  • grpc-gateway/client/observeDevices_test.go
  • grpc-gateway/client/observeResource_test.go
  • grpc-gateway/client/getResource_test.go
  • grpc-gateway/client/getDevice_test.go
  • grpc-gateway/client/maintenance_test.go
  • grpc-gateway/client/deviceSubscriptions_test.go
  • grpc-gateway/client/observeDeviceResources_test.go
  • grpc-gateway/client/createResource_test.go
  • grpc-gateway/client/updateResource_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import `grpcgwTest` is consistent with the codebase.

# Test: Search for the import usage. Expect: Consistent usage across the codebase.
rg --type go 'grpcgwTest "github.com/plgd-dev/hub/v2/grpc-gateway/test"'

Length of output: 1600


Script:

#!/bin/bash
# Description: Verify the usage of the imported `grpcgwTest` in the files where it is imported.

# Test: Search for `grpcgwTest` usage in the relevant test files.
files=(
    "snippet-service/updater/resourceUpdater_test.go"
    "snippet-service/service/service_test.go"
    "snippet-service/service/http/invokeConfiguration_test.go"
    "test/service/service.go"
    "grpc-gateway/client/getDevices_test.go"
    "grpc-gateway/client/deleteResource_test.go"
    "grpc-gateway/client/observeDevices_test.go"
    "grpc-gateway/client/observeResource_test.go"
    "grpc-gateway/client/getResource_test.go"
    "grpc-gateway/client/getDevice_test.go"
    "grpc-gateway/client/maintenance_test.go"
    "grpc-gateway/client/deviceSubscriptions_test.go"
    "grpc-gateway/client/observeDeviceResources_test.go"
    "grpc-gateway/client/createResource_test.go"
    "grpc-gateway/client/updateResource_test.go"
)

for file in "${files[@]}"; do
    echo "Checking usage in $file"
    rg 'grpcgwTest' "$file"
done

Length of output: 5715


27-27: Verify the usage of grpcgwTest.NewTestClient.

Ensure that the usage of grpcgwTest.NewTestClient is correct and efficient.

Verification successful

The usage of grpcgwTest.NewTestClient is correct and efficient.

  • The function NewTestClient is correctly implemented in grpc-gateway/test/test.go.
  • The import statement for grpcgwTest in grpc-gateway/client/observeDevices_test.go is correct.
  • The client is properly initialized and closed in the test file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `grpcgwTest.NewTestClient`.

# Test: Search for the usage of `grpcgwTest.NewTestClient`. Expect: Correct and efficient usage.
rg --type go 'grpcgwTest.NewTestClient'

Length of output: 1651


Script:

#!/bin/bash
# Locate the implementation of `NewTestClient` to understand its functionality.
ast-grep --lang go --pattern 'func NewTestClient($_) $_' 

# Check the imports in the test files to ensure `grpcgwTest` is properly imported.
rg --type go 'import' -A 5 -B 5 grpc-gateway/client/observeDevices_test.go

Length of output: 1045


Script:

#!/bin/bash
# Check the imports in the test files to ensure `grpcgwTest` is properly imported.
rg --type go 'grpcgwTest' -A 5 -B 5 grpc-gateway/client/observeDevices_test.go

Length of output: 882

grpc-gateway/pb/hubConfiguration.proto (1)

61-62: LGTM!

The addition of the snippet_service field to the UIConfiguration message is well-documented and follows the existing pattern.

grpc-gateway/client/maintenance_test.go (2)

54-56: LGTM!

The usage of grpcgwTest.NewTestClient in TestClientFactoryReset is correct and follows the existing pattern in the file.


108-110: LGTM!

The usage of grpcgwTest.NewTestClient in TestClientReboot is correct and follows the existing pattern in the file.

http-gateway/test/test.go (2)

24-24: LGTM!

The addition of the SnippetService field to the MakeWebConfigurationConfig function is well-documented and follows the existing pattern.


55-55: LGTM!

The modification of the MakeConfig function to use config.MakeValidatorConfig for the Authorization field is correct and follows the existing pattern.

cloud2cloud-gateway/test/test.go (1)

7-7: LGTM!

The usage of the slices package in the GetUniqueSubscriptionID function is correct and follows the existing pattern.

grpc-gateway/client/getResource_test.go (2)

11-11: Import statement approved.

The import statement for grpcgwTest is correctly added.


Line range hint 104-108: Test client instantiation approved.

The new test client is correctly instantiated using grpcgwTest.NewTestClient(t) and properly closed after use.

http-gateway/service/getHubConfiguration.go (1)

78-78: Addition of SnippetService field approved.

The new field SnippetService is correctly added to the UIConfiguration and assigned from the requestHandler.config.UI.WebConfiguration.SnippetService.

charts/plgd-hub/templates/http-gateway/_helpers.tpl (1)

86-98: Addition of snippetServiceApiDomain template definition approved.

The new template definition for snippetServiceApiDomain is correctly added and follows the existing structure of the file.

coap-gateway/test/test.go (1)

55-55: Verify the new assignment for Authority.

Ensure that config.MakeValidatorConfig() is the correct function to use for the Authority field and that it matches the expected configuration.

grpc-gateway/client/getDevice_test.go (1)

96-96: Verify the new test client instantiation.

Ensure that grpcgwTest.NewTestClient(t) correctly initializes the test client and integrates well with the existing test logic.

http-gateway/service/getDeviceResourceLinks_test.go (1)

103-104: Verify the new typeFilter logic.

Ensure that the new typeFilter logic using slices.Contains correctly filters the resource links and integrates well with the existing test logic.

http-gateway/service/getHubConfiguration_test.go (2)

33-33: Verify the new SnippetService field addition.

Ensure that the new SnippetService field is correctly added to the expected configuration and integrates well with the existing test logic.


89-89: Verify the new SnippetService field addition.

Ensure that the new SnippetService field is correctly added to the expected configuration and integrates well with the existing test logic.

grpc-gateway/client/updateResource_test.go (3)

11-11: Review the new test client instantiation.

The new test client instantiation method grpcgwTest.NewTestClient(t) is introduced. Ensure that this updated method is correctly used and integrates well with the existing tests.


98-98: Ensure proper cleanup of the test client.

The test client c is instantiated using grpcgwTest.NewTestClient(t). Ensure that the client is properly closed to avoid resource leaks.


135-135: Ensure proper cleanup of the test client.

The test client c is instantiated using grpcgwTest.NewTestClient(t). Ensure that the client is properly closed to avoid resource leaks.

.github/workflows/build-publish.yaml (1)

112-115: Review the new job for snippet-service.

The new job for snippet-service is added with the directory snippet-service, Dockerfile .tmp/docker/snippet-service/Dockerfile, and template file tools/docker/Dockerfile.in. Ensure that the configurations are correct and the job integrates well within the CI/CD pipeline.

grpc-gateway/client/deleteResource_test.go (3)

13-13: Review the new test client instantiation.

The new test client instantiation method grpcgwTest.NewTestClient(t) is introduced. Ensure that this updated method is correctly used and integrates well with the existing tests.


87-87: Ensure proper cleanup of the test client.

The test client c is instantiated using grpcgwTest.NewTestClient(t). Ensure that the client is properly closed to avoid resource leaks.


176-176: Ensure proper cleanup of the test client.

The test client c is instantiated using grpcgwTest.NewTestClient(t). Ensure that the client is properly closed to avoid resource leaks.

.github/workflows/test.yml (2)

87-90: Review the new logging configurations for snippet-service.

The new logging configurations for snippet-service are added. Ensure that the configurations are correct and integrate well within the CI/CD pipeline.


119-119: Review the new logging configurations for snippet-service.

The new logging configurations for snippet-service are added. Ensure that the configurations are correct and integrate well within the CI/CD pipeline.

cloud2cloud-gateway/service/retrieveDevice.go (1)

77-80: LGTM!

The update to use commands.DecodeContent enhances maintainability and consistency.

http-gateway/service/getResourcePendingCommands_test.go (3)

168-178: LGTM!

The addition of new test cases and helper functions improves test coverage and robustness.


191-201: LGTM!

The addition of new test cases and helper functions improves test coverage and robustness.


205-209: LGTM!

The addition of new test cases and helper functions improves test coverage and robustness.

http-gateway/uri/uri.go (1)

25-26: LGTM!

The additions of IncludeHiddenResourcesQueryKey and ForceQueryKey are consistent with existing constants.

http-gateway/service/config.go (1)

196-196: LGTM!

The addition of the SnippetService field to WebConfiguration is consistent with existing fields.

bundle/nginx/nginx.conf.template (1)

124-137: Ensure the REPLACE_HTTP_SNIPPET_SERVICE_PORT is properly set.

The new location block for snippet-service appears correct, but it is crucial to ensure that REPLACE_HTTP_SNIPPET_SERVICE_PORT is properly set during deployment to avoid runtime issues.

coap-gateway/service/resourceDirectory.go (1)

176-177: Verify the triggerDeviceSubscriber method implementation.

The addition of client.triggerDeviceSubscriber() seems to trigger pending commands for published resources. Ensure that this method is correctly implemented and does not introduce side effects.

grpc-gateway/pb/devices.proto (3)

70-71: Fields force and async added to UpdateResourceRequest.

The fields force and async have been added to UpdateResourceRequest. Ensure that these fields are properly handled in the service logic.


225-226: Fields force and async added to DeleteResourceRequest.

The fields force and async have been added to DeleteResourceRequest. Ensure that these fields are properly handled in the service logic.


237-238: Fields force and async added to CreateResourceRequest.

The fields force and async have been added to CreateResourceRequest. Ensure that these fields are properly handled in the service logic.

coap-gateway/service/clientObserveHandler.go (2)

9-9: Ensure compatibility with slices package.

The slices package has been imported. Ensure that the Go version and environment support this package.


122-122: Usage of slices.Contains in isDuplicateEvent method.

The slices.Contains method is used to check if the event's href is in the list of unpublished resources. This is a correct and efficient usage.

http-gateway/service/getDevicePendingCommands_test.go (3)

256-266: Ensure correct error assertion.

In the createFn function, the error assertion is correct. However, ensure that the errC variable is properly checked for context-specific error messages if needed.


279-289: Ensure correct error assertion.

In the updateFn function, the error assertion is correct. However, ensure that the errU variable is properly checked for context-specific error messages if needed.


293-297: Ensure correct error assertion.

In the deleteFn function, the error assertion is correct. However, ensure that the errD variable is properly checked for context-specific error messages if needed.

http-gateway/service/getPendingCommands_test.go (3)

303-313: Ensure correct error assertion.

In the createFn function, the error assertion is correct. However, ensure that the errC variable is properly checked for context-specific error messages if needed.


326-336: Ensure correct error assertion.

In the updateFn function, the error assertion is correct. However, ensure that the errU variable is properly checked for context-specific error messages if needed.


340-344: Ensure correct error assertion.

In the deleteFn function, the error assertion is correct. However, ensure that the errD variable is properly checked for context-specific error messages if needed.

coap-gateway/service/signIn.go (2)

7-7: Ensure the slices import is necessary.

The slices package is imported, but ensure that it is used appropriately in the code.


176-176: Ensure efficient usage of slices.Contains.

The slices.Contains function is used to check if the device ID is in the list of device IDs. Ensure that this function is used correctly and efficiently.

bundle/Dockerfile (3)

116-122: Ensure correct build steps for snippet-service.

The build steps for the snippet-service are added. Ensure that the build steps are correct and follow best practices.


188-189: Ensure correct steps for copying snippet-service binaries and configuration.

The steps for copying the snippet-service binaries and configuration are added. Ensure that the steps are correct and follow best practices.


244-245: Ensure correct environment variable definitions for snippet-service.

The environment variables for the snippet-service are added. Ensure that the environment variables are correctly defined and used.

grpc-gateway/client/deviceSubscriptions_test.go (4)

12-12: Import statement approved.

The import statement adds a new alias grpcgwTest for the grpc-gateway/test package, which is used to instantiate a new test client.


86-88: Test client instance usage approved.

The new test client instance is created and closed properly in TestObserveDeviceResourcesRetrieve.


181-183: Test client instance usage approved.

The new test client instance is created and closed properly in TestObserveDeviceResourcesUpdate.


310-312: Test client instance usage approved.

The new test client instance is created and closed properly in TestObserveDeviceResourcesCreateAndDelete.

grpc-gateway/client/deviceSubscriber.go (1)

269-275: New method TriggerGetPendingCommands approved.

The new method triggers a reconnect by sending to the reconnectChan channel, which is implemented correctly.

coap-gateway/service/observation/deviceObserver.go (2)

9-9: Usage of slices package approved.

The slices package is used to check if a slice contains a specific element, which is implemented correctly.


311-311: Method IsDiscoveryResourceObservable approved.

The method uses slices.Contains to check if the Interfaces slice contains observeInterface, which is implemented correctly.

Makefile (7)

34-35: New logging configurations for snippet-service approved.

The new logging configurations TEST_SNIPPET_SERVICE_LOG_LEVEL and TEST_SNIPPET_SERVICE_LOG_DUMP_BODY are added correctly.


47-47: Addition of snippet-service to SUBDIRS list approved.

The snippet-service is added to the SUBDIRS list correctly.


332-334: Modification of RUN-TESTS-IN-DIRECTORY macro approved.

The macro is modified to run tests with additional shell command, which is implemented correctly.


377-377: Modification of RUN-TESTS-UDP macro approved.

The macro is modified to include new logging configurations for snippet-service, which is implemented correctly.

Also applies to: 385-385


398-398: Modification of test target approved.

The test target is modified to include new logging configurations for snippet-service, which is implemented correctly.


419-419: Modification of test/mem target approved.

The test/mem target is modified to include new logging configurations for snippet-service, which is implemented correctly.


437-444: Modification of RUN-TESTS-IN-DIRECTORY macro approved.

The macro is modified to include new logging configurations for snippet-service, which is implemented correctly.

grpc-gateway/service/updateResource_test.go (1)

418-652: LGTM!

The new test method TestUpdateCreateOnNotExistingResource is well-structured and follows the pattern of other test methods in the file. It correctly handles the context and connection setup and teardown. The test cases cover various scenarios for updating and creating resources.

grpc-gateway/service/subscribeToEvents_test.go (1)

Line range hint 670-721:
LGTM!

The new test method TestRequestHandlerSubscribeForPendingCommands is well-structured and follows the pattern of other test methods in the file. It correctly handles the context and connection setup and teardown. The test cases cover various scenarios for subscribing to pending commands.

bundle/run.sh (5)

27-28: Ensure the new environment variables are used correctly.

The new environment variables SNIPPET_SERVICE_ADDRESS and SNIPPET_SERVICE_HTTP_ADDRESS are exported correctly. Verify their usage in the codebase to ensure they're being utilized as expected.

Verification successful

The new environment variables SNIPPET_SERVICE_ADDRESS and SNIPPET_SERVICE_HTTP_ADDRESS are used correctly in the codebase.

The variables are utilized appropriately within bundle/run.sh:

  • SNIPPET_SERVICE_ADDRESS is used for gRPC address configuration and connection checks.

  • SNIPPET_SERVICE_HTTP_ADDRESS is used for HTTP address configuration.

  • bundle/run.sh:

    • Line 27: export SNIPPET_SERVICE_ADDRESS="localhost:${SNIPPET_SERVICE_PORT}"
    • Line 28: export SNIPPET_SERVICE_HTTP_ADDRESS="localhost:${HTTP_SNIPPET_SERVICE_PORT}"
    • Usage in gRPC and HTTP address settings and connection checks.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `SNIPPET_SERVICE_ADDRESS` and `SNIPPET_SERVICE_HTTP_ADDRESS` in the codebase.

# Test: Search for the environment variables usage. Expect: Proper usage in the codebase.
rg --type sh $'SNIPPET_SERVICE_ADDRESS'
rg --type sh $'SNIPPET_SERVICE_HTTP_ADDRESS'

Length of output: 720


18-18: Ensure the new environment variable is used correctly.

The new environment variable CERTIFICATE_AUTHORITY_HTTP_ADDRESS is exported correctly. Verify its usage in the codebase to ensure it's being utilized as expected.

Verification successful

The new environment variable is used correctly.

The CERTIFICATE_AUTHORITY_HTTP_ADDRESS is correctly exported and utilized within the codebase, particularly in the certificate-authority/config.yaml file.

  • bundle/run.sh: Line 18 - Export statement.
  • charts/plgd-hub/templates/certificate-authority/config.yaml: Usage in configuration.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `CERTIFICATE_AUTHORITY_HTTP_ADDRESS` in the codebase.

# Test: Search for the environment variable usage. Expect: Proper usage in the codebase.
rg --type sh $'CERTIFICATE_AUTHORITY_HTTP_ADDRESS'

Length of output: 233


Script:

#!/bin/bash
# Description: Verify the usage of `.apis.http.address` in the codebase.

# Test: Search for the usage of `.apis.http.address`. Expect: Proper usage in the codebase.
rg --type sh $'.apis.http.address'

Length of output: 549


Script:

#!/bin/bash
# Description: Verify the usage of `.apis.http.address` in the codebase beyond assignments.

# Test: Search for the usage of `.apis.http.address` in the codebase. Expect: Proper usage in the codebase.
rg '.apis.http.address'

Length of output: 1268


1250-1293: Ensure the snippet-service configuration and startup commands are correct.

The configuration and startup commands for the snippet-service are consistent with other services. Verify that the configuration file is correctly generated and the service starts as expected.


1419-1425: Ensure the process check for snippet-service is correct.

The process check for snippet-service is consistent with other similar checks. Verify that the process ID is correctly monitored and the service status is logged as expected.


490-490: Ensure the sed command correctly replaces the placeholder.

The sed command to replace REPLACE_HTTP_SNIPPET_SERVICE_PORT is consistent with other similar commands. Verify that the placeholder is correctly replaced in the nginx configuration.

grpc-gateway/pb/README.md (1)

914-914: Add missing commas and fix double punctuation.

Add a comma before "and" to connect independent clauses and remove the double punctuation at the end of the sentence.

-  | resource_id_filter | [ResourceIdFilter](#grpcgateway-pb-ResourceIdFilter) | repeated | New resource ID filter. For HTTP requests, use it multiple times as a query parameter like &#34;resourceIdFilter={deviceID}{href}&#34;. |
+  | resource_id_filter | [ResourceIdFilter](#grpcgateway-pb-ResourceIdFilter) | repeated | New resource ID filter. For HTTP requests, use it multiple times as a query parameter like &#34;resourceIdFilter={deviceID}{href}.&#34; |
-  | include_hidden_resources | [bool](#bool) |  | Get all pending commands for all resources, even if the resource is not published. |
+  | include_hidden_resources | [bool](#bool) |  | Get all pending commands for all resources, even if the resource is not published. |

Likely invalid or redundant comment.

grpc-gateway/pb/doc.html (5)

844-857: New fields added to CreateResourceRequest.

The fields force and async enhance the functionality of the CreateResourceRequest. These additions look good.


968-981: New fields added to DeleteResourceRequest.

The fields force and async enhance the functionality of the DeleteResourceRequest. These additions look good.


1982-1995: New fields added to UpdateResourceRequest.

The fields force and async enhance the functionality of the UpdateResourceRequest. These additions look good.


2528-2533: New field added to GetPendingCommandsRequest.

The field include_hidden_resources enhances the functionality of the GetPendingCommandsRequest by allowing the retrieval of all pending commands for all resources, even if the resource is not published. This addition looks good.


2941-2946: New field added to UIConfiguration.

The field snippet_service enhances the UIConfiguration by providing the address to the snippet service HTTP API. This addition looks good.

bundle/Dockerfile Show resolved Hide resolved
grpc-gateway/pb/README.md Show resolved Hide resolved
grpc-gateway/pb/README.md Show resolved Hide resolved
grpc-gateway/pb/README.md Show resolved Hide resolved
grpc-gateway/pb/README.md Show resolved Hide resolved
grpc-gateway/pb/README.md Show resolved Hide resolved
@Danielius1922
Copy link
Member Author

@coderabbitai write summary for the PR, focus on the new snippet-service, you can ignore the rest

Copy link

coderabbitai bot commented Jul 5, 2024

@Danielius1922 Here's a summary of the PR focusing on the new snippet-service:


Summary of Changes for snippet-service

  1. CI/CD Pipeline:

    • Updated .github/workflows/build-publish.yaml to include a new job for building and publishing the snippet-service.
  2. Makefile:

    • Added snippet-service to the SUBDIRS list.
    • Modified the RUN-TESTS-IN-DIRECTORY command to support new logging configurations for testing.
  3. Configuration Files:

    • .vscode/settings.json: Added settings for TEST_SNIPPET_SERVICE_LOG_LEVEL and TEST_SNIPPET_SERVICE_LOG_DUMP_BODY.
    • bundle/Dockerfile: Introduced new environment variables and build steps for snippet-service.
    • bundle/nginx/nginx.conf.template: Added a location block for /snippet-service with proxy settings.
    • bundle/run.sh: Included exports for SNIPPET_SERVICE_ADDRESS and related environment variables, along with logic to wait for the service to start.
  4. Kubernetes Templates:

    • charts/plgd-hub/templates/http-gateway/_helpers.tpl: Added configurations for snippet-service.
    • charts/plgd-hub/templates/snippet-service/_helpers.tpl: Introduced templates to manage snippet-service configurations, including service names, domains, and certificates.
  5. Go Files:

    • Refactored various Go files to improve code maintainability and functionality, including adding new methods and updating import paths.

Actions performed

Comments resolved.

@Danielius1922
Copy link
Member Author

@coderabbitai thanks for the summary, now write a description focusing on the snippet-service, that can be used as a commit message

Copy link

coderabbitai bot commented Jul 5, 2024

Tip

For best results, initiate chat on the files or code changes.

@Danielius1922 Here's a description focusing on the snippet-service that can be used as a commit message:


Commit Message

Extend plgd/snippet-service

  • CI/CD Pipeline:

    • Added a new job in .github/workflows/build-publish.yaml for building and publishing the snippet-service.
  • Makefile:

    • Included snippet-service in the SUBDIRS list.
    • Updated the RUN-TESTS-IN-DIRECTORY command to support new logging configurations for testing.
  • Configuration Files:

    • Added settings for TEST_SNIPPET_SERVICE_LOG_LEVEL and TEST_SNIPPET_SERVICE_LOG_DUMP_BODY in .vscode/settings.json.
    • Introduced new environment variables and build steps for snippet-service in bundle/Dockerfile.
    • Added a location block for /snippet-service with proxy settings in bundle/nginx/nginx.conf.template.
    • Included exports for SNIPPET_SERVICE_ADDRESS and related environment variables in bundle/run.sh.
  • Kubernetes Templates:

    • Added configurations for snippet-service in charts/plgd-hub/templates/http-gateway/_helpers.tpl.
    • Introduced templates to manage snippet-service configurations in charts/plgd-hub/templates/snippet-service/_helpers.tpl.
  • Go Files:

    • Refactored various Go files to improve code maintainability and functionality, including adding new methods and updating import paths.

Feel free to adjust the message as needed.

@Danielius1922 Danielius1922 force-pushed the adam/feature/snapshot-service branch from d8a58ff to 0dfa3f3 Compare July 8, 2024 06:55
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: 12

Outside diff range and nitpick comments (1)
snippet-service/service/http/getAppliedConfigurations_test.go (1)

23-179: Use table-driven tests for better readability.

The function uses a table-driven test approach which is good. Ensure that the test cases are clear and maintainable. Consider adding comments to explain each test case scenario.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 37b395c and 0dfa3f3.

Files ignored due to path filters (2)
  • charts/plgd-hub/values.yaml is excluded by !**/*.yaml
  • snippet-service/config.yaml is excluded by !**/*.yaml
Files selected for processing (7)
  • snippet-service/service/grpc/server.go (1 hunks)
  • snippet-service/service/http/deleteAppliedConfigurations_test.go (1 hunks)
  • snippet-service/service/http/getAppliedConfigurations_test.go (1 hunks)
  • snippet-service/service/service.go (1 hunks)
  • snippet-service/service/service_test.go (1 hunks)
  • snippet-service/store/condition.go (1 hunks)
  • snippet-service/store/configuration.go (1 hunks)
Additional comments not posted (30)
snippet-service/store/configuration.go (11)

9-16: LGTM!

The function correctly validates and normalizes the configuration object.


18-23: LGTM!

The ConfigurationVersion type is well-defined.


25-35: LGTM!

The Copy method correctly creates a deep copy of a ConfigurationVersion object.


37-44: LGTM!

The function correctly maps fields from pb.Configuration to ConfigurationVersion.


46-51: LGTM!

The Configuration type is well-defined.


53-61: LGTM!

The method correctly initializes the first Configuration object.


63-75: LGTM!

The method correctly retrieves and maps the latest pb.Configuration object.


77-91: LGTM!

The method correctly iterates over all versions and invokes the callback.


93-107: LGTM!

The method correctly creates a deep copy of a Configuration object.


109-109: LGTM!

The type alias is correctly defined.


111-116: LGTM!

The function correctly validates the InvokeConfigurationRequest object.

snippet-service/store/condition.go (10)

11-18: LGTM!

The function correctly validates and normalizes the condition object.


20-30: LGTM!

The ConditionVersion type is well-defined.


32-44: LGTM!

The Copy method correctly creates a deep copy of a ConditionVersion object.


46-58: LGTM!

The function correctly maps fields from pb.Condition to ConditionVersion.


60-66: LGTM!

The Condition type is well-defined.


68-77: LGTM!

The method correctly initializes the first Condition object.


79-97: LGTM!

The method correctly retrieves and maps the latest pb.Condition object.


99-119: LGTM!

The method correctly iterates over all versions and invokes the callback.


121-135: LGTM!

The method correctly creates a deep copy of a Condition object.


138-144: LGTM!

The function correctly validates and normalizes the conditions query.

snippet-service/service/http/deleteAppliedConfigurations_test.go (1)

27-152: LGTM!

The test comprehensively covers various scenarios for the DeleteAppliedConfigurations endpoint.

snippet-service/service/service.go (5)

35-44: LGTM!

The function correctly creates a store based on the provided configuration.


46-64: LGTM!

The function correctly creates a new HTTP service.


66-77: LGTM!

The function correctly creates a new gRPC service.


79-150: LGTM!

The function correctly initializes and sets up the entire snippet service.


152-154: LGTM!

The function correctly returns the store associated with the service.

snippet-service/service/grpc/server.go (1)

49-54: LGTM!

The method correctly maps store errors to gRPC error codes.

snippet-service/service/service_test.go (2)

41-173: Ensure comprehensive test coverage.

The function uses table-driven tests to cover different configurations. Ensure that the test cases cover edge cases and invalid configurations.


200-496: Ensure comprehensive test coverage.

The function covers various scenarios for creating, updating, and deleting configurations and conditions. Ensure that the tests cover edge cases and invalid configurations.

Comment on lines +147 to +149
_ = resp.Body.Close()
}()
require.Equal(t, tt.wantHTTPCode, resp.StatusCode)
Copy link

Choose a reason for hiding this comment

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

Ensure proper error handling and logging.

Add logging for errors to help with debugging in case of test failures.

-  require.NoError(t, err)
+  if err != nil {
+    t.Errorf("failed to unmarshal response: %v", err)
+  }

Committable suggestion was skipped due to low confidence.

Comment on lines +161 to +175
func (s *SnippetServiceServer) DeleteConfigurations(ctx context.Context, req *pb.DeleteConfigurationsRequest) (*pb.DeleteConfigurationsResponse, error) {
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotDeleteConfigurations(err)))
}
req.IdFilter = append(req.GetIdFilter(), req.ConvertHTTPIDFilter()...)

err = s.store.DeleteConfigurations(ctx, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotDeleteConfigurations(err)))
}
return &pb.DeleteConfigurationsResponse{
Success: true,
}, nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for request filters.

Ensure that the request filters are properly validated to avoid invalid data.

+  if err := validateDeleteConfigurationsRequest(req); err != nil {
+    return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
+  }

Committable suggestion was skipped due to low confidence.

Comment on lines +38 to +47
func (s *SnippetServiceServer) checkOwner(ctx context.Context, owner string) (string, error) {
ownerFromToken, err := pkgGrpc.OwnerFromTokenMD(ctx, s.ownerClaim)
if err != nil {
return "", err
}
if owner != "" && ownerFromToken != owner {
return "", errors.New("owner mismatch")
}
return ownerFromToken, nil
}
Copy link

Choose a reason for hiding this comment

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

Improve error messages for better clarity.

Ensure that error messages are clear and informative to help with debugging.

-  return "", errors.New("owner mismatch")
+  return "", fmt.Errorf("owner mismatch: expected %v, got %v", owner, ownerFromToken)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) checkOwner(ctx context.Context, owner string) (string, error) {
ownerFromToken, err := pkgGrpc.OwnerFromTokenMD(ctx, s.ownerClaim)
if err != nil {
return "", err
}
if owner != "" && ownerFromToken != owner {
return "", errors.New("owner mismatch")
}
return ownerFromToken, nil
}
func (s *SnippetServiceServer) checkOwner(ctx context.Context, owner string) (string, error) {
ownerFromToken, err := pkgGrpc.OwnerFromTokenMD(ctx, s.ownerClaim)
if err != nil {
return "", err
}
if owner != "" && ownerFromToken != owner {
return "", fmt.Errorf("owner mismatch: expected %v, got %v", owner, ownerFromToken)
}
return ownerFromToken, nil
}

Comment on lines +78 to +92
func (s *SnippetServiceServer) UpdateConfiguration(ctx context.Context, conf *pb.Configuration) (*pb.Configuration, error) {
owner, err := s.checkOwner(ctx, conf.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotUpdateConfiguration(err)))
}

conf.Owner = owner
// increment version automatically by mongo
conf.Version = 0
c, err := s.store.UpdateConfiguration(ctx, conf)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotUpdateConfiguration(err)))
}
return c, nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for configuration.

Ensure that the configuration is properly validated before updating to avoid invalid data.

+  if err := validateConfiguration(conf); err != nil {
+    return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid configuration: %v", err))
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) UpdateConfiguration(ctx context.Context, conf *pb.Configuration) (*pb.Configuration, error) {
owner, err := s.checkOwner(ctx, conf.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotUpdateConfiguration(err)))
}
conf.Owner = owner
// increment version automatically by mongo
conf.Version = 0
c, err := s.store.UpdateConfiguration(ctx, conf)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotUpdateConfiguration(err)))
}
return c, nil
}
func (s *SnippetServiceServer) UpdateConfiguration(ctx context.Context, conf *pb.Configuration) (*pb.Configuration, error) {
owner, err := s.checkOwner(ctx, conf.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotUpdateConfiguration(err)))
}
+ if err := validateConfiguration(conf); err != nil {
+ return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid configuration: %v", err))
+ }
conf.Owner = owner
// increment version automatically by mongo
conf.Version = 0
c, err := s.store.UpdateConfiguration(ctx, conf)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotUpdateConfiguration(err)))
}
return c, nil
}

Comment on lines +204 to +216
func (s *SnippetServiceServer) CreateCondition(ctx context.Context, condition *pb.Condition) (*pb.Condition, error) {
owner, err := s.checkOwner(ctx, condition.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotCreateCondition(err)))
}

condition.Owner = owner
c, err := s.store.CreateCondition(ctx, condition)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotCreateCondition(err)))
}
return c, nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for condition.

Ensure that the condition is properly validated before creation to avoid invalid data.

+  if err := validateCondition(condition); err != nil {
+    return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid condition: %v", err))
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) CreateCondition(ctx context.Context, condition *pb.Condition) (*pb.Condition, error) {
owner, err := s.checkOwner(ctx, condition.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotCreateCondition(err)))
}
condition.Owner = owner
c, err := s.store.CreateCondition(ctx, condition)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotCreateCondition(err)))
}
return c, nil
}
func (s *SnippetServiceServer) CreateCondition(ctx context.Context, condition *pb.Condition) (*pb.Condition, error) {
owner, err := s.checkOwner(ctx, condition.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotCreateCondition(err)))
}
+ if err := validateCondition(condition); err != nil {
+ return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid condition: %v", err))
+ }
condition.Owner = owner
c, err := s.store.CreateCondition(ctx, condition)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotCreateCondition(err)))
}
return c, nil
}

Comment on lines +337 to +349
func (s *SnippetServiceServer) DeleteAppliedConfigurations(ctx context.Context, req *pb.DeleteAppliedConfigurationsRequest) (*pb.DeleteAppliedConfigurationsResponse, error) {
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotDeleteAppliedConfigurations(err)))
}
err = s.store.DeleteAppliedConfigurations(ctx, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotDeleteAppliedConfigurations(err)))
}
return &pb.DeleteAppliedConfigurationsResponse{
Success: true,
}, nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for request filters.

Ensure that the request filters are properly validated to avoid invalid data.

+  if err := validateDeleteAppliedConfigurationsRequest(req); err != nil {
+    return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) DeleteAppliedConfigurations(ctx context.Context, req *pb.DeleteAppliedConfigurationsRequest) (*pb.DeleteAppliedConfigurationsResponse, error) {
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotDeleteAppliedConfigurations(err)))
}
err = s.store.DeleteAppliedConfigurations(ctx, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotDeleteAppliedConfigurations(err)))
}
return &pb.DeleteAppliedConfigurationsResponse{
Success: true,
}, nil
}
func (s *SnippetServiceServer) DeleteAppliedConfigurations(ctx context.Context, req *pb.DeleteAppliedConfigurationsRequest) (*pb.DeleteAppliedConfigurationsResponse, error) {
if err := validateDeleteAppliedConfigurationsRequest(req); err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
}
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotDeleteAppliedConfigurations(err)))
}
err = s.store.DeleteAppliedConfigurations(ctx, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotDeleteAppliedConfigurations(err)))
}
return &pb.DeleteAppliedConfigurationsResponse{
Success: true,
}, nil
}

Comment on lines +137 to +155
func (s *SnippetServiceServer) GetConfigurations(req *pb.GetConfigurationsRequest, srv pb.SnippetService_GetConfigurationsServer) error {
owner, err := s.checkOwner(srv.Context(), "")
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotGetConfigurations(err)))
}
req.IdFilter = append(req.GetIdFilter(), req.ConvertHTTPIDFilter()...)
if len(req.GetIdFilter()) == 0 {
// get all latest conditions by default
req.IdFilter = getAllLatest()
}

err = s.store.GetConfigurations(srv.Context(), owner, req, func(c *store.Configuration) error {
return sendConfiguration(srv, c)
})
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotGetConfigurations(err)))
}
return nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for request filters.

Ensure that the request filters are properly validated to avoid invalid data.

+  if err := validateGetConfigurationsRequest(req); err != nil {
+    return s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) GetConfigurations(req *pb.GetConfigurationsRequest, srv pb.SnippetService_GetConfigurationsServer) error {
owner, err := s.checkOwner(srv.Context(), "")
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotGetConfigurations(err)))
}
req.IdFilter = append(req.GetIdFilter(), req.ConvertHTTPIDFilter()...)
if len(req.GetIdFilter()) == 0 {
// get all latest conditions by default
req.IdFilter = getAllLatest()
}
err = s.store.GetConfigurations(srv.Context(), owner, req, func(c *store.Configuration) error {
return sendConfiguration(srv, c)
})
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotGetConfigurations(err)))
}
return nil
}
func (s *SnippetServiceServer) GetConfigurations(req *pb.GetConfigurationsRequest, srv pb.SnippetService_GetConfigurationsServer) error {
if err := validateGetConfigurationsRequest(req); err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
}
owner, err := s.checkOwner(srv.Context(), "")
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotGetConfigurations(err)))
}
req.IdFilter = append(req.GetIdFilter(), req.ConvertHTTPIDFilter()...)
if len(req.GetIdFilter()) == 0 {
// get all latest conditions by default
req.IdFilter = getAllLatest()
}
err = s.store.GetConfigurations(srv.Context(), owner, req, func(c *store.Configuration) error {
return sendConfiguration(srv, c)
})
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotGetConfigurations(err)))
}
return nil
}

Comment on lines +222 to +236
func (s *SnippetServiceServer) UpdateCondition(ctx context.Context, condition *pb.Condition) (*pb.Condition, error) {
owner, err := s.checkOwner(ctx, condition.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotUpdateCondition(err)))
}

condition.Owner = owner
// increment version automatically by mongo
condition.Version = 0
c, err := s.store.UpdateCondition(ctx, condition)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotUpdateCondition(err)))
}
return c, nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for condition.

Ensure that the condition is properly validated before updating to avoid invalid data.

+  if err := validateCondition(condition); err != nil {
+    return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid condition: %v", err))
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) UpdateCondition(ctx context.Context, condition *pb.Condition) (*pb.Condition, error) {
owner, err := s.checkOwner(ctx, condition.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotUpdateCondition(err)))
}
condition.Owner = owner
// increment version automatically by mongo
condition.Version = 0
c, err := s.store.UpdateCondition(ctx, condition)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotUpdateCondition(err)))
}
return c, nil
}
func (s *SnippetServiceServer) UpdateCondition(ctx context.Context, condition *pb.Condition) (*pb.Condition, error) {
owner, err := s.checkOwner(ctx, condition.GetOwner())
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotUpdateCondition(err)))
}
+ if err := validateCondition(condition); err != nil {
+ return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid condition: %v", err))
+ }
condition.Owner = owner
// increment version automatically by mongo
condition.Version = 0
c, err := s.store.UpdateCondition(ctx, condition)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(getGRPCErrorCode(err), "%v", errCannotUpdateCondition(err)))
}
return c, nil
}

Comment on lines +271 to +289
func (s *SnippetServiceServer) GetConditions(req *pb.GetConditionsRequest, srv pb.SnippetService_GetConditionsServer) error {
owner, err := s.checkOwner(srv.Context(), "")
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotGetConditions(err)))
}
req.IdFilter = append(req.GetIdFilter(), req.ConvertHTTPIDFilter()...)
if len(req.GetIdFilter()) == 0 && len(req.GetConfigurationIdFilter()) == 0 {
// get all latest conditions by default
req.IdFilter = getAllLatest()
}

err = s.store.GetConditions(srv.Context(), owner, req, func(c *store.Condition) error {
return sendCondition(srv, c)
})
if err != nil {
return s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotGetConditions(err)))
}
return nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for request filters.

Ensure that the request filters are properly validated to avoid invalid data.

+  if err := validateGetConditionsRequest(req); err != nil {
+    return s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
+  }

Committable suggestion was skipped due to low confidence.

Comment on lines +181 to +198
func (s *SnippetServiceServer) InvokeConfiguration(ctx context.Context, req *pb.InvokeConfigurationRequest) (*pb.InvokeConfigurationResponse, error) {
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotInvokeConfiguration(err)))
}
token, errT := pkgGrpc.TokenFromMD(ctx)
// we must have token for communication by raClient
if errT != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotInvokeConfiguration(errT)))
}
appliedConf, err := s.resourceUpdater.InvokeConfiguration(ctx, token, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotInvokeConfiguration(err)))
}
return &pb.InvokeConfigurationResponse{
AppliedConfigurationId: appliedConf.GetId(),
}, nil
}
Copy link

Choose a reason for hiding this comment

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

Add validation for request.

Ensure that the request is properly validated to avoid invalid data.

+  if err := validateInvokeConfigurationRequest(req); err != nil {
+    return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *SnippetServiceServer) InvokeConfiguration(ctx context.Context, req *pb.InvokeConfigurationRequest) (*pb.InvokeConfigurationResponse, error) {
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotInvokeConfiguration(err)))
}
token, errT := pkgGrpc.TokenFromMD(ctx)
// we must have token for communication by raClient
if errT != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotInvokeConfiguration(errT)))
}
appliedConf, err := s.resourceUpdater.InvokeConfiguration(ctx, token, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotInvokeConfiguration(err)))
}
return &pb.InvokeConfigurationResponse{
AppliedConfigurationId: appliedConf.GetId(),
}, nil
}
func (s *SnippetServiceServer) InvokeConfiguration(ctx context.Context, req *pb.InvokeConfigurationRequest) (*pb.InvokeConfigurationResponse, error) {
owner, err := s.checkOwner(ctx, "")
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.PermissionDenied, "%v", errCannotInvokeConfiguration(err)))
}
+ if err := validateInvokeConfigurationRequest(req); err != nil {
+ return nil, s.logger.LogAndReturnError(status.Errorf(codes.InvalidArgument, "invalid request: %v", err))
+ }
token, errT := pkgGrpc.TokenFromMD(ctx)
// we must have token for communication by raClient
if errT != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotInvokeConfiguration(errT)))
}
appliedConf, err := s.resourceUpdater.InvokeConfiguration(ctx, token, owner, req)
if err != nil {
return nil, s.logger.LogAndReturnError(status.Errorf(codes.Internal, "%v", errCannotInvokeConfiguration(err)))
}
return &pb.InvokeConfigurationResponse{
AppliedConfigurationId: appliedConf.GetId(),
}, nil
}

Copy link

sonarcloud bot commented Jul 8, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

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.

None yet

2 participants