Skip to content

Commit

Permalink
THREESCALE-11358 update the apicast config and curl commands for echo…
Browse files Browse the repository at this point in the history
…-api
  • Loading branch information
austincunningham committed Sep 24, 2024
1 parent 5fd93e1 commit 78e68e0
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions doc/policy_tutorial/POLICY_RUN_LOCALLY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ The contents of the configuration file is:
"services": [
{
"proxy": {
"hosts": ["one"],
"api_backend": "https://echo-api.3scale.net:443",
"backend": {
"endpoint": "http://127.0.0.1:8081",
"host": "backend"
},
"policy_chain": [
{
"name": "hello_world",
Expand Down Expand Up @@ -49,8 +55,8 @@ First, configure the hello_world policy inside the policy chain with overwrite a
### Starting the APIcast server
To start the APIcast server with the hello_world_configuration.json file inside the development container, run the following command:

```shell
bash-4.2$ bin/apicast --log-level=debug --dev -c examples/configuration/hello_world_config.json
```bash
$ APICAST_LOG_LEVEL=debug APICAST_WORKERS=1 APICAST_CONFIGURATION_LOADER=lazy APICAST_CONFIGURATION_CACHE=0 THREESCALE_CONFIG_FILE=examples/configuration/hello_world_config.json ./bin/apicast
```

The bin/apicast executable starts the APIcast server. Set log-level to debug which results in a large amount of debug logging.
Expand Down Expand Up @@ -83,7 +89,8 @@ Now you have another interactive bash shell in the APIcast development container
In the container issue the following HTTP request:

```shell
$ curl localhost:8080
# user_key is a required paramerter for the echoapi backend
$ curl -H "Host: one" "http://localhost:8080/?user_key="
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
Expand All @@ -92,6 +99,10 @@ $ curl localhost:8080
</body>
</html>
```
> **NOTE**:
Alernatively, you can get the docker container ip address and curl from your local machine:
> - `APICAST_IP=$(docker inspect apicast_build_0-development-1 | yq e -P '.[0].NetworkSettings.Networks.apicast_build_0_default.IPAddress' -)`
> - `curl -i -H "Host: one" "http://${APICAST_IP}:8080/?user_key=0123456789"`
The response will be a 403 Forbidden. Look at the logs to see what has happened.

Expand Down Expand Up @@ -124,7 +135,7 @@ if secret_header ~= self.secret then
The policy is now executing. You must provide the secret header in the request to pass the validation. Issue the following HTTP request:

```shell
$ curl localhost:8080 -H 'secret: mysecret'
$ curl "http://localhost:8080/?user_key=" -H 'secret: mysecret' -H "Host: one"
GET / HTTP/1.1
X-Real-IP: 127.0.0.1
Host: echo
Expand All @@ -136,14 +147,14 @@ secret: mysecret
You should receive a valid 200 response from the echo server. The rewrite of query parameters to header is not tested, since the request did not contain any query parameters. Issue a new request with a query parameter to see the transformation at work. Issue the following request:

```shell
$ curl localhost:8080?myparam=myvalue -H 'secret: mysecret'
GET /?myparam=myvalue HTTP/1.1
$ curl localhost:8080?user_key=myvalue -H 'secret: mysecret'
GET /?userkey=myvalue HTTP/1.1
X-Real-IP: 127.0.0.1
Host: echo
User-Agent: curl/7.29.0
Accept: */*
secret: mysecret
myparam: myvalue
user_key: myvalue
```

You will see in the response, the header: myparam:myheader

0 comments on commit 78e68e0

Please sign in to comment.