Add auth v2.0 for swift connection

This commit is contained in:
Thierry Ducrest
2017-09-20 12:43:38 +02:00
committed by Guewen Baconnier
co-authored by Guewen Baconnier
parent 1548fd674a
commit dd8f2fc5c8
4 changed files with 42 additions and 18 deletions
+23 -6
View File
@@ -1,23 +1,22 @@
Attachments on Swift storage
============================
This addon allows to store the attachments (documents and assets) on
OpenStack Object Storage (Swift)
This addon enable storing attachments (documents and assets) on OpenStack Object Storage (Swift)
Configuration
-------------
Activate Swift storage:
* Create or set the system parameter with the key ``ir_attachment.location``
and the value in the form ``swift``.
* Create or set the system parameter with the key ``ir_attachment.location`` with the following value ``swift``.
Configure accesses with environment variables:
* ``SWIFT_HOST``
* ``SWIFT_AUTH_URL`` : URL of the Swift server
* ``SWIFT_TENANT_NAME``
* ``SWIFT_ACCOUNT``
* ``SWIFT_PASSWORD``
* ``SWIFT_WRITE_CONTAINER``
* ``SWIFT_WRITE_CONTAINER`` : Name of the container to use in the store (created if not existing)
Read-only mode:
@@ -32,3 +31,21 @@ credentials) without any risk to alter the production data.
This addon must be added in the server wide addons with (``--load`` option):
``--load=web,web_kanban,attachment_swift``
Python Dependencies
-------------------
This module needs the python-swiftclient and the python-keystoneclient (For auth v2.0) to work.
The python-keystoneclient needs the linux package build-essential and python-dev to install properly.
The python-swiftclient can be used from the command line, useful to test:
export AUTH_VERSION=2.0
export OS_USERNAME={SWIFT_ACCOUNT}
export OS_PASSWORD={SWIFT_PASSWORD}
export OS_TENANT_NAME={SWIFT_TENANT_NAME}
export OS_AUTH_URL=https://auth.cloud.ovh.net/v2.0
swift stat
More information at
https://docs.openstack.org/python-swiftclient/latest/cli/index.html#swift-usage
+4 -2
View File
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
@@ -11,7 +11,9 @@
'category': 'Knowledge Management',
'depends': ['base_attachment_object_storage'],
'external_dependencies': {
'python': ['swiftclient'],
'python': ['swiftclient',
'keystoneclient',
],
},
'website': 'http://www.camptocamp.com',
'data': [],
+13 -9
View File
@@ -24,7 +24,7 @@ except ImportError:
class IrAttachment(models.Model):
_inherit = 'ir.attachment'
_SWIFT_STORAGE = 'swift'
store_name = 'swift'
@api.model
def _get_swift_connection(self):
@@ -32,15 +32,19 @@ class IrAttachment(models.Model):
host = os.environ.get('SWIFT_HOST')
account = os.environ.get('SWIFT_ACCOUNT')
password = os.environ.get('SWIFT_PASSWORD')
if not (host and account and password):
tenant_name = os.environ.get('SWIFT_TENANT_NAME')
if not (host and account and password and tenant_name):
raise exceptions.UserError(_(
'''Problem connecting to Swift store, are the env variables
(SWIFT_HOST, SWIFT_ACCOUNT, SWIFT_PASSWORD) properly set ?
'''))
"Problem connecting to Swift store, are the env variables "
"(SWIFT_HOST, SWIFT_ACCOUNT, SWIFT_PASSWORD, "
"SWIFT_TENANT_NAME) properly set?"
))
try:
conn = swiftclient.client.Connection(authurl=host,
user=account,
key=password)
key=password,
tenant_name=tenant_name,
auth_version='2.0')
except ClientException:
_logger.exception('Error connecting to Swift object store')
raise exceptions.UserError(_('Error on Swift connection'))
@@ -64,7 +68,7 @@ class IrAttachment(models.Model):
return super(IrAttachment, self)._store_file_read(fname, bin_size)
def _store_file_write(self, value, checksum):
if self._storage() == self._SWIFT_STORAGE:
if self._storage() == self.store_name:
container = os.environ.get('SWIFT_WRITE_CONTAINER')
conn = self._get_swift_connection()
conn.put_container(container)
@@ -82,7 +86,7 @@ class IrAttachment(models.Model):
return filename
@api.model
def _store_file_delete(self, fname):
def _file_delete_from_store(self, fname):
if fname.startswith('swift://'):
swifturi = SwiftUri(fname)
container = swifturi.container()
@@ -98,6 +102,6 @@ class IrAttachment(models.Model):
super(IrAttachment, self)._file_delete(fname)
def _get_stores(self):
l = [self._SWIFT_STORAGE]
l = [self.store_name]
l += super(IrAttachment, self)._get_stores()
return l
+2 -1
View File
@@ -2,4 +2,5 @@ boto==2.42.0
redis==2.10.5
python-json-logger==0.1.5
statsd==3.2.1
python-swiftclient==3.0.0
python-swiftclient==3.4.0
python-keystoneclient==3.13.0