예제 #1
0
    def get_image_connection_info(self, scope, team_name):
        """
        :param scope: enterprise(企业) team(团队) goodrain(好雨云市)
        :param service: 应用模型
        :return: image_info

        hub.goodrain.com/goodrain/xxx:lasted
        user: goodrain-admin
        password: goodrain123465
        """
        try:
            if scope == "goodrain":
                return {"hub_url": 'hub.goodrain.com', "namespace": "goodrain"}
            else:
                image_config = ConsoleSysConfig.objects.filter(
                    key='APPSTORE_IMAGE_HUB')
                if not image_config:
                    return {"hub_url": 'goodrain.me', "namespace": team_name}
                image_config_dict = json_load(image_config[0].value)
                hub_url = image_config_dict.get("hub_url", None)
                hub_user = image_config_dict.get("hub_user", None)
                hub_password = image_config_dict.get("hub_password", None)
                image_info = {
                    "hub_url": hub_url,
                    "hub_user": hub_user,
                    "hub_password": hub_password,
                    "namespace": team_name
                }
                return image_info
        except Exception as e:
            logger.exception(e)
            return {}
예제 #2
0
    def get_slug_connection_info(self, scope, team_name):
        """
        :param scope: enterprise(企业) team(团队) goodrain(好雨云市)
        :return: slug_info

        /grdata/build/tenant/
        user: goodrain-admin
        password: goodrain123465
        """
        try:
            if scope == "goodrain":
                return {"namespace": team_name}
            else:
                slug_config = ConsoleSysConfig.objects.filter(
                    key='APPSTORE_SLUG_PATH')
                if not slug_config:
                    return {"namespace": team_name}
                slug_config_dict = json_load(slug_config[0].value)
                ftp_host = slug_config_dict.get("ftp_host", None)
                ftp_port = slug_config_dict.get("ftp_port", None)
                ftp_namespace = slug_config_dict.get("namespace", None)
                ftp_username = slug_config_dict.get("ftp_username", None)
                ftp_password = slug_config_dict.get("ftp_password", None)
                slug_info = {
                    "ftp_host": ftp_host,
                    "ftp_port": ftp_port,
                    "namespace": ftp_namespace + "/" + team_name,
                    "ftp_username": ftp_username,
                    "ftp_password": ftp_password
                }
                return slug_info
        except Exception as e:
            logger.exception(e)
            return {}
예제 #3
0
    def get_image_connection_info(self, scope, team_name):
        """
        :param scope: enterprise(企业) team(团队) goodrain(好雨云市)
        :param service: 应用模型
        :return: image_info

        hub.goodrain.com/goodrain/xxx:lasted
        """
        try:
            team = team_repo.get_team_by_team_name(team_name)
            if not team:
                return {}
            if scope == "goodrain":
                info = market_api.get_share_hub_info(team.tenant_id, "image")
                return info["image_repo"]
            else:
                image_config = ConsoleSysConfig.objects.filter(
                    key='APPSTORE_IMAGE_HUB')
                if not image_config:
                    return {"hub_url": 'goodrain.me', "namespace": team_name}
                image_config_dict = json_load(image_config[0].value)
                hub_url = image_config_dict.get("hub_url", None)
                hub_user = image_config_dict.get("hub_user", None)
                hub_password = image_config_dict.get("hub_password", None)
                namespace = image_config_dict.get("namespace", team_name)
                image_info = {
                    "hub_url": hub_url,
                    "hub_user": hub_user,
                    "hub_password": hub_password,
                    "namespace": namespace
                }
                return image_info
        except Exception as e:
            logger.exception(e)
            return {}
예제 #4
0
    def extract_payload(self, payload, signature):

        expected_sig = self.sign_string(payload)
        if signature != expected_sig:
            return None

        return json_load(base64_url_decode(payload))
예제 #5
0
    def get_image_connection_info(self, scope, team_name):
        """
        :param scope: enterprise(企业) team(团队) goodrain(好雨云市)
        :param team_name: 租户名称
        :return: image_info

        hub.goodrain.com/goodrain/xxx:lasted
        """
        try:
            team = team_repo.get_team_by_team_name(team_name)
            if not team:
                return {}
            if scope.startswith("goodrain"):
                info = market_api.get_share_hub_info(team.tenant_id, "image")
                return info["image_repo"]
            else:
                image_config = ConsoleSysConfig.objects.filter(
                    key='APPSTORE_IMAGE_HUB')
                if not image_config:
                    return {"hub_url": 'goodrain.me', "namespace": team_name}
                image_config_dict = json_load(image_config[0].value)
                hub_url = image_config_dict.get("hub_url", None)
                hub_user = image_config_dict.get("hub_user", None)
                hub_password = image_config_dict.get("hub_password", None)
                namespace = image_config_dict.get("namespace", team_name)
                is_trust = hub_url == 'hub.goodrain.com'
                image_info = {
                    "hub_url": hub_url,
                    "hub_user": hub_user,
                    "hub_password": hub_password,
                    "namespace": namespace,
                    "is_trust": is_trust
                }
                return image_info
        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)
        except Exception as e:
            logger.exception(e)
            return {}
예제 #6
0
    def get_slug_connection_info(self, scope, team_name):
        """
        :param scope: enterprise(企业) team(团队) goodrain(好雨云市)
        :return: slug_info

        /grdata/build/tenant/
        """
        try:
            team = team_repo.get_team_by_team_name(team_name)
            if not team:
                return {}
            if scope == "goodrain":
                info = market_api.get_share_hub_info(team.tenant_id, "slug")
                return info["slug_repo"]
            else:
                slug_config = ConsoleSysConfig.objects.filter(
                    key='APPSTORE_SLUG_PATH')
                if not slug_config:
                    return {"namespace": team_name}
                slug_config_dict = json_load(slug_config[0].value)
                ftp_host = slug_config_dict.get("ftp_host", None)
                ftp_port = slug_config_dict.get("ftp_port", None)
                ftp_namespace = slug_config_dict.get("namespace", None)
                ftp_username = slug_config_dict.get("ftp_username", None)
                ftp_password = slug_config_dict.get("ftp_password", None)
                slug_info = {
                    "ftp_host": ftp_host,
                    "ftp_port": ftp_port,
                    "namespace": ftp_namespace + "/" + team_name,
                    "ftp_username": ftp_username,
                    "ftp_password": ftp_password
                }
                return slug_info
        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)
        except Exception as e:
            logger.exception(e)
            return {}
예제 #7
0
 def get(self, request, *args, **kwargs):
     """
     安装应用
     ---
     parameter:
         - name: team_name
           description: 团队名
           required: true
           type: string
           paramType: path
         - name: app_id
           description: 应用包id
           required: true
           type: string
           paramType: query
     """
     try:
         app_id = request.GET.get("app_id", None)
         if app_id is None or not app_id.isdigit():
             code = 400
             result = general_message(code,
                                      "app_id is missing or not digit!",
                                      "app_id缺失或非数字")
             return Response(result, status=code)
         else:
             code, msg, app = share_service.get_app_by_app_id(app_id=app_id)
             if code == 200:
                 app_template = json_load(app.app_template)
                 share_service.install_service(app_template=app_template)
                 result = general_message(code, "install success", "应用安装成功")
             else:
                 result = general_message(code, "install failed",
                                          "应用安装失败,应用不存在")
             return Response(result, status=code)
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)
예제 #8
0
    def get_slug_connection_info(self, scope, team_name):
        """
        :param scope: enterprise(企业) team(团队) goodrain(好雨云市)
        :return: slug_info

        /grdata/build/tenant/
        """
        try:
            team = team_repo.get_team_by_team_name(team_name)
            if not team:
                return {}
            if scope == "goodrain":
                info = market_api.get_share_hub_info(team.tenant_id, "slug")
                return info["slug_repo"]
            else:
                slug_config = ConsoleSysConfig.objects.filter(
                    key='APPSTORE_SLUG_PATH')
                if not slug_config:
                    return {"namespace": team_name}
                slug_config_dict = json_load(slug_config[0].value)
                ftp_host = slug_config_dict.get("ftp_host", None)
                ftp_port = slug_config_dict.get("ftp_port", None)
                ftp_namespace = slug_config_dict.get("namespace", None)
                ftp_username = slug_config_dict.get("ftp_username", None)
                ftp_password = slug_config_dict.get("ftp_password", None)
                slug_info = {
                    "ftp_host": ftp_host,
                    "ftp_port": ftp_port,
                    "namespace": ftp_namespace + "/" + team_name,
                    "ftp_username": ftp_username,
                    "ftp_password": ftp_password
                }
                return slug_info
        except Exception as e:
            logger.exception(e)
            return {}
예제 #9
0
# -*- coding: utf8 -*-
"""
  Created on 18/2/1.
"""
import threading

from django.conf import settings
from django.core.mail.backends.smtp import EmailBackend

from cadmin.models.main import ConsoleSysConfig
from www.utils.json_tool import json_load

email_config = ConsoleSysConfig.objects.filter(key='EMAIL')
mail_config = json_load(email_config[0].value)
EMAIL_HOST = str(mail_config["EMAIL_HOST"])
EMAIL_PORT = str(mail_config["EMAIL_PORT"])
EMAIL_HOST_USER = str(mail_config["EMAIL_HOST_USER"])
EMAIL_HOST_PASSWORD = str(mail_config["EMAIL_HOST_PASSWORD"])
EMAIL_USE_SSL = mail_config["EMAIL_USE_SSL"]


class SubEmailBackend(EmailBackend):
    def __init__(self,
                 host=None,
                 port=None,
                 username=None,
                 password=None,
                 use_tls=None,
                 fail_silently=False,
                 use_ssl=None,
                 timeout=None,
예제 #10
0
    def get(self, request, group_id, *args, **kwargs):
        """
        查询数据中心分享完成情况,修改状态
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: group_id
              description: 应用组id
              required: true
              type: string
              paramType: path
            - name: app_id
              description: 应用包id
              required: true
              type: string
              paramType: query
        """
        app_id = request.GET.get("app_id", None)
        try:
            if group_id == "-1":
                code = 400
                result = general_message(200, "query success", "未分组应用不可分享")
                return Response(result, status=code)
            else:
                if group_id is None or not group_id.isdigit():
                    code = 400
                    result = general_message(
                        code, "group_id is missing or not digit!",
                        "group_id缺失或非数字")
                    return Response(result, status=code)
                team_id = self.team.tenant_id
                group_count = group_repo.get_group_count_by_team_id_and_group_id(
                    team_id=team_id, group_id=group_id)
                if group_count == 0:
                    code = 400
                    result = general_message(code, "group is not yours!",
                                             "这个应用组不是你的!")
                    return Response(result, status=code)
                else:
                    all_success = True
                    code, msg_show, app = share_service.get_app_by_app_id(
                        app_id=app_id)
                    if app:
                        try:
                            service_list = list()
                            app_template = json_load(app.app_template)
                            for service in app_template:
                                data = dict()
                                res, body = region_api.get_service_publish_status(
                                    self.response_region, self.team_name,
                                    service.get("service_key", None),
                                    service.get("version", None))
                                logger.debug(res, body)

                                bean = body["bean"]
                                status = bean["Status"]
                                success_data = {}
                                if status == "failure" or status == "pushing":
                                    all_success = False
                                    success_data["all_success"] = False
                                    success_data["all_success_cn"] = "应用分享失败"
                                elif status == "success":
                                    success_data["all_success"] = True
                                    success_data["all_success_cn"] = "应用分享成功"
                                    # 应用组发布成功更新数据
                                    share_service.upate_app_complete_by_app_id(
                                        app_id=app_id, data=data)
                                data["id"] = str(
                                    service["service_key"]) + "_" + str(
                                        service["version"])
                                data["service_cname"] = service[
                                    "service_cname"]
                                data["service_key"] = service["service_key"]
                                data["version"] = service["version"]
                                data["status"] = status
                                service_list.append(data)
                                if all_success == 1:
                                    code = 200
                                else:
                                    code = 400
                                result = general_message(
                                    code,
                                    "all_success={0}".format(all_success),
                                    "{0}".format(
                                        success_data.get(
                                            "all_success_cn", None)),
                                    list=service_list)
                                return Response(result, status=200)
                        except Exception as e:
                            logger.exception(e)
                            result = error_message(e.message)
                            return Response(result, status=500)
                    else:
                        result = general_message(400, "failed", "没有此应用包")
                        return Response(result, status=400)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)