Commit Graph

758 Commits

Author SHA1 Message Date
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
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
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
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
Wolfgang Bumiller
ad8fc652f6 make u2f registration challenge Deserialize
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-02 13:07:38 +01:00
Wolfgang Bumiller
a6f8f84632 make u2f attestation certificate optional
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-11-02 12:49:47 +01:00
Wolfgang Bumiller
31b7620f20 bump proxmox to 0.7.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-30 15:15:32 +01:00
Wolfgang Bumiller
6255336f04 totp: rename step to period
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-30 15:13:42 +01:00
Wolfgang Bumiller
0cd88fd832 bump proxmox to 0.6.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 15:04:07 +01:00
Wolfgang Bumiller
8cbf9cb7c8 add proxmox::tools::tfa
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 15:01:26 +01:00
Wolfgang Bumiller
05749ab419 test fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 14:51:22 +01:00
Fabian Grünbichler
51f5acea22 rpcenv: rename user to auth_id
since it does no longer store just a userid, but potentially an API
token identifier as well

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-29 13:59:24 +01:00
Thomas Lamprecht
7d34e6f3a4 api macro: reuse generated default const for "unwrap_or"
Instead of setting a default value to a const and inside an
.unwrap_or_else closure, lets set it only to the const and reuse that
later in .unwrap_or

To achieve that we move the "unrwap_or" code for param plumbing code generation
a bit later so that we have easy access to the generated const name.
As all this code is related to optional/default-value stuff it does read still
relatively OK with that change, IMO.

This has the advantage of not getting a warning like:

>  warning: constant is never used: `API_METHOD_EXAMPLE_FOO_PARAM_DEFAULT_FORCE`
>   --> src/api2/node/foo.rs
>    |
> XY |             force: {
>    |             ^^^^^
>    = note: `#[warn(dead_code)]` on by default

When one has a API endpoint like:

> #[api(
>     input: {
>         properties: {
>             force: {
>                 type: bool,
>                 optional: true,
>                 default: false,
>             },
>         },
>     },
>     ...
> )]
> /// Example
> fn example_foo(force: bool) -> Result<(), Error> {
>     if force {
>         // do something
>     }
>     Ok(())
> }

It effectively changes the output for optional parameters with a default set
and no Option<T> from

> let p = p.unwrap_or_else(|| #default_value);

to

> let p = p.unwrap_or(#const_name_for_default);

where the "#const_name_for_default" is a pub const with value
"#default_value"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-27 09:17:12 +01:00
Thomas Lamprecht
7575f890ed tools fs: fix comment typo and strange glyph
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-20 18:46:50 +02:00
Wolfgang Bumiller
fe652c9263 bump proxmox version to 0.5.0-1
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-19 12:32:51 +02:00
Wolfgang Bumiller
9cd97f9851 proxmox::tools::fs: remove deprecated functions
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-19 12:32:37 +02:00
Fabian Grünbichler
daab5a9faf proxmox: bump nix dependency
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-10-19 12:11:50 +02:00
Dietmar Maurer
f3c10cc9df bump proxmox version to 0.4.4-1 2020-10-16 10:30:22 +02:00
Thomas Lamprecht
88586e9343 api: RPC environment: add client IP getter/setter to trait
This is similar to what we have in PVE and PMG now. Will be used to
set the real client IP for proxied connections.

with a dummy implementation, which avoids the need to implement it
for the CLI or Backup environments, which do not have or care for a
client IP

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-14 13:53:04 +02:00
Wolfgang Bumiller
e5456f873d clippy fixups
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-14 11:13:20 +02:00
Dietmar Maurer
75bc02d9db bump proxmox version to 0.4.3-1 2020-10-08 09:00:22 +02:00
Thomas Lamprecht
82172720a4 tools: change constnamemap to a more automatic constnamedbitmap
We only used this for the privileges for now, and there it's a
nuisance to alter all bit definitions manually if something is added.

This change makes it count the bits up automatically.

Rename the macro to indicate that this is not a generic name map but
a more specific named bit mapping.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-08 08:54:26 +02:00
Wolfgang Bumiller
19dc729b7b formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-05 12:04:22 +02:00
Wolfgang Bumiller
9fa9c76a9c improve error messages in parse_rfc3339
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-05 09:16:51 +02:00
Wolfgang Bumiller
307cb04795 big formatting cleanup
had to be done, sorry not sorry

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-02 10:00:04 +02:00
Wolfgang Bumiller
ef5c719150 formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2020-10-02 09:59:52 +02:00
Dominik Csapak
ef6ccff5d1 proxmox/tools/common_regex: improve IPRE_BRACKET
by disallowing [] around ipv4 adresses (which is not very common)

we did not use this anywhere, so there should not be any compatibility
problem

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-30 06:13:58 +02:00
Dietmar Maurer
d79e1cfefe bump version to 0.4.2-1 2020-09-28 10:06:28 +02:00
Dietmar Maurer
f9763e12f9 simplify open_file_locked 2020-09-28 09:16:53 +02:00
Dominik Csapak
5440c65787 proxmox/tools/fs: create tmpfile helper
by factoring out the code we had in 'replace_file'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-09-28 07:09:02 +02:00