Commit Graph

30 Commits

Author SHA1 Message Date
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
Wolfgang Bumiller
8036941977 router: implement 'rest of the path' wildcard matching
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
60df564f73 api: move router to router.rs
We'll have a separate router for the command line, so the
http router won't live in the root module.

It is still exported at the root level, though, via
proxmox::api::Router.

Also move ApiType into api_type.rs, makes more sense.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
dcfa3ca9a2 allow async api methods to return Response<Bytes>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
3dd6cd3fe0 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-07 12:03:17 +02:00
Wolfgang Bumiller
671a56c545 typo fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 14:47:02 +02:00
Wolfgang Bumiller
5bda38830c Add more documentation
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 14:45:05 +02:00
Wolfgang Bumiller
b873e5e2a5 api: router test file
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 14:07:26 +02:00
Wolfgang Bumiller
fa2ba562ce add proxmox-api crate
This contains the router and will get helpers for
generating documentation, and for parsing command line
parameters for api methods.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 14:06:21 +02:00