Commit Graph

114 Commits

Author SHA1 Message Date
Fabian Ebner
31d4beb47c schema: check format: parse list formats as arrays
Previously, the returned value would be only the last element or undef in case
of an empty list. There's only a handful of callers of check_format() that look
at the return value and AFAICT none of the exisitng ones is for a -list format.
But best to avoid any future surprises.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-05-03 13:05:20 +02:00
Fabian Ebner
91477acefb indentation fix
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-05-03 13:05:20 +02:00
Stefan Reiter
6ab98c4e53 JSONSchema: don't cycle-check 'download' responses
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2021-04-21 17:36:57 +02:00
Stefan Reiter
91fe74a036 fixup: remove double braces
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2021-04-19 11:56:49 +02:00
Fabian Grünbichler
920750982b schema: pull out abstract 'id-pair' verifier
we'll need another one for guest bridge IDs

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-04-16 11:51:27 +02:00
Wolfgang Bumiller
26764d7cc3 get_options: don't set optional positional params to undef
Currently this happened if (and only if) at least one
positional parameter was passed.

We run into this with
  `pmgconfig cert delete <type> [<restart>]`
vs
  `pvenode cert delete [<restart>]`

where in the PVE case the `restart` option was simply
omitted, whereas for PMG due to the existence of `<type>`
the `restart` option was explicitly passedset in the $opts
hash but ended up being `undef`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-03-16 13:15:57 +01:00
Fabian Ebner
ff8d3b1d7a register email-or-username format
To be used for the mailto vzdump parameter.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
2021-02-18 12:49:15 +01:00
Fabian Ebner
4c4bd1047c sendmail: use more complete email regex and shellquote
Shellquote is needed for '~', and while it doesn't help with '-',
there should be no problem, because options are separated from mailto
since commit 216a3f4f13.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
2021-02-18 12:49:12 +01:00
Dominic Jäger
a8f9333441 Make configid regex public
Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
2020-10-29 15:20:40 +01:00
Thomas Lamprecht
3fe29ce6c9 get_options: allow no arguments if all are optional
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-09-07 09:59:07 +02:00
Thomas Lamprecht
804bc6219b get_options: allow optional arguments "arg_params" if no ambiguity
If we run out of passed arguments from the user but still had defined
"arg_params" (those params which went after the command in fixed
order without option -- dashes) we always errored out with "not
enough arguments". But, there are situations where the remaining
arg_params are all marked as optional in the schema, so we do not
need to error out in that case.

A prime (future) use case is "pvesm prune-backups". Currently the
usage is:
> pvesm prune-backups storeid --prune-backups keep-last=1,keep-...

Because the "prune-backups" keep retention property is optional as it
can fallback to the one defined in the storage configuration.
With this patch we can make it an argument and allow the following
two usages:

1. As above, but avoiding the extra ugly --prune-backups
> pvesm prune-backups storeid keep-last=1,keep-...

2. Fallback to storage config:
> pvesm prune-backups storeid

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-08-26 21:21:05 +02:00
Stefan Reiter
d500c0381e JSONSchema: use validator in print_property_string too
Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-07-06 10:40:10 +02:00
Stefan Reiter
70fdc0501b JSONSchema: add format validator support and cleanup check_format
Adds a third, optional parameter to register_format that allows specifying
a function that will be called after parsing and can validate the parsed
data. A validator should die on failed validation, and can also change the
parsed object by returning a modified version of it.

This is useful so one can register a format with its hash, thus allowing
documentation to be generated automatically, while still enforcing certain
validation rules.

The validator only needs to be called in parse_property_string, since
check_format always calls parse_property_string if there is a
possibility of a validator existing at all. parse_property_string should
then be called with named formats for best effect, as only then can
validators be used.

Clean up 'check_format' as well (which pretty much amounts to a rewrite).
No existing functionality is intentionally changed.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2020-07-06 10:40:10 +02:00
Thomas Lamprecht
36b9c07397 follouwp: improve comment detection and refactor slightly
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-06-26 09:55:21 +02:00
Oguz Bektas
e76308e6eb schema: register 'timezone' format and add verification method
/usr/share/zoneinfo/zone.tab has the valid list of time zones.

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-06-26 09:50:26 +02:00
Thomas Lamprecht
79ac628b9e JSONSchema: allow to import parse_property_string
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-05-02 18:42:42 +02:00
Dominik Csapak
6b0c18d4db JSONSchema: extend pve-configid regex by '-'
we use this format for all 'delete' options but we have some options
that have a '-' in the name (e.g. 'sync-defaults-options') that cannot
be deleted if it is not included

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-04-23 07:50:24 +02:00
Thomas Lamprecht
e12df964dc idmap followup: avoid false-negatives through falsy values in collision check
By using "exists" when checking if a hash entry is set, else things
like "0" could get accepted by mistake.

Also cleanup the code a little, like dropping the "PVE::JSONSchema::"
prefix, this is now in that module after all.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-04-02 17:33:47 +02:00
Fabian Grünbichler
18f93ddf63 JSONSchema: add idmap parser and storagepair format
generalized from the start to support extension to bridges or other
entities as well.

this gets us incremental support for the CLI, e.g.:

--targetstorage foo:bar --targetstorage bar:baz --targetstorage foo

creates a mapping of

foo=>bar
bar=>baz

with a default of foo

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-04-01 17:30:49 +02:00
Wolfgang Link
a8117ff3d8 Register acme-plugin-format
Signed-off-by: Wolfgang Link <w.link@proxmox.com>
2020-04-01 11:30:27 +02:00
Wolfgang Link
731950fd1c Reuse id parse code.
The storage_id is the same as the plugin_id.

Signed-off-by: Wolfgang Link <w.link@proxmox.com>
2020-04-01 11:30:27 +02:00
Dominik Csapak
283ac2bae1 add ldap-simple-attr from pmg
we also need it in pve

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-03-09 12:34:06 +01:00
Fabian Grünbichler
4c72ade059 API schema: add 'allowtoken' property
to mark which API methods should be available to clients authenticated using an API token.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-01-27 18:39:26 +01:00
Dominik Csapak
484b6b398b JSONSchema: add pve-tag format
this will be used for vm/ct tag-lists, so that (config) management systems
or similar add additional information that does not reside in the
description

putting it here, since we want to eventually have it also for
nodes,storages,etc.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2019-10-30 08:43:43 +01:00
Wolfgang Bumiller
6e2343254e JSONSchema: add TFA-secret format; support longer secrets
The old format used 16 base32 chars or 40 hex digits. Since they have
a common subset it's hard to distinguish them without the our
previous length constraints, so prefix a 'v2-' of the format to
support arbitrary lengths properly.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-10-29 06:26:55 +01:00
Thomas Lamprecht
9bbc4e174c tree wide trailing whitespace cleanup
generated with:
 # find . -name '*.pm' -exec sed -i 's/\s\+$//' {} \;

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-09-09 16:42:12 +02:00
Thomas Lamprecht
821d408dc4 JSONSchema: sort keys when dumping config for stabillity
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-05-15 14:11:53 +02:00
Dominik Csapak
aad3582eab JSONSchema: add get_netmask_bits and missing netmask
so one can use the mapping from outside the module

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2019-05-08 14:49:45 +00:00
Stoiko Ivanov
34e75688f6 JSONSchema: fix units of bwlimit
the description of bwlimit wrote MiB/s, the use in restore operation is KiB/s

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2019-04-02 10:30:03 +02:00
Thomas Lamprecht
98d5b8cb72 JSONSchema: register 'pve-snapshot-name' here to avoid cyclic dependencies
move it from qemu-server as it was also used in pve-container and
pve-manager (pvesr), while guest-commons AbstractConfig could be a
fit too, just move it here as all depending on this already use
JSONSchema and it just fits here...

Break respective qemu-server version

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-03-21 12:51:16 +01:00
Thomas Lamprecht
4fdf30c439 followup: add verbose_description to new mac-addr standard option
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-03-14 09:49:54 +01:00
Stoiko Ivanov
a750d596c2 JSONSchema: Adapt MAC address format to unicast
MAC-addresses having the LSB of the first octet set, are considered
multicast-addresses (see [0,1]).

the 'mac-addr' format got changed to only permit unicast addresses, which should
work for its current use-case (WOL for nodes).
additionally a default option was registered via register_standard_option to be
used in both PVE::LXC::Config and PVE::QemuServer.

[0] https://lists.linuxcontainers.org/pipermail/lxc-users/2010-August/000783.html
[1] https://en.wikipedia.org/wiki/MAC_address

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2019-03-14 09:41:12 +01:00
Oguz Bektas
4cd6dc0a98 fix #2111: regex match for email addresses
now allows:
* addresses without tld (f.e. user@localhost per bug)
* remove limits for number of subdomains
* allow +, -, ~ in local part
* disallow double dots (.. .a. etc) and dots in the end (abc.@mail.com)

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Acked-by: Dominik Csapak <d.csapak@proxmox.com>
2019-03-01 10:36:50 +01:00
Christian Ebner
14324ea874 JSONSchema: Add format for MAC address verification
Adds a format to verify MAC addresses to JSONSchema.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
2019-01-22 11:11:43 +01:00
Wolfgang Bumiller
31b5a3a7fc JSONSchema: typo fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-09-25 10:38:04 +02:00
Thomas Lamprecht
fb3a1b2985 fix some erro mesage and comment typos
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-09-20 09:31:19 +02:00
Dietmar Maurer
ac6c61bf13 introcude new output format 'yaml' 2018-07-26 12:02:45 +02:00
Dietmar Maurer
cd6591d38b output format options: remove 'plain', add 'json-pretty'
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-07-10 13:52:20 +02:00
Dietmar Maurer
ac15655f45 JSONSchema: register new standard option 'pve-output-format'
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-07-03 13:28:35 +02:00
Dietmar Maurer
03c1e2a061 JSONSchema: define 'renderer' property
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-07-03 13:28:25 +02:00
Dietmar Maurer
b521204225 PVE::JSONSchema::register_renderer - allow to register renderers by name
We want to use those renderer to format CLI output nicely.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-29 14:39:48 +02:00
Dominik Csapak
4842b65105 remove read_password_func from cli handler
we have a param_mapping now, with which we can impement that

e.g. instead of using:

sub read_password {
    # read password
}

we can do:

sub param_mapping {
    my ($name) = @_;

    my $password_map = ['password', sub{
	# read password
    }, '<password', 1];

    my $mapping = {
	'apicall1' => [$password_map],
	'apicall2' => [$password_map],
	...
    };

    return $mapping->{$name};
}

this has the advantage that we can use different subs for different
api calls (e.g. pveum passwd vs pveum ticket)

if a CLIHandler implemenation still has a read_password sub and no
param_mapping, we generate one for them with read_password as the
sub for the standard mapping 'pve-password'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-27 12:37:20 +02:00
Stoiko Ivanov
f8d4eff923 add print_width property to JSONSchema definition
used to define the maximal width of the respective column in the CLI

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-18 11:24:03 +02:00
Dietmar Maurer
ff2bf45fab fix getopt when invoking without arguments 2018-06-07 07:09:59 +02:00
Wolfgang Bumiller
c7171ff272 cli: more generic interactive parameter definition
Instead of hardcoding 'password' as a special case in the
JSONSchema's getopt handling, extend the new parameter
mapping to allow defining a parameters as 'interactive'.
They also take an optional argument on the command line
directly.

This effectively deprecates the password special case which
should be replaced in pct/pveum/... and then dropped in
pve-common.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-03-13 11:04:58 +01:00
Wolfgang Bumiller
2d167ad0d4 schema: add bwlimit standard option and format
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-02-05 09:49:21 +01:00
Wolfgang Bumiller
70ea225069 schema: allow ipv6 prefix lengths up to 128
There's no technical reason for *us* to limit this to 120.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-02-05 09:49:12 +01:00
Thomas Lamprecht
b21cf57546 JSONSchema: add fingerprint-sha256 standard option
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-11 12:20:22 +01:00
Dietmar Maurer
62a8f27b99 JSONSchema.pm - add a 'download' attribute
To mark methods which downloads file content to the client.
2017-11-08 09:42:58 +01:00
Wolfgang Bumiller
1b71e56485 JSONSchema: add parse_boolean helper 2017-08-18 12:37:16 +02:00