Merge pull request #1298 from gravitl/bugfix_v0.14.5_double_join

add timeout for http requests
This commit is contained in:
dcarns 2022-07-07 09:35:17 -04:00 committed by GitHub
commit 6cbffd1348
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import (
"net/http"
"os"
"strings"
"time"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
@ -25,6 +26,9 @@ import (
// LINUX_APP_DATA_PATH - linux path
const LINUX_APP_DATA_PATH = "/etc/netmaker"
// HTTP_TIMEOUT - timeout in seconds for http requests
const HTTP_TIMEOUT = 30
// ListPorts - lists ports of WireGuard devices
func ListPorts() error {
wgclient, err := wgctrl.New()
@ -339,7 +343,9 @@ func API(data any, method, url, authorization string) (*http.Response, error) {
if authorization != "" {
request.Header.Set("authorization", "Bearer "+authorization)
}
client := http.Client{}
client := http.Client{
Timeout: HTTP_TIMEOUT * time.Second,
}
return client.Do(request)
}