Skip to content

Commit

Permalink
Revert "Merge pull request rancher#27143 from mrajashree/ghEmail"
Browse files Browse the repository at this point in the history
This reverts commit f775702, reversing
changes made to 170e08b.
  • Loading branch information
mrajashree committed May 29, 2020
1 parent 4ef4961 commit a0403ad
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 66 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ require (
github.com/rancher/security-scan v0.1.7-0.20200222041501-f7377f127168
github.com/rancher/steve v0.0.0-20200518163824-9e4ed62a470a
github.com/rancher/system-upgrade-controller v0.4.1-0.20200326220202-4655d4a551bd
github.com/rancher/types v0.0.0-20200528211210-57a315b44c03
github.com/rancher/types v0.0.0-20200529180020-29fa023a5bd8
github.com/rancher/wrangler v0.6.2-0.20200515155908-1923f3f8ec3f
github.com/rancher/wrangler-api v0.6.1-0.20200515193802-dcf70881b087
github.com/robfig/cron v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ github.com/rancher/steve v0.0.0-20200518163824-9e4ed62a470a/go.mod h1:48ecYu5vn9
github.com/rancher/system-upgrade-controller v0.4.1-0.20200326220202-4655d4a551bd h1:h4VDCviV2Iixfk9SjUcfzq0l+pRsvadt2QSNuoQKfxE=
github.com/rancher/system-upgrade-controller v0.4.1-0.20200326220202-4655d4a551bd/go.mod h1:8x2eK9Q5/1c2AC9xJtNFyAyjP9ytP4uPHhGA6wajIS0=
github.com/rancher/types v0.0.0-20200326224235-0d1e1dcc8d55/go.mod h1:k5LoTlUpefw0eAzFSJsZI0gf+C4WE41yrc1jm/MS1nM=
github.com/rancher/types v0.0.0-20200528211210-57a315b44c03 h1:jiF1xMhb6WsFBVE0INCOOqlsCal2AWTzyXfc/vAQXnA=
github.com/rancher/types v0.0.0-20200528211210-57a315b44c03/go.mod h1:1f9IG3X8ZreqsCNnt60wcEpGC4p8k9qYp/UZflb1DYw=
github.com/rancher/types v0.0.0-20200529180020-29fa023a5bd8 h1:QLiisqxxK5XQn51/nfo55NKGPQzh7yO+2fp3REYKbAQ=
github.com/rancher/types v0.0.0-20200529180020-29fa023a5bd8/go.mod h1:1f9IG3X8ZreqsCNnt60wcEpGC4p8k9qYp/UZflb1DYw=
github.com/rancher/wrangler v0.1.4/go.mod h1:EYP7cqpg42YqElaCm+U9ieSrGQKAXxUH5xsr+XGpWyE=
github.com/rancher/wrangler v0.4.1/go.mod h1:1cR91WLhZgkZ+U4fV9nVuXqKurWbgXcIReU4wnQvTN8=
github.com/rancher/wrangler v0.5.0/go.mod h1:txHSBkPtVgNH/0pUCvdP0Ak0HptAOc9ffBmFxQnL4z4=
Expand Down
9 changes: 0 additions & 9 deletions pkg/auth/providers/github/github_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ type Account struct {
AvatarURL string `json:"avatar_url,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
Type string `json:"type,omitempty"`
Email string `json:"email,omitempty"`
Company string `json:"company,omitempty"`
Location string `json:"location,omitempty"`
}

//Team defines properties a team on github has
Expand All @@ -29,12 +26,6 @@ type Team struct {
Slug string `json:"slug,omitempty"`
}

// EmailResponse is used for getting response from the emails endpoint. https://developer.github.com/v3/users/emails/#response .We only need the Email and Primary fields
type EmailResponse struct {
Email string `json:"email,omitempty"`
Primary bool `json:"primary,omitempty"`
}

func (t *Team) toGithubAccount(url string, account *Account) {
account.ID = t.ID
account.Name = t.Name
Expand Down
24 changes: 1 addition & 23 deletions pkg/auth/providers/github/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,7 @@ func (g *GClient) getUser(githubAccessToken string, config *v3.GithubConfig) (Ac
logrus.Errorf("Github getGithubUser: error unmarshalling response, err: %v", err)
return Account{}, err
}
// If the UserInfo endpoint does not return the email of a user, we need to query the emails endpoint
if githubAcct.Email == "" {
emailURL := g.getURL("USER_EMAIL", config)
emailResp, _, err := g.getFromGithub(githubAccessToken, emailURL)
if err != nil {
logrus.Errorf("Github getGithubUser: GET email url %v received error from github, err: %v", emailURL, err)
return Account{}, err
}
var userEmails []EmailResponse
if err := json.Unmarshal(emailResp, &userEmails); err != nil {
logrus.Errorf("Github getGithubUser: error unmarshalling email response, err: %v", err)
return Account{}, err
}
// This api endpoint doesn't accept query parameter to filter on primary, so we get all emails and loop through it
for _, userEmail := range userEmails {
if userEmail.Primary {
githubAcct.Email = userEmail.Email
break
}
}
}

return githubAcct, nil
}

Expand Down Expand Up @@ -376,8 +356,6 @@ func (g *GClient) getURL(endpoint string, config *v3.GithubConfig) string {
toReturn = apiEndpoint + "/orgs/"
case "USER_INFO":
toReturn = apiEndpoint + "/user"
case "USER_EMAIL":
toReturn = apiEndpoint + "/user/emails"
case "ORG_INFO":
toReturn = apiEndpoint + "/user/orgs?per_page=1"
case "USER_PICTURE":
Expand Down
5 changes: 0 additions & 5 deletions pkg/auth/providers/github/github_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ func (g *ghProvider) toPrincipal(principalType string, acct Account, token *v3.T
if token != nil {
princ.Me = g.isThisUserMe(token.UserPrincipal, princ)
}
princ.ExtraInfo = map[string]string{
"Email": acct.Email,
"Company": acct.Company,
"Location": acct.Location,
}
} else {
princ.PrincipalType = "group"
if token != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/providers/github/githubconfig_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func githubRedirectURL(hostname, clientID string, tls bool) string {
} else {
redirect = githubDefaultHostName
}
redirect = redirect + "/login/oauth/authorize?client_id=" + clientID + "&scope=read:org%20user:email"
redirect = redirect + "/login/oauth/authorize?client_id=" + clientID
return redirect
}

Expand Down
27 changes: 7 additions & 20 deletions pkg/auth/tokens/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"reflect"
"sort"
"time"

Expand Down Expand Up @@ -561,22 +560,21 @@ func (m *Manager) EnsureAndGetUserAttribute(userID string) (*v3.UserAttribute, b
},
},
GroupPrincipals: map[string]v3.Principals{},
UserPrincipal: v3.Principal{},
LastRefresh: "",
NeedsRefresh: false,
}

return attribs, true, nil
}

func (m *Manager) UserAttributeCreateOrUpdate(userID, provider string, userPrincipal v3.Principal, groupPrincipals []v3.Principal) error {
func (m *Manager) UserAttributeCreateOrUpdate(userID, provider string, groupPrincipals []v3.Principal) error {
attribs, needCreate, err := m.EnsureAndGetUserAttribute(userID)
if err != nil {
return err
}

if needCreate {
updateAttribs(attribs, provider, userPrincipal, groupPrincipals)
attribs.GroupPrincipals[provider] = v3.Principals{Items: groupPrincipals}
_, err := m.userAttributes.Create(attribs)
if err != nil {
return err
Expand All @@ -585,8 +583,8 @@ func (m *Manager) UserAttributeCreateOrUpdate(userID, provider string, userPrinc
}

// Exists, just update if necessary
if m.UserAttributeChanged(attribs, provider, userPrincipal, groupPrincipals) {
updateAttribs(attribs, provider, userPrincipal, groupPrincipals)
if m.UserAttributeChanged(attribs, provider, groupPrincipals) {
attribs.GroupPrincipals[provider] = v3.Principals{Items: groupPrincipals}
_, err := m.userAttributes.Update(attribs)
if err != nil {
return err
Expand All @@ -596,13 +594,7 @@ func (m *Manager) UserAttributeCreateOrUpdate(userID, provider string, userPrinc
return nil
}

func updateAttribs(attribs *v3.UserAttribute, provider string, userPrincipal v3.Principal, groupPrincipals []v3.Principal) {
attribs.GroupPrincipals[provider] = v3.Principals{Items: groupPrincipals}
attribs.UserPrincipal = userPrincipal
attribs.UserName = userPrincipal.DisplayName
}

func (m *Manager) UserAttributeChanged(attribs *v3.UserAttribute, provider string, userPrincipal v3.Principal, groupPrincipals []v3.Principal) bool {
func (m *Manager) UserAttributeChanged(attribs *v3.UserAttribute, provider string, groupPrincipals []v3.Principal) bool {
oldSet := []string{}
newSet := []string{}
for _, principal := range attribs.GroupPrincipals[provider].Items {
Expand All @@ -623,12 +615,7 @@ func (m *Manager) UserAttributeChanged(attribs *v3.UserAttribute, provider strin
return true
}
}
if !reflect.DeepEqual(attribs.UserPrincipal, userPrincipal) {
return true
}
if attribs.UserName != userPrincipal.DisplayName {
return true
}

return false
}

Expand All @@ -649,7 +636,7 @@ func (m *Manager) NewLoginToken(userID string, userPrincipal v3.Principal, group
}

err := wait.ExponentialBackoff(uaBackoff, func() (bool, error) {
err := m.UserAttributeCreateOrUpdate(userID, provider, userPrincipal, groupPrincipals)
err := m.UserAttributeCreateOrUpdate(userID, provider, groupPrincipals)
if err != nil {
logrus.Warnf("Problem creating or updating userAttribute for %v: %v", userID, err)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ github.com/rancher/system-upgrade-controller/pkg/apis/upgrade.cattle.io/v1
github.com/rancher/system-upgrade-controller/pkg/condition
github.com/rancher/system-upgrade-controller/pkg/generated/clientset/versioned/scheme
github.com/rancher/system-upgrade-controller/pkg/generated/clientset/versioned/typed/upgrade.cattle.io/v1
# github.com/rancher/types v0.0.0-20200528211210-57a315b44c03
# github.com/rancher/types v0.0.0-20200529180020-29fa023a5bd8
github.com/rancher/types/apis/apiregistration.k8s.io/v1
github.com/rancher/types/apis/apps/v1
github.com/rancher/types/apis/autoscaling/v2beta2
Expand Down

0 comments on commit a0403ad

Please sign in to comment.