mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 08:27:36 +00:00
Allow custom headers on Config, improve docs and GetRestyClientWithCustomHeaders logic
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/Infisical/infisical-merge/packages/config"
|
"github.com/Infisical/infisical-merge/packages/config"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
@@ -35,18 +36,67 @@ func GetRestyClientWithCustomHeaders() (*resty.Client, error) {
|
|||||||
customHeaders := os.Getenv("INFISICAL_CUSTOM_HEADERS")
|
customHeaders := os.Getenv("INFISICAL_CUSTOM_HEADERS")
|
||||||
if customHeaders != "" {
|
if customHeaders != "" {
|
||||||
headers := map[string]string{}
|
headers := map[string]string{}
|
||||||
pairs := strings.Split(customHeaders, " ")
|
|
||||||
for _, pair := range pairs {
|
pos := 0
|
||||||
kv := strings.SplitN(pair, "=", 2)
|
for pos < len(customHeaders) {
|
||||||
if len(kv) != 2 {
|
for pos < len(customHeaders) && unicode.IsSpace(rune(customHeaders[pos])) {
|
||||||
|
pos++
|
||||||
|
}
|
||||||
|
|
||||||
|
if pos >= len(customHeaders) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
keyStart := pos
|
||||||
|
for pos < len(customHeaders) && customHeaders[pos] != '=' && !unicode.IsSpace(rune(customHeaders[pos])) {
|
||||||
|
pos++
|
||||||
|
}
|
||||||
|
|
||||||
|
if pos >= len(customHeaders) || customHeaders[pos] != '=' {
|
||||||
return nil, fmt.Errorf("invalid custom header format. Expected \"headerKey1=value1 headerKey2=value2 ....\" but got %v", customHeaders)
|
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])
|
key := customHeaders[keyStart:pos]
|
||||||
if !strings.EqualFold(key, "User-Agent") && !strings.EqualFold(key, "Accept") {
|
pos++
|
||||||
|
|
||||||
|
for pos < len(customHeaders) && unicode.IsSpace(rune(customHeaders[pos])) {
|
||||||
|
pos++
|
||||||
|
}
|
||||||
|
|
||||||
|
var value string
|
||||||
|
|
||||||
|
if pos < len(customHeaders) {
|
||||||
|
if customHeaders[pos] == '"' || customHeaders[pos] == '\'' {
|
||||||
|
quoteChar := customHeaders[pos]
|
||||||
|
pos++
|
||||||
|
valueStart := pos
|
||||||
|
|
||||||
|
for pos < len(customHeaders) &&
|
||||||
|
(customHeaders[pos] != quoteChar ||
|
||||||
|
(pos > 0 && customHeaders[pos-1] == '\\')) {
|
||||||
|
pos++
|
||||||
|
}
|
||||||
|
|
||||||
|
if pos < len(customHeaders) {
|
||||||
|
value = customHeaders[valueStart:pos]
|
||||||
|
pos++
|
||||||
|
} else {
|
||||||
|
value = customHeaders[valueStart:]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
valueStart := pos
|
||||||
|
for pos < len(customHeaders) && !unicode.IsSpace(rune(customHeaders[pos])) {
|
||||||
|
pos++
|
||||||
|
}
|
||||||
|
value = customHeaders[valueStart:pos]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if key != "" && !strings.EqualFold(key, "User-Agent") && !strings.EqualFold(key, "Accept") {
|
||||||
headers[key] = value
|
headers[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpClient.SetHeaders(headers)
|
httpClient.SetHeaders(headers)
|
||||||
}
|
}
|
||||||
return httpClient, nil
|
return httpClient, nil
|
||||||
|
|||||||
@@ -120,6 +120,22 @@ The CLI is designed for a variety of secret management applications ranging from
|
|||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
<Tip>
|
||||||
|
## Custom Request Headers
|
||||||
|
|
||||||
|
The Infisical CLI supports custom HTTP headers for requests to servers protected by authentication services such as Cloudflare Access. Configure these headers using the `INFISICAL_CUSTOM_HEADERS` environment variable:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Syntax: headername1=headervalue1 headername2=headervalue2
|
||||||
|
export INFISICAL_CUSTOM_HEADERS="Access-Client-Id=your-client-id Access-Client-Secret=your-client-secret"
|
||||||
|
|
||||||
|
# Execute Infisical commands after setting the environment variable
|
||||||
|
infisical secrets ls
|
||||||
|
```
|
||||||
|
|
||||||
|
This functionality enables secure interaction with Infisical instances that require specific authentication headers.
|
||||||
|
</Tip>
|
||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
Your terminal keeps a history with the commands you run. When you create Infisical secrets directly from your terminal, they'll stay there for a while.
|
Your terminal keeps a history with the commands you run. When you create Infisical secrets directly from your terminal, they'll stay there for a while.
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ client := infisical.NewInfisicalClient(context.Background(), infisical.Config{
|
|||||||
<ParamField query="CacheExpiryInSeconds" type="number" default={0} optional>
|
<ParamField query="CacheExpiryInSeconds" type="number" default={0} optional>
|
||||||
Defines how long certain responses should be cached in memory, in seconds. When set to a positive value, responses from specific methods (like secret fetching) will be cached for this duration. Set to 0 to disable caching.
|
Defines how long certain responses should be cached in memory, in seconds. When set to a positive value, responses from specific methods (like secret fetching) will be cached for this duration. Set to 0 to disable caching.
|
||||||
</ParamField>
|
</ParamField>
|
||||||
|
|
||||||
|
<ParamField query="CustomHeaders" type="string" default="" optional>
|
||||||
|
Allows you to pass custom headers to the HTTP requests made by the SDK. Expected format is `Header1=Value1 Header2="Value 2"`.
|
||||||
|
</ParamField>
|
||||||
</Expandable>
|
</Expandable>
|
||||||
|
|
||||||
</ParamField>
|
</ParamField>
|
||||||
|
|||||||
Reference in New Issue
Block a user