[pve-devel] applied: [PATCH access-control] token create: return also full token id for convenience
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Apr 15 20:42:53 CEST 2020
makes creating a client for this slightly nicer, as it doesn't needs
to be as state full.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
PVE/API2/User.pm | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/PVE/API2/User.pm b/PVE/API2/User.pm
index 311f913..210a0b2 100644
--- a/PVE/API2/User.pm
+++ b/PVE/API2/User.pm
@@ -600,6 +600,11 @@ __PACKAGE__->register_method ({
type => 'string',
description => 'API token value used for authentication.',
},
+ 'full-tokenid' => {
+ type => 'string',
+ format_description => '<userid>!<tokenid>',
+ description => 'The full token id.',
+ },
},
},
code => sub {
@@ -611,7 +616,7 @@ __PACKAGE__->register_method ({
my $usercfg = cfs_read_file("user.cfg");
my $token = PVE::AccessControl::check_token_exist($usercfg, $userid, $tokenid, 1);
- my $value;
+ my ($full_tokenid, $value);
PVE::AccessControl::check_user_exist($usercfg, $userid);
raise_param_exc({ 'tokenid' => 'Token already exists.' }) if defined($token);
@@ -621,7 +626,7 @@ __PACKAGE__->register_method ({
PVE::AccessControl::check_user_exist($usercfg, $userid);
die "Token already exists.\n" if defined(PVE::AccessControl::check_token_exist($usercfg, $userid, $tokenid, 1));
- my $full_tokenid = PVE::AccessControl::join_tokenid($userid, $tokenid);
+ $full_tokenid = PVE::AccessControl::join_tokenid($userid, $tokenid);
$value = PVE::TokenConfig::generate_token($full_tokenid);
$token = {};
@@ -635,7 +640,11 @@ __PACKAGE__->register_method ({
PVE::AccessControl::lock_user_config($generate_and_add_token, 'generating token failed');
- return { info => $token, value => $value };
+ return {
+ info => $token,
+ value => $value,
+ 'full-tokenid' => $full_tokenid,
+ };
}});
--
2.20.1
More information about the pve-devel
mailing list