Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / settings.py @ ff5edb80

History | View | Annotate | Download (8.1 kB)

1
# Copyright 2012-2014 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

    
34
#coding=utf8
35
import logging
36

    
37
from django.conf import settings
38
from synnefo.lib import parse_base_url, join_urls
39
from synnefo.lib.services import fill_endpoints
40
from pithos.api.services import pithos_services as vanilla_pithos_services
41
from astakosclient import AstakosClient
42

    
43
from copy import deepcopy
44

    
45

    
46
logger = logging.getLogger(__name__)
47

    
48
# --------------------------------------------------------------------
49
# Process Pithos settings
50

    
51
# Top-level URL for Pithos. Must set.
52
BASE_URL = getattr(settings, 'PITHOS_BASE_URL',
53
                   "https://object-store.example.synnefo.org/pithos/")
54
# Service Token acquired by identity provider.
55
SERVICE_TOKEN = getattr(settings, 'PITHOS_SERVICE_TOKEN', '')
56

    
57
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
58

    
59
pithos_services = deepcopy(vanilla_pithos_services)
60
fill_endpoints(pithos_services, BASE_URL)
61
PITHOS_PREFIX = pithos_services['pithos_object-store']['prefix']
62
PUBLIC_PREFIX = pithos_services['pithos_public']['prefix']
63
UI_PREFIX = pithos_services['pithos_ui']['prefix']
64
VIEW_PREFIX = join_urls(UI_PREFIX, 'view')
65

    
66

    
67
# --------------------------------------------------------------------
68
# Process Astakos settings
69

    
70
ASTAKOS_AUTH_URL = getattr(
71
    settings, 'ASTAKOS_AUTH_URL',
72
    'https://accounts.example.synnefo.org/astakos/identity/v2.0')
73

    
74
ASTAKOSCLIENT_POOLSIZE = \
75
    getattr(settings, 'PITHOS_ASTAKOSCLIENT_POOLSIZE', 200)
76

    
77

    
78
# --------------------------------------
79
# Define a LazyAstakosUrl
80
# This is used to define ASTAKOS_ACCOUNT_URL and
81
# ASTAKOS_UI_URL and should never be used as is.
82
class LazyAstakosUrl(object):
83
    def __init__(self, endpoints_name):
84
        self.endpoints_name = endpoints_name
85

    
86
    def __str__(self):
87
        if not hasattr(self, 'str'):
88
            try:
89
                astakos_client = \
90
                    AstakosClient(SERVICE_TOKEN, ASTAKOS_AUTH_URL)
91
                self.str = getattr(astakos_client, self.endpoints_name)
92
            except Exception as excpt:
93
                logger.exception(
94
                    "Could not retrieve endpoints from Astakos url %s: %s",
95
                    ASTAKOS_AUTH_URL, excpt)
96
                return ""
97
        return self.str
98

    
99
# --------------------------------------
100
# Define ASTAKOS_ACCOUNT_URL and ASTAKOS_UR_URL as LazyAstakosUrl
101
# These are used to define the proxy paths.
102
# These have to be resolved lazily (by the proxy function) so
103
# they should not be used as is.
104
ASTAKOS_ACCOUNT_URL = LazyAstakosUrl('account_url')
105
ASTAKOS_UI_URL = LazyAstakosUrl('ui_url')
106

    
107
# --------------------------------------
108
# Define Astakos prefixes
109
ASTAKOS_PROXY_PREFIX = getattr(settings, 'PITHOS_PROXY_PREFIX', '_astakos')
110
ASTAKOS_AUTH_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'identity')
111
ASTAKOS_ACCOUNT_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'account')
112
ASTAKOS_UI_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'ui')
113

    
114
# --------------------------------------
115
# Define Astakos proxy paths
116
ASTAKOS_AUTH_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_AUTH_PREFIX)
117
ASTAKOS_ACCOUNT_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_ACCOUNT_PREFIX)
118
ASTAKOS_UI_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_UI_PREFIX)
119

    
120
# Astakos login URL to redirect if the user information is missing
121
LOGIN_URL = join_urls(ASTAKOS_UI_PROXY_PATH, 'login')
122

    
123

    
124
# --------------------------------------------------------------------
125
# Backend settings
126

    
127
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
128
BACKEND_DB_MODULE = getattr(
129
    settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy')
130
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION',
131
                                'sqlite:////tmp/pithos-backend.db')
132

    
133
# Block storage.
134
BACKEND_BLOCK_MODULE = getattr(
135
    settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler')
136
BACKEND_BLOCK_PATH = getattr(
137
    settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/')
138
BACKEND_BLOCK_UMASK = getattr(settings, 'PITHOS_BACKEND_BLOCK_UMASK', 0o022)
139

    
140
# Queue for billing.
141
BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE', None)
142
# Example: 'pithos.backends.lib.rabbitmq'
143

    
144
BACKEND_QUEUE_HOSTS = getattr(settings, 'PITHOS_BACKEND_QUEUE_HOSTS', None)
145
# Example: "['amqp://guest:guest@localhost:5672']"
146

    
147
BACKEND_QUEUE_EXCHANGE = getattr(settings, 'PITHOS_BACKEND_QUEUE_EXCHANGE',
148
                                 'pithos')
149

    
150
# Default setting for new accounts.
151
BACKEND_ACCOUNT_QUOTA = getattr(
152
    settings, 'PITHOS_BACKEND_ACCOUNT_QUOTA', 50 * 1024 * 1024 * 1024)
153
BACKEND_CONTAINER_QUOTA = getattr(
154
    settings, 'PITHOS_BACKEND_CONTAINER_QUOTA', 0)
155
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto')
156
BACKEND_FREE_VERSIONING = getattr(settings, 'PITHOS_BACKEND_FREE_VERSIONING',
157
                                  True)
158

    
159
# Enable backend pooling
160
BACKEND_POOL_ENABLED = getattr(settings, 'PITHOS_BACKEND_POOL_ENABLED', True)
161

    
162
# Default backend pool size
163
BACKEND_POOL_SIZE = getattr(settings, 'PITHOS_BACKEND_POOL_SIZE', 5)
164

    
165
# Update object checksums.
166
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', False)
167

    
168
RADOS_STORAGE = getattr(settings, 'PITHOS_RADOS_STORAGE', False)
169
RADOS_POOL_BLOCKS = getattr(settings, 'PITHOS_RADOS_POOL_BLOCKS', 'blocks')
170
RADOS_POOL_MAPS = getattr(settings, 'PITHOS_RADOS_POOL_MAPS', 'maps')
171

    
172
# This enables a ui compatibility layer for the introduction of UUIDs in
173
# identity management.  WARNING: Setting to True will break your installation.
174
TRANSLATE_UUIDS = getattr(settings, 'PITHOS_TRANSLATE_UUIDS', False)
175

    
176
# Set how many random bytes to use for constructing the URL
177
# of Pithos public files
178
PUBLIC_URL_SECURITY = getattr(settings, 'PITHOS_PUBLIC_URL_SECURITY', 16)
179
# Set the alphabet to use for constructing the URL of Pithos public files
180
PUBLIC_URL_ALPHABET = getattr(
181
    settings,
182
    'PITHOS_PUBLIC_URL_ALPHABET',
183
    '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
184

    
185
# The maximum number or items returned by the listing api methods
186
API_LIST_LIMIT = getattr(settings, 'PITHOS_API_LIST_LIMIT', 10000)
187

    
188
# The backend block size
189
BACKEND_BLOCK_SIZE = getattr(
190
    settings, 'PITHOS_BACKEND_BLOCK_SIZE', 4 * 1024 * 1024)
191

    
192
# The backend block hash algorithm
193
BACKEND_HASH_ALGORITHM = getattr(
194
    settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256')
195

    
196
# Set the credentials (client identifier, client secret) issued for
197
# authenticating the views with astakos during the resource access token
198
# generation procedure
199
OAUTH2_CLIENT_CREDENTIALS = getattr(settings,
200
                                    'PITHOS_OAUTH2_CLIENT_CREDENTIALS',
201
                                    (None, None))
202

    
203
# Set domain to restrict requests of pithos object contents serve endpoint or
204
# None for no domain restriction
205
UNSAFE_DOMAIN = getattr(settings, 'PITHOS_UNSAFE_DOMAIN', None)