15
15
from operatorcourier .push import PushCmd
16
16
from operatorcourier .format import format_bundle
17
17
from operatorcourier .nest import nest_bundles
18
+ from operatorcourier .errors import OpCourierBadBundle
18
19
19
20
logger = logging .getLogger (__name__ )
20
21
@@ -31,6 +32,12 @@ def build_and_verify(source_dir=None, yamls=None, ui_validate_io=False,
31
32
:param ui_validate_io: Optional flag to test operatorhub.io specific validation
32
33
:param validation_output: Path to optional output file for validation logs
33
34
:param repository: Repository name for the application
35
+
36
+ :raises TypeError: When called with both source_dir and yamls specified
37
+
38
+ :raises OpCourierBadYaml: When an invalid yaml file is encountered
39
+ :raises OpCourierBadArtifact: When a file is not any of {CSV, CRD, Package}
40
+ :raises OpCourierBadBundle: When the resulting bundle fails validation
34
41
"""
35
42
36
43
if source_dir is not None and yamls is not None :
@@ -53,17 +60,19 @@ def build_and_verify(source_dir=None, yamls=None, ui_validate_io=False,
53
60
valid , validation_results_dict = ValidateCmd (ui_validate_io ).validate (bundle ,
54
61
repository )
55
62
56
- if not valid :
57
- bundle = None
58
- logger .error ("Bundle failed validation." )
59
- raise ValueError ("Resulting bundle is invalid, input yaml is improperly defined." )
60
- else :
61
- bundle = format_bundle (bundle )
62
-
63
63
if validation_output is not None :
64
64
with open (validation_output , 'w' ) as f :
65
65
f .write (json .dumps (validation_results_dict ) + "\n " )
66
- return bundle
66
+
67
+ if valid :
68
+ bundle = format_bundle (bundle )
69
+ return bundle
70
+ else :
71
+ logger .error ("Bundle failed validation." )
72
+ raise OpCourierBadBundle (
73
+ "Resulting bundle is invalid, input yaml is improperly defined." ,
74
+ validation_info = validation_results_dict
75
+ )
67
76
68
77
69
78
def build_verify_and_push (namespace , repository , revision , token ,
@@ -82,6 +91,16 @@ def build_verify_and_push(namespace, repository, revision, token,
82
91
:param source_dir: Path to local directory of yaml files to be read
83
92
:param yamls: List of yaml strings to create bundle with
84
93
:param validation_output: Path to optional output file for validation logs
94
+
95
+ :raises TypeError: When called with both source_dir and yamls specified
96
+
97
+ :raises OpCourierBadYaml: When an invalid yaml file is encountered
98
+ :raises OpCourierBadArtifact: When a file is not any of {CSV, CRD, Package}
99
+ :raises OpCourierBadBundle: When the resulting bundle fails validation
100
+
101
+ :raises OpCourierQuayCommunicationError: When communication with Quay fails
102
+ :raises OpCourierQuayErrorResponse: When Quay responds with an error
103
+ :raises OpCourierQuayError: When the request fails in an unexpected way
85
104
"""
86
105
87
106
bundle = build_and_verify (source_dir , yamls , repository = repository ,
@@ -102,6 +121,9 @@ def nest(source_dir, registry_dir):
102
121
:param source_dir: Path to local directory of yaml files to be read
103
122
:param output_dir: Path of your directory to be populated.
104
123
If directory does not exist, it will be created.
124
+
125
+ :raises OpCourierBadYaml: When an invalid yaml file is encountered
126
+ :raises OpCourierBadArtifact: When a file is not any of {CSV, CRD, Package}
105
127
"""
106
128
107
129
yaml_files = []
0 commit comments