add GET /config
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user