run k8 only on specific suffix
import logging
-
from yaml import YAMLError
from checkov.kubernetes.parser import k8_yaml, k8_json
@@ -11,11 +10,15 @@ except ImportError:
logger = logging.getLogger(__name__)
+
def parse(filename):
template = None
template_lines = None
try:
+ if filename.endswith(".yaml") or filename.endswith(".yml"):
(template, template_lines) = k8_yaml.load(filename)
+ if filename.endswith(".json"):
+ (template, template_lines) = k8_json.load(filename)
except IOError as e:
if e.errno == 2:
logger.error('Template file not found: %s', filename)
@@ -28,15 +31,6 @@ def parse( filename):
except UnicodeDecodeError as err:
logger.error('Cannot read file contents: %s', filename)
except YAMLError as err:
- if err.problem in [
- 'expected \'<document start>\', but found \'{\'']:
- try:
- (template, template_lines) = k8_json.load(filename)
- except Exception as json_err: # pylint: disable=W0703
- logger.error(
- 'Template %s is malformed: %s', filename, err.problem)
pass
return template, template_lines
-
-
