This commit is contained in:
AJ ONeal 2020-11-30 17:48:09 -07:00
parent d17d521e4a
commit c3cd41a24f
6 changed files with 22 additions and 12 deletions

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
@ -13,6 +12,7 @@ import (
"strings"
"time"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"
@ -79,7 +79,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
// r.Body is always .Close()ed by Go's http server
r.Body = http.MaxBytesReader(w, r.Body, options.DefaultMaxBodySize)
// TODO admin auth middleware
log.Println("TODO: handle authentication")
log.Printf("TODO: handle authentication")
next.ServeHTTP(w, r)
})
})
@ -153,7 +153,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
decoder := json.NewDecoder(r.Body)
msg := &KillMsg{}
if err := decoder.Decode(msg); nil != err {
log.Println("kill job invalid json:", err)
log.Printf("kill job invalid json:\n%v", err)
http.Error(w, "invalid json body", http.StatusBadRequest)
return
}
@ -178,12 +178,12 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
decoder := json.NewDecoder(r.Body)
msg := &webhooks.Ref{}
if err := decoder.Decode(msg); nil != err {
log.Println("promotion job invalid json:", err)
log.Printf("promotion job invalid json:\n%v", err)
http.Error(w, "invalid json body", http.StatusBadRequest)
return
}
if "" == msg.HTTPSURL || "" == msg.RefName {
log.Println("promotion job incomplete json", msg)
log.Printf("promotion job incomplete json %s", msg)
http.Error(w, "incomplete json body", http.StatusBadRequest)
return
}
@ -196,7 +196,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
}
}
if n < 0 {
log.Println("promotion job invalid: cannot promote:", n)
log.Printf("promotion job invalid: cannot promote: %d", n)
http.Error(w, "invalid promotion", http.StatusBadRequest)
return
}
@ -319,7 +319,7 @@ func remove(jobID string, nokill bool) {
if nil != job.Cmd.Process {
// but definitely was started
err := job.Cmd.Process.Kill()
log.Println("error killing job:", err)
log.Printf("error killing job:\n%v", err)
}
}
}

10
internal/log/log.go Normal file
View File

@ -0,0 +1,10 @@
package log
import (
"log"
)
// Printf wraps log.Printf
func Printf(msg string, els ...interface{}) {
log.Printf(msg, els...)
}

View File

@ -5,11 +5,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"
@ -114,7 +114,7 @@ func InitWebhook(providername string, secretList *string, envname string) func()
branch = refName
ref = fmt.Sprintf("refs/heads/%s", refName)
default:
log.Println("unexpected bitbucket RefType", refType)
log.Printf("unexpected bitbucket RefType %s\n", refType)
ref = fmt.Sprintf("refs/UNKNOWN/%s", refName)
}

View File

@ -7,11 +7,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"

View File

@ -3,11 +3,11 @@ package github
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
@ -15,6 +14,7 @@ import (
"git.rootprojects.org/root/gitdeploy/assets/examples"
"git.rootprojects.org/root/gitdeploy/assets/public"
"git.rootprojects.org/root/gitdeploy/internal/api"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"
"git.rootprojects.org/root/vfscopy"