diff --git a/cmd/dkl-local-server/ws-configs.go b/cmd/dkl-local-server/ws-configs.go index c58243c..872ed79 100644 --- a/cmd/dkl-local-server/ws-configs.go +++ b/cmd/dkl-local-server/ws-configs.go @@ -13,6 +13,20 @@ import ( "novit.tech/direktil/pkg/localconfig" ) +func wsFetchConfig(req *restful.Request, resp *restful.Response) { + cfg, err := readConfig() + if err != nil { + if os.IsNotExist(err) { + wsNotFound(resp) + } else { + wsError(resp, httperr.Internal(err)) + } + return + } + + resp.WriteEntity(cfg) +} + func wsUploadConfig(req *restful.Request, resp *restful.Response) { cfg := &localconfig.Config{} if err := req.ReadEntity(cfg); err != nil { diff --git a/cmd/dkl-local-server/ws.go b/cmd/dkl-local-server/ws.go index 62540a3..6d3a911 100644 --- a/cmd/dkl-local-server/ws.go +++ b/cmd/dkl-local-server/ws.go @@ -73,6 +73,9 @@ func registerWS(rest *restful.Container) { Doc("Sign a download set")) // - configs API + ws.Route(ws.GET("/config").To(wsFetchConfig). + Produces(mime.JSON, mime.YAML). + Doc("Fetch the current configuration")) ws.Route(ws.POST("/configs").To(wsUploadConfig). Consumes(mime.YAML, mime.JSON).Param(ws.BodyParameter("config", "The new full configuration")). Produces(mime.JSON).Writes(true).