-
Notifications
You must be signed in to change notification settings - Fork 1.5k
{edge-action} Bugfix: edge action get version code and swap default version unsupported media type error #9445
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
Merged
necusjz
merged 3 commits into
Azure:main
from
tundwed:bugfix/edge-action-get-version-code-media-type
Nov 26, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,11 @@ def _build_arguments_schema(cls, *args, **kwargs): | |||||
| max_length=50, | ||||||
| ), | ||||||
| ) | ||||||
| _args_schema.output_directory = AAZStrArg( | ||||||
| options=["--output-directory", "-d"], | ||||||
| help="Output directory to save the decoded version code as a zip file. If not specified, returns the base64-encoded content.", | ||||||
| required=False, | ||||||
| ) | ||||||
| return cls._args_schema | ||||||
|
|
||||||
| def _execute_operations(self): | ||||||
|
|
@@ -85,6 +90,45 @@ def post_operations(self): | |||||
|
|
||||||
| def _output(self, *args, **kwargs): | ||||||
| result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) | ||||||
|
|
||||||
| # If output directory is specified, decode and save the file | ||||||
| output_dir = self.ctx.args.output_directory.to_serialized_data() if self.ctx.args.output_directory else None | ||||||
| if output_dir: | ||||||
| import base64 | ||||||
| import os | ||||||
| from knack.log import get_logger | ||||||
|
|
||||||
| logger = get_logger(__name__) | ||||||
|
|
||||||
| # Get the base64 encoded content | ||||||
| content = result.get('content') | ||||||
| name = result.get('name', 'version_code') | ||||||
|
|
||||||
| if not content: | ||||||
| from azure.cli.core.azclierror import ValidationError | ||||||
| raise ValidationError("No content returned from the API") | ||||||
|
|
||||||
| # Decode base64 content | ||||||
| try: | ||||||
| decoded_content = base64.b64decode(content) | ||||||
| except Exception as e: | ||||||
| from azure.cli.core.azclierror import ValidationError | ||||||
| raise ValidationError(f"Failed to decode base64 content: {str(e)}") | ||||||
|
|
||||||
| # Create output directory if it doesn't exist | ||||||
| os.makedirs(output_dir, exist_ok=True) | ||||||
|
|
||||||
| # Save as zip file | ||||||
| output_file = os.path.join(output_dir, f"{name}.zip") | ||||||
| try: | ||||||
| with open(output_file, 'wb') as f: | ||||||
| f.write(decoded_content) | ||||||
| logger.warning(f"Version code saved to: {output_file}") | ||||||
| return {"message": f"Version code saved to: {output_file}", "file": output_file} | ||||||
| except Exception as e: | ||||||
|
||||||
| except Exception as e: | |
| except (OSError, PermissionError) as e: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using bare
except Exceptionis too broad. Consider catching specific exception types (e.g.,base64.binascii.Errorfor base64 decoding errors) or at minimum re-raising unexpected exceptions after logging them. This will make debugging easier and prevent masking unexpected errors.