# Info: KCL Proxy task schemas for provisioning (Provisioning)
# Author: JesusPerezLorenzo 
# Release: 0.0.4
# Date: 10-12-2023

import regex 

schema ProxyBackend:
    """
    ProxyBackend
    """
    name: str  = "be_repo"
    ssl_sni: str = "localrepo.cloudnative.zone"
    mode: "http"| "tcp"  = "tcp"
    balance: str  = "roundrobin"
    option: str 
    server_name: str
    server_host_ip: str
    server_port: int 
    server_ops: str = "check fall 3 rise 2"
    check: 
        regex.match(server_host_ip,"^\$.*$") or regex.match(server_host_ip, "^((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])$"), "'server_hosts_ip = ${server_host_ip}' check value definition (use $vaule or xx.xx.xx.xx)"

schema IPBind:
    """
    IP bind settings for https 
    """
    ip: str
    port: int
    check: 
        regex.match(ip,"^\$.*$") or regex.match(ip, "^((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])$"), "'ip = ${ip}' check value definition (use $vaule or xx.xx.xx.xx)"

schema Proxy:
    """
    Proxy settings
    """
    proxy_version: str
    proxy_lib: str = "/var/lib/haproxy"
    proxy_cfg_file: str = "haproxy.cfg"
    run_user: str = "haproxy"
    run_group: str = "haproxy"
    run_user_home: str = "/home/${run_user}"
    https_in_binds: [ IPBind ] 
    https_options: [ str ] = [ "tcplog", "dontlognull" ]
    https_log_format: str = "%H %ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"
    backends: [ ProxyBackend ]
    
