def delete(self, request, app_id, rule_id, *args, **kwargs): rule = domain_service.get_http_rule_by_id(self.team.tenant_id, rule_id) if not rule: raise ErrNotFoundDomain domain_service.unbind_httpdomain(self.team, self.region_name, rule_id) re = HTTPGatewayRuleSerializer(data=model_to_dict(rule)) re.is_valid() return Response(re.data, status=status.HTTP_200_OK)
def post(self, request, app_id, *args, **kwargs): ads = PostHTTPGatewayRuleSerializer(data=request.data) ads.is_valid(raise_exception=True) app = group_service.get_app_by_id(self.team, self.region_name, app_id) if not app: raise ErrAppNotFound httpdomain = ads.data # Compatible history code httpdomain["domain_heander"] = httpdomain.get("domain_header", None) httpdomain["domain_type"] = DomainType.WWW protocol = "http" if httpdomain.get("certificate_id", None): protocol = "https" httpdomain["protocol"] = protocol service = service_repo.get_service_by_tenant_and_id( self.team.tenant_id, httpdomain["service_id"]) if not service: rst = {"msg": "组件不存在"} return Response(rst, status=status.HTTP_400_BAD_REQUEST) if domain_service.check_domain_exist( httpdomain["service_id"], httpdomain["container_port"], httpdomain["domain_name"], protocol, httpdomain.get("domain_path"), httpdomain.get("rule_extensions")): rst = {"msg": "策略已存在"} return Response(rst, status=status.HTTP_400_BAD_REQUEST) if service.service_source == "third_party": msg, msg_show, code = port_service.check_domain_thirdpart( self.team, service) if code != 200: logger.exception(msg, msg_show) return Response({ "msg": msg, "msg_show": msg_show }, status=code) if httpdomain.get("whether_open", True): tenant_service_port = port_service.get_service_port_by_port( service, httpdomain["container_port"]) # 仅开启对外端口 code, msg, data = port_service.manage_port( self.team, service, service.service_region, int(tenant_service_port.container_port), "only_open_outer", tenant_service_port.protocol, tenant_service_port.port_alias) if code != 200: return Response({"msg": "change port fail"}, status=code) tenant_service_port = port_service.get_service_port_by_port( service, httpdomain["container_port"]) if not tenant_service_port.is_outer_service: return Response({"msg": "没有开启对外端口"}, status=status.HTTP_400_BAD_REQUEST) data = domain_service.bind_httpdomain(self.team, self.request.user, service, httpdomain, True) serializer = HTTPGatewayRuleSerializer(data=data.to_dict()) serializer.is_valid() return Response(serializer.data, status=status.HTTP_201_CREATED)
def put(self, request, app_id, rule_id, *args, **kwargs): ads = UpdatePostHTTPGatewayRuleSerializer(data=request.data) ads.is_valid(raise_exception=True) app = group_service.get_app_by_id(self.team, self.region_name, app_id) if not app: raise ErrAppNotFound httpdomain = ads.data service = service_repo.get_service_by_tenant_and_id(self.team.tenant_id, httpdomain["service_id"]) if not service: rst = {"msg": "组件不存在"} return Response(rst, status=status.HTTP_400_BAD_REQUEST) data = domain_service.update_httpdomain(self.team, service, rule_id, ads.data, True) re = HTTPGatewayRuleSerializer(data=model_to_dict(data)) re.is_valid() return Response(re.data, status=status.HTTP_200_OK)