opentf-toolkit-nightly 0.63.0.dev1406__py3-none-any.whl → 0.63.0.dev1418__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.
opentf/scripts/startup.py CHANGED
@@ -434,90 +434,43 @@ def maybe_generate_token() -> None:
434
434
 
435
435
 
436
436
  def maybe_populate_keystore() -> None:
437
- """Populate Java keystore if CURL_CA_BUNDLE defined."""
437
+ """Populate keystore if CURL_CA_BUNDLE defined."""
438
438
  if (ca_bundle := os.environ.get('CURL_CA_BUNDLE')) is None:
439
439
  return
440
440
  if not os.path.isfile(ca_bundle):
441
441
  logging.error('CURL_CA_BUNDLE "%s" does not exist, aborting.', ca_bundle)
442
442
  sys.exit(1)
443
443
 
444
- with open(ca_bundle, 'r', encoding='utf-8') as bundle_file:
445
- ca_list = bundle_file.read().split(CA_END)
446
- if not ca_list[-1].rstrip():
447
- ca_list.pop()
444
+ add_keystore_certificate(ca_bundle)
448
445
 
449
- if truststore := os.environ.get('JAVA_TRUSTSTORE'):
450
- logging.debug('Using truststore "%s".', truststore)
451
- keystore = ('-keystore', truststore)
452
- else:
453
- logging.debug('Using default truststore.')
454
- keystore = ('-cacerts',)
455
-
456
- for ca_counter, ca in enumerate(ca_list):
457
- add_keystore_certificate(ca_counter, f'{ca}{CA_END}', keystore)
458
-
459
-
460
- def add_keystore_certificate(
461
- ca_counter: int, ca: str, keystore: Tuple[str, ...]
462
- ) -> None:
463
- """Add certificate to keystore.
464
-
465
- !!! warning
466
- This calls `keytool`, which requires root privileges, as it
467
- add certificates to the system's keystore.
468
-
469
- Certificates will have an alias of the form:
470
446
 
471
- `opentf:{ca_counter}_{random string}`
472
-
473
- # Required parameters
474
-
475
- - ca_counter: an integer, the certificate position in the bundle
476
- - ca: the certificate as a string
477
- """
478
- with tempfile.NamedTemporaryFile('w') as ca_file:
479
- ca_path = ca_file.name
480
- ca_alias = f'opentf:{ca_counter}_{os.path.basename(ca_path)}'
481
- try:
482
- ca_file.write(ca)
483
- logging.debug('File "%s" written.', ca_path)
484
- except IOError as err:
485
- logging.error('An error occurred while writing the file: %s.', err)
486
- sys.exit(1)
487
- ca_file.flush()
488
- try:
489
- ca_import_execute = subprocess.run(
490
- [
491
- 'keytool',
492
- '-importcert',
493
- '-alias',
494
- ca_alias,
495
- '-file',
496
- ca_path,
497
- '-storepass',
498
- 'changeit',
499
- '-noprompt',
500
- *keystore,
501
- ],
502
- stdout=subprocess.PIPE,
503
- stderr=subprocess.STDOUT,
504
- check=True,
505
- )
506
- logging.debug(
507
- 'Certificate %d successfully added to keystore with alias %s:\n%s.',
508
- ca_counter,
509
- ca_alias,
510
- ca_import_execute.stdout.decode().rstrip(''),
511
- )
512
- except subprocess.CalledProcessError as err:
513
- logging.error(
514
- 'Failed to add certificate %d with alias %s to keystore: %s.\n%s',
515
- ca_counter,
516
- ca_alias,
517
- err,
518
- err.stdout.decode().rstrip(''),
519
- )
520
- sys.exit(1)
447
+ def add_keystore_certificate(ca_bundle: str) -> None:
448
+ try:
449
+ subprocess.run(
450
+ [
451
+ 'openssl',
452
+ 'pkcs12',
453
+ '-export',
454
+ '-nokeys',
455
+ '-in',
456
+ ca_bundle,
457
+ '-password',
458
+ 'pass:',
459
+ '-out',
460
+ '/app/keystore.p12',
461
+ ],
462
+ stdout=subprocess.PIPE,
463
+ stderr=subprocess.STDOUT,
464
+ check=True,
465
+ )
466
+ logging.debug('Certificate successfully added to keystore.')
467
+ except subprocess.CalledProcessError as err:
468
+ logging.error(
469
+ 'Failed to add certificate to keystore: %s\n%s',
470
+ err,
471
+ err.stdout.decode().rstrip(''),
472
+ )
473
+ sys.exit(1)
521
474
 
522
475
 
523
476
  def _ensure_abac_if_defined(name, value):
@@ -17,7 +17,6 @@
17
17
 
18
18
  from typing import Any, Callable, Dict, List, NamedTuple, Optional, Set, Tuple, Union
19
19
 
20
- from collections import defaultdict
21
20
  from copy import deepcopy
22
21
  from datetime import datetime
23
22
  from shlex import quote
@@ -48,15 +47,6 @@ STOPCOMMANDS_COMMAND = re.compile(r'^::stop-commands::(\w+)$')
48
47
  ADDMASK_COMMAND = re.compile(r'^::add-mask::(.*)$')
49
48
  PUT_FILE_COMMAND = re.compile(r'^::put\s+file=(.*?)\s*::(.*?)\s*$')
50
49
 
51
- COMMAND_PATTERNS = (
52
- ATTACH_COMMAND,
53
- UPLOAD_COMMAND,
54
- DOWNLOAD_COMMAND,
55
- PUT_FILE_COMMAND,
56
- SETOUTPUT_COMMAND,
57
- )
58
-
59
-
60
50
  ## step sequence IDs
61
51
 
62
52
  CHANNEL_REQUEST = -1
@@ -323,7 +313,10 @@ class JobState:
323
313
  def __init__(self) -> None:
324
314
  self.stop_command: Optional[str] = None
325
315
  self.masks: List[str] = []
326
- self.workflow_commands: List[str] = []
316
+ self.output_commands: List[str] = []
317
+ self.attachments: List[str] = []
318
+ self.attachments_metadata: Dict[str, Any] = {}
319
+ self.artifacts_resp: bool = False
327
320
 
328
321
 
329
322
  def mask(line: str, state: JobState) -> str:
@@ -552,17 +545,16 @@ def process_output(
552
545
  outputs = {}
553
546
  logs: List[str] = []
554
547
  attachments: List[str] = []
555
- attachments_metadata = {}
548
+ attachments_metadata: Dict[str, Any] = {}
556
549
 
557
550
  is_channel_notify = False
558
551
  step_sequence_id = metadata['step_sequence_id']
559
552
  if resp is None:
560
553
  resp, is_channel_notify = 0, True
561
- if not is_channel_notify and jobstate.workflow_commands:
562
- stdout.extend(jobstate.workflow_commands)
563
- jobstate.workflow_commands.clear()
554
+ if not is_channel_notify and jobstate.output_commands:
555
+ stdout.extend(jobstate.output_commands)
556
+ jobstate.output_commands.clear()
564
557
 
565
- has_artifacts = False
566
558
  for line in stdout:
567
559
  # Parsing stdout for workflow commands
568
560
  if jobstate.stop_command:
@@ -570,14 +562,14 @@ def process_output(
570
562
  jobstate.stop_command = None
571
563
  continue
572
564
 
573
- if is_channel_notify and any(p.match(line) for p in COMMAND_PATTERNS):
574
- jobstate.workflow_commands.append(line)
565
+ if is_channel_notify and SETOUTPUT_COMMAND.match(line):
566
+ jobstate.output_commands.append(line)
575
567
  continue
576
568
 
577
569
  if wcmd := ATTACH_COMMAND.match(line):
578
570
  resp = _attach(wcmd.group(2), wcmd.group(1))
579
571
  elif wcmd := UPLOAD_COMMAND.match(line):
580
- has_artifacts = True
572
+ jobstate.artifacts_resp = True
581
573
  resp = _attach(wcmd.group(2), wcmd.group(1), is_artifact=True)
582
574
  elif wcmd := DOWNLOAD_COMMAND.match(line):
583
575
  resp = _download(wcmd.group(2), wcmd.group(1))
@@ -602,6 +594,9 @@ def process_output(
602
594
  notify['logs'] = logs
603
595
  if notify['metadata'].get('artifacts'):
604
596
  del notify['metadata']['artifacts']
597
+ if attachments:
598
+ jobstate.attachments.extend(attachments)
599
+ jobstate.attachments_metadata.update(attachments_metadata)
605
600
  return notify
606
601
 
607
602
  if metadata.get('artifacts'):
@@ -621,11 +616,17 @@ def process_output(
621
616
  result['outputs'] = outputs
622
617
  if logs:
623
618
  result['logs'] = logs
624
- if attachments:
625
- result['attachments'] = attachments
626
- result['metadata']['attachments'] = attachments_metadata
627
- if has_artifacts:
619
+ if attachments or jobstate.attachments:
620
+ result['attachments'] = jobstate.attachments + attachments
621
+ result['metadata']['attachments'] = {
622
+ **jobstate.attachments_metadata,
623
+ **attachments_metadata,
624
+ }
625
+ jobstate.attachments.clear()
626
+ jobstate.attachments_metadata = {}
627
+ if jobstate.artifacts_resp:
628
628
  result['metadata']['upload'] = resp
629
+ jobstate.artifacts_resp = False
629
630
  if opentf_variables:
630
631
  result['variables'] = opentf_variables
631
632
  return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.63.0.dev1406
3
+ Version: 0.63.0.dev1418
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -56,13 +56,13 @@ opentf/schemas/opentestfactory.org/v1beta1/ServiceConfig.json,sha256=m5ZgWAKbutu
56
56
  opentf/schemas/opentestfactory.org/v1beta1/Workflow.json,sha256=QZ8mM9PhzsI9gTmwmKTWYNoRn--rtcM3L0PzgnPBfMU,15424
57
57
  opentf/schemas/opentestfactory.org/v1beta2/ServiceConfig.json,sha256=rEvK2YWL5lG94_qYgR_GnLWNsaQhaQ-2kuZdWJr5NnY,3517
58
58
  opentf/scripts/launch_java_service.sh,sha256=S0jAaCuv2sZy0Gf2NGBuPX-eD531rcM-b0fNyhmzSjw,2423
59
- opentf/scripts/startup.py,sha256=DLanDaXutUTYcG2PwoJ34QH-5G0TwfLUY_xy1VkVOqA,23202
59
+ opentf/scripts/startup.py,sha256=CZc4sKOQqox0X4R6qQ8GP-4OJwqewrt-XELJ5unG7o0,21456
60
60
  opentf/toolkit/__init__.py,sha256=YnH66dmePAIU7dq_xWFYTIEUrsL9qV9f82LRDiBzbzs,22057
61
- opentf/toolkit/channels.py,sha256=8WuybkK7HZpTvCqstnik6cz-OGd7p4AMBAfBJX3E3zA,27389
61
+ opentf/toolkit/channels.py,sha256=BQh5ztQmIKpxns6ozDNto4YpegktydPZyhOO9F3g-2Q,27731
62
62
  opentf/toolkit/core.py,sha256=jMBDIYZ8Qn3BvsysfKoG0iTtjOnZsggetpH3eXygCsI,9636
63
63
  opentf/toolkit/models.py,sha256=PNfXVQbeyOwDfaNrLjcfhYm6duMSlNWBtZsWZcs53ag,6583
64
- opentf_toolkit_nightly-0.63.0.dev1406.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
65
- opentf_toolkit_nightly-0.63.0.dev1406.dist-info/METADATA,sha256=EXkrO2T8qRPNdSP83yiGluJDu-aq7zwXDY4mDbsrbUg,2215
66
- opentf_toolkit_nightly-0.63.0.dev1406.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
67
- opentf_toolkit_nightly-0.63.0.dev1406.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
68
- opentf_toolkit_nightly-0.63.0.dev1406.dist-info/RECORD,,
64
+ opentf_toolkit_nightly-0.63.0.dev1418.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
65
+ opentf_toolkit_nightly-0.63.0.dev1418.dist-info/METADATA,sha256=ZlrRo3jDrv1hF_gDXgQmh6zztZ5NAKTCvti59zQx5EA,2215
66
+ opentf_toolkit_nightly-0.63.0.dev1418.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
67
+ opentf_toolkit_nightly-0.63.0.dev1418.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
68
+ opentf_toolkit_nightly-0.63.0.dev1418.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5