Skip to content
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

Add support for filter option for proxies. #111

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst
* `haproxy_listen.{n}.capture.type`: [required]: What to capture (`cookie`, `request header`, `response header`)
* `haproxy_listen.{n}.capture.name`: [required]: Name of the header or cookie to capture
* `haproxy_listen.{n}.capture.length`: [required]: Maximum number of characters to capture and report in the logs
* `haproxy_listen.{n}.filter`: [optional]: Content filters to apply to this section
* `haproxy_listen.{n}.filter.{n}.name`: [required]: The filter to apply
* `haproxy_listen.{n}.filter.{n}.params`: [optional]: Parameters for the filter
* `haproxy_listen.{n}.http_request`: [optional]: Access control for Layer 7 requests
* `haproxy_listen.{n}.http_request.{n}.action`: [required]: The rules action (e.g. `add-header`)
* `haproxy_listen.{n}.http_request.{n}.param`: [optional]: The complete line to be added (e.g. `X-Forwarded-Proto https`)
Expand Down Expand Up @@ -222,6 +225,8 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst
* `haproxy_frontend.{n}.capture.type`: [required]: What to capture (`cookie`, `request header`, `response header`)
* `haproxy_frontend.{n}.capture.name`: [required]: Name of the header or cookie to capture
* `haproxy_frontend.{n}.capture.length`: [required]: Maximum number of characters to capture and report in the logs
* `haproxy_frontend.{n}.filter`: [optional]: Dictionary of content filters to apply to this section
* `haproxy_frontend.{n}.filter.{name}`: [required]: One or more filter `name: param` entries to apply
* `haproxy_frontend.{n}.http_request`: [optional]: Access control for Layer 7 requests
* `haproxy_frontend.{n}.http_request.{n}.action`: [required]: The rules action (e.g. `add-header`)
* `haproxy_frontend.{n}.http_request.{n}.param`: [optional]: The complete line to be added (e.g. `X-Forwarded-Proto https`)
Expand Down Expand Up @@ -344,6 +349,8 @@ Set up (the latest version of) [HAProxy](http://www.haproxy.org/) in Ubuntu syst
* `haproxy_backend.{n}.rspirep.{n}.string`: [required]: The complete line to be added. Any space or known delimiter must be escaped using a backslash (`'\'`) (in version < 1.6)
* `haproxy_backend.{n}.rspirep.{n}.cond`: [optional]: Matching condition built from ACLs
* `haproxy_backend.{n}.cookie`: [optional]: Enable cookie-based persistence in a backend (e.g. `JSESSIONID prefix nocache`)
* `haproxy_backend.{n}.filter`: [optional]: Dictionary of content filters to apply to this section
* `haproxy_backend.{n}.filter.{name}`: [required]: One or more filter `name: param` entries to apply
* `haproxy_backend.{n}.http_request`: [optional]: Access control for Layer 7 requests
* `haproxy_backend.{n}.http_request.{n}.action`: [required]: The rules action (e.g. `add-header`)
* `haproxy_backend.{n}.http_request.{n}.param`: [optional]: The complete line to be added (e.g. `X-Forwarded-Proto https`)
Expand Down
3 changes: 3 additions & 0 deletions templates/etc/haproxy/backend.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ backend {{ backend.name }}
{% if backend.cookie is defined %}
cookie {{ backend.cookie }}
{% endif %}
{% for filter in backend.filter | default([]) %}
filter {{ filter.name }}{{ filter.params is defined | ternary([''] + [filter.params], []) | join(' ') }}
{% endfor %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to use something like this:

{% for param in server.param | default([]) %} {{ param }}{% endfor %}

I find that a bit easier to read.

Copy link
Contributor Author

@mjbnz mjbnz Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in another of my PR's (#113 ), Ansible has trim_blocks enabled, so that format requires the presence of an unexplained blank line after the conditional. the line I used above avoids that.

{% for acl in backend.acl | default([]) %}
acl {{ acl.string }}
{% endfor %}
Expand Down
3 changes: 3 additions & 0 deletions templates/etc/haproxy/frontend.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ frontend {{ frontend.name }}
{% for timeout in frontend.timeout | default([]) %}
timeout {{ timeout.type }} {{ timeout.timeout }}
{% endfor %}
{% for filter in frontend.filter | default([]) %}
filter {{ filter.name }}{{ filter.params is defined | ternary([''] + [filter.params], []) | join(' ') }}
{% endfor %}
{% for acl in frontend.acl | default([]) %}
acl {{ acl.string }}
{% endfor %}
Expand Down
3 changes: 3 additions & 0 deletions templates/etc/haproxy/listen.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ listen {{ listen.name }}
{% for timeout in listen.timeout | default([]) %}
timeout {{ timeout.type }} {{ timeout.timeout }}
{% endfor %}
{% for filter in listen.filter | default([]) %}
filter {{ filter.name }}{{ filter.params is defined | ternary([''] + [filter.params], []) | join(' ') }}
{% endfor %}
{% for acl in listen.acl | default([]) %}
acl {{ acl.string }}
{% endfor %}
Expand Down