hid_data_transfer_lib 0.3.11__tar.gz → 0.4.0__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.
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/PKG-INFO +2 -2
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/README.md +1 -1
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/hid_dt_configuration.py +74 -70
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/hid_dt_lib.py +65 -6
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/keycloak/keycloak_rest.py +4 -2
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/nifi/nifi_client.py +13 -5
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/pyproject.toml +2 -1
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/__init__.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/__init__.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/hid_dt.cfg +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/hid_dt_local.cfg +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/hid_dt_psnc.cfg +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/exceptions/__init__.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/exceptions/hid_dt_exceptions.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/keycloak/__init__.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/nifi/__init__.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/nifi/nifi_rest.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/py.typed +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/util/__init__.py +0 -0
- {hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/util/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hid_data_transfer_lib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: HiDALGO Data Transfer library provides methods to transfer data between different data providers and consumers using NIFI pipelines
|
|
5
5
|
License: APL-2.0
|
|
6
6
|
Author: Jesús Gorroñogoitia
|
|
@@ -123,7 +123,7 @@ keycloak_login=<user_name>
|
|
|
123
123
|
keycloak_password=<password>
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
Under the Nifi section, you must also specify a user account (username, private_key) that grants to upload/download files to the NIFI server (as requested to upload temporary HPC keys or to support local file transfer). This user's account is provided by Hidalgo2 infrastructure provider and it is user's or service's specific.
|
|
126
|
+
Under the Nifi section, you must also specify a user account (username, private_key) that grants to upload/download files to the NIFI server (as requested to upload temporary HPC keys or to support local file transfer). This user's account is provided by Hidalgo2 infrastructure provider and it is user's or service's specific. Note: this user's account requires to belond to group *users*.
|
|
127
127
|
|
|
128
128
|
Under the Keycloak section, you must specify your Keycloak account (username and password). This account granted with access to the NIFI service.
|
|
129
129
|
|
|
@@ -104,7 +104,7 @@ keycloak_login=<user_name>
|
|
|
104
104
|
keycloak_password=<password>
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
Under the Nifi section, you must also specify a user account (username, private_key) that grants to upload/download files to the NIFI server (as requested to upload temporary HPC keys or to support local file transfer). This user's account is provided by Hidalgo2 infrastructure provider and it is user's or service's specific.
|
|
107
|
+
Under the Nifi section, you must also specify a user account (username, private_key) that grants to upload/download files to the NIFI server (as requested to upload temporary HPC keys or to support local file transfer). This user's account is provided by Hidalgo2 infrastructure provider and it is user's or service's specific. Note: this user's account requires to belond to group *users*.
|
|
108
108
|
|
|
109
109
|
Under the Keycloak section, you must specify your Keycloak account (username and password). This account granted with access to the NIFI service.
|
|
110
110
|
|
|
@@ -24,6 +24,7 @@ from hid_data_transfer_lib.exceptions.hid_dt_exceptions import (
|
|
|
24
24
|
HidDataTransferException
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
+
STATUS_SLEEP_LAPSE = 10 # seconds
|
|
27
28
|
|
|
28
29
|
class HidDataTransferConfiguration:
|
|
29
30
|
"""This class manages the configuration of the Data Transfer library"""
|
|
@@ -44,21 +45,22 @@ class HidDataTransferConfiguration:
|
|
|
44
45
|
__keycloak_login = None
|
|
45
46
|
__keycloak_passwd = None
|
|
46
47
|
|
|
47
|
-
__check_status_sleep_lapse =
|
|
48
|
+
__check_status_sleep_lapse = STATUS_SLEEP_LAPSE # seconds
|
|
48
49
|
|
|
49
50
|
def __init__(self, logging_level: Optional[int] = logging.INFO):
|
|
50
51
|
self.__logging_level = logging_level
|
|
51
52
|
|
|
52
|
-
def check_keycloak_conf(self):
|
|
53
|
+
def check_keycloak_conf(self, use_keycloak_account):
|
|
53
54
|
"""Check if keycloak configuration is valid"""
|
|
54
|
-
if
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
if use_keycloak_account:
|
|
56
|
+
if self.__keycloak_login is None:
|
|
57
|
+
raise HidDataTransferException(
|
|
58
|
+
"Keycloak login must be set in the configuration"
|
|
59
|
+
)
|
|
60
|
+
if self.__keycloak_passwd is None:
|
|
61
|
+
raise HidDataTransferException(
|
|
62
|
+
"Keycloak passwd must be set in the configuration"
|
|
63
|
+
)
|
|
62
64
|
if self.__keycloak_endpoint is None:
|
|
63
65
|
raise HidDataTransferException(
|
|
64
66
|
"Keycloak endpoint must be set in the configuration"
|
|
@@ -195,6 +197,14 @@ class HidDataTransferConfiguration:
|
|
|
195
197
|
"""Returns the NIFI login password"""
|
|
196
198
|
return self.__keycloak_passwd
|
|
197
199
|
|
|
200
|
+
def reset_keycloak_login(self):
|
|
201
|
+
"""Reset the NIFI login name"""
|
|
202
|
+
self.__keycloak_login = None
|
|
203
|
+
|
|
204
|
+
def reset_keycloak_passwd(self):
|
|
205
|
+
"""Reset the NIFI login password"""
|
|
206
|
+
self.__keycloak_passwd = None
|
|
207
|
+
|
|
198
208
|
def logger(self, logger_name):
|
|
199
209
|
"""Returns the logging level"""
|
|
200
210
|
return self.__set_logger(logger_name)
|
|
@@ -256,7 +266,8 @@ class HidDataTransferConfiguration:
|
|
|
256
266
|
self,
|
|
257
267
|
user_config_file: Optional[str] = None,
|
|
258
268
|
user_config_dict: Optional[dict] = None,
|
|
259
|
-
logging_level: Optional[int] = None
|
|
269
|
+
logging_level: Optional[int] = None,
|
|
270
|
+
use_keycloak_account: Bool = True,
|
|
260
271
|
) -> HidDataTransferConfiguration:
|
|
261
272
|
"""
|
|
262
273
|
Reads the configuration and sets this class' configuration values
|
|
@@ -276,38 +287,33 @@ class HidDataTransferConfiguration:
|
|
|
276
287
|
self.load_nifi_configuration(config)
|
|
277
288
|
|
|
278
289
|
# Keycloak section
|
|
279
|
-
self.load_keycloak_configuration(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
290
|
+
self.load_keycloak_configuration(
|
|
291
|
+
config, check_configuration = use_keycloak_account)
|
|
292
|
+
|
|
293
|
+
# # Check if either NIFI or Keycloak login and password are set
|
|
294
|
+
# if not use_keycloak_token and (
|
|
295
|
+
# self.__nifi_login is None and self.__nifi_passwd is None
|
|
296
|
+
# ) and (
|
|
297
|
+
# self.__keycloak_login is None and
|
|
298
|
+
# self.__keycloak_passwd is None
|
|
299
|
+
# ):
|
|
300
|
+
# raise HidDataTransferException(
|
|
301
|
+
# "Either (KEYCLOAK_LOGIN and KEYCLOAK_PASSWORD) "
|
|
302
|
+
# "or (NIFI_LOGIN and NIFI_PASSWORD) "
|
|
303
|
+
# "environment variables must be set"
|
|
304
|
+
# )
|
|
291
305
|
|
|
292
306
|
# Logging section
|
|
293
307
|
if logging_level is not None:
|
|
294
308
|
self.__logging_level = logging_level
|
|
295
309
|
else:
|
|
296
|
-
logging_level_str = config.get("Logging", "logging_level")
|
|
310
|
+
logging_level_str = config.get("Logging", "logging_level", fallback="Info")
|
|
297
311
|
self.__logging_level = getattr(
|
|
298
312
|
logging, logging_level_str.upper(), logging.INFO)
|
|
299
313
|
|
|
300
314
|
# Network section
|
|
301
|
-
self.__check_status_sleep_lapse = config.get(
|
|
302
|
-
"Network", "check_status_sleep_lapse")
|
|
303
|
-
|
|
304
|
-
# Network section
|
|
305
|
-
self.__check_status_sleep_lapse = config.get(
|
|
306
|
-
"Network", "check_status_sleep_lapse")
|
|
307
|
-
|
|
308
|
-
# Network section
|
|
309
|
-
self.__check_status_sleep_lapse = config.get(
|
|
310
|
-
"Network", "check_status_sleep_lapse")
|
|
315
|
+
self.__check_status_sleep_lapse = int(config.get(
|
|
316
|
+
"Network", "check_status_sleep_lapse", fallback=STATUS_SLEEP_LAPSE))
|
|
311
317
|
|
|
312
318
|
return self
|
|
313
319
|
|
|
@@ -316,69 +322,67 @@ class HidDataTransferConfiguration:
|
|
|
316
322
|
"Error parsing CLI configuration file"
|
|
317
323
|
) from ex
|
|
318
324
|
|
|
319
|
-
def load_keycloak_configuration(self, config):
|
|
325
|
+
def load_keycloak_configuration(self, config, check_configuration = True):
|
|
320
326
|
"""Load Keycloak configuration from config file"""
|
|
321
327
|
# Read Keycloak login and password from configuration
|
|
322
|
-
self.__keycloak_login = config.get("Keycloak", "keycloak_login")
|
|
323
|
-
self.__keycloak_passwd = config.get("Keycloak", "keycloak_password")
|
|
324
|
-
if
|
|
325
|
-
self.__keycloak_login is None
|
|
326
|
-
):
|
|
328
|
+
self.__keycloak_login = config.get("Keycloak", "keycloak_login", fallback=None)
|
|
329
|
+
self.__keycloak_passwd = config.get("Keycloak", "keycloak_password", fallback=None)
|
|
330
|
+
if check_configuration and (
|
|
331
|
+
self.__keycloak_login is None or self.__keycloak_passwd is None):
|
|
327
332
|
raise HidDataTransferException(
|
|
328
333
|
"Both KEYCLOAK_LOGIN and KEYCLOAK_PASSWORD "
|
|
329
334
|
"environment variables must be set"
|
|
330
335
|
)
|
|
331
336
|
|
|
332
337
|
# Read other keycloak configuration from config file
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
)
|
|
338
|
+
self.__keycloak_endpoint = config.get(
|
|
339
|
+
"Keycloak", "keycloak_endpoint", fallback=None)
|
|
340
|
+
if self.__keycloak_endpoint is None:
|
|
341
|
+
raise HidDataTransferException(
|
|
342
|
+
"Could not find Keycloak endpoint in config file."
|
|
343
|
+
)
|
|
340
344
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
345
|
+
self.__keycloak_client_id = config.get(
|
|
346
|
+
"Keycloak", "keycloak_client_id", fallback=None)
|
|
347
|
+
if self.__keycloak_client_id is None:
|
|
348
|
+
raise HidDataTransferException(
|
|
349
|
+
"Could not find Keycloak client id "
|
|
350
|
+
"for NIFI in config file."
|
|
351
|
+
)
|
|
348
352
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
keycloak_client_secret = config.get(
|
|
354
|
+
"Keycloak", "keycloak_client_secret", fallback=None)
|
|
355
|
+
if keycloak_client_secret is not None:
|
|
356
|
+
self.__keycloak_client_secret = keycloak_client_secret
|
|
357
|
+
else:
|
|
358
|
+
raise HidDataTransferException(
|
|
359
|
+
"Could not find Keycloak client secret "
|
|
360
|
+
"for NIFI in config file."
|
|
361
|
+
)
|
|
358
362
|
|
|
359
363
|
def load_nifi_configuration(self, config):
|
|
360
364
|
"""Load NIFI configuration from config file"""
|
|
361
|
-
self.__nifi_endpoint = config.get("Nifi", "nifi_endpoint")
|
|
365
|
+
self.__nifi_endpoint = config.get("Nifi", "nifi_endpoint", fallback=None)
|
|
362
366
|
if self.__nifi_endpoint is None:
|
|
363
367
|
raise HidDataTransferException(
|
|
364
368
|
"Could not find Nifi endpoint in config file."
|
|
365
369
|
)
|
|
366
370
|
|
|
367
|
-
nifi_secure_connection = config.get("Nifi", "nifi_secure_connection")
|
|
371
|
+
nifi_secure_connection = config.get("Nifi", "nifi_secure_connection", fallback=None)
|
|
368
372
|
if nifi_secure_connection is not None:
|
|
369
373
|
self.__nifi_secure_connection = \
|
|
370
374
|
nifi_secure_connection.lower() == "true"
|
|
371
375
|
else:
|
|
372
376
|
self.__nifi_secure_connection = False
|
|
373
377
|
|
|
374
|
-
self.__nifi_upload_folder = config.get("Nifi", "nifi_upload_folder")
|
|
378
|
+
self.__nifi_upload_folder = config.get("Nifi", "nifi_upload_folder", fallback=None)
|
|
375
379
|
if self.__nifi_upload_folder is None:
|
|
376
380
|
raise HidDataTransferException(
|
|
377
381
|
"Could not find Nifi nifi_upload_folder in config file"
|
|
378
382
|
)
|
|
379
383
|
|
|
380
384
|
self.__nifi_download_folder = config.get(
|
|
381
|
-
"Nifi", "nifi_download_folder")
|
|
385
|
+
"Nifi", "nifi_download_folder", fallback=None)
|
|
382
386
|
if self.__nifi_download_folder is None:
|
|
383
387
|
raise HidDataTransferException(
|
|
384
388
|
"Could not find Nifi nifi_download_folder in config file"
|
|
@@ -386,9 +390,9 @@ class HidDataTransferConfiguration:
|
|
|
386
390
|
|
|
387
391
|
# Optional NIFI server account in case of local file transfer
|
|
388
392
|
self.__nifi_server_user_name = config.get(
|
|
389
|
-
"Nifi", "nifi_server_username")
|
|
393
|
+
"Nifi", "nifi_server_username", fallback=None)
|
|
390
394
|
self.__nifi_server_private_key = config.get(
|
|
391
|
-
"Nifi", "nifi_server_private_key")
|
|
395
|
+
"Nifi", "nifi_server_private_key", fallback=None)
|
|
392
396
|
|
|
393
397
|
if (
|
|
394
398
|
self.__nifi_server_user_name and
|
|
@@ -400,7 +404,7 @@ class HidDataTransferConfiguration:
|
|
|
400
404
|
"environment variables must be set"
|
|
401
405
|
)
|
|
402
406
|
|
|
403
|
-
nifi_concurrent_tasks = config.get("Nifi", "nifi_concurrent_tasks")
|
|
407
|
+
nifi_concurrent_tasks = config.get("Nifi", "nifi_concurrent_tasks", fallback=None)
|
|
404
408
|
if nifi_concurrent_tasks is not None:
|
|
405
409
|
self.__nifi_concurrent_tasks = int(nifi_concurrent_tasks)
|
|
406
410
|
else:
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/hid_dt_lib.py
RENAMED
|
@@ -35,8 +35,10 @@ from hid_data_transfer_lib.nifi.nifi_client import (
|
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
HDFS_DATA_FOLDER = "hdfs.data_folder"
|
|
38
|
+
HDFS_DATA_FILENAME = "hdfs.data_filename"
|
|
38
39
|
HDFS_FILENAME = "hdfs.filename"
|
|
39
40
|
HPC_TARGET_FOLDER = "hpc.target_folder"
|
|
41
|
+
HPC_TARGET_FILENAME = "hpc.target_filename"
|
|
40
42
|
HPC_DATA_FOLDER = "hpc.data_folder"
|
|
41
43
|
HPC_FILENAME = "hpc.filename"
|
|
42
44
|
HPC_FILENAME_REGEX = "hpc.filename.regex"
|
|
@@ -68,13 +70,16 @@ class HIDDataTransfer:
|
|
|
68
70
|
"""
|
|
69
71
|
self.__conf = conf
|
|
70
72
|
self.__secure = secure
|
|
71
|
-
self.
|
|
73
|
+
self.use_keycloak_account = (keycloak_token is None)
|
|
74
|
+
self.__nifi_client = NIFIClient().configure(
|
|
75
|
+
conf, secure, use_keycloak_account=self.use_keycloak_account)
|
|
72
76
|
self.__logger = self.__conf.logger("hid_data_transfer_lib")
|
|
73
77
|
self.__keycloak_token = keycloak_token
|
|
74
78
|
|
|
75
79
|
def reset(self):
|
|
76
80
|
""" Reset NIFIClient configuration"""
|
|
77
|
-
self.__nifi_client = NIFIClient().configure(
|
|
81
|
+
self.__nifi_client = NIFIClient().configure(
|
|
82
|
+
self.__conf, self.__secure, use_keycloak_account=self.use_keycloak_account)
|
|
78
83
|
|
|
79
84
|
# Helper methods
|
|
80
85
|
def process_wildcards(self, name):
|
|
@@ -173,12 +178,26 @@ class HIDDataTransfer:
|
|
|
173
178
|
try:
|
|
174
179
|
arguments: Dict[str, Any] = {}
|
|
175
180
|
self.__nifi_client.add_default_hpc_parameters(arguments, args)
|
|
176
|
-
|
|
181
|
+
|
|
177
182
|
arguments[HDFS_DATA_FOLDER] = \
|
|
178
183
|
"/".join(args.data_source.split("/")[:-1])
|
|
179
184
|
arguments[HDFS_FILENAME] = \
|
|
180
185
|
self.process_wildcards(args.data_source.split("/")[-1])
|
|
181
186
|
|
|
187
|
+
# If multiple data source files are selected, data_target represents a folder
|
|
188
|
+
# Else If data_target ends with / represents a folder, otherwise a file
|
|
189
|
+
arguments[HPC_TARGET_FILENAME] = ""
|
|
190
|
+
if args.data_source and (
|
|
191
|
+
"*" in args.data_source or
|
|
192
|
+
"?" in args.data_source
|
|
193
|
+
):
|
|
194
|
+
arguments[HPC_TARGET_FOLDER] = args.data_target
|
|
195
|
+
elif args.data_target.endswith('/'):
|
|
196
|
+
arguments[HPC_TARGET_FOLDER] = args.data_target[:-1]
|
|
197
|
+
else:
|
|
198
|
+
arguments[HPC_TARGET_FOLDER] = "/".join(args.data_target.split("/")[:-1])
|
|
199
|
+
arguments[HPC_TARGET_FILENAME] = "/".join(args.data_target.split("/")[-1:])
|
|
200
|
+
|
|
182
201
|
arguments[RECURSIVE] = args.recursive
|
|
183
202
|
|
|
184
203
|
execution_type = {
|
|
@@ -548,7 +567,21 @@ class HIDDataTransfer:
|
|
|
548
567
|
arguments[HPC_DATA_FOLDER] = args.data_source[
|
|
549
568
|
: args.data_source.rfind("/")
|
|
550
569
|
]
|
|
551
|
-
|
|
570
|
+
|
|
571
|
+
# If multiple data source files are selected, data_target represents a folder
|
|
572
|
+
# Else If data_target ends with / represents a folder, otherwise a file
|
|
573
|
+
arguments[HDFS_DATA_FILENAME] = ""
|
|
574
|
+
if args.data_source and (
|
|
575
|
+
"*" in args.data_source or
|
|
576
|
+
"?" in args.data_source
|
|
577
|
+
):
|
|
578
|
+
arguments[HDFS_DATA_FOLDER] = args.data_target
|
|
579
|
+
elif args.data_target.endswith('/'):
|
|
580
|
+
arguments[HDFS_DATA_FOLDER] = args.data_target[:-1]
|
|
581
|
+
else:
|
|
582
|
+
arguments[HDFS_DATA_FOLDER] = "/".join(args.data_target.split("/")[:-1])
|
|
583
|
+
arguments[HDFS_DATA_FILENAME] = "/".join(args.data_target.split("/")[-1:])
|
|
584
|
+
|
|
552
585
|
arguments[RECURSIVE] = args.recursive
|
|
553
586
|
|
|
554
587
|
execution_type = {
|
|
@@ -1038,7 +1071,20 @@ class HIDDataTransfer:
|
|
|
1038
1071
|
self.__nifi_client.add_default_ckan_parameters(arguments, args)
|
|
1039
1072
|
arguments[self.__nifi_client.CKAN_RESOURCE] = \
|
|
1040
1073
|
self.process_wildcards(args.ckan_resource)
|
|
1041
|
-
|
|
1074
|
+
|
|
1075
|
+
# If multiple ckan resource files are selected, data_target represents a folder
|
|
1076
|
+
# Else If data_target ends with / represents a folder, otherwise a file
|
|
1077
|
+
arguments[HDFS_DATA_FILENAME] = ""
|
|
1078
|
+
if args.ckan_resource and (
|
|
1079
|
+
"*" in args.ckan_resource or
|
|
1080
|
+
"?" in args.ckan_resource
|
|
1081
|
+
):
|
|
1082
|
+
arguments[HDFS_DATA_FOLDER] = args.data_target
|
|
1083
|
+
elif args.data_target.endswith('/'):
|
|
1084
|
+
arguments[HDFS_DATA_FOLDER] = args.data_target[:-1]
|
|
1085
|
+
else:
|
|
1086
|
+
arguments[HDFS_DATA_FOLDER] = "/".join(args.data_target.split("/")[:-1])
|
|
1087
|
+
arguments[HDFS_DATA_FILENAME] = "/".join(args.data_target.split("/")[-1:])
|
|
1042
1088
|
|
|
1043
1089
|
execution_type = {
|
|
1044
1090
|
"CKANFileDownloader": ExecutionType.ONCE,
|
|
@@ -1158,11 +1204,24 @@ class HIDDataTransfer:
|
|
|
1158
1204
|
try:
|
|
1159
1205
|
arguments: Dict[str, Any] = {}
|
|
1160
1206
|
self.__nifi_client.add_default_hpc_parameters(arguments, args)
|
|
1161
|
-
arguments[HPC_TARGET_FOLDER] = args.data_target
|
|
1162
1207
|
self.__nifi_client.add_default_ckan_parameters(arguments, args)
|
|
1163
1208
|
arguments[self.__nifi_client.CKAN_RESOURCE] = \
|
|
1164
1209
|
self.process_wildcards(args.ckan_resource)
|
|
1165
1210
|
|
|
1211
|
+
# If multiple ckan resource files are selected, data_target represents a folder
|
|
1212
|
+
# Else If data_target ends with / represents a folder, otherwise a file
|
|
1213
|
+
arguments[HPC_TARGET_FILENAME] = ""
|
|
1214
|
+
if args.ckan_resource and (
|
|
1215
|
+
"*" in args.ckan_resource or
|
|
1216
|
+
"?" in args.ckan_resource
|
|
1217
|
+
):
|
|
1218
|
+
arguments[HPC_TARGET_FOLDER] = args.data_target
|
|
1219
|
+
elif args.data_target.endswith('/'):
|
|
1220
|
+
arguments[HPC_TARGET_FOLDER] = args.data_target[:-1]
|
|
1221
|
+
else:
|
|
1222
|
+
arguments[HPC_TARGET_FOLDER] = "/".join(args.data_target.split("/")[:-1])
|
|
1223
|
+
arguments[HPC_TARGET_FILENAME] = "/".join(args.data_target.split("/")[-1:])
|
|
1224
|
+
|
|
1166
1225
|
keys_arguments = {
|
|
1167
1226
|
self.__nifi_client.HPC_SECRET_KEY_PATH: arguments[
|
|
1168
1227
|
self.__nifi_client.HPC_SECRET_KEY_PATH
|
|
@@ -69,12 +69,13 @@ class KeycloakRESTClient:
|
|
|
69
69
|
|
|
70
70
|
def configure(
|
|
71
71
|
self, conf: HidDataTransferConfiguration,
|
|
72
|
-
secure: bool = False, refresh: bool = False
|
|
72
|
+
secure: bool = False, refresh: bool = False,
|
|
73
|
+
use_keycloak_account = True,
|
|
73
74
|
) -> KeycloakRESTClient:
|
|
74
75
|
"""constructs a API client,
|
|
75
76
|
with the Keycloak endpoint taken from configuration
|
|
76
77
|
"""
|
|
77
|
-
conf.check_keycloak_conf()
|
|
78
|
+
conf.check_keycloak_conf(use_keycloak_account)
|
|
78
79
|
self.__conf = conf
|
|
79
80
|
self.__refresh = refresh
|
|
80
81
|
self.__keycloak_login = conf.keycloak_login()
|
|
@@ -117,6 +118,7 @@ class KeycloakRESTClient:
|
|
|
117
118
|
|
|
118
119
|
def set_token(self, user, token, expires_in, refresh_token):
|
|
119
120
|
"""Set the given token and renews it every time it expires"""
|
|
121
|
+
self.__keycloak_login = user
|
|
120
122
|
self.__token = token
|
|
121
123
|
self.__refresh_token = refresh_token
|
|
122
124
|
self.__set_expires_in(expires_in)
|
|
@@ -135,14 +135,15 @@ class NIFIClient:
|
|
|
135
135
|
self.check_status_sleep_lapse = 1
|
|
136
136
|
|
|
137
137
|
def configure(self, conf: HidDataTransferConfiguration,
|
|
138
|
-
secure: bool = False) -> NIFIClient:
|
|
138
|
+
secure: bool = False, use_keycloak_account = True) -> NIFIClient:
|
|
139
139
|
"""constructs a NIFI client,
|
|
140
140
|
with the NIFI endpoint taken from configuration
|
|
141
141
|
"""
|
|
142
142
|
self.__conf = conf
|
|
143
143
|
self.nifi_rest_client = NIFIRESTClient().configure(conf, secure)
|
|
144
|
+
self.use_keycloak_account = use_keycloak_account
|
|
144
145
|
self.keycloak_rest_client = KeycloakRESTClient().configure(
|
|
145
|
-
conf, secure, refresh=True)
|
|
146
|
+
conf, secure, refresh=True, use_keycloak_account=self.use_keycloak_account)
|
|
146
147
|
self.__logger = self.__conf.logger("nifi.v2.client")
|
|
147
148
|
self.check_status_sleep_lapse = int(
|
|
148
149
|
self.__conf.check_status_sleep_lapse())
|
|
@@ -152,14 +153,21 @@ class NIFIClient:
|
|
|
152
153
|
"""gets the NIFI access token,
|
|
153
154
|
using NIFI account taken from configuration
|
|
154
155
|
this access token is required for any further request sent to NIFI
|
|
156
|
+
If a taken was provided upon configuration, it gets the latest renewed
|
|
155
157
|
"""
|
|
158
|
+
|
|
156
159
|
if self.__conf.nifi_login() and self.__conf.nifi_passwd():
|
|
157
160
|
return self.nifi_rest_client.get_access_token()
|
|
158
|
-
|
|
161
|
+
# Keycloak token provided, but not an account
|
|
162
|
+
elif not self.use_keycloak_account:
|
|
159
163
|
return self.keycloak_rest_client.get_token()
|
|
160
|
-
|
|
164
|
+
# Keycloak token not provided, check an account is available
|
|
165
|
+
elif self.use_keycloak_account and self.__conf.keycloak_login() and \
|
|
166
|
+
self.__conf.keycloak_passwd():
|
|
167
|
+
return self.keycloak_rest_client.get_token()
|
|
168
|
+
else: # Not valid token provider configuration found
|
|
161
169
|
raise HidDataTransferException(
|
|
162
|
-
"NIFI or Keycloak login and password must be provided"
|
|
170
|
+
"NIFI or Keycloak account (login and password) or Keycloak token must be provided"
|
|
163
171
|
)
|
|
164
172
|
|
|
165
173
|
def set_access_token(self, keycloak_token):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hid_data_transfer_lib"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "HiDALGO Data Transfer library provides methods to transfer data between different data providers and consumers using NIFI pipelines"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Jesús Gorroñogoitia", email = "jesus.gorronogoitia@eviden.com" },
|
|
@@ -28,6 +28,7 @@ include = ["py.typed"]
|
|
|
28
28
|
[tool.poetry.group.dev.dependencies]
|
|
29
29
|
flake8 = "^7.2.0"
|
|
30
30
|
black = "^25.1.0"
|
|
31
|
+
ipykernel = "^7.2.0"
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
[tool.poetry.group.types.dependencies]
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/__init__.py
RENAMED
|
File without changes
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/__init__.py
RENAMED
|
File without changes
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/conf/hid_dt.cfg
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/nifi/__init__.py
RENAMED
|
File without changes
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/nifi/nifi_rest.py
RENAMED
|
File without changes
|
|
File without changes
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/util/__init__.py
RENAMED
|
File without changes
|
{hid_data_transfer_lib-0.3.11 → hid_data_transfer_lib-0.4.0}/hid_data_transfer_lib/util/util.py
RENAMED
|
File without changes
|