bfabric-web-apps 0.2.0__py3-none-any.whl → 0.2.2__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.
@@ -63,4 +63,7 @@ TRX_SSH_KEY = config.TRX_SSH_KEY
63
63
  URL = config.URL
64
64
 
65
65
  SERVICE_ID = config.SERVICE_ID
66
- DATASET_TEMPLATE_ID = config.DATASET_TEMPLATE_ID
66
+ DATASET_TEMPLATE_ID = config.DATASET_TEMPLATE_ID
67
+
68
+ REDIS_USERNAME = config.REDIS_USERNAME
69
+ REDIS_PASSWORD = config.REDIS_PASSWORD
@@ -88,7 +88,8 @@ class BfabricInterface( Bfabric ):
88
88
  if current_time > datetime.datetime.strptime(expiry_time, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(days=7):
89
89
  return "EXPIRED"
90
90
 
91
- environment_dict = {"Production":"https://fgcz-bfabric.uzh.ch/bfabric","Test":"https://fgcz-bfabric-test.uzh.ch/bfabric"}
91
+ envioronment_name = str(userinfo['environment']).strip().lower()
92
+ environment_dict = {"production":"https://fgcz-bfabric.uzh.ch/bfabric","prod":"https://fgcz-bfabric.uzh.ch/bfabric","test":"https://fgcz-bfabric-test.uzh.ch/bfabric"}
92
93
 
93
94
  token_data = dict(
94
95
  environment = userinfo['environment'],
@@ -96,7 +97,7 @@ class BfabricInterface( Bfabric ):
96
97
  token_expires = expiry_time,
97
98
  entity_id_data = userinfo['entityId'],
98
99
  entityClass_data = userinfo['entityClassName'],
99
- webbase_data = environment_dict.get(userinfo['environment'], None),
100
+ webbase_data = environment_dict[envioronment_name],
100
101
  application_params_data = {},
101
102
  application_data = str(userinfo['applicationId']),
102
103
  userWsPassword = userinfo['userWsPassword'],
@@ -129,10 +130,9 @@ class BfabricInterface( Bfabric ):
129
130
  Returns:
130
131
  Bfabric: An authenticated Bfabric instance.
131
132
  """
132
-
133
+
133
134
  bfabric_auth = BfabricAuth(login=token_response.get('user_data'), password=token_response.get('userWsPassword'))
134
- bfabric_client_config = BfabricClientConfig(base_url=token_response.get('webbase_data'))
135
-
135
+ bfabric_client_config = BfabricClientConfig(base_url=token_response['webbase_data'])
136
136
  bfabric_wrapper = bfabric.Bfabric(config=bfabric_client_config, auth=bfabric_auth)
137
137
 
138
138
  return bfabric_wrapper
@@ -18,7 +18,7 @@ class Logger:
18
18
  Args:
19
19
  jobid (int): The ID of the current job.
20
20
  username (str): The name of the user performing the operations.
21
- environment (str): The environment (e.g., Production, Test).
21
+ environment (str): The environment (e.g., production, test).
22
22
  """
23
23
  self.jobid = jobid
24
24
  self.username = username
@@ -53,6 +53,8 @@ def process_url_and_token(url_params):
53
53
  ) if tdata else "Bfabric App Interface"
54
54
 
55
55
  environment = tdata.get("environment", "").strip().lower() # 'test' or 'prod'
56
+ tdata["environment"] = environment.lower()
57
+
56
58
  job_id = tdata.get("jobId", None) # Extract job ID
57
59
 
58
60
  job_link = None
@@ -114,8 +116,6 @@ def submit_bug_report(n_clicks, bug_description, token, entity_data):
114
116
  else:
115
117
  token_data = {}
116
118
 
117
- print(token_data)
118
-
119
119
  # Extract logging-related information from token_data, with defaults for missing values
120
120
  jobId = token_data.get('jobId', None)
121
121
  username = token_data.get("user_data", "None")
@@ -184,8 +184,8 @@ def populate_workunit_details(token_data):
184
184
  """
185
185
 
186
186
  environment_urls = {
187
- "Test": "https://fgcz-bfabric-test.uzh.ch/bfabric/workunit/show.html?id=",
188
- "Production": "https://fgcz-bfabric.uzh.ch/bfabric/workunit/show.html?id="
187
+ "test": "https://fgcz-bfabric-test.uzh.ch/bfabric/workunit/show.html?id=",
188
+ "production": "https://fgcz-bfabric.uzh.ch/bfabric/workunit/show.html?id="
189
189
  }
190
190
 
191
191
  if token_data:
@@ -223,7 +223,7 @@ def populate_workunit_details(token_data):
223
223
  html.P(f"Status: {wu.get('status', 'n/a')}")
224
224
  ])
225
225
  ], style={"width": "400px", "margin":"10px"}),
226
- href=environment_urls[token_data.get("environment", "Test")] + str(wu["id"]),
226
+ href=environment_urls[token_data.get("environment", "test")] + str(wu["id"]),
227
227
  target="_blank",
228
228
  style={"text-decoration": "none"}
229
229
  )
@@ -1,10 +1,14 @@
1
1
  from pydantic_settings import BaseSettings
2
2
  from pydantic import EmailStr
3
+ from typing import Optional
3
4
 
4
5
  class Settings(BaseSettings):
5
6
 
6
7
  REDIS_HOST: str = "localhost"
7
8
  REDIS_PORT: int = 6379
9
+
10
+ REDIS_USERNAME: Optional[str] = None
11
+ REDIS_PASSWORD: Optional[str] = None
8
12
 
9
13
  CONFIG_FILE_PATH: str = "~/.bfabricpy.yml"
10
14
 
@@ -3,4 +3,12 @@ from .config import settings as config
3
3
 
4
4
  from redis import Redis
5
5
 
6
- redis_conn = Redis(host=config.REDIS_HOST, port=config.REDIS_PORT)
6
+ if config.REDIS_USERNAME and config.REDIS_PASSWORD:
7
+ redis_conn = Redis(
8
+ host=config.REDIS_HOST,
9
+ port=config.REDIS_PORT,
10
+ username=config.REDIS_USERNAME,
11
+ password=config.REDIS_PASSWORD
12
+ )
13
+ else:
14
+ redis_conn = Redis(host=config.REDIS_HOST, port=config.REDIS_PORT)
@@ -20,15 +20,45 @@ def keepalive_ping(conn, interval=60):
20
20
  print("Redis keepalive ping failed:", e)
21
21
  time.sleep(interval)
22
22
 
23
- def run_worker(host, port, queue_names):
23
+ def run_worker(host, port, queue_names, username=None, password=None):
24
24
  """
25
25
  Starts an RQ worker with a background Redis keepalive thread to prevent Azure from dropping idle connections.
26
26
  """
27
- conn = redis.Redis(
28
- host=host,
29
- port=port,
30
- socket_keepalive=True
31
- )
27
+
28
+ def build_redis(protocol=2):
29
+
30
+ if username and password:
31
+
32
+ print("Connecting to Redis with authentication.")
33
+ print(f"Host: {host}, Port: {port}, Username: {username}")
34
+
35
+ conn = redis.Redis(
36
+ host=host,
37
+ port=port,
38
+ username=username,
39
+ password=password,
40
+ socket_keepalive=True,
41
+ protocol=protocol
42
+ )
43
+
44
+ else:
45
+
46
+ print("Connecting to Redis without authentication.")
47
+ print(f"Host: {host}, Port: {port}")
48
+
49
+ conn = redis.Redis(
50
+ host=host,
51
+ port=port,
52
+ socket_keepalive=True,
53
+ protocol=protocol
54
+ )
55
+ return conn
56
+
57
+ try:
58
+ conn = build_redis(protocol=2)
59
+ except Exception as e:
60
+ print("Failed to connect to Redis with protocol 2, trying protocol 3...")
61
+ conn = build_redis(protocol=3)
32
62
 
33
63
  # Start Redis keepalive thread
34
64
  threading.Thread(target=keepalive_ping, args=(conn,), daemon=True).start()
@@ -211,6 +211,8 @@ def save_files_from_bytes(files_as_byte_strings: dict, logger):
211
211
  for destination, file_bytes in files_as_byte_strings.items():
212
212
  try:
213
213
  # Write file from byte string
214
+ if destination.startswith("~"):
215
+ destination = os.path.expanduser(destination)
214
216
  with open(destination, "+wb") as f:
215
217
  f.write(file_bytes)
216
218
  logger.log_operation("File saved | ORIGIN: run_main_job function", f"File {destination} saved successfully.", params=None, flush_logs=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bfabric-web-apps
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A package containing handy boilerplate utilities for developing bfabric web-applications
5
5
  Author: Marc Zuber, Griffin White, GWC GmbH
6
6
  Requires-Python: >=3.10,<4.0
@@ -0,0 +1,22 @@
1
+ bfabric_web_apps/__init__.py,sha256=4ldtAK1Qs9l5xb8t2M3VL4oRmpQB5Qi71z2VZtfJGRI,1794
2
+ bfabric_web_apps/layouts/layouts.py,sha256=z8gL4n4wwLdpLGomO9CftBLnGpc3r6OpmUc2-wBg8uo,14661
3
+ bfabric_web_apps/objects/BfabricInterface.py,sha256=iz3m3SXtUVaEMm0ZRm-2IFePd2UkVu1ob87mq1ogLXA,10751
4
+ bfabric_web_apps/objects/Logger.py,sha256=TdioFzxTHuXTRD1X2N9Pm2OlqcoPTzzXy_WQyt7lSNA,5224
5
+ bfabric_web_apps/utils/app_init.py,sha256=RCdpCXp19cF74bouYJLPe-KSETZ0Vwqtd02Ta2VXEF8,428
6
+ bfabric_web_apps/utils/callbacks.py,sha256=6ji5qsJpJa6MUnrwF_ypGRkSxjOv24-X-o9HREyjGQA,12716
7
+ bfabric_web_apps/utils/charging.py,sha256=oNNazH59SFkbxJKPvCel0IxdsRHC8xpJ0AXCLvI88FI,1069
8
+ bfabric_web_apps/utils/components.py,sha256=X3NRnv--LsHWMtWL83Pzr2whOZLSEJIwXTklQdAQpZE,984
9
+ bfabric_web_apps/utils/config.py,sha256=gqTsO5tFWL7JVTzZgSk5xiyCrhJsBz3veoPBqHWAKC4,1324
10
+ bfabric_web_apps/utils/create_app_in_bfabric.py,sha256=Z7puke8QB4SBuDJ9x3_OjgApzovKu0Nt1g8EqkOHJpc,2758
11
+ bfabric_web_apps/utils/dataset_utils.py,sha256=p_UtoOl1kJpSm2BGdg31Ji0C7ctst40wp4LX1tUe4tI,3360
12
+ bfabric_web_apps/utils/get_logger.py,sha256=0Y3SrXW93--eglS0_ZOc34NOriAt6buFPik5n0ltzRA,434
13
+ bfabric_web_apps/utils/get_power_user_wrapper.py,sha256=T33z64XjmJ0KSlmfEmrEP8eYpbpINCVD6Xld_V7PR2g,1027
14
+ bfabric_web_apps/utils/redis_connection.py,sha256=TPROVkI_gqlbiOorADfhpt26gby4xe7ppmxe8paVh8A,368
15
+ bfabric_web_apps/utils/redis_queue.py,sha256=MCx7z_I2NusJ4P42mcLvV7STtXBFMIIvun83fM8zOGI,168
16
+ bfabric_web_apps/utils/redis_worker_init.py,sha256=W_7XbvbGK7yDi2v7wO0WQJls0XYCsjs9ucn6-DLkPWc,1939
17
+ bfabric_web_apps/utils/resource_utilities.py,sha256=N4EiUkxXHZ18jnU2OuRqaGSroCZ73Ogb9lkeA21Kvq4,5716
18
+ bfabric_web_apps/utils/run_main_pipeline.py,sha256=-5o2QZW27OIvPJ_BtJ3s5UXoONOUcgUeXH4RSTN8oZg,23219
19
+ bfabric_web_apps-0.2.2.dist-info/LICENSE,sha256=k0O_i2k13i9e35aO-j7FerJafAqzzu8x0kkBs0OWF3c,1065
20
+ bfabric_web_apps-0.2.2.dist-info/METADATA,sha256=FpsbVNdputwhaI3gZLnMms1F0inGRMKdatzZh89uycQ,687
21
+ bfabric_web_apps-0.2.2.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
22
+ bfabric_web_apps-0.2.2.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- bfabric_web_apps/__init__.py,sha256=eRYBvXrDM8Bhdm7cbI80L1hjtbRFqUasJiBW52Hx3TI,1715
2
- bfabric_web_apps/layouts/layouts.py,sha256=z8gL4n4wwLdpLGomO9CftBLnGpc3r6OpmUc2-wBg8uo,14661
3
- bfabric_web_apps/objects/BfabricInterface.py,sha256=cEUcAdr4iUH8aS2VGe3CFnAbNQiTj13hYuSVcDg725A,10646
4
- bfabric_web_apps/objects/Logger.py,sha256=62LC94xhm7YG5LUw3yH46NqvJQsAX7wnc9D4zbY16rA,5224
5
- bfabric_web_apps/utils/app_init.py,sha256=RCdpCXp19cF74bouYJLPe-KSETZ0Vwqtd02Ta2VXEF8,428
6
- bfabric_web_apps/utils/callbacks.py,sha256=tB1xtHl_ePY6KJWNz3erkrZw3HFhRneewGqZm9xIYtI,12687
7
- bfabric_web_apps/utils/charging.py,sha256=oNNazH59SFkbxJKPvCel0IxdsRHC8xpJ0AXCLvI88FI,1069
8
- bfabric_web_apps/utils/components.py,sha256=X3NRnv--LsHWMtWL83Pzr2whOZLSEJIwXTklQdAQpZE,984
9
- bfabric_web_apps/utils/config.py,sha256=F4EExu7EkY7upOnxk6BU6zTLt9eU6_iy2y8esIlxTSc,1209
10
- bfabric_web_apps/utils/create_app_in_bfabric.py,sha256=Z7puke8QB4SBuDJ9x3_OjgApzovKu0Nt1g8EqkOHJpc,2758
11
- bfabric_web_apps/utils/dataset_utils.py,sha256=p_UtoOl1kJpSm2BGdg31Ji0C7ctst40wp4LX1tUe4tI,3360
12
- bfabric_web_apps/utils/get_logger.py,sha256=0Y3SrXW93--eglS0_ZOc34NOriAt6buFPik5n0ltzRA,434
13
- bfabric_web_apps/utils/get_power_user_wrapper.py,sha256=T33z64XjmJ0KSlmfEmrEP8eYpbpINCVD6Xld_V7PR2g,1027
14
- bfabric_web_apps/utils/redis_connection.py,sha256=qXSPxW6m55Ogv44BhmPCl9ACuvzmpfZNU73UJhHRXL4,133
15
- bfabric_web_apps/utils/redis_queue.py,sha256=MCx7z_I2NusJ4P42mcLvV7STtXBFMIIvun83fM8zOGI,168
16
- bfabric_web_apps/utils/redis_worker_init.py,sha256=wtjQL48PLNXD1s-5s3Oq5EC8BmcfKcd7IhUbTH_EYz8,1014
17
- bfabric_web_apps/utils/resource_utilities.py,sha256=N4EiUkxXHZ18jnU2OuRqaGSroCZ73Ogb9lkeA21Kvq4,5716
18
- bfabric_web_apps/utils/run_main_pipeline.py,sha256=whmUbO9mMom9voOCv7iS51wh6St4DfawCD337BuPvtY,23112
19
- bfabric_web_apps-0.2.0.dist-info/LICENSE,sha256=k0O_i2k13i9e35aO-j7FerJafAqzzu8x0kkBs0OWF3c,1065
20
- bfabric_web_apps-0.2.0.dist-info/METADATA,sha256=vhqne76HPRsHA9uFhTPgP7wudTKYJq74V7GEQYR9S1I,687
21
- bfabric_web_apps-0.2.0.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
22
- bfabric_web_apps-0.2.0.dist-info/RECORD,,