cdiam-cli 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/LICENSE.md +20 -20
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/PKG-INFO +3 -2
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/README.md +28 -28
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/__init__.py +2 -2
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/__main__.py +3 -3
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/api/__init__.py +4 -4
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/api/api_action.py +123 -123
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/api/download.py +27 -27
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/api/settings.py +59 -59
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/api/utils.py +0 -0
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/command/__init__.py +1 -1
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/command/data.py +33 -33
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/command/project.py +29 -29
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/helper/__init__.py +2 -2
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/helper/curl_helper.py +42 -42
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/helper/json_helper.py +6 -6
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/helper/yaml_helper.py +10 -10
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/main.py +22 -22
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/schemas/__init__.py +1 -1
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/schemas/analysis.py +60 -60
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/schemas/base.py +28 -28
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/schemas/project.py +36 -36
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/cdiam_cli/schemas/schemas.py +36 -36
- {cdiam_cli-0.1.2 → cdiam_cli-0.1.3}/pyproject.toml +2 -2
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) [year] [fullname]
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [year] [fullname]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: cdiam-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary:
|
|
5
5
|
Author: tungtp99
|
|
6
6
|
Author-email: tungtp181199@gmail.com
|
|
@@ -10,6 +10,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
14
|
Requires-Dist: click (>=8.1.7,<9.0.0)
|
|
14
15
|
Requires-Dist: datetime (>=5.5,<6.0)
|
|
15
16
|
Requires-Dist: idna (==3.4)
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
# CDIAM CLI
|
|
2
|
-
|
|
3
|
-
This is a repository for CDIAM CLI. .
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
|
|
7
|
-
To get started with this project, follow these steps:
|
|
8
|
-
|
|
9
|
-
### From source
|
|
10
|
-
1. Clone the repository: `git clone github.com/C-DIAM/cdiam-cli.git`
|
|
11
|
-
2. Install: `poetry install` install poetry with https://python-poetry.org/docs/
|
|
12
|
-
|
|
13
|
-
### From pypip
|
|
14
|
-
Run `pip install cdiam-cli`
|
|
15
|
-
|
|
16
|
-
### View CLI command
|
|
17
|
-
Run `cdiam-cli --help`
|
|
18
|
-
|
|
19
|
-
## Features
|
|
20
|
-
|
|
21
|
-
- Save token: `cdiam-cli save-token` must provide server endpoint E.g. https://c-diam.com/api and TOKEN get from CDIAM APP
|
|
22
|
-
- Call API: `cdiam-cli call-api <PATH_TO_YAML_OR_JSON_PARAMS>` more detail about params schemas at `<SERVER_ENPOINT>/schemas/docs` E.g. https://c-diam.com/api/schemas/docs
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## License
|
|
27
|
-
|
|
28
|
-
This project is licensed under the [MIT License](LICENSE).
|
|
1
|
+
# CDIAM CLI
|
|
2
|
+
|
|
3
|
+
This is a repository for CDIAM CLI. .
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
To get started with this project, follow these steps:
|
|
8
|
+
|
|
9
|
+
### From source
|
|
10
|
+
1. Clone the repository: `git clone github.com/C-DIAM/cdiam-cli.git`
|
|
11
|
+
2. Install: `poetry install` install poetry with https://python-poetry.org/docs/
|
|
12
|
+
|
|
13
|
+
### From pypip
|
|
14
|
+
Run `pip install cdiam-cli`
|
|
15
|
+
|
|
16
|
+
### View CLI command
|
|
17
|
+
Run `cdiam-cli --help`
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- Save token: `cdiam-cli save-token` must provide server endpoint E.g. https://c-diam.com/api and TOKEN get from CDIAM APP
|
|
22
|
+
- Call API: `cdiam-cli call-api <PATH_TO_YAML_OR_JSON_PARAMS>` more detail about params schemas at `<SERVER_ENPOINT>/schemas/docs` E.g. https://c-diam.com/api/schemas/docs
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from . import api
|
|
2
|
-
from . import helper
|
|
1
|
+
from . import api
|
|
2
|
+
from . import helper
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# python
|
|
2
|
-
from .main import main_group
|
|
3
|
-
|
|
1
|
+
# python
|
|
2
|
+
from .main import main_group
|
|
3
|
+
|
|
4
4
|
main_group()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .settings import save_token
|
|
2
|
-
from .download import download_data
|
|
3
|
-
from .api_action import call_api
|
|
4
|
-
from . import utils
|
|
1
|
+
from .settings import save_token
|
|
2
|
+
from .download import download_data
|
|
3
|
+
from .api_action import call_api
|
|
4
|
+
from . import utils
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import click
|
|
3
|
-
from cdiam_cli.helper import yaml_helper, curl_helper
|
|
4
|
-
import subprocess
|
|
5
|
-
from typing import Union, Callable, Any, Dict, overload, Literal
|
|
6
|
-
from .settings import read_api_endpoint, read_api_token
|
|
7
|
-
from cdiam_cli.schemas import ParamsRequestGetTaskStatus
|
|
8
|
-
from cdiam_cli.schemas.analysis import AnalysisResultRead, AnalysisResult
|
|
9
|
-
from time import sleep
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def wait_task(task_id: str):
|
|
13
|
-
while True:
|
|
14
|
-
sleep(5)
|
|
15
|
-
print("Load status info")
|
|
16
|
-
res = run(
|
|
17
|
-
ParamsRequestGetTaskStatus(api="get_task_status", task_id=task_id).dict()
|
|
18
|
-
)
|
|
19
|
-
status = AnalysisResultRead(**res)
|
|
20
|
-
|
|
21
|
-
if status.task is None:
|
|
22
|
-
raise Exception("Task FAILURE")
|
|
23
|
-
if status.task.status == "FAILURE":
|
|
24
|
-
raise Exception("Task FAILURE")
|
|
25
|
-
if status.task.status == "SUCCESS":
|
|
26
|
-
break
|
|
27
|
-
return status
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def parse_and_wait_task(process: Any):
|
|
31
|
-
analysis_result: AnalysisResult = AnalysisResult(**process)
|
|
32
|
-
assert analysis_result.task_id is not None
|
|
33
|
-
print(analysis_result)
|
|
34
|
-
status = wait_task(task_id=analysis_result.task_id)
|
|
35
|
-
print(status)
|
|
36
|
-
return status
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@overload
|
|
40
|
-
def run(
|
|
41
|
-
params: Union[str, Dict[Any, Any]],
|
|
42
|
-
modify_params_callback: Union[Callable[[Any], Any], None] = None,
|
|
43
|
-
wait_as_analysis: Literal[False] = False,
|
|
44
|
-
) -> Any: ...
|
|
45
|
-
@overload
|
|
46
|
-
def run(
|
|
47
|
-
params: Union[str, Dict[Any, Any]],
|
|
48
|
-
modify_params_callback: Union[Callable[[Any], Any], None] = None,
|
|
49
|
-
wait_as_analysis: Literal[True] = True,
|
|
50
|
-
) -> AnalysisResult: ...
|
|
51
|
-
def run(
|
|
52
|
-
params: Union[str, Dict[Any, Any]],
|
|
53
|
-
modify_params_callback: Union[Callable[[Any], Any], None] = None,
|
|
54
|
-
wait_as_analysis: bool = False,
|
|
55
|
-
):
|
|
56
|
-
"""
|
|
57
|
-
Runs an API call with the provided parameters and returns the API response.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
params (Union[str, Dict[Any, Any]]): The API parameters, either as a path to a JSON or YAML file, or as a dictionary.
|
|
61
|
-
More details about api schemas can be found in the documentation at https://c-diam.com/api/schemas/docs or if you are using different endpoint you can find it at https://<your-end-point>/api/schemas/docs.
|
|
62
|
-
modify_params_callback (Union[Callable[[Any], Any], None]): An optional callback function to modify the API parameters before the call.
|
|
63
|
-
wait_as_analysis (bool): If True, the function will wait for the API task to complete and return the analysis result.
|
|
64
|
-
|
|
65
|
-
Returns:
|
|
66
|
-
Any: The API response, or an AnalysisResult if wait_as_analysis is True.
|
|
67
|
-
|
|
68
|
-
Raises:
|
|
69
|
-
Exception: If the API call fails.
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
if isinstance(params, str):
|
|
73
|
-
if params.endswith(".json"):
|
|
74
|
-
with open(params) as f:
|
|
75
|
-
data = json.load(f)
|
|
76
|
-
else:
|
|
77
|
-
data = yaml_helper.read(params)
|
|
78
|
-
if modify_params_callback is not None:
|
|
79
|
-
data = modify_params_callback(data)
|
|
80
|
-
else:
|
|
81
|
-
data = params
|
|
82
|
-
|
|
83
|
-
if
|
|
84
|
-
form_data = curl_helper.convert_json_to_form_data(data)
|
|
85
|
-
command = curl_helper.generate_curl_form_command(
|
|
86
|
-
form_data, endpoint=f"{read_api_endpoint()}/api_public/{data['api']}" # type: ignore
|
|
87
|
-
)
|
|
88
|
-
else:
|
|
89
|
-
command = curl_helper.generate_curl_json_command(
|
|
90
|
-
data, endpoint=f"{read_api_endpoint()}/api_public/{data['api']}" # type: ignore
|
|
91
|
-
)
|
|
92
|
-
command.append("-b")
|
|
93
|
-
command.append(f"cdiam_session_token={read_api_token()}")
|
|
94
|
-
|
|
95
|
-
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
96
|
-
process.check_returncode()
|
|
97
|
-
output = json.loads(process.stdout.decode())
|
|
98
|
-
if "detail" in output:
|
|
99
|
-
raise Exception(output)
|
|
100
|
-
|
|
101
|
-
if wait_as_analysis:
|
|
102
|
-
output = parse_and_wait_task(output)
|
|
103
|
-
|
|
104
|
-
return output
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@click.command()
|
|
108
|
-
@click.argument("params", type=click.Path(exists=True), required=True)
|
|
109
|
-
def call_api(params: str):
|
|
110
|
-
"""
|
|
111
|
-
Calls the API with the provided parameters and returns the API response.
|
|
112
|
-
|
|
113
|
-
Args:
|
|
114
|
-
params (str): The path to a JSON or YAML file containing the API parameters. More details about api schemas can be found in the documentation at https://c-diam.com/api/schemas/docs or if you are using different endpoint you can find it at https://<your-end-point>/api/schemas/docs.
|
|
115
|
-
Returns:
|
|
116
|
-
str: The API response.
|
|
117
|
-
|
|
118
|
-
Raises:
|
|
119
|
-
Exception: If the API call fails.
|
|
120
|
-
"""
|
|
121
|
-
|
|
122
|
-
data = run(params)
|
|
123
|
-
print(json.dumps(data, indent=4, sort_keys=True))
|
|
1
|
+
import json
|
|
2
|
+
import click
|
|
3
|
+
from cdiam_cli.helper import yaml_helper, curl_helper
|
|
4
|
+
import subprocess
|
|
5
|
+
from typing import Union, Callable, Any, Dict, overload, Literal
|
|
6
|
+
from .settings import read_api_endpoint, read_api_token
|
|
7
|
+
from cdiam_cli.schemas import ParamsRequestGetTaskStatus
|
|
8
|
+
from cdiam_cli.schemas.analysis import AnalysisResultRead, AnalysisResult
|
|
9
|
+
from time import sleep
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def wait_task(task_id: str):
|
|
13
|
+
while True:
|
|
14
|
+
sleep(5)
|
|
15
|
+
print("Load status info")
|
|
16
|
+
res = run(
|
|
17
|
+
ParamsRequestGetTaskStatus(api="get_task_status", task_id=task_id).dict()
|
|
18
|
+
)
|
|
19
|
+
status = AnalysisResultRead(**res)
|
|
20
|
+
|
|
21
|
+
if status.task is None:
|
|
22
|
+
raise Exception("Task FAILURE")
|
|
23
|
+
if status.task.status == "FAILURE":
|
|
24
|
+
raise Exception("Task FAILURE")
|
|
25
|
+
if status.task.status == "SUCCESS":
|
|
26
|
+
break
|
|
27
|
+
return status
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def parse_and_wait_task(process: Any):
|
|
31
|
+
analysis_result: AnalysisResult = AnalysisResult(**process)
|
|
32
|
+
assert analysis_result.task_id is not None
|
|
33
|
+
print(analysis_result)
|
|
34
|
+
status = wait_task(task_id=analysis_result.task_id)
|
|
35
|
+
print(status)
|
|
36
|
+
return status
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@overload
|
|
40
|
+
def run(
|
|
41
|
+
params: Union[str, Dict[Any, Any]],
|
|
42
|
+
modify_params_callback: Union[Callable[[Any], Any], None] = None,
|
|
43
|
+
wait_as_analysis: Literal[False] = False,
|
|
44
|
+
) -> Any: ...
|
|
45
|
+
@overload
|
|
46
|
+
def run(
|
|
47
|
+
params: Union[str, Dict[Any, Any]],
|
|
48
|
+
modify_params_callback: Union[Callable[[Any], Any], None] = None,
|
|
49
|
+
wait_as_analysis: Literal[True] = True,
|
|
50
|
+
) -> AnalysisResult: ...
|
|
51
|
+
def run(
|
|
52
|
+
params: Union[str, Dict[Any, Any]],
|
|
53
|
+
modify_params_callback: Union[Callable[[Any], Any], None] = None,
|
|
54
|
+
wait_as_analysis: bool = False,
|
|
55
|
+
):
|
|
56
|
+
"""
|
|
57
|
+
Runs an API call with the provided parameters and returns the API response.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
params (Union[str, Dict[Any, Any]]): The API parameters, either as a path to a JSON or YAML file, or as a dictionary.
|
|
61
|
+
More details about api schemas can be found in the documentation at https://c-diam.com/api/schemas/docs or if you are using different endpoint you can find it at https://<your-end-point>/api/schemas/docs.
|
|
62
|
+
modify_params_callback (Union[Callable[[Any], Any], None]): An optional callback function to modify the API parameters before the call.
|
|
63
|
+
wait_as_analysis (bool): If True, the function will wait for the API task to complete and return the analysis result.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
Any: The API response, or an AnalysisResult if wait_as_analysis is True.
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
Exception: If the API call fails.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
if isinstance(params, str):
|
|
73
|
+
if params.endswith(".json"):
|
|
74
|
+
with open(params) as f:
|
|
75
|
+
data = json.load(f)
|
|
76
|
+
else:
|
|
77
|
+
data = yaml_helper.read(params)
|
|
78
|
+
if modify_params_callback is not None:
|
|
79
|
+
data = modify_params_callback(data)
|
|
80
|
+
else:
|
|
81
|
+
data = params
|
|
82
|
+
|
|
83
|
+
if "upload_" in data["api"]: # type: ignore
|
|
84
|
+
form_data = curl_helper.convert_json_to_form_data(data)
|
|
85
|
+
command = curl_helper.generate_curl_form_command(
|
|
86
|
+
form_data, endpoint=f"{read_api_endpoint()}/api_public/{data['api']}" # type: ignore
|
|
87
|
+
)
|
|
88
|
+
else:
|
|
89
|
+
command = curl_helper.generate_curl_json_command(
|
|
90
|
+
data, endpoint=f"{read_api_endpoint()}/api_public/{data['api']}" # type: ignore
|
|
91
|
+
)
|
|
92
|
+
command.append("-b")
|
|
93
|
+
command.append(f"cdiam_session_token={read_api_token()}")
|
|
94
|
+
|
|
95
|
+
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
96
|
+
process.check_returncode()
|
|
97
|
+
output = json.loads(process.stdout.decode())
|
|
98
|
+
if "detail" in output:
|
|
99
|
+
raise Exception(output)
|
|
100
|
+
|
|
101
|
+
if wait_as_analysis:
|
|
102
|
+
output = parse_and_wait_task(output)
|
|
103
|
+
|
|
104
|
+
return output
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@click.command()
|
|
108
|
+
@click.argument("params", type=click.Path(exists=True), required=True)
|
|
109
|
+
def call_api(params: str):
|
|
110
|
+
"""
|
|
111
|
+
Calls the API with the provided parameters and returns the API response.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
params (str): The path to a JSON or YAML file containing the API parameters. More details about api schemas can be found in the documentation at https://c-diam.com/api/schemas/docs or if you are using different endpoint you can find it at https://<your-end-point>/api/schemas/docs.
|
|
115
|
+
Returns:
|
|
116
|
+
str: The API response.
|
|
117
|
+
|
|
118
|
+
Raises:
|
|
119
|
+
Exception: If the API call fails.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
data = run(params)
|
|
123
|
+
print(json.dumps(data, indent=4, sort_keys=True))
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import click
|
|
2
|
-
import requests
|
|
3
|
-
from urllib.request import urlopen
|
|
4
|
-
from .settings import read_api_endpoint, read_api_token
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@click.command()
|
|
8
|
-
@click.argument("object_id", type=str)
|
|
9
|
-
def download_data(object_id: str):
|
|
10
|
-
"""This api download data of given object_id"""
|
|
11
|
-
res = requests.get(
|
|
12
|
-
f"{read_api_endpoint()}/data/data/download-file/{object_id}",
|
|
13
|
-
cookies={"cdiam_session_token": read_api_token()},
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
if res.status_code != 200:
|
|
17
|
-
print(res.json())
|
|
18
|
-
else:
|
|
19
|
-
for url in res.json()["url"]:
|
|
20
|
-
response = urlopen(url)
|
|
21
|
-
file_name = response.headers.get_filename()
|
|
22
|
-
with requests.get(url, stream=True) as r:
|
|
23
|
-
r.raise_for_status()
|
|
24
|
-
with open(file_name, "wb") as f:
|
|
25
|
-
for chunk in r.iter_content(chunk_size=8192):
|
|
26
|
-
if chunk:
|
|
27
|
-
f.write(chunk)
|
|
1
|
+
import click
|
|
2
|
+
import requests
|
|
3
|
+
from urllib.request import urlopen
|
|
4
|
+
from .settings import read_api_endpoint, read_api_token
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@click.command()
|
|
8
|
+
@click.argument("object_id", type=str)
|
|
9
|
+
def download_data(object_id: str):
|
|
10
|
+
"""This api download data of given object_id"""
|
|
11
|
+
res = requests.get(
|
|
12
|
+
f"{read_api_endpoint()}/data/data/download-file/{object_id}",
|
|
13
|
+
cookies={"cdiam_session_token": read_api_token()},
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if res.status_code != 200:
|
|
17
|
+
print(res.json())
|
|
18
|
+
else:
|
|
19
|
+
for url in res.json()["url"]:
|
|
20
|
+
response = urlopen(url)
|
|
21
|
+
file_name = response.headers.get_filename()
|
|
22
|
+
with requests.get(url, stream=True) as r:
|
|
23
|
+
r.raise_for_status()
|
|
24
|
+
with open(file_name, "wb") as f:
|
|
25
|
+
for chunk in r.iter_content(chunk_size=8192):
|
|
26
|
+
if chunk:
|
|
27
|
+
f.write(chunk)
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import click
|
|
2
|
-
import os
|
|
3
|
-
from os.path import expanduser
|
|
4
|
-
import json
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def get_path_settings():
|
|
8
|
-
home = expanduser("~")
|
|
9
|
-
return os.path.join(home, ".cdiam_cli")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def read_api_endpoint():
|
|
13
|
-
if not os.path.exists(get_path_settings()):
|
|
14
|
-
raise Exception("Run save-settings first")
|
|
15
|
-
with open(get_path_settings(), "r") as f:
|
|
16
|
-
settings = json.load(f)
|
|
17
|
-
if "endpoint" not in settings:
|
|
18
|
-
raise Exception(
|
|
19
|
-
"Cannot found endpoint setting. Please run save-settings first"
|
|
20
|
-
)
|
|
21
|
-
return settings["endpoint"]
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def read_api_token():
|
|
25
|
-
if not os.path.exists(get_path_settings()):
|
|
26
|
-
raise Exception("Run save-settings first")
|
|
27
|
-
with open(get_path_settings(), "r") as f:
|
|
28
|
-
settings = json.load(f)
|
|
29
|
-
if "token" not in settings:
|
|
30
|
-
raise Exception(
|
|
31
|
-
"Cannot found token setting. Please run save-settings first"
|
|
32
|
-
)
|
|
33
|
-
return settings["token"]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class HiddenPassword(object):
|
|
37
|
-
def __init__(self, password=""):
|
|
38
|
-
self.password = password
|
|
39
|
-
|
|
40
|
-
def __str__(self):
|
|
41
|
-
return "*" * len(self.password)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@click.command()
|
|
45
|
-
def save_token():
|
|
46
|
-
"""This api save your endpoint and your token in your machine"""
|
|
47
|
-
endpoint = click.prompt(
|
|
48
|
-
"Please enter the server endpoint E.g. https://c-diam.com/api", type=str
|
|
49
|
-
)
|
|
50
|
-
value = click.prompt("Please enter the token", type=HiddenPassword, hide_input=True)
|
|
51
|
-
with open(get_path_settings(), "w") as f:
|
|
52
|
-
json.dump(
|
|
53
|
-
{
|
|
54
|
-
"endpoint": endpoint,
|
|
55
|
-
"token": value.password,
|
|
56
|
-
},
|
|
57
|
-
f,
|
|
58
|
-
)
|
|
59
|
-
print(f"Save settings at {get_path_settings()}")
|
|
1
|
+
import click
|
|
2
|
+
import os
|
|
3
|
+
from os.path import expanduser
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_path_settings():
|
|
8
|
+
home = expanduser("~")
|
|
9
|
+
return os.path.join(home, ".cdiam_cli")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def read_api_endpoint():
|
|
13
|
+
if not os.path.exists(get_path_settings()):
|
|
14
|
+
raise Exception("Run save-settings first")
|
|
15
|
+
with open(get_path_settings(), "r") as f:
|
|
16
|
+
settings = json.load(f)
|
|
17
|
+
if "endpoint" not in settings:
|
|
18
|
+
raise Exception(
|
|
19
|
+
"Cannot found endpoint setting. Please run save-settings first"
|
|
20
|
+
)
|
|
21
|
+
return settings["endpoint"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def read_api_token():
|
|
25
|
+
if not os.path.exists(get_path_settings()):
|
|
26
|
+
raise Exception("Run save-settings first")
|
|
27
|
+
with open(get_path_settings(), "r") as f:
|
|
28
|
+
settings = json.load(f)
|
|
29
|
+
if "token" not in settings:
|
|
30
|
+
raise Exception(
|
|
31
|
+
"Cannot found token setting. Please run save-settings first"
|
|
32
|
+
)
|
|
33
|
+
return settings["token"]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class HiddenPassword(object):
|
|
37
|
+
def __init__(self, password=""):
|
|
38
|
+
self.password = password
|
|
39
|
+
|
|
40
|
+
def __str__(self):
|
|
41
|
+
return "*" * len(self.password)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@click.command()
|
|
45
|
+
def save_token():
|
|
46
|
+
"""This api save your endpoint and your token in your machine"""
|
|
47
|
+
endpoint = click.prompt(
|
|
48
|
+
"Please enter the server endpoint E.g. https://c-diam.com/api", type=str
|
|
49
|
+
)
|
|
50
|
+
value = click.prompt("Please enter the token", type=HiddenPassword, hide_input=True)
|
|
51
|
+
with open(get_path_settings(), "w") as f:
|
|
52
|
+
json.dump(
|
|
53
|
+
{
|
|
54
|
+
"endpoint": endpoint,
|
|
55
|
+
"token": value.password,
|
|
56
|
+
},
|
|
57
|
+
f,
|
|
58
|
+
)
|
|
59
|
+
print(f"Save settings at {get_path_settings()}")
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from . import project
|
|
1
|
+
from . import project
|
|
2
2
|
from . import data
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
import click
|
|
4
|
-
|
|
5
|
-
from cdiam_cli import api
|
|
6
|
-
from cdiam_cli.schemas.base import MessageResponseError, MessageResponseSuccess
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@click.group('data')
|
|
10
|
-
@click.pass_context
|
|
11
|
-
def data_cli(ctx):
|
|
12
|
-
"""
|
|
13
|
-
This command group provides various commands to show and manage data related to projects.
|
|
14
|
-
Use the subcommands under this group to interact with project effectively.
|
|
15
|
-
"""
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@data_cli.command('list')
|
|
20
|
-
@click.argument('project_id')
|
|
21
|
-
def list_all_data(project_id: str):
|
|
22
|
-
"""
|
|
23
|
-
This command lists all available data in given project id.
|
|
24
|
-
"""
|
|
25
|
-
try:
|
|
26
|
-
response: Any = api.api_action.run({
|
|
27
|
-
"api": "list_data",
|
|
28
|
-
"project_id": project_id
|
|
29
|
-
})
|
|
30
|
-
output = MessageResponseSuccess(data=response)
|
|
31
|
-
except Exception as e:
|
|
32
|
-
output = MessageResponseError(error=str(e))
|
|
33
|
-
click.echo(output.json())
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from cdiam_cli import api
|
|
6
|
+
from cdiam_cli.schemas.base import MessageResponseError, MessageResponseSuccess
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.group('data')
|
|
10
|
+
@click.pass_context
|
|
11
|
+
def data_cli(ctx):
|
|
12
|
+
"""
|
|
13
|
+
This command group provides various commands to show and manage data related to projects.
|
|
14
|
+
Use the subcommands under this group to interact with project effectively.
|
|
15
|
+
"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@data_cli.command('list')
|
|
20
|
+
@click.argument('project_id')
|
|
21
|
+
def list_all_data(project_id: str):
|
|
22
|
+
"""
|
|
23
|
+
This command lists all available data in given project id.
|
|
24
|
+
"""
|
|
25
|
+
try:
|
|
26
|
+
response: Any = api.api_action.run({
|
|
27
|
+
"api": "list_data",
|
|
28
|
+
"project_id": project_id
|
|
29
|
+
})
|
|
30
|
+
output = MessageResponseSuccess(data=response)
|
|
31
|
+
except Exception as e:
|
|
32
|
+
output = MessageResponseError(error=str(e))
|
|
33
|
+
click.echo(output.json())
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
import click
|
|
4
|
-
|
|
5
|
-
from cdiam_cli import api
|
|
6
|
-
from cdiam_cli.schemas.base import MessageResponseError, MessageResponseSuccess
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@click.group('project')
|
|
10
|
-
@click.pass_context
|
|
11
|
-
def project_cli(ctx):
|
|
12
|
-
"""
|
|
13
|
-
This command group provides various commands to show and manage data related to projects.
|
|
14
|
-
Use the subcommands under this group to interact with project effectively.
|
|
15
|
-
"""
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@project_cli.command('list')
|
|
20
|
-
def list_all_project():
|
|
21
|
-
"""
|
|
22
|
-
This command lists all the projects available in the system.
|
|
23
|
-
"""
|
|
24
|
-
try:
|
|
25
|
-
response: Any = api.api_action.run({"api": 'list_project'})
|
|
26
|
-
output = MessageResponseSuccess(data=response)
|
|
27
|
-
except Exception as e:
|
|
28
|
-
output = MessageResponseError(error=str(e))
|
|
29
|
-
click.echo(output.json())
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from cdiam_cli import api
|
|
6
|
+
from cdiam_cli.schemas.base import MessageResponseError, MessageResponseSuccess
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.group('project')
|
|
10
|
+
@click.pass_context
|
|
11
|
+
def project_cli(ctx):
|
|
12
|
+
"""
|
|
13
|
+
This command group provides various commands to show and manage data related to projects.
|
|
14
|
+
Use the subcommands under this group to interact with project effectively.
|
|
15
|
+
"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@project_cli.command('list')
|
|
20
|
+
def list_all_project():
|
|
21
|
+
"""
|
|
22
|
+
This command lists all the projects available in the system.
|
|
23
|
+
"""
|
|
24
|
+
try:
|
|
25
|
+
response: Any = api.api_action.run({"api": 'list_project'})
|
|
26
|
+
output = MessageResponseSuccess(data=response)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
output = MessageResponseError(error=str(e))
|
|
29
|
+
click.echo(output.json())
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from . import yaml_helper
|
|
2
|
-
from . import curl_helper
|
|
1
|
+
from . import yaml_helper
|
|
2
|
+
from . import curl_helper
|
|
3
3
|
from . import json_helper
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from typing import Any, Dict
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def _convert(data: Any, ret: Dict[str, str], key: str):
|
|
6
|
-
if isinstance(data, dict):
|
|
7
|
-
for k in data.keys():
|
|
8
|
-
_convert(data[k], ret, f"{key}[{k}]" if key != "" else k)
|
|
9
|
-
elif isinstance(data, list):
|
|
10
|
-
for index, k in enumerate(data):
|
|
11
|
-
_convert(data[index], ret, f"{key}[{index}]")
|
|
12
|
-
else:
|
|
13
|
-
if data is not None:
|
|
14
|
-
ret[key] = data
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def generate_curl_form_command(form_data: Dict[str, str], endpoint: str):
|
|
18
|
-
command = ["curl", "-X", "POST", "-H", "Content-Type: multipart/form-data"]
|
|
19
|
-
for k, v in form_data.items():
|
|
20
|
-
|
|
21
|
-
command.append("-F")
|
|
22
|
-
if v is None or v.startswith("@"):
|
|
23
|
-
command.append(f'{k}={"null" if v is None else v}')
|
|
24
|
-
else:
|
|
25
|
-
command.append(f'{k}="{v}"')
|
|
26
|
-
|
|
27
|
-
command.append(endpoint)
|
|
28
|
-
return command
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def generate_curl_json_command(json_data: Dict[str, str], endpoint: str):
|
|
32
|
-
command = ["curl", "-X", "POST", "-H", "Content-Type: application/json"]
|
|
33
|
-
command.append("-d")
|
|
34
|
-
command.append(json.dumps(json_data))
|
|
35
|
-
command.append(endpoint)
|
|
36
|
-
return command
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def convert_json_to_form_data(json_object: Any):
|
|
40
|
-
ret = {}
|
|
41
|
-
_convert(json_object, ret, "")
|
|
42
|
-
return ret
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def _convert(data: Any, ret: Dict[str, str], key: str):
|
|
6
|
+
if isinstance(data, dict):
|
|
7
|
+
for k in data.keys():
|
|
8
|
+
_convert(data[k], ret, f"{key}[{k}]" if key != "" else k)
|
|
9
|
+
elif isinstance(data, list):
|
|
10
|
+
for index, k in enumerate(data):
|
|
11
|
+
_convert(data[index], ret, f"{key}[{index}]")
|
|
12
|
+
else:
|
|
13
|
+
if data is not None:
|
|
14
|
+
ret[key] = data
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def generate_curl_form_command(form_data: Dict[str, str], endpoint: str):
|
|
18
|
+
command = ["curl", "-X", "POST", "-H", "Content-Type: multipart/form-data"]
|
|
19
|
+
for k, v in form_data.items():
|
|
20
|
+
|
|
21
|
+
command.append("-F")
|
|
22
|
+
if v is None or v.startswith("@"):
|
|
23
|
+
command.append(f'{k}={"null" if v is None else v}')
|
|
24
|
+
else:
|
|
25
|
+
command.append(f'{k}="{v}"')
|
|
26
|
+
|
|
27
|
+
command.append(endpoint)
|
|
28
|
+
return command
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def generate_curl_json_command(json_data: Dict[str, str], endpoint: str):
|
|
32
|
+
command = ["curl", "-X", "POST", "-H", "Content-Type: application/json"]
|
|
33
|
+
command.append("-d")
|
|
34
|
+
command.append(json.dumps(json_data))
|
|
35
|
+
command.append(endpoint)
|
|
36
|
+
return command
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def convert_json_to_form_data(json_object: Any):
|
|
40
|
+
ret = {}
|
|
41
|
+
_convert(json_object, ret, "")
|
|
42
|
+
return ret
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
|
-
def read(path: str):
|
|
4
|
-
with open(path ,'r') as f:
|
|
5
|
-
return json.load(f)
|
|
6
|
-
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
def read(path: str):
|
|
4
|
+
with open(path ,'r') as f:
|
|
5
|
+
return json.load(f)
|
|
6
|
+
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import yaml
|
|
2
|
-
|
|
3
|
-
def read(path: str):
|
|
4
|
-
with open(path) as stream:
|
|
5
|
-
try:
|
|
6
|
-
return yaml.safe_load(stream)
|
|
7
|
-
except yaml.YAMLError as exc:
|
|
8
|
-
print(exc)
|
|
9
|
-
raise Exception(exc)
|
|
10
|
-
|
|
1
|
+
import yaml
|
|
2
|
+
|
|
3
|
+
def read(path: str):
|
|
4
|
+
with open(path) as stream:
|
|
5
|
+
try:
|
|
6
|
+
return yaml.safe_load(stream)
|
|
7
|
+
except yaml.YAMLError as exc:
|
|
8
|
+
print(exc)
|
|
9
|
+
raise Exception(exc)
|
|
10
|
+
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import click
|
|
2
|
-
|
|
3
|
-
from cdiam_cli import api
|
|
4
|
-
from cdiam_cli.command import data, project
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@click.group()
|
|
8
|
-
@click.pass_context
|
|
9
|
-
def main_group(ctx):
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# Groups
|
|
14
|
-
main_group.add_command(project.project_cli)
|
|
15
|
-
main_group.add_command(data.data_cli)
|
|
16
|
-
|
|
17
|
-
# Single command
|
|
18
|
-
main_group.add_command(api.call_api)
|
|
19
|
-
main_group.add_command(api.save_token)
|
|
20
|
-
|
|
21
|
-
if __name__ == "__main__":
|
|
22
|
-
main_group()
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from cdiam_cli import api
|
|
4
|
+
from cdiam_cli.command import data, project
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@click.group()
|
|
8
|
+
@click.pass_context
|
|
9
|
+
def main_group(ctx):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Groups
|
|
14
|
+
main_group.add_command(project.project_cli)
|
|
15
|
+
main_group.add_command(data.data_cli)
|
|
16
|
+
|
|
17
|
+
# Single command
|
|
18
|
+
main_group.add_command(api.call_api)
|
|
19
|
+
main_group.add_command(api.save_token)
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
main_group()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
from .schemas import *
|
|
1
|
+
from .schemas import *
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
from typing import Optional, List
|
|
3
|
-
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class TaskStatus(BaseModel):
|
|
8
|
-
status: str = "UNKNOWN"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class AnalysisResultBase(BaseModel):
|
|
12
|
-
result_id: str
|
|
13
|
-
data_id: str
|
|
14
|
-
analysis: int
|
|
15
|
-
task_id: str
|
|
16
|
-
args: str
|
|
17
|
-
project_id: str
|
|
18
|
-
user_email: Optional[str]
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class AnalysisCatalogBase(BaseModel):
|
|
22
|
-
name: str
|
|
23
|
-
description: Optional[str]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class AnalysisCatalog(AnalysisCatalogBase):
|
|
27
|
-
"""
|
|
28
|
-
This table stores available analyses type
|
|
29
|
-
that the App supports.
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
id: int
|
|
33
|
-
time_created: datetime
|
|
34
|
-
time_modified: datetime
|
|
35
|
-
"""A list of all analysis results of this type"""
|
|
36
|
-
results: List["AnalysisResult"]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class AnalysisResultRead(AnalysisResultBase):
|
|
40
|
-
"""
|
|
41
|
-
A response model of an anlysis result
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
time_created: datetime
|
|
45
|
-
time_modified: datetime
|
|
46
|
-
task: Optional[TaskStatus]
|
|
47
|
-
result_data_status: Optional[str]
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class AnalysisResult(AnalysisResultBase):
|
|
51
|
-
"""
|
|
52
|
-
This table stores all analyses that had been produced for a data
|
|
53
|
-
The analysis reference points to the description of the analysis.
|
|
54
|
-
The result_id reference points to the detail result of the analysis
|
|
55
|
-
"""
|
|
56
|
-
|
|
57
|
-
time_created: datetime
|
|
58
|
-
time_modified: datetime
|
|
59
|
-
"""An object of the analysis type"""
|
|
60
|
-
analysis_orm: AnalysisCatalog
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Optional, List
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TaskStatus(BaseModel):
|
|
8
|
+
status: str = "UNKNOWN"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AnalysisResultBase(BaseModel):
|
|
12
|
+
result_id: str
|
|
13
|
+
data_id: str
|
|
14
|
+
analysis: int
|
|
15
|
+
task_id: str
|
|
16
|
+
args: str
|
|
17
|
+
project_id: str
|
|
18
|
+
user_email: Optional[str]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AnalysisCatalogBase(BaseModel):
|
|
22
|
+
name: str
|
|
23
|
+
description: Optional[str]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AnalysisCatalog(AnalysisCatalogBase):
|
|
27
|
+
"""
|
|
28
|
+
This table stores available analyses type
|
|
29
|
+
that the App supports.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
id: int
|
|
33
|
+
time_created: datetime
|
|
34
|
+
time_modified: datetime
|
|
35
|
+
"""A list of all analysis results of this type"""
|
|
36
|
+
results: List["AnalysisResult"]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AnalysisResultRead(AnalysisResultBase):
|
|
40
|
+
"""
|
|
41
|
+
A response model of an anlysis result
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
time_created: datetime
|
|
45
|
+
time_modified: datetime
|
|
46
|
+
task: Optional[TaskStatus]
|
|
47
|
+
result_data_status: Optional[str]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class AnalysisResult(AnalysisResultBase):
|
|
51
|
+
"""
|
|
52
|
+
This table stores all analyses that had been produced for a data
|
|
53
|
+
The analysis reference points to the description of the analysis.
|
|
54
|
+
The result_id reference points to the detail result of the analysis
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
time_created: datetime
|
|
58
|
+
time_modified: datetime
|
|
59
|
+
"""An object of the analysis type"""
|
|
60
|
+
analysis_orm: AnalysisCatalog
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class MessageStatusEnum(str, Enum):
|
|
8
|
-
SUCCESS = "success"
|
|
9
|
-
ERROR = "error"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class MessageResponse(BaseModel):
|
|
13
|
-
status: MessageStatusEnum
|
|
14
|
-
error: str
|
|
15
|
-
data: Any
|
|
16
|
-
|
|
17
|
-
class Config:
|
|
18
|
-
allow_population_by_field_name = True
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class MessageResponseSuccess(MessageResponse):
|
|
22
|
-
status: MessageStatusEnum = MessageStatusEnum.SUCCESS
|
|
23
|
-
error: str = ""
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class MessageResponseError(MessageResponse):
|
|
27
|
-
status: MessageStatusEnum = MessageStatusEnum.ERROR
|
|
28
|
-
data: Any = None
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MessageStatusEnum(str, Enum):
|
|
8
|
+
SUCCESS = "success"
|
|
9
|
+
ERROR = "error"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MessageResponse(BaseModel):
|
|
13
|
+
status: MessageStatusEnum
|
|
14
|
+
error: str
|
|
15
|
+
data: Any
|
|
16
|
+
|
|
17
|
+
class Config:
|
|
18
|
+
allow_population_by_field_name = True
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MessageResponseSuccess(MessageResponse):
|
|
22
|
+
status: MessageStatusEnum = MessageStatusEnum.SUCCESS
|
|
23
|
+
error: str = ""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MessageResponseError(MessageResponse):
|
|
27
|
+
status: MessageStatusEnum = MessageStatusEnum.ERROR
|
|
28
|
+
data: Any = None
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
from pydantic import validator
|
|
5
|
-
from cdiam_cli.schemas import ProjectSettings
|
|
6
|
-
from pydantic import BaseModel
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class ProjectBase(BaseModel):
|
|
10
|
-
name: str
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class Project(ProjectBase):
|
|
14
|
-
|
|
15
|
-
id: str
|
|
16
|
-
tombstone: Optional[bool]
|
|
17
|
-
time_created: datetime
|
|
18
|
-
is_public: bool
|
|
19
|
-
delete_date: Optional[datetime]
|
|
20
|
-
settings: Optional[str]
|
|
21
|
-
storage_used: int
|
|
22
|
-
created_by: str
|
|
23
|
-
|
|
24
|
-
@validator("settings")
|
|
25
|
-
def validate_settings(cls, v: str):
|
|
26
|
-
if v == "nan":
|
|
27
|
-
v = "{}"
|
|
28
|
-
if v is None:
|
|
29
|
-
v = "{}"
|
|
30
|
-
return ProjectSettings.encode_settings(ProjectSettings.decode_setting(v))
|
|
31
|
-
|
|
32
|
-
@validator("tombstone")
|
|
33
|
-
def validate_tombstone(cls, v):
|
|
34
|
-
if not v:
|
|
35
|
-
return False
|
|
36
|
-
return v
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from pydantic import validator
|
|
5
|
+
from cdiam_cli.schemas import ProjectSettings
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ProjectBase(BaseModel):
|
|
10
|
+
name: str
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Project(ProjectBase):
|
|
14
|
+
|
|
15
|
+
id: str
|
|
16
|
+
tombstone: Optional[bool]
|
|
17
|
+
time_created: datetime
|
|
18
|
+
is_public: bool
|
|
19
|
+
delete_date: Optional[datetime]
|
|
20
|
+
settings: Optional[str]
|
|
21
|
+
storage_used: int
|
|
22
|
+
created_by: str
|
|
23
|
+
|
|
24
|
+
@validator("settings")
|
|
25
|
+
def validate_settings(cls, v: str):
|
|
26
|
+
if v == "nan":
|
|
27
|
+
v = "{}"
|
|
28
|
+
if v is None:
|
|
29
|
+
v = "{}"
|
|
30
|
+
return ProjectSettings.encode_settings(ProjectSettings.decode_setting(v))
|
|
31
|
+
|
|
32
|
+
@validator("tombstone")
|
|
33
|
+
def validate_tombstone(cls, v):
|
|
34
|
+
if not v:
|
|
35
|
+
return False
|
|
36
|
+
return v
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
from typing import Literal
|
|
2
|
-
from pydantic import BaseModel
|
|
3
|
-
from typing import Union, List, Dict, Any
|
|
4
|
-
import json
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ProjectSettings(BaseModel):
|
|
8
|
-
class Config:
|
|
9
|
-
orm_mode = True
|
|
10
|
-
|
|
11
|
-
cpdb: List[str] = []
|
|
12
|
-
enrichment: List[str] = []
|
|
13
|
-
|
|
14
|
-
@staticmethod
|
|
15
|
-
def encode_settings(settings: Union[Dict[str, Any], "ProjectSettings"]) -> str:
|
|
16
|
-
return ProjectSettings.parse_obj(settings).json()
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def decode_setting(settings: str) -> "ProjectSettings":
|
|
20
|
-
if settings is None:
|
|
21
|
-
settings = "{}"
|
|
22
|
-
return ProjectSettings.parse_obj(json.loads(settings))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class ParamsRequestGetTaskStatus(BaseModel):
|
|
26
|
-
"""
|
|
27
|
-
Represents the parameters for a request to get the status of an analysis task.
|
|
28
|
-
|
|
29
|
-
:param api: The API endpoint being called, which should be "get_task_status".
|
|
30
|
-
:param task_id: The unique identifier of the analysis task.
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
api: Literal["get_task_status"]
|
|
34
|
-
task_id: str
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
from typing import Literal
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
from typing import Union, List, Dict, Any
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ProjectSettings(BaseModel):
|
|
8
|
+
class Config:
|
|
9
|
+
orm_mode = True
|
|
10
|
+
|
|
11
|
+
cpdb: List[str] = []
|
|
12
|
+
enrichment: List[str] = []
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def encode_settings(settings: Union[Dict[str, Any], "ProjectSettings"]) -> str:
|
|
16
|
+
return ProjectSettings.parse_obj(settings).json()
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def decode_setting(settings: str) -> "ProjectSettings":
|
|
20
|
+
if settings is None:
|
|
21
|
+
settings = "{}"
|
|
22
|
+
return ProjectSettings.parse_obj(json.loads(settings))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ParamsRequestGetTaskStatus(BaseModel):
|
|
26
|
+
"""
|
|
27
|
+
Represents the parameters for a request to get the status of an analysis task.
|
|
28
|
+
|
|
29
|
+
:param api: The API endpoint being called, which should be "get_task_status".
|
|
30
|
+
:param task_id: The unique identifier of the analysis task.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
api: Literal["get_task_status"]
|
|
34
|
+
task_id: str
|
|
35
|
+
|
|
36
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "cdiam-cli"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.3"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["tungtp99 <tungtp181199@gmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -26,4 +26,4 @@ build-backend = "poetry.core.masonry.api"
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
[tool.poetry.scripts]
|
|
29
|
-
cdiam-cli = 'cdiam_cli.main:main_group'
|
|
29
|
+
cdiam-cli = 'cdiam_cli.main:main_group'
|