def get_slug_hub_info(self, store=None, app_id=None, enterprise_id=None): image_config = { "ftp_host": None, "ftp_port": None, "namespace": None, "ftp_username": None, "ftp_password": None } data = None if store: store_client = get_market_client(store.access_key, store.url) data = store_client.get_app_hub_info(app_id=app_id, market_domain=store.domain, _return_http_data_only=True) image_config["ftp_host"] = data.hub_url image_config["ftp_username"] = data.hub_user image_config["ftp_password"] = data.hub_password image_config["namespace"] = data.namespace if not data: data = EnterpriseConfigService(enterprise_id).get_config_by_key( "APPSTORE_IMAGE_HUB") if data: image_config_dict = eval(data.value) namespace = (image_config_dict.get("namespace") if image_config_dict.get("namespace") else data.enterprise_id) image_config["ftp_host"] = image_config_dict.get( "hub_url", None) image_config["ftp_username"] = image_config_dict.get( "hub_user", None) image_config["ftp_password"] = image_config_dict.get( "hub_password", None) image_config["namespace"] = namespace return image_config
def get_app_versions(self, store, app_id, query_all=False): store_client = get_market_client(store.access_key, store.url) data = store_client.get_user_app_versions(app_id=app_id, market_domain=store.domain, query_all=query_all, _return_http_data_only=True) return data
def create_app_version(self, store, app_id, body): store_client = get_market_client(store.access_key, store.url) body = openapi_client.V1CreateAppPaaSVersionRequest(**body) data = store_client.create_app_version(app_id=app_id, body=body, market_domain=store.domain) return data
def get_apps(self, store, query, query_all, page=1, page_size=10): store_client = get_market_client(store.access_key, store.url) data = store_client.get_user_app_list(page=page, page_size=page_size, market_domain=store.domain, query=query, query_all=query_all) return data
def get_app_version(self, store, app_id, version, for_install=False, get_template=False): store_client = get_market_client(store.access_key, store.url) data = store_client.get_user_app_version_detail( app_id=app_id, version=version, market_domain=store.domain, for_install=for_install, get_template=get_template) return data
def post(self, request, *args, **kwargs): serializer = MarketInstallSerializer(data=request.data) serializer.is_valid(raise_exception=True) data = serializer.data logger.info(data) app = group_service.get_app_by_id(data["app_id"]) if not app: return Response(FailSerializer( {"msg": "install target app not found"}), status=status.HTTP_400_BAD_REQUEST) tenant = team_services.get_team_by_team_id(app.tenant_id) # TODO: get app info by order id token = market_sycn_service.get_enterprise_access_token( tenant.enterprise_id, "market") if token: market_client = get_market_client(token.access_id, token.access_token, token.access_url) app_version = market_client.download_app_by_order( order_id=data["order_id"]) if not app_version: return Response(FailSerializer( {"msg": "download app metadata failure"}), status=status.HTTP_400_BAD_REQUEST) rainbond_app, rainbond_app_version = market_app_service.conversion_cloud_version_to_app( app_version) market_app_service.install_service(tenant, app.region_name, request.user, app.ID, rainbond_app, rainbond_app_version, True, True) services = group_service.get_group_services(data["app_id"]) appInfo = model_to_dict(app) appInfo["enterprise_id"] = tenant.enterprise_id appInfo["service_list"] = ServiceBaseInfoSerializer(services, many=True).data reapp = AppInfoSerializer(data=appInfo) reapp.is_valid() return Response(reapp.data, status=status.HTTP_200_OK) else: return Response(FailSerializer( {"msg": "not support install from market, not bound"}), status=status.HTTP_400_BAD_REQUEST)
def get_cloud_app(self, enterprise_id, market_id, app_id): try: token = self.get_enterprise_access_token(enterprise_id, "market") if token: market_client = get_market_client(token.access_id, token.access_token, token.access_url) else: market_client = get_default_market_client() market = market_client.get_app_versions(market_id=market_id, app_id=app_id, _request_timeout=10) return market except ApiException as e: logger.exception(e) if e.status == 403: raise ServiceHandleException("no cloud permission", msg_show="云市授权不通过", status_code=403, error_code=10407) raise ServiceHandleException("call cloud api failure", msg_show="云市请求错误", status_code=500, error_code=500) except (httplib2.ServerNotFoundError, MaxRetryError, ConnectTimeoutError) as e: logger.exception(e) raise e except socket.timeout as e: logger.warning("request cloud app list timeout", e) raise ServiceHandleException("connection timeout", msg_show="云市通信超时", status_code=500, error_code=10409)
def get_market(self, store): store_client = get_market_client(store.access_key, store.url) data = store_client.get_market_info(market_domain=store.domain) return data
def get_orgs(self, store): store_client = get_market_client(store.access_key, store.url) data = store_client.get_orgs() return data
def list_bindable_markets(self, store): store_client = get_market_client(store.access_key, store.url) return store_client.bindable_markets()
def create_app(self, store, body): store_client = get_market_client(store.access_key, store.url) body = openapi_client.V1AppModelCreateRequest(**body) data = store_client.create_app(body=body, market_domain=store.domain) return data
def update_app(self, store, app_id, body): store_client = get_market_client(store.access_key, store.url) data = store_client.update_app(app_id=app_id, body=body, market_domain=store.domain) return data
def get_app(self, store, app_id): store_client = get_market_client(store.access_key, store.url) data = store_client.get_user_app_detail(app_id=app_id, market_domain=store.domain, _return_http_data_only=True) return data