def put(self, request, *args, **kwargs): """ 服务端口自定义二级域名 --- parameters: - name: tenantName description: 团队名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path - name: domain_name description: 域名 required: true type: string paramType: form - name: container_port description: 服务端口 required: true type: string paramType: form """ try: container_port = request.data.get("container_port", None) domain_name = request.data.get("domain_name", None) if not container_port or not domain_name: return Response(general_message(400, "params error", "参数错误"), status=400) container_port = int(container_port) sld_domains = domain_service.get_sld_domains(self.service, container_port) if not sld_domains: code, msg = domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port, "http", None, DomainType.SLD_DOMAIN) if code != 200: return Response(general_message(code, "bind domain error", msg), status=code) else: # 先解绑 再绑定 code, msg = domain_service.unbind_domain(self.tenant, self.service, container_port, sld_domains[0].domain_name, is_tcp=False) if code != 200: return Response(general_message(code, "unbind domain error", msg), status=code) domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port, "http", None, DomainType.SLD_DOMAIN) result = general_message(200, "success", "二级域名修改成功") except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def post(self, request, *args, **kwargs): """ 服务端口绑定域名 --- parameters: - name: tenantName description: 团队名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path - name: domain_name description: 域名 required: true type: string paramType: form - name: container_port description: 服务端口 required: true type: string paramType: form - name: protocol description: 端口协议(http,https,httptohttps,httpandhttps) required: true type: string paramType: form - name: certificate_id description: 证书ID required: false type: string paramType: form """ try: container_port = request.data.get("container_port", None) domain_name = request.data.get("domain_name", None) protocol = request.data.get("protocol", None) certificate_id = request.data.get("certificate_id", None) code, msg = domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port, protocol, certificate_id, DomainType.WWW) if code != 200: return Response(general_message(code, "bind domain error", msg), status=code) result = general_message(200, "success", "域名绑定成功") except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def post(self, request, *args, **kwargs): """ 服务端口绑定域名 --- parameters: - name: tenantName description: 团队名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path - name: domain_name description: 域名 required: true type: string paramType: form - name: container_port description: 服务端口 required: true type: string paramType: form - name: protocol description: 端口协议(http,https,httptohttps,httpandhttps) required: true type: string paramType: form - name: certificate_id description: 证书ID required: false type: string paramType: form """ try: container_port = request.data.get("container_port", None) domain_name = request.data.get("domain_name", None) protocol = request.data.get("protocol", None) certificate_id = request.data.get("certificate_id", None) rule_extensions = request.data.get("rule_extensions", None) # 判断策略是否存在 service_domain = domain_repo.get_domain_by_name_and_port_and_protocol(self.service.service_id, container_port, domain_name, protocol) if service_domain: result = general_message(400, "faild", "策略已存在") return Response(result, status=400) code, msg = domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port, protocol, certificate_id, DomainType.WWW, rule_extensions) if code != 200: return Response(general_message(code, "bind domain error", msg), status=code) # htt与https共存的协议需存储两条数据(创建完https数据再创建一条http数据) if protocol == "httpandhttps": certificate_id = 0 code, msg = domain_service.bind_domain(self.tenant, self.user, self.service, domain_name, container_port, protocol, certificate_id, DomainType.WWW, rule_extensions) if code != 200: return Response(general_message(code, "bind domain error", msg), status=code) result = general_message(200, "success", "域名绑定成功") except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])