Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(submit): only adding .json files from the inputs #1048

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rpdk/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,13 @@ def _add_overrides_file_to_zip(self, zip_file):
LOG.debug("%s found. Writing to package.", OVERRIDES_FILENAME)
except FileNotFoundError:
LOG.debug("%s not found. Not writing to package.", OVERRIDES_FILENAME)


def _add_resources_content_to_zip(self, zip_file):
zip_file.write(self.schema_path, SCHEMA_UPLOAD_FILENAME)
if os.path.isdir(self.inputs_path):
for filename in os.listdir(self.inputs_path):
input_files = os.listdir(self.inputs_path)
for filename in list(filter(lambda f: f.endsWith('.json'), input_files)):
absolute_path = self.inputs_path / filename
zip_file.write(absolute_path, INPUTS_FOLDER + "/" + filename)
LOG.debug("%s found. Writing to package.", filename)
Expand Down
14 changes: 11 additions & 3 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
PRE_CREATE_INPUTS_FILE = "inputs/inputs_1_pre_create.json"
PRE_UPDATE_INPUTS_FILE = "inputs/inputs_1_pre_update.json"
INVALID_PRE_DELETE_INPUTS_FILE = "inputs/inputs_1_invalid_pre_delete.json"
README_INPUTS_FILE = "inputs/README.md"

PLUGIN_INFORMATION = {
"plugin-version": "2.1.3",
Expand Down Expand Up @@ -1125,7 +1126,7 @@ def test_settings_not_found(project):
assert "init" in str(excinfo.value)


def create_input_file(base):
def create_input_files(base):
path = base / "inputs"
os.mkdir(path, mode=0o777)

Expand All @@ -1141,6 +1142,11 @@ def create_input_file(base):
with path_invalid.open("w", encoding="utf-8") as f:
f.write("{}")

# Add a file
path_readme = base / README_INPUTS_FILE
with path_readme.open("w", encoding="utf-8") as f:
f.write("# My README for devs")


def create_hook_input_file(base):
path = base / "inputs"
Expand Down Expand Up @@ -1207,7 +1213,7 @@ def test_submit_dry_run(project, is_type_configuration_available):
with project.overrides_path.open("w", encoding="utf-8") as f:
f.write(json.dumps(empty_override()))

create_input_file(project.root)
create_input_files(project.root)

project.write_settings()

Expand Down Expand Up @@ -1279,6 +1285,8 @@ def test_submit_dry_run(project, is_type_configuration_available):
assert input_invalid == {}
input_update = json.loads(zip_file.read(UPDATE_INPUTS_FILE).decode("utf-8"))
assert input_update == {}
# ensure we don't add non-json files
assert README_INPUTS_FILE not in zipfile.namelist()
assert zip_file.testzip() is None
metadata_info = json.loads(zip_file.read(CFN_METADATA_FILENAME).decode("utf-8"))
assert "cli-version" in metadata_info
Expand Down Expand Up @@ -1374,7 +1382,7 @@ def test_submit_dry_run_hooks(project):
with project.overrides_path.open("w", encoding="utf-8") as f:
f.write(json.dumps(empty_hook_override()))

create_input_file(project.root)
create_input_files(project.root)

project.write_settings()

Expand Down