fix: upload config without previous config + bump deps

This commit is contained in:
Mikaël Cluseau
2019-12-07 21:09:12 +01:00
parent f43f4fcec4
commit 8ce4e97922
7 changed files with 30 additions and 43 deletions

View File

@ -25,7 +25,7 @@ func casCleaner() {
func cleanCAS() error {
cfg, err := readConfig()
if err != nil {
return err
return nil
}
activeTags := make([]string, len(cfg.Hosts))

View File

@ -7,7 +7,7 @@ import (
"path/filepath"
restful "github.com/emicklei/go-restful"
"github.com/mcluseau/go-swagger-ui"
swaggerui "github.com/mcluseau/go-swagger-ui"
"novit.nc/direktil/pkg/cas"
"novit.nc/direktil/local-server/pkg/apiutils"
@ -27,6 +27,8 @@ var (
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
flag.Parse()
if *address == "" && *tlsAddress == "" {

View File

@ -35,8 +35,21 @@ func writeNewConfig(reader io.Reader) (err error) {
return
}
archivesPath := filepath.Join(*dataDir, "archives")
cfgPath := configFilePath()
in, err := os.Open(cfgPath)
if err == nil {
err = backupCurrentConfig(in)
} else if !os.IsNotExist(err) {
return
}
err = os.Rename(out.Name(), cfgPath)
return
}
func backupCurrentConfig(in io.ReadCloser) (err error) {
archivesPath := filepath.Join(*dataDir, "archives")
err = os.MkdirAll(archivesPath, 0700)
if err != nil {
@ -52,11 +65,6 @@ func writeNewConfig(reader io.Reader) (err error) {
defer bck.Close()
in, err := os.Open(cfgPath)
if err != nil {
return
}
gz, err := gzip.NewWriterLevel(bck, 2)
if err != nil {
return
@ -66,10 +74,5 @@ func writeNewConfig(reader io.Reader) (err error) {
gz.Close()
in.Close()
if err != nil {
return
}
err = os.Rename(out.Name(), cfgPath)
return
}

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"net"
"net/http"
@ -124,7 +125,7 @@ func wsNotFound(req *restful.Request, resp *restful.Response) {
}
func wsError(resp *restful.Response, err error) {
log.Print("request failed: ", err)
log.Output(2, fmt.Sprint("request failed: ", err))
resp.WriteErrorString(
http.StatusInternalServerError,
http.StatusText(http.StatusInternalServerError))