Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (8.3 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
# Archipelago Configuration File
142
BACKEND_ARCHIPELAGO_CONF = getattr(
143
        settings, 'PITHOS_BACKEND_ARCHIPELAGO_CONF',
144
        '/etc/archipelago/archipelago.conf')
145

    
146
# Queue for billing.
147
BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE', None)
148
# Example: 'pithos.backends.lib.rabbitmq'
149

    
150
BACKEND_QUEUE_HOSTS = getattr(settings, 'PITHOS_BACKEND_QUEUE_HOSTS', None)
151
# Example: "['amqp://guest:guest@localhost:5672']"
152

    
153
BACKEND_QUEUE_EXCHANGE = getattr(settings, 'PITHOS_BACKEND_QUEUE_EXCHANGE',
154
                                 'pithos')
155

    
156
# Default setting for new accounts.
157
BACKEND_ACCOUNT_QUOTA = getattr(
158
    settings, 'PITHOS_BACKEND_ACCOUNT_QUOTA', 50 * 1024 * 1024 * 1024)
159
BACKEND_CONTAINER_QUOTA = getattr(
160
    settings, 'PITHOS_BACKEND_CONTAINER_QUOTA', 0)
161
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto')
162
BACKEND_FREE_VERSIONING = getattr(settings, 'PITHOS_BACKEND_FREE_VERSIONING',
163
                                  True)
164

    
165
# Enable backend pooling
166
BACKEND_POOL_ENABLED = getattr(settings, 'PITHOS_BACKEND_POOL_ENABLED', True)
167

    
168
# Default backend pool size
169
BACKEND_POOL_SIZE = getattr(settings, 'PITHOS_BACKEND_POOL_SIZE', 5)
170

    
171
# Update object checksums.
172
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', False)
173

    
174
RADOS_STORAGE = getattr(settings, 'PITHOS_RADOS_STORAGE', False)
175
RADOS_POOL_BLOCKS = getattr(settings, 'PITHOS_RADOS_POOL_BLOCKS', 'blocks')
176
RADOS_POOL_MAPS = getattr(settings, 'PITHOS_RADOS_POOL_MAPS', 'maps')
177

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

    
182
# Set how many random bytes to use for constructing the URL
183
# of Pithos public files
184
PUBLIC_URL_SECURITY = getattr(settings, 'PITHOS_PUBLIC_URL_SECURITY', 16)
185
# Set the alphabet to use for constructing the URL of Pithos public files
186
PUBLIC_URL_ALPHABET = getattr(
187
    settings,
188
    'PITHOS_PUBLIC_URL_ALPHABET',
189
    '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
190

    
191
# The maximum number or items returned by the listing api methods
192
API_LIST_LIMIT = getattr(settings, 'PITHOS_API_LIST_LIMIT', 10000)
193

    
194
# The backend block size
195
BACKEND_BLOCK_SIZE = getattr(
196
    settings, 'PITHOS_BACKEND_BLOCK_SIZE', 4 * 1024 * 1024)
197

    
198
# The backend block hash algorithm
199
BACKEND_HASH_ALGORITHM = getattr(
200
    settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256')
201

    
202
# Set the credentials (client identifier, client secret) issued for
203
# authenticating the views with astakos during the resource access token
204
# generation procedure
205
OAUTH2_CLIENT_CREDENTIALS = getattr(settings,
206
                                    'PITHOS_OAUTH2_CLIENT_CREDENTIALS',
207
                                    (None, None))
208

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