[mod] role:mas:conf

This commit is contained in:
roydfalk 2024-10-17 20:20:10 +02:00
parent e486e595dc
commit 4e1647fa4b
7 changed files with 93 additions and 20 deletions

View file

@ -16,7 +16,7 @@
"var_mas_authentication_upstream_data_authelia_url_base": "https://authelia.example.org", "var_mas_authentication_upstream_data_authelia_url_base": "https://authelia.example.org",
"var_mas_authentication_upstream_data_authelia_auth_method": "client_secret_post", "var_mas_authentication_upstream_data_authelia_auth_method": "client_secret_post",
"var_mas_authentication_upstream_data_authelia_scope": "openid profile email", "var_mas_authentication_upstream_data_authelia_scope": "openid profile email",
"var_mas_authentication_upstream_data_authelia_name": "authelia", "var_mas_authentication_upstream_data_authelia_id": "01JADRQ54Y0KCQS0AEJQ4YTY36",
"var_mas_authentication_upstream_data_authelia_client_id": "mas", "var_mas_authentication_upstream_data_authelia_client_id": "mas",
"var_mas_authentication_upstream_data_authelia_client_secret": "REPLACE_ME" "var_mas_authentication_upstream_data_authelia_client_secret": "REPLACE_ME"
} }

View file

@ -65,20 +65,12 @@ def main():
## args ## args
argument_parser = _argparse.ArgumentParser() argument_parser = _argparse.ArgumentParser()
argument_parser.add_argument( argument_parser.add_argument(
"-b", "-s",
"--base-file-path", "--source-directory",
type = str, type = str,
dest = "base_file_path", dest = "source_directory",
default = "/opt/mas/conf.d/base.json", default = "/opt/mas/conf.d",
metavar = "<base-file-path>", metavar = "<source-directory>",
)
argument_parser.add_argument(
"-c",
"--clients-directory-path",
type = str,
dest = "clients_directory_path",
default = "/opt/mas/conf.d/clients",
metavar = "<clients-directory-path>",
) )
argument_parser.add_argument( argument_parser.add_argument(
"-f", "-f",
@ -105,7 +97,25 @@ def main():
if True: if True:
data = dict_merge( data = dict_merge(
data, data,
_json.loads(file_read(args.base_file_path)) _yaml.loads(file_read(_os.path.join(args.source_directory, "base.yaml")))
)
### database
if True:
data = dict_merge(
data,
_json.loads(file_read(_os.path.join(args.source_directory, "database.json")))
)
### matrix
if True:
data = dict_merge(
data,
_json.loads(file_read(_os.path.join(args.source_directory, "matrix.json")))
)
### upstream
if True:
data = dict_merge(
data,
_json.loads(file_read(_os.path.join(args.source_directory, "upstream.json")))
) )
### clients ### clients
if True: if True:
@ -114,8 +124,8 @@ def main():
{ {
"clients": list( "clients": list(
map( map(
lambda name: _json.loads(file_read(_os.path.join(args.clients_directory_path, name))), lambda name: _json.loads(file_read(_os.path.join(args.source_directory, "clients", name))),
_os.listdir(args.clients_directory_path) _os.listdir(_os.path.join(args.source_directory, "clients"))
) )
), ),
} }

View file

@ -0,0 +1,9 @@
{
"database": {
"host": "{{var_mas_database_host}}",
"port": {{var_mas_database_port | string}},
"username": "{{var_mas_database_username}}",
"password": "{{var_mas_database_password}}",
"database": "{{var_mas_database_schema}}"
}
}

View file

@ -66,9 +66,36 @@
"name": "configuration | base", "name": "configuration | base",
"become": true, "become": true,
"become_user": "{{var_mas_user}}", "become_user": "{{var_mas_user}}",
"ansible.builtin.command": {
"cmd": "./mas-cli config generate > {{var_mas_directory}}/conf.d/base.yaml",
"chdir": "{{var_mas_directory}}"
}
},
{
"name": "configuration | database",
"become": true,
"become_user": "{{var_mas_user}}",
"ansible.builtin.template": { "ansible.builtin.template": {
"src": "config-base.json.j2", "src": "config-database.json.j2",
"dest": "{{var_mas_directory}}/conf.d/base.json" "dest": "{{var_mas_directory}}/conf.d/database.json"
}
},
{
"name": "configuration | matrix",
"become": true,
"become_user": "{{var_mas_user}}",
"ansible.builtin.template": {
"src": "config-matrix.json.j2",
"dest": "{{var_mas_directory}}/conf.d/matrix.json"
}
},
{
"name": "configuration | upstream",
"become": true,
"become_user": "{{var_mas_user}}",
"ansible.builtin.template": {
"src": "config-upstream.json.j2",
"dest": "{{var_mas_directory}}/conf.d/upstream.json"
} }
}, },
{ {

View file

@ -94,7 +94,7 @@
"upstream_oauth2": { "upstream_oauth2": {
"providers": [ "providers": [
{ {
"id": "{{var_mas_authentication_upstream_data_authelia_name}}", "id": "{{var_mas_authentication_upstream_data_authelia_id}}",
"issuer": "{{var_mas_authentication_upstream_data_authelia_url_base}}", "issuer": "{{var_mas_authentication_upstream_data_authelia_url_base}}",
"authorization_endpoint": "{{var_mas_authentication_upstream_data_authelia_url_base}}/api/oidc/authorization", "authorization_endpoint": "{{var_mas_authentication_upstream_data_authelia_url_base}}/api/oidc/authorization",
"token_endpoint": "{{var_mas_authentication_upstream_data_authelia_url_base}}/api/oidc/token", "token_endpoint": "{{var_mas_authentication_upstream_data_authelia_url_base}}/api/oidc/token",

View file

@ -0,0 +1,7 @@
{
"matrix": {
"homeserver": "{{var_mas_matrix_server}}",
"secret": "{{var_mas_matrix_secret}}",
"endpoint": "{{var_mas_matrix_endpoint}}"
}
}

View file

@ -0,0 +1,20 @@
{
{% if var_mas_authentication_upstream_kind == 'none' %}
{% endif %}
{% if var_mas_authentication_upstream_kind == 'authelia' %}
"upstream_oauth2": {
"providers": [
{
"id": "{{var_mas_authentication_upstream_data_authelia_id}}",
"issuer": "{{var_mas_authentication_upstream_data_authelia_url_base}}",
"authorization_endpoint": "{{var_mas_authentication_upstream_data_authelia_url_base}}/api/oidc/authorization",
"token_endpoint": "{{var_mas_authentication_upstream_data_authelia_url_base}}/api/oidc/token",
"token_endpoint_auth_method": "{{var_mas_authentication_upstream_data_authelia_auth_method}}",
"scope": "{{var_mas_authentication_upstream_data_authelia_scope}}",
"client_id": "{{var_mas_authentication_upstream_data_authelia_client_id}}",
"client_secret": "{{var_mas_authentication_upstream_data_authelia_client_secret}}"
}
]
}
{% endif %}
}