Fail if remote url address doesnt exist (#527)

This commit is contained in:
Itxaka
2024-09-11 15:57:53 +02:00
committed by GitHub
parent 0cad53f6c5
commit 419f09160f
3 changed files with 18 additions and 31 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
@@ -340,6 +341,21 @@ func prepareConfiguration(source string) (io.Reader, error) {
cfg = bytes.NewReader(file)
return cfg, nil
}
// Its a remote url
// Check if it actually exists and fail if it doesn't
resp, err := http.Head(source)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusNotFound {
return nil, errors.New("configuration file not found in remote address")
} else {
return nil, errors.New(resp.Status)
}
}
cfgUrl := fmt.Sprintf(`config_url: %s`, source)
cfg = strings.NewReader(cfgUrl)