-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
X-Forwarded-For #4380
Merged
Merged
X-Forwarded-For #4380
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
914a77b
WIP: X-Forwarded-For
jefferai 6f450e6
Add beginnings of tests and some minor code updates
jefferai a632325
Reshuffle some test logic and add more tests
jefferai d051c90
Finish tests and parallelize them
jefferai 58c51ec
Address review feedback
jefferai 8bb6a8c
Update config params so we won't clash if we support Forwarded in the…
jefferai 6f9caf2
Address review feedback
jefferai 72b3f40
Fix interface conversion panic
jefferai 92e7cf8
Add website docs
jefferai 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 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 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 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 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 |
---|---|---|
|
@@ -3,10 +3,13 @@ package parseutil | |
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/hashicorp/errwrap" | ||
sockaddr "github.com/hashicorp/go-sockaddr" | ||
"github.com/hashicorp/vault/helper/strutil" | ||
"github.com/mitchellh/mapstructure" | ||
) | ||
|
@@ -118,3 +121,43 @@ func ParseCommaStringSlice(in interface{}) ([]string, error) { | |
} | ||
return strutil.TrimStrings(result), nil | ||
} | ||
|
||
func ParseAddrs(addrs interface{}) ([]*sockaddr.SockAddrMarshaler, error) { | ||
out := make([]*sockaddr.SockAddrMarshaler, 0) | ||
stringAddrs := make([]string, 0) | ||
|
||
switch addrs.(type) { | ||
case string: | ||
stringAddrs = strutil.ParseArbitraryStringSlice(addrs.(string), ",") | ||
if len(stringAddrs) == 0 { | ||
return nil, fmt.Errorf("unable to parse addresses from %v", addrs) | ||
} | ||
|
||
case []string: | ||
stringAddrs = addrs.([]string) | ||
|
||
case []interface{}: | ||
for _, v := range addrs.([]interface{}) { | ||
stringAddr, ok := v.(string) | ||
if !ok { | ||
return nil, fmt.Errorf("error parsing %v as string", v) | ||
} | ||
stringAddrs = append(stringAddrs, stringAddr) | ||
} | ||
|
||
default: | ||
return nil, fmt.Errorf("unknown address input type %T", addrs) | ||
} | ||
|
||
for _, addr := range stringAddrs { | ||
sa, err := sockaddr.NewSockAddr(addr) | ||
if err != nil { | ||
return nil, errwrap.Wrapf("error parsing address: {{err}}", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to mention the problematic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
out = append(out, &sockaddr.SockAddrMarshaler{ | ||
SockAddr: sa, | ||
}) | ||
} | ||
|
||
return out, nil | ||
} |
This file contains 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.
Thoughts on
non_authorized
vsnot_authorized
?not_authorized
can go a little better withnot_present
.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.
Good idea, changed.