Exemplo n.º 1
0
    def __check_domain_name(self, team_name, domain_name, domain_type, certificate_id):
        if not domain_name:
            return 400, u"域名不能为空"
        zhPattern = re.compile(u'[\u4e00-\u9fa5]+')
        match = zhPattern.search(domain_name.decode('utf-8'))
        if match:
            return 400, u"域名不能包含中文"
        # a租户绑定了域名manage.com,b租户就不可以在绑定该域名,只有a租户下可以绑定
        s_domain = domain_repo.get_domain_by_domain_name(domain_name)
        if s_domain:
            team = team_services.get_tenant_by_tenant_name(team_name)
            if team:
                if s_domain.tenant_id != team.tenant_id:
                    return 400, u"该域名已被其他团队使用"
        # re_exp = "^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$"
        # if not re.match(re_exp, domain_name):
        #     return 400, u"域名不规范(示例:www.example.com 域名不应包含协议头)"
        if len(domain_name) > 256:
            return 400, u"域名过长"
        if certificate_id:
            certificate_info = domain_repo.get_certificate_by_pk(int(certificate_id))
            cert = base64.b64decode(certificate_info.certificate)
            data = analyze_cert(cert)
            certificat_domain_name = data["issued_to"]
            if certificat_domain_name.startswith('*'):
                domain_suffix = certificat_domain_name[2:]
            else:
                domain_suffix = certificat_domain_name
            logger.debug('---------domain_suffix-------->{0}'.format(domain_suffix))
            domain_str = domain_name.encode('utf-8')
            if not domain_str.endswith(domain_suffix):
                return 400, u"域名和证书不匹配"

        return 200, u"success"
Exemplo n.º 2
0
    def bind_siample_http_domain(self, tenant, user, service, domain_name,
                                 container_port):

        res, msg = self.bind_domain(tenant, user, service, domain_name,
                                    container_port, "http", None,
                                    DomainType.WWW, None)
        if res == 200:
            return domain_repo.get_domain_by_domain_name(domain_name)
        return None
Exemplo n.º 3
0
 def __check_domain_name(self, domain_name):
     if not domain_name:
         return 400, u"域名不能为空"
     zhPattern = re.compile(u'[\u4e00-\u9fa5]+')
     match = zhPattern.search(domain_name.decode('utf-8'))
     if match:
         return 400, u"域名不能包含中文"
     re_exp = "^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$"
     if not re.match(re_exp,domain_name):
         return 400, u"域名不规范(示例:www.example.com 域名不应包含协议头)"
     domain = domain_repo.get_domain_by_domain_name(domain_name)
     if domain:
         return 412, u"域名已存在"
     return 200, u"success"
Exemplo n.º 4
0
 def __check_domain_name(self,
                         team_id,
                         region_id,
                         domain_name,
                         certificate_id=None):
     if not domain_name:
         raise ServiceHandleException(status_code=400,
                                      error_code=400,
                                      msg="domain can not be empty",
                                      msg_show="域名不能为空")
     zh_pattern = re.compile('[\\u4e00-\\u9fa5]+')
     match = zh_pattern.search(domain_name)
     if match:
         raise ServiceHandleException(
             status_code=400,
             error_code=400,
             msg="domain can not be include chinese",
             msg_show="域名不能包含中文")
     # a租户绑定了域名manage.com,b租户就不可以在绑定该域名,只有a租户下可以绑定
     s_domain = domain_repo.get_domain_by_domain_name(domain_name)
     if s_domain and s_domain.tenant_id != team_id and s_domain.region_id == region_id:
         raise ServiceHandleException(status_code=400,
                                      error_code=400,
                                      msg="domain be used other team",
                                      msg_show="域名已经被其他团队使用")
     if len(domain_name) > 256:
         raise ServiceHandleException(status_code=400,
                                      error_code=400,
                                      msg="domain more than 256 bytes",
                                      msg_show="域名超过256个字符")
     if certificate_id:
         certificate_info = domain_repo.get_certificate_by_pk(
             int(certificate_id))
         cert = base64.b64decode(certificate_info.certificate).decode()
         data = analyze_cert(cert)
         sans = data["issued_to"]
         for certificat_domain_name in sans:
             if certificat_domain_name.startswith('*'):
                 domain_suffix = certificat_domain_name[2:]
             else:
                 domain_suffix = certificat_domain_name
             if domain_name.endswith(domain_suffix):
                 return
         raise ServiceHandleException(status_code=400,
                                      error_code=400,
                                      msg="domain",
                                      msg_show="域名与选择的证书不匹配")
Exemplo n.º 5
0
    def __check_domain_name(self, team_name, domain_name, domain_type):
        if not domain_name:
            return 400, u"域名不能为空"
        zhPattern = re.compile(u'[\u4e00-\u9fa5]+')
        match = zhPattern.search(domain_name.decode('utf-8'))
        if match:
            return 400, u"域名不能包含中文"
        re_exp = "^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$"
        if not re.match(re_exp, domain_name):
            return 400, u"域名不规范(示例:www.example.com 域名不应包含协议头)"
        if len(domain_name) > 256:
            return 400, u"域名过长"
        domain = domain_repo.get_domain_by_domain_name(domain_name)
        if domain:
            return 412, u"域名已存在"
        if domain_type == DomainType.WWW:
            is_domain_conflict, conflict_domain = self.__is_domain_conflict(domain_name, team_name)
            if is_domain_conflict:
                return 409, u"域名中不能该域名{0}".format(conflict_domain)

        return 200, u"success"
Exemplo n.º 6
0
 def is_domain_exist(self, domain_name):
     domain = domain_repo.get_domain_by_domain_name(domain_name)
     return True if domain else False