New field 'body' to HTTP GET/GET-by-POST metadata#293
Merged
guicassolato merged 1 commit intomainfrom Jun 3, 2022
Merged
Conversation
thomasmaas
reviewed
Jun 2, 2022
thomasmaas
reviewed
Jun 2, 2022
The new field is an alternative to 'bodyParameters' for defining raw HTTP bodies and ensure proper content encoding of JSON with multiple levels.
E.g., the following config:
```yaml
apiVersion: authorino.kuadrant.io/v1beta1
kind: AuthConfig
metadata:
name: talker-api-protection
spec:
hosts: ["talker-api-authorino.127.0.0.1.nip.io"]
metadata:
- name: echo-api-post-json
http:
endpoint: http://talker-api.default.svc.cluster.local:3000/metadata?encoding=json
method: POST
contentType: application/json
body:
valueFrom:
authJSON: |
\{"original_path":"{context.request.http.headers.x-forwarded-for}","request":\{"key1":\{"key2":\{"key3":"{context.request.http.headers.x-forwarded-for}"\}\}\}\}
```
will send a request:
```
POST /metadata?encoding=json HTTP/1.1
Content-Length: 81
Content-Type: application/json
Host: talker-api.default.svc.cluster.local:3000
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
Version: HTTP/1.1
(…request headers omitted)
{"original_path":"10.244.0.8","request":{"key1":{"key2":{"key3":"10.244.0.8"}}}}
```
A similar config to the above using 'bodyParameters' instead would be:
```yaml
kubectl apply -f -<<EOF
apiVersion: authorino.kuadrant.io/v1beta1
kind: AuthConfig
metadata:
name: talker-api-protection
spec:
hosts: ["talker-api-authorino.127.0.0.1.nip.io"]
metadata:
- name: echo-api-post-json
http:
endpoint: http://talker-api.default.svc.cluster.local:3000/metadata?encoding=json
method: POST
contentType: application/json
bodyParameters:
- name: original_path
valueFrom: { authJSON: context.request.http.headers.x-forwarded-for }
- name: request
valueFrom:
authJSON: |
\{"key1":\{"key2":\{"key3":"{context.request.http.headers.x-forwarded-for}"\}\}\}
```
In the latter however, 'request' is encoded as a JSON string, thus resulting in the following request sent to the metadata service:
```
POST /metadata?encoding=json HTTP/1.1
Content-Length: 92
Content-Type: application/json
Host: talker-api.default.svc.cluster.local:3000
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
Version: HTTP/1.1
(…request headers omitted)
{"original_path":"10.244.0.8","request":"{\"key1\":{\"key2\":{\"key3\":\"10.244.0.8\"}}}\n"}
```
efcc8be to
5c1d98c
Compare
eguzki
approved these changes
Jun 3, 2022
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
It adds a new field
spec.metadata.body.The new field is an alternative to
spec.metadata.bodyParametersfor defining raw HTTP bodies and ensure proper content encoding of JSON with multiple levels.E.g., the following config:
will send a request:
A similar config to the above using
bodyParametersinstead would be:In the latter however, 'request' is encoded as a JSON string, thus resulting in the following request sent to the metadata service:
Closes #271