Ejemplo n.º 1
0
 def _publish_to_market(self, tenant, user_name, plugin):
     tenant_plugin = TenantPlugin.objects.get(plugin_id=plugin.plugin_id)
     market_api = MarketOpenAPI()
     data = {
         "tenant_id": tenant.tenant_id,
         "plugin_key": plugin.plugin_key,
         "plugin_version": plugin.version,
         "build_version": plugin.build_version,
         "plugin_name": plugin.plugin_name,
         "share_user": user_name,
         "share_team": tenant.tenant_alias,
         "intro": plugin.desc,
         "plugin_template": plugin.plugin_template,
         "logo": plugin.pic,
         "category": tenant_plugin.category
     }
     result = market_api.publish_plugin_template_data(tenant.tenant_id, data)
     return result["plugin_url"]
Ejemplo n.º 2
0
 def publish_app_to_public_market(self, tenant, user_name, app):
     market_api = MarketOpenAPI()
     data = dict()
     data["tenant_id"] = tenant.tenant_id
     data["group_key"] = app.group_key
     data["group_version"] = app.version
     data["template_version"] = app.template_version
     data["publish_user"] = user_name
     data["publish_team"] = tenant.tenant_alias
     data["update_note"] = app.describe
     data["group_template"] = app.app_template
     data["group_share_alias"] = app.group_name
     data["logo"] = app.pic
     result = market_api.publish_v2_template_group_data(
         tenant.tenant_id, data)
     # 云市url
     app_url = result["app_url"]
     return app_url
Ejemplo n.º 3
0
    def post(self, request):
        """
        添加或修改企业访问云市的认证信息接口
        ---
        parameters:
            - name: enterprise_id
              description: 云帮本地企业id
              required: true
              type: string
              paramType: form
            - name: market_client_id
              description: 云市授予的企业身份id
              required: true
              type: string
              paramType: form
            - name: market_client_token
              description: 云市授予的企业访问的token
              required: true
              type: string
              paramType: form
        """
        enterprise_id = request.POST.get('enterprise_id')
        market_client_id = request.POST.get('market_client_id')
        market_client_token = request.POST.get('market_client_token')
        if not enterprise_id or not market_client_id or not market_client_token:
            return JsonResponse({'ok': False, 'message': 'missing post parameter!'}, status=400)

        enter = client_auth_service.get_enterprise_by_id(enterprise_id)
        if not enter:
            return JsonResponse({'ok': False, 'message': 'specify enterprise does not existed!'}, status=500)

        try:
            market_api = MarketOpenAPI()
            domain = os.getenv('GOODRAIN_APP_API', settings.APP_SERVICE_API["url"])
            market_api.confirm_access_token(domain, market_client_id, market_client_token)
        except Exception:
            return JsonResponse({'ok': False, 'message': '认证企业信息失败'})

        token_info = client_auth_service.get_market_access_token_by_access_token(market_client_id, market_client_token)
        if token_info and token_info.enterprise_id != enter.ID:
            return JsonResponse({'ok': False, 'message': '非法绑定操作!'})

        client_auth_service.save_market_access_token(enterprise_id, domain, market_client_id, market_client_token)
        return JsonResponse({'ok': True, 'message': 'ok'})
Ejemplo n.º 4
0
 def publish_app_to_public_market(self,
                                  tenant,
                                  user_name,
                                  app,
                                  share_type="private"):
     try:
         market_api = MarketOpenAPI()
         data = dict()
         data["tenant_id"] = tenant.tenant_id
         data["group_key"] = app.group_key
         data["group_version"] = app.version
         data["template_version"] = app.template_version
         data["publish_user"] = user_name
         data["publish_team"] = tenant.tenant_alias
         data["update_note"] = app.describe
         data["group_template"] = app.app_template
         data["group_share_alias"] = app.group_name
         data["logo"] = app.pic
         data["details"] = app.details
         data["share_type"] = share_type
         result = market_api.publish_v2_template_group_data(
             tenant.tenant_id, data)
         # 云市url
         app_url = result["app_url"]
         return app_url
     except HttpClient.CallApiError as e:
         logger.exception(e)
         if e.status == 403:
             raise ServiceHandleException("no cloud permission",
                                          msg_show="云市授权不通过",
                                          status_code=403,
                                          error_code=10407)
         else:
             raise ServiceHandleException("call cloud api failure",
                                          msg_show="云市请求错误",
                                          status_code=500,
                                          error_code=500)
Ejemplo n.º 5
0
from www.views import AuthedView
from www.views.mixin import LeftSideBarMixin
from www.decorator import perm_required
from www.apiclient.marketclient import MarketOpenAPI
from www.services import app_group_svc

logger = logging.getLogger('default')

regionClient = RegionServiceApi()
appClient = AppServiceApi()
baseService = BaseTenantService()
tenantUsedResource = TenantUsedResource()
monitorhook = MonitorHook()
tenantAccountService = TenantAccountService()
codeRepositoriesService = CodeRepositoriesService()
market_api = MarketOpenAPI()


class RemoteServiceMarketAjax(AuthedView):
    """远程的服务数据"""
    def post(self, request, *args, **kwargs):
        try:
            res, resp = appClient.getRemoteServices()
            if res.status == 200:
                # logger.debug(resp.data)
                return JsonResponse({
                    "success": True,
                    "data": resp.data,
                    "info": u"查询成功"
                })
            else:
Ejemplo n.º 6
0
    def post(self, request, *args, **kwargs):
        """
        优化云市绑定企业账号
        ---
        parameters:
            - name: tenantName
              description: 团队名称
              required: true
              type: string
              paramType: path
            - name: enterprise_id
              description: 云帮本地企业id
              required: true
              type: string
              paramType: form
            - name: market_info
              description: 云市授予的认证信息
              required: true
              type: string
              paramType: form

        """
        try:
            logger.debug("bind market access token")
            enterprise_id = request.data.get('enterprise_id')
            ret = request.data.get('market_info')
            market_info = eval(base64.decodestring(ret))
            market_client_id = market_info.get('eid')
            market_client_token = market_info.get('token')
            if not enterprise_id or not market_client_id or not market_client_token:
                return Response(general_message(400, "param error", "请填写相关信息"),
                                status=400)
            enter = enterprise_services.get_enterprise_by_enterprise_id(
                enterprise_id)
            if not enter:
                return Response(general_message(404, "enterprise not found",
                                                "指定的企业未找到"),
                                status=404)
            try:
                market_api = MarketOpenAPI()
                domain = os.getenv('GOODRAIN_APP_API',
                                   settings.APP_SERVICE_API["url"])
                market_api.confirm_access_token(domain, market_client_id,
                                                market_client_token)
            except Exception as e:
                logger.exception(e)
                logger.debug(
                    "joint cloud id:{0} token: {1} check token failure".format(
                        market_client_id, market_client_token))
                return Response(general_message(500, "bind access token fail",
                                                "企业认证失败"),
                                status=500)

            token_info = client_auth_service.get_market_access_token_by_access_token(
                market_client_id, market_client_token)
            if token_info and token_info.enterprise_id != enter.ID:
                return Response(general_message(409, "illegal operation",
                                                "非法绑定操作"),
                                status=409)

            client_auth_service.save_market_access_token(
                enterprise_id, domain, market_client_id, market_client_token)
            result = general_message(200, "success", "绑定成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
Ejemplo n.º 7
0
 def __send_all_group_data(self, tenant, data):
     logger.debug("GROUP DATA START".center(90, "-"))
     logger.debug(json.dumps(data))
     logger.debug("GROUP DATA START".center(90, "-"))
     appClient = MarketOpenAPI()
     appClient.publish_all_service_group_data(tenant.tenant_id, data)
Ejemplo n.º 8
0
# -*- coding: utf8 -*-

import logging

from rest_framework.response import Response

from backends.services.resultservice import *
from console.services.region_services import region_services
from console.services.team_services import team_services
from console.views.base import JWTAuthApiView, RegionTenantHeaderView
from www.apiclient.marketclient import MarketOpenAPI
from www.utils.return_message import error_message, general_message

logger = logging.getLogger("default")
open_api = MarketOpenAPI()


class RegSimQuyView(JWTAuthApiView):
    def get(self, request, team_name, *args, **kwargs):
        """
        获取团队数据中心(简表)
        ---
        parameters:
            - name: team_name
              description: 当前团队名字
              required: true
              type: string
              paramType: path
        """
        try:
            code = 200
Ejemplo n.º 9
0
from console.repositories.app import service_repo
from console.services.app_actions import app_manage_service
from console.services.app_actions.app_deploy import AppDeployService
from console.services.app_actions.exception import ErrServiceSourceNotFound
from console.services.app_config.env_service import AppEnvVarService
from console.services.market_app_service import market_app_service
from console.services.team_services import team_services
from console.views.app_config.base import AppBaseView
from console.views.base import RegionTenantHeaderView
from www.apiclient.regionapi import RegionInvokeApi
from www.decorator import perm_required
from www.utils.return_message import general_message
from console.enum.component_enum import is_support, is_state
from www.apiclient.marketclient import MarketOpenAPI

market_openapi = MarketOpenAPI()

logger = logging.getLogger("default")

env_var_service = AppEnvVarService()
app_deploy_service = AppDeployService()
region_api = RegionInvokeApi()


class StartAppView(AppBaseView):
    @never_cache
    @perm_required('start_service')
    def post(self, request, *args, **kwargs):
        """
        启动组件
        ---