Skip to content

Commit

Permalink
allowing to change listen address
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Mar 3, 2024
1 parent 3cd474a commit f83a33b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* SQLite connection optimizations
* Database version-upgrade enhancements
* Allow to change listen address

----

Expand Down
5 changes: 5 additions & 0 deletions docs/source/usage/4_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ Some settings are only available as environmental variables.
Port to listen on. Default: :code:`8000`


* **AW_LISTEN**

IP Address to listen on. Default: :code:`127.0.0.1`


* **AW_SSL_CERT**

Optionally provide the path to a ssl certificate to use. Use a (full-)chain if not self-signed.
Expand Down
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _get_defaults_docker(var: str) -> any:
# need to be referenced multiple times without import dependencies
CONFIG_DEFAULTS = {
'port': 8000,
'address': '127.0.0.1',
'run_timeout': 3600,
'path_run': '/tmp/ansible-webui',
'path_play': getcwd(),
Expand Down
1 change: 1 addition & 0 deletions src/ansibleguy-webui/aw/config/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

AW_ENV_VARS = {
'port': ['AW_PORT'],
'address': ['AW_LISTEN', 'AW_LISTEN_ADDRESS'],
'timezone': ['AW_TIMEZONE'],
'secret': ['AW_SECRET'],
'path_run': ['AW_PATH_RUN'],
Expand Down
38 changes: 38 additions & 0 deletions src/ansibleguy-webui/aw/migrations/0003_v0_0_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.0.2 on 2024-03-03 08:45

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("aw", "0002_v0_0_13"),
]

operations = [
migrations.CreateModel(
name="SchemaMetadata",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created", models.DateTimeField(auto_now_add=True)),
("updated", models.DateTimeField(auto_now=True)),
("schema_version", models.CharField(max_length=50)),
(
"schema_version_prev",
models.CharField(
blank=True, default=None, max_length=50, null=True
),
),
],
options={
"abstract": False,
},
),
]
9 changes: 9 additions & 0 deletions src/ansibleguy-webui/aw/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,21 @@ def debug_mode() -> bool:

# WEB BASICS
PORT_WEB = get_aw_env_var_or_default('port')
LISTEN_ADDRESS = get_aw_env_var_or_default('address')
CSRF_TRUSTED_ORIGINS = [
'http://localhost',
f'http://localhost:{PORT_WEB}',
'http://127.0.0.1',
f'http://127.0.0.1:{PORT_WEB}',
]
if LISTEN_ADDRESS != '127.0.0.1':
CSRF_TRUSTED_ORIGINS.extend([
f'http://{LISTEN_ADDRESS}'
f'http://{LISTEN_ADDRESS}:{PORT_WEB}'
f'https://{LISTEN_ADDRESS}'
f'https://{LISTEN_ADDRESS}:{PORT_WEB}'
])

if 'AW_PROXY' in environ:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
USE_X_FORWARDED_HOST = True
Expand Down
3 changes: 2 additions & 1 deletion src/ansibleguy-webui/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from aw.config.environment import get_aw_env_var_or_default

PORT_WEB = get_aw_env_var_or_default('port')
LISTEN_ADDRESS = get_aw_env_var_or_default('address')

# https://docs.gunicorn.org/en/stable/settings.html
OPTIONS_DEV = {
Expand All @@ -20,7 +21,7 @@
'workers': 2,
}
OPTIONS_PROD = {
'bind': f'127.0.0.1:{PORT_WEB}',
'bind': f'{LISTEN_ADDRESS}:{PORT_WEB}',
'reload': False,
'loglevel': 'warning',
}
Expand Down

0 comments on commit f83a33b

Please sign in to comment.