-
Notifications
You must be signed in to change notification settings - Fork 182
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
Allow user Regex and Allow Group prefixes #29
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ package internal | |
|
||
import ( | ||
"context" | ||
"strings" | ||
"io/ioutil" | ||
"regexp" | ||
|
||
"github.com/awslabs/ssosync/internal/aws" | ||
"github.com/awslabs/ssosync/internal/config" | ||
|
@@ -100,6 +102,11 @@ func (s *syncGSuite) SyncUsers() error { | |
continue | ||
} | ||
|
||
if !s.allowPattern(u.PrimaryEmail) { | ||
log.Debug("Filtered out a user") | ||
continue | ||
} | ||
|
||
ll := log.WithFields(log.Fields{ | ||
"email": u.PrimaryEmail, | ||
}) | ||
|
@@ -156,6 +163,10 @@ func (s *syncGSuite) SyncGroups() error { | |
continue | ||
} | ||
|
||
if ! s.allowGroup(g.Email) { | ||
continue | ||
} | ||
|
||
log := log.WithFields(log.Fields{ | ||
"group": g.Email, | ||
}) | ||
|
@@ -296,3 +307,34 @@ func (s *syncGSuite) ignoreGroup(name string) bool { | |
|
||
return false | ||
} | ||
|
||
func (s *syncGSuite) allowGroup(name string) bool { | ||
if len(s.cfg.AllowGroups) == 0 { | ||
return true | ||
} | ||
|
||
for _, g := range s.cfg.AllowGroups { | ||
if strings.HasPrefix(name, g) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (s *syncGSuite) allowPattern(name string) bool { | ||
if len(s.cfg.AllowGroups) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be testing the length of |
||
return true | ||
} | ||
for _, p := range s.cfg.AllowPattern { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit Everywhere else you've inserted a blank line before the |
||
if p == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would accepting a pattern of |
||
return true | ||
} | ||
|
||
re := regexp.MustCompile(p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to be a performance problem with lots of patterns compiled and applied at each user? Should we really be preprocessing the patterns once to compile them (newish to go) |
||
if re.FindStringIndex(name) != nil { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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.
nit This one place you've got a blank
after the bang
!
... maybe delete that?