Skip to content

fix: [Prod]Git account breaking whenever opening an existing account git repo. #4117

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions api/restHandler/app/AutoCompleteRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type DevtronAppAutoCompleteRestHandler interface {
GitListAutocomplete(w http.ResponseWriter, r *http.Request)
DisabledGitListAutocomplete(w http.ResponseWriter, r *http.Request)
RegistriesListAutocomplete(w http.ResponseWriter, r *http.Request)
TeamListAutocomplete(w http.ResponseWriter, r *http.Request)
EnvironmentListAutocomplete(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -169,6 +170,33 @@ func (handler PipelineConfigRestHandlerImpl) GitListAutocomplete(w http.Response
common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) DisabledGitListAutocomplete(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
vars := mux.Vars(r)
appId, err := strconv.Atoi(vars["appId"])
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
providerId := vars["providerId"]
handler.Logger.Infow("request payload, DisabledGitListAutocomplete", "appId", appId)
//RBAC
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, object); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
}
//RBAC
res, err := handler.gitRegistryConfig.FetchOneDisabledGitProvider(providerId)
if err != nil {
handler.Logger.Errorw("service err, DisabledGitListAutocomplete", "err", err, "appId", appId)
Copy link
Member

Choose a reason for hiding this comment

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

add providerId

common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

common.WriteJsonResp(w, err, res, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) RegistriesListAutocomplete(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
vars := mux.Vars(r)
Expand Down
1 change: 1 addition & 0 deletions api/router/PipelineConfigRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mu

configRouter.Path("/{appId}/autocomplete/environment").HandlerFunc(router.restHandler.EnvironmentListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/git").HandlerFunc(router.restHandler.GitListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/disabled-git/{providerId}").HandlerFunc(router.restHandler.DisabledGitListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/docker").HandlerFunc(router.restHandler.RegistriesListAutocomplete).Methods("GET")
configRouter.Path("/{appId}/autocomplete/team").HandlerFunc(router.restHandler.TeamListAutocomplete).Methods("GET")

Expand Down
11 changes: 11 additions & 0 deletions internal/sql/repository/GitProviderRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type GitProviderRepository interface {
FindByUrl(providerUrl string) (GitProvider, error)
Update(gitProvider *GitProvider) error
MarkProviderDeleted(gitProvider *GitProvider) error
FindDisabledById(providerId string) (GitProvider, error)
}

type GitProviderRepositoryImpl struct {
Expand Down Expand Up @@ -89,6 +90,16 @@ func (impl GitProviderRepositoryImpl) FindAllActiveForAutocomplete() ([]GitProvi
return providers, err
}

func (impl GitProviderRepositoryImpl) FindDisabledById(providerId string) (GitProvider, error) {
var provider GitProvider
err := impl.dbConnection.Model(&provider).
Where("id = ?", providerId).
Where("active = ?", false).
Column("id", "name", "url", "auth_mode").
Where("deleted = ?", false).Select()
return provider, err
}

func (impl GitProviderRepositoryImpl) FindAll() ([]GitProvider, error) {
var providers []GitProvider
err := impl.dbConnection.Model(&providers).
Expand Down
19 changes: 19 additions & 0 deletions pkg/pipeline/GitRegistryConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type GitRegistryConfig interface {
GetAll() ([]GitRegistry, error)
FetchAllGitProviders() ([]GitRegistry, error)
FetchOneGitProvider(id string) (*GitRegistry, error)
FetchOneDisabledGitProvider(id string) (*GitRegistry, error)
Update(request *GitRegistry) (*GitRegistry, error)
Delete(request *GitRegistry) error
}
Expand Down Expand Up @@ -201,6 +202,24 @@ func (impl GitRegistryConfigImpl) FetchOneGitProvider(providerId string) (*GitRe
return providerRes, err
}

func (impl GitRegistryConfigImpl) FetchOneDisabledGitProvider(providerId string) (*GitRegistry, error) {
impl.logger.Debug("fetch disabled git provider by ID from db")
provider, err := impl.gitProviderRepo.FindDisabledById(providerId)
if err != nil {
impl.logger.Errorw("error in fetching disabled git providers", "err", err)
Copy link
Member

Choose a reason for hiding this comment

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

add providerId in log

return nil, err
}

providerRes := &GitRegistry{
Id: provider.Id,
Name: provider.Name,
Url: provider.Url,
AuthMode: provider.AuthMode,
}

return providerRes, err
}

func (impl GitRegistryConfigImpl) Update(request *GitRegistry) (*GitRegistry, error) {
impl.logger.Debugw("get repo create request", "req", request)

Expand Down