Commit Graph

116 Commits

Author SHA1 Message Date
Wolfgang Bumiller
f6e089555e schema: verify property strings w/ new serde code
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:19 +02:00
Wolfgang Bumiller
12da5121ff schema: predictable order of errors for tests
Otherwise we'd have to "search" & match the errors...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:17 +02:00
Wolfgang Bumiller
c702638bd8 schema: fixup empty error list handling
Some(<empty list of errors>) does not actually signal an error...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:16 +02:00
Wolfgang Bumiller
aa10025366 schema: guard property string constraint checking
StringSchema::check_constraint runs `parse_property_string` for
property strings, but when we deserialize a `PropertyString` we
immediately follow that up with deserializing it using the schema, so
there's no need to check it beforehand.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:13 +02:00
Wolfgang Bumiller
1a46283b78 schema: get rid of some unsafe code
the borrow tracking won't hurt...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:11 +02:00
Wolfgang Bumiller
73a20c7f5f schema: use schema when serializing property strings
Adds a Schema to the `PropertyString` type and uses it for better
serialization.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:09 +02:00
Wolfgang Bumiller
413d631fa6 schema: convenience accessors to schema subtypes
Adds `const fn <type>(&self) -> Option<&<Type>Schema>` methods to
`Schema`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:19:05 +02:00
Wolfgang Bumiller
5a64f3258a schema: serde based property string de- and serialization
This provides `proxmox_schema::property_string::PropertyString<T>` for
a typed property-string.

To facilitate this, this introduces
`proxmox_schema:🇩🇪:SchemaDeserializer` which is a serde deserializer
for property strings given a schema.

This basically maps to one of `de::SeqAccess` (for array schemas) or
`de::MapAccess` (for object schemas).

Additionally, a `de::NoSchemaDeserializer` is added, since properties
within the strings may have string schemas with no format to it, while
the type we serialize to may ask for an array (a simple "list") via
serde.

The deserializers support borrowing, for which a helper `Cow3` needed
to be added, since property strings support quoting with escape
sequences where an intermediate string would be allocated and with an
intermediate lifetime distinct from the `'de` lifetime.

A `de::verify` module is added which uses serde infrastructure to
validate schemas without first having to deserialize a complete
`serde_json::Value`.

For serialization, `proxmox_schema::ser::PropertyStringSerializer` is
added split into similar parts `ser::SerializeStruct` and
`ser::SerializeSeq` at the top level, and the same prefixed with
`Element` for inside the actual string. This should also properly
quote the contents if required.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-07-13 16:18:58 +02:00
Wolfgang Bumiller
8f8d52f148 update d/copyright files to debian copyright-format 1.0
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-05-23 13:02:39 +02:00
Wolfgang Bumiller
2f5b1f26cc bump proxmox-schema to 1.3.7-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-03-02 16:44:35 +01:00
Wolfgang Bumiller
a8bd8fca15 schema: add basic api types feature
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-03-02 16:14:04 +01:00
Fabian Grünbichler
9c44e9b410 update d/control files
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-01-05 12:17:00 +01:00
Fabian Grünbichler
d0c1958f86 bump proxmox-schema to 1.3.6-1
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-01-05 12:08:58 +01:00
Fabian Grünbichler
ff9aa2012e update nix to 0.26
it's the version currently shipped by bookworm, so let's unify this widely-used
dependency to make bootstrapping easier.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-01-05 12:07:16 +01:00
Fabian Grünbichler
6953154254 update d/control
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-01-05 11:49:03 +01:00
Fabian Grünbichler
8316fd3899 more workspace dependencies
regex was missed in the first pass, and two intra-workspace dev-dependencies as
well.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-12 09:30:30 +01:00
Fabian Grünbichler
e5abc0590e define workspace dependencies in workspace
so that we no longer have to (or forget to) bump the version in multiple places.

notable changes:
- outdated versions have been unified
- proxmox-metrics -> proxmox-async no longer uses explicit empty features
  (proxmox-async doesn't provide any anyway)
- proxmox-subscription -> proxmox-http no longer uses explicit default_features
  = false (proxmox-http has an empty default feature anyway)
- missing path dependencies added (mainly proxmox-rest-server)

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-07 09:48:38 +01:00
Fabian Grünbichler
6c161bd5ab update d/control files
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-07 09:48:38 +01:00
Fabian Grünbichler
4189221470 inherit shared, external dependencies
noteworthy changes:
- proxmox-http had a default_features_false dep on hyper, which is dropped (the
  default feature is empty anyway)
- hyper, libc, nix, tokio and url versions are unified
- missing (cosmetic) bindgen feature on zstd enabled everywhere

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-07 09:48:38 +01:00
Fabian Grünbichler
64959d9ae0 move common metadata to workspace
and switch all crates to 2021 edition as well as a unified "authors" value.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-07 09:48:25 +01:00
Fabian Grünbichler
538578c558 clippy 1.65 fixes
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-05 11:17:37 +01:00
Fabian Grünbichler
50aa62b764 proxmox-schema: bump to 1.3.5
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-01 11:10:01 +01:00
Fabian Grünbichler
30388b7256 schema: update to textwrap 0.16
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-12-01 11:06:41 +01:00
Fabian Grünbichler
28e30719e8 clippy fixes
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-10-11 09:48:04 +02:00
Thomas Lamprecht
52a8eb6ace d/control: tree wide update after switch to weak/namespaced dependencies
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-08-26 12:07:36 +02:00
Fabian Grünbichler
289d297c7d build: use weak and namespaced features
to reduce the creep of optional dependencies being exposed as features.

this requires cargo 0.63 (and debcargo built against at least that
version), but greatly reduces the number of binary packages and provides
generated, while still allowing sensible selection of optional
dependencies via the explicit feature meant for pulling them in.

diff stat for running `make  deb` after this change:
 proxmox-http/debian/control         | 226 ++++--------------------------------
 proxmox-router/debian/control       |  74 +-----------
 proxmox-schema/debian/control       |  53 ++-------
 proxmox-subscription/debian/control |  17 +--
 proxmox-sys/debian/control          |  51 +++-----
 proxmox-tfa/debian/control          | 110 ++----------------
 6 files changed, 72 insertions(+), 459 deletions(-)

the 'dep:' prefix marks something on the RHS inside the features section
as dependency, it's only allowed if the string after it is an optional
dependency an no explicit feature of the same name exists. if all
pointers to the optional dependency in the features section are marked
as such, the optional dependency itself will not be exposed as a feature
(either on the cargo or debian/control level).

the '?' suffix marks dependencies as "weak", which only enables the
optional dependency + its feature(s) if the optional dependency itself
is also enabled. it has no effect on d/control since such a relationship
is not encodable in Debian package relations, but it does affect cargo
dependency resolution and allows skipping the build of unneeded optional
dependencies in some cases.

with no packages/crates depending on the no longer exposed automatically
generated features/packages, so these are safe to remove even though
it's technically a breaking change.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-08-26 10:35:00 +02:00
Fabian Grünbichler
12da49b5ec schema: bump to 1.3.4
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-08-19 12:41:15 +02:00
Fabian Grünbichler
1349f24d49 schema: update to textwrap 0.15
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-08-19 12:26:42 +02:00
Fabian Grünbichler
8cb1a99934 bump proxmox-schema to 1.3.3
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-06-02 14:33:12 +02:00
Wolfgang Bumiller
92069b224d update proxmox-schema to nix 0.24.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-06-02 13:34:09 +02:00
Wolfgang Bumiller
f7da6ee7d4 bump proxmox-schema to 1.3.2
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-06-02 10:14:23 +02:00
Wolfgang Bumiller
d68a755536 schema: drop some commented out lines
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-06-02 10:14:23 +02:00
Wolfgang Bumiller
532140de86 schema: bump api macro dep to 1.0.3
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-05-31 09:43:59 +02:00
Wolfgang Bumiller
9079afc831 schema: clippy fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-05-31 09:42:25 +02:00
Thomas Lamprecht
44735fe5d6 schema: doc comment format/slight-expansion
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-05-05 11:03:21 +02:00
Wolfgang Bumiller
ac50b068de bump proxmox-schema to 1.3.1-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-04-13 08:20:35 +02:00
Wolfgang Bumiller
8291d9ed81 schema: bump api macro to 1.0.2 for the streaming attribute
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-04-13 08:19:00 +02:00
Thomas Lamprecht
3a3dd296cc schema: rustfmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-04-10 12:42:09 +02:00
Wolfgang Bumiller
6221d86c64 schema: add another test case
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-03-09 14:29:53 +01:00
Wolfgang Bumiller
d7283d5aeb schema: don't accept unterminated quoted strings
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-03-09 13:41:09 +01:00
Wolfgang Bumiller
cdf4326e43 schema: factor out string verify fn and improve docs
We'll need to name the type when we add more perl bindings.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-03-04 14:51:16 +01:00
Wolfgang Bumiller
6e4a912bea bump schema to 1.3.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-03-04 09:47:40 +01:00
Wolfgang Bumiller
1e0c04a4ba drop param_bail test
it's not actually testing anything useful

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-03-04 09:44:51 +01:00
Dominik Csapak
7c7e99dca1 proxmox-schema: add convenience macros for ParameterError
with two variants:

(expr, expr) => assumes that the second is an 'Error'
(expr, (tt)+) => passes the tt through anyhow::format_err

also added tests

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2022-03-04 09:43:01 +01:00
Wolfgang Bumiller
ec5ff23d70 make property_string module public
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-03-01 14:57:45 +01:00
Wolfgang Bumiller
fca5218749 schema: add const fn unwrap_*_schema/format methods
'unwrap_' because they will panic and as `const fn` since
panic in const fn is now possible

Note that const evaluation will only be triggered when
actually used in const context, so to ensure *compile time*
checks, use something like this:

    const FOO_SCHEMA: &AllOfSchema =
        SomeType::API_SCHEMA.unwrap_all_of_schema();
    then_use(FOO_SCHEMA);

or to use the list of enum values of an enum string type
with compile time checks:

    const LIST: &'static [EnumEntry] =
        AnEnumStringType::API_SCHEMA
            .unwrap_string_schema()
            .unwrap_format()
            .unwrap_enum_format();
    for values in LIST {
        ...
    }

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-22 09:35:06 +01:00
Wolfgang Bumiller
46580ee3e9 bump proxmox-schema to 1.2.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-17 12:06:15 +01:00
Wolfgang Bumiller
46541feecf support quoted strings in property strings
This allows free form text to exist within property strings,
quoted, like:
    key="A value with \"quotes, also commas",key2=value2
or also:
    "the value for a default_key",key2=value2

And drop ';' as a key=value separator since those are meant
for arrays inside property strings...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-17 09:36:43 +01:00
Wolfgang Bumiller
39eac6280f schema: FromIterator lifetime fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-14 11:20:48 +01:00
Wolfgang Bumiller
c43ac0a64c schema: impl FromIterator for ParameterError
for where we also have Extend impls

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-14 09:46:20 +01:00
Wolfgang Bumiller
706d966c87 schema: bump edition to 2021
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-14 09:45:38 +01:00
Wolfgang Bumiller
ae0ee80f43 bump proxmox-schema to 1.2.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-11 14:08:30 +01:00
Wolfgang Bumiller
8a60e6c8d0 schema: rustfmt
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-11 14:05:05 +01:00
Wolfgang Bumiller
a5ba444a5b schema: ParameterError convenience
for ease of use implement these traits for ParameterError:
    * From<(&str, Error)>
    * From<(String, Error)>
    * Extend<(String, Error)>
    * Extend<(&str, Error)>
    * IntoIterator<Item = (String, Error)>

and add the following methods:
    * fn into_inner(self) -> Vec<(String, Error)>;

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2022-02-11 14:01:57 +01:00
Wolfgang Bumiller
2d9fbc02ab schema: fix deprecation warnings in tests
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-17 08:07:02 +01:00
Wolfgang Bumiller
241dbcff16 schema: bump regex dep to 1.5
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-16 11:16:00 +01:00
Wolfgang Bumiller
e865ac59f3 bump proxmox-schema to 1.1.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-16 11:07:30 +01:00
Wolfgang Bumiller
28c0ede638 schema: deny unsafe_op_in_unsafe_fn
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-16 10:17:41 +01:00
Wolfgang Bumiller
efe492034e schema: make verification functions methods
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-16 10:16:55 +01:00
Wolfgang Bumiller
5f75b37301 schema: formatting
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-12-07 11:53:18 +01:00
Fabian Grünbichler
9c9b5c02b4 clippy: collapse match/if let/..
best viewed with `-w` ;)

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-12-02 09:01:52 +01:00
Fabian Grünbichler
e303ad8605 clippy: misc fixes
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-12-02 09:00:52 +01:00
Fabian Grünbichler
a81b2672d8 clippy: remove unnecessary reference taking
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-12-02 08:58:10 +01:00
Dietmar Maurer
745c4f37dd bump proxmox-schema version to 1.0.1-1
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2021-11-10 09:58:32 +01:00
Fabian Grünbichler
4128c5fdb5 updater: impl UpdaterType for Vec
by replacing the whole Vec.

if we ever want to support adding/removing/modifying elements of a Vec
via the Updater, we'd need to extend it anyway (or use a custom
updater).

Suggested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-09 09:18:08 +01:00
Wolfgang Bumiller
41f3fdfeb9 add proxmox-schema and proxmox-router crates
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2021-10-11 11:39:59 +02:00