valar 1.0.18__py3-none-any.whl → 1.0.19__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.
Potentially problematic release.
This version of valar might be problematic. Click here for more details.
- valar/data/file/__init__.py +91 -0
- valar/data/migrations/0001_initial.py +172 -516
- valar/data/models.py +15 -6
- valar/data/orm/__init__.py +33 -8
- valar/data/orm/meta.py +59 -6
- valar/data/orm/meta_frame.py +49 -0
- valar/data/orm/meta_loader.py +70 -19
- valar/data/orm/values.py +11 -2
- valar/data/urls.py +3 -0
- valar/data/views.py +56 -7
- {valar-1.0.18.dist-info → valar-1.0.19.dist-info}/METADATA +5 -1
- valar-1.0.19.dist-info/RECORD +27 -0
- {valar-1.0.18.dist-info → valar-1.0.19.dist-info}/WHEEL +1 -1
- valar/data/migrations/0002_valatree_alter_metafield_allow_sort.py +0 -36
- valar-1.0.18.dist-info/RECORD +0 -26
- {valar-1.0.18.dist-info → valar-1.0.19.dist-info}/licenses/LICENSE +0 -0
- {valar-1.0.18.dist-info → valar-1.0.19.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from io import BytesIO
|
|
3
|
+
|
|
4
|
+
from django.conf import settings
|
|
5
|
+
from minio import Minio
|
|
6
|
+
from urllib3 import HTTPResponse
|
|
7
|
+
|
|
8
|
+
def minio_upload_object(bucket_name, object_name, _bytes):
|
|
9
|
+
client = __get_minio_client__()
|
|
10
|
+
__create_bucket__(bucket_name, client)
|
|
11
|
+
file_data = BytesIO(_bytes)
|
|
12
|
+
file_size = len(_bytes) # file.siz
|
|
13
|
+
client.put_object(bucket_name=bucket_name, object_name=object_name, data=file_data, length=file_size)
|
|
14
|
+
return f'{bucket_name}/{object_name}'
|
|
15
|
+
|
|
16
|
+
def minio_remove_object(bucket_name, object_name):
|
|
17
|
+
client = __get_minio_client__()
|
|
18
|
+
client.remove_object(bucket_name=bucket_name, object_name=object_name)
|
|
19
|
+
|
|
20
|
+
def minio_remove_path(path):
|
|
21
|
+
[bucket_name, object_name] = path.split('/')
|
|
22
|
+
client = __get_minio_client__()
|
|
23
|
+
client.remove_object(bucket_name=bucket_name, object_name=object_name)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def minio_read_object(bucket_name, object_name) -> HTTPResponse:
|
|
27
|
+
client = __get_minio_client__()
|
|
28
|
+
return client.get_object(bucket_name=bucket_name, object_name=object_name)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def __get_minio_client__(bucket_name=None):
|
|
35
|
+
options = settings.MINIO_SETTINGS
|
|
36
|
+
client = Minio(**options)
|
|
37
|
+
if bucket_name:
|
|
38
|
+
__create_bucket__(bucket_name, client)
|
|
39
|
+
return client
|
|
40
|
+
|
|
41
|
+
def __create_bucket__(bucket_name, client=None):
|
|
42
|
+
client = client or __get_minio_client__()
|
|
43
|
+
exists = client.bucket_exists(bucket_name)
|
|
44
|
+
if not exists:
|
|
45
|
+
client.make_bucket(bucket_name)
|
|
46
|
+
policy = generate_policy(bucket_name)
|
|
47
|
+
client.set_bucket_policy(bucket_name, policy)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_minio_bucket_name(entity):
|
|
51
|
+
value = f'{settings.BASE_DIR.name}.{entity}'
|
|
52
|
+
bucket_name = value.replace('_','-').lower()
|
|
53
|
+
__create_bucket__(bucket_name)
|
|
54
|
+
return bucket_name
|
|
55
|
+
|
|
56
|
+
def get_minio_object_name(_id, prop, file_name):
|
|
57
|
+
return f"{_id}-{prop}-{file_name}"
|
|
58
|
+
|
|
59
|
+
def generate_policy(bucket_name):
|
|
60
|
+
return json.dumps({
|
|
61
|
+
"Version": "2012-10-17",
|
|
62
|
+
"Statement": [
|
|
63
|
+
{
|
|
64
|
+
"Sid": "",
|
|
65
|
+
"Effect": "Allow",
|
|
66
|
+
"Principal": {"AWS": "*"},
|
|
67
|
+
"Action": "s3:GetBucketLocation",
|
|
68
|
+
"Resource": f"arn:aws:s3:::{bucket_name}"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"Sid": "",
|
|
72
|
+
"Effect": "Allow",
|
|
73
|
+
"Principal": {"AWS": "*"},
|
|
74
|
+
"Action": "s3:ListBucket",
|
|
75
|
+
"Resource": f"arn:aws:s3:::{bucket_name}"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"Sid": "",
|
|
79
|
+
"Effect": "Allow",
|
|
80
|
+
"Principal": {"AWS": "*"},
|
|
81
|
+
"Action": "s3:GetObject",
|
|
82
|
+
"Resource": f"arn:aws:s3:::{bucket_name}/*"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"Sid": "",
|
|
86
|
+
"Effect": "Allow",
|
|
87
|
+
"Principal": {"AWS": "*"},
|
|
88
|
+
"Action": "s3:PutObject",
|
|
89
|
+
"Resource": f"arn:aws:s3:::{bucket_name}/*"
|
|
90
|
+
}
|
|
91
|
+
]})
|