hirundo 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl
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.
- hirundo/__init__.py +17 -9
- hirundo/_constraints.py +34 -2
- hirundo/_http.py +7 -2
- hirundo/_iter_sse_retrying.py +61 -17
- hirundo/dataset_optimization.py +421 -83
- hirundo/enum.py +8 -5
- hirundo/git.py +85 -20
- hirundo/storage.py +233 -62
- {hirundo-0.1.8.dist-info → hirundo-0.1.9.dist-info}/METADATA +78 -42
- hirundo-0.1.9.dist-info/RECORD +20 -0
- {hirundo-0.1.8.dist-info → hirundo-0.1.9.dist-info}/WHEEL +1 -1
- hirundo-0.1.8.dist-info/RECORD +0 -20
- {hirundo-0.1.8.dist-info → hirundo-0.1.9.dist-info}/LICENSE +0 -0
- {hirundo-0.1.8.dist-info → hirundo-0.1.9.dist-info}/entry_points.txt +0 -0
- {hirundo-0.1.8.dist-info → hirundo-0.1.9.dist-info}/top_level.txt +0 -0
hirundo/enum.py
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class LabelingType(str, Enum):
|
|
5
5
|
"""
|
|
6
|
-
Enum indicate what type of
|
|
6
|
+
Enum indicate what type of labeling is used for the given dataset.
|
|
7
7
|
Supported types are:
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
SINGLE_LABEL_CLASSIFICATION = "SingleLabelClassification"
|
|
11
|
+
OBJECT_DETECTION = "ObjectDetection"
|
|
12
|
+
SPEECH_TO_TEXT = "SpeechToText"
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class DatasetMetadataType(str, Enum):
|
|
@@ -17,4 +18,6 @@ class DatasetMetadataType(str, Enum):
|
|
|
17
18
|
Supported types are:
|
|
18
19
|
"""
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
HIRUNDO_CSV = "HirundoCSV"
|
|
22
|
+
COCO = "COCO"
|
|
23
|
+
YOLO = "YOLO"
|
hirundo/git.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import datetime
|
|
1
2
|
import re
|
|
2
3
|
import typing
|
|
3
|
-
from typing import Annotated
|
|
4
4
|
|
|
5
5
|
import pydantic
|
|
6
6
|
import requests
|
|
7
7
|
from pydantic import BaseModel, field_validator
|
|
8
8
|
from pydantic_core import Url
|
|
9
9
|
|
|
10
|
+
from hirundo._constraints import RepoUrl
|
|
10
11
|
from hirundo._env import API_HOST
|
|
11
12
|
from hirundo._headers import get_auth_headers, json_headers
|
|
12
13
|
from hirundo._http import raise_for_status_with_reason
|
|
@@ -48,7 +49,7 @@ class GitRepo(BaseModel):
|
|
|
48
49
|
"""
|
|
49
50
|
A name to identify the Git repository in the Hirundo system.
|
|
50
51
|
"""
|
|
51
|
-
repository_url:
|
|
52
|
+
repository_url: typing.Union[str, RepoUrl]
|
|
52
53
|
"""
|
|
53
54
|
The URL of the Git repository, it should start with `ssh://` or `https://` or be in the form `user@host:path`.
|
|
54
55
|
If it is in the form `user@host:path`, it will be rewritten to `ssh://user@host:path`.
|
|
@@ -84,30 +85,45 @@ class GitRepo(BaseModel):
|
|
|
84
85
|
|
|
85
86
|
@field_validator("repository_url", mode="before", check_fields=True)
|
|
86
87
|
@classmethod
|
|
87
|
-
def check_valid_repository_url(cls, repository_url: str):
|
|
88
|
-
# Check if the URL
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
def check_valid_repository_url(cls, repository_url: typing.Union[str, RepoUrl]):
|
|
89
|
+
# Check if the URL has the `@` and `:` pattern with a non-numeric section before the next slash
|
|
90
|
+
match = re.match("([^@]+@[^:]+):([^0-9/][^/]*)/(.+)", str(repository_url))
|
|
91
|
+
if match:
|
|
92
|
+
user_host = match.group(1)
|
|
93
|
+
path = match.group(2) + "/" + match.group(3)
|
|
94
|
+
rewritten_url = Url(f"ssh://{user_host}/{path}")
|
|
95
|
+
# Check if the URL already has a protocol
|
|
96
|
+
url_scheme = rewritten_url.scheme
|
|
97
|
+
logger.info(
|
|
98
|
+
"Modified Git repo to replace %s@%s:%s/%s with %s",
|
|
99
|
+
url_scheme,
|
|
100
|
+
match.group(1),
|
|
101
|
+
match.group(2),
|
|
102
|
+
match.group(3),
|
|
103
|
+
rewritten_url,
|
|
104
|
+
)
|
|
105
|
+
return rewritten_url
|
|
106
|
+
if not str(repository_url).startswith("ssh://") and not str(
|
|
107
|
+
repository_url
|
|
108
|
+
).startswith("https://"):
|
|
101
109
|
raise ValueError("Repository URL must start with 'ssh://' or 'https://'")
|
|
110
|
+
if not isinstance(repository_url, Url):
|
|
111
|
+
repository_url = Url(repository_url)
|
|
102
112
|
return repository_url
|
|
103
113
|
|
|
104
|
-
def create(self):
|
|
114
|
+
def create(self, replace_if_exists: bool = False) -> int:
|
|
105
115
|
"""
|
|
106
116
|
Create a Git repository in the Hirundo system.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
replace_if_exists: If a Git repository with the same name already exists, replace it.
|
|
107
120
|
"""
|
|
108
121
|
git_repo = requests.post(
|
|
109
122
|
f"{API_HOST}/git-repo/",
|
|
110
|
-
json=
|
|
123
|
+
json={
|
|
124
|
+
**self.model_dump(mode="json"),
|
|
125
|
+
"replace_if_exists": replace_if_exists,
|
|
126
|
+
},
|
|
111
127
|
headers={
|
|
112
128
|
**json_headers,
|
|
113
129
|
**get_auth_headers(),
|
|
@@ -120,7 +136,41 @@ class GitRepo(BaseModel):
|
|
|
120
136
|
return git_repo_id
|
|
121
137
|
|
|
122
138
|
@staticmethod
|
|
123
|
-
def
|
|
139
|
+
def get_by_id(git_repo_id: int) -> "GitRepoOut":
|
|
140
|
+
"""
|
|
141
|
+
Retrieves a `GitRepo` instance from the server by its ID
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
git_repo_id: The ID of the `GitRepo` to retrieve
|
|
145
|
+
"""
|
|
146
|
+
git_repo = requests.get(
|
|
147
|
+
f"{API_HOST}/git-repo/{git_repo_id}",
|
|
148
|
+
headers=get_auth_headers(),
|
|
149
|
+
timeout=READ_TIMEOUT,
|
|
150
|
+
)
|
|
151
|
+
raise_for_status_with_reason(git_repo)
|
|
152
|
+
return GitRepoOut(**git_repo.json())
|
|
153
|
+
|
|
154
|
+
@staticmethod
|
|
155
|
+
def get_by_name(
|
|
156
|
+
name: str,
|
|
157
|
+
) -> "GitRepoOut":
|
|
158
|
+
"""
|
|
159
|
+
Retrieves a `GitRepo` instance from the server by its name
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
name: The name of the `GitRepo` to retrieve
|
|
163
|
+
"""
|
|
164
|
+
git_repo = requests.get(
|
|
165
|
+
f"{API_HOST}/git-repo/by-name/{name}",
|
|
166
|
+
headers=get_auth_headers(),
|
|
167
|
+
timeout=READ_TIMEOUT,
|
|
168
|
+
)
|
|
169
|
+
raise_for_status_with_reason(git_repo)
|
|
170
|
+
return GitRepoOut(**git_repo.json())
|
|
171
|
+
|
|
172
|
+
@staticmethod
|
|
173
|
+
def list() -> list["GitRepoOut"]:
|
|
124
174
|
"""
|
|
125
175
|
List all Git repositories in the Hirundo system.
|
|
126
176
|
"""
|
|
@@ -132,7 +182,13 @@ class GitRepo(BaseModel):
|
|
|
132
182
|
timeout=READ_TIMEOUT,
|
|
133
183
|
)
|
|
134
184
|
raise_for_status_with_reason(git_repos)
|
|
135
|
-
|
|
185
|
+
git_repo_json = git_repos.json()
|
|
186
|
+
return [
|
|
187
|
+
GitRepoOut(
|
|
188
|
+
**git_repo,
|
|
189
|
+
)
|
|
190
|
+
for git_repo in git_repo_json
|
|
191
|
+
]
|
|
136
192
|
|
|
137
193
|
@staticmethod
|
|
138
194
|
def delete_by_id(git_repo_id: int):
|
|
@@ -158,3 +214,12 @@ class GitRepo(BaseModel):
|
|
|
158
214
|
if not self.id:
|
|
159
215
|
raise ValueError("No GitRepo has been created")
|
|
160
216
|
GitRepo.delete_by_id(self.id)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
class GitRepoOut(BaseModel):
|
|
220
|
+
id: int
|
|
221
|
+
name: str
|
|
222
|
+
repository_url: RepoUrl
|
|
223
|
+
|
|
224
|
+
created_at: datetime.datetime
|
|
225
|
+
updated_at: datetime.datetime
|
hirundo/storage.py
CHANGED
|
@@ -1,42 +1,130 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
from enum import Enum
|
|
3
|
+
from pathlib import Path
|
|
3
4
|
|
|
4
5
|
import pydantic
|
|
5
6
|
import requests
|
|
6
7
|
from pydantic import BaseModel, model_validator
|
|
7
8
|
from pydantic_core import Url
|
|
8
9
|
|
|
9
|
-
from hirundo._constraints import S3BucketUrl,
|
|
10
|
+
from hirundo._constraints import S3BucketUrl, StorageConfigName
|
|
10
11
|
from hirundo._env import API_HOST
|
|
11
12
|
from hirundo._headers import get_auth_headers, json_headers
|
|
12
13
|
from hirundo._http import raise_for_status_with_reason
|
|
13
14
|
from hirundo._timeouts import MODIFY_TIMEOUT, READ_TIMEOUT
|
|
14
|
-
from hirundo.git import GitRepo
|
|
15
|
+
from hirundo.git import GitRepo, GitRepoOut
|
|
15
16
|
from hirundo.logger import get_logger
|
|
16
17
|
|
|
17
18
|
logger = get_logger(__name__)
|
|
18
19
|
|
|
20
|
+
S3_PREFIX = "s3://"
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
class StorageS3Base(BaseModel):
|
|
21
24
|
endpoint_url: typing.Optional[Url] = None
|
|
22
25
|
bucket_url: S3BucketUrl
|
|
23
26
|
region_name: str
|
|
24
27
|
# ⬆️ We could restrict this, but if we're allowing custom endpoints then the validation may be wrong
|
|
25
28
|
access_key_id: typing.Optional[str] = None
|
|
29
|
+
|
|
30
|
+
def get_url(self, path: typing.Union[str, Path]) -> Url:
|
|
31
|
+
"""
|
|
32
|
+
Get the full URL for a file in the S3 bucket
|
|
33
|
+
|
|
34
|
+
Chains the bucket URL with the path, ensuring that the path is formatted correctly
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
- path: The path to the file in the S3 bucket, e.g. `my-file.txt` or `/my-folder/my-file.txt`
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The full URL to the file in the S3 bucket, e.g. `s3://my-bucket/my-file.txt` or `s3://my-bucket/my-folder/my-file.txt`,
|
|
41
|
+
where `s3://my-bucket` is the bucket URL provided in the S3 storage config
|
|
42
|
+
"""
|
|
43
|
+
return Url(
|
|
44
|
+
f"{S3_PREFIX}{self.bucket_url.removeprefix(S3_PREFIX).removesuffix('/')}/{str(path).removeprefix('/')}"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class StorageS3(StorageS3Base):
|
|
26
49
|
secret_access_key: typing.Optional[str] = None
|
|
27
50
|
|
|
28
51
|
|
|
29
|
-
class
|
|
52
|
+
class StorageS3Out(StorageS3Base):
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class StorageGCPBase(BaseModel):
|
|
30
57
|
bucket_name: str
|
|
31
58
|
project: str
|
|
59
|
+
|
|
60
|
+
def get_url(self, path: typing.Union[str, Path]) -> Url:
|
|
61
|
+
"""
|
|
62
|
+
Get the full URL for a file in the GCP bucket
|
|
63
|
+
|
|
64
|
+
Chains the bucket URL with the path, ensuring that the path is formatted correctly
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
- path: The path to the file in the GCP bucket, e.g. `my-file.txt` or `/my-folder/my-file.txt`
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
The full URL to the file in the GCP bucket, e.g. `gs://my-bucket/my-file.txt` or `gs://my-bucket/my-folder/my-file.txt`,
|
|
71
|
+
where `my-bucket` is the bucket name provided in the GCP storage config
|
|
72
|
+
"""
|
|
73
|
+
return Url(f"gs://{self.bucket_name}/{str(path).removeprefix('/')}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class StorageGCP(StorageGCPBase):
|
|
32
77
|
credentials_json: typing.Optional[dict] = None
|
|
33
78
|
|
|
34
79
|
|
|
35
|
-
|
|
80
|
+
class StorageGCPOut(StorageGCPBase):
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# TODO: Azure storage config is coming soon
|
|
36
85
|
# class StorageAzure(BaseModel):
|
|
86
|
+
# account_url: HttpUrl
|
|
87
|
+
# container_name: str
|
|
88
|
+
# tenant_id: str
|
|
89
|
+
|
|
90
|
+
# def get_url(self, path: typing.Union[str, Path]) -> Url:
|
|
91
|
+
# """
|
|
92
|
+
# Get the full URL for a file in the Azure container
|
|
93
|
+
|
|
94
|
+
# Chains the container URL with the path, ensuring that the path is formatted correctly
|
|
95
|
+
|
|
96
|
+
# Args:
|
|
97
|
+
# - path: The path to the file in the Azure container, e.g. `my-file.txt` or `/my-folder/my-file.txt`
|
|
98
|
+
|
|
99
|
+
# Returns:
|
|
100
|
+
# The full URL to the file in the Azure container
|
|
101
|
+
# """
|
|
102
|
+
# return Url(f"{str(self.account_url)}/{self.container_name}/{str(path).removeprefix('/')}")
|
|
103
|
+
# class StorageAzureOut(BaseModel):
|
|
37
104
|
# container: str
|
|
38
|
-
#
|
|
39
|
-
|
|
105
|
+
# account_url: str
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def get_git_repo_url(
|
|
109
|
+
repo_url: typing.Union[str, Url], path: typing.Union[str, Path]
|
|
110
|
+
) -> Url:
|
|
111
|
+
"""
|
|
112
|
+
Get the full URL for a file in the git repository
|
|
113
|
+
|
|
114
|
+
Chains the repository URL with the path, ensuring that the path is formatted correctly
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
- repo_url: The URL of the git repository, e.g. `https://my-git-repository.com`
|
|
118
|
+
- path: The path to the file in the git repository, e.g. `my-file.txt` or `/my-folder/my-file.txt`
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
The full URL to the file in the git repository, e.g. `https://my-git-repository.com/my-file.txt` or `https://my-git-repository.com/my-folder/my-file.txt`
|
|
122
|
+
"""
|
|
123
|
+
if not isinstance(repo_url, Url):
|
|
124
|
+
repo_url = Url(repo_url)
|
|
125
|
+
return Url(
|
|
126
|
+
f"{repo_url.scheme}{str(repo_url).removeprefix(repo_url.scheme)}/{str(path).removeprefix('/')}"
|
|
127
|
+
)
|
|
40
128
|
|
|
41
129
|
|
|
42
130
|
class StorageGit(BaseModel):
|
|
@@ -61,46 +149,88 @@ class StorageGit(BaseModel):
|
|
|
61
149
|
raise ValueError("Either repo_id or repo must be provided")
|
|
62
150
|
return self
|
|
63
151
|
|
|
152
|
+
def get_url(self, path: typing.Union[str, Path]) -> Url:
|
|
153
|
+
"""
|
|
154
|
+
Get the full URL for a file in the git repository
|
|
155
|
+
|
|
156
|
+
Chains the repository URL with the path, ensuring that the path is formatted correctly
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
- path: The path to the file in the git repository, e.g. `my-file.txt` or `/my-folder/my-file.txt`
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
The full URL to the file in the git repository, e.g. `https://my-git-repository.com/my-file.txt` or `https://my-git-repository.com/my-folder/my-file.txt`,
|
|
163
|
+
where `https://my-git-repository.com` is the repository URL provided in the git storage config's git repo
|
|
164
|
+
"""
|
|
165
|
+
if not self.repo:
|
|
166
|
+
raise ValueError("Repo must be provided to use `get_url`")
|
|
167
|
+
repo_url = self.repo.repository_url
|
|
168
|
+
return get_git_repo_url(repo_url, path)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class StorageGitOut(BaseModel):
|
|
172
|
+
repo: GitRepoOut
|
|
173
|
+
branch: str
|
|
174
|
+
|
|
175
|
+
def get_url(self, path: typing.Union[str, Path]) -> Url:
|
|
176
|
+
"""
|
|
177
|
+
Get the full URL for a file in the git repository
|
|
178
|
+
|
|
179
|
+
Chains the repository URL with the path, ensuring that the path is formatted correctly
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
- path: The path to the file in the git repository, e.g. `my-file.txt` or `/my-folder/my-file.txt`
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
The full URL to the file in the git repository, e.g. `https://my-git-repository.com/my-file.txt` or `https://my-git-repository.com/my-folder/my-file.txt`,
|
|
186
|
+
where `https://my-git-repository.com` is the repository URL provided in the git storage config's git repo
|
|
187
|
+
"""
|
|
188
|
+
repo_url = self.repo.repository_url
|
|
189
|
+
return get_git_repo_url(repo_url, path)
|
|
190
|
+
|
|
64
191
|
|
|
65
192
|
class StorageTypes(str, Enum):
|
|
66
193
|
"""
|
|
67
|
-
Enum for the different types of storage
|
|
194
|
+
Enum for the different types of storage configs.
|
|
68
195
|
Supported types are:
|
|
69
196
|
"""
|
|
70
197
|
|
|
71
198
|
S3 = "S3"
|
|
72
199
|
GCP = "GCP"
|
|
73
|
-
# AZURE = "Azure" TODO: Azure storage
|
|
200
|
+
# AZURE = "Azure" TODO: Azure storage config is coming soon
|
|
74
201
|
GIT = "Git"
|
|
75
202
|
LOCAL = "Local"
|
|
76
203
|
"""
|
|
77
|
-
Local storage
|
|
204
|
+
Local storage config is only supported for on-premises installations.
|
|
78
205
|
"""
|
|
79
206
|
|
|
80
207
|
|
|
81
|
-
class
|
|
208
|
+
class StorageConfig(BaseModel):
|
|
82
209
|
id: typing.Optional[int] = None
|
|
210
|
+
"""
|
|
211
|
+
The ID of the `StorageConfig` in the Hirundo system.
|
|
212
|
+
"""
|
|
83
213
|
|
|
84
214
|
organization_id: typing.Optional[int] = None
|
|
85
215
|
"""
|
|
86
|
-
The ID of the organization that the `
|
|
216
|
+
The ID of the organization that the `StorageConfig` belongs to.
|
|
87
217
|
If not provided, it will be assigned to your default organization.
|
|
88
218
|
"""
|
|
89
219
|
|
|
90
|
-
name:
|
|
220
|
+
name: StorageConfigName
|
|
91
221
|
"""
|
|
92
|
-
A name to identify the `
|
|
222
|
+
A name to identify the `StorageConfig` in the Hirundo system.
|
|
93
223
|
"""
|
|
94
224
|
type: typing.Optional[StorageTypes] = pydantic.Field(
|
|
95
225
|
examples=[
|
|
96
226
|
StorageTypes.S3,
|
|
97
227
|
StorageTypes.GCP,
|
|
98
|
-
# StorageTypes.AZURE, TODO: Azure storage
|
|
228
|
+
# StorageTypes.AZURE, TODO: Azure storage is coming soon
|
|
99
229
|
StorageTypes.GIT,
|
|
100
230
|
]
|
|
101
231
|
)
|
|
102
232
|
"""
|
|
103
|
-
The type of the `
|
|
233
|
+
The type of the `StorageConfig`.
|
|
104
234
|
Supported types are:
|
|
105
235
|
- `S3`
|
|
106
236
|
- `GCP`
|
|
@@ -122,7 +252,7 @@ class StorageIntegration(BaseModel):
|
|
|
122
252
|
],
|
|
123
253
|
)
|
|
124
254
|
"""
|
|
125
|
-
The Amazon Web Services (AWS) S3 storage
|
|
255
|
+
The Amazon Web Services (AWS) S3 storage config details.
|
|
126
256
|
Use this if you want to link to an S3 bucket.
|
|
127
257
|
"""
|
|
128
258
|
gcp: typing.Optional[StorageGCP] = pydantic.Field(
|
|
@@ -151,7 +281,7 @@ class StorageIntegration(BaseModel):
|
|
|
151
281
|
],
|
|
152
282
|
)
|
|
153
283
|
"""
|
|
154
|
-
The Google Cloud (GCP) Storage
|
|
284
|
+
The Google Cloud (GCP) Storage config details.
|
|
155
285
|
Use this if you want to link to an GCS bucket.
|
|
156
286
|
"""
|
|
157
287
|
azure: None = None
|
|
@@ -167,7 +297,7 @@ class StorageIntegration(BaseModel):
|
|
|
167
297
|
# },
|
|
168
298
|
# None,
|
|
169
299
|
# ],
|
|
170
|
-
# ) TODO: Azure storage
|
|
300
|
+
# ) TODO: Azure storage config is coming soon
|
|
171
301
|
git: typing.Optional[StorageGit] = pydantic.Field(
|
|
172
302
|
default=None,
|
|
173
303
|
examples=[
|
|
@@ -186,73 +316,116 @@ class StorageIntegration(BaseModel):
|
|
|
186
316
|
],
|
|
187
317
|
)
|
|
188
318
|
"""
|
|
189
|
-
The Git storage
|
|
319
|
+
The Git storage config details.
|
|
190
320
|
Use this if you want to link to a Git repository.
|
|
191
321
|
"""
|
|
192
322
|
|
|
193
323
|
@staticmethod
|
|
194
|
-
def
|
|
324
|
+
def get_by_id(storage_config_id: int) -> "ResponseStorageConfig":
|
|
195
325
|
"""
|
|
196
|
-
|
|
197
|
-
Note: The return type is `list[dict]` and not `list[StorageIntegration]`
|
|
326
|
+
Retrieves a `StorageConfig` instance from the server by its ID
|
|
198
327
|
|
|
199
328
|
Args:
|
|
200
|
-
|
|
201
|
-
If not provided, it will list `StorageIntegration`'s for the default organization.
|
|
329
|
+
storage_config_id: The ID of the `StorageConfig` to retrieve
|
|
202
330
|
"""
|
|
203
|
-
|
|
204
|
-
f"{API_HOST}/storage-
|
|
205
|
-
params={"storage_integration_organization_id": organization_id},
|
|
331
|
+
storage_config = requests.get(
|
|
332
|
+
f"{API_HOST}/storage-config/{storage_config_id}",
|
|
206
333
|
headers=get_auth_headers(),
|
|
207
334
|
timeout=READ_TIMEOUT,
|
|
208
335
|
)
|
|
209
|
-
raise_for_status_with_reason(
|
|
210
|
-
return
|
|
336
|
+
raise_for_status_with_reason(storage_config)
|
|
337
|
+
return ResponseStorageConfig(**storage_config.json())
|
|
211
338
|
|
|
212
339
|
@staticmethod
|
|
213
|
-
def
|
|
340
|
+
def get_by_name(name: str, storage_type: StorageTypes) -> "ResponseStorageConfig":
|
|
214
341
|
"""
|
|
215
|
-
|
|
342
|
+
Retrieves a `StorageConfig` instance from the server by its name
|
|
216
343
|
|
|
217
344
|
Args:
|
|
218
|
-
|
|
345
|
+
name: The name of the `StorageConfig` to retrieve
|
|
346
|
+
storage_type: The type of the `StorageConfig` to retrieve
|
|
347
|
+
|
|
348
|
+
Note: The type is required because the name is not unique across different storage types
|
|
219
349
|
"""
|
|
220
|
-
|
|
221
|
-
f"{API_HOST}/storage-
|
|
350
|
+
storage_config = requests.get(
|
|
351
|
+
f"{API_HOST}/storage-config/by-name/{name}?storage_type={storage_type.value}",
|
|
352
|
+
headers=get_auth_headers(),
|
|
353
|
+
timeout=READ_TIMEOUT,
|
|
354
|
+
)
|
|
355
|
+
raise_for_status_with_reason(storage_config)
|
|
356
|
+
return ResponseStorageConfig(**storage_config.json())
|
|
357
|
+
|
|
358
|
+
@staticmethod
|
|
359
|
+
def list(
|
|
360
|
+
organization_id: typing.Optional[int] = None,
|
|
361
|
+
) -> list["ResponseStorageConfig"]:
|
|
362
|
+
"""
|
|
363
|
+
Lists all the `StorageConfig`'s created by user's default organization
|
|
364
|
+
Note: The return type is `list[dict]` and not `list[StorageConfig]`
|
|
365
|
+
|
|
366
|
+
Args:
|
|
367
|
+
organization_id: The ID of the organization to list `StorageConfig`'s for.
|
|
368
|
+
If not provided, it will list `StorageConfig`'s for the default organization.
|
|
369
|
+
"""
|
|
370
|
+
storage_configs = requests.get(
|
|
371
|
+
f"{API_HOST}/storage-config/",
|
|
372
|
+
params={"storage_config_organization_id": organization_id},
|
|
373
|
+
headers=get_auth_headers(),
|
|
374
|
+
timeout=READ_TIMEOUT,
|
|
375
|
+
)
|
|
376
|
+
raise_for_status_with_reason(storage_configs)
|
|
377
|
+
return [ResponseStorageConfig(**si) for si in storage_configs.json()]
|
|
378
|
+
|
|
379
|
+
@staticmethod
|
|
380
|
+
def delete_by_id(storage_config_id) -> None:
|
|
381
|
+
"""
|
|
382
|
+
Deletes a `StorageConfig` instance from the server by its ID
|
|
383
|
+
|
|
384
|
+
Args:
|
|
385
|
+
storage_config_id: The ID of the `StorageConfig` to delete
|
|
386
|
+
"""
|
|
387
|
+
storage_config = requests.delete(
|
|
388
|
+
f"{API_HOST}/storage-config/{storage_config_id}",
|
|
222
389
|
headers=get_auth_headers(),
|
|
223
390
|
timeout=MODIFY_TIMEOUT,
|
|
224
391
|
)
|
|
225
|
-
raise_for_status_with_reason(
|
|
226
|
-
logger.info("Deleted storage
|
|
392
|
+
raise_for_status_with_reason(storage_config)
|
|
393
|
+
logger.info("Deleted storage config with ID: %s", storage_config_id)
|
|
227
394
|
|
|
228
395
|
def delete(self) -> None:
|
|
229
396
|
"""
|
|
230
|
-
Deletes the `
|
|
397
|
+
Deletes the `StorageConfig` instance from the server
|
|
231
398
|
"""
|
|
232
399
|
if not self.id:
|
|
233
|
-
raise ValueError("No
|
|
400
|
+
raise ValueError("No StorageConfig has been created")
|
|
234
401
|
self.delete_by_id(self.id)
|
|
235
402
|
|
|
236
|
-
def create(self) -> int:
|
|
403
|
+
def create(self, replace_if_exists: bool = False) -> int:
|
|
237
404
|
"""
|
|
238
|
-
Create a `
|
|
405
|
+
Create a `StorageConfig` instance on the server
|
|
406
|
+
|
|
407
|
+
Args:
|
|
408
|
+
replace_if_exists: If a `StorageConfig` with the same name and type already exists, replace it.
|
|
239
409
|
"""
|
|
240
410
|
if self.git and self.git.repo:
|
|
241
|
-
self.git.repo_id = self.git.repo.create()
|
|
242
|
-
|
|
243
|
-
f"{API_HOST}/storage-
|
|
244
|
-
json=
|
|
411
|
+
self.git.repo_id = self.git.repo.create(replace_if_exists=replace_if_exists)
|
|
412
|
+
storage_config = requests.post(
|
|
413
|
+
f"{API_HOST}/storage-config/",
|
|
414
|
+
json={
|
|
415
|
+
**self.model_dump(mode="json"),
|
|
416
|
+
"replace_if_exists": replace_if_exists,
|
|
417
|
+
},
|
|
245
418
|
headers={
|
|
246
419
|
**json_headers,
|
|
247
420
|
**get_auth_headers(),
|
|
248
421
|
},
|
|
249
422
|
timeout=MODIFY_TIMEOUT,
|
|
250
423
|
)
|
|
251
|
-
raise_for_status_with_reason(
|
|
252
|
-
|
|
253
|
-
self.id =
|
|
254
|
-
logger.info("Created storage
|
|
255
|
-
return
|
|
424
|
+
raise_for_status_with_reason(storage_config)
|
|
425
|
+
storage_config_id = storage_config.json()["id"]
|
|
426
|
+
self.id = storage_config_id
|
|
427
|
+
logger.info("Created storage config with ID: %s", storage_config_id)
|
|
428
|
+
return storage_config_id
|
|
256
429
|
|
|
257
430
|
@model_validator(mode="after")
|
|
258
431
|
def validate_storage_type(self):
|
|
@@ -281,15 +454,13 @@ class StorageIntegration(BaseModel):
|
|
|
281
454
|
return self
|
|
282
455
|
|
|
283
456
|
|
|
284
|
-
class
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
Note: Only files in this path will be retrieved and it will be used as the root for paths in the CSV.
|
|
295
|
-
"""
|
|
457
|
+
class ResponseStorageConfig(BaseModel):
|
|
458
|
+
id: int
|
|
459
|
+
name: StorageConfigName
|
|
460
|
+
type: StorageTypes
|
|
461
|
+
organization_name: str
|
|
462
|
+
creator_name: str
|
|
463
|
+
s3: typing.Optional[StorageS3Out]
|
|
464
|
+
gcp: typing.Optional[StorageGCPOut]
|
|
465
|
+
# azure: typing.Optional[StorageAzureOut]
|
|
466
|
+
git: typing.Optional[StorageGitOut]
|