-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
361 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
from django.contrib import admin | ||
|
||
from .models import GatewayAppBinding | ||
|
||
|
||
class GatewayAppBindingAdmin(admin.ModelAdmin): | ||
list_display = ["id", "gateway", "bk_app_code", "updated_time"] | ||
search_fields = ["gateway__id", "bk_app_code"] | ||
list_filter = ["gateway"] | ||
|
||
|
||
admin.site.register(GatewayAppBinding, GatewayAppBindingAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
from django.apps import AppConfig | ||
|
||
|
||
class GatewayConfig(AppConfig): | ||
name = "apigateway.apps.gateway" |
49 changes: 49 additions & 0 deletions
49
src/dashboard/apigateway/apigateway/apps/gateway/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
# Generated by Django 3.2.18 on 2023-11-08 03:52 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('core', '0032_gateway__developers'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GatewayAppBinding', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_time', models.DateTimeField(auto_now_add=True, null=True)), | ||
('updated_time', models.DateTimeField(auto_now=True, null=True)), | ||
('created_by', models.CharField(blank=True, max_length=32, null=True)), | ||
('updated_by', models.CharField(blank=True, max_length=32, null=True)), | ||
('bk_app_code', models.CharField(db_index=True, max_length=32)), | ||
('gateway', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.gateway')), | ||
], | ||
options={ | ||
'db_table': 'gateway_app_binding', | ||
'unique_together': {('gateway', 'bk_app_code')}, | ||
}, | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
src/dashboard/apigateway/apigateway/apps/gateway/migrations/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# |
39 changes: 39 additions & 0 deletions
39
src/dashboard/apigateway/apigateway/apps/gateway/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
from django.db import models | ||
|
||
from apigateway.common.mixins.models import OperatorModelMixin, TimestampedModelMixin | ||
from apigateway.core.models import Gateway | ||
|
||
|
||
class GatewayAppBinding(TimestampedModelMixin, OperatorModelMixin): | ||
""" | ||
网关绑定的蓝鲸应用 | ||
- 仅影响 HomePage 中运维开发分数的计算 | ||
""" | ||
|
||
gateway = models.ForeignKey(Gateway, on_delete=models.CASCADE) | ||
bk_app_code = models.CharField(max_length=32, db_index=True) | ||
|
||
def __str__(self): | ||
return f"<GatewayAppBinding: {self.bk_app_code}/{self.gateway_id}>" | ||
|
||
class Meta: | ||
db_table = "gateway_app_binding" | ||
unique_together = ("gateway", "bk_app_code") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/dashboard/apigateway/apigateway/biz/gateway_app_binding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# TencentBlueKing is pleased to support the open source community by making | ||
# 蓝鲸智云 - API 网关(BlueKing - APIGateway) available. | ||
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://opensource.org/licenses/MIT | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We undertake not to change the open source license (MIT license) applicable | ||
# to the current version of the project delivered to anyone in the future. | ||
# | ||
from typing import List | ||
|
||
from apigateway.apps.gateway.models import GatewayAppBinding | ||
from apigateway.core.models import Gateway | ||
|
||
|
||
class GatewayAppBindingHandler: | ||
@classmethod | ||
def update_gateway_app_bindings(cls, gateway: Gateway, bk_app_codes: List[str]): | ||
""" | ||
更新网关应用的绑定 | ||
- 1. 如果 bk_app_codes 中应用未绑定,则新增绑定 | ||
- 2. 如果已绑定的应用未在 bk_app_codes 中,则删除 | ||
""" | ||
bound_app_codes = cls.get_bound_app_codes(gateway) | ||
app_codes_to_add = set(bk_app_codes) - set(bound_app_codes) | ||
app_codes_to_delete = set(bound_app_codes) - set(bk_app_codes) | ||
|
||
if app_codes_to_add: | ||
GatewayAppBinding.objects.bulk_create( | ||
[GatewayAppBinding(gateway=gateway, bk_app_code=code) for code in app_codes_to_add] | ||
) | ||
|
||
if app_codes_to_delete: | ||
GatewayAppBinding.objects.filter(gateway=gateway, bk_app_code__in=app_codes_to_delete).delete() | ||
|
||
@staticmethod | ||
def get_bound_app_codes(gateway: Gateway) -> List[str]: | ||
"""获取已绑定的应用""" | ||
return list(GatewayAppBinding.objects.filter(gateway=gateway).values_list("bk_app_code", flat=True)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.