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: Validate Interval and IntervalAction before loading from config #3646

Merged
merged 2 commits into from
Aug 3, 2021
Merged

feat: Validate Interval and IntervalAction before loading from config #3646

merged 2 commits into from
Aug 3, 2021

Conversation

weichou1229
Copy link
Member

Close: #3642

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/master/.github/Contributing.md.

What is the current behavior?

Issue Number: #3642

What is the new behavior?

Interval and IntervalAction should be created as a DTO, and call validate() to ensure the data is valid.

Does this PR introduce a breaking change?

  • Yes
  • No

New Imports

  • Yes
  • No

Specific Instructions

Are there any specific instructions or things that should be known prior to reviewing?

Other information

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2021

Codecov Report

Merging #3646 (3d5ecab) into main (ced8146) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3646   +/-   ##
=======================================
  Coverage   47.29%   47.29%           
=======================================
  Files         112      112           
  Lines        9174     9174           
=======================================
  Hits         4339     4339           
  Misses       4462     4462           
  Partials      373      373           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ced8146...3d5ecab. Read the comment docs.

Name: configuration.Intervals[i].Name,
Start: configuration.Intervals[i].Start,
End: configuration.Intervals[i].End,
Interval: configuration.Intervals[i].Interval,
}
validateErr := common.Validate(dto)
if validateErr != nil {
return errors.NewCommonEdgeXWrapper(validateErr)
Copy link
Member

Choose a reason for hiding this comment

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

wrap the error with the proper error message:
validate pre-defined Interval %s from configuration failed , dto.Name

Copy link
Member Author

Choose a reason for hiding this comment

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

Modified.

_, err := dbClient.IntervalActionByName(action.Name)
validateErr := common.Validate(dto)
if validateErr != nil {
return errors.NewCommonEdgeXWrapper(validateErr)
Copy link
Member

Choose a reason for hiding this comment

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

wrap the error with the proper error message:
validate pre-defined IntervalAction %s from configuration failed , dto.Name

Copy link
Member Author

Choose a reason for hiding this comment

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

Modified.

Interval and IntervalAction should be created as a DTO, and call validate() to ensure the data is valid.

Close: #3642
Signed-off-by: weichou <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 3, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@weichou1229 weichou1229 requested a review from cloudxxx8 August 3, 2021 11:06
Copy link
Member

@cloudxxx8 cloudxxx8 left a comment

Choose a reason for hiding this comment

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

LGTM

@cloudxxx8 cloudxxx8 merged commit c934d26 into edgexfoundry:main Aug 3, 2021
@weichou1229 weichou1229 deleted the issue-3642 branch August 3, 2021 14:22
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.

The interval and interval action loaded from configuration should be validated
3 participants