Skip to content

Commit

Permalink
Issue 640 Ignore unrelated files when creating modules zip (#700)
Browse files Browse the repository at this point in the history
When we validate the fragments folder we only look at files ending on json or yaml, but when we run cfn submit we just zip up everything in the fragments folder. This can cause the module registration to fail when there are unrelated files in that folder (such as files created by an IDE for example). This PR changes the file-zipping logic to only include the relevant fragment files.
  • Loading branch information
MalikAtalla-AWS authored Mar 11, 2021
1 parent 5b11f02 commit a804c60
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/rpdk/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
InvalidProjectError,
SpecValidationError,
)
from .fragment.module_fragment_reader import _get_fragment_file
from .jsonutils.pointer import fragment_decode, fragment_encode
from .jsonutils.utils import traverse
from .plugin_registry import load_plugin
Expand Down Expand Up @@ -438,6 +439,17 @@ def load(self):
msg = "Resource specification is invalid: " + str(e)
self._raise_invalid_project(msg, e)

def _add_modules_content_to_zip(self, zip_file):
if not os.path.exists(self.root / SCHEMA_UPLOAD_FILENAME):
msg = "Module schema could not be found"
raise InternalError(msg)
zip_file.write(self.root / SCHEMA_UPLOAD_FILENAME, SCHEMA_UPLOAD_FILENAME)
file = _get_fragment_file(self.fragment_dir)
zip_file.write(
file,
arcname=file.replace(str(self.fragment_dir), "fragments/"),
)

@staticmethod
def _validate_fragments(template_fragment):
template_fragment.validate_fragments()
Expand All @@ -461,23 +473,8 @@ def submit(
# file-size check on upload
with zipfile.ZipFile(f, mode="w") as zip_file:
zip_file.write(self.settings_path, SETTINGS_FILENAME)
# Include all fragments in zip file
if self.artifact_type == ARTIFACT_TYPE_MODULE:
if not os.path.exists(self.root / SCHEMA_UPLOAD_FILENAME):
msg = "Module schema could not be found."
raise InternalError(msg)
zip_file.write(
self.root / SCHEMA_UPLOAD_FILENAME, SCHEMA_UPLOAD_FILENAME
)
for root, _dirs, files in os.walk(self.fragment_dir):
for file in files:
zip_file.write(
os.path.join(root, file),
arcname=os.path.join(
root.replace(str(self.fragment_dir), "fragments/"),
file,
),
)
self._add_modules_content_to_zip(zip_file)
else:
zip_file.write(self.schema_path, SCHEMA_UPLOAD_FILENAME)
try:
Expand Down

0 comments on commit a804c60

Please sign in to comment.