-
Notifications
You must be signed in to change notification settings - Fork 46
feat: support custom headers #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexanderzobnin
wants to merge
16
commits into
openfga:main
Choose a base branch
from
grafana:alexz/custom-headers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f5174c7
feat: support custom headers
alexanderzobnin 6f9b420
add docs to readme
alexanderzobnin 59399fb
avoid empty header
alexanderzobnin 540a9ea
validate malformed custom headers and improve docs
alexanderzobnin 80b85f9
use sentinel errors for custom header validation
alexanderzobnin 0eba131
Merge branch 'main' into alexz/custom-headers
alexanderzobnin d9497fb
add integration test verifying custom headers are sent in requests
alexanderzobnin 3d4df97
lint
alexanderzobnin 181be80
chore: bump toolchain to 1.26.2
alexanderzobnin a1f2afe
fix viper binding for StringArray flags from YAML config
alexanderzobnin ea77157
lint
alexanderzobnin 1890217
fix linter violations in viper binding
alexanderzobnin d05304d
fix linter
alexanderzobnin 257d29f
refactor TestCustomHeadersSentInRequest to use a channel for capturin…
alexanderzobnin 80efc8a
use strings.Cut
alexanderzobnin 81a0323
Enhance viperValueToStrings to handle typed slices for strings and in…
alexanderzobnin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [tools] | ||
| go = "1.26.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| Copyright © 2023 OpenFGA | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package cmdutils | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestViperValueToStrings(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testcases := []struct { | ||
| name string | ||
| value any | ||
| expected []string | ||
| }{ | ||
| { | ||
| name: "slice value produces one string per element", | ||
| value: []any{ | ||
| "X-Custom-Header: value1", | ||
| "X-Request-ID: abc123", | ||
| }, | ||
| expected: []string{"X-Custom-Header: value1", "X-Request-ID: abc123"}, | ||
| }, | ||
| { | ||
| name: "single element slice", | ||
| value: []any{"X-Custom-Header: value1"}, | ||
| expected: []string{"X-Custom-Header: value1"}, | ||
| }, | ||
| { | ||
| name: "empty slice", | ||
| value: []any{}, | ||
| expected: []string{}, | ||
| }, | ||
| { | ||
| name: "typed string slice produces one string per element", | ||
| value: []string{"X-Custom-Header: value1", "X-Request-ID: abc123"}, | ||
| expected: []string{"X-Custom-Header: value1", "X-Request-ID: abc123"}, | ||
| }, | ||
| { | ||
| name: "typed int slice produces one string per element", | ||
| value: []int{1, 2, 3}, | ||
| expected: []string{"1", "2", "3"}, | ||
| }, | ||
| { | ||
| name: "scalar string produces single-element slice", | ||
| value: "https://api.fga.example", | ||
| expected: []string{"https://api.fga.example"}, | ||
| }, | ||
| { | ||
| name: "boolean value is stringified", | ||
| value: true, | ||
| expected: []string{"true"}, | ||
| }, | ||
| { | ||
| name: "integer value is stringified", | ||
| value: 42, | ||
| expected: []string{"42"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range testcases { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| result := viperValueToStrings(test.value) | ||
| assert.Equal(t, test.expected, result) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what @rhamzeh asked to do (this was a part of go toolchain bump).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhamzeh should we keep it?