root / snf-pithos-app / pithos / api / settings.py @ 79c0ca48
History | View | Annotate | Download (6 kB)
1 |
#coding=utf8
|
---|---|
2 |
from django.conf import settings |
3 |
from synnefo.lib import parse_base_url, join_urls |
4 |
from synnefo.lib.services import fill_endpoints |
5 |
from synnefo.util.keypath import get_path |
6 |
from pithos.api.services import pithos_services as vanilla_pithos_services |
7 |
from astakosclient import AstakosClient |
8 |
|
9 |
from copy import deepcopy |
10 |
|
11 |
|
12 |
# --------------------------------------------------------------------
|
13 |
# Process Pithos settings
|
14 |
|
15 |
# Top-level URL for Pithos. Must set.
|
16 |
BASE_URL = getattr(settings, 'PITHOS_BASE_URL', |
17 |
"https://object-store.example.synnefo.org/pithos/")
|
18 |
# Service Token acquired by identity provider.
|
19 |
SERVICE_TOKEN = getattr(settings, 'PITHOS_SERVICE_TOKEN', '') |
20 |
|
21 |
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL) |
22 |
|
23 |
pithos_services = deepcopy(vanilla_pithos_services) |
24 |
fill_endpoints(pithos_services, BASE_URL) |
25 |
PITHOS_PREFIX = get_path(pithos_services, 'pithos_object-store.prefix')
|
26 |
PUBLIC_PREFIX = get_path(pithos_services, 'pithos_public.prefix')
|
27 |
UI_PREFIX = get_path(pithos_services, 'pithos_ui.prefix')
|
28 |
VIEW_PREFIX = join_urls(UI_PREFIX, 'view')
|
29 |
|
30 |
COOKIE_NAME = getattr(settings, 'PITHOS_ASTAKOS_COOKIE_NAME', '_pithos2_a') |
31 |
|
32 |
|
33 |
# --------------------------------------------------------------------
|
34 |
# Process Astakos settings
|
35 |
|
36 |
ASTAKOS_AUTH_URL = getattr(
|
37 |
settings, 'ASTAKOS_AUTH_URL',
|
38 |
'https://accounts.example.synnefo.org/astakos/identity/v2.0')
|
39 |
|
40 |
ASTAKOSCLIENT_POOLSIZE = \ |
41 |
getattr(settings, 'PITHOS_ASTAKOSCLIENT_POOLSIZE', 200) |
42 |
|
43 |
|
44 |
# --------------------------------------
|
45 |
# Define a LazyAstakosUrl
|
46 |
class LazyAstakosUrl(object): |
47 |
def __init__(self, endpoints_name): |
48 |
self.endpoints_name = endpoints_name
|
49 |
|
50 |
def __str__(self): |
51 |
if not hasattr(self, 'str'): |
52 |
try:
|
53 |
astakos_client = \ |
54 |
AstakosClient(SERVICE_TOKEN, ASTAKOS_AUTH_URL) |
55 |
self.str = getattr(astakos_client, self.endpoints_name) |
56 |
except:
|
57 |
return None |
58 |
return self.str |
59 |
|
60 |
# --------------------------------------
|
61 |
# Define ASTAKOS_ACCOUNT_URL and ASTAKOS_UR_URL as LazyAstakosUrl
|
62 |
ASTAKOS_ACCOUNT_URL = LazyAstakosUrl('account_url')
|
63 |
ASTAKOS_UI_URL = LazyAstakosUrl('ui_url')
|
64 |
|
65 |
# --------------------------------------
|
66 |
# Define Astakos prefixes
|
67 |
ASTAKOS_PROXY_PREFIX = getattr(settings, 'PITHOS_PROXY_PREFIX', '_astakos') |
68 |
ASTAKOS_AUTH_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'identity') |
69 |
ASTAKOS_ACCOUNT_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'account') |
70 |
ASTAKOS_UI_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'ui') |
71 |
|
72 |
# --------------------------------------
|
73 |
# Define Astakos proxy paths
|
74 |
ASTAKOS_AUTH_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_AUTH_PREFIX) |
75 |
ASTAKOS_ACCOUNT_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_ACCOUNT_PREFIX) |
76 |
ASTAKOS_UI_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_UI_PREFIX) |
77 |
|
78 |
# Astakos login URL to redirect if the user information is missing
|
79 |
LOGIN_URL = join_urls(ASTAKOS_UI_PROXY_PATH, 'login')
|
80 |
|
81 |
|
82 |
# --------------------------------------------------------------------
|
83 |
# Backend settings
|
84 |
|
85 |
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
|
86 |
BACKEND_DB_MODULE = getattr(
|
87 |
settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy') |
88 |
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION', |
89 |
'sqlite:////tmp/pithos-backend.db')
|
90 |
|
91 |
# Block storage.
|
92 |
BACKEND_BLOCK_MODULE = getattr(
|
93 |
settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler') |
94 |
BACKEND_BLOCK_PATH = getattr(
|
95 |
settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/') |
96 |
BACKEND_BLOCK_UMASK = getattr(settings, 'PITHOS_BACKEND_BLOCK_UMASK', 0o022) |
97 |
|
98 |
# Queue for billing.
|
99 |
BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE', None) |
100 |
# Example: 'pithos.backends.lib.rabbitmq'
|
101 |
|
102 |
BACKEND_QUEUE_HOSTS = getattr(settings, 'PITHOS_BACKEND_QUEUE_HOSTS', None) |
103 |
# Example: "['amqp://guest:guest@localhost:5672']"
|
104 |
|
105 |
BACKEND_QUEUE_EXCHANGE = getattr(settings, 'PITHOS_BACKEND_QUEUE_EXCHANGE', |
106 |
'pithos')
|
107 |
|
108 |
# Default setting for new accounts.
|
109 |
BACKEND_ACCOUNT_QUOTA = getattr(
|
110 |
settings, 'PITHOS_BACKEND_ACCOUNT_QUOTA', 50 * 1024 * 1024 * 1024) |
111 |
BACKEND_CONTAINER_QUOTA = getattr(
|
112 |
settings, 'PITHOS_BACKEND_CONTAINER_QUOTA', 0) |
113 |
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto') |
114 |
BACKEND_FREE_VERSIONING = getattr(settings, 'PITHOS_BACKEND_FREE_VERSIONING', |
115 |
True)
|
116 |
|
117 |
# Enable backend pooling
|
118 |
BACKEND_POOL_ENABLED = getattr(settings, 'PITHOS_BACKEND_POOL_ENABLED', True) |
119 |
|
120 |
# Default backend pool size
|
121 |
BACKEND_POOL_SIZE = getattr(settings, 'PITHOS_BACKEND_POOL_SIZE', 5) |
122 |
|
123 |
# Update object checksums.
|
124 |
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', False) |
125 |
|
126 |
RADOS_STORAGE = getattr(settings, 'PITHOS_RADOS_STORAGE', False) |
127 |
RADOS_POOL_BLOCKS = getattr(settings, 'PITHOS_RADOS_POOL_BLOCKS', 'blocks') |
128 |
RADOS_POOL_MAPS = getattr(settings, 'PITHOS_RADOS_POOL_MAPS', 'maps') |
129 |
|
130 |
# This enables a ui compatibility layer for the introduction of UUIDs in
|
131 |
# identity management. WARNING: Setting to True will break your installation.
|
132 |
TRANSLATE_UUIDS = getattr(settings, 'PITHOS_TRANSLATE_UUIDS', False) |
133 |
|
134 |
# Set how many random bytes to use for constructing the URL
|
135 |
# of Pithos public files
|
136 |
PUBLIC_URL_SECURITY = getattr(settings, 'PITHOS_PUBLIC_URL_SECURITY', 16) |
137 |
# Set the alphabet to use for constructing the URL of Pithos public files
|
138 |
PUBLIC_URL_ALPHABET = getattr(
|
139 |
settings, |
140 |
'PITHOS_PUBLIC_URL_ALPHABET',
|
141 |
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
142 |
|
143 |
# The maximum number or items returned by the listing api methods
|
144 |
API_LIST_LIMIT = getattr(settings, 'PITHOS_API_LIST_LIMIT', 10000) |
145 |
|
146 |
# The backend block size
|
147 |
BACKEND_BLOCK_SIZE = getattr(
|
148 |
settings, 'PITHOS_BACKEND_BLOCK_SIZE', 4 * 1024 * 1024) |
149 |
|
150 |
# The backend block hash algorithm
|
151 |
BACKEND_HASH_ALGORITHM = getattr(
|
152 |
settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256') |
153 |
# Set the credentials (client_id, client_secret) issued to authenticate
|
154 |
# the views with astakos during the resource access token generation procedure
|
155 |
OA2_CLIENT_CREDENTIALS = getattr(settings, 'PITHOS_OA2_CLIENT_CREDENTIALS', |
156 |
(None, None)) |