6
6
7
7
"""Tool to manage KernelCI API users"""
8
8
9
- import getpass
10
-
11
9
from .base import Args , sub_main
12
10
from .base_api import APICommand , AttributesCommand
13
11
14
12
15
- class cmd_whoami (APICommand ): # pylint: disable=invalid-name
16
- """Use the /whoami entry point to get the current user's data"""
17
- args = APICommand .args + [Args .api_token ]
18
- opt_args = APICommand .opt_args + [Args .indent ]
19
-
20
- def _api_call (self , api , configs , args ):
21
- data = api .whoami ()
22
- self ._print_json (data , args .indent )
23
- return True
24
-
25
-
26
- class cmd_get_token (APICommand ): # pylint: disable=invalid-name
27
- """Create a new API token for the current user"""
28
- args = APICommand .args + [Args .username ]
29
- opt_args = APICommand .opt_args + [
30
- {
31
- 'name' : '--scopes' ,
32
- 'action' : 'append' ,
33
- 'help' : "Security scopes" ,
34
- },
35
- ]
36
-
37
- def _api_call (self , api , configs , args ):
38
- password = getpass .getpass ()
39
- token = api .create_token (args .username , password , args .scopes )
40
- self ._print_json (token , args .indent )
41
- return True
42
-
43
-
44
- class cmd_password_hash (APICommand ): # pylint: disable=invalid-name
45
- """Get an encryption hash for an arbitrary password"""
46
-
47
- def _api_call (self , api , configs , args ):
48
- password = getpass .getpass ()
49
- print (api .password_hash (password ))
50
- return True
51
-
52
-
53
- class cmd_change_password (APICommand ): # pylint: disable=invalid-name
54
- """Change a password for a given user"""
55
- args = APICommand .args + [Args .username ]
56
-
57
- def _api_call (self , api , configs , args ):
58
- current = getpass .getpass ("Current password: " )
59
- new = getpass .getpass ("New password: " )
60
- retyped = getpass .getpass ("Retype new password: " )
61
- if new != retyped :
62
- print ("Sorry, passwords do not match." )
63
- return False
64
- api .change_password (args .username , current , new )
65
- return True
66
-
67
-
68
13
class cmd_get_group (APICommand ): # pylint: disable=invalid-name
69
14
"""Get a user group with a given ID"""
70
15
args = APICommand .args + [Args .group_id ]
@@ -89,42 +34,6 @@ def _api_call(self, api, configs, args):
89
34
return True
90
35
91
36
92
- class cmd_add (APICommand ): # pylint: disable=invalid-name
93
- """Add a new user account"""
94
- args = APICommand .args + [
95
- Args .api_token ,
96
- {
97
- 'name' : 'username' ,
98
- 'help' : "Username of the new user" ,
99
- },
100
- {
101
- 'name' : 'email' ,
102
- 'help' : "Email address of the new user" ,
103
- },
104
- ]
105
-
106
- def _api_call (self , api , configs , args ):
107
- profile = {
108
- 'email' : args .email ,
109
- }
110
- password = getpass .getpass ()
111
- api .create_user (args .username , password , profile )
112
- return True
113
-
114
-
115
- class cmd_find_users (AttributesCommand ): # pylint: disable=invalid-name
116
- """Find user profiles with arbitrary attributes"""
117
- opt_args = AttributesCommand .opt_args + [
118
- Args .limit , Args .offset
119
- ]
120
-
121
- def _api_call (self , api , configs , args ):
122
- attributes = self ._split_attributes (args .attributes )
123
- profiles = api .get_user_profiles (attributes , args .offset , args .limit )
124
- self ._print_json (profiles , args .indent )
125
- return True
126
-
127
-
128
37
class cmd_update (APICommand ): # pylint: disable=invalid-name
129
38
"""Update a new user account"""
130
39
args = APICommand .args + [
0 commit comments