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

task: added api for getting default template values #2905

Merged
merged 4 commits into from
Feb 1, 2023
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
35 changes: 35 additions & 0 deletions api/restHandler/app/DeploymentPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type DevtronAppDeploymentRestHandler interface {
type DevtronAppDeploymentConfigRestHandler interface {
ConfigureDeploymentTemplateForApp(w http.ResponseWriter, r *http.Request)
GetDeploymentTemplate(w http.ResponseWriter, r *http.Request)
GetDefaultDeploymentTemplate(w http.ResponseWriter, r *http.Request)
GetAppOverrideForDefaultTemplate(w http.ResponseWriter, r *http.Request)

EnvConfigOverrideCreate(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -588,6 +589,40 @@ func (handler PipelineConfigRestHandlerImpl) GetDeploymentTemplate(w http.Respon
common.WriteJsonResp(w, nil, appConfigResponse, http.StatusOK)
}

func (handler *PipelineConfigRestHandlerImpl) GetDefaultDeploymentTemplate(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appId, err := strconv.Atoi(vars["appId"])
if err != nil {
handler.Logger.Error("error in getting appId path param, GetDefaultDeploymentTemplate", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
chartRefId, err := strconv.Atoi(vars["chartRefId"])
if err != nil {
handler.Logger.Error("error in getting chartRefId path param, GetDefaultDeploymentTemplate", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
token := r.Header.Get("token")
app, err := handler.pipelineBuilder.GetApp(appId)
if err != nil {
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
obj := handler.enforcerUtil.GetAppRBACName(app.AppName)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionGet, obj); !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), "unauthorized user", http.StatusForbidden)
return
}
defaultTemplate, err := handler.chartService.GetAppOverrideForDefaultTemplate(chartRefId)
if err != nil {
handler.Logger.Errorw("error in getting default deployment template, GetDefaultDeploymentTemplate", "err", err, "appId", appId, "chartRefId", chartRefId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, nil, defaultTemplate, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) GetCdPipelines(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appId, err := strconv.Atoi(vars["appId"])
Expand Down
1 change: 1 addition & 0 deletions api/router/PipelineConfigRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mu

configRouter.Path("/template").HandlerFunc(router.restHandler.ConfigureDeploymentTemplateForApp).Methods("POST")
configRouter.Path("/template/{appId}/{chartRefId}").HandlerFunc(router.restHandler.GetDeploymentTemplate).Methods("GET")
configRouter.Path("/template/default/{appId}/{chartRefId}").HandlerFunc(router.restHandler.GetDefaultDeploymentTemplate).Methods("GET")
configRouter.Path("/template/update").HandlerFunc(router.restHandler.UpdateAppOverride).Methods("POST")

configRouter.Path("/cd-pipeline").HandlerFunc(router.restHandler.CreateCdPipeline).Methods("POST")
Expand Down
40 changes: 40 additions & 0 deletions specs/default-template-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
openapi: "3.0.3"
info:
version: 1.0.0
title: Devtron Labs
paths:
/orchestrator/app/template/default:
get:
description: Get default values of template by chartRefId
parameters:
- name: appId
in: query
required: true
schema:
type: integer
- name: chartRefId
in: query
required: true
schema:
type: integer
responses:
"200":
description: value
content:
application/json:
schema:
$ref: "#/components/schemas/DefaultTemplateResponse"
components:
schemas:
DefaultTemplateResponse:
properties:
appOverride:
type: array
items:
type: object
properties:
Key:
type: string
Value:
type: string
description: template json in form of map