-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Script File Path Support with Automatic BOM Removal to mssql_script Module #10203
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Hi @zollo thanks for your contribution. I must say, I am a bit uneasy about this PR - I mean, the "alternate credentials" part of it. That does not seem to be anything particular to MSSQL, in fact the code literally tries with one set of credentials and if that does not work, it tries to login with the other one. IMHO, this feature:
I think those questions are very subjective, and as such, we should try and avoid bringing them up in the context of the module. The maintenance of common/shared code based on individual's subjective views is probably going to much more painful than it needs to. Sorry, I don't think we should add that feature to the module, but I might be wrong in that. It would be nice if more folks could chip in this one. @Andersson007 you are maintaining the PGSQL modules (right? 😁 ), what do you think of this? That being said, the handling of BOM markers is definitely something we could benefit from. |
@russoz thanks for pinging! I'm also not sure if we should add these "in-case-of-failure" features (cause a lot of things can fail).
my opinion |
This comment was marked as outdated.
This comment was marked as outdated.
script_source: | ||
description: Source of the executed script. | ||
type: str | ||
returned: always |
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.
This isn't returned if the module fails. Also all new return values need a version_added
entry.
returned: always | |
returned: success | |
version_added: 11.0.0 |
choices: ["file", "parameter"] | ||
script_path: | ||
description: Path to the script file that was executed. | ||
type: str |
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.
type: str | |
type: path |
script_path: | ||
description: Path to the script file that was executed. | ||
type: str | ||
returned: when script_path parameter is used |
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.
Same below:
returned: when script_path parameter is used | |
returned: success and O(script_path) is provided |
bom_removed: | ||
description: Whether a Byte Order Mark was detected and removed from the script file. | ||
type: bool | ||
returned: when script_path parameter is used and BOM was found |
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.
Why not always provide this if script_path
is used? It's not very helpful if this is sometimes true
and sometimes not there.
description: Type of Byte Order Mark that was detected and removed. | ||
type: str | ||
returned: when script_path parameter is used and BOM was found | ||
sample: "UTF-8" |
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.
How about returning none
/null
(the Jinja/YAML equivalent for Python's None
) here if script_path
is used, but no BOM was found?
- If the file contains a Byte Order Mark (BOM), it will be automatically detected and removed. | ||
- Mutually exclusive with O(script). | ||
type: path | ||
version_added: 10.8.0 |
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.
version_added: 10.8.0 | |
version_added: 11.0.0 |
- mssql_script - add ``script_path`` parameter to allow executing SQL scripts from files as an alternative to inline scripts. | ||
- mssql_script - add automatic Byte Order Mark (BOM) detection and removal for script files to prevent SQL parsing errors. |
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.
The second fragment isn't needed, since this is part of the feature mentioned in the first fragment. Also the URLs are missing.
- mssql_script - add ``script_path`` parameter to allow executing SQL scripts from files as an alternative to inline scripts. | |
- mssql_script - add automatic Byte Order Mark (BOM) detection and removal for script files to prevent SQL parsing errors. | |
- mssql_script - add ``script_path`` parameter to allow executing SQL scripts from files as an alternative to inline scripts (https://github.com/ansible-collections/community.general/issues/10201, https://github.com/ansible-collections/community.general/pull/10203). |
script_path: | ||
description: | ||
- Path to a file containing the SQL script to be executed. | ||
- Script can contain multiple SQL statements. Multiple Batches can be separated by V(GO) command. |
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.
- Script can contain multiple SQL statements. Multiple Batches can be separated by V(GO) command. | |
- Script can contain multiple SQL statements. Multiple batches can be separated by V(GO) command. |
- Path to a file containing the SQL script to be executed. | ||
- Script can contain multiple SQL statements. Multiple Batches can be separated by V(GO) command. | ||
- Each batch must return at least one result set. | ||
- If the file contains a Byte Order Mark (BOM), it will be automatically detected and removed. |
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.
- If the file contains a Byte Order Mark (BOM), it will be automatically detected and removed. | |
- If the file contains a Byte Order Mark (BOM), it will be automatically detected and removed. | |
The return values RV(bom_removed) and RV(bom_type) will be set accordingly. |
script_content = raw_content.decode('utf-8', errors='replace') | ||
|
||
# Detect and remove BOM | ||
cleaned_content, bom_removed, bom_type = detect_and_remove_bom( |
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.
Shouldn't the BOM detection/removal happen before any decoding is done? The BOM basically tells you the encoding you have to use to decode the script.
Returns tuple (script_content, bom_info) | ||
""" | ||
if not os.path.exists(script_path): | ||
raise IOError(f"Script file not found: {script_path}") |
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.
f-strings are not compatible with Python 2.7, you cannot use them currently in modules.
Thank you for the great feedback @felixfontein - I will address these ASAP. |
Ping @zollo needs_info |
@zollo This pullrequest is waiting for your response. Please respond or the pullrequest will be closed. |
SUMMARY
Fixes #10201
This feature branch updates the
mssql_script
module with a new parameter allowing users to supply a file path containing their SQL script. To avoid potential execution issues, the file is checked for the presence of any common BOM patterns - if found, they are removed.Notes:
script_path
param.ISSUE TYPE
COMPONENT NAME
mssql_script
ADDITIONAL INFORMATION
See changelog fragment for more information.
This code contribution is made on behalf of the Omnissa UEM Cloud Services Team (formerly VMware EUC), internal reference Jira AWSA-47744.