mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
Add auth v2.0 for swift connection
This commit is contained in:
committed by
Guewen Baconnier
co-authored by
Guewen Baconnier
parent
1548fd674a
commit
dd8f2fc5c8
@@ -1,23 +1,22 @@
|
|||||||
Attachments on Swift storage
|
Attachments on Swift storage
|
||||||
============================
|
============================
|
||||||
|
|
||||||
This addon allows to store the attachments (documents and assets) on
|
This addon enable storing attachments (documents and assets) on OpenStack Object Storage (Swift)
|
||||||
OpenStack Object Storage (Swift)
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Activate Swift storage:
|
Activate Swift storage:
|
||||||
|
|
||||||
* Create or set the system parameter with the key ``ir_attachment.location``
|
* Create or set the system parameter with the key ``ir_attachment.location`` with the following value ``swift``.
|
||||||
and the value in the form ``swift``.
|
|
||||||
|
|
||||||
Configure accesses with environment variables:
|
Configure accesses with environment variables:
|
||||||
|
|
||||||
* ``SWIFT_HOST``
|
* ``SWIFT_AUTH_URL`` : URL of the Swift server
|
||||||
|
* ``SWIFT_TENANT_NAME``
|
||||||
* ``SWIFT_ACCOUNT``
|
* ``SWIFT_ACCOUNT``
|
||||||
* ``SWIFT_PASSWORD``
|
* ``SWIFT_PASSWORD``
|
||||||
* ``SWIFT_WRITE_CONTAINER``
|
* ``SWIFT_WRITE_CONTAINER`` : Name of the container to use in the store (created if not existing)
|
||||||
|
|
||||||
Read-only mode:
|
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):
|
This addon must be added in the server wide addons with (``--load`` option):
|
||||||
|
|
||||||
``--load=web,web_kanban,attachment_swift``
|
``--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
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2016 Camptocamp SA
|
# Copyright 2017 Camptocamp SA
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,9 @@
|
|||||||
'category': 'Knowledge Management',
|
'category': 'Knowledge Management',
|
||||||
'depends': ['base_attachment_object_storage'],
|
'depends': ['base_attachment_object_storage'],
|
||||||
'external_dependencies': {
|
'external_dependencies': {
|
||||||
'python': ['swiftclient'],
|
'python': ['swiftclient',
|
||||||
|
'keystoneclient',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
'website': 'http://www.camptocamp.com',
|
'website': 'http://www.camptocamp.com',
|
||||||
'data': [],
|
'data': [],
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ except ImportError:
|
|||||||
class IrAttachment(models.Model):
|
class IrAttachment(models.Model):
|
||||||
_inherit = 'ir.attachment'
|
_inherit = 'ir.attachment'
|
||||||
|
|
||||||
_SWIFT_STORAGE = 'swift'
|
store_name = 'swift'
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_swift_connection(self):
|
def _get_swift_connection(self):
|
||||||
@@ -32,15 +32,19 @@ class IrAttachment(models.Model):
|
|||||||
host = os.environ.get('SWIFT_HOST')
|
host = os.environ.get('SWIFT_HOST')
|
||||||
account = os.environ.get('SWIFT_ACCOUNT')
|
account = os.environ.get('SWIFT_ACCOUNT')
|
||||||
password = os.environ.get('SWIFT_PASSWORD')
|
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(_(
|
raise exceptions.UserError(_(
|
||||||
'''Problem connecting to Swift store, are the env variables
|
"Problem connecting to Swift store, are the env variables "
|
||||||
(SWIFT_HOST, SWIFT_ACCOUNT, SWIFT_PASSWORD) properly set ?
|
"(SWIFT_HOST, SWIFT_ACCOUNT, SWIFT_PASSWORD, "
|
||||||
'''))
|
"SWIFT_TENANT_NAME) properly set?"
|
||||||
|
))
|
||||||
try:
|
try:
|
||||||
conn = swiftclient.client.Connection(authurl=host,
|
conn = swiftclient.client.Connection(authurl=host,
|
||||||
user=account,
|
user=account,
|
||||||
key=password)
|
key=password,
|
||||||
|
tenant_name=tenant_name,
|
||||||
|
auth_version='2.0')
|
||||||
except ClientException:
|
except ClientException:
|
||||||
_logger.exception('Error connecting to Swift object store')
|
_logger.exception('Error connecting to Swift object store')
|
||||||
raise exceptions.UserError(_('Error on Swift connection'))
|
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)
|
return super(IrAttachment, self)._store_file_read(fname, bin_size)
|
||||||
|
|
||||||
def _store_file_write(self, value, checksum):
|
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')
|
container = os.environ.get('SWIFT_WRITE_CONTAINER')
|
||||||
conn = self._get_swift_connection()
|
conn = self._get_swift_connection()
|
||||||
conn.put_container(container)
|
conn.put_container(container)
|
||||||
@@ -82,7 +86,7 @@ class IrAttachment(models.Model):
|
|||||||
return filename
|
return filename
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _store_file_delete(self, fname):
|
def _file_delete_from_store(self, fname):
|
||||||
if fname.startswith('swift://'):
|
if fname.startswith('swift://'):
|
||||||
swifturi = SwiftUri(fname)
|
swifturi = SwiftUri(fname)
|
||||||
container = swifturi.container()
|
container = swifturi.container()
|
||||||
@@ -98,6 +102,6 @@ class IrAttachment(models.Model):
|
|||||||
super(IrAttachment, self)._file_delete(fname)
|
super(IrAttachment, self)._file_delete(fname)
|
||||||
|
|
||||||
def _get_stores(self):
|
def _get_stores(self):
|
||||||
l = [self._SWIFT_STORAGE]
|
l = [self.store_name]
|
||||||
l += super(IrAttachment, self)._get_stores()
|
l += super(IrAttachment, self)._get_stores()
|
||||||
return l
|
return l
|
||||||
|
|||||||
+2
-1
@@ -2,4 +2,5 @@ boto==2.42.0
|
|||||||
redis==2.10.5
|
redis==2.10.5
|
||||||
python-json-logger==0.1.5
|
python-json-logger==0.1.5
|
||||||
statsd==3.2.1
|
statsd==3.2.1
|
||||||
python-swiftclient==3.0.0
|
python-swiftclient==3.4.0
|
||||||
|
python-keystoneclient==3.13.0
|
||||||
|
|||||||
Reference in New Issue
Block a user