[pve-devel] applied: Re: [PATCH v2 common 1/5] jsonschema: register 'timezone' format and add verification method

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Jun 30 17:18:45 CEST 2020


On 17.06.20 15:32, Oguz Bektas wrote:
> /usr/share/zoneinfo/zone.tab has the valid list of time zones.
> 
> Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> ---
> 
> v1->v2:
> * don't use array for verifying format
> 
>  src/PVE/JSONSchema.pm | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
> index 84fb694..15a498c 100644
> --- a/src/PVE/JSONSchema.pm
> +++ b/src/PVE/JSONSchema.pm
> @@ -482,6 +482,25 @@ sub pve_verify_dns_name {
>      return $name;
>  }
>  
> +register_format('timezone', \&pve_verify_timezone);
> +sub pve_verify_timezone {
> +    my ($timezone, $noerr) = @_;
> +
> +    my $zonetab = "/usr/share/zoneinfo/zone.tab";
> +    return $timezone if $timezone eq 'UTC';
> +    open(my $fh, "<", $zonetab);
> +    while(my $line = <$fh>) {
> +	next if $line =~ /^#/;

missing lines with \s+#, fixed in followup

> +	chomp $line;

the chomp isn't required

> +	return $timezone if $timezone eq (split /\t/, $line)[2]; # found

While relatively clear it's IMO nicer to have the "extract the zone" part separately:
my $zone = (split /\t/, $line)[2];
makes it clearer due to the variable name.

> +    }
> +    close $fh;
> +
> +    return undef if $noerr;
> +    die "invalid time zone '$timezone'\n";
> +
> +}
> +
>  # network interface name
>  register_format('pve-iface', \&pve_verify_iface);
>  sub pve_verify_iface {
> 


applied, thanks!




More information about the pve-devel mailing list