Compare commits

...

3 Commits

Author SHA1 Message Date
uumas
8742ccd7f1 v0.5.8 2023-05-09 21:43:04 +03:00
uumas
25a5700b57 indentation 2023-05-09 21:39:50 +03:00
uumas
e4dcc74610 vhost: Add support for http basic auth 2023-05-09 21:39:37 +03:00
5 changed files with 40 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
namespace: uumas namespace: uumas
name: general name: general
version: 0.5.7 version: 0.5.8
readme: README.md readme: README.md
authors: authors:
- uumas - uumas

View File

@@ -5,6 +5,9 @@ web_server: caddy
vhost_locations: [] vhost_locations: []
vhost_headers: {} vhost_headers: {}
vhost_basicauth: false
vhost_basicauth_users: {}
proxy_target_protocol: http proxy_target_protocol: http
proxy_target_host: localhost proxy_target_host: localhost

View File

@@ -33,6 +33,17 @@ argument_specs:
required: false required: false
default: {} default: {}
vhost_basicauth:
description: Whether to require basic auth for the vhost
type: bool
required: false
default: false
vhost_basicauth_users:
description: A dict of basic auth users and their password hashes. Required if vhost_basicauth is true
type: dict
required: false
default: {}
proxy_target_port: proxy_target_port:
description: Port where to proxy requests to. Only applicable if vhost_type is reverse_proxy description: Port where to proxy requests to. Only applicable if vhost_type is reverse_proxy
type: int type: int
@@ -107,6 +118,16 @@ argument_specs:
required: false required: false
default: "{{ vhost_headers }}" default: "{{ vhost_headers }}"
basicauth:
description: Whether to require basic auth for the location
type: bool
required: false
default: "{{ vhost_basicauth }}"
basicauth_users:
description: A dict of basic auth users and their password hashes. Required if basicauth is true
type: dict
default: "{{ vhost_basicauth_users }}"
proxy_target_port: proxy_target_port:
description: Port where to proxy requests to. Only applicable if type is reverse_proxy. description: Port where to proxy requests to. Only applicable if type is reverse_proxy.
type: int type: int

View File

@@ -11,6 +11,13 @@
{% for header in location.headers | dict2items %} {% for header in location.headers | dict2items %}
header {{ header.key }} `{{ header.value }}` header {{ header.key }} `{{ header.value }}`
{% endfor %} {% endfor %}
{% if location.basicauth %}
basicauth {
{% for user in location.basicauth_users | dict2items %}
{{ user.key }} {{ user.value }}
{% endfor %}
}
{% endif %}
{% if location.type == 'reverse_proxy' %} {% if location.type == 'reverse_proxy' %}
reverse_proxy {{ location.proxy_target_protocol }}://{{ location.proxy_target_host }}:{{ location.proxy_target_port }} { reverse_proxy {{ location.proxy_target_protocol }}://{{ location.proxy_target_host }}:{{ location.proxy_target_port }} {
{% if location.proxy_target_protocol == 'https' and location.proxy_target_host == 'localhost' %} {% if location.proxy_target_protocol == 'https' and location.proxy_target_host == 'localhost' %}
@@ -22,11 +29,11 @@
{% elif location.type == 'redirect' %} {% elif location.type == 'redirect' %}
redir {{ location.redirect_target }}{{ '{uri}' if location.redirect_preserve_path }} {{ location.redirect_type }} redir {{ location.redirect_target }}{{ '{uri}' if location.redirect_preserve_path }} {{ location.redirect_type }}
{% elif location.type == 'respond' %} {% elif location.type == 'respond' %}
{% if location.respond_content_type == 'json' %} {% if location.respond_content_type == 'json' %}
respond `{{ location.respond_content | to_json }}` respond `{{ location.respond_content | to_json }}`
{% else %} {% else %}
respond `{{ location.respond_content }}` respond `{{ location.respond_content }}`
{% endif %} {% endif %}
{% endif %} {% endif %}
} }
{% endfor %} {% endfor %}

View File

@@ -26,6 +26,9 @@
'type': item.type | default(vhost_type), 'type': item.type | default(vhost_type),
'headers': item.headers | default(vhost_headers), 'headers': item.headers | default(vhost_headers),
'basicauth': item.basicauth | default(vhost_basicauth),
'basicauth_users': item.basicauth_users | default(vhost_basicauth_users),
'proxy_target_port': item.proxy_target_port | default(proxy_target_port if vhost_type == 'reverse_proxy' else ''), 'proxy_target_port': item.proxy_target_port | default(proxy_target_port if vhost_type == 'reverse_proxy' else ''),
'proxy_target_host': item.proxy_target_host | default(proxy_target_host), 'proxy_target_host': item.proxy_target_host | default(proxy_target_host),
'proxy_target_protocol': item.proxy_target_protocol | default(proxy_target_protocol), 'proxy_target_protocol': item.proxy_target_protocol | default(proxy_target_protocol),