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

import regex

schema ETCD:
   version: str
   name: str = "etcd"
   etcd_name: str = "$hostname"
   # how to generate ssl certificates
   ssl_mode: "cfssl"| "openssl" = "openssl"
   # It seems only RSA works (dic-2023)
   ssl_sign: "ECC" | "RSA" = "RSA"
   ca_sign: "ECC" | "RSA" = "RSA"
   ssl_curve: "" | "secp384r1" | "secp256k1" | "secp521r1" | "prime256v1" = "prime256v1"
   long_sign: 2048 | 4096 = 4096
   cipher: "" | "-aes256"  = ""
   ca_sign_days: int = 1460
   sign_days: int = 730
   sign_sha: 256 | 384 | 512 = 256
   sign_pass: str = ""
   etcd_protocol: "https"| "http" = "https"
   source_url: "google" | "github" = "github"
   cluster_name: str
   hostname: str
   cn: str
   c: str
   data_dir: str = "/var/lib/etcd"
   conf_path: str = "/etc/etcd/config.yaml"
   log_level: "warn" | "error" = "warn"
   log_out: "stdout" | "stderr" = "stderr"
   discover_url: str = ""
   cli_ip: str
   cli_port: int = 2379
   peer_ip: str
   peer_port: int = 2380
   cluster_list: str
   token: str
   certs_path: str = "/etc/ssl/etcd"
   prov_path: str = "etcdcerts"
   listen_peers: str = ""
   adv_listen_peers: str = ""
   initial_peers: str = ""
   listen_clients: str = ""
   adv_listen_clients: str = ""
   use_localhost: bool = False
   dns_domain_path: str = ""
   domain_name: str = ""
   discovery_srv: str = ""
   use_dns: bool = True

   #check:
   #   cli_ip == Undefined or regex.match(cli_ip,"^\$.*$") or regex.match(cli_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])$"), "'cp_ip = ${cp_ip}' check value definition (use $vaule or xx.xx.xx.xx)"
   #   peer_ip == Undefined or regex.match(peer_ip,"^\$.*$") or regex.match(peer_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])$"), "'cp_ip = ${cp_ip}' check value definition (use $vaule or xx.xx.xx.xx)"

