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

Allow --gh-team-allowlist to work with team names and slugs #2717

Closed
1 task done
nitrocode opened this issue Nov 25, 2022 · 0 comments · Fixed by #2719
Closed
1 task done

Allow --gh-team-allowlist to work with team names and slugs #2717

nitrocode opened this issue Nov 25, 2022 · 0 comments · Fixed by #2719
Labels
feature New functionality/enhancement

Comments

@nitrocode
Copy link
Member

nitrocode commented Nov 25, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Describe the user story

The gh team allowlist seems like it should work for slugs but it only works with names.

Related doc PRs

Possibly related discussion #2716

Describe the solution you'd like

Allow both slug or name.

The Node exposes Name but also exposes Slug and we only append the Name.

func (g *GithubClient) GetTeamNamesForUser(repo models.Repo, user models.User) ([]string, error) {

var q struct {
Organization struct {
Teams struct {
Edges []struct {
Node struct {
Name string
}

for _, edge := range q.Organization.Teams.Edges {
teamNames = append(teamNames, edge.Node.Name)
}

This function is called here

teams, err := c.VCSClient.GetTeamNamesForUser(repo, user)
if err != nil {
return false, err
}
ok := c.TeamAllowlistChecker.IsCommandAllowedForAnyTeam(teams, cmd.Name.String())

func (checker *TeamAllowlistChecker) IsCommandAllowedForTeam(team string, command string) bool {
for _, rule := range checker.rules {
for key, value := range rule {
if (key == wildcard || strings.EqualFold(key, team)) && (value == wildcard || strings.EqualFold(value, command)) {
return true
}
}
}
return false
}
// IsCommandAllowedForAnyTeam returns true if any of the teams is allowed to execute the command
// and false otherwise.
func (checker *TeamAllowlistChecker) IsCommandAllowedForAnyTeam(teams []string, command string) bool {
if len(teams) == 0 {
for _, rule := range checker.rules {
for key, value := range rule {
if (key == wildcard) && (value == wildcard || strings.EqualFold(value, command)) {
return true
}
}
}
} else {
for _, t := range teams {
if checker.IsCommandAllowedForTeam(t, command) {
return true
}
}
}
return false

Describe the drawbacks of your solution

Additional logic to check for both

Describe alternatives you've considered

None

@nitrocode nitrocode added the feature New functionality/enhancement label Nov 25, 2022
@nitrocode nitrocode changed the title Allow --gh-team-allowlist to work with team names and slugs Allow --gh-team-allowlist to work with team names and slugs Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant