Skip to content

Commit 81f8a10

Browse files
authored
support config file template (#526)
1 parent bcb3663 commit 81f8a10

21 files changed

+2404
-741
lines changed

apiserver/httpserver/config_console_access.go

+28
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,31 @@ func (h *HTTPServer) GetConfigFileReleaseHistory(req *restful.Request, rsp *rest
260260

261261
handler.WriteHeaderAndProto(response)
262262
}
263+
264+
// GetAllConfigFileTemplates get all config file template
265+
func (h *HTTPServer) GetAllConfigFileTemplates(req *restful.Request, rsp *restful.Response) {
266+
handler := &Handler{req, rsp}
267+
268+
response := h.configServer.GetAllConfigFileTemplates(handler.ParseHeaderContext())
269+
270+
handler.WriteHeaderAndProto(response)
271+
}
272+
273+
// CreateConfigFileTemplate create config file template
274+
func (h *HTTPServer) CreateConfigFileTemplate(req *restful.Request, rsp *restful.Response) {
275+
handler := &Handler{req, rsp}
276+
277+
configFileTemplate := &api.ConfigFileTemplate{}
278+
ctx, err := handler.Parse(configFileTemplate)
279+
requestId := ctx.Value(utils.StringContext("request-id"))
280+
281+
if err != nil {
282+
configLog.Error("[Config][HttpServer] parse config file template from request error.",
283+
zap.String("requestId", requestId.(string)),
284+
zap.String("error", err.Error()))
285+
handler.WriteHeaderAndProto(api.NewConfigFileTemplateResponseWithMessage(api.ParseException, err.Error()))
286+
return
287+
}
288+
289+
handler.WriteHeaderAndProto(h.configServer.CreateConfigFileTemplate(ctx, configFileTemplate))
290+
}

apiserver/httpserver/config_server.go

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func (h *HTTPServer) bindConfigConsoleEndpoint(ws *restful.WebService) {
8181
// 配置文件发布历史
8282
ws.Route(ws.GET("/configfiles/releasehistory").To(h.GetConfigFileReleaseHistory))
8383

84+
// config file template
85+
ws.Route(ws.GET("/configfiletemplates").To(h.GetAllConfigFileTemplates))
86+
ws.Route(ws.POST("/configfiletemplates").To(h.CreateConfigFileTemplate))
8487
}
8588

8689
func (h *HTTPServer) bindConfigClientEndpoint(ws *restful.WebService) {

common/api/v1/codeinfo.go

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const (
157157
InvalidConfigFileTags uint32 = 400805
158158
InvalidWatchConfigFileFormat uint32 = 400806
159159
NotFoundResourceConfigFile uint32 = 400807
160+
InvalidConfigFileTemplateName uint32 = 400808
160161

161162
// 鉴权相关错误码
162163
InvalidUserOwners uint32 = 400410
@@ -317,6 +318,7 @@ var code2info = map[uint32]string{
317318
InvalidConfigFileTags: "invalid config file tags, tags should be pair, like key1,value1,key2,value2. and key,value should not blank",
318319
InvalidWatchConfigFileFormat: "invalid watch config file format",
319320
NotFoundResourceConfigFile: "config file not existed",
321+
InvalidConfigFileTemplateName: "invalid config file template name",
320322

321323
// 鉴权错误
322324
NotFoundUser: "not found user",

0 commit comments

Comments
 (0)