Skip to content

Commit

Permalink
chore: webdav: enable gosec
Browse files Browse the repository at this point in the history
  • Loading branch information
dsonck92 committed Jul 10, 2024
1 parent b491ab4 commit 1667c7a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
1 change: 0 additions & 1 deletion webdav/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ linters:
- nestif
- canonicalheader
- lll
- gosec
- funlen

severity:
Expand Down
2 changes: 1 addition & 1 deletion webdav/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (cl *APIClient) DownloadOriginal(file *File, outputPath string) error {
infra.GetLogger().Error(err.Error())
}
}(resp.Body)
out, err := os.Create(outputPath)
out, err := os.Create(outputPath) //nolint:gosec // Known safe value
if err != nil {
return err
}
Expand Down
9 changes: 3 additions & 6 deletions webdav/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
)

type Config struct {
Port int
Host string
Port string
APIURL string
IdPURL string
S3 S3Config
Expand Down Expand Up @@ -46,12 +47,8 @@ var config *Config

func GetConfig() *Config {
if config == nil {
port, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
panic(err)
}
config = &Config{
Port: port,
Port: os.Getenv("PORT"),
}
readURLs(config)
readS3(config)
Expand Down
4 changes: 2 additions & 2 deletions webdav/handler/method_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (h *Handler) methodGet(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Length", fmt.Sprintf("%d", chunkSize))
w.Header().Set("Content-Type", "application/octet-stream")
w.WriteHeader(http.StatusPartialContent)
file, err := os.Open(outputPath)
file, err := os.Open(outputPath) //nolint:gosec // Known safe path
if err != nil {
infra.HandleError(err, w)
return
Expand All @@ -106,7 +106,7 @@ func (h *Handler) methodGet(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Length", fmt.Sprintf("%d", stat.Size()))
w.Header().Set("Content-Type", "application/octet-stream")
w.WriteHeader(http.StatusOK)
file, err := os.Open(outputPath)
file, err := os.Open(outputPath) //nolint:gosec // Known safe path
if err != nil {
infra.HandleError(err, w)
return
Expand Down
2 changes: 1 addition & 1 deletion webdav/handler/method_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (h *Handler) methodPut(w http.ResponseWriter, r *http.Request) {
return
}
outputPath := filepath.Join(os.TempDir(), uuid.New().String())
ws, err := os.Create(outputPath)
ws, err := os.Create(outputPath) //nolint:gosec // Known safe path
if err != nil {
infra.HandleError(err, w)
return
Expand Down
25 changes: 16 additions & 9 deletions webdav/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ package main

import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -115,12 +115,19 @@ func main() {

startTokenRefresh(idpClient)

log.Printf("Listening on port %d", cfg.Port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Port), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/v2/health") {
mux.ServeHTTP(w, r)
} else {
basicAuthMiddleware(mux, idpClient).ServeHTTP(w, r)
}
})))
server := &http.Server{
Addr: net.JoinHostPort(cfg.Host, cfg.Port),
ReadHeaderTimeout: 30 * time.Second,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/v2/health") {
mux.ServeHTTP(w, r)
} else {
basicAuthMiddleware(mux, idpClient).ServeHTTP(w, r)
}
}),
}

log.Printf("Listening on %s", server.Addr)

log.Fatal(server.ListenAndServe())
}

0 comments on commit 1667c7a

Please sign in to comment.