Skip to content
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

fix: update job ticket allow list #2392

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 3.2.16 on 2023-11-28 06:44

from django.db import migrations

from backend.api.authorization.constants import AuthorizationAPIEnum
from backend.api.constants import ALLOW_ANY


def init_allow_list(apps, schema_editor):
"""初始化授权API白名单"""
AuthAPIAllowListConfig = apps.get_model("authorization", "AuthAPIAllowListConfig")
# 查询已存在白名单,避免重复
all_allow_list = AuthAPIAllowListConfig.objects.all()
allow_set = set([(a.type, a.system_id, a.object_id) for a in all_allow_list])
# 新建关联实例授权API 白名单
system_resource_types = {
"bk_job": ["ticket"],
}
auth_api_allow_list_config = []
for system_id, resource_types in system_resource_types.items():
for resource_type_id in resource_types:
# 已存在,则直接忽略
if (AuthorizationAPIEnum.CREATOR_AUTHORIZATION_INSTANCE.value, system_id, resource_type_id) in allow_set:
continue
auth_api_allow_list_config.append(
AuthAPIAllowListConfig(
type=AuthorizationAPIEnum.CREATOR_AUTHORIZATION_INSTANCE.value,
system_id=system_id,
object_id=resource_type_id,
)
)
if len(auth_api_allow_list_config) != 0:
AuthAPIAllowListConfig.objects.bulk_create(auth_api_allow_list_config)


class Migration(migrations.Migration):

dependencies = [
('authorization', '0014_auto_20231109_1046'),
]

operations = [migrations.RunPython(init_allow_list)]