Commit Graph

2953 Commits

Author SHA1 Message Date
Wolfgang Bumiller
50eadf23fb macro: support Option in deserialization
When deserializing we currently expect all fields to be
available, but we actually want Option types to be truly
optional...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:50:23 +02:00
Wolfgang Bumiller
ce5fa31721 formatting cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:30:48 +02:00
Wolfgang Bumiller
061cc5b525 implement accessors for types with defaults
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:09:15 +02:00
Wolfgang Bumiller
7cbc6d0962 api: add a meta module to help with macro impls
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 14:08:55 +02:00
Wolfgang Bumiller
cb2c260f87 default to not serializing None options
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 13:22:18 +02:00
Wolfgang Bumiller
d9f57ed107 cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 11:08:38 +02:00
Wolfgang Bumiller
ec1ad87193 macro: replace named struct handler
We now derive Serialize and Deserialize automatically.
This way we'll be able to add verifiers right into the
structs, support our 'rename' functionality, and our
'default' handling etc. which needs to be compatible with
what we have in perl.
Ideally this will also give us the option to mark structs as
being perl-compatible "property strings"
(PVE::JSONSchema::parse_property_string()) and automatically
derive FromStr for structs on demand.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 11:04:55 +02:00
Wolfgang Bumiller
0a8a9cdb5b macro: error handling
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 10:04:38 +02:00
Wolfgang Bumiller
bb62dde9b0 macro: common defs: add default, and sort
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 10:01:59 +02:00
Wolfgang Bumiller
bb673ec0db macro: improved error output
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-19 09:58:07 +02:00
Wolfgang Bumiller
183125b1cd macro: named struct: allow short form for fields
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 15:05:26 +02:00
Wolfgang Bumiller
c54afe1be4 macro: add spans to more errors
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:59:09 +02:00
Wolfgang Bumiller
f340968773 macro: ability to rename enum variants via an attribute
In PVE we have multiple different enum types: hyphenated,
all-caps, underscores.

By default our api-macro enums will convert CamelCase to
underscores, so we need a way to represent the rest:

enum AnEnum {
	CaseOne, // becomes "case_one",
	#[api(rename = "case-two")]
	CaseTwo, // "case-two",
	#[api(rename = "CASE_THREE")]
	CaseThree,
}

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:52:25 +02:00
Wolfgang Bumiller
4b3333aa5c macro: cleanup error handling, remove error module
syn::Error already covers this

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-18 14:41:27 +02:00
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
Dietmar Maurer
fd40d69ae0 src/server/rest.rs: avoid unwrap 2019-07-03 12:00:43 +02:00
Dietmar Maurer
4ca8acb083 src/server/rest.rs: log peer address, use hyper MakeService 2019-07-03 11:54:35 +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
744903f874 daemon: remove last use of tools::read/write
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-01 10:39:13 +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
Dietmar Maurer
206d63a20b file download: avoid unnecessary copy 2019-06-28 07:07:52 +02:00
Dietmar Maurer
319e42552b src/server/h2service.rs: implement generic h2 service 2019-06-26 17:38: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