/
identify.py
33 lines (29 loc) · 1.16 KB
/
identify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from yaml import safe_load
from yaml import MarkedYAMLError
import logging
from operatorcourier.errors import OpCourierBadYaml
from operatorcourier.manifest_parser import CRD_STR, CSV_STR, PKG_STR
logger = logging.getLogger(__name__)
def get_operator_artifact_type(operatorArtifactString):
"""get_operator_artifact_type takes a yaml string and determines if it is
one of the expected bundle types: ClusterServiceVersion,
CustomResourceDefinition, or Package.
:param operatorArtifactString: Yaml string to type check
"""
try:
operatorArtifact = safe_load(operatorArtifactString)
except MarkedYAMLError:
msg = "Courier requires valid input YAML files"
logger.error(msg)
raise OpCourierBadYaml(msg)
else:
artifact_type = None
if isinstance(operatorArtifact, dict):
if "packageName" in operatorArtifact:
artifact_type = PKG_STR
elif operatorArtifact.get("kind") in {CRD_STR, CSV_STR}:
artifact_type = operatorArtifact["kind"]
if artifact_type is not None:
return artifact_type
else:
return ""