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

python3 support for letsencrypt module (fixes #30690) #32734

Merged
merged 4 commits into from
Dec 8, 2017

Conversation

bverschueren
Copy link
Contributor

@bverschueren bverschueren commented Nov 9, 2017

  • decorate fetch_url to upsert lowercase representation of the header names returned in info-dict

  • initialize result to a dict in some methods to prevent 'NoneType is not iterable' TypeError

  • use dict.get() to retrieve values from info dict to prevent KeyError

  • convert to/from text/bytes using _text methods for PY3 support

SUMMARY

fixes #30690

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

lib/ansible/modules/web_infrastructure/letsencrypt.py

ANSIBLE VERSION
ansible 2.5.0

  * decorate fetch_url to upsert lowercase representation of the header names returned in info-dict

  * initialize result to a dict in some methods to prevent 'NoneType is not iterable' TypeError

  * use dict.get() to retrieve values from info dict to prevent KeyError

  * convert to/from text/bytes using _text methods for PY3 support
@ansibot
Copy link
Contributor

ansibot commented Nov 9, 2017

The test ansible-test compile --python 2.6 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/letsencrypt.py:185:46: SyntaxError: info.update({header.lower(): value for header, value in info.items()})

The test ansible-test sanity --test ansible-doc --python 2.6 [?] failed with the following error:

Command "ansible-doc letsencrypt" returned exit status 1.
>>> Standard Error
ERROR! module letsencrypt missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test import --python 2.6 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/letsencrypt.py:185:46: SyntaxError: invalid syntax

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 9, 2017

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bugfix_pull_request module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. labels Nov 9, 2017
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Nov 9, 2017
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 10, 2017
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Nov 18, 2017
@ansibot
Copy link
Contributor

ansibot commented Nov 26, 2017

cc @resmo
click here for bot help

return response, info
return func_wrapper

fetch_url = _upsert_lowercase_headers(fetch_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just make this a plain function that calls fetch_url and then lowercases the keys instead of making it a decorator. I'm a little hesitant about overriding the name (I'd use a different name than fetch_url) but I can see you do that so you don't have to change the name everywhere. Since I'm not the module author, I won't block it over that but I think it's better style to use a new name.

Copy link
Contributor Author

@bverschueren bverschueren Dec 5, 2017

Choose a reason for hiding this comment

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

The reason I've used a decorator was indeed to prevent having to rename all fetch_url occurrences. And since I'm not altering the values but merely ensuring the lowercase representation is included, I figured a decorator would be easier.
Maybe this should be fixed in the fetch_url module utility ? Otherwise every module that uses this function AND wants to support py3 needs to create a wrapper or create several conditionals to capture header case variations ?

@@ -355,7 +370,7 @@ def _parse_account_key(self, key):

pub_hex, pub_exp = re.search(
r"modulus:\n\s+00:([a-f0-9\:\s]+?)\npublicExponent: ([0-9]+)",
out.decode('utf8'), re.MULTILINE | re.DOTALL).groups()
to_text(out), re.MULTILINE | re.DOTALL).groups()
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless simply constructing a message for the user, use to_text, to_bytes, etc with errors='surrogate_or_strict' like this:

to_text(out, errors='surrogate_or_strict'), re.MULTILINE | re.DOTALL).groups()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, have added the error handler argument.

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Dec 4, 2017
@abadger
Copy link
Contributor

abadger commented Dec 5, 2017 via email

@abadger
Copy link
Contributor

abadger commented Dec 5, 2017 via email

@bverschueren
Copy link
Contributor Author

@abadger have updated this to be a function wrapper instead. I've kept the name fetch_url for now - wouldn’t want to mangle too much with the rest of the module without maintainer's involvement.

@abadger abadger merged commit 3a63405 into ansible:devel Dec 8, 2017
abadger pushed a commit that referenced this pull request Dec 8, 2017
*   python3 support for letsencrypt module (fixes #30690)
  * initialize result to a dict in some methods to prevent 'NoneType is not iterable' TypeError
  * use dict.get() to retrieve values from info dict to prevent KeyError
  * convert to/from text/bytes using _text methods for PY3 support

(cherry picked from commit 3a63405)
@abadger abadger added this to Done in 2.4.3 in 2.4.x Blocker List Dec 8, 2017
@abadger
Copy link
Contributor

abadger commented Dec 8, 2017

Merged to devel and cherry-picked to the stable-2.4 branch for inclusion in 2.4.3 beta1

@resmo
Copy link
Contributor

resmo commented Dec 8, 2017

thanks @abadger for stepping in.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@bverschueren bverschueren deleted the letsencrypt_py3 branch March 21, 2018 13:22
@dagwieers dagwieers added the crypto Crypto community (ACME, openssl, letsencrypt) label Feb 7, 2019
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. crypto Crypto community (ACME, openssl, letsencrypt) module This issue/PR relates to a module. python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
No open projects
2.4.x Blocker List
Done in 2.4.3
Development

Successfully merging this pull request may close these issues.

Lets Encrypt module appears to fail with Python 3
6 participants