def create_enterprise(self, enterprise_name='', enterprise_alias=''):
        """
        创建一个本地的企业信息, 并生成本地的企业ID

        :param enterprise_name: 企业的英文名, 如果没有则自动生成一个, 如果存在则需要保证传递的名字在数据库中唯一
        :param enterprise_alias: 企业的别名, 可以中文, 用于展示用, 如果为空则自动生成一个
        :return:
        """
        enterprise = TenantEnterprise()

        # Deal with enterprise English name, discard logic.
        if enterprise_name:
            enterprise_name_regx = re.compile(r'^[a-z0-9-]*$')
            if enterprise_name and not enterprise_name_regx.match(
                    enterprise_name):
                logger.error('bad enterprise_name: {}'.format(enterprise_name))
                raise Exception(
                    'enterprise_name  must consist of lower case alphanumeric characters or -'
                )

            if TenantEnterprise.objects.filter(
                    enterprise_name=enterprise_name).count() > 0:
                raise Exception('enterprise_name [{}] already existed!'.format(
                    enterprise_name))
            else:
                enter_name = enterprise_name
        else:
            enter_name = self.random_enterprise_name()
        enterprise.enterprise_name = enter_name

        # 根据企业英文名确认UUID
        is_first_ent = TenantEnterprise.objects.count() == 0
        eid = os.environ.get('ENTERPRISE_ID')
        if not eid or not is_first_ent:
            eid = make_uuid(enter_name)
        region = region_repo.get_all_regions().first()
        if region:
            region.enterprise_id = eid
            region.save()
        enterprise.enterprise_id = eid

        # 处理企业别名
        if not enterprise_alias:
            enterprise.enterprise_alias = '企业{0}'.format(enter_name)
        else:
            enterprise.enterprise_alias = enterprise_alias

        enterprise.save()
        return enterprise
    def create_oauth_enterprise(self, enterprise_name, enterprise_alias, enterprise_id):
        """
        创建一个本地的企业信息, 并生成本地的企业ID

        :param enterprise_name: 企业的domain, 如果没有则自动生成一个, 如果存在则需要保证传递的名字在数据库中唯一
        :param enterprise_alias: 企业的名称, 可以中文, 用于展示用, 如果为空则自动生成一个
        :param enterprise_id: 企业的id
        :return:
        """
        enterprise = TenantEnterprise()
        enterprise.enterprise_name = enterprise_name
        enterprise.enterprise_id = enterprise_id
        enterprise.enterprise_alias = enterprise_alias
        enterprise.save()
        return enterprise
 def _update_entalias(self, eid, alias):
     ent = enterprise_services.get_enterprise_by_id(eid)
     if ent is None:
         raise TenantEnterprise.DoesNotExist()
     ent.enterprise_alias = alias
     ent.save()
Example #4
0
 def init(self):
     self.sources = [
         Tenants(),
         TenantRegionInfo(),
         TenantRegionResource(),
         ServiceInfo(),
         TenantServiceInfo(),
         TenantServiceInfoDelete(),
         TenantServiceLog(),
         TenantServiceRelation(),
         TenantServiceEnv(),
         TenantServiceAuth(),
         TenantServiceExtendMethod(),
         ServiceDomain(),
         ServiceDomainCertificate(),
         PermRelService(),
         PermRelTenant(),
         PhoneCode(),
         TenantServiceL7Info(),
         TenantServiceEnvVar(),
         TenantServicesPort(),
         TenantServiceMountRelation(),
         TenantServiceVolume(),
         TenantServiceConfigurationFile(),
         ServiceGroup(),
         ServiceGroupRelation(),
         ImageServiceRelation(),
         ComposeServiceRelation(),
         ServiceRule(),
         ServiceRuleHistory(),
         ServiceCreateStep(),
         ServiceProbe(),
         ConsoleConfig(),
         TenantEnterprise(),
         TenantEnterpriseToken(),
         TenantServiceGroup(),
         ServiceTcpDomain(),
         ThirdPartyServiceEndpoints(),
         ServiceWebhooks(),
         GatewayCustomConfiguration(),
         ConsoleSysConfig(),
         RainbondCenterApp(),
         RainbondCenterAppInherit(),
         RainbondCenterPlugin(),
         ServiceShareRecord(),
         EnterpriseUserPerm(),
         TenantUserRole(),
         TenantUserPermission(),
         TenantUserRolePermission(),
         PermGroup(),
         ServiceRelPerms(),
         AppExportRecord(),
         UserMessage(),
         AppImportRecord(),
         GroupAppBackupRecord(),
         GroupAppMigrateRecord(),
         GroupAppBackupImportRecord(),
         Applicants(),
         DeployRelation(),
         ServiceBuildSource(),
         TenantServiceBackup(),
         AppUpgradeRecord(),
         ServiceUpgradeRecord(),
         RegionConfig(),
         CloundBangImages(),
         Announcement(),
     ]