Skip to content

Commit

Permalink
Fix: use of PyYAML 'safe_load' instead of 'CLoader' (#42)
Browse files Browse the repository at this point in the history
Issue:
When manual install is skipped, the virtual environment might fail to detect `libyaml`, `CLoader` is then not available within `PyYAML` and fails with an `ImportError` if `CLoader` is imported.

Error message - `ERROR: could not read file /home/user/Projects/edb-terraform/infrastructure-examples/aws-all.yml (module 'yaml' has no attribute 'CLoader')`
Ref: yaml/pyyaml#108

Fix:
Use `safe_load` instead of using `CLoader`, which depends on `libyaml` and might require a manual install with the use of `python setup.py --with-libyaml install` when using python virtual environments.

Other Changes:
* Removed unused `security_group_ids` variable from AWS modules root variable file
* added `ImportError` to `try/except` import
  • Loading branch information
bryan-bar committed Mar 21, 2023
1 parent da0424f commit cd7bcb9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
6 changes: 0 additions & 6 deletions edbterraform/data/terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,3 @@ variable "vpc_id" {
description = "VPC ID"
default = ""
}

variable "custom_security_group_ids" {
description = "Security Group assign to the instances. Example: 'sg-12345'."
type = string
default = ""
}
2 changes: 1 addition & 1 deletion edbterraform/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
try:
from edbterraform.utils.dict import change_keys
from edbterraform.utils.files import load_yaml_file
except:
except ImportError:
from utils.dict import change_keys
from utils.files import load_yaml_file

Expand Down
2 changes: 1 addition & 1 deletion edbterraform/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def load_yaml_file(file_path):

try:
with open(file_path) as f:
vars = yaml.load(f.read(), Loader=yaml.CLoader)
vars = yaml.safe_load(f.read())
return vars

except Exception as e:
Expand Down

0 comments on commit cd7bcb9

Please sign in to comment.