netbox-sqlquery 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. netbox_sqlquery-0.1.0/LICENSE +200 -0
  2. netbox_sqlquery-0.1.0/PKG-INFO +140 -0
  3. netbox_sqlquery-0.1.0/README.md +127 -0
  4. netbox_sqlquery-0.1.0/netbox_sqlquery/__init__.py +72 -0
  5. netbox_sqlquery-0.1.0/netbox_sqlquery/abstract_schema.py +406 -0
  6. netbox_sqlquery-0.1.0/netbox_sqlquery/access.py +157 -0
  7. netbox_sqlquery-0.1.0/netbox_sqlquery/api/__init__.py +0 -0
  8. netbox_sqlquery-0.1.0/netbox_sqlquery/api/serializers.py +35 -0
  9. netbox_sqlquery-0.1.0/netbox_sqlquery/api/urls.py +8 -0
  10. netbox_sqlquery-0.1.0/netbox_sqlquery/api/views.py +15 -0
  11. netbox_sqlquery-0.1.0/netbox_sqlquery/filtersets.py +12 -0
  12. netbox_sqlquery-0.1.0/netbox_sqlquery/forms.py +20 -0
  13. netbox_sqlquery-0.1.0/netbox_sqlquery/management/__init__.py +0 -0
  14. netbox_sqlquery-0.1.0/netbox_sqlquery/management/commands/__init__.py +0 -0
  15. netbox_sqlquery-0.1.0/netbox_sqlquery/management/commands/sqlquery_create_views.py +39 -0
  16. netbox_sqlquery-0.1.0/netbox_sqlquery/migrations/0001_initial.py +95 -0
  17. netbox_sqlquery-0.1.0/netbox_sqlquery/migrations/0002_query_permissions.py +21 -0
  18. netbox_sqlquery-0.1.0/netbox_sqlquery/migrations/0003_tablepermission_groups_to_users_group.py +17 -0
  19. netbox_sqlquery-0.1.0/netbox_sqlquery/migrations/__init__.py +0 -0
  20. netbox_sqlquery-0.1.0/netbox_sqlquery/models.py +106 -0
  21. netbox_sqlquery-0.1.0/netbox_sqlquery/navigation.py +44 -0
  22. netbox_sqlquery-0.1.0/netbox_sqlquery/preferences.py +64 -0
  23. netbox_sqlquery-0.1.0/netbox_sqlquery/schema.py +52 -0
  24. netbox_sqlquery-0.1.0/netbox_sqlquery/tables.py +18 -0
  25. netbox_sqlquery-0.1.0/netbox_sqlquery/tests/__init__.py +0 -0
  26. netbox_sqlquery-0.1.0/netbox_sqlquery/tests/test_access.py +96 -0
  27. netbox_sqlquery-0.1.0/netbox_sqlquery/tests/test_api.py +41 -0
  28. netbox_sqlquery-0.1.0/netbox_sqlquery/tests/test_models.py +45 -0
  29. netbox_sqlquery-0.1.0/netbox_sqlquery/tests/test_views.py +94 -0
  30. netbox_sqlquery-0.1.0/netbox_sqlquery/urls.py +22 -0
  31. netbox_sqlquery-0.1.0/netbox_sqlquery/views.py +354 -0
  32. netbox_sqlquery-0.1.0/netbox_sqlquery.egg-info/PKG-INFO +140 -0
  33. netbox_sqlquery-0.1.0/netbox_sqlquery.egg-info/SOURCES.txt +35 -0
  34. netbox_sqlquery-0.1.0/netbox_sqlquery.egg-info/dependency_links.txt +1 -0
  35. netbox_sqlquery-0.1.0/netbox_sqlquery.egg-info/top_level.txt +1 -0
  36. netbox_sqlquery-0.1.0/pyproject.toml +31 -0
  37. netbox_sqlquery-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,200 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. Please also get an original
185
+ source header from http://www.apache.org/legal/ to verify that
186
+ you have the correct license header.
187
+
188
+ Copyright 2026 Ravi Pina
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: netbox-sqlquery
3
+ Version: 0.1.0
4
+ Summary: SQL query interface for NetBox with syntax highlighting, abstract views, and role-based access control
5
+ Author-email: Ravi Pina <ravi@pina.org>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/ravinald/netbox-sqlquery
8
+ Project-URL: Issues, https://github.com/ravinald/netbox-sqlquery/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # netbox-sqlquery
15
+
16
+ [![CI](https://github.com/ravinald/netbox-sqlquery/actions/workflows/ci.yml/badge.svg)](https://github.com/ravinald/netbox-sqlquery/actions/workflows/ci.yml)
17
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
18
+
19
+ A NetBox plugin that provides a SQL query interface with syntax highlighting, abstract views, saved queries, and role-based access control.
20
+
21
+ ## Features
22
+
23
+ - SQL console with real-time syntax highlighting and auto-uppercase keywords
24
+ - Abstract views (`nb_*`) that resolve foreign keys to names and aggregate tags
25
+ - Schema sidebar with search filter and Raw SQL / Views toggle
26
+ - Interactive results: click columns to refine SELECT, click cells to add WHERE filters
27
+ - Saved queries with save/load dialogs and private/public visibility
28
+ - Write query support (INSERT, UPDATE, DELETE) with confirmation dialog
29
+ - Role-based access control integrated with NetBox's ObjectPermission system
30
+ - Per-user color preferences for syntax highlighting
31
+ - CSV export
32
+ - Compatible with NetBox 4.0 through 4.5, netbox-docker, and OIDC providers
33
+
34
+ ## Screenshots
35
+
36
+ ### Views mode
37
+ Query abstract views that resolve foreign keys and aggregate tags, matching how data appears in the NetBox UI.
38
+
39
+ <img src="docs/images/view-query.png" alt="Views mode query" width="800">
40
+
41
+ ### Raw SQL mode
42
+ Query the database directly with full PostgreSQL power.
43
+
44
+ <img src="docs/images/raw-query.png" alt="Raw SQL query" width="800">
45
+
46
+ ### Column select
47
+ Click column headers to refine which columns are returned.
48
+
49
+ <img src="docs/images/view-query-column-select.png" alt="Column selection" width="800">
50
+
51
+ ### Saving queries
52
+ Save queries for reuse with private or public visibility.
53
+
54
+ <img src="docs/images/saving-query.png" alt="Save query dialog" width="400">
55
+
56
+ ### Saved queries list
57
+
58
+ <img src="docs/images/saved-query-list.png" alt="Saved queries list" width="800">
59
+
60
+ ### Permissions setup
61
+ Control access using NetBox's native ObjectPermission system.
62
+
63
+ <img src="docs/images/permissions.png" alt="Permissions setup" width="800">
64
+
65
+ ### User preferences
66
+ Customize syntax highlighting colors per user.
67
+
68
+ <img src="docs/images/user-preferences.png" alt="User preferences" width="800">
69
+
70
+ ## Compatibility
71
+
72
+ See [COMPATIBILITY.md](COMPATIBILITY.md) for the full version matrix.
73
+
74
+ | NetBox version | Python versions |
75
+ |----------------|------------------------------|
76
+ | 4.0 - 4.5 | 3.10, 3.11, 3.12, 3.13, 3.14 |
77
+
78
+ ## Installation
79
+
80
+ ```bash
81
+ pip install netbox-sqlquery
82
+ ```
83
+
84
+ Add to your NetBox `configuration.py`:
85
+
86
+ ```python
87
+ PLUGINS = ["netbox_sqlquery"]
88
+
89
+ PLUGINS_CONFIG = {
90
+ "netbox_sqlquery": {
91
+ "require_superuser": True,
92
+ "max_rows": 1000,
93
+ "statement_timeout_ms": 10000,
94
+ "deny_tables": [
95
+ "auth_user",
96
+ "users_token",
97
+ "users_userconfig",
98
+ ],
99
+ }
100
+ }
101
+ ```
102
+
103
+ Run migrations:
104
+
105
+ ```bash
106
+ python manage.py migrate netbox_sqlquery
107
+ ```
108
+
109
+ Collect static files:
110
+
111
+ ```bash
112
+ python manage.py collectstatic --no-input
113
+ ```
114
+
115
+ For Docker-based installations, see [docs/docker.md](docs/docker.md).
116
+
117
+ ## Configuration
118
+
119
+ | Setting | Type | Default | Description |
120
+ |------------------------|------|----------------------------------------------------|-------------------------------------------------------|
121
+ | `require_superuser` | bool | `True` | Require superuser to access the query view |
122
+ | `max_rows` | int | `1000` | Maximum rows returned per query |
123
+ | `statement_timeout_ms` | int | `10000` | PostgreSQL statement timeout in milliseconds |
124
+ | `deny_tables` | list | `["auth_user", "users_token", "users_userconfig"]` | Tables blocked for all users including superusers |
125
+ | `top_level_menu` | bool | `False` | Show as a top-level nav menu instead of under Plugins |
126
+
127
+ ## Documentation
128
+
129
+ - [Installation](docs/installation.md)
130
+ - [Configuration](docs/configuration.md)
131
+ - [Usage](docs/usage.md)
132
+ - [Permissions](docs/permissions.md)
133
+ - [Saved queries](docs/saved-queries.md)
134
+ - [Operations](docs/operations.md)
135
+ - [Docker](docs/docker.md)
136
+ - [Uninstalling](docs/uninstall.md)
137
+
138
+ ## License
139
+
140
+ Apache 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,127 @@
1
+ # netbox-sqlquery
2
+
3
+ [![CI](https://github.com/ravinald/netbox-sqlquery/actions/workflows/ci.yml/badge.svg)](https://github.com/ravinald/netbox-sqlquery/actions/workflows/ci.yml)
4
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
5
+
6
+ A NetBox plugin that provides a SQL query interface with syntax highlighting, abstract views, saved queries, and role-based access control.
7
+
8
+ ## Features
9
+
10
+ - SQL console with real-time syntax highlighting and auto-uppercase keywords
11
+ - Abstract views (`nb_*`) that resolve foreign keys to names and aggregate tags
12
+ - Schema sidebar with search filter and Raw SQL / Views toggle
13
+ - Interactive results: click columns to refine SELECT, click cells to add WHERE filters
14
+ - Saved queries with save/load dialogs and private/public visibility
15
+ - Write query support (INSERT, UPDATE, DELETE) with confirmation dialog
16
+ - Role-based access control integrated with NetBox's ObjectPermission system
17
+ - Per-user color preferences for syntax highlighting
18
+ - CSV export
19
+ - Compatible with NetBox 4.0 through 4.5, netbox-docker, and OIDC providers
20
+
21
+ ## Screenshots
22
+
23
+ ### Views mode
24
+ Query abstract views that resolve foreign keys and aggregate tags, matching how data appears in the NetBox UI.
25
+
26
+ <img src="docs/images/view-query.png" alt="Views mode query" width="800">
27
+
28
+ ### Raw SQL mode
29
+ Query the database directly with full PostgreSQL power.
30
+
31
+ <img src="docs/images/raw-query.png" alt="Raw SQL query" width="800">
32
+
33
+ ### Column select
34
+ Click column headers to refine which columns are returned.
35
+
36
+ <img src="docs/images/view-query-column-select.png" alt="Column selection" width="800">
37
+
38
+ ### Saving queries
39
+ Save queries for reuse with private or public visibility.
40
+
41
+ <img src="docs/images/saving-query.png" alt="Save query dialog" width="400">
42
+
43
+ ### Saved queries list
44
+
45
+ <img src="docs/images/saved-query-list.png" alt="Saved queries list" width="800">
46
+
47
+ ### Permissions setup
48
+ Control access using NetBox's native ObjectPermission system.
49
+
50
+ <img src="docs/images/permissions.png" alt="Permissions setup" width="800">
51
+
52
+ ### User preferences
53
+ Customize syntax highlighting colors per user.
54
+
55
+ <img src="docs/images/user-preferences.png" alt="User preferences" width="800">
56
+
57
+ ## Compatibility
58
+
59
+ See [COMPATIBILITY.md](COMPATIBILITY.md) for the full version matrix.
60
+
61
+ | NetBox version | Python versions |
62
+ |----------------|------------------------------|
63
+ | 4.0 - 4.5 | 3.10, 3.11, 3.12, 3.13, 3.14 |
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ pip install netbox-sqlquery
69
+ ```
70
+
71
+ Add to your NetBox `configuration.py`:
72
+
73
+ ```python
74
+ PLUGINS = ["netbox_sqlquery"]
75
+
76
+ PLUGINS_CONFIG = {
77
+ "netbox_sqlquery": {
78
+ "require_superuser": True,
79
+ "max_rows": 1000,
80
+ "statement_timeout_ms": 10000,
81
+ "deny_tables": [
82
+ "auth_user",
83
+ "users_token",
84
+ "users_userconfig",
85
+ ],
86
+ }
87
+ }
88
+ ```
89
+
90
+ Run migrations:
91
+
92
+ ```bash
93
+ python manage.py migrate netbox_sqlquery
94
+ ```
95
+
96
+ Collect static files:
97
+
98
+ ```bash
99
+ python manage.py collectstatic --no-input
100
+ ```
101
+
102
+ For Docker-based installations, see [docs/docker.md](docs/docker.md).
103
+
104
+ ## Configuration
105
+
106
+ | Setting | Type | Default | Description |
107
+ |------------------------|------|----------------------------------------------------|-------------------------------------------------------|
108
+ | `require_superuser` | bool | `True` | Require superuser to access the query view |
109
+ | `max_rows` | int | `1000` | Maximum rows returned per query |
110
+ | `statement_timeout_ms` | int | `10000` | PostgreSQL statement timeout in milliseconds |
111
+ | `deny_tables` | list | `["auth_user", "users_token", "users_userconfig"]` | Tables blocked for all users including superusers |
112
+ | `top_level_menu` | bool | `False` | Show as a top-level nav menu instead of under Plugins |
113
+
114
+ ## Documentation
115
+
116
+ - [Installation](docs/installation.md)
117
+ - [Configuration](docs/configuration.md)
118
+ - [Usage](docs/usage.md)
119
+ - [Permissions](docs/permissions.md)
120
+ - [Saved queries](docs/saved-queries.md)
121
+ - [Operations](docs/operations.md)
122
+ - [Docker](docs/docker.md)
123
+ - [Uninstalling](docs/uninstall.md)
124
+
125
+ ## License
126
+
127
+ Apache 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,72 @@
1
+ import logging
2
+
3
+ from netbox.plugins import PluginConfig
4
+
5
+ logger = logging.getLogger("netbox_sqlquery")
6
+
7
+
8
+ class NetBoxSQLQueryConfig(PluginConfig):
9
+ name = "netbox_sqlquery"
10
+ verbose_name = "SQL Query Explorer"
11
+ description = (
12
+ "SQL query interface for NetBox with syntax highlighting,"
13
+ " abstract views, and role-based access control"
14
+ )
15
+ version = "0.1.0"
16
+ author = "Ravi Pina"
17
+ author_email = "ravi@pina.org"
18
+ base_url = "sqlquery"
19
+ min_version = "4.0.0"
20
+ max_version = None
21
+ required_settings = []
22
+ default_settings = {
23
+ "require_superuser": True,
24
+ "max_rows": 1000,
25
+ "statement_timeout_ms": 10_000,
26
+ "deny_tables": [
27
+ "auth_user",
28
+ "users_token",
29
+ "users_userconfig",
30
+ ],
31
+ "top_level_menu": False,
32
+ }
33
+
34
+ # Suppress auto-loading; we register navigation conditionally in ready()
35
+ menu = None
36
+ menu_items = None
37
+
38
+ def ready(self):
39
+ super().ready()
40
+
41
+ # Register navigation based on top_level_menu setting
42
+ self._register_navigation()
43
+
44
+ # Create abstract SQL views
45
+ try:
46
+ from .abstract_schema import ensure_views
47
+ ensure_views()
48
+ except Exception as exc:
49
+ logger.warning(
50
+ "Could not create abstract SQL views: %s. "
51
+ "Run 'manage.py sqlquery_create_views' manually.",
52
+ exc,
53
+ )
54
+
55
+ def _register_navigation(self):
56
+ from netbox.plugins.registration import register_menu, register_menu_items
57
+
58
+ from .navigation import get_menu, get_menu_items
59
+
60
+ try:
61
+ from netbox.plugins import get_plugin_config
62
+ top_level = get_plugin_config("netbox_sqlquery", "top_level_menu")
63
+ except Exception:
64
+ top_level = False
65
+
66
+ if top_level:
67
+ register_menu(get_menu())
68
+ else:
69
+ register_menu_items(self.verbose_name, get_menu_items())
70
+
71
+
72
+ config = NetBoxSQLQueryConfig