Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / settings.py @ 8f2eb016

History | View | Annotate | Download (7.5 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
from django.conf import settings
36
from synnefo.lib import parse_base_url, join_urls
37
from synnefo.lib.services import fill_endpoints
38
from synnefo.util.keypath import get_path
39
from pithos.api.services import pithos_services as vanilla_pithos_services
40
from astakosclient import AstakosClient
41

    
42
from copy import deepcopy
43

    
44

    
45
# --------------------------------------------------------------------
46
# Process Pithos settings
47

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

    
54
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
55

    
56
pithos_services = deepcopy(vanilla_pithos_services)
57
fill_endpoints(pithos_services, BASE_URL)
58
PITHOS_PREFIX = get_path(pithos_services, 'pithos_object-store.prefix')
59
PUBLIC_PREFIX = get_path(pithos_services, 'pithos_public.prefix')
60
UI_PREFIX = get_path(pithos_services, 'pithos_ui.prefix')
61
VIEW_PREFIX = join_urls(UI_PREFIX, 'view')
62

    
63
COOKIE_NAME = getattr(settings, 'PITHOS_ASTAKOS_COOKIE_NAME', '_pithos2_a')
64

    
65

    
66
# --------------------------------------------------------------------
67
# Process Astakos settings
68

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

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

    
76

    
77
# --------------------------------------
78
# Define a LazyAstakosUrl
79
class LazyAstakosUrl(object):
80
    def __init__(self, endpoints_name):
81
        self.endpoints_name = endpoints_name
82

    
83
    def __str__(self):
84
        if not hasattr(self, 'str'):
85
            try:
86
                astakos_client = \
87
                    AstakosClient(SERVICE_TOKEN, ASTAKOS_AUTH_URL)
88
                self.str = getattr(astakos_client, self.endpoints_name)
89
            except:
90
                return None
91
        return self.str
92

    
93
# --------------------------------------
94
# Define ASTAKOS_ACCOUNT_URL and ASTAKOS_UR_URL as LazyAstakosUrl
95
ASTAKOS_ACCOUNT_URL = LazyAstakosUrl('account_url')
96
ASTAKOS_UI_URL = LazyAstakosUrl('ui_url')
97

    
98
# --------------------------------------
99
# Define Astakos prefixes
100
ASTAKOS_PROXY_PREFIX = getattr(settings, 'PITHOS_PROXY_PREFIX', '_astakos')
101
ASTAKOS_AUTH_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'identity')
102
ASTAKOS_ACCOUNT_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'account')
103
ASTAKOS_UI_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'ui')
104

    
105
# --------------------------------------
106
# Define Astakos proxy paths
107
ASTAKOS_AUTH_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_AUTH_PREFIX)
108
ASTAKOS_ACCOUNT_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_ACCOUNT_PREFIX)
109
ASTAKOS_UI_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_UI_PREFIX)
110

    
111
# Astakos login URL to redirect if the user information is missing
112
LOGIN_URL = join_urls(ASTAKOS_UI_PROXY_PATH, 'login')
113

    
114

    
115
# --------------------------------------------------------------------
116
# Backend settings
117

    
118
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
119
BACKEND_DB_MODULE = getattr(
120
    settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy')
121
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION',
122
                                'sqlite:////tmp/pithos-backend.db')
123

    
124
# Block storage.
125
BACKEND_BLOCK_MODULE = getattr(
126
    settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler')
127
BACKEND_BLOCK_PATH = getattr(
128
    settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/')
129
BACKEND_BLOCK_UMASK = getattr(settings, 'PITHOS_BACKEND_BLOCK_UMASK', 0o022)
130

    
131
# Queue for billing.
132
BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE', None)
133
# Example: 'pithos.backends.lib.rabbitmq'
134

    
135
BACKEND_QUEUE_HOSTS = getattr(settings, 'PITHOS_BACKEND_QUEUE_HOSTS', None)
136
# Example: "['amqp://guest:guest@localhost:5672']"
137

    
138
BACKEND_QUEUE_EXCHANGE = getattr(settings, 'PITHOS_BACKEND_QUEUE_EXCHANGE',
139
                                 'pithos')
140

    
141
# Default setting for new accounts.
142
BACKEND_ACCOUNT_QUOTA = getattr(
143
    settings, 'PITHOS_BACKEND_ACCOUNT_QUOTA', 50 * 1024 * 1024 * 1024)
144
BACKEND_CONTAINER_QUOTA = getattr(
145
    settings, 'PITHOS_BACKEND_CONTAINER_QUOTA', 0)
146
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto')
147
BACKEND_FREE_VERSIONING = getattr(settings, 'PITHOS_BACKEND_FREE_VERSIONING',
148
                                  True)
149

    
150
# Enable backend pooling
151
BACKEND_POOL_ENABLED = getattr(settings, 'PITHOS_BACKEND_POOL_ENABLED', True)
152

    
153
# Default backend pool size
154
BACKEND_POOL_SIZE = getattr(settings, 'PITHOS_BACKEND_POOL_SIZE', 5)
155

    
156
# Update object checksums.
157
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', False)
158

    
159
RADOS_STORAGE = getattr(settings, 'PITHOS_RADOS_STORAGE', False)
160
RADOS_POOL_BLOCKS = getattr(settings, 'PITHOS_RADOS_POOL_BLOCKS', 'blocks')
161
RADOS_POOL_MAPS = getattr(settings, 'PITHOS_RADOS_POOL_MAPS', 'maps')
162

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

    
167
# Set how many random bytes to use for constructing the URL
168
# of Pithos public files
169
PUBLIC_URL_SECURITY = getattr(settings, 'PITHOS_PUBLIC_URL_SECURITY', 16)
170
# Set the alphabet to use for constructing the URL of Pithos public files
171
PUBLIC_URL_ALPHABET = getattr(
172
    settings,
173
    'PITHOS_PUBLIC_URL_ALPHABET',
174
    '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
175

    
176
# The maximum number or items returned by the listing api methods
177
API_LIST_LIMIT = getattr(settings, 'PITHOS_API_LIST_LIMIT', 10000)
178

    
179
# The backend block size
180
BACKEND_BLOCK_SIZE = getattr(
181
    settings, 'PITHOS_BACKEND_BLOCK_SIZE', 4 * 1024 * 1024)
182

    
183
# The backend block hash algorithm
184
BACKEND_HASH_ALGORITHM = getattr(
185
    settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256')
186
# Set the credentials (client_id, client_secret) issued to authenticate
187
# the views with astakos during the resource access token generation procedure
188
OA2_CLIENT_CREDENTIALS = getattr(settings, 'PITHOS_OA2_CLIENT_CREDENTIALS',
189
                                 (None, None))