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

Enable reading SSL parameters from configuration file #552

Merged
merged 1 commit into from
Feb 28, 2017

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Feb 27, 2017

This enables the reading of some basic SSL parameters from the
configuration file. It gives precedence to the ssl parameters provided
by the class parameter (the ssl dict).

# No SSL parameters were given either via the class parameter or
# the configuration file
if not any(x for x in ssl.values()):
ssl = None
Copy link
Member

Choose a reason for hiding this comment

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

if not any(ssl.values())

And read_default_file option changes how ssl = {"ca": ""} is considered.
if read_default_file=False, ssl is overwritten to None. Otherwise, passed ssl is used as-is.
I don't like it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this is for the if read_default_file: case. So it will only be read when that's set.

ssl = None

self.ssl = False
if ssl:
Copy link
Member

Choose a reason for hiding this comment

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

Mabe, if ssl and any(ssl.values()).

@JAORMX
Copy link
Contributor Author

JAORMX commented Feb 27, 2017

@methane I updated the commit. What do you think?

# must have preference.
for key, value in ssl_config_params.items():
if value:
ssl.setdefault(key, value)
Copy link
Member

Choose a reason for hiding this comment

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

since you used _config when building ssl_config_params,
you can just ssl[key] = value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using ssl[key] = value would overwrite the value that's already there, and this gives priority to the values that are set via the ssl dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why I added the comment above this for loop.

Copy link
Member

Choose a reason for hiding this comment

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

read _config() function.

@JAORMX
Copy link
Contributor Author

JAORMX commented Feb 27, 2017

@methane you are right, I changed it accordingly.

}
for key, value in ssl_config_params.items():
if value:
ssl[key] = value
Copy link
Member

Choose a reason for hiding this comment

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

How about this?

for key in ["ca", "capath", "cert", "key", "cipher"]:
    value = cfg.get(read_default_group, "ssl-" + key)
    if value:
        ssl[key] = value

(I hadn't check mysql options yet.)

Copy link
Member

Choose a reason for hiding this comment

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

I confirmed options have exactly same name.

@JAORMX
Copy link
Contributor Author

JAORMX commented Feb 27, 2017

@methane by the way, I see that in the _create_ssl_ctx function there is a check such as this:
if isinstance(sslp, ssl.SSLContext):
return sslp
should I take that into account as well?

@methane
Copy link
Member

methane commented Feb 27, 2017

Ah, yes please. Use config only when dict is None or isinstance(ssl, dict)

This enables the reading of some basic SSL parameters from the
configuration file. It gives precedence to the ssl parameters provided
by the class parameter (the ssl dict).
@JAORMX
Copy link
Contributor Author

JAORMX commented Feb 27, 2017

@methane done; and I really liked your suggestion. I added the minimized loop you suggested as part of the change.

@JAORMX
Copy link
Contributor Author

JAORMX commented Feb 27, 2017

Tested it successfully in my deployment. @methane thanks for the great reviews. Let me know if there's anything else I should change.

@methane methane merged commit 557d0d9 into PyMySQL:master Feb 28, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants