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

import regex

schema Webhook:
    name: str = "webhook"
    # https://github.com/adnanh/webhook/release
    webhook_version: str
    # config file for webhook in /etc/webhook
    webhook_conf: str = "hooks.conf"
    # IP to listen
    webhook_ip: str = "$network_private_ip"
    # Port to listen
    webhook_port: int = 9000
    # Path for logs
    webhook_logs_path: str = "/var/log/webhooks.logs"
    # User 
    webhook_user: str = "webhook"
    webhook_group: str = "${webhook_user}"
    webhook_home: str = "/home/${webhook_user}"
    repo_username: str
    # hostname for ssh/config
    repo_hostname: str
    # IMPORTANT: repo_ssh_key keys are copied form local to devops_admin (devadm)
    # Has to be registered in repositiory (giteaa) to be used for git commands 
    # should not have passphrase, use private key name 
    repo_ssh_key: str 
    repo_ssh_port: int  = 2022
    # kloud path to clone repositories
    provisioning_kloud: str
    # default aws profie for env
    aws_profile: str
    check:
        len(repo_hostname) > 0, "Check repo_hostname"
        webhook_ip == Undefined or regex.match(webhook_ip,"^\$.*$") or regex.match(webhook_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])$"), "'webhook_ip = ${webhook_ip}' check value definition (use $vaule or xx.xx.xx.xx)"

