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

Support regex expression for node_labels #2206

Closed
wants to merge 8 commits into from
Closed

Support regex expression for node_labels #2206

wants to merge 8 commits into from

Conversation

ken5scal
Copy link

@ken5scal ken5scal commented Sep 6, 2018

@gravitational-jenkins
Copy link

Can one of the admins verify this patch?

@ken5scal
Copy link
Author

Anyone?

@klizhentas
Copy link
Contributor

Thanks for your PR and your patience! We are going to review and address it after 3.0 release.

}

// matchLabels, labelsMessage := MatchLabels(role.GetNodeLabels(Deny), s.GetAllLabels())
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete commented out code.

if !utils.SliceContainsStr(selectorValues, Wildcard) {
result, err := utils.SliceContainsRegexStr(targetVal, selectorValues)
if err != nil {
return false, "", trace.BadParameter(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

return false, "", trace.Wrap(err)

matchLabels, labelsMessage := MatchLabels(role.GetNodeLabels(Deny), s.GetAllLabels())
matchLabels, labelsMessage, err := MatchLabels(role.GetNodeLabels(Deny), s.GetAllLabels())
if err != nil {
return trace.CompareFailed(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is trace.CompareFailed checked anywhere? If not, I would just trace.Wrap(err) here as well.

matchLabels, labelsMessage := MatchLabels(role.GetNodeLabels(Allow), s.GetAllLabels())
matchLabels, labelsMessage, err := MatchLabels(role.GetNodeLabels(Allow), s.GetAllLabels())
if err != nil {
return trace.CompareFailed(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is trace.CompareFailed checked anywhere? If not, I would just trace.Wrap(err) here as well.

@@ -46,5 +46,26 @@ func ReplaceRegexp(expression string, replaceWith string, input string) (string,
return expr.ReplaceAllString(input, replaceWith), nil
}

func SliceContainsRegexStr(input string, expressions []string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing comment explaining what the function does.

if err != nil {
return false, trace.BadParameter(err.Error())
}
if expr.MatchString(input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment that because the expression is always surrounded by ^ and $ this is an exact match for either a a plain string (for example ^hello$) or for a regexp (for example ^hel*o$).

@ken5scal
Copy link
Author

ken5scal commented Oct 9, 2018

@russjones thanks for your comments let me update it.

@klizhentas
Copy link
Contributor

@ken5scal no need to update - we already applied updates to your commit in #2262

@russjones
Copy link
Contributor

@ken5scal We merged your work in #2262. Thank you for contributing!

@klizhentas
Copy link
Contributor

note that we have preserved your original commit for history as well :)

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.

4 participants