Skip to content

Commit e97d749

Browse files
committed
Add admin group
Signed-off-by: Ching Yi, Chan <qrtt1@infuseai.io>
1 parent 7ea7654 commit e97d749

File tree

7 files changed

+491
-411
lines changed

7 files changed

+491
-411
lines changed

docs/CLI/datasets.md

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ Usage:
88
Get a dataset or list datasets
99
1010
Available Commands:
11-
create Create a dataset
12-
delete Delete a dataset by id
1311
get Get a dataset by name
1412
list List datasets
15-
update Update the dataset
16-
upload_secret Regenerate the secret of the upload server
1713
1814
Options:
1915
-h, --help Show the help
@@ -28,36 +24,6 @@ Global Options:
2824
```
2925

3026

31-
### create
32-
33-
Create a dataset
34-
35-
36-
```
37-
primehub datasets create
38-
```
39-
40-
41-
* *(optional)* file
42-
43-
44-
45-
46-
### delete
47-
48-
Delete a dataset by id
49-
50-
51-
```
52-
primehub datasets delete <id>
53-
```
54-
55-
* id: The dataset id
56-
57-
58-
59-
60-
6127
### get
6228

6329
Get a dataset by name
@@ -85,36 +51,6 @@ primehub datasets list
8551

8652

8753

88-
89-
### update
90-
91-
Update the dataset
92-
93-
94-
```
95-
primehub datasets update <name>
96-
```
97-
98-
* name
99-
100-
101-
102-
103-
104-
### upload_secret
105-
106-
Regenerate the secret of the upload server
107-
108-
109-
```
110-
primehub datasets upload_secret <id>
111-
```
112-
113-
* id: The dataset id or name
114-
115-
116-
117-
11854

11955

12056
## Examples

primehub/__init__.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ class PrimeHub(object):
192192
def __init__(self, config: PrimeHubConfig):
193193
self.primehub_config = config
194194
self.json_output = True
195+
self.usage_role = 'user'
195196
self.commands: Dict[str, Module] = dict()
197+
self.admin_commands: Dict[str, Module] = dict()
196198
self._stderr = sys.stderr
197199
self._stdout = sys.stdout
198200

@@ -212,6 +214,9 @@ def __init__(self, config: PrimeHubConfig):
212214
self.register_command('apptemplates', 'AppTemplate')
213215
self.register_command('apps', 'Apps')
214216

217+
# register admin commands
218+
self.register_admin_command('admin_datasets', 'AdminDatasets', 'datasets')
219+
215220
# initial
216221
self._ensure_config_details(config)
217222

@@ -236,19 +241,42 @@ def request_logs(self, endpint: str, follow: bool, tail: int):
236241
def request_file(self, endpint: str, dest: str):
237242
return Client(self.primehub_config).request_file(endpint, dest)
238243

239-
def register_command(self, module_name: str, command_class: Union[str, Callable], command_name=None):
240-
if not command_name:
241-
command_name = module_name
242-
244+
def _find_command_class(self, command_class, module_name):
243245
# create command instance
244246
if isinstance(command_class, str):
245247
clazz = importlib.import_module('primehub.' + module_name).__getattribute__(command_class)
246248
else:
247249
clazz = command_class
250+
return clazz
251+
252+
def register_command(self, module_name: str, command_class: Union[str, Callable], command_name=None):
253+
if not command_name:
254+
command_name = module_name
255+
256+
clazz = self._find_command_class(command_class, module_name)
248257

249258
# register to the commands table
250259
self.commands[command_name] = clazz(self)
251260

261+
def register_admin_command(self, module_name: str, command_class: Union[str, Callable], command_name=None):
262+
if not command_name:
263+
command_name = module_name
264+
265+
clazz = self._find_command_class(command_class, module_name)
266+
267+
# register to the commands table
268+
self.admin_commands[command_name] = clazz(self)
269+
270+
def switch_admin_role(self):
271+
self.usage_role = 'admin'
272+
self.commands = self.admin_commands
273+
274+
@property
275+
def admin(self):
276+
admin_primehub = PrimeHub(self.primehub_config)
277+
admin_primehub.commands = self.admin_commands
278+
return admin_primehub
279+
252280
def __getattr__(self, item):
253281
if item in self.commands:
254282
return self.commands[item]

0 commit comments

Comments
 (0)