ryan-roemer / django-cloud-browser

Django application browser for cloud datastores (Rackspace, AWS, etc.).
http://ryan-roemer.github.com/django-cloud-browser/
MIT License
81 stars 27 forks source link

Pass additional kwargs to libcloud #44

Open gassc opened 3 years ago

gassc commented 3 years ago

Hi! I'm using the apache-libcloud datastore and looking to access an S3 bucket that isn't in the AWS's us-east-1 region.

After setting up django-cloud-browser, I can see the bucket listed! (So easy to set up--thank you.) When I click the link to look in the bucket, Django throws an error:

<LibcloudError in <class 'libcloud.storage.drivers.s3.S3StorageDriver'> 'This bucket is located in a different region. Please use the correct driver. Bucket region "us-east-2", used region "us-east-1".'>

That's obviously an apache-libcloud error--it has a default region to fallback on. In looking up that error I found this:

https://github.com/apache/libcloud/issues/1379#issuecomment-568214155

...and it looks like the fix is to explicitly pass a region kwarg to get_driver constructor. Make sense.

I read through the django-cloud-browser documentation and source but it doesn't look like there is way to pass additional kwargs through to here:

https://github.com/ryan-roemer/django-cloud-browser/blob/3eda8c8029eebbafead95bff2f5cf40faa35eba8/cloud_browser/cloud/apache_libcloud.py#L162

via here:

https://github.com/ryan-roemer/django-cloud-browser/blob/3eda8c8029eebbafead95bff2f5cf40faa35eba8/cloud_browser/cloud/config.py#L32

  1. My first question is--am I missing an obvious way to set the region keyword in django-cloud-browser so it gets picked up in apached-libcloud?

  2. Second question is, assuming I'm not missing something...would it make sense to have a settings.py variable that could contain arbitrary kwargs that can be passed through to libcloud? Something like:

CLOUD_BROWSER_APACHE_LIBCLOUD_KWARGS = {
  'region': 'us-east-2'
}

Or, since region seems to be a kwarg found for most (all?) classes in libcloud.storage.drivers, would it make sense to follow the pattern in https://github.com/ryan-roemer/django-cloud-browser/commit/77e8f036f6ff1e7c32e4a6e42c6f770e6d69a0e7 and add a CLOUD_BROWSER_APACHE_LIBCLOUD_REGION variable?

I'd be happy to work up a PR doing this if the approach make sense.

c-w commented 3 years ago

Thanks for reaching out. The kwargs approach that you mentioned sounds great to me. Would be happy to accept a pull request for this.