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

chore: merging user service with connection manager #6225

Merged
merged 9 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 6 additions & 6 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import (
repocreds "github.com/devtron-labs/devtron/client/argocdServer/repocreds"
repository2 "github.com/devtron-labs/devtron/client/argocdServer/repository"
session2 "github.com/devtron-labs/devtron/client/argocdServer/session"
"github.com/devtron-labs/devtron/client/argocdServer/version"
"github.com/devtron-labs/devtron/client/cron"
"github.com/devtron-labs/devtron/client/dashboard"
eClient "github.com/devtron-labs/devtron/client/events"
Expand Down Expand Up @@ -166,7 +167,6 @@ import (
workflow3 "github.com/devtron-labs/devtron/pkg/workflow"
"github.com/devtron-labs/devtron/pkg/workflow/dag"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
cron2 "github.com/devtron-labs/devtron/util/cron"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/google/wire"
Expand Down Expand Up @@ -447,8 +447,8 @@ func InitializeApp() (*App, error) {
wire.Bind(new(repository8.ImageTaggingRepository), new(*repository8.ImageTaggingRepositoryImpl)),
imageTagging.NewImageTaggingServiceImpl,
wire.Bind(new(imageTagging.ImageTaggingService), new(*imageTagging.ImageTaggingServiceImpl)),
argocdServer.NewVersionServiceImpl,
wire.Bind(new(argocdServer.VersionService), new(*argocdServer.VersionServiceImpl)),
version.NewVersionServiceImpl,
wire.Bind(new(version.VersionService), new(*version.VersionServiceImpl)),

router.NewGitProviderRouterImpl,
wire.Bind(new(router.GitProviderRouter), new(*router.GitProviderRouterImpl)),
Expand Down Expand Up @@ -799,9 +799,9 @@ func InitializeApp() (*App, error) {

connection.NewArgoCDConnectionManagerImpl,
wire.Bind(new(connection.ArgoCDConnectionManager), new(*connection.ArgoCDConnectionManagerImpl)),
argo.NewArgoUserServiceImpl,
wire.Bind(new(argo.ArgoUserService), new(*argo.ArgoUserServiceImpl)),
//util2.GetEnvironmentVariables,
//argo.NewArgoUserServiceImpl,
//wire.Bind(new(argo.ArgoUserService), new(*argo.ArgoUserServiceImpl)),
////util2.GetEnvironmentVariables,
// AuthWireSet,

cron.NewCdApplicationStatusUpdateHandlerImpl,
Expand Down
23 changes: 9 additions & 14 deletions api/appStore/InstalledAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource"
util3 "github.com/devtron-labs/devtron/pkg/appStore/util"
"github.com/devtron-labs/devtron/pkg/bean"
"github.com/devtron-labs/devtron/pkg/cluster/read"
"gopkg.in/go-playground/validator.v9"
"net/http"
"reflect"
Expand All @@ -50,7 +51,6 @@ import (
"github.com/devtron-labs/devtron/pkg/auth/user"
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/devtron-labs/devtron/util/response"
"github.com/go-pg/pg"
Expand Down Expand Up @@ -88,11 +88,11 @@ type InstalledAppRestHandlerImpl struct {
appStoreDeploymentService service.AppStoreDeploymentService
appStoreDeploymentDBService service.AppStoreDeploymentDBService
helmAppClient client.HelmAppClient
argoUserService argo.ArgoUserService
cdApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler
installedAppRepository repository.InstalledAppRepository
appCrudOperationService app2.AppCrudOperationService
installedAppDeploymentTypeChangeService deploymentTypeChange.InstalledAppDeploymentTypeChangeService
clusterReadService read.ClusterReadService
}

func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService,
Expand All @@ -102,11 +102,13 @@ func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService u
chartGroupService chartGroup.ChartGroupService, validator *validator.Validate, clusterService cluster.ClusterService,
acdServiceClient application.ServiceClient, appStoreDeploymentService service.AppStoreDeploymentService,
appStoreDeploymentDBService service.AppStoreDeploymentDBService,
helmAppClient client.HelmAppClient, argoUserService argo.ArgoUserService,
helmAppClient client.HelmAppClient,

cdApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler,
installedAppRepository repository.InstalledAppRepository,
appCrudOperationService app2.AppCrudOperationService,
installedAppDeploymentTypeChangeService deploymentTypeChange.InstalledAppDeploymentTypeChangeService) *InstalledAppRestHandlerImpl {
installedAppDeploymentTypeChangeService deploymentTypeChange.InstalledAppDeploymentTypeChangeService,
clusterReadService read.ClusterReadService) *InstalledAppRestHandlerImpl {
return &InstalledAppRestHandlerImpl{
Logger: Logger,
userAuthService: userAuthService,
Expand All @@ -122,11 +124,11 @@ func NewInstalledAppRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService u
appStoreDeploymentService: appStoreDeploymentService,
appStoreDeploymentDBService: appStoreDeploymentDBService,
helmAppClient: helmAppClient,
argoUserService: argoUserService,
cdApplicationStatusUpdateHandler: cdApplicationStatusUpdateHandler,
installedAppRepository: installedAppRepository,
appCrudOperationService: appCrudOperationService,
installedAppDeploymentTypeChangeService: installedAppDeploymentTypeChangeService,
clusterReadService: clusterReadService,
}
}
func (handler *InstalledAppRestHandlerImpl) FetchAppOverview(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -550,7 +552,7 @@ func (impl *InstalledAppRestHandlerImpl) DefaultComponentInstallation(w http.Res
return
}
impl.Logger.Errorw("request payload, DefaultComponentInstallation", "clusterId", clusterId)
cluster, err := impl.clusterService.FindById(clusterId)
cluster, err := impl.clusterReadService.FindById(clusterId)
if err != nil {
impl.Logger.Errorw("service err, DefaultComponentInstallation", "error", err, "clusterId", clusterId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down Expand Up @@ -648,13 +650,6 @@ func (handler *InstalledAppRestHandlerImpl) DeleteArgoInstalledAppWithNonCascade
return
}
//rback block ends here
acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
handler.Logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx := context.WithValue(r.Context(), "token", acdToken)
request := &appStoreBean.InstallAppVersionDTO{}
request.InstalledAppId = installedAppId
request.AppName = installedApp.AppName
Expand All @@ -668,7 +663,7 @@ func (handler *InstalledAppRestHandlerImpl) DeleteArgoInstalledAppWithNonCascade
request.Namespace = installedApp.Namespace
request.AcdPartialDelete = true

request, err = handler.appStoreDeploymentService.DeleteInstalledApp(ctx, request)
request, err = handler.appStoreDeploymentService.DeleteInstalledApp(r.Context(), request)
if err != nil {
handler.Logger.Errorw("service err, DeleteInstalledApp", "err", err, "installAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
32 changes: 2 additions & 30 deletions api/appStore/deployment/AppStoreDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/go-pg/pg"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -64,7 +63,6 @@ type AppStoreDeploymentRestHandlerImpl struct {
appStoreDeploymentDBService service.AppStoreDeploymentDBService
validator *validator.Validate
helmAppService service2.HelmAppService
argoUserService argo.ArgoUserService
installAppService EAMode.InstalledAppDBService
attributesService attributes.AttributesService
}
Expand All @@ -73,8 +71,8 @@ func NewAppStoreDeploymentRestHandlerImpl(Logger *zap.SugaredLogger, userAuthSer
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, enforcerUtilHelm rbac.EnforcerUtilHelm,
appStoreDeploymentService service.AppStoreDeploymentService,
appStoreDeploymentDBService service.AppStoreDeploymentDBService,
validator *validator.Validate, helmAppService service2.HelmAppService,
argoUserService argo.ArgoUserService,
validator *validator.Validate,
helmAppService service2.HelmAppService,
installAppService EAMode.InstalledAppDBService, attributesService attributes.AttributesService) *AppStoreDeploymentRestHandlerImpl {
return &AppStoreDeploymentRestHandlerImpl{
Logger: Logger,
Expand All @@ -86,7 +84,6 @@ func NewAppStoreDeploymentRestHandlerImpl(Logger *zap.SugaredLogger, userAuthSer
appStoreDeploymentDBService: appStoreDeploymentDBService,
validator: validator,
helmAppService: helmAppService,
argoUserService: argoUserService,
installAppService: installAppService,
attributesService: attributesService,
}
Expand Down Expand Up @@ -165,16 +162,7 @@ func (handler AppStoreDeploymentRestHandlerImpl) InstallApp(w http.ResponseWrite
}
if util2.IsBaseStack() || util2.IsHelmApp(request.AppOfferingMode) {
ctx = context.WithValue(r.Context(), "token", token)
} else {
acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
handler.Logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(r.Context(), "token", acdToken)
}

defer cancel()
res, err := handler.appStoreDeploymentService.InstallApp(&request, ctx)
if err != nil {
Expand Down Expand Up @@ -348,14 +336,6 @@ func (handler AppStoreDeploymentRestHandlerImpl) DeleteInstalledApp(w http.Respo
}
if util2.IsBaseStack() || util2.IsHelmApp(request.AppOfferingMode) {
ctx = context.WithValue(r.Context(), "token", token)
} else {
acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
handler.Logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(r.Context(), "token", acdToken)
}

request, err = handler.appStoreDeploymentService.DeleteInstalledApp(ctx, request)
Expand Down Expand Up @@ -476,14 +456,6 @@ func (handler AppStoreDeploymentRestHandlerImpl) UpdateInstalledApp(w http.Respo
}
if util2.IsBaseStack() || util2.IsHelmApp(request.AppOfferingMode) {
ctx = context.WithValue(r.Context(), "token", token)
} else {
acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
handler.Logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(r.Context(), "token", acdToken)
}
res, err := handler.appStoreDeploymentService.UpdateInstalledApp(ctx, &request)
if err != nil {
Expand Down
13 changes: 1 addition & 12 deletions api/appStore/deployment/CommonDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
"github.com/devtron-labs/devtron/pkg/auth/user"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"github.com/devtron-labs/devtron/util/rbac"
"github.com/gorilla/mux"
"go.opentelemetry.io/otel"
Expand All @@ -61,15 +60,14 @@ type CommonDeploymentRestHandlerImpl struct {
installedAppService EAMode.InstalledAppDBService
validator *validator.Validate
helmAppService service2.HelmAppService
argoUserService argo.ArgoUserService
attributesService attributes.AttributesService
}

func NewCommonDeploymentRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService,
enforcer casbin.Enforcer, enforcerUtil rbac.EnforcerUtil, enforcerUtilHelm rbac.EnforcerUtilHelm,
appStoreDeploymentService service.AppStoreDeploymentService, installedAppService EAMode.InstalledAppDBService,
validator *validator.Validate, helmAppService service2.HelmAppService,
argoUserService argo.ArgoUserService, attributesService attributes.AttributesService) *CommonDeploymentRestHandlerImpl {
attributesService attributes.AttributesService) *CommonDeploymentRestHandlerImpl {
return &CommonDeploymentRestHandlerImpl{
Logger: Logger,
userAuthService: userAuthService,
Expand All @@ -80,7 +78,6 @@ func NewCommonDeploymentRestHandlerImpl(Logger *zap.SugaredLogger, userAuthServi
installedAppService: installedAppService,
validator: validator,
helmAppService: helmAppService,
argoUserService: argoUserService,
attributesService: attributesService,
}
}
Expand Down Expand Up @@ -305,14 +302,6 @@ func (handler *CommonDeploymentRestHandlerImpl) RollbackApplication(w http.Respo
}
if util2.IsBaseStack() || util2.IsHelmApp(appOfferingMode) {
ctx = context.WithValue(r.Context(), "token", token)
} else {
acdToken, err := handler.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
handler.Logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(r.Context(), "token", acdToken)
}

defer cancel()
Expand Down
36 changes: 0 additions & 36 deletions api/cluster/ClusterRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/devtron-labs/devtron/pkg/cluster"
delete2 "github.com/devtron-labs/devtron/pkg/delete"
util2 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"github.com/go-pg/pg"
"github.com/gorilla/mux"
"go.uber.org/zap"
Expand Down Expand Up @@ -72,7 +71,6 @@ type ClusterRestHandlerImpl struct {
validator *validator.Validate
enforcer casbin.Enforcer
deleteService delete2.DeleteService
argoUserService argo.ArgoUserService
environmentService environment.EnvironmentService
clusterRbacService rbac.ClusterRbacService
}
Expand All @@ -85,7 +83,6 @@ func NewClusterRestHandlerImpl(clusterService cluster.ClusterService,
validator *validator.Validate,
enforcer casbin.Enforcer,
deleteService delete2.DeleteService,
argoUserService argo.ArgoUserService,
environmentService environment.EnvironmentService,
clusterRbacService rbac.ClusterRbacService) *ClusterRestHandlerImpl {
return &ClusterRestHandlerImpl{
Expand All @@ -97,7 +94,6 @@ func NewClusterRestHandlerImpl(clusterService cluster.ClusterService,
validator: validator,
enforcer: enforcer,
deleteService: deleteService,
argoUserService: argoUserService,
environmentService: environmentService,
clusterRbacService: clusterRbacService,
}
Expand Down Expand Up @@ -139,14 +135,6 @@ func (impl ClusterRestHandlerImpl) SaveClusters(w http.ResponseWriter, r *http.R
}
if util2.IsBaseStack() {
ctx = context.WithValue(ctx, "token", token)
} else {
acdToken, err := impl.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
impl.logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(ctx, "token", acdToken)
}

for _, bean := range beans {
Expand Down Expand Up @@ -215,14 +203,6 @@ func (impl ClusterRestHandlerImpl) Save(w http.ResponseWriter, r *http.Request)
}
if util2.IsBaseStack() {
ctx = context.WithValue(ctx, "token", token)
} else {
acdToken, err := impl.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
impl.logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(ctx, "token", acdToken)
}
bean, err = impl.clusterService.Save(ctx, bean, userId)
if err != nil {
Expand Down Expand Up @@ -284,14 +264,6 @@ func (impl ClusterRestHandlerImpl) ValidateKubeconfig(w http.ResponseWriter, r *
}
if util2.IsBaseStack() {
ctx = context.WithValue(ctx, "token", token)
} else {
acdToken, err := impl.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
impl.logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(ctx, "token", acdToken)
}
res, err := impl.clusterService.ValidateKubeconfig(bean.Config)
if err != nil {
Expand Down Expand Up @@ -434,14 +406,6 @@ func (impl ClusterRestHandlerImpl) Update(w http.ResponseWriter, r *http.Request
}
if util2.IsBaseStack() {
ctx = context.WithValue(ctx, "token", token)
} else {
acdToken, err := impl.argoUserService.GetLatestDevtronArgoCdUserToken()
if err != nil {
impl.logger.Errorw("error in getting acd token", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ctx = context.WithValue(ctx, "token", acdToken)
}
_, err = impl.clusterService.Update(ctx, &bean, userId)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions api/helm-app/service/read/HelmAppReadService.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ package read
import (
"github.com/devtron-labs/common-lib/utils/k8s/commonBean"
"github.com/devtron-labs/devtron/api/helm-app/gRPC"
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/pkg/cluster/read"
"go.uber.org/zap"
)

type HelmAppReadServiceImpl struct {
logger *zap.SugaredLogger
clusterService cluster.ClusterService
logger *zap.SugaredLogger
clusterReadService read.ClusterReadService
}

type HelmAppReadService interface {
GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error)
}

func NewHelmAppReadServiceImpl(logger *zap.SugaredLogger,
clusterService cluster.ClusterService,
clusterReadService read.ClusterReadService,
) *HelmAppReadServiceImpl {
return &HelmAppReadServiceImpl{
clusterService: clusterService,
logger: logger,
logger: logger,
clusterReadService: clusterReadService,
}
}

func (impl *HelmAppReadServiceImpl) GetClusterConf(clusterId int) (*gRPC.ClusterConfig, error) {
cluster, err := impl.clusterService.FindById(clusterId)
cluster, err := impl.clusterReadService.FindById(clusterId)
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "err", err)
return nil, err
Expand Down
Loading
Loading