Пример #1
0
def getCloudsFromConfig(config_file: str) -> List[cloud_storage.CloudStorage]:
    """Summary
    
    Args:
        config_file (str): Description
    
    Returns:
        List[cloud_storage.CloudStorage]: Description
    """

    config = readConfig(config_file)

    clouds = []

    for cloud in config['clouds']:
        clouds.append(list(cloud.values()))

    cloud_storage_providers = []

    for cloud in clouds:
        if cloud[0].lower() in providers.DRIVERS:
            print("Creating cloud storage provider for", cloud[0])
            # unpacks the could config into a list of args
            # needed becasue some cloud providers require different args than others
            c = cloud_storage.CloudStorage(cloud)
            try:
                c.driver.list_containers()
            except:
                print("ERROR: Failed to connect to cloud:", cloud[0])
                continue
            cloud_storage_providers.append(c)
        else:
            print("ERROR: cloud provider", cloud[0].lower(), "not found")

    return cloud_storage_providers
Пример #2
0
    def export_records(self):
        if not (self.auth and self.auth.read_permission):
            # TODO(gimite): i18n
            self.error(403, message='Missing or invalid authorization key.')
            return

        storage = cloud_storage.CloudStorage()
        object_name = self.config.latest_csv_object_name
        if object_name:
            csv_url = storage.sign_url(
                object_name, url_lifetime=datetime.timedelta(minutes=10))
            self.render('export.html', csv_url=csv_url)
        else:
            self.error(
                404,
                # Translators: An error message indicating that the data
                # requested by the user is not available yet.
                message=_('The data is not ready yet. Try again in 24 hours.'))
Пример #3
0
    def post(self, id):
        data = {}
        try:
            bucket_info = request.get_json()
            if bucket_info == None:
                return {}, 400

            if 'bucket' in bucket_info:
                bucket_name = bucket_info['bucket']

            capital_record = countries.Capitals().fetch_capital(id)
            gcs = cloud_storage.CloudStorage()
            # gcs.create_bucket(capital_record, bucket_name, id)
            mesg, code = gcs.store_file_to_gcs(bucket_name,
                                               json.dumps(capital_record), id)
            return mesg, code

        except Exception as e:
            # swallow up exceptions
            logging.exception('Oops!')
            return 'failed to store capital', 404
Пример #4
0
 def __init__(self, *args, **kwargs):
     super(DumpCSV, self).__init__(*args, **kwargs)
     self.storage = cloud_storage.CloudStorage()