mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Add opa_query_path to Organization/Inventory/JobTemplate (#15863)
This commit is contained in:
parent
8fb5862223
commit
628a0e6a36
46
awx/main/migrations/0197_add_opa_query_path.py
Normal file
46
awx/main/migrations/0197_add_opa_query_path.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Generated by Django 4.2.18 on 2025-03-17 16:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0196_indirect_managed_node_audit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='inventory',
|
||||
name='opa_query_path',
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
default=None,
|
||||
help_text='The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule.',
|
||||
max_length=128,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='jobtemplate',
|
||||
name='opa_query_path',
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
default=None,
|
||||
help_text='The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule.',
|
||||
max_length=128,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='organization',
|
||||
name='opa_query_path',
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
default=None,
|
||||
help_text='The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule.',
|
||||
max_length=128,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
]
|
||||
@ -5,7 +5,7 @@ from django.db import migrations
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('main', '0196_indirect_managed_node_audit'),
|
||||
('main', '0197_add_opa_query_path'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -5,7 +5,7 @@ from django.db import migrations
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('main', '0197_delete_profile'),
|
||||
('main', '0198_delete_profile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -6,7 +6,7 @@ from django.db import migrations, models
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0198_remove_sso_app_content'),
|
||||
('main', '0199_remove_sso_app_content'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -6,7 +6,7 @@ from django.db import migrations
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0199_alter_inventorysource_source_and_more'),
|
||||
('main', '0200_alter_inventorysource_source_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -8,7 +8,7 @@ from awx.main.migrations._create_system_jobs import delete_clear_tokens_sjt
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0200_alter_oauth2application_unique_together_and_more'),
|
||||
('main', '0201_alter_oauth2application_unique_together_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -43,6 +43,7 @@ from awx.main.models.mixins import (
|
||||
TaskManagerInventoryUpdateMixin,
|
||||
RelatedJobsMixin,
|
||||
CustomVirtualEnvMixin,
|
||||
OpaQueryPathMixin,
|
||||
)
|
||||
from awx.main.models.notifications import (
|
||||
NotificationTemplate,
|
||||
@ -68,7 +69,7 @@ class InventoryConstructedInventoryMembership(models.Model):
|
||||
)
|
||||
|
||||
|
||||
class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
||||
class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin, OpaQueryPathMixin):
|
||||
"""
|
||||
an inventory source contains lists and hosts.
|
||||
"""
|
||||
|
||||
@ -51,6 +51,7 @@ from awx.main.models.mixins import (
|
||||
RelatedJobsMixin,
|
||||
WebhookMixin,
|
||||
WebhookTemplateMixin,
|
||||
OpaQueryPathMixin,
|
||||
)
|
||||
from awx.main.constants import JOB_VARIABLE_PREFIXES
|
||||
|
||||
@ -192,7 +193,9 @@ class JobOptions(BaseModel):
|
||||
return needed
|
||||
|
||||
|
||||
class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, WebhookTemplateMixin):
|
||||
class JobTemplate(
|
||||
UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, WebhookTemplateMixin, OpaQueryPathMixin
|
||||
):
|
||||
"""
|
||||
A job template is a reusable job definition for applying a project (with
|
||||
playbook) to an inventory source with a given credential.
|
||||
|
||||
@ -42,6 +42,7 @@ __all__ = [
|
||||
'TaskManagerInventoryUpdateMixin',
|
||||
'ExecutionEnvironmentMixin',
|
||||
'CustomVirtualEnvMixin',
|
||||
'OpaQueryPathMixin',
|
||||
]
|
||||
|
||||
|
||||
@ -692,3 +693,16 @@ class WebhookMixin(models.Model):
|
||||
logger.debug("Webhook status update sent.")
|
||||
else:
|
||||
logger.error("Posting webhook status failed, code: {}\n" "{}\nPayload sent: {}".format(response.status_code, response.text, json.dumps(data)))
|
||||
|
||||
|
||||
class OpaQueryPathMixin(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
opa_query_path = models.CharField(
|
||||
max_length=128,
|
||||
blank=True,
|
||||
null=True,
|
||||
default=None,
|
||||
help_text=_("The query path for the OPA policy to evaluate prior to job execution. The query path should be formatted as package/rule."),
|
||||
)
|
||||
|
||||
@ -22,12 +22,12 @@ from awx.main.models.rbac import (
|
||||
ROLE_SINGLETON_SYSTEM_AUDITOR,
|
||||
)
|
||||
from awx.main.models.unified_jobs import UnifiedJob
|
||||
from awx.main.models.mixins import ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin
|
||||
from awx.main.models.mixins import ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, OpaQueryPathMixin
|
||||
|
||||
__all__ = ['Organization', 'Team', 'UserSessionMembership']
|
||||
|
||||
|
||||
class Organization(CommonModel, NotificationFieldsModel, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin):
|
||||
class Organization(CommonModel, NotificationFieldsModel, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, OpaQueryPathMixin):
|
||||
"""
|
||||
An organization is the basic unit of multi-tenancy divisions
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user