Ejemplo n.º 1
0
def get_sample_content(sha256):
    path = get_sample_path(sha256)
    if Config().api.use_aws:
        s3key = AWSStorage.get_key()
        s3key.name = path
        if s3key.storage_class == 'GLACIER':
            s3key.restore(15)
            return (503, jsonize({'error': 'sample_not_online'}))
        else:
            return (200, s3key.get_contents_as_string())
    else:
        return open(path, "rb").read()
Ejemplo n.º 2
0
def get_sample_path(sha256):
    path = os.path.join(Config().api.repository, sha256[0], sha256[1], sha256[2], sha256[3], sha256)
    if Config().api.use_aws:
        s3key = AWSStorage.get_key()
        s3key.name = path
        if not s3key.exists():
            return None
    else:
        if not os.path.exists(path):
            return None

    return path
Ejemplo n.º 3
0
    def __init__(self, path=None, data=None):
        self.path = path
        self.s3key = None

        if path:
            if Config().api.use_aws:
                self.s3key = AWSStorage.get_key()
                self.s3key.name = self.path
                self.data = self.s3key.get_contents_as_string()
            else:
                self.data = open(self.path, "rb").read()
        else:
            self.data = data