Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5174c7
feat: support custom headers
alexanderzobnin Apr 8, 2026
6f9b420
add docs to readme
alexanderzobnin Apr 8, 2026
59399fb
avoid empty header
alexanderzobnin Apr 8, 2026
540a9ea
validate malformed custom headers and improve docs
alexanderzobnin Apr 15, 2026
80b85f9
use sentinel errors for custom header validation
alexanderzobnin Apr 15, 2026
0eba131
Merge branch 'main' into alexz/custom-headers
alexanderzobnin Apr 15, 2026
d9497fb
add integration test verifying custom headers are sent in requests
alexanderzobnin Apr 15, 2026
3d4df97
lint
alexanderzobnin Apr 15, 2026
181be80
chore: bump toolchain to 1.26.2
alexanderzobnin Apr 15, 2026
a1f2afe
fix viper binding for StringArray flags from YAML config
alexanderzobnin Apr 15, 2026
ea77157
lint
alexanderzobnin Apr 15, 2026
1890217
fix linter violations in viper binding
alexanderzobnin Apr 15, 2026
d05304d
fix linter
alexanderzobnin Apr 15, 2026
257d29f
refactor TestCustomHeadersSentInRequest to use a channel for capturin…
alexanderzobnin Apr 16, 2026
80efc8a
use strings.Cut
alexanderzobnin Apr 16, 2026
81a0323
Enhance viperValueToStrings to handle typed slices for strings and in…
alexanderzobnin Apr 16, 2026
f488c7a
softer validation rules
alexanderzobnin Apr 16, 2026
ed898fd
handle arrays the same way as slices
alexanderzobnin Apr 16, 2026
a085d3d
return ErrInvalidHeaderFormat instead
alexanderzobnin Apr 16, 2026
00d4e94
fix linters
alexanderzobnin Apr 17, 2026
853ffed
use viperInstance.GetStringSlice()
alexanderzobnin Apr 21, 2026
b814e5b
allow viper in linter
alexanderzobnin Apr 21, 2026
ed4e7cf
Merge branch 'main' into alexz/custom-headers
alexanderzobnin Apr 23, 2026
89919a0
add env var style test case
alexanderzobnin Apr 24, 2026
2e365cd
fix expected format
alexanderzobnin Apr 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func init() {
rootCmd.PersistentFlags().String("client-id", "", "Client ID. Sent to the Token Issuer during the Client Credentials flow") //nolint:lll
rootCmd.PersistentFlags().String("client-secret", "", "Client Secret. Sent to the Token Issuer during the Client Credentials flow") //nolint:lll
rootCmd.PersistentFlags().StringArray("api-scopes", []string{}, "API Scopes (repeat option for multiple values). Used in the Client Credentials flow") //nolint:lll
rootCmd.PersistentFlags().StringArray("custom-headers", []string{}, "Custom HTTP Headers (repeat option for multiple values)") //nolint:lll
Comment thread
rhamzeh marked this conversation as resolved.
Outdated
rootCmd.PersistentFlags().Bool("debug", false, "Enable debug mode - can print more detailed information for debugging")

_ = rootCmd.Flags().MarkHidden("debug")
Expand Down
2 changes: 2 additions & 0 deletions internal/cmdutils/get-client-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func GetClientConfig(cmd *cobra.Command) fga.ClientConfig {
clientCredentialsClientID, _ := cmd.Flags().GetString("client-id")
clientCredentialsClientSecret, _ := cmd.Flags().GetString("client-secret")
clientCredentialsScopes, _ := cmd.Flags().GetStringArray("api-scopes")
customHeaders, _ := cmd.Flags().GetStringArray("custom-headers")
debug, _ := cmd.Flags().GetBool("debug")

return fga.ClientConfig{
Expand All @@ -56,6 +57,7 @@ func GetClientConfig(cmd *cobra.Command) fga.ClientConfig {
ClientID: clientCredentialsClientID,
ClientSecret: clientCredentialsClientSecret,
APIScopes: clientCredentialsScopes,
CustomHeaders: customHeaders,
Debug: debug,
}
}
17 changes: 16 additions & 1 deletion internal/fga/fga.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ClientConfig struct {
APIScopes []string `json:"api_scopes,omitempty"`
ClientID string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"` //nolint:gosec
CustomHeaders []string `json:"custom_headers,omitempty"`
Debug bool `json:"debug,omitempty"`
}

Expand Down Expand Up @@ -95,6 +96,20 @@ func (c ClientConfig) getClientConfig() *client.ClientConfiguration {
MaxRetry: MaxSdkRetry,
MinWaitInMs: MinSdkWaitInMs,
},
Debug: c.Debug,
Debug: c.Debug,
DefaultHeaders: c.getCustomHeaders(),
}
}

func (c ClientConfig) getCustomHeaders() map[string]string {
headers := map[string]string{}
Comment thread
alexanderzobnin marked this conversation as resolved.
Outdated
for _, header := range c.CustomHeaders {
parts := strings.SplitN(header, ":", 2)
if len(parts) == 2 {
head := strings.TrimSpace(parts[0])
value := strings.TrimSpace(parts[1])
headers[head] = value
Comment thread
alexanderzobnin marked this conversation as resolved.
Outdated
}
Comment thread
alexanderzobnin marked this conversation as resolved.
}
Comment thread
alexanderzobnin marked this conversation as resolved.
Outdated
return headers
}
Loading