Skip to content

Commit

Permalink
Merge pull request #1108 from 2i2c-org/revert-1107-revert-1104-remove…
Browse files Browse the repository at this point in the history
…-explicit-error
  • Loading branch information
sgibson91 authored Mar 15, 2022
2 parents ef8dfc1 + d3e60a1 commit ed60444
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions deployer/file_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
absolute paths, decrypting and reading encrypted files when needed.
"""
import os
import json
import warnings
import subprocess
import tempfile
Expand Down Expand Up @@ -102,29 +101,15 @@ def get_decrypted_file(original_filepath):
if "secret" in filename:
# We must then determine if the file is using sops
# sops files are JSON/YAML with a `sops` key. So we first check
# if the file is valid JSON/YAML, and then if it has a `sops` key
# if the file is valid JSON/YAML, and then if it has a `sops` key.
# Since valid JSON is also valid YAML by design, a YAML parser can read in JSON.
with open(original_filepath) as f:

# FIXME: Right now we expect encrypted files to be JSON or YAML files, and
# so we fail if these are not valid JSON/YAML. However in the
# future, we may want to support encrypted files of other types
# and we should update this section accordingly.
#
# Support the (clearly wrong) people who use .yml instead of .yaml
if ext == ".yaml" or ext == ".yml":
try:
content = yaml.load(f)
except ScannerError:
raise ScannerError(
"We expect encrypted files to be valid JSON or YAML files."
)
elif ext == ".json":
try:
content = json.load(f)
except json.JSONDecodeError:
raise json.JSONDecodeError(
"We expect encrypted files to be valid JSON or YAML files."
)
try:
content = yaml.load(f)
except ScannerError:
raise ScannerError(
"We expect encrypted files to be valid JSON or YAML files."
)

if "sops" not in content:
raise KeyError(
Expand Down

0 comments on commit ed60444

Please sign in to comment.