Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue #1184 - Github connector now returns a full group list when no org is specified#1340

Merged
srenatus merged 7 commits into
dexidp:masterfrom
alexmt:1184-github-groups
Nov 16, 2018
Merged

Issue #1184 - Github connector now returns a full group list when no org is specified#1340
srenatus merged 7 commits into
dexidp:masterfrom
alexmt:1184-github-groups

Conversation

@alexmt
Copy link
Copy Markdown
Contributor

@alexmt alexmt commented Nov 14, 2018

Fixes #1102

PR contains a subset of changes implemented in #1184. Original PR had been closed without merging since it accumulated too many changes and authors decided to maintain a fork.

This change unblocks an important use case: give read-only access to anyone and give extra privileges to users which belongs to the specified group.

@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 14, 2018

PS:

We are using Dex to get seamless SSO in https://github.com/argoproj/argo-cd . Dex saved us a lot of time. Thank you for maintaining it!

@srenatus
Copy link
Copy Markdown
Contributor

We are using Dex to get seamless SSO in https://github.com/argoproj/argo-cd . Dex saved us a lot of time. Thank you for maintaining it!

😄 That's nice! The more, the merrier, so, if you or someone else wants to join maintaining Dex, please don't hesitate 😉 #1281 is still dangling, but that shouldn't block anyone.

Copy link
Copy Markdown
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Solid work, thank you! Some nitpicks and questions inline 👇 🙃

Comment thread connector/github/github.go Outdated
return nil, nil
}

// formatTeamName return unique team name: prgs might have the same team names team name should be prefixed with org name to make team names unique across orgs.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] Could you add a line break, and maybe some punctuation? 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, fixed.

Comment thread connector/github/github.go Outdated
return groups, fmt.Errorf("github: user %q not in required orgs or teams", userName)
}

func (c *githubConnector) userGroups(ctx context.Context, client *http.Client) (groups []string, err error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] I hate named returns. Do you cling to them? (It's a bit of a controversial thing, I guess, and it's difficult to get these matters smoothed across the code base...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't really like named returns as well. Fixed.

Comment thread connector/github/github.go Outdated
func (c *githubConnector) userGroups(ctx context.Context, client *http.Client) (groups []string, err error) {
orgs, err := c.userOrgs(ctx, client)
if err != nil {
return groups, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] How about return nil, err? A lot less "huh, what's groups?" when reading this 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread connector/github/github.go Outdated

orgTeams, err := c.userOrgTeams(ctx, client)
if err != nil {
return groups, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] see above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread connector/github/github.go Outdated
}
}

return groups, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] return groups, nil, maybe? Just for clarity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree. Fixed

Comment thread connector/github/github.go Outdated

// userOrgs retrieves list of current user orgs
func (c *githubConnector) userOrgs(ctx context.Context, client *http.Client) ([]string, error) {
apiURL, groups := c.apiURL+"/user/orgs", []string{}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] I guess it wouldn't hurt to use two lines here 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread connector/github/github.go Outdated
return nil, fmt.Errorf("github: get orgs: %v", err)
}

for _, org := range orgs {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] we're shadowing the type org here, can we use some other name? I suppose for _, o := range orgs { would't be too terrible, either

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed to o

Comment thread connector/github/github.go Outdated
return nil, fmt.Errorf("github: get teams: %v", err)
}

for _, team := range teams {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] see above, team variable vs team struct type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed to t

if !reflect.DeepEqual(a, b) {
t.Errorf("Expected %+v to equal %+v", a, b)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❓ Am I just not seeing it or is it missing: Can we have a test that ensures the pagination for {} loops work as they should? https://github.com/dexidp/dex/pull/1340/files#diff-de977d377b738d6060529d91926d264bR432 and https://github.com/dexidp/dex/pull/1340/files#diff-de977d377b738d6060529d91926d264bR406 -- right now, I think we're only doing one iteration of each. (Not sure where we stand with the existing code and this question, either.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right. Updated test to validate pagination.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

Would you mind fixing the comment on getPagination? It's a bit confusing (it's not returning a boolean at all, is it?) and you surely have all the context right now... 😃

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done: a9f71e3

@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 15, 2018

Thank you for quick review @srenatus ! Addressed your comments. Please take another look.

Copy link
Copy Markdown
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks. Just one tiny ask, and then let's get this merged 😄

Comment thread connector/github/github.go Outdated
}

groups := make([]string, 0)
for _, org := range orgs {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] we're still shadowing org and team here, but it really doesn't matter that much.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make sense to fix it. Done: e876353

if !reflect.DeepEqual(a, b) {
t.Errorf("Expected %+v to equal %+v", a, b)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

Would you mind fixing the comment on getPagination? It's a bit confusing (it's not returning a boolean at all, is it?) and you surely have all the context right now... 😃

@srenatus
Copy link
Copy Markdown
Contributor

@alexmt Thanks for all the work. Could you make your changes reflect in the connector docs? It would really round this off, I'd think 😄

@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 15, 2018

Thank you for reminding about docs! While updating it I've noticed a bug: teamNameField was not taken into account.
Updated documentation and fixed bug as well (ce3cd53 )

PTAL

@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 15, 2018

I don't have permissions to merge. @srenatus please merge it if everything looks good to you.

@srenatus
Copy link
Copy Markdown
Contributor

@alexmt I'll give this a final look and push the button first thing tomorrow morning. Hope that's OK

@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 15, 2018

Sure, there is no rush. Thank you !

@vito
Copy link
Copy Markdown
Contributor

vito commented Nov 15, 2018

Sweet, happy to see this alive again! I work with the original submitter of #1184 on Concourse. We're planning to submit PRs for our other changes soon. We don't intend to sit on our fork forever. 🙂

@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 15, 2018

Thanks for working on original PR, @vito ! I think 94cb3da would be very useful!

@alexmt alexmt force-pushed the 1184-github-groups branch from 3f3f56d to 20bc6cd Compare November 15, 2018 22:13
@alexmt
Copy link
Copy Markdown
Contributor Author

alexmt commented Nov 15, 2018

@srenatus , I've added one more last-minute change: 20bc6cd

I believe this proposal is correct: #1102 (comment) . Full claims list should include user teams (in org:team format) as well as org names. E.g.

[
    "org-1",
    "org-1:team-1",
    "org-1:team-2",
    "org-1:team-3",
    "org-2",
    "org-2:team-4",
    "org-3"
]

This make it possible for application which uses dex to match org as well as team.

@srenatus
Copy link
Copy Markdown
Contributor

@alexmt @vito While code-wise, this looks good to merge, I'm a bit conflicted about attribution now. Can you help me clarify? It looks like some of the connector code is by @pivotal-jwinters, but given

I work with the original submitter of #1184 on Concourse.

I trust that @pivotal-jwinters is OK with that. Anyways, a quick thumbs-up would be appreciated, @pivotal-jwinters.

We're planning to submit PRs for our other changes soon. We don't intend to sit on our fork forever.

Also, I'm glad to hear that 😄

@srenatus srenatus merged commit 2425c6e into dexidp:master Nov 16, 2018
@alexmt alexmt deleted the 1184-github-groups branch November 18, 2018 21:28
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
Issue dexidp#1184 - Github connector now returns a full group list when no org is specified
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.

Github: Groups not getting loaded when no org is specified in config

3 participants