-
Notifications
You must be signed in to change notification settings - Fork 484
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
fix: added consul policy list check #4164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should refactor to remove the find by name logic if already found
case http.StatusOK: | ||
for _, policy := range policyList { | ||
if policyName == policy.Name { | ||
isExistingPolicy = true | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we already found policy here, we can just return policy? why we need to find policy by name again below? (IMO, kind of redundant logic below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not. The list API only returns the names of the policies. Still need another call to actually get the policy (i.e. it is just chaining off to the original code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is not true: see this: https://www.consul.io/api-docs/acl/policies#list-policies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jim-wang-intel I understand, I think, what you were saying. We only really need the name and the ID, not the text of the policy. I think I like the solution as presented because it addresses the bug as stated (error in consul log due to get of non-existent policy.) Since this is bootstrapping logic, it is not performance critical that we get the answer we need in one or two REST API calls. I think we should implement the simplest and most readable fix. We can refactor later if we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it sounds ok
247dd7a
to
4167d64
Compare
Added a check in getPolicyByName to see whether the policy exists in the policy list before attempting to get the policy. This prevents erroneous or unclear logging. closes: edgexfoundry#4108 Signed-off-by: Rico Chavez-Lopez <[email protected]>
4167d64
to
aa55db8
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Added a check in getPolicyByName to see whether the policy exists in the policy list before attempting to get the policy. This prevents erroneous or unclear logging.
closes: #4108
Signed-off-by: Rico Chavez-Lopez [email protected]
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/main/.github/Contributing.md
PR Checklist
Please check if your PR fulfills the following requirements:
BREAKING CHANGE:
describing the break)Testing Instructions