openrelik-api-client 0.2.1__tar.gz → 0.2.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.
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/PKG-INFO +1 -1
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/openrelik_api_client/api_client.py +28 -3
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/openrelik_api_client/folders.py +25 -0
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/pyproject.toml +1 -1
- openrelik_api_client-0.2.1/openrelik_api_client/test.py +0 -11
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/LICENSE +0 -0
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/README.md +0 -0
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/openrelik_api_client/__init__.py +0 -0
- {openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/openrelik_api_client/workflows.py +0 -0
{openrelik_api_client-0.2.1 → openrelik_api_client-0.2.3}/openrelik_api_client/api_client.py
RENAMED
@@ -12,6 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
import tempfile
|
15
16
|
from requests_toolbelt import MultipartEncoder
|
16
17
|
from requests.exceptions import RequestException
|
17
18
|
import requests
|
@@ -71,6 +72,26 @@ class APIClient:
|
|
71
72
|
url = f"{self.base_url}{endpoint}"
|
72
73
|
return self.session.delete(url, **kwargs)
|
73
74
|
|
75
|
+
def download_file(self, file_id: int, filename: str) -> str | None:
|
76
|
+
"""Downloads a file from OpenRelik.
|
77
|
+
|
78
|
+
Args:
|
79
|
+
file_id: The ID of the file to download.
|
80
|
+
filename: The name of the file to download.
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
str: The path to the downloaded file.
|
84
|
+
"""
|
85
|
+
endpoint = f"{self.base_url}/files/{file_id}/download"
|
86
|
+
response = self.session.get(endpoint)
|
87
|
+
filename_prefix, extension = os.path.splitext(filename)
|
88
|
+
file = tempfile.NamedTemporaryFile(
|
89
|
+
mode="wb", prefix=f"{filename_prefix}", suffix=extension, delete=False
|
90
|
+
)
|
91
|
+
file.write(response.content)
|
92
|
+
file.close()
|
93
|
+
return file.name
|
94
|
+
|
74
95
|
def upload_file(
|
75
96
|
self, file_path: str, folder_id: int) -> int | None:
|
76
97
|
"""Uploads a file to the server.
|
@@ -108,11 +129,15 @@ class APIClient:
|
|
108
129
|
while chunk := fh.read(chunk_size):
|
109
130
|
resumableChunkNumber += 1
|
110
131
|
params = {
|
111
|
-
"
|
112
|
-
"
|
132
|
+
"resumableRelativePath": resumableFilename,
|
133
|
+
"resumableTotalSize": total_size,
|
134
|
+
"resumableCurrentChunkSize": chunk_size,
|
135
|
+
"resumableChunkSize": chunk_size,
|
136
|
+
"resumableChunkNumber": resumableChunkNumber,
|
137
|
+
"resumableTotalChunks": resumableTotalChunks,
|
113
138
|
"resumableIdentifier": resumableIdentifier,
|
114
139
|
"resumableFilename": resumableFilename,
|
115
|
-
"folder_id":
|
140
|
+
"folder_id": folder_id
|
116
141
|
}
|
117
142
|
encoder = MultipartEncoder(
|
118
143
|
{"file": (file_path.name, chunk,
|
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
from typing import Any
|
16
|
+
|
15
17
|
from openrelik_api_client.api_client import APIClient
|
16
18
|
|
17
19
|
|
@@ -81,3 +83,26 @@ class FoldersAPI:
|
|
81
83
|
response = self.api_client.session.get(endpoint)
|
82
84
|
response.raise_for_status()
|
83
85
|
return response.status_code == 200
|
86
|
+
|
87
|
+
def update_folder(
|
88
|
+
self, folder_id: int, folder_data: dict[str, Any]
|
89
|
+
):
|
90
|
+
"""Updates an existing folder.
|
91
|
+
|
92
|
+
Args:
|
93
|
+
folder_id: The ID of the folder to update.
|
94
|
+
folder_data: The updated folder data.
|
95
|
+
|
96
|
+
Returns:
|
97
|
+
The updated folder data, or None.
|
98
|
+
|
99
|
+
Raises:
|
100
|
+
HTTPError: If the API request failed.
|
101
|
+
"""
|
102
|
+
endpoint = f"{self.api_client.base_url}/folders/{folder_id}"
|
103
|
+
response = self.api_client.session.patch(
|
104
|
+
endpoint,
|
105
|
+
json=folder_data
|
106
|
+
)
|
107
|
+
response.raise_for_status()
|
108
|
+
return response.json()
|
@@ -1,11 +0,0 @@
|
|
1
|
-
from folders import FoldersAPI
|
2
|
-
|
3
|
-
|
4
|
-
def main():
|
5
|
-
c = FoldersAPI("http://172.19.0.6:8710", api_key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJmZThmMjkyYWViZDM0MjA3YjkyODYxOGQ5MmRmZThkMSIsImlhdCI6MTczNDQ0NzcyOSwibmJmIjoxNzM0NDQ3NzI5LCJleHAiOjE3MzUwNTI1MjksImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODcxMCIsImF1ZCI6ImFwaS1jbGllbnQiLCJqdGkiOiI2ZWZhNzBiYWU0ZDE0MjJlOGM4ODY5OGY1NDhmOTBjYiIsInRva2VuX3R5cGUiOiJyZWZyZXNoIn0.MJA48D570agD49oE4HXfTWCQRpyh5JCy7YCIsHN5YJs")
|
6
|
-
# r = c.create_root_folder("myfolder")
|
7
|
-
# r = c.create_subfolder(33, 'myfolder_sub')
|
8
|
-
print(c.folder_exists(1))
|
9
|
-
|
10
|
-
|
11
|
-
main()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|