mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 13:56:43 +00:00
Allow custom headers on CLI
This commit is contained in:
@@ -4,8 +4,10 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Infisical/infisical-merge/packages/config"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
func GetHomeDir() (string, error) {
|
||||
@@ -27,3 +29,25 @@ func ValidateInfisicalAPIConnection() (ok bool) {
|
||||
_, err := http.Get(fmt.Sprintf("%v/status", config.INFISICAL_URL))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func GetRestyClientWithCustomHeaders() (*resty.Client, error) {
|
||||
httpClient := resty.New()
|
||||
customHeaders := os.Getenv("INFISICAL_CUSTOM_HEADERS")
|
||||
if customHeaders != "" {
|
||||
headers := map[string]string{}
|
||||
pairs := strings.Split(customHeaders, " ")
|
||||
for _, pair := range pairs {
|
||||
kv := strings.SplitN(pair, "=", 2)
|
||||
if len(kv) != 2 {
|
||||
return nil, fmt.Errorf("invalid custom header format. Expected \"headerKey1=value1 headerKey2=value2 ....\" but got %v", customHeaders)
|
||||
}
|
||||
key := strings.TrimSpace(kv[0])
|
||||
value := strings.TrimSpace(kv[1])
|
||||
if !strings.EqualFold(key, "User-Agent") && !strings.EqualFold(key, "Accept") {
|
||||
headers[key] = value
|
||||
}
|
||||
}
|
||||
httpClient.SetHeaders(headers)
|
||||
}
|
||||
return httpClient, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user