Commit Graph

3028 Commits

Author SHA1 Message Date
Wolfgang Bumiller
fe46b11152 add an api-test module
Run with:
cargo run -p api-test -- SomeDirectory/

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 15:54:52 +02:00
Wolfgang Bumiller
11b09e578c router: parse an optional visibility
The 'pub' in `pub static ROUTER: ...`

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 15:31:19 +02:00
Wolfgang Bumiller
841799d882 fixup add missing question mark
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +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
1c1c8530c5 formatting cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
7db28deaff macro: body type support for router and api macros
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
10451f65eb rewrite parse_object
This should support arbitrary expresion, so gobble up
elements up to the next comma and then run it through
syn::parse2.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
1791c089b6 macro: need to allow specifying the body type now
TODO:
  - change parse_object to use Punctuated for the fields to
    support longer value types (so we can use actual types
    as fields)
  - allow adding a body type to methods
  - allow adding a body type to routers explicitly

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
ff2767129f rename reload_timezone -> reload-timezone
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
b82b14d947 macro: add wildcard matching to router macro
router!{
    /path/{parameter}*: {
        methods...
    }
}

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
3f7e4c0eda router: add remaining missing ::proxmox::api:: prefixes
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
2b577c9c17 cleanup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
1993460d4a allow integer literals as subdirectories
eg: /api/2/ should be legal

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
f3e2e672be use 'quote' in router macro
get rid of a lot of unreadable TokenTree entries

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
7155689724 fix missing proxmox_api -> proxmox::api replacement
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
cd23e0956a macro: switch to using proxmox::api
and fixup a `bail!` -> `::failure::bail!`

Signed-off-by: Wolfgang Bumiller <wry.git@bumiller.com>
2019-06-12 09:48:30 +02:00
Wolfgang Bumiller
024930f63c cargo fmt --all
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-12 09:48:30 +02:00
Dietmar Maurer
71f2d48c2e start proxmox-sys module 2019-06-07 18:03:07 +02:00
Wolfgang Bumiller
a99f7ec987 tree-wide: use 'dyn' for all trait objects
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-07 13:13:48 +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
b5c05fc85c import proxmox-api-macro crate
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 15:25:47 +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
Wolfgang Bumiller
2e6520a987 initial import, starting with vec & io helpers
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-06-06 14:00:25 +02:00
Dietmar Maurer
e8a799cf06 src/server/rest.rs: correctly verify json parameters 2019-05-24 09:10:59 +02:00
Dietmar Maurer
4dd886d9a7 src/server/rest.rs: improve error handling 2019-05-23 08:15:32 +02:00
Dietmar Maurer
27c2183ef4 src/server/rest.rs: do not log 1xx status codes as errors 2019-05-14 06:23:22 +02:00
Dietmar Maurer
3bbbece6a2 handle_async_api_request: put rpcenv into a Box
So that we can pass rpcenv into futures.
2019-05-09 18:01:24 +02:00
Dietmar Maurer
d5901112de src/server/formatter.rs: further cleanups and renaming ... 2019-05-09 13:28:26 +02:00
Dietmar Maurer
5b91995837 src/server/formatter.rs: rename format_result to format_data
To avoid confusions with Rust Result type.
2019-05-09 13:15:15 +02:00
Dietmar Maurer
1b61b80482 src/api2/admin/datastore/backup.rs: implement upload chunk 2019-05-09 13:06:09 +02:00
Dietmar Maurer
66f849d272 rc/api2/admin/datastore/h2upload.rs: implement BackupEnvironment
To pass arbitrary information/state to api methods.
2019-05-08 11:26:54 +02:00
Dietmar Maurer
010e7b80a8 src/server/rest.rs: use generics to pass RpcEnvironment 2019-05-08 11:09:01 +02:00
Dietmar Maurer
19b33e55af src/server/rest.rs: make handle_(a)sync_api_request public 2019-05-07 11:23:52 +02:00
Dietmar Maurer
16b5c3c80b RestEnvironment: derive Clone 2019-05-07 11:09:18 +02:00
Dietmar Maurer
e53d4dadaa move normalize_path to tools::normalize_uri_path 2019-05-07 09:44:34 +02:00
Dietmar Maurer
83f663b7a3 src/server/state.rs: use new BroadcastData helper 2019-04-30 10:21:48 +02:00
Wolfgang Bumiller
88aaa1841a use double-fork for reload
To ensure the new process' parent is pid 1, so systemd won't
complain about supervising a process it does not own.

Fixes the following log spam on reloads:
Apr 25 10:50:54 deb-dev systemd[1]: proxmox-backup.service: Supervising process 1625 which is not our child. We'll most likely not notice when it exits.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-04-25 11:02:12 +00:00
Wolfgang Bumiller
30150eef0f use service Type=notify
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-04-25 11:01:33 +00:00
Wolfgang Bumiller
efd898a71c tools/daemon: add sd_notify wrapper
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-04-25 11:01:28 +00:00
Wolfgang Bumiller
e6bdfe0674 api_schema: allow generic api handler functions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-04-16 11:22:23 +02:00
Dietmar Maurer
3e4290e956 src/server/command_socket.rs: check control socket permissions 2019-04-11 10:51:59 +02:00
Wolfgang Bumiller
04f7276b1a tools/daemon: dup the TcpListener file descriptor
Now that we let hyper shutdown gracefully we need an owned
version of the listening socket to prevent it from closing
before running the reload preparations.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-04-10 15:20:10 +02:00