Commit Graph

886 Commits

Author SHA1 Message Date
Wolfgang Bumiller
09eaef022f formatting cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 13:58:26 +02:00
Wolfgang Bumiller
43d69cb1aa macro: more error handling improvements
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 13:57:51 +02:00
Wolfgang Bumiller
9c9413ae56 macro: add types.rs, preserve Span for Expressions
Move the Name type into types.rs and make it hashable.
Expression::Object not contains an Object where the
hashmap's key is a Name and therefore preserves the Span of
all the keys for better error messages.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 13:54:52 +02:00
Wolfgang Bumiller
4803bfcb59 macro: add TypeInfo for enum types
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:26:57 +02:00
Wolfgang Bumiller
7510f3179c macro: more absolute paths
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:26:49 +02:00
Wolfgang Bumiller
a034fe3335 cleanup/remove old code
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:15:21 +02:00
Wolfgang Bumiller
7f704d12df macro: started basic enum support
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 11:14:58 +02:00
Wolfgang Bumiller
624afe28a4 prepare to parse enums
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:51:16 +02:00
Wolfgang Bumiller
da40267188 api-server, tools: formatting cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:47:56 +02:00
Wolfgang Bumiller
9654d1feeb macro: add spanned format_err equivalent
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:47:41 +02:00
Wolfgang Bumiller
145abf62a5 macro: helpers for error handling
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 10:30:40 +02:00
Wolfgang Bumiller
a1c8b00f17 example for better error messages
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 16:49:19 +02:00
Wolfgang Bumiller
18d6fc28b4 api: export derive_parse_cli_from_str
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 16:19:45 +02:00
Wolfgang Bumiller
bfbba4e605 tests: use an async block instead of an async closure
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 16:13:36 +02:00
Wolfgang Bumiller
23e4a1ee3f update api server to hyper git master
This is now an example requiring no future-compat anymore.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 12:12:23 +02:00
Wolfgang Bumiller
3f8feff618 tools: actually add raw module
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-17 12:12:08 +02:00
Wolfgang Bumiller
404256a646 tools: add raw::Fd
to replace proxmox_backup's tools::Fd

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-02 15:47:37 +02:00
Wolfgang Bumiller
7efc037717 make valgrind opt-in, not opt-out
otherwise this crate cannot be compiled without nightly as
valgrind_request requires feature(asm)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-02 15:23:32 +02:00
Wolfgang Bumiller
3111d615b8 tools: move vec::ops::* to vec::ByteVecExt
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-01 11:00:29 +02:00
Wolfgang Bumiller
e290d78840 remove deprecated tools::io::ops reexport
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-01 10:56:27 +02:00
Wolfgang Bumiller
3310c5e05d tools: add io::WriteExt
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-01 10:25:15 +02:00
Wolfgang Bumiller
9e7dfce827 tools: change tools::io::ops::*:
We'll stick to existing naming conventions and provide:
    tools::io::{ReadExt, WriteExt}

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-01 09:55:08 +02:00
Wolfgang Bumiller
205a9fc2aa api: split ApiHandler out of ApiMethodInfo
The method info part is not generic after all.
(Makes it easier to test different representations of
ApiHandler without having to adapt all the other methods as
well.)

Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-07-01 09:48:33 +02:00
Wolfgang Bumiller
8a2d7a43e0 macro: cleanup: rename parse_object2 to parse_object
The old parse_object function is gone now.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-26 15:08:20 +02:00
Wolfgang Bumiller
916f9d945f api: WIP: don't depend on a specific Body type
For a T which is not directly a Body or Response<Body> type
    #[api]
    fn foo() -> T;
should not require a specific Body type.

Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-23 11:41:27 +02:00
Wolfgang Bumiller
c8e11115d2 api: replace handler() with call()
An `fn` type can be more annoying to produce in some generic
cases, and we haven't really needed it yet.

Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-23 11:19:49 +02:00
Wolfgang Bumiller
b4378755f0 api-macro: remove old comment
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-23 11:10:32 +02:00
Wolfgang Bumiller
bd79dd8f02 api: make method body an associated type
This way we do not need to carry the body type into the CLI
router and can instead just require the body to be
Into<Bytes>.

This also makes more sense, because previously a method
could in theory implement multiple ApiMethodInfo types with
different bodies which seems pointless.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-19 15:16:40 +02:00
Wolfgang Bumiller
dbcadda6b2 tools: add doc tests for bin_to_hex, hex_to_bin
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-19 14:14:54 +02:00
Wolfgang Bumiller
80343b1141 add make apitest
runs the api test server

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 17:53:43 +02:00
Wolfgang Bumiller
35a60f765e add helper Makefile
make -> make check
make check -> cargo test
make fmt -> cargo fmt --all
make checkfmt -> cargo fmt --all -- --check
...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 17:49:41 +02:00
Wolfgang Bumiller
a202f3ce99 test update
use the 'newboth' command as well

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 13:14:33 +02:00
Wolfgang Bumiller
e085107119 api: fix Option<> types, implement bools, add tests
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 12:45:19 +02:00
Wolfgang Bumiller
4b2f3d3284 tools: add doc-test for bytes_as_base64
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 12:13:12 +02:00
Wolfgang Bumiller
be6d9fb6ab tools: make date_time_as_rfc3339 work for all TimeZones
and add a doc-test passing `cargo test`
(and formatting fixup)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 12:11:23 +02:00
Wolfgang Bumiller
099efb2da5 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 11:47:26 +02:00
Dietmar Maurer
d966061f54 src/serde.rs: add serde helpers 2019-06-18 10:23:06 +02:00
Wolfgang Bumiller
adb425aeb2 api: set missing description of Option types
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 15:06:18 +02:00
Wolfgang Bumiller
85a29246d5 cli: fix options with arguments, add tests
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 15:06:06 +02:00
Wolfgang Bumiller
a5af6eedf7 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 12:32:42 +02:00
Wolfgang Bumiller
c48e17fe26 macro: add cli property and remove specialization
Drop #!feature(specialization) in favor of having a `cli`
property for types to decide whether they are CLI
compatible.

The unconstrained_type! macro now has both ParseCli and
ParseCliFromStr in view, and requires one of the two to be
implemented for a type. This means that if a type implements
FromStr, it should "just work".

For types created without the help of the #[api] macro,
there's a shortcut to exclude a type from the CLI via
the no_cli_type!{typename} macro.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 12:31:29 +02:00
Wolfgang Bumiller
ed3b7de2fd first succesful CLI test
Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-17 12:31:29 +02:00
Wolfgang Bumiller
691af5cade add the ParseCli trait
In order to get parameters from the command line into the
API we need to get them into a json value, so that we can
pass it down the handler which deserializes them into their
real type and runs verifications.
For this we need to define how the type is going to be
converted into a json Value. We cannot simply use
Deserialize as that would for instance require quotes
around strings. So instead, we have a ParseCli trait, which
is a nop (direct serde_json::Value::String()) for string
types, and uses .parse() (the std::str::FromStr trait) for
everything else.

Currently this uses a `default fn` as an example of the
specialization feature, but I'll probably remove this and
use yet another mass-impl macro since there isn't much
activity on that feature's issue tracker. (The issue itself
seems to be outdated ...

Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-17 12:31:29 +02:00
Wolfgang Bumiller
dc3b88f50c start command resolution
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 12:31:29 +02:00
Wolfgang Bumiller
3182df96c0 api: started CLI layout
The CLI part itself needs much less info now as we'll take
as much as we can from the api methods themselves. Note that
we may still want to be able to add extra info to a cli
command in particular, for instance, for the completion
callbacks. For now this is all part of the method itself.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-17 12:31:29 +02:00
Dietmar Maurer
64d9e81c76 src/lib.rs: add hex_to_bin and bin_to_hex 2019-06-17 10:59:59 +02:00
Dietmar Maurer
f2716a0d26 add hex_to_digest and digest_to_hex 2019-06-14 11:27:40 +02:00
Dietmar Maurer
d7fbee66e3 proxmox-tools/src/lib.rs: implement offsetof 2019-06-14 09:57:18 +02:00
Wolfgang Bumiller
b243d9664d macro: implement minimum and maximum verification
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-13 14:29:09 +02:00
Wolfgang Bumiller
b1e3a9f0d2 impl ApiType for bool
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-13 14:19:01 +02:00