Skip to content

Commit c36dbe1

Browse files
authored
Refactoring pipeline (#893)
* first cut refactoring - WIP * work in progress refactoring * compiled after refactoring
1 parent 4ec07f7 commit c36dbe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4580
-4444
lines changed

Wire.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package main
2323
import (
2424
"github.com/devtron-labs/devtron/api/connector"
2525
"github.com/devtron-labs/devtron/api/restHandler"
26+
pipeline2 "github.com/devtron-labs/devtron/api/restHandler/app"
2627
"github.com/devtron-labs/devtron/api/router"
2728
"github.com/devtron-labs/devtron/api/router/pubsub"
2829
"github.com/devtron-labs/devtron/api/sse"
@@ -140,8 +141,8 @@ func InitializeApp() (*App, error) {
140141

141142
pipeline.NewPipelineBuilderImpl,
142143
wire.Bind(new(pipeline.PipelineBuilder), new(*pipeline.PipelineBuilderImpl)),
143-
restHandler.NewPipelineRestHandlerImpl,
144-
wire.Bind(new(restHandler.PipelineConfigRestHandler), new(*restHandler.PipelineConfigRestHandlerImpl)),
144+
pipeline2.NewPipelineRestHandlerImpl,
145+
wire.Bind(new(pipeline2.PipelineConfigRestHandler), new(*pipeline2.PipelineConfigRestHandlerImpl)),
145146
router.NewPipelineRouterImpl,
146147
wire.Bind(new(router.PipelineConfigRouter), new(*router.PipelineConfigRouterImpl)),
147148
pipeline.NewDbPipelineOrchestrator,
@@ -276,8 +277,8 @@ func InitializeApp() (*App, error) {
276277
repository2.NewServiceClientImpl,
277278
wire.Bind(new(repository2.ServiceClient), new(*repository2.ServiceClientImpl)),
278279
wire.Bind(new(connector.Pump), new(*connector.PumpImpl)),
279-
restHandler.NewApplicationRestHandlerImpl,
280-
wire.Bind(new(restHandler.ApplicationRestHandler), new(*restHandler.ApplicationRestHandlerImpl)),
280+
restHandler.NewArgoApplicationRestHandlerImpl,
281+
wire.Bind(new(restHandler.ArgoApplicationRestHandler), new(*restHandler.ArgoApplicationRestHandlerImpl)),
281282
router.NewApplicationRouterImpl,
282283
wire.Bind(new(router.ApplicationRouter), new(*router.ApplicationRouterImpl)),
283284
//app.GetConfig,

api/restHandler/AppLabelsRestHandler.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package restHandler
1919

2020
import (
2121
"encoding/json"
22+
"github.com/devtron-labs/devtron/api/restHandler/common"
2223
"github.com/devtron-labs/devtron/pkg/app"
2324
"github.com/devtron-labs/devtron/pkg/bean"
2425
"github.com/devtron-labs/devtron/pkg/user"
@@ -62,15 +63,15 @@ func NewAppLabelRestHandlerImpl(logger *zap.SugaredLogger, appLabelService app.A
6263
func (handler AppLabelRestHandlerImpl) GetAllLabels(w http.ResponseWriter, r *http.Request) {
6364
userId, err := handler.userAuthService.GetLoggedInUser(r)
6465
if userId == 0 || err != nil {
65-
writeJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
66+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
6667
return
6768
}
6869
token := r.Header.Get("token")
6970
results := make([]*bean.AppLabelDto, 0)
7071
labels, err := handler.appLabelService.FindAll()
7172
if err != nil {
7273
handler.logger.Errorw("service err, GetAllLabels", "err", err)
73-
writeJsonResp(w, err, nil, http.StatusInternalServerError)
74+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
7475
return
7576
}
7677
objects := handler.enforcerUtil.GetRbacObjectsForAllApps()
@@ -80,45 +81,45 @@ func (handler AppLabelRestHandlerImpl) GetAllLabels(w http.ResponseWriter, r *ht
8081
results = append(results, label)
8182
}
8283
}
83-
writeJsonResp(w, nil, results, http.StatusOK)
84+
common.WriteJsonResp(w, nil, results, http.StatusOK)
8485
}
8586

8687
func (handler AppLabelRestHandlerImpl) GetAppMetaInfo(w http.ResponseWriter, r *http.Request) {
8788
userId, err := handler.userAuthService.GetLoggedInUser(r)
8889
if userId == 0 || err != nil {
89-
writeJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
90+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
9091
return
9192
}
9293
vars := mux.Vars(r)
9394
appId, err := strconv.Atoi(vars["appId"])
9495
if err != nil {
9596
handler.logger.Errorw("request err, GetAppMetaInfo", "err", err, "appId", appId)
96-
writeJsonResp(w, err, nil, http.StatusBadRequest)
97+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
9798
return
9899
}
99100

100101
//rback implementation starts here
101102
token := r.Header.Get("token")
102103
object := handler.enforcerUtil.GetAppRBACNameByAppId(appId)
103104
if ok := handler.enforcer.Enforce(token, rbac.ResourceApplications, rbac.ActionGet, object); !ok {
104-
writeJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
105+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
105106
return
106107
}
107108
//rback implementation ends here
108109

109110
res, err := handler.appLabelService.GetAppMetaInfo(appId)
110111
if err != nil {
111112
handler.logger.Errorw("service err, GetAppMetaInfo", "err", err)
112-
writeJsonResp(w, err, nil, http.StatusInternalServerError)
113+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
113114
return
114115
}
115-
writeJsonResp(w, nil, res, http.StatusOK)
116+
common.WriteJsonResp(w, nil, res, http.StatusOK)
116117
}
117118

118119
func (handler AppLabelRestHandlerImpl) UpdateLabelsInApp(w http.ResponseWriter, r *http.Request) {
119120
userId, err := handler.userAuthService.GetLoggedInUser(r)
120121
if userId == 0 || err != nil {
121-
writeJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
122+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
122123
return
123124
}
124125
decoder := json.NewDecoder(r.Body)
@@ -127,29 +128,29 @@ func (handler AppLabelRestHandlerImpl) UpdateLabelsInApp(w http.ResponseWriter,
127128
request.UserId = userId
128129
if err != nil {
129130
handler.logger.Errorw("request err, UpdateLabelsInApp", "err", err, "request", request)
130-
writeJsonResp(w, err, nil, http.StatusBadRequest)
131+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
131132
return
132133
}
133134
handler.logger.Infow("request payload, UpdateLabelsInApp", "request", request)
134135
err = handler.validator.Struct(request)
135136
if err != nil {
136137
handler.logger.Errorw("validation err, UpdateLabelsInApp", "err", err, "request", request)
137-
writeJsonResp(w, err, nil, http.StatusBadRequest)
138+
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
138139
return
139140
}
140141
//rback implementation starts here
141142
token := r.Header.Get("token")
142143
object := handler.enforcerUtil.GetAppRBACNameByAppId(request.AppId)
143144
if ok := handler.enforcer.Enforce(token, rbac.ResourceApplications, rbac.ActionUpdate, object); !ok {
144-
writeJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
145+
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
145146
return
146147
}
147148
//rback implementation ends here
148149
res, err := handler.appLabelService.UpdateLabelsInApp(&request)
149150
if err != nil {
150151
handler.logger.Errorw("service err, UpdateLabelsInApp", "err", err)
151-
writeJsonResp(w, err, nil, http.StatusInternalServerError)
152+
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
152153
return
153154
}
154-
writeJsonResp(w, nil, res, http.StatusOK)
155+
common.WriteJsonResp(w, nil, res, http.StatusOK)
155156
}

0 commit comments

Comments
 (0)