Skip to content

Commit

Permalink
[Blueprint] Prevent hidden artifacts parsing
Browse files Browse the repository at this point in the history
Blueprint extension was parsing all files in the artifacts folder
including hidden files. This unwanted behavior can also raise errors
(eg. UnicodeDecodeError). This commit fixes this by preventing hidden
Linux and Windows files from being parsed.

closes #4984
  • Loading branch information
Simon Kheng committed Jun 27, 2022
1 parent 0bf987a commit 5392ed0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/blueprint/azext_blueprint/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import json
import os
import stat
from knack.util import CLIError
from azure.cli.core.util import user_confirmation
from azure.core.exceptions import HttpResponseError
Expand Down Expand Up @@ -48,12 +49,15 @@ def import_blueprint_with_artifacts(cmd,
for filename in os.listdir(os.path.join(input_path, 'artifacts')):
artifact_name = filename.split('.')[0]
filepath = os.path.join(input_path, 'artifacts', filename)
with open(filepath) as artifact_file:
try:
artifact = json.load(artifact_file)
art_dict[artifact_name] = artifact
except json.decoder.JSONDecodeError as ex:
raise CLIError('JSON decode error for {}: {}'.format(filepath, str(ex))) from ex
# skip hidden files
if ((os.name != 'nt' and not filename.startswith('.')) or
(os.name == 'nt' and not bool(os.stat(filepath).st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN))):
with open(filepath) as artifact_file:
try:
artifact = json.load(artifact_file)
art_dict[artifact_name] = artifact
except json.decoder.JSONDecodeError as ex:
raise CLIError('JSON decode error for {}: {}'.format(filepath, str(ex))) from ex
except FileNotFoundError as ex:
raise CLIError('File not Found: {}'.format(str(ex))) from ex

Expand Down

0 comments on commit 5392ed0

Please sign in to comment.