Revision e407f159 snf-cyclades-app/synnefo/cyclades_settings.py
b/snf-cyclades-app/synnefo/cyclades_settings.py | ||
---|---|---|
36 | 36 |
from synnefo.util.keypath import get_path, set_path |
37 | 37 |
from synnefo.api.services import cyclades_services as vanilla_cyclades_services |
38 | 38 |
from synnefo.lib.services import fill_endpoints |
39 |
from astakosclient import astakos_services as vanilla_astakos_services
|
|
39 |
from astakosclient import AstakosClient
|
|
40 | 40 |
|
41 | 41 |
from copy import deepcopy |
42 | 42 |
|
43 | 43 |
|
44 |
# -------------------------------------------------------------------- |
|
44 | 45 |
# Process Cyclades settings |
45 | 46 |
|
46 | 47 |
BASE_URL = getattr(settings, 'CYCLADES_BASE_URL', |
47 | 48 |
'https://compute.example.synnefo.org/compute/') |
48 | 49 |
BASE_HOST, BASE_PATH = parse_base_url(BASE_URL) |
50 |
SERVICE_TOKEN = getattr(settings, 'CYCLADES_SERVICE_TOKEN', "") |
|
49 | 51 |
|
50 | 52 |
CUSTOMIZE_SERVICES = getattr(settings, 'CYCLADES_CUSTOMIZE_SERVICES', ()) |
51 | 53 |
cyclades_services = deepcopy(vanilla_cyclades_services) |
... | ... | |
64 | 66 |
COMPUTE_ROOT_URL = join_urls(BASE_URL, COMPUTE_PREFIX) |
65 | 67 |
|
66 | 68 |
|
69 |
# -------------------------------------------------------------------- |
|
67 | 70 |
# Process Astakos settings |
68 | 71 |
|
69 |
ASTAKOS_BASE_URL = getattr(settings, 'ASTAKOS_BASE_URL', |
|
70 |
'https://accounts.example.synnefo.org/astakos/') |
|
71 |
ASTAKOS_BASE_HOST, ASTAKOS_BASE_PATH = parse_base_url(ASTAKOS_BASE_URL) |
|
72 |
|
|
73 |
# Patch astakosclient directly, otherwise it will not see any customization |
|
74 |
#astakos_services = deepcopy(vanilla_astakos_services) |
|
75 |
CUSTOMIZE_ASTAKOS_SERVICES = \ |
|
76 |
getattr(settings, 'CYCLADES_CUSTOMIZE_ASTAKOS_SERVICES', ()) |
|
77 |
|
|
78 |
astakos_services = deepcopy(vanilla_astakos_services) |
|
79 |
fill_endpoints(astakos_services, ASTAKOS_BASE_URL) |
|
80 |
for path, value in CUSTOMIZE_ASTAKOS_SERVICES: |
|
81 |
set_path(astakos_services, path, value, createpath=True) |
|
82 |
|
|
83 |
ASTAKOS_ACCOUNTS_PREFIX = get_path(astakos_services, 'astakos_account.prefix') |
|
84 |
ASTAKOS_VIEWS_PREFIX = get_path(astakos_services, 'astakos_ui.prefix') |
|
85 |
ASTAKOS_KEYSTONE_PREFIX = get_path(astakos_services, 'astakos_identity.prefix') |
|
86 |
|
|
87 |
|
|
88 |
# Proxy Astakos settings |
|
89 |
|
|
90 |
BASE_ASTAKOS_PROXY_PATH = getattr(settings, |
|
91 |
'CYCLADES_BASE_ASTAKOS_PROXY_PATH', |
|
92 |
ASTAKOS_BASE_PATH) |
|
93 |
BASE_ASTAKOS_PROXY_PATH = join_urls(BASE_PATH, BASE_ASTAKOS_PROXY_PATH) |
|
94 |
BASE_ASTAKOS_PROXY_PATH = BASE_ASTAKOS_PROXY_PATH.strip('/') |
|
95 |
|
|
96 |
PROXY_USER_SERVICES = getattr(settings, 'CYCLADES_PROXY_USER_SERVICES', True) |
|
72 |
ASTAKOS_AUTH_URL = getattr( |
|
73 |
settings, 'ASTAKOS_AUTH_URL', |
|
74 |
'https://accounts.example.synnefo.org/astakos/identity/v2.0/') |
|
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_UI_URL and ASTAKOS_ACCOUNT_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, 'CYCLADES_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) |
Also available in: Unified diff