authorize: add request IP to rego evaluation (#3107)

This commit is contained in:
Caleb Doxsey 2022-03-07 15:07:58 -07:00 committed by GitHub
parent 5ac55f68b6
commit a0e64b1cf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 1 deletions

View file

@ -40,16 +40,24 @@ type RequestHTTP struct {
URL string `json:"url"`
Headers map[string]string `json:"headers"`
ClientCertificate string `json:"client_certificate"`
IP string `json:"ip"`
}
// NewRequestHTTP creates a new RequestHTTP.
func NewRequestHTTP(method string, requestURL url.URL, headers map[string]string, rawClientCertificate string) RequestHTTP {
func NewRequestHTTP(
method string,
requestURL url.URL,
headers map[string]string,
rawClientCertificate string,
ip string,
) RequestHTTP {
return RequestHTTP{
Method: method,
Path: requestURL.Path,
URL: requestURL.String(),
Headers: headers,
ClientCertificate: rawClientCertificate,
IP: ip,
}
}

View file

@ -481,6 +481,7 @@ func TestEvaluator(t *testing.T) {
*mustParseURL("https://from.example.com/"),
nil,
testValidCert,
"",
),
})
require.NoError(t, err)
@ -494,6 +495,7 @@ func TestEvaluator(t *testing.T) {
*mustParseURL("https://from.example.com/test"),
nil,
testValidCert,
"",
),
})
require.NoError(t, err)