Esempio n. 1
0
    def active_market_enterprise(self, sso_user, enterprise_id,
                                 market_client_id, market_client_token):
        """
        将sso_user 绑定到指定的enterprise上,并绑定访问云市的认证信息
        :param sso_user: 
        :param enterprise_id: 
        :param market_client_id: 
        :param market_client_token: 
        :return: 
        """
        enterprise = enterprise_svc.get_enterprise_by_id(enterprise_id)
        # 如果要绑定的企业在本地云帮不存在, 且eid与云市eid一致,则创建一个与公有云一致的企业信息
        if not enterprise and enterprise_id == sso_user.eid:
            # 注册一个用户信息
            user = user_svc.register_user_from_sso(sso_user)

            # 创建一个企业信息
            enterprise = enterprise_svc.create_enterprise(
                enterprise_id=sso_user.eid, enterprise_alias=sso_user.company)
            logger.info('create enterprise[{0}] with name {1}[{2}]'.format(
                enterprise.enterprise_id, enterprise.enterprise_alias,
                enterprise.enterprise_name))
            # 绑定用户与企业关系
            user.enterprise_id = enterprise.enterprise_id
            user.save()

            logger.info(
                'create user[{0}] with name [{1}] from [{2}] use sso_id [{3}]'.
                format(user.user_id, user.nick_name, user.rf,
                       user.sso_user_id))
            # 初始化用户工作环境
            tenant = enterprise_svc.create_and_init_tenant(
                user_id=user.user_id, enterprise_id=user.enterprise_id)

        domain = os.getenv('GOODRAIN_APP_API', settings.APP_SERVICE_API["url"])
        return client_auth_service.save_market_access_token(
            enterprise_id, domain, market_client_id, market_client_token)
Esempio n. 2
0
 def get_enterprise_by_id(self, enterprise_id):
     return enterprise_svc.get_enterprise_by_id(enterprise_id)