-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
Migrate provider api #341
Migrate provider api #341
Conversation
Hi. I'm an automated pull request bot named CapsuleCD. I handle testing, versioning and package releases for this project.
If you're interested in learning more about CapsuleCD, or adding it to your project, you can check it out here |
ooof. This looks like a pretty big change. I'd like to take a closer look at it this weekend, just so I understand whats going on. Though, the tests are passing, so I'm not too worried. |
Of course. The only real new logic is in |
ah, I see. |
Migrate provider api
Each of provider modules expose a subclass of the
Provider
class declared in thelexicon.providers.base
module. TheProvider
class requires to implement four methods for the four actions available (create, list, update and delete). Each of these methods accept an argument namedtype
.Pylint complains about this, with reason:
type
is a special keyword in Python, as it corresponds to the functiontype()
that gives the type of a reference. It means that currently, standardtype()
function is hidden by thetype
parameter of thesesProvider
method and thus cannot be used.From Pylint point of view. I could just hide the error, but I would like to solve this situation in a more elegant way, in order to allow to use normally
type()
.Obsiously, the refactor implies to rename this
type
parameter to something else. I choosedrtype
.But doing this refactoring on the public methods of
Provider
subclasses would break the API, if you use theses methods through named parameters (eg.provider.list_records(type='TXT',...
). Even ifProvider
subclasses should not be used directly, it is the case, in particular in Certbot. It could be corrected on upstream, but anyway retro-compatibility would be broken in an unacceptable range in my opinion.So this PR tries to solve also the retro-compatibility issue in a way that makes also the code stronger: instead of requiring to implement the public methods, it is now some private methods that are abstract. Public methods are defined only on the base class and call the private methods.
This approach avoid to rewrite accidentally the API on some providers (I saw it during this PR, and corrected it). And it allows to implement any retro-compatibility processing required to preserve the API: here, the public methods take advantage of
**kwargs
to detect iftype
named parameter have been passed, and redirect its value tortype
.This way, old codes will still work, without the need to hide the standard
type()
function. API refers officially nowrtype
, and a deprecation warning will be thrown iftype
is used in the relevant methods.