root / snf-pithos-app / pithos / api / settings.py @ 6ce03057
History | View | Annotate | Download (5.7 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 |
|
29 |
COOKIE_NAME = getattr(settings, 'PITHOS_ASTAKOS_COOKIE_NAME', '_pithos2_a') |
30 |
|
31 |
|
32 |
# --------------------------------------------------------------------
|
33 |
# Process Astakos settings
|
34 |
|
35 |
ASTAKOS_AUTH_URL = getattr(
|
36 |
settings, 'ASTAKOS_AUTH_URL',
|
37 |
'https://accounts.example.synnefo.org/astakos/identity/v2.0')
|
38 |
|
39 |
ASTAKOSCLIENT_POOLSIZE = \ |
40 |
getattr(settings, 'PITHOS_ASTAKOSCLIENT_POOLSIZE', 200) |
41 |
|
42 |
|
43 |
# --------------------------------------
|
44 |
# Define a LazyAstakosUrl
|
45 |
class LazyAstakosUrl(object): |
46 |
def __init__(self, endpoints_name): |
47 |
self.endpoints_name = endpoints_name
|
48 |
|
49 |
def __str__(self): |
50 |
if not hasattr(self, 'str'): |
51 |
try:
|
52 |
astakos_client = \ |
53 |
AstakosClient(SERVICE_TOKEN, ASTAKOS_AUTH_URL) |
54 |
self.str = getattr(astakos_client, self.endpoints_name) |
55 |
except:
|
56 |
return None |
57 |
return self.str |
58 |
|
59 |
# --------------------------------------
|
60 |
# Define ASTAKOS_ACCOUNT_URL and ASTAKOS_UR_URL as LazyAstakosUrl
|
61 |
ASTAKOS_ACCOUNT_URL = LazyAstakosUrl('account_url')
|
62 |
ASTAKOS_UI_URL = LazyAstakosUrl('ui_url')
|
63 |
|
64 |
# --------------------------------------
|
65 |
# Define Astakos prefixes
|
66 |
ASTAKOS_PROXY_PREFIX = getattr(settings, 'PITHOS_PROXY_PREFIX', '_astakos') |
67 |
ASTAKOS_AUTH_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'identity') |
68 |
ASTAKOS_ACCOUNT_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'account') |
69 |
ASTAKOS_UI_PREFIX = join_urls('/', ASTAKOS_PROXY_PREFIX, 'ui') |
70 |
|
71 |
# --------------------------------------
|
72 |
# Define Astakos proxy paths
|
73 |
ASTAKOS_AUTH_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_AUTH_PREFIX) |
74 |
ASTAKOS_ACCOUNT_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_ACCOUNT_PREFIX) |
75 |
ASTAKOS_UI_PROXY_PATH = join_urls(BASE_PATH, ASTAKOS_UI_PREFIX) |
76 |
|
77 |
# Astakos login URL to redirect if the user information is missing
|
78 |
LOGIN_URL = join_urls(ASTAKOS_UI_PROXY_PATH, 'login')
|
79 |
|
80 |
|
81 |
# --------------------------------------------------------------------
|
82 |
# Backend settings
|
83 |
|
84 |
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
|
85 |
BACKEND_DB_MODULE = getattr(
|
86 |
settings, 'PITHOS_BACKEND_DB_MODULE', 'pithos.backends.lib.sqlalchemy') |
87 |
BACKEND_DB_CONNECTION = getattr(settings, 'PITHOS_BACKEND_DB_CONNECTION', |
88 |
'sqlite:////tmp/pithos-backend.db')
|
89 |
|
90 |
# Block storage.
|
91 |
BACKEND_BLOCK_MODULE = getattr(
|
92 |
settings, 'PITHOS_BACKEND_BLOCK_MODULE', 'pithos.backends.lib.hashfiler') |
93 |
BACKEND_BLOCK_PATH = getattr(
|
94 |
settings, 'PITHOS_BACKEND_BLOCK_PATH', '/tmp/pithos-data/') |
95 |
BACKEND_BLOCK_UMASK = getattr(settings, 'PITHOS_BACKEND_BLOCK_UMASK', 0o022) |
96 |
|
97 |
# Queue for billing.
|
98 |
BACKEND_QUEUE_MODULE = getattr(settings, 'PITHOS_BACKEND_QUEUE_MODULE', None) |
99 |
# Example: 'pithos.backends.lib.rabbitmq'
|
100 |
|
101 |
BACKEND_QUEUE_HOSTS = getattr(settings, 'PITHOS_BACKEND_QUEUE_HOSTS', None) |
102 |
# Example: "['amqp://guest:guest@localhost:5672']"
|
103 |
|
104 |
BACKEND_QUEUE_EXCHANGE = getattr(settings, 'PITHOS_BACKEND_QUEUE_EXCHANGE', |
105 |
'pithos')
|
106 |
|
107 |
# Default setting for new accounts.
|
108 |
BACKEND_ACCOUNT_QUOTA = getattr(
|
109 |
settings, 'PITHOS_BACKEND_ACCOUNT_QUOTA', 50 * 1024 * 1024 * 1024) |
110 |
BACKEND_CONTAINER_QUOTA = getattr(
|
111 |
settings, 'PITHOS_BACKEND_CONTAINER_QUOTA', 0) |
112 |
BACKEND_VERSIONING = getattr(settings, 'PITHOS_BACKEND_VERSIONING', 'auto') |
113 |
BACKEND_FREE_VERSIONING = getattr(settings, 'PITHOS_BACKEND_FREE_VERSIONING', |
114 |
True)
|
115 |
|
116 |
# Enable backend pooling
|
117 |
BACKEND_POOL_ENABLED = getattr(settings, 'PITHOS_BACKEND_POOL_ENABLED', True) |
118 |
|
119 |
# Default backend pool size
|
120 |
BACKEND_POOL_SIZE = getattr(settings, 'PITHOS_BACKEND_POOL_SIZE', 5) |
121 |
|
122 |
# Update object checksums.
|
123 |
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', False) |
124 |
|
125 |
RADOS_STORAGE = getattr(settings, 'PITHOS_RADOS_STORAGE', False) |
126 |
RADOS_POOL_BLOCKS = getattr(settings, 'PITHOS_RADOS_POOL_BLOCKS', 'blocks') |
127 |
RADOS_POOL_MAPS = getattr(settings, 'PITHOS_RADOS_POOL_MAPS', 'maps') |
128 |
|
129 |
# This enables a ui compatibility layer for the introduction of UUIDs in
|
130 |
# identity management. WARNING: Setting to True will break your installation.
|
131 |
TRANSLATE_UUIDS = getattr(settings, 'PITHOS_TRANSLATE_UUIDS', False) |
132 |
|
133 |
# Set how many random bytes to use for constructing the URL
|
134 |
# of Pithos public files
|
135 |
PUBLIC_URL_SECURITY = getattr(settings, 'PITHOS_PUBLIC_URL_SECURITY', 16) |
136 |
# Set the alphabet to use for constructing the URL of Pithos public files
|
137 |
PUBLIC_URL_ALPHABET = getattr(
|
138 |
settings, |
139 |
'PITHOS_PUBLIC_URL_ALPHABET',
|
140 |
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
141 |
|
142 |
# The maximum number or items returned by the listing api methods
|
143 |
API_LIST_LIMIT = getattr(settings, 'PITHOS_API_LIST_LIMIT', 10000) |
144 |
|
145 |
# The backend block size
|
146 |
BACKEND_BLOCK_SIZE = getattr(
|
147 |
settings, 'PITHOS_BACKEND_BLOCK_SIZE', 4 * 1024 * 1024) |
148 |
|
149 |
# The backend block hash algorithm
|
150 |
BACKEND_HASH_ALGORITHM = getattr(
|
151 |
settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256') |