-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add reverse_pointer filter and reverse_lookup lookup #228
Conversation
Docs Build 📝Thank you for contribution!✨ This PR has been merged and the docs are now incorporated into |
2da4a2e
to
f1907de
Compare
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.
LGTM. I suggested some type hints but I'll leave it to your discretion b/c I know they require import statements. I find them useful anyway. Hope this helps.
pass | ||
|
||
|
||
def reverse_pointer(ip): |
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.
def reverse_pointer(ip): | |
def reverse_pointer(ip: str) -> str: |
class FilterModule(object): | ||
'''Ansible jinja2 filters''' | ||
|
||
def filters(self): |
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.
def filters(self): | |
def filters(self) -> Dict[str, Any]: |
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.
I'm not sure since when exactly, but since Python 3.8 or 3.9 you can also write dict[str, Any]
(same for list
and tuple
etc.).
server=name, | ||
) | ||
|
||
def run(self, terms, variables=None, **kwargs): |
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.
def run(self, terms, variables=None, **kwargs): | |
def run(self, terms: List[str], variables: Optional[dict] = None, **kwargs: Any): -> List[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.
Instead of Optional[dict]
you can also use dict | None
. That requires either 3.9 or 3.10 (I'm not sure anymore), but with the right __future__
import (I think from __future__ import annotations
) you can already start using it in Python 3.7+ (as long as the type checking happens with a new enough Python).
|
||
class LookupModule(LookupBase): | ||
@staticmethod | ||
def _resolve(resolver, name, rdtype, server_addresses): |
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.
def _resolve(resolver, name, rdtype, server_addresses): | |
def _resolve(resolver, name: str, rdtype: int, server_addresses: Optional[List[str]]): -> List[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.
I think the type hint for the resolver
parameter would be SimpleResolver
right? so resolver: SimpleResolver
Type hints are a great idea; the collection requires ansible-core 2.14+, which means Python 3.9+ on the controller side. So type hints are definitely possible! (And already would have been since ansible-core 2.12+.) I'd prefer to add type hints in a follow-up PR though (and then for everything else than modules and module_utils as well), and figure out there how well type checking works with ansible-test. |
@oraNod thanks for reviewing this! |
SUMMARY
Add plugins for helping with reverse lookups:
Fixes #227.
ISSUE TYPE
COMPONENT NAME
reverse_pointer filter