Skip to content

Commit c13e6e4

Browse files
committed
[change] Rename who_is files/directories
- Added message matching for Validation errors - Docs update Signed-off-by: DragnEmperor <[email protected]>
1 parent dff447c commit c13e6e4

19 files changed

+260
-226
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ the OpenWISP architecture.
4949
user/openvpn.rst
5050
user/subnet-division-rules.rst
5151
user/rest-api.rst
52+
user/who-is.rst
5253
user/settings.rst
5354

5455
.. toctree::

docs/user/settings.rst

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -743,53 +743,41 @@ For more information on these settings, you can refer to the `the celery
743743
documentation regarding automatic retries for known errors.
744744
<https://docs.celeryq.dev/en/stable/userguide/tasks.html#automatic-retry-for-known-exceptions>`_
745745

746-
``OPENWISP_CONTROLLER_WHO_IS_ENABLED``
747-
--------------------------------------
746+
``OPENWISP_CONTROLLER_WHOIS_ENABLED``
747+
-------------------------------------
748748

749749
============ =========
750750
**type**: ``bool``
751751
**default**: ``False``
752752
============ =========
753753

754-
Allows to enable WhoIs lookup feature.
754+
Allows enabling the optional :doc:`WHOIS Lookup feature <who-is>`.
755755

756756
.. image:: https://github.com/user-attachments/assets/0737d39c-1fad-4fca-aca9-9b42bc321763
757-
:alt: who_is admin setting
757+
:alt: WHOIS admin setting
758758

759-
This feature is used to fetch details of a device based on its last
760-
reported public IP address. The fetched details include ASN, CIDR,
761-
address, timezone and name of organization associated with ASN.
759+
This feature is disabled by default. To enable it, set this option to
760+
``True`` and define both :ref:`OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT
761+
<OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT>` and
762+
:ref:`OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY
763+
<OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY>`.
762764

763-
This feature is disabled by default and requires setting the
764-
:ref:`OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID
765-
<OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID>` and
766-
:ref:`OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY
767-
<OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY>` settings to enable it.
768-
769-
``OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID``
770-
----------------------------------------
765+
``OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT``
766+
-------------------------------------------
771767

772768
============ =======
773769
**type**: ``str``
774770
**default**: None
775771
============ =======
776772

777-
This setting represents the Account ID of your Maxmind Account which can
778-
be obtained by following the steps mentioned in the :doc:`WhoIs Lookup
779-
<who-is>`.
773+
Maxmind Account ID required for :doc:`WHOIS Lookup <who-is>`.
780774

781-
This setting is required for WhoIs lookup feature to work.
782-
783-
``OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY``
784-
-----------------------------------------
775+
``OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY``
776+
---------------------------------------
785777

786778
============ =======
787779
**type**: ``str``
788780
**default**: None
789781
============ =======
790782

791-
This setting represents the License Key of your Maxmind Account which can
792-
be obtained by following the steps mentioned in the :doc:`WhoIs Lookup
793-
<who-is>`.
794-
795-
This setting is required for WhoIs lookup feature to work.
783+
Maxmind License Key required for :doc:`WHOIS Lookup <who-is>`.

docs/user/who-is.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ WHOIS Lookup
33

44
.. important::
55

6-
The WhoIs Lookup feature is disabled by default.
6+
The **WHOIS Lookup** feature is disabled by default.
77

88
In order to enable this feature you have to follow the `setup
9-
instructions <controller_setup_who_is_lookup_>`_ below and then
9+
instructions <controller_setup_whois_lookup_>`_ below and then
1010
activate it via :ref:`global setting or from the admin interface
11-
<OPENWISP_CONTROLLER_WHO_IS_ENABLED>`.
11+
<OPENWISP_CONTROLLER_WHOIS_ENABLED>`.
1212

1313
.. warning::
1414

15-
If the :ref:`OPENWISP_CONTROLLER_WHO_IS_ENABLED` setting is set to
15+
If the :ref:`OPENWISP_CONTROLLER_WHOIS_ENABLED` setting is set to
1616
``True`` and the required environment variables are not set, then
1717
``ImproperlyConfigured`` exception will be raised.
1818

19-
Both of the settings :ref:`OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID` and
20-
:ref:`OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY` are required to be set,
21-
to ensure the WhoIs Lookup feature can be enabled/disabled for each
19+
Both of the settings :ref:`OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT`
20+
and :ref:`OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY` are required to be set,
21+
to ensure the WHOIS Lookup feature can be enabled/disabled for each
2222
organization. Else, the feature will be disabled globally and the
2323
field will not be available to configure on admin interface.
2424

25-
WhoIs feature includes fetching details of the last public ip address
25+
WHOIS feature includes fetching details of the last public ip address
2626
reported by a device to ensure better device management.
2727

28-
The fetched details include Organization Name, ASN, CIDR, Address,
29-
Timezone.
28+
The fetched details include ASN, CIDR, Address, Timezone and Name of
29+
Organization associated with ASN.
3030

31-
.. _controller_setup_who_is_lookup:
31+
.. _controller_setup_whois_lookup:
3232

3333
Setup
3434
-----
@@ -38,11 +38,11 @@ follows:
3838

3939
.. code-block:: python
4040
41-
OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID = os.getenv(
42-
"OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID", ""
41+
OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT = os.getenv(
42+
"OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT", ""
4343
)
44-
OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY = os.getenv(
45-
"OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY", ""
44+
OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY = os.getenv(
45+
"OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY", ""
4646
)
4747
4848
Steps to obtain values of above settings
@@ -58,5 +58,5 @@ Steps to obtain values of above settings
5858
- Generate a New license Key. Name it whatever you like .. image::
5959
https://github.com/user-attachments/assets/57df27bc-4f9d-4701-88bf-91e6b715e4a6
6060
- Copy the *Account Id* and *License Key* and Paste it in the environment
61-
variables: **OPENWISP_CONTROLLER_GEOIP_ACCOUNT_ID** and
62-
**OPENWISP_CONTROLLER_GEOIP_LICENSE_KEY**.
61+
variables: **OPENWISP_CONTROLLER_WHOIS_GEOIP_ACCOUNT** and
62+
**OPENWISP_CONTROLLER_WHOIS_GEOIP_KEY**.

openwisp_controller/config/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,8 @@ class ConfigSettingsInline(admin.StackedInline):
13641364

13651365
def get_fields(self, request, obj=None):
13661366
fields = super().get_fields(request, obj)
1367-
if not app_settings.WHO_IS_CONFIGURED:
1368-
fields.remove("who_is_enabled")
1367+
if not app_settings.WHOIS_CONFIGURED:
1368+
fields.remove("whois_enabled")
13691369
return fields
13701370

13711371
OrganizationAdmin.save_on_top = True

openwisp_controller/config/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
vpn_peers_changed,
3232
vpn_server_modified,
3333
)
34-
from .who_is.handlers import connect_who_is_handlers
34+
from .whois.handlers import connect_whois_handlers
3535

3636
# ensure Device.hardware_id field is not flagged as unique
3737
# (because it's flagged as unique_together with organization)
@@ -53,7 +53,7 @@ def ready(self, *args, **kwargs):
5353
self.register_dashboard_charts()
5454
self.register_menu_groups()
5555
self.notification_cache_update()
56-
connect_who_is_handlers()
56+
connect_whois_handlers()
5757

5858
def __setmodels__(self):
5959
self.device_model = load_model("config", "Device")

openwisp_controller/config/base/device.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
management_ip_changed,
2020
)
2121
from ..validators import device_name_validator, mac_address_validator
22-
from ..who_is.service import WhoIsService
22+
from ..whois.service import WhoIsService
2323
from .base import BaseModel
2424

2525

@@ -122,7 +122,7 @@ def __init__(self, *args, **kwargs):
122122
super().__init__(*args, **kwargs)
123123
# Initial value for last_ip is required in WhoIs
124124
# to remove WhoIs info related to that ip address.
125-
if app_settings.WHO_IS_CONFIGURED:
125+
if app_settings.WHOIS_CONFIGURED:
126126
self._changed_checked_fields.append("last_ip")
127127

128128
self._set_initial_values_for_changed_checked_fields()
@@ -286,7 +286,7 @@ def save(self, *args, **kwargs):
286286
self.key = self.generate_key(shared_secret)
287287
state_adding = self._state.adding
288288
super().save(*args, **kwargs)
289-
if app_settings.WHO_IS_CONFIGURED:
289+
if app_settings.WHOIS_CONFIGURED:
290290
self._check_last_ip()
291291
if state_adding and self.group and self.group.templates.exists():
292292
self.create_default_config()
@@ -379,9 +379,7 @@ def _check_last_ip(self):
379379
"""Trigger WhoIs lookup if last_ip is not deferred."""
380380
if self._initial_last_ip == models.DEFERRED:
381381
return
382-
383-
self.who_is_service.trigger_who_is_lookup()
384-
382+
self.whois_service.trigger_whois_lookup()
385383
self._initial_last_ip = self.last_ip
386384

387385
def _check_organization_id_changed(self):
@@ -423,7 +421,7 @@ def status(self):
423421
return self._get_config_attr("get_status_display")
424422

425423
@cached_property
426-
def who_is_service(self):
424+
def whois_service(self):
427425
"""
428426
Used as a shortcut to get WhoIsService instance
429427
for the device.

openwisp_controller/config/base/multitenancy.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class AbstractOrganizationConfigSettings(UUIDModel):
3434
verbose_name=_("shared secret"),
3535
help_text=_("used for automatic registration of devices"),
3636
)
37+
whois_enabled = FallbackBooleanChoiceField(
38+
help_text=_("Whether the WhoIs lookup feature is enabled"),
39+
fallback=app_settings.WHOIS_ENABLED,
40+
verbose_name=_("WhoIs Enabled"),
41+
)
3742
context = JSONField(
3843
blank=True,
3944
default=dict,
@@ -44,11 +49,6 @@ class AbstractOrganizationConfigSettings(UUIDModel):
4449
),
4550
verbose_name=_("Configuration Variables"),
4651
)
47-
who_is_enabled = FallbackBooleanChoiceField(
48-
help_text=_("Whether the WhoIs lookup feature is enabled"),
49-
fallback=app_settings.WHO_IS_ENABLED,
50-
verbose_name=_("WhoIs Enabled"),
51-
)
5252

5353
class Meta:
5454
verbose_name = _("Configuration management settings")
@@ -62,12 +62,14 @@ def get_context(self):
6262
return deepcopy(self.context)
6363

6464
def clean(self):
65-
if not app_settings.WHO_IS_CONFIGURED and self.who_is_enabled:
65+
if not app_settings.WHOIS_CONFIGURED and self.whois_enabled:
6666
raise ValidationError(
67-
_(
68-
"GEOIP_ACCOUNT_ID and GEOIP_LICENSE_KEY must be set "
69-
+ "before enabling WhoIs feature."
70-
)
67+
{
68+
"whois_enabled": _(
69+
"WHOIS_GEOIP_ACCOUNT and WHOIS_GEOIP_KEY must be set "
70+
+ "before enabling WhoIs feature."
71+
)
72+
}
7173
)
7274
return super().clean()
7375

openwisp_controller/config/base/who_is.py renamed to openwisp_controller/config/base/whois.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from openwisp_utils.base import TimeStampedEditableModel
1010

11-
from ..who_is.service import WhoIsService
11+
from ..whois.service import WhoIsService
1212

1313

1414
class AbstractWhoIsInfo(TimeStampedEditableModel):
@@ -51,7 +51,11 @@ class Meta:
5151
def clean(self):
5252
if ip_address(self.ip_address).is_private:
5353
raise ValidationError(
54-
_("WhoIs information cannot be created for private IP addresses.")
54+
{
55+
"ip_address": _(
56+
"WhoIs information cannot be created for private IP addresses."
57+
)
58+
}
5559
)
5660
if self.cidr:
5761
try:
@@ -61,19 +65,19 @@ def clean(self):
6165
ip_network(self.cidr, strict=False)
6266
except ValueError as e:
6367
raise ValidationError(
64-
_("Invalid CIDR format: %(error)s") % {"error": str(e)}
68+
{"cidr": _("Invalid CIDR format: %(error)s") % {"error": str(e)}}
6569
)
6670
return super().clean()
6771

6872
@staticmethod
69-
def device_who_is_info_delete_handler(instance, **kwargs):
73+
def device_whois_info_delete_handler(instance, **kwargs):
7074
"""
7175
Delete WhoIs information for a device when the last IP address is removed or
7276
when device is deleted.
7377
"""
74-
if instance._get_organization__config_settings().who_is_enabled:
78+
if instance._get_organization__config_settings().whois_enabled:
7579
transaction.on_commit(
76-
lambda: WhoIsService.delete_who_is_record.delay(instance.last_ip)
80+
lambda: WhoIsService.delete_whois_record.delay(instance.last_ip)
7781
)
7882

7983
# this method is kept here instead of in OrganizationConfigSettings because

openwisp_controller/config/migrations/0060_whoisinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Migration(migrations.Migration):
8282
field=openwisp_utils.fields.FallbackBooleanChoiceField(
8383
blank=True,
8484
default=None,
85-
fallback=app_settings.WHO_IS_ENABLED,
85+
fallback=app_settings.WHOIS_ENABLED,
8686
help_text="Whether WhoIs details lookup is enabled",
8787
null=True,
8888
verbose_name="WhoIs Enabled",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.1 on 2025-06-24 15:30
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("config", "0061_remove_whoisinfo_country_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name="organizationconfigsettings",
15+
old_name="who_is_enabled",
16+
new_name="whois_enabled",
17+
),
18+
]

0 commit comments

Comments
 (0)