Commit Graph

2744 Commits

Author SHA1 Message Date
Wolfgang Bumiller
301918529d api-macro: more tuple refactoring
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:21:13 +01:00
Wolfgang Bumiller
75530cb68c api-macro: object schema entry tuple -> struct
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:20:48 +01:00
Wolfgang Bumiller
de749b1a52 schema: ExtractValueDeserializer
A deserializer which takes an `&mut Value` and an object
schema reference and deserializes by extracting (removing)
the values from the references serde Value.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:20:05 +01:00
Wolfgang Bumiller
9d9231313d api-macro: suport AllOf on structs
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:19:40 +01:00
Wolfgang Bumiller
357b3016d5 api-macro: add more standard Maybe methods
Note that any methods added there should be oriented around
`Option`.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:19:16 +01:00
Wolfgang Bumiller
6b5bf36989 api-macro: forbid flattened fields
They don't appear in the json data structure and therefore
should not be named separately in the schema. Structs with
flattened fields will become an `AllOf` schema instead.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:18:46 +01:00
Wolfgang Bumiller
fbc9be471b api-macro: add 'flatten' to SerdeAttrib
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:18:08 +01:00
Wolfgang Bumiller
0cdd47c8fc schema: allow AllOf schema as method parameter
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:17:47 +01:00
Wolfgang Bumiller
3f490368cf schema: support AllOf schemas
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:03:37 +01:00
Wolfgang Bumiller
4916d5b10d api-macro: support optional return values
The return specification can now include an `optional`
field.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:02:47 +01:00
Wolfgang Bumiller
e8998851f8 schema: support optional return values
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:02:17 +01:00
Wolfgang Bumiller
89a3dd5b1f formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-22 07:00:46 +01:00
Dominik Csapak
f9378cad13 tools/daemon: improve reload behaviour
it seems that sometimes, the child process signal gets handled
before the parent process signal. Systemd then ignores the
childs signal (finished reloading) and only after going into
reloading state because of the parent. this will never finish.

Instead, wait for the state to change to 'reloading' after sending
that signal in the parent, an only fork afterwards. This way
we ensure that systemd knows about the reloading before actually trying
to do it.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-By: Fabian Ebner <f.ebner@proxmox.com>
2020-12-18 10:30:37 +01:00
Wolfgang Bumiller
4dec479d2c update d/control
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-09 10:44:58 +01:00
Wolfgang Bumiller
8cc4c167ac bump proxmox-api-macro to 0.2.4-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-09 10:43:49 +01:00
Wolfgang Bumiller
84d0859ddb document forward_de/serialize_to_display/from_str
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-09 10:19:59 +01:00
Wolfgang Bumiller
4a0f06d084 doc fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-09 10:18:58 +01:00
Wolfgang Bumiller
0ad74b431e api-macro: lower a whole bunch of errors
to be non fatal for better error messages, this way the user
will see the compile error, but we still generate all the
code & schema variables so that one error isn't accompanied
by all the ones resulting from not having the generated code
there at all.

Eg.

    error: description not allowed on external type
       --> src/api2/access/user.rs:472:22
        |
    472 |         description: "Get API token metadata (with config digest).",
        |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Was previously also accompanied by

    error[E0425]: cannot find value `API_METHOD_READ_TOKEN` in this scope
       --> src/api2/access/user.rs:774:11
        |
    699 | pub fn delete_token(
        | ------ similarly named constant `API_METHOD_DELETE_TOKEN` defined here
    ...
    774 |     .get(&API_METHOD_READ_TOKEN)
        |           ^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `API_METHOD_DELETE_TOKEN`

The second error was "wrong" and came much later, needlessly
filling the screen if this happened on multiple functions.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-07 15:34:02 +01:00
Wolfgang Bumiller
273ce60242 api-macro: forbid description on incompatible schemas
References to external schemas (or types) already include
the description in the external schema and therefore are
illegal.

The implementation consists of multiple parts:

* Introduce a `Maybe` type which can be `Explicit`,
  `Derived` or `None`.
* Forbid `Explicit` descriptions on references.
* Instead of bailing out on such errors which causes all of
  the generated code to vanish and create heaps of
  additional nonsensical errors, add a way to *add* errors
  without bailing out immediately via the `error!()` macro.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-07 15:09:45 +01:00
Hannes Laimer
9de5b2a58e correct email in changelog
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
2020-12-07 11:43:11 +01:00
Dietmar Maurer
c9c28f7631 bump proxmox version to 0.8.1-1 2020-12-06 09:08:41 +01:00
Dietmar Maurer
c7be237b57 trait ReadExt: add read_exact_or_eof and skip_to_end 2020-12-06 09:05:26 +01:00
Wolfgang Bumiller
a793453944 proxmox: fix example array in Cargo.toml
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-12-03 09:58:02 +01:00
Fabian Grünbichler
cce052e97f build: track d/control in git
and check build-dependencies before building..

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-30 15:13:01 +01:00
Wolfgang Bumiller
6b0dabefd4 file logger: remove test.log after test as well
and a doc formatting fixup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 14:13:21 +01:00
Wolfgang Bumiller
09b2a5961e bump proxmox to 0.8.0
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 11:18:57 +01:00
Wolfgang Bumiller
194f2605e4 minor clippy lints
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 11:18:37 +01:00
Wolfgang Bumiller
3d29fbf15e introduce FdRef and BorrowedFd
Types used to reprecent borrowed raw file descriptors.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 10:48:05 +01:00
Wolfgang Bumiller
2216b348a1 make_tmp_file: properly guard file descriptor
and return an Fd

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-30 09:43:00 +01:00
Fabian Grünbichler
b210ad69eb run 'cargo fmt'
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-27 11:43:55 +01:00
Fabian Grünbichler
97509b63ad fix clippy warnings
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-27 11:43:21 +01:00
Dietmar Maurer
1d2a0d9e81 bump version to 0.7.2-1 2020-11-24 13:24:11 +01:00
Dietmar Maurer
e7cb1f20d0 implement cli command alias feature 2020-11-24 12:44:54 +01:00
Dietmar Maurer
474fae5b3d fix typo 2020-11-24 12:44:03 +01:00
Wolfgang Bumiller
bba65fe051 bump proxmox to 0.7.1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-19 09:17:26 +01:00
Wolfgang Bumiller
08d6e20c63 tools: refactor hex parsing
deduplicate parsing into a `hex_to_bin_exact`

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-19 09:16:50 +01:00
Wolfgang Bumiller
46c71f7da3 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-16 14:21:45 +01:00
Fabian Grünbichler
85b5be8133 rest: check for disabled token (user)
when authenticating a token, and not just when authenticating a
user/ticket.

Reported-By: Dominik Jäger <d.jaeger@proxmox.com>

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-11 12:21:29 +01:00
Thomas Lamprecht
e6edbb5c3b daemon: rename method, endless loop, bail on exec error
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-11 10:14:01 +01:00
Dominik Csapak
d75579790c daemon: add hack for sd_notify
sd_notify is not synchronous, iow. it only waits until the message
reaches the queue not until it is processed by systemd

when the process that sent such a message exits before systemd could
process it, it cannot be associated to the correct pid

so in case of reloading, we send a message with 'MAINPID=<newpid>'
to signal that it will change. if now the old process exits before
systemd knows this, it will not accept the 'READY=1' message from the
child, since it rejects the MAINPID change

since there is no (AFAICS) library interface to check the unit status,
we use 'systemctl is-active <SERVICE_NAME>' to check the state until
it is not 'reloading' anymore.

on newer systemd versions, there is 'sd_notify_barrier' which would
allow us to wait for systemd to have all messages from the current
pid to be processed before acknowledging to the child, but on buster
the systemd version is to old...

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-11-11 09:43:00 +01:00
Wolfgang Bumiller
055793c481 api-macro: support raw method parameters
Support raw parameter name identifiers (eg. `r#type`)

    #[api(
        input: {
            properties: {
                type: {
                    type: String,
                    description: "Foo",
                },
            },
        },
    )]
    fn foo(r#type: String) { code... }

The "r#type" parameter in the fn decl will match the "type"
parameter name in the input property list.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-10 13:53:06 +01:00
Thomas Lamprecht
0c816fe383 bump proxmox-api-macro version to 0.2.3
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-05 12:13:05 +01:00
Thomas Lamprecht
0f802c8667 proxmox: loosen version requirement to api macro crate
allow updates of minor api-macro releases, breaking ones should get
the first or second version tuple bumped anyway.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-05 12:13:05 +01:00
Fabian Ebner
63b9f31c7b fix prefix for nested commands
Fixes a regression from commit f50a627f34
which resulted in re-using the prefix without sub-commands when calling
handle_simple_command(_future)

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-05 11:18:03 +01:00
Dominik Csapak
df9b42db3f tools/daemon: fix reload with open connections
instead of await'ing the result of 'create_service' directly,
poll it together with the shutdown_future

if we reached that, fork_restart the new daemon, and await
the open future from 'create_service'

this way the old process still handles open connections until they finish,
while we already start a new process that handles new incoming connections

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-05 11:14:56 +01:00
Thomas Lamprecht
5d7ae1f38c api: factor out auth logger and use for all API authentication failures
we have information here not available in the access log, especially
if the /api2/extjs formatter is used, which encapsulates errors in a
200 response.

So keep the auth log for now, but extend it use from create ticket
calls to all authentication failures for API calls, this ensures one
can also fail2ban tokens.

Do that logging in a central place, which makes it simple but means
that we do not have the user ID information available to include in
the log.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-04 17:26:34 +01:00
Wolfgang Bumiller
8a9a87bbf4 tfa: make AuthResponse fields public
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-04 13:21:41 +01:00
Thomas Lamprecht
4031710b36 server: implement access log rotation with re-open via command socket
re-use the future we already have for task log rotation to trigger
it.

Move the FileLogger in ApiConfig into an Arc, so that we can actually
update it and REST using the new one.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:53:30 +01:00
Thomas Lamprecht
6e2e7e66c5 command socket: make create_control_socket private
this is internal for now, use the comanndo socket struct
implementation, and ideally not a new one but the existing ones
created in the proxy and api daemons.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:50:24 +01:00
Thomas Lamprecht
3dd23fd3ba server: add CommandoSocket where multiple users can register commands
This is a preparatory step to replace the task control socket with it
and provide a "reopen log file" command for the rest server.

Kept it simple by disallowing to register new commands after the
socket gets spawned, this avoids the need for locking.

If we really need that we can always wrap it in a Arc<RWLock<..>> or
something like that, or even nicer, register at compile time.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-11-02 19:32:22 +01:00