Commit Graph

90 Commits

Author SHA1 Message Date
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
Dietmar Maurer
031efdd022 PVE::JSONSchema - add proxyto_callback property 2017-05-31 07:25:52 +02:00
Dietmar Maurer
752743e717 Revert "JSONSchema.pm: register new standard option pve-replicate"
This reverts commit b6501c2fd9.

No longer required, because we use a separate SectionConfig file to
store replication config.
2017-05-31 07:25:52 +02:00
Dietmar Maurer
b6501c2fd9 JSONSchema.pm: register new standard option pve-replicate 2017-05-08 11:23:39 +02:00
Thomas Lamprecht
c990256896 get_options: handle array and scalar refs on decoding
get_options is for parsing CLI options, here we decode after using
Getopt as we are not sure how well it handles already decoded data.
But as Gettopt can produces references for the parsed data we must
handle them explictily.
So check if we have a ARRAY or SCALAR reference and decode them
respectively.
All other reference types should not get returned from Getopt so
error out on them.

This bug was seen when viewing backup jobs, as we save the job as a
comand entry in /etc/pve/vzdump.cron and parse it then with this
function on reading.
Besides the use there we use it in the RESTHandler Packages
cli_handler sub method, so some CLI tools could be possibly affected
by this.

Fixes: 24197a9f6c
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2017-05-05 12:37:50 +02:00
Dietmar Maurer
24197a9f6c use Encode::Locale to encode parameters read from console(getopt) 2017-05-02 11:14:36 +02:00
Dietmar Maurer
79501b2a58 JSONSchema::check_type: return success (not value) 2017-02-25 09:24:24 +01:00
Wolfgang Bumiller
26bcdf92d5 JSONSchema: adding skiplock option here 2017-02-07 14:54:31 +01:00
Dietmar Maurer
7278cb3c12 JSONSchema: remove formatter option
We do no longer store that information in the method info.
2017-01-18 16:46:54 +01:00
Dietmar Maurer
abc1afd874 schema_get_type_text: do not always expand enums
We try to keep the text short by default.
2016-11-05 16:44:59 +01:00
Dietmar Maurer
25d9bda941 schema_get_type_text: render generic types as <type> 2016-11-05 15:38:29 +01:00
Wolfgang Bumiller
7c1617b01d JSONSchema: named formats in parse_property_string
While our code currently passes the format hashes directly,
some code gets them via the format property of a
configuration description which verifies successfully via
check_format() for named property string formats, so this
should be allowed.
2016-11-02 12:40:56 +01:00
Dominik Csapak
8b6e737a75 fix typo
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2016-10-28 08:50:02 +02:00
Dietmar Maurer
b54ad320a5 fix doc generator (do not convert efidisk0 to efidisk[N])
Also fix spacing in typetext generator.
2016-09-29 12:15:47 +02:00
Dietmar Maurer
05185ea25a schema_get_type_text: always access values as number
Else PVE::RESTHandler::api_dump prints values as strings.
2016-09-05 09:27:50 +02:00
Wolfgang Bumiller
88a490ff71 allow Regexp objects for strings in the schema
The 'pattern' property has type string and format regex, so
it makes sense to allow Regexp objects to be used for it.

While check_type() doesn't know the format, Regexp objects
can be treated like strings anyway, including compared via
'eq' or matched via '=~', so we allow strings to generally
come from a Regexp object.
2016-07-14 10:28:57 +02:00
Wolfgang Bumiller
e43faad9ff Consider /31 and /32 valid subnet masks.
Since we already allow this for container IP addresses it is
reasonable to assume the host might be using such a setup as
well. (You can use an additional route to reach the gateway
and then simply have no "LAN".) Some people seem to want
this...
2016-06-03 11:21:42 +02:00
Wolfgang Bumiller
971353e8ac print_property_string: don't print the default key's name
We had this behavior in the past and didn't mean to change
it.
2016-05-23 06:24:46 +02:00
Dietmar Maurer
32f8e0c75b improve doc generator, introduce verbose_description property 2016-05-19 13:11:26 +02:00
Dietmar Maurer
2289890bad print_property_string: correctly implement skip parameter 2016-05-12 07:25:51 +02:00
Dietmar Maurer
c88c582dec fix keyAlias test 2016-05-11 13:04:01 +02:00
Dietmar Maurer
d8c2b9477c JSONSchema fix property sort order
order: default_key, required options, other
2016-05-11 10:57:06 +02:00
Dietmar Maurer
bf27456b4e remove PodParser.pm, implement keyAlias feature
The keyAlias feature replaces the previous 'group_ feature.
2016-05-11 10:02:34 +02:00
Wolfgang Bumiller
445e8267b2 property strings: introduce key grouping feature
Use case: networks for kvm use a <model>=<macaddr> scheme
where the model represents the network card. The schema
previously could not represent this, so we now introduce a
'group' key which works similar to an alias with the
difference that the data structure also gets an entry named
after the group filled with the name of the key that was
used to fill it.

Usage:
{
    virtio => { group => 'model' },
    e1000 => { group => 'model' },
    model => {
        type => 'string',
        pattern => ... # pattern for mac address
        ...
    }
}

Now the string 'virtio=aa:bb:cc:dd:ee:ff' gets parsed into:
{
    model => 'virtio',
    virtio => 'aa:bb:cc:dd:ee:ff'
}

Error examples:
  With bad value:
    virtio: value does not match the regex pattern
  Missing group:
    model: property is missing and it is not optional

parse_net() however used the 'macaddr' key for the mac
address, which can be achieved by aliasing 'model' to
'macaddr':
{
    virtio => { group => 'model' },
    e1000 => { group => 'model' },
    model => { alias => 'macaddr' },
    macaddr => {
        type => 'string',
        pattern => ... # pattern for mac address
        ...
    }
}

Then the above string will be parsed into:
{
    model => 'virtio',
    macaddr => 'aa:bb:cc:dd:ee:ff'
}

The error output now always shows the 'macaddr' key:
Error examples:
  With bad value:
    macaddr: value does not match the regex pattern
  Missing group:
    macaddr: property is missing and it is not optional

In order to support specifying no mac address we can now set
model.default_key = 1 and macaddr.optional = 1.
That way `virtio,bridge=vmbr2` gets parsed correctly into
just a model with no macaddr. This works because default
keys as aliases have previously not been supported and would
not have been aliased accordingly. This case is now also
taken into account when printing default keys, which is now
skipped if it is also an alias.
2016-04-01 09:00:53 +02:00
Wolfgang Bumiller
166e27c74f cleanup: whitespace and than/then typo 2016-03-23 11:38:26 +01:00