Skip to content

Commit 628a0e6

Browse files
Add opa_query_path to Organization/Inventory/JobTemplate (#15863)
1 parent 8fb5862 commit 628a0e6

10 files changed

+73
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Generated by Django 4.2.18 on 2025-03-17 16:10
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('main', '0196_indirect_managed_node_audit'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='inventory',
15+
name='opa_query_path',
16+
field=models.CharField(
17+
blank=True,
18+
default=None,
19+
help_text='The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule.',
20+
max_length=128,
21+
null=True,
22+
),
23+
),
24+
migrations.AddField(
25+
model_name='jobtemplate',
26+
name='opa_query_path',
27+
field=models.CharField(
28+
blank=True,
29+
default=None,
30+
help_text='The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule.',
31+
max_length=128,
32+
null=True,
33+
),
34+
),
35+
migrations.AddField(
36+
model_name='organization',
37+
name='opa_query_path',
38+
field=models.CharField(
39+
blank=True,
40+
default=None,
41+
help_text='The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule.',
42+
max_length=128,
43+
null=True,
44+
),
45+
),
46+
]

awx/main/migrations/0197_delete_profile.py awx/main/migrations/0198_delete_profile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Migration(migrations.Migration):
77
dependencies = [
8-
('main', '0196_indirect_managed_node_audit'),
8+
('main', '0197_add_opa_query_path'),
99
]
1010

1111
operations = [

awx/main/migrations/0198_remove_sso_app_content.py awx/main/migrations/0199_remove_sso_app_content.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Migration(migrations.Migration):
77
dependencies = [
8-
('main', '0197_delete_profile'),
8+
('main', '0198_delete_profile'),
99
]
1010

1111
operations = [

awx/main/migrations/0199_alter_inventorysource_source_and_more.py awx/main/migrations/0200_alter_inventorysource_source_and_more.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('main', '0198_remove_sso_app_content'),
9+
('main', '0199_remove_sso_app_content'),
1010
]
1111

1212
operations = [

awx/main/migrations/0200_alter_oauth2application_unique_together_and_more.py awx/main/migrations/0201_alter_oauth2application_unique_together_and_more.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('main', '0199_alter_inventorysource_source_and_more'),
9+
('main', '0200_alter_inventorysource_source_and_more'),
1010
]
1111

1212
operations = [

awx/main/migrations/0201_delete_token_cleanup_job.py awx/main/migrations/0202_delete_token_cleanup_job.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Migration(migrations.Migration):
99

1010
dependencies = [
11-
('main', '0200_alter_oauth2application_unique_together_and_more'),
11+
('main', '0201_alter_oauth2application_unique_together_and_more'),
1212
]
1313

1414
operations = [

awx/main/models/inventory.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
TaskManagerInventoryUpdateMixin,
4444
RelatedJobsMixin,
4545
CustomVirtualEnvMixin,
46+
OpaQueryPathMixin,
4647
)
4748
from awx.main.models.notifications import (
4849
NotificationTemplate,
@@ -68,7 +69,7 @@ class InventoryConstructedInventoryMembership(models.Model):
6869
)
6970

7071

71-
class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
72+
class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin, OpaQueryPathMixin):
7273
"""
7374
an inventory source contains lists and hosts.
7475
"""

awx/main/models/jobs.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
RelatedJobsMixin,
5252
WebhookMixin,
5353
WebhookTemplateMixin,
54+
OpaQueryPathMixin,
5455
)
5556
from awx.main.constants import JOB_VARIABLE_PREFIXES
5657

@@ -192,7 +193,9 @@ def passwords_needed_to_start(self):
192193
return needed
193194

194195

195-
class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, WebhookTemplateMixin):
196+
class JobTemplate(
197+
UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, WebhookTemplateMixin, OpaQueryPathMixin
198+
):
196199
"""
197200
A job template is a reusable job definition for applying a project (with
198201
playbook) to an inventory source with a given credential.

awx/main/models/mixins.py

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'TaskManagerInventoryUpdateMixin',
4343
'ExecutionEnvironmentMixin',
4444
'CustomVirtualEnvMixin',
45+
'OpaQueryPathMixin',
4546
]
4647

4748

@@ -692,3 +693,16 @@ def update_webhook_status(self, status):
692693
logger.debug("Webhook status update sent.")
693694
else:
694695
logger.error("Posting webhook status failed, code: {}\n" "{}\nPayload sent: {}".format(response.status_code, response.text, json.dumps(data)))
696+
697+
698+
class OpaQueryPathMixin(models.Model):
699+
class Meta:
700+
abstract = True
701+
702+
opa_query_path = models.CharField(
703+
max_length=128,
704+
blank=True,
705+
null=True,
706+
default=None,
707+
help_text=_("The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule."),
708+
)

awx/main/models/organization.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
ROLE_SINGLETON_SYSTEM_AUDITOR,
2323
)
2424
from awx.main.models.unified_jobs import UnifiedJob
25-
from awx.main.models.mixins import ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin
25+
from awx.main.models.mixins import ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, OpaQueryPathMixin
2626

2727
__all__ = ['Organization', 'Team', 'UserSessionMembership']
2828

2929

30-
class Organization(CommonModel, NotificationFieldsModel, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin):
30+
class Organization(CommonModel, NotificationFieldsModel, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, OpaQueryPathMixin):
3131
"""
3232
An organization is the basic unit of multi-tenancy divisions
3333
"""

0 commit comments

Comments
 (0)