Commit Graph

58 Commits

Author SHA1 Message Date
Dietmar Maurer
e89a52c30b proxmox-api: further cleanups
- improve docs
- move  ConstRegexPattern to const_regex.rs
2019-11-23 10:42:17 +01:00
Dietmar Maurer
fa83cbde13 proxmox-api/src/lib.rs: hide modules with inlined docs 2019-11-23 09:53:18 +01:00
Dietmar Maurer
edb41c1929 proxmox_api - ApiHandler: rename Async into AsyncHttp
And improve docs.
2019-11-23 08:54:07 +01:00
Dietmar Maurer
e06151b90e api: simplify ApiAsyncHandlerFn 2019-11-22 12:48:36 +01:00
Wolfgang Bumiller
f73ebb7209 api: add format module
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-22 09:28:22 +01:00
Wolfgang Bumiller
a6ce1e432b api: fully qualify types in exported macros
and move const_regex macro into a separate module

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 14:05:23 +01:00
Wolfgang Bumiller
c38d18484d api: move ApiMethod from router to top level
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:43:10 +01:00
Wolfgang Bumiller
c0266a17cd move HttpError to separate error module
the router doesn't actually use it

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:38:57 +01:00
Wolfgang Bumiller
2577effaf7 api: schema: avoid an extra temp string
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:32:42 +01:00
Wolfgang Bumiller
b489c2ceeb import the new api definitions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:30:28 +01:00
Wolfgang Bumiller
068d56ed3d delete the old api macro stuff
to be replaced by a new set of macros for the current api
schema in proxmox-backup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:13:18 +01:00
Wolfgang Bumiller
617e25abba api: make ApiMethodInfo already require Send + Sync
ApiMethodInfo provides static information about a type

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-09-28 10:30:33 +02:00
Wolfgang Bumiller
eb4e28d7bf remove async_await feature gate
then we can build with beta as well

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-09-28 10:10:06 +02:00
Wolfgang Bumiller
ec1448cd29 [clippy] api: mostly noise reduction
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-22 09:45:39 +02:00
Wolfgang Bumiller
5be4143d92 api: allow () type, but panic when used as CLI input
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-16 09:44:25 +02:00
Wolfgang Bumiller
a7b9c8d89e fixup tests for router change
Signed-off-by: Wolfgang Bumiller <w.bumiller@errno.eu>
2019-08-15 20:26:18 +02:00
Wolfgang Bumiller
82f8df963e api: router: return Map on lookup
Instead of a Value, makes it easier to use the parameters
later on.

Signed-off-by: Wolfgang Bumiller <w.bumiller@errno.eu>
2019-08-15 11:02:09 +02:00
Wolfgang Bumiller
d78142302c formatting fixup
add #[rustfmt::skip] to our macros...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-05 09:45:14 +02:00
Wolfgang Bumiller
75e90ebb25 api: support HashSet<String> as api type
This is just an array of strings in json, or a
semicolon-separated string on the command line.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-08-01 11:20:11 +02:00
Wolfgang Bumiller
2a4af329a7 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 15:20:55 +02:00
Wolfgang Bumiller
fab0210287 api, macro: implement 'format' verifier for structs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-30 10:06:32 +02:00
Wolfgang Bumiller
b77733c8ef api: macro: implement minimum/maximum_length checks
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:40:04 +02:00
Wolfgang Bumiller
f1f4c14819 api: verify: rename Verify to TestMinMax
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:30:32 +02:00
Wolfgang Bumiller
20b8c709c6 api: add helper module for verifiers
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-07-29 14:16:05 +02:00
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
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
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
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
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
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
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
099efb2da5 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-18 11:47:26 +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
Wolfgang Bumiller
b1e3a9f0d2 impl ApiType for bool
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-13 14:19:01 +02:00
Wolfgang Bumiller
0d133c4d2c add 'returns' member to method info dump
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 17:26:02 +02:00
Wolfgang Bumiller
a64832aac2 testing a Router::api_dump method
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 17:24:59 +02:00
Wolfgang Bumiller
23d8e1d4e0 api: Parameter::type_info must be an fn
while filling the Parameter fields as &'static we cannot
really make use of the get_type_info() yet because it would
need to be a `const fn` (possible via #!feature(const_fn)),
so for now we store the method pointer until `const_fn` is
stable

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 16:43:24 +02:00
Wolfgang Bumiller
22f4d076e2 api: ApiMethodInfo should be Send + Sync
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
6488a5cddb api: ApiFutures need to be Send
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
7d2c13da95 api: add generic Body parameter
Since we already know we'll want to be using hyper::Body and
bytes::Bytes as API output, we need to allow making routers
for each kind.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00