def sync_market_plugin_templates(self, tenant, plugin_data): plugin_template = market_api.get_plugin_templates(tenant.tenant_id, plugin_data.get('plugin_key'), plugin_data.get('version')) market_plugin = plugin_template.get('plugin') if not market_plugin: return True rcps = RainbondCenterPlugin.objects.filter( plugin_key=market_plugin.get('plugin_key'), version=market_plugin.get('major_version'), enterprise_id__in=[tenant.enterprise_id, "public"]) rcp = None if rcps: # 优先获取企业的插件 enter_rcp = rcps.filter(enterprise_id=tenant.enterprise_id) if enter_rcp: rcp = enter_rcp[0] else: rcp = rcps[0] if rcp: rcp.share_user = 0 user_name = market_plugin.get('share_user') if user_name: try: user = user_repo.get_enterprise_user_by_username(tenant.enterprise_id, user_name) rcp.share_user = user.user_id except Exception as e: logger.exception(e) rcp.plugin_template = market_plugin.get("template").get('template_content') rcp.pic = market_plugin.get('logo') rcp.desc = market_plugin.get('intro') rcp.version = market_plugin.get('major_version') rcp.details = market_plugin.get("desc", "") rcp.is_complete = True rcp.save() return True else: enterprise_id = tenant.enterprise_id rcp = RainbondCenterPlugin( plugin_key=market_plugin.get('plugin_key'), plugin_name=market_plugin.get('name'), version=market_plugin.get('major_version'), desc=market_plugin.get('intro'), pic=market_plugin.get('logo'), build_version=market_plugin.get('build_version'), record_id=0, category=market_plugin.get('category'), scope='goodrain', source='market', share_user=0, share_team='', enterprise_id=enterprise_id, plugin_template=market_plugin.get("template").get('template_content'), is_complete=True, details=market_plugin.get("desc", "")) rcp.save() return True
def create_plugin_share_info(self, share_record, share_info, user_id, tenant, region_name): tenant_id = tenant.tenant_id tenant_name = tenant.tenant_name sid = transaction.savepoint() try: PluginShareRecordEvent.objects.filter( record_id=share_record.ID).delete() RainbondCenterPlugin.objects.filter( record_id=share_record.ID).delete() plugin_info = share_info.get("share_plugin_info") if isinstance(plugin_info, unicode): plugin_info = json.loads(plugin_info) if plugin_info.get('scope') == 'goodrain': ent = enterprise_repo.get_enterprise_by_enterprise_id( tenant.enterprise_id) if ent and not ent.is_active: return 10407, "用户未跟云市认证", None plugin_id = plugin_info.get("plugin_id") plugin_version = plugin_svc.get_tenant_plugin_newest_versions( region_name, tenant, plugin_id) if not plugin_version or plugin_version[ 0].build_status != "build_success": return 400, "插件未构建", None plugin_version = plugin_version.first() tenant_plugin = plugin_repo.get_plugin_by_plugin_id( tenant_id, plugin_id) plugin_template = { "plugin_id": plugin_info.get("plugin_id"), "plugin_key": plugin_info.get("plugin_key"), "plugin_name": plugin_info.get("plugin_name"), "plugin_version": plugin_info.get("version"), "code_repo": tenant_plugin.code_repo, "build_source": tenant_plugin.build_source, "image": tenant_plugin.image, "category": tenant_plugin.category } if plugin_version.plugin_version_status != "fixed": plugin_version.plugin_version_status = "fixed" plugin_version.save() plugin_template["build_version"] = plugin_version.to_dict() plugin_info["plugin_image"] = app_store.get_image_connection_info( plugin_info["scope"], tenant_name) if not plugin_info["plugin_image"]: if sid: transaction.savepoint_rollback(sid) return 400, "获取镜像上传地址错误", None event = PluginShareRecordEvent( record_id=share_record.ID, team_name=tenant_name, team_id=tenant_id, plugin_id=plugin_info['plugin_id'], plugin_name=plugin_info['plugin_name'], event_status='not_start') event.save() RainbondCenterPlugin.objects.filter( version=plugin_info["version"], plugin_id=share_record.group_id).delete() plugin_info["source"] = "local" plugin_info["record_id"] = share_record.ID plugin_template['share_plugin_info'] = plugin_info plugin = RainbondCenterPlugin( plugin_key=plugin_info.get("plugin_key"), plugin_name=plugin_info.get("plugin_name"), plugin_id=plugin_info.get("plugin_id"), record_id=share_record.ID, version=plugin_info.get("version"), build_version=plugin_info.get('build_version'), pic=plugin_info.get("pic", ""), scope=plugin_info.get("scope"), source="local", share_user=user_id, share_team=tenant_name, desc=plugin_info.get("desc"), enterprise_id=tenant.enterprise_id, plugin_template=json.dumps(plugin_template), category=plugin_info.get('category')) plugin.save() share_record.step = 2 share_record.update_time = datetime.now() share_record.save() transaction.savepoint_commit(sid) return 200, "分享信息处理成功", plugin.to_dict() except Exception as e: logger.exception(e) if sid: transaction.savepoint_rollback(sid) return 500, "插件分享处理发生错误", None
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(), ]