Skip to content

Commit

Permalink
feat: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangSetSail committed Jan 11, 2024
2 parents 83677b9 + 897c44c commit 1d5aaba
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 4 deletions.
6 changes: 6 additions & 0 deletions console/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@
ServicePluginsView)
from console.views.pod import AppPodsView
from console.views.protocols import RegionProtocolView
from console.views.proxy import ProxyPassView
from console.views.public_areas import (AllServiceInfo, GroupServiceView, ServiceEventsView, ServiceGroupView,
TeamAppSortViewView, TeamOverView, TeamServiceOverViewView, TenantServiceEnvsView,
GroupOperatorManagedView, AccessTokenView, TeamArchView, TeamAppNamesView)
from console.views.region import (GetRegionFeature, GetRegionPublicKeyView, MavenSettingRUDView, MavenSettingView,
OpenRegionView, QyeryRegionView, RegQuyView, RegUnopenView)
from console.views.registry import HubRegistryView
from console.views.role_prems import TeamAddUserView
from console.views.service_docker import DockerContainerView
from console.views.service_share import (
Expand Down Expand Up @@ -145,6 +147,8 @@
from console.views.rbd_ability import RainbondAbilityLView, RainbondAbilityRUDView

urlpatterns = [
url(r'^v2/proxy-pass/(.*?)', ProxyPassView.as_view()),

# record error logs
url(r'^errlog$', ErrLogView.as_view()),
# 获取云帮Logo、标题、github、gitlab配置信息
Expand Down Expand Up @@ -187,6 +191,8 @@
# 修改密码
url(r'^users/changepwd$', ChangeLoginPassword.as_view()),

# 全局镜像仓库配置
url(r'^hub/registry$', HubRegistryView.as_view()),
# 我的详情
url(r'^users/details$', UserDetailsView.as_view()),
# 模糊查询用户
Expand Down
2 changes: 2 additions & 0 deletions console/views/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def delete(self, request, service_id, *args, **kwargs):
class OAuthServiceRedirect(AlowAnyApiView):
def get(self, request, *args, **kwargs):
code = request.GET.get("code")
if not code:
return HttpResponseRedirect("/")
service_id = request.GET.get("service_id")
service = oauth_repo.get_oauth_services_by_service_id(service_id)
route_mode = os.getenv("ROUTE_MODE", "hash")
Expand Down
29 changes: 29 additions & 0 deletions console/views/proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf8 -*-
import logging

from django.views.decorators.cache import never_cache
from rest_framework.response import Response

from www.apiclient.regionapi import RegionInvokeApi

from console.views.base import JWTAuthApiView
from www.utils.return_message import general_message

logger = logging.getLogger("default")
region_api = RegionInvokeApi()


class ProxyPassView(JWTAuthApiView):
@never_cache
def post(self, request, *args, **kwargs):
path = request.get_full_path().replace("/console", "")
resp = region_api.post_proxy(request.GET.get("region_name"), path, request.data)
result = general_message(200, "success", "请求成功", bean=resp['bean'], list=resp['list'])
return Response(result, status=result["code"])

@never_cache
def get(self, request, *args, **kwargs):
path = request.get_full_path().replace("/console", "")
resp = region_api.get_proxy(request.GET.get("region_name"), path)
result = general_message(200, "success", "请求成功", bean=resp['bean'], list=resp['list'])
return Response(result, status=result["code"])
56 changes: 56 additions & 0 deletions console/views/registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from django.views.decorators.cache import never_cache
from console.services.team_services import team_services
from www.utils.return_message import general_message
from rest_framework.response import Response
from console.repositories.team_repo import team_registry_auth_repo
from console.utils.reqparse import parse_item

from console.views.base import JWTAuthApiView


class HubRegistryView(JWTAuthApiView):
@never_cache
def get(self, request, *args, **kwargs):
result = team_services.list_registry_auths('', '')
auths = [auth.to_dict() for auth in result]
result = general_message(200, "success", "查询成功", list=auths)
return Response(result, status=result["code"])

def post(self, request, *args, **kwargs):
domain = parse_item(request, "domain", required=True)
username = parse_item(request, "username", required=True)
password = parse_item(request, "password", required=True)
secret_id = parse_item(request, "secret_id", required=True)
params = {
"tenant_id": '',
"region_name": '',
"secret_id": secret_id,
"domain": domain,
"username": username,
"password": password,
}
team_registry_auth_repo.create_team_registry_auth(**params)

result = general_message(200, "success", "创建成功")
return Response(result, status=result["code"])

def put(self, request, *args, **kwargs):
secret_id = request.GET.get("secret_id")
data = {
"username": parse_item(request, "username", required=True),
"password": parse_item(request, "password", required=True)
}
auth = team_registry_auth_repo.get_by_secret_id(secret_id)
if not auth:
result = general_message(400, "bad request", "您要更新的镜像仓库不存在")
return Response(result, status=result["code"])
team_registry_auth_repo.update_team_registry_auth('', '', secret_id, **data)

result = general_message(200, "success", "更新成功")
return Response(result, status=result["code"])

def delete(self, request, *args, **kwargs):
secret_id = request.GET.get("secret_id")
team_registry_auth_repo.delete_team_registry_auth('', '', secret_id)
result = general_message(200, "success", "删除成功")
return Response(result, status=result["code"])
36 changes: 35 additions & 1 deletion openapi/serializer/app_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from openapi.serializer.utils import DateCharField
from rest_framework import serializers, validators
from www.models.main import ServiceGroup, TenantServiceInfo
from www.models.main import ServiceGroup, TenantServiceInfo, TenantServicesPort

ACTION_CHOICE = (
("stop", ("stop")),
Expand All @@ -30,6 +30,18 @@
("market", ("market")),
)

COMPONENT_PORT_PROTOCOL = (
("http", ("http")),
("tcp", ("tcp")),
("udp", ("udp")),
("mysql", ("msyql")),
("grpc", ("grpc")),
)

COMPONENT_PORT_ACTION = (("open_outer", ("open_outer")), ("only_open_outer", ("only_open_outer")),
("close_outer", ("close_outer")), ("open_inner", ("open_inner")), ("close_inner", ("close_inner")),
("change_protocol", ("change_protocol")), ("change_port_alias", ("change_port_alias")))

COMPONENT_SOURCE_TYPE = (
("svn", ("svn")),
("git", ("git")),
Expand Down Expand Up @@ -66,6 +78,12 @@ class Meta:
access_infos = serializers.ListField(required=False, allow_empty=True, default=[], help_text="组件访问地址")


class ServicePortSerializer(serializers.ModelSerializer):
class Meta:
model = TenantServicesPort
exclude = ["ID", "tenant_id", "service_id", "name"]


class AppInfoSerializer(AppBaseInfoSerializer):
enterprise_id = serializers.CharField(max_length=32, help_text="企业ID(联合云ID)")
service_count = serializers.IntegerField(help_text="组件数量")
Expand Down Expand Up @@ -247,6 +265,22 @@ class ComponentEventSerializers(serializers.Serializer):
event_id = serializers.CharField(max_length=64, help_text="事件ID")


class ComponentUpdatePortReqSerializers(serializers.Serializer):
action = serializers.ChoiceField(choices=COMPONENT_PORT_ACTION, required=True, allow_null=False, help_text="端口操作类型")
port_alias = serializers.CharField(max_length=255, required=False, allow_null=True, help_text="端口别名")
protocol = serializers.ChoiceField(
choices=COMPONENT_PORT_PROTOCOL, default='http', required=False, allow_null=True, help_text="端口协议")
k8s_service_name = serializers.CharField(max_length=255, required=False, allow_null=True, help_text="内部域名")


class ComponentPortReqSerializers(serializers.Serializer):
port = serializers.IntegerField(help_text="组件端口", required=True, allow_null=False)
protocol = serializers.ChoiceField(
choices=COMPONENT_PORT_PROTOCOL, default='http', required=False, allow_null=True, help_text="端口协议")
port_alias = serializers.CharField(max_length=255, required=False, allow_null=True, help_text="端口别名")
is_inner_service = serializers.BooleanField(help_text="开启对内端口")


class ComponentBuildReqSerializers(serializers.Serializer):
build_type = serializers.ChoiceField(choices=COMPONENT_BUILD_TYPE, required=False, allow_null=True, help_text="组件构建源类型")
server_type = serializers.ChoiceField(choices=COMPONENT_SOURCE_TYPE, required=False, allow_null=True, help_text="源码来源类型")
Expand Down
5 changes: 4 additions & 1 deletion openapi/sub_urls/app_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from openapi.views.apps.apps import (AppInfoView, APPOperationsView, AppServiceEventsView, AppServicesView,
AppServiceTelescopicHorizontalView, AppServiceTelescopicVerticalView, ComponentBuildView,
ComponentEnvsUView, CreateThirdComponentView, ListAppServicesView, TeamAppsCloseView,
TeamAppsMonitorQueryRangeView, TeamAppsMonitorQueryView)
TeamAppsMonitorQueryRangeView, TeamAppsMonitorQueryView, ComponentPortsShowView,
ComponentPortsChangeView)
from openapi.views.apps.market import AppInstallView, AppUpgradeView
from openapi.views.gateway.gateway import (ListAppGatewayHTTPRuleView, ListAppGatewayRuleView, UpdateAppGatewayHTTPRuleView,
UpdateAppGatewayRuleView)
Expand Down Expand Up @@ -35,6 +36,8 @@
url(r'^(?P<app_id>[\d\-]+)/services/(?P<service_id>[\w\-]+)/telescopic/horizontal$',
AppServiceTelescopicHorizontalView.as_view(), perms.AppServiceTelescopicHorizontalView),
url(r'^(?P<app_id>[\d\-]+)/services/(?P<service_id>[\w\-]+)/envs$', ComponentEnvsUView.as_view()),
url(r'^(?P<app_id>[\d\-]+)/services/(?P<service_id>[\w\-]+)/ports/(?P<port>[\w\-]+)$$', ComponentPortsChangeView.as_view()),
url(r'^(?P<app_id>[\d\-]+)/services/(?P<service_id>[\w\-]+)/ports$', ComponentPortsShowView.as_view()),
url(r'^(?P<app_id>[\d\-]+)/services/(?P<service_id>[\w\-]+)/build$', ComponentBuildView.as_view()),
url(r'^(?P<app_id>[\d\-]+)/third-components$', CreateThirdComponentView.as_view()),
]
115 changes: 114 additions & 1 deletion openapi/views/apps/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
AppServiceTelescopicHorizontalSerializer, AppServiceTelescopicVerticalSerializer, ComponentBuildReqSerializers,
ComponentEnvsSerializers, ComponentEventSerializers, ComponentMonitorSerializers, CreateThirdComponentResponseSerializer,
CreateThirdComponentSerializer, ListServiceEventsResponse, ServiceBaseInfoSerializer, ServiceGroupOperationsSerializer,
TeamAppsCloseSerializers, DeployAppSerializer)
TeamAppsCloseSerializers, DeployAppSerializer, ServicePortSerializer, ComponentPortReqSerializers,
ComponentUpdatePortReqSerializers)
from openapi.serializer.base_serializer import (FailSerializer, SuccessSerializer)
from openapi.services.app_service import app_service
from openapi.services.component_action import component_action_service
Expand Down Expand Up @@ -678,6 +679,118 @@ def put(self, request, *args, **kwargs):
return Response(serializers.data, status=200)


class ComponentPortsChangeView(TeamAppServiceAPIView):
@swagger_auto_schema(
operation_description="删除组件端口",
manual_parameters=[
openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
openapi.Parameter("service_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_STRING),
openapi.Parameter("team_id", openapi.IN_PATH, description="团队id", type=openapi.TYPE_STRING),
openapi.Parameter("region_name", openapi.IN_PATH, description="集群名称", type=openapi.TYPE_STRING),
],
responses={200: ServicePortSerializer()},
tags=['openapi-apps'],
)
def delete(self, request, *args, **kwargs):
container_port = kwargs.get("port")
if not container_port:
raise AbortRequest("container_port not specify", "端口变量名未指定")
data = port_service.delete_port_by_container_port(self.team, self.service, int(container_port), self.user.nick_name)
re = ServicePortSerializer(data)
result = general_message(200, "success", "删除成功", bean=re.data)
return Response(result, status=status.HTTP_200_OK)

@swagger_auto_schema(
operation_description="更新组件端口",
manual_parameters=[
openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
openapi.Parameter("service_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_STRING),
openapi.Parameter("team_id", openapi.IN_PATH, description="团队id", type=openapi.TYPE_STRING),
openapi.Parameter("region_name", openapi.IN_PATH, description="集群名称", type=openapi.TYPE_STRING),
],
request_body=ComponentUpdatePortReqSerializers,
responses={200: ServicePortSerializer()},
tags=['openapi-apps'],
)
def put(self, request, *args, **kwargs):
port_update = ComponentUpdatePortReqSerializers(data=request.data)
port_update.is_valid(raise_exception=True)
container_port = kwargs.get("port")
action = port_update.data.get("action", None)
port_alias = port_update.data.get("port_alias", None)
protocol = port_update.data.get("protocol", None)
k8s_service_name = port_update.data.get("k8s_service_name", "")
if not container_port:
raise AbortRequest("container_port not specify", "端口变量名未指定")

if self.service.service_source == "third_party" and ("outer" in action):
msg, msg_show, code = port_service.check_domain_thirdpart(self.team, self.service)
if code != 200:
logger.exception(msg, msg_show)
return Response(general_message(code, msg, msg_show), status=code)

code, msg, data = port_service.manage_port(self.team, self.service, self.region_name, int(container_port), action,
protocol, port_alias, k8s_service_name, self.user.nick_name)
if code != 200:
return Response(general_message(code, "change port fail", msg), status=code)

re = ServicePortSerializer(data)
result = general_message(200, "success", "操作成功", bean=re.data)
return Response(result, status=status.HTTP_200_OK)


class ComponentPortsShowView(TeamAppServiceAPIView):
@swagger_auto_schema(
operation_description="获取组件端口列表",
manual_parameters=[
openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
openapi.Parameter("service_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_STRING),
openapi.Parameter("team_id", openapi.IN_PATH, description="团队id", type=openapi.TYPE_STRING),
openapi.Parameter("region_name", openapi.IN_PATH, description="集群名称", type=openapi.TYPE_STRING),
],
responses={200: ServicePortSerializer(many=True)},
tags=['openapi-apps'],
)
def get(self, request, *args, **kwargs):
ports = port_repo.get_service_ports(self.team.tenant_id, self.service.service_id)
re = ServicePortSerializer(ports, many=True)
result = general_message(200, "success", "查询成功", list=re.data)
return Response(result, status=status.HTTP_200_OK)

@swagger_auto_schema(
operation_description="新增组件端口",
manual_parameters=[
openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
openapi.Parameter("service_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_STRING),
openapi.Parameter("team_id", openapi.IN_PATH, description="团队id", type=openapi.TYPE_STRING),
openapi.Parameter("region_name", openapi.IN_PATH, description="集群名称", type=openapi.TYPE_STRING),
],
request_body=ComponentPortReqSerializers,
responses={200: ServicePortSerializer()},
tags=['openapi-apps'],
)
def post(self, request, *args, **kwargs):
port_info = ComponentPortReqSerializers(data=request.data)
port_info.is_valid(raise_exception=True)
port = port_info.data.get("port")
protocol = port_info.data.get("protocol")
port_alias = port_info.data.get("port_alias", "")
is_inner_service = port_info.data.get("is_inner_service", False)
if not port:
return Response(general_message(400, "params error", "缺少端口参数"), status=400)
if not protocol:
return Response(general_message(400, "params error", "缺少协议参数"), status=400)
if not port_alias:
port_alias = self.service.service_alias.upper().replace("-", "_") + str(port)
code, msg, port_info = port_service.add_service_port(self.team, self.service, port, protocol, port_alias,
is_inner_service, False, None, self.user.nick_name)
if code != 200:
return Response(general_message(code, "add port error", msg), status=code)
re = ServicePortSerializer(port_info)
result = general_message(200, "success", "添加成功", bean=re.data)
return Response(result, status=status.HTTP_200_OK)


class ComponentBuildView(TeamAppServiceAPIView):
@swagger_auto_schema(
operation_description="构建组件,用于CI/CD工作流调用",
Expand Down
20 changes: 19 additions & 1 deletion www/apiclient/regionapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2658,4 +2658,22 @@ def delete_lang_version(self, enterprise_id, region, data):
url = region_info.url
url += "/v2/cluster/langVersion"
res, body = self._delete(url, self.default_headers, body=json.dumps(data), region=region_info.region_name)
return body
return body

def post_proxy(self, region_name, path, data):
region_info = self.get_region_info(region_name)
if not region_info:
raise ServiceHandleException("region not found")
url = region_info.url + path
self._set_headers(region_info.token)
res, body = self._post(url, self.default_headers, region=region_name, body=json.dumps(data))
return body

def get_proxy(self, region_name, path):
region_info = self.get_region_info(region_name)
if not region_info:
raise ServiceHandleException("region not found")
url = region_info.url + path
self._set_headers(region_info.token)
res, body = self._get(url, self.default_headers, region=region_name)
return body

0 comments on commit 1d5aaba

Please sign in to comment.