-
-
Notifications
You must be signed in to change notification settings - Fork 909
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 Custom Link and Webhook initializers #391
Conversation
@cimnine, as requested, I pulled the new features into a new branch. The code was already outdated so I also updated the startup scripts and added error handling, icon printing, etc. |
fix comment
…latest netbox release
d6e11ff
to
1ad1faf
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.
Thank you for the contribution! This could one day even the way to do full fledged integration testing of the webhooks feature. Really cool!
Please also see my previous feedback. I would like to merge this in the version we're currently preparing. If you can't look at the feedback right now (that's perfectly ok!), I'd appreciate a quick message so that we can get all the other changes out.
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
I typically get on around 8pm CST. I am just seeing this, I apologize if this is late notice. I can fix it tonight. |
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Move to a more standard method of object handling
No need to apologize. I don't expect people to have time immediately. I just wanted to know whether we should proceed with the release or if you think you will have time soon-ish to look at the comments :) |
Thank you for your help! Is there anything left to do before merging this in? |
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.
Thank you for your effort to improve and fix the code. I've again added some recommendations. If you find them actionable, please make sure to check the rest of this PR's changes if these remarks apply there as well, as I typically don't add a remark twice when it's the identical remark, just on a different subset of the code.
Otherwise I welcome your argument wherever you disagree :)
# - name: link_to_localhost | ||
# text: 'Link to the users localhost' | ||
# url: 'http://localhost' | ||
# new_window: True | ||
# content_type: device |
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.
This part is still wrong:
# - name: link_to_localhost | |
# text: 'Link to the users localhost' | |
# url: 'http://localhost' | |
# new_window: True | |
# content_type: device | |
# - name: link_to_localhost | |
# text: 'Link to the users localhost' | |
# url: 'http://localhost' | |
# new_window: True | |
# content_type: device |
You can run the test locally to see if your changes work and integrate with all the other initializers:
./build-latest.sh && ./test.sh latest
if link['content_type_id'] is not None: | ||
custom_link = CustomLink(**link) | ||
if not CustomLink.objects.filter(name=custom_link.name): | ||
custom_link.save() |
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.
You did change the implementation to get_or_create
after my comment in 290_webhooks.py
– didn't that work with custom links, was this just an oversight or didn't you intentionally not change it here?
for link in custom_links: | ||
content_type = link.pop('content_type') | ||
link['content_type_id'] = get_content_type_id(content_type) | ||
if link['content_type_id'] is not None: |
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 suggest to change the logic here as follows:
if link['content_type_id'] is not None: | |
if link['content_type_id'] is None: | |
print("⚠️ Unable to create Custom Link '{0}': The content_type '{1}' is unknown".format(link.name, content_type)) | |
continue |
This will make it obvious which custom link failed to get created and why.
try: | ||
return ContentType.objects.get(model=content_type_str).id | ||
except ContentType.DoesNotExist: | ||
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_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.
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str)) | |
return None |
... or ...
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str)) | |
pass |
... (not sure which is more idiomatic in Python).
The error is technically accurate, but not actionable for our users.
They will not know what went wrong. And because we don't have access to the context here (i.e. the custom_link.name
is not known, and it would be a drag to pass it to this function just in case there's an error), I would skip a message here and replace it with an error in the caller. (As per above suggestion.)
custom_link = CustomLink(**link) | ||
if not CustomLink.objects.filter(name=custom_link.name): | ||
custom_link.save() | ||
print("🖥️ Created Custom Link {0}".format(custom_link.name)) |
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.
print("🖥️ Created Custom Link {0}".format(custom_link.name)) | |
print("🖥️ Created Custom Link '{0}'".format(custom_link.name)) |
It's cool to have this additional information, which custom link was created. Though it's good habit to enclose strings into quotation signs when printing them to stdout. Otherwise it's really hard to see if there is e.g. an extra whitespace where there shouldn't have been one.
Merged with commit f33c647 |
Related Issue:
New Behavior
Custom link and web hooks can now be created via startup scripts.
...
Contrast to Current Behavior
Current implementation is missing this behavior.
...
Discussion: Benefits and Drawbacks
...
Changes to the Wiki
...
Proposed Release Note Entry
Added custom_link initializer
Added webhook initializer
...
Double Check
develop
branch.