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

Added explicit encoding for key_data string. #38

Merged
merged 5 commits into from
Jul 27, 2020
Merged

Added explicit encoding for key_data string. #38

merged 5 commits into from
Jul 27, 2020

Conversation

phospi
Copy link
Contributor

@phospi phospi commented Apr 16, 2020

SUMMARY

Explicit encoding for pem key variable was added and tested with:

  • python 3.6.8
  • python 2.7.5

Fixes #37

ISSUE TYPE
  • Bugfix Pull Request
  • Feature Pull Request
COMPONENT NAME

ec2_win_password

ADDITIONAL INFORMATION

This pull request is supposed to ensure compatibility with python2 and python3 for module ec2_win_password

@phospi
Copy link
Contributor Author

phospi commented May 22, 2020

Can somebody explain to me why no one is checking or merging this PR? Is there any contribution guidance? I didn't find any.

@jillr

Copy link
Contributor

@briantist briantist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the linked issue, and test out this fix.
This worked for me; thanks!

@briantist
Copy link
Contributor

@phospi this lgtm, but I'm just a user and don't have any privs on the project. I recommend trying to ping someone in IRC in the #ansible-aws channel

@briantist
Copy link
Contributor

@phospi I don't know why there still has been zero response to this. In the meantime you should consider adding a changelog as you'll likely be asked to once someone looks at this.

@jillr jillr changed the base branch from master to main July 2, 2020 19:48
Copy link
Collaborator

@s-hertel s-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phospi Thanks very much for taking the time to make a PR. Things are still kind of in flux with this repo, I think. It still needs the bot hooked up so module authors are pinged. Ideally @RickMendes would review as the author. Reviews tend to happen whenever community members have time, as just about everyone is a volunteer.

@@ -181,7 +181,7 @@ def main():
module.fail_json(msg="unable to parse key file")
elif key_data is not None and key_file is None:
try:
key = load_pem_private_key(key_data, b_key_passphrase, default_backend())
key = load_pem_private_key(key_data.encode('ascii'), b_key_passphrase, default_backend())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like load_pem_private_key expects a bytes like object so the key_data can just use to_bytes (like b_key_passphrase).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I did it for b_key_passphrase:

b_key_passphrase = to_bytes(module.params.get('key_passphrase'), err    ors='surrogate_or_strict')

OMG - I haven't seen this code since 2016.

@phospi
Copy link
Contributor Author

phospi commented Jul 23, 2020

@RickMendes @s-hertel Would you approve this PR?

@ghost
Copy link

ghost commented Jul 23, 2020

@phospi I would feel better about approving this if you were using a bytes object instead of an encoded string. It may work today, but you are still passing a different object than load_pem_private_key expects.

@phospi
Copy link
Contributor Author

phospi commented Jul 24, 2020

@RickMendes Good point. I did the modification.

I did some refactoring as well. The main reason is that it is now easier to use with testing. I added a first test case to ensure basic functionality.

@ghost
Copy link

ghost commented Jul 24, 2020

@phospi Thanks for making those changes. I approve 👍

@ghost
Copy link

ghost commented Jul 24, 2020

Re-approved 👍

@phospi
Copy link
Contributor Author

phospi commented Jul 27, 2020

@s-hertel @jillr I think this PR made enough progress to be merged. Who can do the merge?

@s-hertel s-hertel merged commit 2f8c7b6 into ansible-collections:main Jul 27, 2020
@s-hertel
Copy link
Collaborator

Thanks so much @phospi for the patch!

alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 14, 2021
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 15, 2021
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 16, 2021
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 17, 2021
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
Added explicit encoding for key_data string.
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
Added explicit encoding for key_data string.
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request Jul 19, 2021
Added explicit encoding for key_data string.
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this pull request May 25, 2022
…ions#38)

* Move last boto 2 modules to AnsibleAWSModule

* Move last boto3 modules to AnsibleAWSModule

* Remove last use of ec2_argument_spec in modules

* HAS_BOTO3 logic no longer required - Using AnsibleAWSModule

* Be more consistent in our use of HAS_BOTO

* Split imports by line - much easier to work with during refactoring/cleanup

* Use module.client() to get boto3 clients

* Shuffle import orders for consistency

* Pull camel_dict_to_snake_dict from its canonical source

* Use module.fail_json_aws and is_boto3_error_code to simplify error handling

* tweak integration tests to allow more information in the error messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2_win_password fails for given key_data if module is executed with python3. It works with python2.
3 participants