示例#1
0
 def save_market_access_token(self, enterprise_id, url, market_client_id,
                              market_client_token):
     """
     保存企业访问云市的api的token
     :param enterprise_id: 要绑定激活的云市企业ID
     :param url: 云市url
     :param market_client_id: 云市业ID
     :param market_client_token: 云市企业token
     :return:
     """
     enterprise = self.get_enterprise_by_id(enterprise_id)
     if not enterprise:
         return False
     # enterprise的认证信息统一由TenantEnterpriseToken管理
     try:
         token = TenantEnterpriseToken.objects.get(
             enterprise_id=enterprise.pk, access_target='market')
         token.access_url = url
         token.access_id = market_client_id
         token.access_token = market_client_token
         token.update_time = dt.datetime.now()
         token.save()
     except TenantEnterpriseToken.DoesNotExist:
         token = TenantEnterpriseToken()
         token.enterprise_id = enterprise.pk
         token.access_target = 'market'
         token.access_url = url
         token.access_id = market_client_id
         token.access_token = market_client_token
         token.save()
     enterprise.is_active = 1
     enterprise.save()
     self.reflush_access_token(enterprise_id, 'market')
     return True
示例#2
0
    def save_region_access_token(self, enterprise_id, region_name, access_url,
                                 access_token, key, crt):
        """
        保存企业访问数据中心api的token
        :param enterprise_id: 企业ID
        :param region_name: 数据中心名字
        :param access_url: 数据中心访问url
        :param access_token: 数据中心访问token
        :param key: 数据中心访问证书key
        :param crt: 数据中心访问证书crt
        :return:
        """
        enterprise = self.get_enterprise_by_id(enterprise_id)
        if not enterprise:
            return False

        try:
            token = TenantEnterpriseToken.objects.get(
                enterprise_id=enterprise.pk, access_target=region_name)
            token.access_url = access_url
            token.access_token = access_token
            token.key = key
            token.crt = crt
            token.update_time = dt.datetime.now()
            token.save()

            self.reflush_access_token(enterprise_id, region_name)
        except TenantEnterpriseToken.DoesNotExist:
            token = TenantEnterpriseToken()
            token.enterprise_id = enterprise.pk
            token.access_target = region_name
            token.access_url = access_url
            token.access_token = access_token
            token.key = key
            token.crt = crt
            token.save()

        return True