Revision f759041f snf-pithos-app/pithos/api/settings.py

b/snf-pithos-app/pithos/api/settings.py
1 1
#coding=utf8
2 2
from django.conf import settings
3 3
from synnefo.lib import parse_base_url, join_urls
4
from synnefo.lib.services import fill_endpoints, get_public_endpoint
5
from synnefo.util.keypath import get_path, set_path
4
from synnefo.lib.services import fill_endpoints
5
from synnefo.util.keypath import get_path
6 6
from pithos.api.services import pithos_services as vanilla_pithos_services
7
from astakosclient import astakos_services as vanilla_astakos_services
7
from astakosclient import AstakosClient
8 8

  
9 9
from copy import deepcopy
10 10

  
11

  
12
# --------------------------------------------------------------------
13
# Process Pithos settings
14

  
11 15
# Top-level URL for Pithos. Must set.
12 16
BASE_URL = getattr(settings, 'PITHOS_BASE_URL',
13 17
                   "https://object-store.example.synnefo.org/pithos/")
18
# Service Token acquired by identity provider.
19
SERVICE_TOKEN = getattr(settings, 'PITHOS_SERVICE_TOKEN', '')
14 20

  
15 21
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL)
16 22

  
17
# Process Astakos settings
18
ASTAKOS_BASE_URL = getattr(settings, 'ASTAKOS_BASE_URL',
19
                           'https://accounts.example.synnefo.org/astakos/')
20
ASTAKOS_BASE_HOST, ASTAKOS_BASE_PATH = parse_base_url(ASTAKOS_BASE_URL)
21

  
22 23
pithos_services = deepcopy(vanilla_pithos_services)
23 24
fill_endpoints(pithos_services, BASE_URL)
24 25
PITHOS_PREFIX = get_path(pithos_services, 'pithos_object-store.prefix')
25 26
PUBLIC_PREFIX = get_path(pithos_services, 'pithos_public.prefix')
26 27
UI_PREFIX = get_path(pithos_services, 'pithos_ui.prefix')
27 28

  
28
astakos_services = deepcopy(vanilla_astakos_services)
29
fill_endpoints(astakos_services, ASTAKOS_BASE_URL)
30
CUSTOMIZE_ASTAKOS_SERVICES = getattr(settings,
31
                                     'PITHOS_CUSTOMIZE_ASTAKOS_SERVICES', ())
32
for path, value in CUSTOMIZE_ASTAKOS_SERVICES:
33
    set_path(astakos_services, path, value, createpath=True)
29
COOKIE_NAME = getattr(settings, 'PITHOS_ASTAKOS_COOKIE_NAME', '_pithos2_a')
30

  
34 31

  
35
ASTAKOS_ACCOUNTS_PREFIX = get_path(astakos_services, 'astakos_account.prefix')
36
ASTAKOS_VIEWS_PREFIX = get_path(astakos_services, 'astakos_ui.prefix')
37
ASTAKOS_KEYSTONE_PREFIX = get_path(astakos_services, 'astakos_identity.prefix')
32
# --------------------------------------------------------------------
33
# Process Astakos settings
38 34

  
39
BASE_ASTAKOS_PROXY_PATH = getattr(settings, 'PITHOS_BASE_ASTAKOS_PROXY_PATH',
40
                                  ASTAKOS_BASE_PATH)
41
BASE_ASTAKOS_PROXY_PATH = join_urls(BASE_PATH, BASE_ASTAKOS_PROXY_PATH)
42
BASE_ASTAKOS_PROXY_PATH = BASE_ASTAKOS_PROXY_PATH.strip('/')
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)
43 76

  
77
# Astakos login URL to redirect if the user information is missing
78
LOGIN_URL = join_urls(ASTAKOS_UI_PROXY_PATH, 'login')
44 79

  
45
ASTAKOSCLIENT_POOLSIZE = getattr(settings, 'PITHOS_ASTAKOSCLIENT_POOLSIZE',
46
                                 200)
47 80

  
48
COOKIE_NAME = getattr(settings, 'PITHOS_ASTAKOS_COOKIE_NAME', '_pithos2_a')
81
# --------------------------------------------------------------------
82
# Backend settings
49 83

  
50 84
# SQLAlchemy (choose SQLite/MySQL/PostgreSQL).
51 85
BACKEND_DB_MODULE = getattr(
......
88 122
# Update object checksums.
89 123
UPDATE_MD5 = getattr(settings, 'PITHOS_UPDATE_MD5', False)
90 124

  
91
# Service Token acquired by identity provider.
92
SERVICE_TOKEN = getattr(settings, 'PITHOS_SERVICE_TOKEN', '')
93

  
94 125
RADOS_STORAGE = getattr(settings, 'PITHOS_RADOS_STORAGE', False)
95 126
RADOS_POOL_BLOCKS = getattr(settings, 'PITHOS_RADOS_POOL_BLOCKS', 'blocks')
96 127
RADOS_POOL_MAPS = getattr(settings, 'PITHOS_RADOS_POOL_MAPS', 'maps')
......
99 130
# identity management.  WARNING: Setting to True will break your installation.
100 131
TRANSLATE_UUIDS = getattr(settings, 'PITHOS_TRANSLATE_UUIDS', False)
101 132

  
102
# Set PROXY_USER_SERVICES to True to have snf-pithos-app handle all Astakos
103
# user-visible services (feedback, login, etc.) by proxying them to a running
104
# Astakos.
105
# Set to False if snf astakos-app is running on the same machine, so it handles
106
# the requests on its own.
107
PROXY_USER_SERVICES = getattr(settings, 'PITHOS_PROXY_USER_SERVICES', True)
108

  
109 133
# Set how many random bytes to use for constructing the URL
110 134
# of Pithos public files
111 135
PUBLIC_URL_SECURITY = getattr(settings, 'PITHOS_PUBLIC_URL_SECURITY', 16)
......
125 149
# The backend block hash algorithm
126 150
BACKEND_HASH_ALGORITHM = getattr(
127 151
    settings, 'PITHOS_BACKEND_HASH_ALGORITHM', 'sha256')
128

  
129
ASTAKOS_UI_URL = get_public_endpoint(astakos_services, 'astakos_ui', '').rstrip('/')
130

  
131
# Astakos login URL to redirect if the user information is missing
132
LOGIN_URL = join_urls(ASTAKOS_UI_URL, 'login')

Also available in: Unified diff