mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
SSOwat ACL (WIP)
This commit is contained in:
parent
02e6c5843a
commit
c65e37216b
3 changed files with 56 additions and 5 deletions
|
@ -284,6 +284,11 @@ app:
|
||||||
full: --raw
|
full: --raw
|
||||||
help: Return complete dict
|
help: Return complete dict
|
||||||
action: store_true
|
action: store_true
|
||||||
|
-u:
|
||||||
|
full: --user
|
||||||
|
help: Allowed app map for a user
|
||||||
|
pattern: '^[a-z0-9_]+$'
|
||||||
|
|
||||||
|
|
||||||
### app_install() TODO: Write help
|
### app_install() TODO: Write help
|
||||||
install:
|
install:
|
||||||
|
|
|
@ -126,13 +126,25 @@ def app_list(offset=None, limit=None, filter=None, raw=False):
|
||||||
else:
|
else:
|
||||||
list_dict=[]
|
list_dict=[]
|
||||||
|
|
||||||
if not applists: app_fetchlist()
|
if not applists:
|
||||||
|
app_fetchlist()
|
||||||
|
applists = os.listdir(repo_path)
|
||||||
|
|
||||||
for applist in applists:
|
for applist in applists:
|
||||||
if '.json' in applist:
|
if '.json' in applist:
|
||||||
with open(repo_path +'/'+ applist) as json_list:
|
with open(repo_path +'/'+ applist) as json_list:
|
||||||
app_dict.update(json.loads(str(json_list.read())))
|
app_dict.update(json.loads(str(json_list.read())))
|
||||||
|
|
||||||
|
for app in os.listdir(apps_setting_path):
|
||||||
|
if app not in app_dict:
|
||||||
|
# Look for forks
|
||||||
|
if '__' in app:
|
||||||
|
original_app = app[:app.index('__')]
|
||||||
|
if original_app in app_dict:
|
||||||
|
app_dict[app] = app_dict[original_app]
|
||||||
|
continue
|
||||||
|
app_dict[app] = { 'orphan': True }
|
||||||
|
|
||||||
if len(app_dict) > (0 + offset) and limit > 0:
|
if len(app_dict) > (0 + offset) and limit > 0:
|
||||||
sorted_app_dict = {}
|
sorted_app_dict = {}
|
||||||
for sorted_keys in sorted(app_dict.keys())[offset:]:
|
for sorted_keys in sorted(app_dict.keys())[offset:]:
|
||||||
|
@ -142,7 +154,6 @@ def app_list(offset=None, limit=None, filter=None, raw=False):
|
||||||
for app_id, app_info in sorted_app_dict.items():
|
for app_id, app_info in sorted_app_dict.items():
|
||||||
if i < limit:
|
if i < limit:
|
||||||
if (filter and ((filter in app_id) or (filter in app_info['manifest']['name']))) or not filter:
|
if (filter and ((filter in app_id) or (filter in app_info['manifest']['name']))) or not filter:
|
||||||
#TODO: make _is_installed
|
|
||||||
installed = _is_installed(app_id)
|
installed = _is_installed(app_id)
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
|
@ -173,10 +184,13 @@ def app_info(app, raw=False):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
app_info = app_list(filter=app, limit=1, raw=True)[app]
|
app_info = app_list(filter=app, raw=True)[app]
|
||||||
except YunoHostError:
|
except YunoHostError:
|
||||||
app_info = {}
|
app_info = {}
|
||||||
|
|
||||||
|
with open(apps_setting_path + app +'/settings.yml') as f:
|
||||||
|
app_info['settings'] = yaml.load(f)
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
return app_info
|
return app_info
|
||||||
else:
|
else:
|
||||||
|
@ -187,13 +201,14 @@ def app_info(app, raw=False):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def app_map(app=None, raw=False):
|
def app_map(app=None, raw=False, user=None):
|
||||||
"""
|
"""
|
||||||
List apps by domain
|
List apps by domain
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
app -- Specific app to map
|
app -- Specific app to map
|
||||||
raw -- Return complete dict
|
raw -- Return complete dict
|
||||||
|
user -- Only accessible app for user
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -203,6 +218,12 @@ def app_map(app=None, raw=False):
|
||||||
if app and (app != app_id):
|
if app and (app != app_id):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if user is not None:
|
||||||
|
app_dict = app_info(app=app_id, raw=True)
|
||||||
|
if ('mode' not in app_dict['settings']) or ('mode' in app_dict['settings'] and app_dict['settings']['mode'] == 'private'):
|
||||||
|
if 'allowed_users' in app_dict['settings'] and user not in app_dict['settings']['allowed_users'].split(','):
|
||||||
|
continue
|
||||||
|
|
||||||
with open(apps_setting_path + app_id +'/settings.yml') as f:
|
with open(apps_setting_path + app_id +'/settings.yml') as f:
|
||||||
app_settings = yaml.load(f)
|
app_settings = yaml.load(f)
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import shutil
|
||||||
import json
|
import json
|
||||||
from urllib import urlopen
|
from urllib import urlopen
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
||||||
|
#from yunohost_app import app_list, app_info, app_map
|
||||||
|
|
||||||
|
|
||||||
def domain_list(filter=None, limit=None, offset=None):
|
def domain_list(filter=None, limit=None, offset=None):
|
||||||
|
@ -272,6 +273,28 @@ def domain_ssowatconf():
|
||||||
|
|
||||||
domains = domain_list()['Domains']
|
domains = domain_list()['Domains']
|
||||||
|
|
||||||
|
#apps = {}
|
||||||
|
#for app, v in app_list(raw=True):
|
||||||
|
# app_settings = app_info(raw=True, app=app)['settings']
|
||||||
|
# if 'domain' in app_settings:
|
||||||
|
# if 'path' not in app_settings:
|
||||||
|
# app_settings['path'] = '/'
|
||||||
|
# if 'mode' not in app_settings:
|
||||||
|
# app_settings['mode'] = 'private'
|
||||||
|
# if 'allowed_users' not in app_settings:
|
||||||
|
# app_settings['allowed_users'] = ''
|
||||||
|
|
||||||
|
# apps[app] = {
|
||||||
|
# 'domain': app_settings['domain'],
|
||||||
|
# 'path': app_settings['path'],
|
||||||
|
# 'mode': app_settings['mode'],
|
||||||
|
# 'allowed_users': app_settings['allowed_users']
|
||||||
|
# }
|
||||||
|
|
||||||
|
#users = {}
|
||||||
|
#for user, v in user_list()['Users']:
|
||||||
|
# users[user] = app_map(user=user)
|
||||||
|
|
||||||
conf_dict = {
|
conf_dict = {
|
||||||
'portal_domain': main_domain,
|
'portal_domain': main_domain,
|
||||||
'portal_path': '/ynhsso/',
|
'portal_path': '/ynhsso/',
|
||||||
|
@ -285,7 +308,9 @@ def domain_ssowatconf():
|
||||||
},
|
},
|
||||||
'domains': domains,
|
'domains': domains,
|
||||||
'skipped_urls': ['https://'+ main_domain +'/ynhadmin'],
|
'skipped_urls': ['https://'+ main_domain +'/ynhadmin'],
|
||||||
'unprotected_urls': []
|
'unprotected_urls': [],
|
||||||
|
# 'apps': apps,
|
||||||
|
# 'users': users
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('/etc/ssowat/conf.json', 'wb') as f:
|
with open('/etc/ssowat/conf.json', 'wb') as f:
|
||||||
|
|
Loading…
Add table
Reference in a new issue