当前位置: 首页>>代码示例>>Python>>正文


Python Validator.validate_service_key方法代码示例

本文整理汇总了Python中validator.Validator.validate_service_key方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.validate_service_key方法的具体用法?Python Validator.validate_service_key怎么用?Python Validator.validate_service_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在validator.Validator的用法示例。


在下文中一共展示了Validator.validate_service_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import validate_service_key [as 别名]

#.........这里部分代码省略.........
            keys_to_restore.append(key_data)

        # before enabling app for packager we must delete and archive all keys
        if (nodryrun == True):
            try:
                t_del = []
                for k in package_keys_to_delete:
                    t_del.append(k['id'])

                if (len(t_del) > 0):
                    self.base.delete('package_key', t_del) 
            except ValueError as err:
                self.logger.error('Problem deleting package keys: %s', json.dumps(err.args)) 
                return False

            application_data['is_packaged'] = False
            try:
                self.base.update('application', application_data)
            except ValueError as err:
                if (err.args[0][0]['message'] == 'Invalid Object'):
                    application_data = self.update_object_with_required_attributes(application_data, err.args[0][0]['data'])
                    try:
                        application = self.base.update('application', application_data)
                    except ValueError as err:
                        self.logger.error(json.dumps(err.args))
                        return False
                else:
                    self.logger.error(json.dumps(err.args))
                    return False

            for key in keys_to_restore:
                try:
                    restored_key = self.base.create('key', key)
                    # make sure the data is really restored, including "status" - that often gets 
                    # screwed up due to deleted keys counting against limits
                    backup_key = self.get_service_key_from_backup(self.migration_environment.configuration['migration']['backup_location'], key)
                    if (backup_key == None):
                        backup_key = self.fetch_key(key)

                    if (self.validator.validate_service_key(restored_key, backup_key) == False):
                        self.base.update('key', backup_key)
                except ValueError as err:
                    self.logger.error('Problem creating keys: %s', json.dumps(err.args))
                    return False

        return True



    def get_service_key_from_backup(self, backup_location, key): 
        key_data = None
        try:
            f = open(backup_location + str(key['apikey']) + '_' + str(key['service_key']) + '.json', 'r')
            file_contents = f.read()
            key_data = json.loads(file_contents)
            f.close()
        except IOError as err:
            self.logger.error('Problem retrieving backup key: %s', json.dumps(err.args))
        
        if (key_data == None or len(key_data) == 0):
            self.logger.error('Problem retrieving backup key: %s', json.dumps(err.args))
            return None

        return key_data

    def fetch_key(self, key):
        key_data = None
        # fetch key data
        try:
            key_data = self.base.fetch('keys', '*, member, application, service, developer_class', 'WHERE apikey = \'' + key['apikey'] + '\' AND service_key = \'' + key['service_key'] + '\'')
        except ValueError as err:
            self.logger.error('Problem fetching key: %s', json.dumps(err.args))
            return False

        if (len(key_data) == 1):
            key_data = key_data[0]
        else:
            self.logger.error('Problem fetching key for %s', json.dumps(key))
        
        return key_data


    def fetch_application(self, application):
        application_data = None
        if (application['id'] != ''):
            try:
                # get the application from the database
                application_data = self.base.fetch('applications', '*, keys.*, keys.member, keys.service, keys.developer_class', 'WHERE id = ' + str(application['id']))
            except ValueError as err:
                self.logger.error('Problem fetching application: %s', json.dumps(err.args))

            if (len(application_data) == 1):
                application_data = application_data[0]
            else:
                self.logger.error('Problem fetching application for %s', json.dumps(application))

            if (len(application['keys']) != len(application_data['keys'])):
                self.logger.error('Application data missing keys: json file: %s  api return: %s', json.dumps(application), json.dumps(application_data))

        return application_data
开发者ID:cheryl-mashery,项目名称:masheryapi,代码行数:104,代码来源:base_migrator.py


注:本文中的validator.Validator.validate_service_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。