fix: moved authenticated requests to helper
Some checks failed
CI / build (push) Failing after 3m19s
CI / lint (push) Failing after 2m50s
CI / pkl-validate (push) Successful in 10s
CI / integration-tests (push) Has been skipped
CI / conformance-tests (latest) (push) Has been skipped

This commit is contained in:
2026-02-03 22:44:23 +01:00
parent ca99733c9c
commit 35a789d5d9
3 changed files with 38 additions and 94 deletions

View File

@@ -3,6 +3,9 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)
@@ -45,3 +48,31 @@ func parseLXCProperties(data json.RawMessage) (*LXCProperties, error) {
}
return &props, nil
}
func createAuthorizationString(username, token string) string {
return "PVEAPIToken=" + username + "=" + token
}
func authenticatedRequest(method, url, authorization string, body io.Reader) ([]byte, error) {
client := &http.Client{}
request, err := http.NewRequest(method, url, body)
if err != nil {
return nil, err
}
request.Header.Set("Authorization", authorization)
resp, err := client.Do(request)
if err != nil {
return nil, err
}
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
log.Println("URL: ", method, "Status Code:", resp.Status, "Body: ", string(data))
return data, nil
}