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

feat: REST API to update entity twin data #3425

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

Conversation

albinsuresh
Copy link
Contributor

@albinsuresh albinsuresh commented Feb 26, 2025

Proposed changes

REST API to update entity twin data

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@albinsuresh albinsuresh marked this pull request as draft February 26, 2025 15:38
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...s/core/tedge_agent/src/http_server/entity_store.rs 92.02% 1 Missing and 10 partials ⚠️
...ates/core/tedge_agent/src/entity_manager/server.rs 89.28% 2 Missing and 1 partial ⚠️
...rates/core/tedge_agent/src/entity_manager/tests.rs 92.30% 2 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

Copy link
Contributor

github-actions bot commented Feb 26, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
583 0 3 583 100 1h40m32.786878999s

Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

  • It would be good to implement tedge http patch along this PR.
  • I was expecting the updated twin data to be published over the twin topics.

Comment on lines 70 to 71
#[error("Fragment keys starting with '@' are not allowed as twin data")]
pub struct InvalidTwinData;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to tell which key has been rejected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved by 6e7c4c6

Comment on lines 448 to 476
Update existing fragment: `name`, add new fragment: `hardware` and remove existing fragment: `maintenanceMode` with a `null` value:

```json
{
"name": "Child 01",
"new-fragment": {
"new-key": "new-value"
},
"extra-fragment": null
}
```

**Example**

```shell
curl http://localhost:8000/tedge/entity-store/v1/entities/device/child01 \
-X PATCH \
-H "Content-Type: application/json" \
-d '{
"type": "Raspberry Pi 4",
"hardware": {
"serialNo": "98761234"
},
"maintenanceMode": null
}'
```
Copy link
Contributor

Choose a reason for hiding this comment

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

The example doesn't match the text.

Suggested change
Update existing fragment: `name`, add new fragment: `hardware` and remove existing fragment: `maintenanceMode` with a `null` value:
```json
{
"name": "Child 01",
"new-fragment": {
"new-key": "new-value"
},
"extra-fragment": null
}
```
**Example**
```shell
curl http://localhost:8000/tedge/entity-store/v1/entities/device/child01 \
-X PATCH \
-H "Content-Type: application/json" \
-d '{
"type": "Raspberry Pi 4",
"hardware": {
"serialNo": "98761234"
},
"maintenanceMode": null
}'
```
Update existing fragment: `name`, add new fragment: `hardware` and remove existing fragment: `maintenanceMode` with a `null` value:
```shell
curl http://localhost:8000/tedge/entity-store/v1/entities/device/child01 \
-X PATCH \
-H "Content-Type: application/json" \
-d '{
"name": "Child 01",
"hardware": {
"serialNo": "98761234"
},
"maintenanceMode": null
}'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved by 6e7c4c6

@didier-wenzek
Copy link
Contributor

  • It would be good to implement tedge http patch along this PR.

I pushed a commit for that: 4e3e940

@albinsuresh
Copy link
Contributor Author

I was expecting the updated twin data to be published over the twin topics.

Resolved by 6e7c4c6

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.

2 participants