# Info: KCL OCIReg task schemas for provisioning (Provisioning)
# Author: JesusPerezLorenzo 
# Release: 0.0.4
# Date: 11-01-2024

import regex

schema OCIRegStorageDriver:
   name: str
   rootdirectory: str
   region: str
   bucket: str
   secure: bool = True
   regionendpoint: str
   accesskey: str
   secretkey: str
   skipverify: bool = False

schema OCIRegTLS:
   cert: str = "/etc/zot/ssl/fullchain.pem"
   key: str ="/etc/zot/ssl/privkey.pem"

schema OCIRegHtpasswd:
   path: str = "/etc/zot/htpasswd"

schema OCIRegAuth:
   htpasswd?: OCIRegHtpasswd
   failDelay: int = 5

schema OCIRegHTTP:
   address: str = "0.0.0.0"
   port: int = 5000
   realm: str = "zot"
   tls?: OCIRegTLS 
   auth?: OCIRegAuth 
   check:
      address == Undefined or regex.match(address,"^\$.*$") or regex.match(address,"^((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])$"), "'address = ${address}' check value definition (use $vaule or xx.xx.xx.xx)"

schema OCIRegLog:
   level: str = "debug"
   output: str = "/var/log/zot/zot.log"
   audit: str = "/var/log/zot/zot-audit.log"

schema OCIRegRegistry:
   urls: [str]
   onDemand: bool = True
   maxRetries?: int
   retryDelay?: str #  "5m"
   pollInterval?: str # "6h"

schema OCIRegCVE:
   updateInterval: str = "24h"

schema OCIRegExtUI:
   enable: bool = True

schema OCIRegExtSearch:
   enable: bool = True
   cve: OCIRegCVE = { updateInterval = "24h"}

schema OCIRegExtSync:
   enable: bool = True
   registries?: [OCIRegRegistry]

schema OCIRegExtScrub:
   enable: bool = True
   interval: str = "24h"

schema OCIRegStorage:
   rootDirectory: str
   dedupe: bool = True
   gc?: bool
   gcDelay?: str  # "1h"
   gcInterval?: str # "6h"
   remoteCache?: bool = False
   storageDriver?: OCIRegStorageDriver

schema OCIRegExtensions:
   ui?: OCIRegExtUI
   search?: OCIRegExtSearch
   sync?: OCIRegExtSync
   scrub?: OCIRegExtScrub

schema OCIRegConfig:
   distSpecVersion: str = "1.0.1"
   storage: OCIRegStorage
   http?: OCIRegHTTP 
   log?: OCIRegLog
   extensions?: OCIRegExtensions

schema OCIReg:
   version: str
   name: str
   oci_data: str = "/data/zot"
   oci_etc: str = "/etc/zot"
   oci_log: str = "/var/log/zot"
   oci_user: str = "zot"
   oci_user_group: str = "zot"
   oci_cmds: str = "zot zli"  
   oci_memory_high: int = 30
   oci_memory_max: int =32
   oci_bin_path: str = "/usr/local/bin"
   copy_paths: [str] 
   config: OCIRegConfig
