talentro-commons 0.19.9__py3-none-any.whl → 0.19.10__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.
@@ -6,8 +6,8 @@ from enum import StrEnum
6
6
  from http import HTTPStatus
7
7
 
8
8
  from fastapi import UploadFile
9
- from google.api_core.exceptions import NotFound
10
9
  from google.cloud import storage
10
+ from google.cloud.exceptions import NotFound
11
11
  from google.cloud.storage import Bucket, Blob
12
12
  from talentro.constants import ErrorCode, DisplayMessage
13
13
  from talentro.exceptions import APIException
@@ -18,9 +18,10 @@ from ..util.string import render_template_path
18
18
 
19
19
 
20
20
  class BucketEnum(StrEnum):
21
- PUBLIC = "talentro-static"
22
- BILLING = "talentro-billing"
23
- CANDIDATES = "talentro-candidates"
21
+ PUBLIC = "static"
22
+ BILLING = "billing"
23
+ CANDIDATES = "candidates"
24
+ SYSTEM = "system"
24
25
 
25
26
 
26
27
  class FilePathEnum(StrEnum):
@@ -28,14 +29,20 @@ class FilePathEnum(StrEnum):
28
29
  IAM_PROFILE_PICTURE = "iam/users/{user_id}/profile/profile_picture.{extension}"
29
30
  CANDIDATES_CANDIDATE_CV_FILE = "organizations/{organization_id}/cand_{candidate_id}/cv/{file_name}"
30
31
  CANDIDATES_CANDIDATE_CV_FOLDER = "organizations/{organization_id}/cand_{candidate_id}/cv/"
32
+ SYSTEM_DPG_SYNC = "dpg/last_sync.txt"
31
33
 
32
34
 
33
35
  class GoogleStorage(metaclass=SingletonMeta):
34
36
 
35
37
  def __init__(self):
36
38
  self._client = storage.Client()
39
+ self.env = os.getenv("ENVIRONMENT")
37
40
 
38
- def upload_base64_to_gcs(self, file: FileData, bucket: BucketEnum, destination: FilePathEnum, path_definitions: dict) -> Blob:
41
+ if not self.env:
42
+ raise Exception("Environment variable ENVIRONMENT is not set.")
43
+
44
+ def upload_base64_to_gcs(self, file: FileData, bucket: BucketEnum, destination: FilePathEnum,
45
+ path_definitions: dict | None = None) -> Blob:
39
46
  file_bytes = base64.b64decode(file.data)
40
47
 
41
48
  _, ext = os.path.splitext(file.file_name)
@@ -49,7 +56,7 @@ class GoogleStorage(metaclass=SingletonMeta):
49
56
 
50
57
  blob.upload_from_filename(
51
58
  tmp_path,
52
- content_type=file.content_type # handig voor GCS metadata
59
+ content_type=file.content_type # Handig voor GCS metadata
53
60
  )
54
61
 
55
62
  if os.path.exists(tmp_path):
@@ -61,12 +68,13 @@ class GoogleStorage(metaclass=SingletonMeta):
61
68
  try:
62
69
  bucket = self._client.get_bucket(bucket.value)
63
70
  except NotFound:
64
- print("Bucket not found.")
71
+ print(f"Bucket {bucket.value} not found, creating...")
65
72
  bucket = self._client.create_bucket(bucket.value)
66
73
 
67
74
  return bucket
68
75
 
69
- def _get_blob(self, bucket: BucketEnum, destination: FilePathEnum, path_definitions: dict):
76
+ def _get_blob(self, bucket: BucketEnum, destination: FilePathEnum, path_definitions: dict | None = None):
77
+
70
78
  bucket = self._get_bucket(bucket)
71
79
 
72
80
  try:
@@ -118,7 +126,8 @@ class GoogleStorage(metaclass=SingletonMeta):
118
126
  traceback.print_exc()
119
127
  return False
120
128
 
121
- def upload_file(self, file: UploadFile, bucket: BucketEnum, destination: FilePathEnum, path_definitions: dict) -> Blob:
129
+ def upload_file(self, file: UploadFile, bucket: BucketEnum, destination: FilePathEnum,
130
+ path_definitions: dict) -> Blob:
122
131
  """
123
132
  Uploads a file to Google Storage
124
133
 
talentro/util/string.py CHANGED
@@ -1,10 +1,16 @@
1
1
  import string
2
2
 
3
- def render_template_path(template: str, values: dict) -> str:
3
+ def render_template_path(template: str, values: dict | None) -> str:
4
4
  formatter = string.Formatter()
5
5
 
6
6
  required_fields = [field for _, field, _, _ in formatter.parse(template) if field]
7
7
 
8
+ if required_fields is None or required_fields is []:
9
+ return template
10
+
11
+ if not values:
12
+ raise ValueError(f"Values are expected but not set")
13
+
8
14
  missing = [field for field in required_fields if field not in values]
9
15
 
10
16
  if missing:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: talentro-commons
3
- Version: 0.19.9
3
+ Version: 0.19.10
4
4
  Summary: This package contains all globally used code, services, models and data structures for Talentro
5
5
  License: Proprietary
6
6
  Author: Emiel van Essen
@@ -26,19 +26,19 @@ talentro/services/billing.py,sha256=Y2UaQK8lSRa3G8lTZKqLi4t-Jc-EWd7Yn15nR9HOAx8,
26
26
  talentro/services/caching.py,sha256=mmjhXAMJ_g8D8cJqn15YqZ7ST-G5lD9MS-PmlowI7pU,2921
27
27
  talentro/services/clients.py,sha256=vluOrdYdDAQLyGR9-EmogLjA9OUlJtHy0tYD9LhwxKg,2174
28
28
  talentro/services/db.py,sha256=cnKCrYG7GwIu7ZZhA25D-yaXaiCJqPpzfcanWquyrBY,822
29
- talentro/services/google_storage.py,sha256=p7fX9u8rWLS0DHcw-4aYVJAqkA_RYkDgEBGH6zmpzdA,4835
29
+ talentro/services/google_storage.py,sha256=edol1h4lXshcJSoFr8tUPNR5hX8W619D_cAUTD4-Pyk,5121
30
30
  talentro/services/rabbitmq.py,sha256=RNIsLqXM48z5SRRqJ3iWqhRp6FL9TwRwEeii_m8-xDo,6854
31
31
  talentro/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
32
  talentro/util/attributes.py,sha256=PgJnn9LMtHkiNIaMov2HQt5944HweD6gRlAHBZrJGPA,448
33
33
  talentro/util/enum.py,sha256=YftsoJKnrn8HAjA2Q1tqIYBMrNnlq6m1b34N8hfykbE,155
34
34
  talentro/util/files.py,sha256=0pfISW89XC5kNyFooHebjVdmMnP-L49uIpKY5DjGuN4,176
35
35
  talentro/util/singleton.py,sha256=nM5XgRa75xF6gX4BZKlkvjtZJQ3OFFEsANLVLnsyxmM,635
36
- talentro/util/string.py,sha256=KJmN96w1E63r4-7P4MKahEnetb4IMz1VpYmuBIT0MW4,398
36
+ talentro/util/string.py,sha256=i8oODLdCj6F3-9jgdgyLzNfoMM3i5ee_8SkovENnw5s,568
37
37
  talentro/util/vacancy.py,sha256=mZ_ruL_YPsbJjaUEti78_6TumXhOGAY7Taa2JvXkTkg,1067
38
38
  talentro/vacancies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
39
39
  talentro/vacancies/dataclasses.py,sha256=E6H5fsZH4IwtBFSLDolzF6u39tEIrANtWiNVoB65P0c,15074
40
40
  talentro/vacancies/models.py,sha256=GoXr71CNzU6csf8gdmv84etb3Rm-Cdfigp1yqPI_jjQ,4822
41
41
  talentro/vacancies/taxanomy.py,sha256=K3f0yD5g-oxhLXSYNY4WSsGzBfBIb6ngsTDVNGbqO30,6324
42
- talentro_commons-0.19.9.dist-info/METADATA,sha256=SaULkE38ZGSyPMutptjhRGCpQf4yL-WZmVi_Q0yCW40,1507
43
- talentro_commons-0.19.9.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
44
- talentro_commons-0.19.9.dist-info/RECORD,,
42
+ talentro_commons-0.19.10.dist-info/METADATA,sha256=eLypP7xaBLwQxtc8ilGhxDOwj2qwch6mQoRiI6RE8RE,1508
43
+ talentro_commons-0.19.10.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
44
+ talentro_commons-0.19.10.dist-info/RECORD,,