Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (8.7 kB)

1
# Copyright 2012, 2013 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 synnefo.util.keypath import get_path
41
from pithos.api.services import pithos_services as vanilla_pithos_services
42
from astakosclient import AstakosClient
43

    
44
from copy import deepcopy
45

    
46

    
47
logger = logging.getLogger(__name__)
48

    
49
# --------------------------------------------------------------------
50
# Process Pithos settings
51

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

    
58
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
59

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

    
67

    
68
# --------------------------------------------------------------------
69
# Process Astakos settings
70

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

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

    
78

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

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

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

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

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

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

    
124

    
125
# --------------------------------------------------------------------
126
# Backend settings
127

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
208
# Archipelago Configuration File
209
BACKEND_ARCHIPELAGO_CONF = getattr(settings, 'PITHOS_BACKEND_ARCHIPELAGO_CONF',
210
                                   '/etc/archipelago/archipelago.conf')
211

    
212
# Archipelagp xseg pool size
213
BACKEND_XSEG_POOL_SIZE = getattr(settings, 'PITHOS_BACKEND_XSEG_POOL_SIZE', 8)
214

    
215
# The maximum interval (in seconds) for consequent backend object map checks
216
BACKEND_MAP_CHECK_INTERVAL = getattr(settings,
217
                                     'PITHOS_BACKEND_MAP_CHECK_INTERVAL', 5)