Commit Graph

2871 Commits

Author SHA1 Message Date
Dietmar Maurer
9cb2c97c77 proxmox-rest-server: improve docs
And renames abort_worker_async to abort_worker_nowait (avoid confusion,
because the function itself is not async).
2021-09-30 10:51:41 +02:00
Dietmar Maurer
50c62be82c proxmox-rest-server: cleanup FileLogger docs 2021-09-30 10:51:31 +02:00
Dietmar Maurer
f23aeff910 cleanup: move use clause to top 2021-09-30 08:42:37 +02:00
Dietmar Maurer
2ed2c0334c proxmox-rest-server: allow to catch SIGINT and SIGHUP separately
And make ServerState private.
2021-09-30 08:41:30 +02:00
Dietmar Maurer
93802ec2ef proxmox-rtest-server: make Reloader and Reloadable private 2021-09-30 07:44:19 +02:00
Dietmar Maurer
abfac6738c proxmox-rest-server: improve logging
And rename server_state_init() into catch_shutdown_and_reload_signals().
2021-09-29 14:48:46 +02:00
Dietmar Maurer
5b72478077 proxmox-rest-server: avoid useless call to request_shutdown
Also avoid unsafe code.
2021-09-29 14:37:07 +02:00
Dietmar Maurer
aedc1db9e2 daemon: simlify code (make it easier to use) 2021-09-29 12:04:48 +02:00
Dietmar Maurer
a8c75df695 cleanup: make BoxedStoreFunc private
There is no need to export this type.
2021-09-29 09:55:43 +02:00
Dominik Csapak
15dcfbf162 examples: add example for a simple rest server with a small api
show how to generally start a daemon that serves a rest api + index page

api calls are (prefixed with either /api2/json or /api2/extjs):
/		GET	listing
/ping		GET	returns "pong"
/items		GET	lists existing items
		POST	lets user create new items
/items/{id}	GET	returns the content of a single item
		PUT	updates an item
		DELETE	deletes an item

Contains a small dummy user/authinfo

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-29 09:48:47 +02:00
Dominik Csapak
2ce3e5fb78 rest-server: use hypers AddrIncoming for proxmox-backup-api
this has a 'from_listener' (tokio::net::TcpListener) since hyper 0.14.5 in
the 'tcp' feature (we use 'full', which includes that; since 0.14.13
it is not behind a feature flag anymore).

this makes it possible to create a hyper server without our
'StaticIncoming' wrapper and thus makes it unnecessary.

The only other thing we have to do is to change the Service impl from
tokio::net::TcpStream to hyper::server::conn::AddStream to fulfill the trait
requirements.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-29 09:38:40 +02:00
Dietmar Maurer
5bff2a1d4b add test for property string verification errors 2021-09-29 08:59:28 +02:00
Dietmar Maurer
d62d1e5707 move api schema tests into separate file 2021-09-29 08:25:23 +02:00
Dietmar Maurer
8e1d573844 add tests for schema verification errors 2021-09-29 08:17:53 +02:00
Dietmar Maurer
9ec9d1f9e6 ParameterError: construct XPath like string to identify nested properties 2021-09-28 12:34:08 +02:00
Dietmar Maurer
48ba0a2dd5 ExtJsFormatter: use ParameterError to correctly compute 'errors'
By default, 'errors' is now empty.

Depend on proxmox 0.13.5.
2021-09-28 10:19:55 +02:00
Dietmar Maurer
b5ea4f9bb2 bump proxmox version to 0.13.5-1 2021-09-28 09:52:27 +02:00
Dietmar Maurer
51db0d0f12 ParameterError: record parameter names 2021-09-28 09:52:27 +02:00
Dominik Csapak
5a88aaf074 cli/text_table: calculate correct column width for unicode characters
When printing unicode text, a glyph can take up more (or less) space than
a single column. To handle that, use the 'unicode-width' crate which
calculates the width by the unicode standard.

This makes the text tables correctly aligned when printing unicode
characters (e.g. in a datastore/user/syncjob comment).

'unicode-width' is used itself in the rust compiler to format errors
(see e.g. the Cargo.toml in /compiler/rustc_errors of the rust git)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2021-09-28 08:05:28 +02:00
Dietmar Maurer
962553d252 proxmox-rest-server: cleanup formatter, improve docs
Use trait for OutputFormatter. This is functionally equivalent,
but more rust-like...
2021-09-28 07:45:50 +02:00
Dietmar Maurer
6e50c7aac3 WorkerTaskContext: add shutdown_requested() and fail_on_shutdown() 2021-09-24 12:04:31 +02:00
Dietmar Maurer
42dae7e1fb cleanup WorkerTaskContext 2021-09-24 11:39:30 +02:00
Dominik Csapak
5a37cfd4c0 upid: remove arbitrary 128 max length for UPID
we can easily go beyond that when having long datastore/remote names
also because we do 'systemd-encode' them, which means that every special
char takes up 4 bytes (e.g. '-' => '\x2d')

while we could just increase the lenght to say 256 or 512, i do not
really see the benefit to limit this at all, since users cannot create
tasks with arbitrary names, and all other fields are generated from
other valid types (username, datastore, remote, etc.)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2021-09-24 11:08:59 +02:00
Dietmar Maurer
020c8e6980 cleanup worker task logging
In order to avoid name conflicts with WorkerTaskContext

- renamed WorkerTask::log to WorkerTask::log_message

Note: Methods have different fuction signatures

Also renamed WorkerTask::warn to WorkerTask::log_warning for
consistency reasons.

Use the task_log!() and task_warn!() macros more often.
2021-09-24 10:34:11 +02:00
Dietmar Maurer
7a4bb6000e rename TaskState to WorkerTaskContext 2021-09-24 10:33:49 +02:00
Dietmar Maurer
85ec987a48 move src/server/h2service.rs into proxmox-rest-server crate 2021-09-24 10:28:17 +02:00
Dietmar Maurer
e8c124fe1b move worker_task.rs into proxmox-rest-server crate
Also moved pbs-datastore/src/task.rs to pbs-tools, which now depends on 'log'.
2021-09-24 10:28:17 +02:00
Dietmar Maurer
3cec879463 bump proxmox version to 0.13.4-1 2021-09-23 12:06:48 +02:00
Dietmar Maurer
ed9bdab576 add UPID api type 2021-09-23 12:04:15 +02:00
Dietmar Maurer
fc2253b3e8 add systemd escape_unit and unescape_unit 2021-09-23 12:04:15 +02:00
Dietmar Maurer
eb1f23c588 use UPID and systemd helpers from proxmox 0.13.4 2021-09-23 12:01:43 +02:00
Fabian Grünbichler
0999494564 schema: add extra info to array parameters
it's not immediately obvious that they can be specified more than once
otherwise.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-22 07:58:52 +02:00
Fabian Grünbichler
5f5a5194de schema: print item type-text instead of <array>
this is only used for CLI synopsis/usage strings, the API viewer already
prints the full type text in a correct format. the old variant was also
rather misleading, since on the CLI we don't pass in an array, but each
item as its own parameter.

noticed this while working on the pull/sync filtering series, but it
affects quite a lot of stuff, among other things the Updater and
Deleteable CLI, e.g. from `man proxmox-backup-manager`:

>       --delete <array>
>                     List of properties to delete.

vs.

>       --delete disable|validation-delay
>                     List of properties to delete.

But some of them might only have <string> as the item type text,
which is not much nicer but also not really worse.

The whole "List of .." is confusing anyway, but not easily solvable,
since the description is used for
- API dump/viewer (where it is a list/array of ..)
- usage message/man pages (where it's a parameter that gives a single
  element, but it might be passed in multiple times to construct an
  array)

Also, for some common occurrences, the item description is too
generic, and it's not possible to override the description for
external types with the current api macro.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
 [ Thomas: Added more context that was in the diffstat of the path ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-22 07:56:09 +02:00
Dietmar Maurer
1d60abf9f1 move src/server/rest.rs to proxmox-rest-server crate
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
7c1bd58a8a rest server: cleanup auth-log handling
Handle auth logs the same way as access log.
- Configure with ApiConfig
- CommandoSocket command to reload auth-logs "api-auth-log-reopen"

Inside API calls, we now access the ApiConfig using the RestEnvironment.

The openid_login api now also logs failed logins and return http_err!(UNAUTHORIZED, ..)
on failed logins.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
48b7a61a21 rest server: do not use pbs_api_types::Authid
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
2ea6f8d01d rest server: return UserInformation from ApiAuth::check_auth
This need impl UserInformation for Arc<CachedUserInfo> which is implemented
with proxmox 0.13.2

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
efeccc11cc make get_index and ApiConfig property (callback)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
3d73529460 rest server: simplify get_index() method signature
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
cc67441662 move normalize_uri_path and extract_cookie to proxmox-rest-server crate
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
fbe0de85d0 move src/tools/compression.rs to proxmox-rest-server crate
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
dc28aa1ae7 move src/server/formatter.rs to proxmox-rest-server crate
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
ba04dfb9b2 move src/server/environment.rs to proxmox-rest-server crate
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
51d84f9847 move src/tools/daemon.rs to proxmox-rest-server workspace
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
ca7a26166f move ApiConfig, FileLogger and CommandoSocket to proxmox-rest-server workspace
ApiConfig: avoid using  pbs_config::backup_user()
CommandoSocket: avoid using  pbs_config::backup_user()
FileLogger: avoid using  pbs_config::backup_user()
- use atomic_open_or_create_file()

Auth Trait: moved definitions to proxmox-rest-server/src/lib.rs
- removed CachedUserInfo patrameter
- return user as String (not Authid)

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
2e426f9df2 start new proxmox-rest-server workspace
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-09-21 08:46:41 +02:00
Dietmar Maurer
3cd221c163 bump proxmox version to 0.13.3-1 2021-09-21 06:45:28 +02:00
Dietmar Maurer
b6b9118ce3 atomic_open_or_create_file: add support for OFlag::O_EXCL 2021-09-20 08:24:44 +02:00
Dietmar Maurer
b46a0720ae atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY 2021-09-20 08:13:28 +02:00
Dietmar Maurer
c7e1a1f3c8 update proxmox/debian/control 2021-09-20 08:12:18 +02:00