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

refactor(install): revamp the git auth configuration and make the organization selectable for environment repositories #2474

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion pkg/auth/auth_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ func (c *AuthConfig) SetUserAuth(url string, auth *UserAuth) {
if a.Username == auth.Username {
c.Servers[i].Users[j] = auth
c.Servers[i].CurrentUser = username
c.DefaultUsername = username
c.CurrentServer = url
return
}
}
c.Servers[i].Users = append(c.Servers[i].Users, auth)
c.Servers[i].CurrentUser = username
c.DefaultUsername = username
c.CurrentServer = url
return
}
}
Expand All @@ -91,6 +95,9 @@ func (c *AuthConfig) SetUserAuth(url string, auth *UserAuth) {
Users: []*UserAuth{auth},
CurrentUser: username,
})
c.DefaultUsername = username
c.CurrentServer = url

}

func urlsEqual(url1, url2 string) bool {
Expand Down Expand Up @@ -143,12 +150,20 @@ func (c *AuthConfig) DeleteServer(url string) {
}

func (c *AuthConfig) CurrentUser(server *AuthServer, inCluster bool) *UserAuth {
if server == nil {
return nil
}
if urlsEqual(c.PipeLineServer, server.URL) && inCluster {
return server.GetUserAuth(c.PipeLineUsername)
}
return server.CurrentAuth()
}

// CurrentAuthServer returns the current AuthServer configured in the configuration
func (c *AuthConfig) CurrentAuthServer() *AuthServer {
return c.GetServer(c.CurrentServer)
}

func (c *AuthConfig) GetOrCreateServer(url string) *AuthServer {
name := ""
kind := ""
Expand Down Expand Up @@ -303,7 +318,7 @@ func (c *AuthConfig) PickServerUserAuth(server *AuthServer, message string, batc
}
answer := m[username]
if answer == nil {
return nil, fmt.Errorf("no username chosen")
return &UserAuth{}, fmt.Errorf("no username chosen")
}
return answer, nil
}
Expand Down Expand Up @@ -429,3 +444,10 @@ func (c *AuthConfig) UpdatePipelineServer(server *AuthServer, user *UserAuth) {
c.PipeLineServer = server.URL
c.PipeLineUsername = user.Username
}

// GetPipelineAuth returns the current pipline server and user authentication
func (c *AuthConfig) GetPipelineAuth() (*AuthServer, *UserAuth) {
server := c.GetServer(c.PipeLineServer)
user := server.GetUserAuth(c.PipeLineUsername)
return server, user
}
Loading